File: vehicle_power_test.cpp

package info (click to toggle)
cataclysm-dda 0.C%2Bgit20190228.faafa3a-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 181,636 kB
  • sloc: cpp: 256,609; python: 2,621; makefile: 862; sh: 495; perl: 37; xml: 33
file content (76 lines) | stat: -rw-r--r-- 3,202 bytes parent folder | download
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
#include "catch/catch.hpp"
#include "game.h"
#include "map.h"
#include "map_iterator.h"
#include "vehicle.h"
#include "veh_type.h"
#include "player.h"
#include "itype.h"
#include "calendar.h"
#include "weather.h"

static const itype_id fuel_type_battery( "battery" );
static const itype_id fuel_type_plut_cell( "plut_cell" );

TEST_CASE( "vehicle_power" )
{
    GIVEN( "Reactor and solar panels" ) {
        for( const tripoint &p : g->m.points_in_rectangle( tripoint( 0, 0, 0 ),
                tripoint( MAPSIZE * SEEX, MAPSIZE * SEEY, 0 ) ) ) {
            g->m.furn_set( p, furn_id( "f_null" ) );
            g->m.ter_set( p, ter_id( "t_pavement" ) );
            g->m.trap_set( p, trap_id( "tr_null" ) );
            g->m.i_clear( p );
        }

        g->m.build_map_cache( 0, true );

        const tripoint test_origin( 15, 15, 0 );
        g->u.setpos( test_origin );
        const tripoint vehicle_origin = tripoint( 10, 10, 0 );
        VehicleList vehs = g->m.get_vehicles();
        vehicle *veh_ptr;
        for( auto &vehs_v : vehs ) {
            veh_ptr = vehs_v.v;
            g->m.destroy_vehicle( veh_ptr );
        }
        g->refresh_all();
        REQUIRE( g->m.get_vehicles().empty() );
        veh_ptr = g->m.add_vehicle( vproto_id( "reactor_test" ), vehicle_origin, 0, 0, 0 );
        REQUIRE( veh_ptr != nullptr );
        g->refresh_all();
        REQUIRE( !veh_ptr->reactors.empty() );
        vehicle_part &reactor = veh_ptr->parts[ veh_ptr->reactors.front() ];
        reactor.ammo_unset();
        veh_ptr->discharge_battery( veh_ptr->fuel_left( fuel_type_battery ) );
        REQUIRE( veh_ptr->fuel_left( fuel_type_battery ) == 0 );
        reactor.ammo_set( fuel_type_plut_cell, 1 );
        REQUIRE( reactor.ammo_remaining() == 1 );
        veh_ptr->power_parts();
        CHECK( reactor.ammo_remaining() == 0 );
        CHECK( veh_ptr->fuel_left( fuel_type_battery ) == 100 );
        g->m.destroy_vehicle( veh_ptr );
        g->refresh_all();
        REQUIRE( g->m.get_vehicles().empty() );
        const tripoint solar_origin = tripoint( 5, 5, 0 );
        veh_ptr = g->m.add_vehicle( vproto_id( "solar_panel_test" ), solar_origin, 0, 0, 0 );
        REQUIRE( veh_ptr != nullptr );
        g->refresh_all();
        calendar::turn = to_turns<int>( calendar::turn.season_length() ) + DAYS( 1 );
        const time_point start_time = calendar::turn.sunrise() + 3_hours;
        veh_ptr->update_time( start_time );
        veh_ptr->discharge_battery( veh_ptr->fuel_left( fuel_type_battery ) );
        REQUIRE( veh_ptr->fuel_left( fuel_type_battery ) == 0 );
        g->weather_override = WEATHER_SUNNY;
        veh_ptr->update_time( start_time + 30_minutes );
        int approx_battery1 = veh_ptr->fuel_left( fuel_type_battery ) / 100;
        const int exp_min = 12;
        const int exp_max = 14;
        CHECK( approx_battery1 >= exp_min );
        CHECK( approx_battery1 <= exp_max );
        veh_ptr->update_time( start_time + 2 * 30_minutes );
        int approx_battery2 = veh_ptr->fuel_left( fuel_type_battery ) / 100;
        CHECK( approx_battery2 >= approx_battery1 + exp_min );
        CHECK( approx_battery2 <= approx_battery1 + exp_max );
    }
}