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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
|
#include <array>
#include <iosfwd>
#include <memory>
#include <new>
#include <optional>
#include <set>
#include <string>
#include <vector>
#include "calendar.h"
#include "cata_catch.h"
#include "character.h"
#include "creature_tracker.h"
#include "game.h"
#include "game_constants.h"
#include "map.h"
#include "map_helpers.h"
#include "monster.h"
#include "point.h"
#include "tileray.h"
#include "type_id.h"
#include "units.h"
#include "veh_type.h"
#include "vehicle.h"
#include "vpart_position.h"
#include "vpart_range.h"
static const mtype_id debug_mon( "debug_mon" );
static void clear_game_and_set_ramp( const int transit_x, bool use_ramp, bool up )
{
// Set to turn 0 to prevent solars from producing power
calendar::turn = calendar::turn_zero;
clear_map();
clear_vehicles();
Character &player_character = get_player_character();
// Move player somewhere safe
REQUIRE_FALSE( player_character.in_vehicle );
map &here = get_map();
build_test_map( ter_id( "t_pavement" ) );
if( use_ramp ) {
const int upper_zlevel = up ? 1 : 0;
const int lower_zlevel = up - 1;
const int highx = transit_x + ( up ? 0 : 1 );
const int lowx = transit_x + ( up ? 1 : 0 );
// up z1 ...... rdh rDl
// z0 rUh rul .................
// down z0 rDl rdh .................
// z-1 ...... rdl rUh
// 60 61
for( int y = 0; y < SEEY * MAPSIZE; y++ ) {
for( int x = 0; x < transit_x; x++ ) {
const int mid = up ? upper_zlevel : lower_zlevel;
here.ter_set( tripoint( x, y, mid - 2 ), ter_id( "t_rock" ) );
here.ter_set( tripoint( x, y, mid - 1 ), ter_id( "t_rock" ) );
here.ter_set( tripoint( x, y, mid ), ter_id( "t_pavement" ) );
here.ter_set( tripoint( x, y, mid + 1 ), ter_id( "t_open_air" ) );
here.ter_set( tripoint( x, y, mid + 2 ), ter_id( "t_open_air" ) );
}
const tripoint ramp_up_low = tripoint( lowx, y, lower_zlevel );
const tripoint ramp_up_high = tripoint( highx, y, lower_zlevel );
const tripoint ramp_down_low = tripoint( lowx, y, upper_zlevel );
const tripoint ramp_down_high = tripoint( highx, y, upper_zlevel );
here.ter_set( ramp_up_low, ter_id( "t_ramp_up_low" ) );
here.ter_set( ramp_up_high, ter_id( "t_ramp_up_high" ) );
here.ter_set( ramp_down_low, ter_id( "t_ramp_down_low" ) );
here.ter_set( ramp_down_high, ter_id( "t_ramp_down_high" ) );
for( int x = transit_x + 2; x < SEEX * MAPSIZE; x++ ) {
here.ter_set( tripoint( x, y, 1 ), ter_id( "t_open_air" ) );
here.ter_set( tripoint( x, y, 0 ), ter_id( "t_pavement" ) );
here.ter_set( tripoint( x, y, -1 ), ter_id( "t_rock" ) );
}
}
}
here.invalidate_map_cache( 0 );
here.build_map_cache( 0, true );
}
// Algorithm goes as follows:
// Clear map and create a ramp
// Spawn a vehicle
// Drive it over the ramp, and confirm that the vehicle changes z-levels
static void ramp_transition_angled( const vproto_id &veh_id, const units::angle angle,
const int transition_x, bool use_ramp, bool up )
{
map &here = get_map();
clear_game_and_set_ramp( transition_x, use_ramp, up );
const tripoint map_starting_point( transition_x + 4, 60, 0 );
REQUIRE( here.ter( map_starting_point ) == ter_id( "t_pavement" ) );
if( here.ter( map_starting_point ) != ter_id( "t_pavement" ) ) {
return;
}
vehicle *veh_ptr = here.add_vehicle( veh_id, map_starting_point, angle, 1, 0 );
REQUIRE( veh_ptr != nullptr );
if( veh_ptr == nullptr ) {
return;
}
vehicle &veh = *veh_ptr;
veh.check_falling_or_floating();
REQUIRE( !veh.is_in_water() );
veh.tags.insert( "IN_CONTROL_OVERRIDE" );
veh.engine_on = true;
Character &player_character = get_player_character();
player_character.setpos( map_starting_point );
REQUIRE( player_character.pos() == map_starting_point );
if( player_character.pos() != map_starting_point ) {
return;
}
get_map().board_vehicle( map_starting_point, &player_character );
REQUIRE( player_character.pos() == map_starting_point );
if( player_character.pos() != map_starting_point ) {
return;
}
const int transition_cycle = 3;
veh.cruise_velocity = 0;
veh.velocity = 0;
here.vehmove();
const int target_velocity = 400;
veh.cruise_velocity = target_velocity;
veh.velocity = target_velocity;
CHECK( veh.safe_velocity() > 0 );
int cycles = 0;
const int target_z = use_ramp ? ( up ? 1 : -1 ) : 0;
std::set<tripoint> vpts = veh.get_points();
while( veh.engine_on && veh.safe_velocity() > 0 && cycles < 10 ) {
clear_creatures();
CAPTURE( cycles );
for( const tripoint &checkpt : vpts ) {
int partnum = 0;
vehicle *check_veh = here.veh_at_internal( checkpt, partnum );
CAPTURE( veh_ptr->global_pos3() );
CAPTURE( veh_ptr->face.dir() );
CAPTURE( checkpt );
CHECK( check_veh == veh_ptr );
}
vpts.clear();
here.vehmove();
CHECK( veh.velocity == target_velocity );
// If the vehicle starts skidding, the effects become random and test is RUINED
REQUIRE( !veh.skidding );
for( const tripoint &pos : veh.get_points() ) {
REQUIRE( here.ter( pos ) );
}
for( const vpart_reference &vp : veh.get_all_parts() ) {
if( vp.info().location != "structure" ) {
continue;
}
const point &pmount = vp.mount();
CAPTURE( pmount );
const tripoint &ppos = vp.pos();
CAPTURE( ppos );
if( cycles > ( transition_cycle - pmount.x ) ) {
CHECK( ppos.z == target_z );
} else {
CHECK( ppos.z == 0 );
}
if( pmount.x == 0 && pmount.y == 0 ) {
CHECK( player_character.pos() == ppos );
}
}
vpts = veh.get_points();
cycles++;
}
const std::optional<vpart_reference> vp = here.veh_at( player_character.pos() ).part_with_feature(
VPFLAG_BOARDABLE, true );
REQUIRE( vp );
if( vp ) {
const int z_change = map_starting_point.z - player_character.pos().z;
here.unboard_vehicle( *vp, &player_character, false );
here.ter_set( map_starting_point, ter_id( "t_pavement" ) );
player_character.setpos( map_starting_point );
if( z_change ) {
g->vertical_move( z_change, true );
}
}
}
static void test_ramp( const std::string &type, const int transition_x )
{
CAPTURE( type );
SECTION( "no ramp" ) {
ramp_transition_angled( vproto_id( type ), 180_degrees, transition_x, false, false );
}
SECTION( "ramp up" ) {
ramp_transition_angled( vproto_id( type ), 180_degrees, transition_x, true, true );
}
SECTION( "ramp down" ) {
ramp_transition_angled( vproto_id( type ), 180_degrees, transition_x, true, false );
}
SECTION( "angled no ramp" ) {
ramp_transition_angled( vproto_id( type ), 225_degrees, transition_x, false, false );
}
SECTION( "angled ramp down" ) {
ramp_transition_angled( vproto_id( type ), 225_degrees, transition_x, true, false );
}
SECTION( "angled ramp up" ) {
ramp_transition_angled( vproto_id( type ), 225_degrees, transition_x, true, true );
}
}
static std::vector<std::string> ramp_vehs_to_test = {{
"motorcycle",
}
};
// I'd like to do this in a single loop, but that doesn't work for some reason
TEST_CASE( "vehicle_ramp_test_59", "[vehicle][ramp]" )
{
for( const std::string &veh : ramp_vehs_to_test ) {
test_ramp( veh, 59 );
}
}
TEST_CASE( "vehicle_ramp_test_60", "[vehicle][ramp]" )
{
for( const std::string &veh : ramp_vehs_to_test ) {
test_ramp( veh, 60 );
}
}
TEST_CASE( "vehicle_ramp_test_61", "[vehicle][ramp]" )
{
for( const std::string &veh : ramp_vehs_to_test ) {
test_ramp( veh, 61 );
}
}
static void level_out( const vproto_id &veh_id, const bool drop_pos )
{
map &here = get_map();
clear_game_and_set_ramp( 75, drop_pos, false );
const int start_z = drop_pos ? 1 : 0;
const tripoint map_starting_point( 60, 60, start_z );
// Make sure the avatar is out of the way
Character &player_character = get_player_character();
player_character.setpos( map_starting_point + point( 5, 5 ) );
vehicle *veh_ptr = here.add_vehicle( veh_id, map_starting_point, 180_degrees, 1, 0 );
REQUIRE( veh_ptr != nullptr );
if( veh_ptr == nullptr ) {
return;
}
vehicle &veh = *veh_ptr;
veh.check_falling_or_floating();
REQUIRE( !veh.is_in_water() );
veh.tags.insert( "IN_CONTROL_OVERRIDE" );
veh.engine_on = true;
const int target_velocity = 800;
veh.cruise_velocity = target_velocity;
veh.velocity = target_velocity;
CHECK( veh.safe_velocity() > 0 );
std::vector<vehicle_part *> all_parts;
for( const tripoint &pos : veh.get_points() ) {
for( vehicle_part *prt : veh.get_parts_at( pos, "", part_status_flag::any ) ) {
all_parts.push_back( prt );
if( drop_pos && prt->mount.x < 0 ) {
prt->precalc[0].z = -1;
prt->precalc[1].z = -1;
} else if( !drop_pos && prt->mount.x > 1 ) {
prt->precalc[0].z = 1;
prt->precalc[1].z = 1;
}
}
}
std::set<int> z_span;
for( vehicle_part *prt : all_parts ) {
z_span.insert( veh.global_part_pos3( *prt ).z );
}
REQUIRE( z_span.size() > 1 );
creature_tracker &creatures = get_creature_tracker();
Creature *existing_creature =
creatures.creature_at<Creature>( map_starting_point );
if( existing_creature ) {
CAPTURE( existing_creature->as_character() );
CAPTURE( existing_creature->as_avatar() );
CAPTURE( existing_creature->is_monster() );
REQUIRE( !existing_creature );
}
monster *dmon_p = g->place_critter_at( debug_mon, map_starting_point );
REQUIRE( dmon_p );
monster &dmon = *dmon_p;
for( int y = 0; y < SEEY * MAPSIZE; y++ ) {
for( int x = 0; x < SEEX * MAPSIZE; x++ ) {
here.ter_set( tripoint( x, y, 1 ), ter_id( "t_open_air" ) );
here.ter_set( tripoint( x, y, 0 ), ter_id( "t_pavement" ) );
}
}
here.vehmove();
for( vehicle_part *prt : all_parts ) {
CHECK( veh.global_part_pos3( *prt ).z == 0 );
}
CHECK( dmon.posz() == 0 );
CHECK( veh.global_pos3().z == 0 );
}
static void test_leveling( const std::string &type )
{
SECTION( type + " body drop" ) {
level_out( vproto_id( type ), true );
}
SECTION( type + " edge drop" ) {
level_out( vproto_id( type ), false );
}
}
static std::vector<std::string> level_vehs_to_test = {{
"beetle",
}
};
TEST_CASE( "vehicle_level_test", "[vehicle][ramp]" )
{
for( const std::string &veh : level_vehs_to_test ) {
test_leveling( veh );
}
}
|