Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Venera3 committed May 4, 2024
1 parent 86fe71b commit a424102
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 1 deletion.
1 change: 1 addition & 0 deletions data/json/body_parts.json
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,7 @@
"accusative": { "ctxt": "bodypart_accusative", "str": "debug tail" },
"hp_bar_ui_text": "DBG TAIL",
"base_hp": 20,
"health_limit": 5,
"flags": [ "ALWAYS_BLOCK", "NONSTANDARD_BLOCK", "MEND_LIMB", "WALL_CLING" ],
"armor": { "bash": 10 },
"unarmed_damage": [ { "damage_type": "acid", "amount": 10 }, { "damage_type": "bullet", "amount": 5, "armor_penetration": 100 } ],
Expand Down
19 changes: 19 additions & 0 deletions data/mods/TEST_DATA/body_parts.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
[
{
"type": "body_part",
"id": "mouth",
"copy-from": "mouth",
"name": "mouth",
"similar_bodyparts": [ "test_corvid_beak" ],
"limb_type": "mouth",
"limb_scores": [ [ "breathing", 1.0 ], [ "manip", 0.05, 0.2 ] ]
},
{
"type": "sub_body_part",
"id": "mouth_lips",
"copy-from": "mouth_lips",
"similar_bodyparts": [ "sub_limb_test_corvid_beak" ],
"opposite": "mouth_lips",
"side": 0,
"name": "lips",
"name_multiple": "lips"
},
{
"type": "body_part",
"id": "test_arm_l",
Expand Down
41 changes: 40 additions & 1 deletion data/mods/TEST_DATA/martialarts.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,35 @@
[
{
"type": "technique",
"id": "test_vector_tech_1",
"name": "Test Vectors One",
"//": "Fails because of missing limbs of type other",
"unarmed_allowed": true,
"messages": [ "You tail-slap %s", "<npcname> tail-slaps %s" ],
"attack_vectors": [ "test_tail_req" ]
},
{
"type": "technique",
"id": "test_vector_tech_2",
"name": "Test Vectors Two",
"//": "Beaks get substituted, succeeds on birdperson",
"unarmed_allowed": true,
"messages": [ "You peck the %s", "<npcname> pecks the %s" ],
"attack_vectors": [ "test_beak" ]
},
{
"type": "attack_vector",
"id": "test_tail_req",
"limbs": [ "hand_l" ],
"contact_area": [ "hand_fingers_l" ],
"limb_req": [ [ "tail", 1 ] ]
},
{
"type": "attack_vector",
"id": "test_beak",
"limbs": [ "mouth" ],
"contact_area": [ "mouth_lips" ]
},
{
"type": "technique",
"id": "test_technique",
Expand Down Expand Up @@ -121,7 +152,15 @@
"weapon_categories_allowed": "KNIVES"
}
],
"techniques": [ "test_technique", "test_tech_condition_sweep", "test_tech_condition_stun", "test_tech_condition_knockback" ],
"techniques": [
"test_technique",
"test_tech_condition_sweep",
"test_tech_condition_stun",
"test_tech_condition_knockback",
"test_vector_tech_1",
"test_vector_tech_2",
"test_vector_tech_3"
],
"weapon_category": [ "TEST_CAT1" ]
}
]
54 changes: 54 additions & 0 deletions tests/martial_art_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
#include "mtype.h"
#include "npc.h"

static const bodypart_str_id body_part_debug_tail( "debug_tail" );
static const efftype_id effect_downed( "downed" );
static const efftype_id effect_grabbed( "grabbed" );
static const efftype_id effect_grabbing( "grabbing" );
static const efftype_id effect_stunned( "stunned" );

static const enchantment_id enchantment_ENCH_TEST_BIRD_PARTS( "ENCH_TEST_BIRD_PARTS" );

