forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vehicle_turrets_test.cpp
102 lines (82 loc) · 2.8 KB
/
vehicle_turrets_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <algorithm>
#include <map>
#include <memory>
#include <utility>
#include <vector>
#include "avatar.h"
#include "catch/catch.hpp"
#include "ammo.h"
#include "game.h"
#include "itype.h"
#include "map.h"
#include "veh_type.h"
#include "vehicle.h"
#include "item.h"
#include "item_location.h"
#include "optional.h"
#include "string_id.h"
#include "units.h"
#include "type_id.h"
#include "point.h"
static std::vector<const vpart_info *> turret_types()
{
std::vector<const vpart_info *> res;
for( const auto &e : vpart_info::all() ) {
if( e.second.has_flag( "TURRET" ) ) {
res.push_back( &e.second );
}
}
return res;
}
static const vpart_info *biggest_tank( const ammotype &ammo )
{
std::vector<const vpart_info *> res;
for( const auto &e : vpart_info::all() ) {
const auto &vp = e.second;
if( !item( vp.item ).is_watertight_container() ) {
continue;
}
const itype *fuel = item::find_type( vp.fuel_type );
if( fuel->ammo && fuel->ammo->type == ammo ) {
res.push_back( &vp );
}
}
if( res.empty() ) {
return nullptr;
}
return * std::max_element( res.begin(), res.end(),
[]( const vpart_info * lhs, const vpart_info * rhs ) {
return lhs->size < rhs->size;
} );
}
TEST_CASE( "vehicle_turret", "[vehicle] [gun] [magazine] [.]" )
{
for( auto e : turret_types() ) {
SECTION( e->name() ) {
vehicle *veh = g->m.add_vehicle( vproto_id( "none" ), point( 65, 65 ), 270, 0, 0 );
REQUIRE( veh );
const int idx = veh->install_part( point_zero, e->get_id(), true );
REQUIRE( idx >= 0 );
REQUIRE( veh->install_part( point_zero, vpart_id( "storage_battery" ), true ) >= 0 );
veh->charge_battery( 10000 );
auto ammo = ammotype( veh->turret_query( veh->parts[idx] ).base()->ammo_default() );
if( veh->part_flag( idx, "USE_TANKS" ) ) {
auto *tank = biggest_tank( ammo );
REQUIRE( tank );
INFO( tank->get_id().str() );
auto tank_idx = veh->install_part( point_zero, tank->get_id(), true );
REQUIRE( tank_idx >= 0 );
REQUIRE( veh->parts[ tank_idx ].ammo_set( ammo->default_ammotype() ) );
} else if( ammo ) {
veh->parts[ idx].ammo_set( ammo->default_ammotype() );
}
auto qry = veh->turret_query( veh->parts[ idx ] );
REQUIRE( qry );
REQUIRE( qry.query() == turret_data::status::ready );
REQUIRE( qry.range() > 0 );
g->u.setpos( veh->global_part_pos3( idx ) );
REQUIRE( qry.fire( g->u, g->u.pos() + point( qry.range(), 0 ) ) > 0 );
g->m.destroy_vehicle( veh );
}
}
}