109 lines
3.5 KiB
C++
109 lines
3.5 KiB
C++
#include <string>
|
|
|
|
#include "avatar.h"
|
|
#include "calendar.h"
|
|
#include "cata_catch.h"
|
|
#include "character.h"
|
|
#include "coordinates.h"
|
|
#include "item.h"
|
|
#include "item_location.h"
|
|
#include "map.h"
|
|
#include "player_helpers.h"
|
|
#include "type_id.h"
|
|
|
|
static const itype_id itype_arrow_field_point_fletched( "arrow_field_point_fletched" );
|
|
static const itype_id itype_arrow_flamming( "arrow_flamming" );
|
|
static const itype_id itype_cheese_hard( "cheese_hard" );
|
|
static const itype_id itype_grenade_act( "grenade_act" );
|
|
static const itype_id itype_migo_plate( "migo_plate" );
|
|
static const itype_id itype_migo_plate_undergrown( "migo_plate_undergrown" );
|
|
static const itype_id itype_test_rock_cheese( "test_rock_cheese" );
|
|
|
|
TEST_CASE( "countdown_action_triggering", "[item]" )
|
|
{
|
|
avatar dummy;
|
|
Character *who = &dummy;
|
|
|
|
item &grenade = *who->i_add( item( itype_grenade_act ) );
|
|
grenade.active = true;
|
|
|
|
SECTION( "countdown_point is in future" ) {
|
|
grenade.countdown_point = calendar::turn + 10_seconds;
|
|
// Grenade does not explode
|
|
CHECK( grenade.process( get_map(), who, tripoint_bub_ms::zero ) == false );
|
|
}
|
|
|
|
SECTION( "countdown_point is in past" ) {
|
|
grenade.countdown_point = calendar::turn - 10_seconds;
|
|
// Grenade explodes and is to be removed
|
|
CHECK( grenade.process( get_map(), who, tripoint_bub_ms::zero ) == true );
|
|
}
|
|
|
|
SECTION( "countdown_point is now" ) {
|
|
grenade.countdown_point = calendar::turn;
|
|
// Grenade explodes and is to be removed
|
|
CHECK( grenade.process( get_map(), who, tripoint_bub_ms::zero ) == true );
|
|
}
|
|
}
|
|
|
|
TEST_CASE( "countdown_action_revert_to", "[item]" )
|
|
{
|
|
avatar dummy;
|
|
Character *who = &dummy;
|
|
clear_character( dummy );
|
|
|
|
SECTION( "revert to inert item" ) {
|
|
item &test_item = *who->i_add( item( itype_arrow_flamming ) );
|
|
test_item.active = true;
|
|
test_item.countdown_point = calendar::turn;
|
|
|
|
// Is not deleted after coundown action
|
|
CHECK( test_item.process( get_map(), who, tripoint_bub_ms::zero ) == false );
|
|
|
|
// Turns into normal arrow
|
|
CHECK( test_item.typeId() == itype_arrow_field_point_fletched );
|
|
|
|
// Is not active anymore
|
|
CHECK_FALSE( test_item.active );
|
|
|
|
// Timer is gone
|
|
CHECK( test_item.countdown_point == calendar::turn_max );
|
|
}
|
|
|
|
SECTION( "revert to item with new timer" ) {
|
|
item &test_item = *who->i_add( item( itype_migo_plate_undergrown ) );
|
|
test_item.active = true;
|
|
test_item.countdown_point = calendar::turn;
|
|
|
|
// Is not deleted after coundown action
|
|
CHECK( test_item.process( get_map(), who, tripoint_bub_ms::zero ) == false );
|
|
|
|
// Turns into new armor type
|
|
CHECK( test_item.typeId() == itype_migo_plate );
|
|
|
|
// Is still active
|
|
CHECK( test_item.active );
|
|
|
|
// Has new timer
|
|
CHECK( test_item.countdown_point == calendar::turn + 24_hours );
|
|
}
|
|
|
|
SECTION( "revert to item that requires processing" ) {
|
|
item &test_item = *who->i_add( item( itype_test_rock_cheese ) );
|
|
test_item.active = true;
|
|
test_item.countdown_point = calendar::turn;
|
|
|
|
// Is not deleted after coundown action
|
|
CHECK( test_item.process( get_map(), who, tripoint_bub_ms::zero ) == false );
|
|
|
|
// Turns into cheese
|
|
CHECK( test_item.typeId() == itype_cheese_hard );
|
|
|
|
// Is still active
|
|
CHECK( test_item.active );
|
|
|
|
// Timer is gone
|
|
CHECK( test_item.countdown_point == calendar::turn_max );
|
|
}
|
|
}
|