static const itype_id itype_club_wooden( "club_wooden" );
static const itype_id itype_sword_crude( "sword_crude" );
static const itype_id itype_test_weapon1( "test_weapon1" );
Expand All @@ -24,11 +27,15 @@ static const matec_id test_tech_condition_knockback( "test_tech_condition_knockb
static const matec_id test_tech_condition_stun( "test_tech_condition_stun" );
static const matec_id test_tech_condition_sweep( "test_tech_condition_sweep" );
static const matec_id test_technique( "test_technique" );
static const matec_id test_vector_tech_1( "test_vector_tech_1" );
static const matec_id test_vector_tech_2( "test_vector_tech_2" );
static const matype_id test_style_ma1( "test_style_ma1" );

static const species_id species_SLIME( "SLIME" );
static const species_id species_ZOMBIE( "ZOMBIE" );

static const trait_id trait_DEBUG_TAIL( "DEBUG_TAIL" );

static constexpr tripoint dude_pos( HALF_MAPSIZE_X, HALF_MAPSIZE_Y, 0 );

TEST_CASE( "martial_arts", "[martial_arts]" )
Expand Down Expand Up @@ -80,6 +87,53 @@ TEST_CASE( "Martial_art_required_weapon_categories", "[martial_arts]" )
}
}

TEST_CASE( "Attack_vector_test", "[martial_arts][limb]" )
{
clear_map();
standard_npc dude( "TestCharacter", dude_pos, {}, 0, 8, 8, 8, 8 );
clear_character( dude );
dude.martial_arts_data->add_martialart( test_style_ma1 );
dude.martial_arts_data->set_style( test_style_ma1, false );
monster &target_1 = spawn_test_monster( "mon_zombie_fat", dude_pos + tripoint_east );
SECTION( "Limb requirements" ) {
const matec_id &tec = *test_style_ma1->techniques.find( test_vector_tech_1 );
REQUIRE( dude.get_all_body_parts_of_type( body_part_type::type::tail ).empty() );
// Can't trigger the tech without a tail
CHECK( !dude.evaluate_technique( tec, target_1, dude.used_weapon(), false, false,
false ) );
// Grow a tail, suddenly we can use it
dude.toggle_trait( trait_DEBUG_TAIL );
REQUIRE( !dude.get_all_body_parts_of_type( body_part_type::type::tail ).empty() );
CHECK( dude.evaluate_technique( tec, target_1, dude.used_weapon(), false, false,
false ) );
// Unless our tail breaks
REQUIRE( body_part_debug_tail->health_limit == 5 );
dude.set_part_hp_cur( body_part_debug_tail, 1 );
CHECK( !dude.evaluate_technique( tec, target_1, dude.used_weapon(), false, false,
false ) );
dude.set_part_hp_cur( body_part_debug_tail, 20 );
CHECK( dude.evaluate_technique( tec, target_1, dude.used_weapon(), false, false,
false ) );
// Lose our vector limb
dude.enchantment_cache->force_add( *enchantment_ENCH_TEST_BIRD_PARTS, dude );
dude.recalculate_bodyparts();
REQUIRE( !dude.has_part( body_part_hand_l ) );
CHECK( !dude.evaluate_technique( tec, target_1, dude.used_weapon(), false, false,
false ) );
}
SECTION( "Limb substitution" ) {
const matec_id &tec2 = *test_style_ma1->techniques.find( test_vector_tech_2 );
// Succeed before changing
CHECK( dude.evaluate_technique( tec2, target_1, dude.used_weapon(), false, false,
false ) );
// Beak substitution lets us succeed afterwards
dude.enchantment_cache->force_add( *enchantment_ENCH_TEST_BIRD_PARTS, dude );
dude.recalculate_bodyparts();
CHECK( dude.evaluate_technique( tec2, target_1, dude.used_weapon(), false, false,
false ) );
}
}

TEST_CASE( "Martial_art_technique_conditionals", "[martial_arts]" )
{
clear_map();
Expand Down

0 comments on commit a424102

Please sign in to comment.