Skip to content

Commit

Permalink
Enforce mon_ prefix for monster id (#72734)
Browse files Browse the repository at this point in the history
* Test for mon_ prefix

* Replace LIXA_ with mon_

* deal with pseudo monsters

* Check for prefix in vanilla monster during data load

* better cpp

* fix hardcoded ids

---------

Co-authored-by: Fris0uman <[email protected]>
  • Loading branch information
Fris0uman and Fris0uman authored Apr 9, 2024
1 parent 7e7089f commit 5fa102a
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1332,9 +1332,9 @@
{ "compare_string": [ "mon_archunk_strong", { "context_val": "victim_type" } ] },
{ "compare_string": [ "mon_void_spider", { "context_val": "victim_type" } ] },
{ "compare_string": [ "mon_XEDRA_officer", { "context_val": "victim_type" } ] },
{ "compare_string": [ "LIXA_eigenspectre_3", { "context_val": "victim_type" } ] },
{ "compare_string": [ "LIXA_eigenspectre_4", { "context_val": "victim_type" } ] },
{ "compare_string": [ "LIXA_living_vector", { "context_val": "victim_type" } ] }
{ "compare_string": [ "mon_eigenspectre_3", { "context_val": "victim_type" } ] },
{ "compare_string": [ "mon_eigenspectre_4", { "context_val": "victim_type" } ] },
{ "compare_string": [ "mon_living_vector", { "context_val": "victim_type" } ] }
]
}
]
Expand Down
34 changes: 17 additions & 17 deletions data/json/mapgen/LIXA_mapgen.json
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,7 @@
{ "point": "trap", "id": "tr_LIXA_back_16", "x": 21, "y": 0 }
],
"palettes": [ "LIXA_unfolded_palette" ],
"place_monster": [ { "monster": "LIXA_eigenspectre_1", "x": [ 8, 21 ], "y": [ 2, 21 ], "repeat": 2 } ]
"place_monster": [ { "monster": "mon_eigenspectre_1", "x": [ 8, 21 ], "y": [ 2, 21 ], "repeat": 2 } ]
}
},
{
Expand Down Expand Up @@ -1160,7 +1160,7 @@
{ "point": "trap", "id": "tr_LIXA_forward_16", "x": 21, "y": 23 }
],
"palettes": [ "LIXA_unfolded_palette" ],
"place_monster": [ { "monster": "LIXA_eigenspectre_1", "x": [ 8, 21 ], "y": [ 2, 21 ], "pack_size": 1, "repeat": 1 } ]
"place_monster": [ { "monster": "mon_eigenspectre_1", "x": [ 8, 21 ], "y": [ 2, 21 ], "pack_size": 1, "repeat": 1 } ]
}
},
{
Expand Down Expand Up @@ -1231,7 +1231,7 @@
],
"palettes": [ "LIXA_unfolded_palette" ],
"terrain": { "2": [ "t_LIXA_unfolded_tube", "t_LIXA_unfolded_tube_broken" ] },
"place_monster": [ { "monster": "LIXA_eigenspectre_1", "x": [ 8, 21 ], "y": [ 2, 21 ], "pack_size": 1, "repeat": 1 } ]
"place_monster": [ { "monster": "mon_eigenspectre_1", "x": [ 8, 21 ], "y": [ 2, 21 ], "pack_size": 1, "repeat": 1 } ]
}
},
{
Expand Down Expand Up @@ -1301,8 +1301,8 @@
{ "point": "trap", "id": "tr_LIXA_forward_16", "x": 21, "y": 23 }
],
"place_monster": [
{ "monster": "LIXA_eigenspectre_1", "x": [ 8, 21 ], "y": [ 2, 21 ], "pack_size": 1 },
{ "monster": "LIXA_eigenspectre_2", "x": [ 8, 21 ], "y": [ 2, 21 ], "pack_size": 1 }
{ "monster": "mon_eigenspectre_1", "x": [ 8, 21 ], "y": [ 2, 21 ], "pack_size": 1 },
{ "monster": "mon_eigenspectre_2", "x": [ 8, 21 ], "y": [ 2, 21 ], "pack_size": 1 }
],
"palettes": [ "LIXA_unfolded_palette" ],
"terrain": { "2": [ "t_LIXA_unfolded_tube", "t_LIXA_unfolded_tube_broken" ] }
Expand Down Expand Up @@ -1375,8 +1375,8 @@
{ "point": "trap", "id": "tr_LIXA_back_16", "x": 21, "y": 0 }
],
"place_monster": [
{ "monster": "LIXA_eigenspectre_1", "x": [ 8, 21 ], "y": [ 2, 21 ], "pack_size": 1 },
{ "monster": "LIXA_eigenspectre_2", "x": [ 8, 21 ], "y": [ 2, 21 ], "pack_size": 1 }
{ "monster": "mon_eigenspectre_1", "x": [ 8, 21 ], "y": [ 2, 21 ], "pack_size": 1 },
{ "monster": "mon_eigenspectre_2", "x": [ 8, 21 ], "y": [ 2, 21 ], "pack_size": 1 }
],
"palettes": [ "LIXA_unfolded_palette" ],
"terrain": {
Expand Down Expand Up @@ -1453,8 +1453,8 @@
],
"palettes": [ "LIXA_unfolded_palette" ],
"place_monster": [
{ "monster": "LIXA_eigenspectre_3", "x": [ 8, 21 ], "y": [ 7, 18 ], "pack_size": 1 },
{ "monster": "LIXA_eigenspectre_1", "x": [ 8, 21 ], "y": [ 7, 18 ], "pack_size": 1 }
{ "monster": "mon_eigenspectre_3", "x": [ 8, 21 ], "y": [ 7, 18 ], "pack_size": 1 },
{ "monster": "mon_eigenspectre_1", "x": [ 8, 21 ], "y": [ 7, 18 ], "pack_size": 1 }
],
"terrain": {
"2": [ "t_LIXA_unfolded_tube", "t_LIXA_unfolded_tube_broken" ],
Expand Down Expand Up @@ -1529,8 +1529,8 @@
{ "point": "trap", "id": "tr_LIXA_back_16", "x": 21, "y": 0 }
],
"place_monster": [
{ "monster": "LIXA_eigenspectre_1", "x": [ 8, 21 ], "y": [ 2, 21 ], "pack_size": 1 },
{ "monster": "LIXA_eigenspectre_3", "x": [ 8, 21 ], "y": [ 2, 21 ], "pack_size": 1 }
{ "monster": "mon_eigenspectre_1", "x": [ 8, 21 ], "y": [ 2, 21 ], "pack_size": 1 },
{ "monster": "mon_eigenspectre_3", "x": [ 8, 21 ], "y": [ 2, 21 ], "pack_size": 1 }
],
"palettes": [ "LIXA_unfolded_palette" ],
"terrain": {
Expand Down Expand Up @@ -1606,8 +1606,8 @@
{ "point": "trap", "id": "tr_LIXA_forward_16", "x": 21, "y": 23 }
],
"place_monster": [
{ "monster": "LIXA_eigenspectre_2", "x": [ 8, 21 ], "y": [ 2, 21 ], "pack_size": 1 },
{ "monster": "LIXA_eigenspectre_4", "x": [ 8, 21 ], "y": [ 2, 21 ], "pack_size": 1 }
{ "monster": "mon_eigenspectre_2", "x": [ 8, 21 ], "y": [ 2, 21 ], "pack_size": 1 },
{ "monster": "mon_eigenspectre_4", "x": [ 8, 21 ], "y": [ 2, 21 ], "pack_size": 1 }
],
"palettes": [ "LIXA_unfolded_palette" ],
"terrain": {
Expand Down Expand Up @@ -1757,10 +1757,10 @@
],
"palettes": [ "LIXA_unfolded_palette" ],
"place_monster": [
{ "monster": "LIXA_eigenspectre_2", "x": [ 7, 18 ], "y": [ 2, 21 ], "pack_size": 1, "repeat": 1 },
{ "monster": "LIXA_eigenspectre_3", "x": [ 7, 18 ], "y": [ 2, 21 ], "pack_size": 1 },
{ "monster": "LIXA_eigenspectre_4", "x": [ 7, 18 ], "y": [ 2, 21 ], "pack_size": 1 },
{ "monster": "LIXA_living_vector", "x": [ 7, 18 ], "y": [ 2, 21 ], "pack_size": 1 }
{ "monster": "mon_eigenspectre_2", "x": [ 7, 18 ], "y": [ 2, 21 ], "pack_size": 1, "repeat": 1 },
{ "monster": "mon_eigenspectre_3", "x": [ 7, 18 ], "y": [ 2, 21 ], "pack_size": 1 },
{ "monster": "mon_eigenspectre_4", "x": [ 7, 18 ], "y": [ 2, 21 ], "pack_size": 1 },
{ "monster": "mon_living_vector", "x": [ 7, 18 ], "y": [ 2, 21 ], "pack_size": 1 }
],
"terrain": {
"2": [ "t_LIXA_unfolded_tube", "t_LIXA_unfolded_tube_broken" ],
Expand Down
6 changes: 3 additions & 3 deletions data/json/mapgen/debug_ramps.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
"terrain": { "#": "t_rock", ".": "t_grass", "<": "t_low_stairs_begin", "E": "t_low_stairs_end", "H": "t_grass", "~": "t_water_dp" },
"furniture": { "H": "f_ladder" },
"place_monster": [
{ "monster": "debug_mon", "x": 1, "y": 1 },
{ "monster": "debug_mon", "x": 3, "y": 1 },
{ "monster": "debug_mon", "x": 5, "y": 1 }
{ "monster": "pseudo_debug_mon", "x": 1, "y": 1 },
{ "monster": "pseudo_debug_mon", "x": 3, "y": 1 },
{ "monster": "pseudo_debug_mon", "x": 5, "y": 1 }
]
}
}
Expand Down
14 changes: 7 additions & 7 deletions data/json/monsters/LIXA_monsters.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"base_casting_time": 100,
"shape": "blast",
"effect": "summon",
"effect_str": "LIXA_eigenspectre_3_echo"
"effect_str": "mon_eigenspectre_3_echo"
},
{
"id": "LIXA_vector_volley",
Expand Down Expand Up @@ -129,7 +129,7 @@
"effect_str": "EOC_LIXA_unfold_return"
},
{
"id": "LIXA_eigenspectre_1",
"id": "mon_eigenspectre_1",
"type": "MONSTER",
"name": { "str": "eigenspectre" },
"description": "This is the opposite of a human silhouette; every facet of every detail on display, with no shape to make sense of them. You can see both sides of an ID badge on a white labcoat. You can see every muscle and nerve in eyes blown wide with horror.",
Expand Down Expand Up @@ -159,7 +159,7 @@
"armor": { "electric": 1 }
},
{
"id": "LIXA_eigenspectre_2",
"id": "mon_eigenspectre_2",
"type": "MONSTER",
"name": { "str": "photonic eigenspectre" },
"description": "The endless details of this figure are mercifully obscured by the viscous light coursing 'through' it. It cannot contain anything, but the smears of light follow the shapes of stomach and intestines, and are splattered across what must be the lips and chin.",
Expand Down Expand Up @@ -214,7 +214,7 @@
"armor": { "electric": 1 }
},
{
"id": "LIXA_eigenspectre_3",
"id": "mon_eigenspectre_3",
"type": "MONSTER",
"name": { "str": "shifting eigenspectre" },
"description": "This distorted figure is a kaleidescope of borders. Every part of a human, flattened into place, warps wildly from second to second. The word your mind conjures to describe it is 'rotating', though you're not sure why.",
Expand Down Expand Up @@ -252,7 +252,7 @@
"armor": { "electric": 1 }
},
{
"id": "LIXA_eigenspectre_3_echo",
"id": "mon_eigenspectre_3_echo",
"type": "MONSTER",
"name": { "str": "shifting eigenspectre" },
"description": "This distorted figure is a kaleidescope of borders. Every part of a human, flattened into place, warps wildly from second to second. The word your mind conjures to describe it is 'rotating', though you're not sure why.",
Expand Down Expand Up @@ -291,7 +291,7 @@
"armor": { "electric": 1 }
},
{
"id": "LIXA_eigenspectre_4",
"id": "mon_eigenspectre_4",
"type": "MONSTER",
"name": { "str": "titanic eigenspectre" },
"description": "There is somehow more of this figure than the others. Every side of every surface is on display, but each of those seems like the thin edge of a larger shape. There is an eternity here, where a scientist used to be.",
Expand Down Expand Up @@ -326,7 +326,7 @@
"armor": { "electric": 1 }
},
{
"id": "LIXA_living_vector",
"id": "mon_living_vector",
"type": "MONSTER",
"name": { "str": "unfolded impossibility", "str_pl": "unfolded impossibilities" },
"description": "This is the entirety of the infinite chamber you are in, which perfectly contains itself. If you look very closely, you might see yourself looking back. You are sure that at any other time, seeing this would crack your brain like an eggshell. But you understand it just fine right now. And you can see it breathing.",
Expand Down
4 changes: 2 additions & 2 deletions data/json/monsters/misc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"id": "debug_mon",
"id": "pseudo_debug_mon",
"type": "MONSTER",
"name": { "str": "debug monster" },
"description": "This monster exists only for testing purposes.",
Expand Down Expand Up @@ -136,7 +136,7 @@
]
},
{
"id": "weakpoint_mon",
"id": "pseudo_weakpoint_mon",
"type": "MONSTER",
"name": { "str": "weakpoint monster" },
"description": "This monster exists only for weakpoint testing purposes.",
Expand Down
2 changes: 1 addition & 1 deletion data/mods/Magiclysm/Spells/debug.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
"valid_targets": [ "ground" ],
"effect": "summon",
"shape": "blast",
"effect_str": "debug_mon",
"effect_str": "pseudo_debug_mon",
"base_casting_time": 100,
"max_level": 30,
"min_aoe": 10,
Expand Down
4 changes: 2 additions & 2 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,11 @@ static const material_id material_wool( "wool" );

static const morale_type morale_null( "morale_null" );

static const mtype_id debug_mon( "debug_mon" );
static const mtype_id mon_human( "mon_human" );
static const mtype_id mon_zombie_smoker( "mon_zombie_smoker" );
static const mtype_id mon_zombie_soldier( "mon_zombie_soldier" );
static const mtype_id mon_zombie_survivor( "mon_zombie_survivor" );
static const mtype_id pseudo_debug_mon( "pseudo_debug_mon" );

static const quality_id qual_BOIL( "BOIL" );
static const quality_id qual_JACK( "JACK" );
Expand Down Expand Up @@ -2347,7 +2347,7 @@ struct dps_comp_data {
};

static const std::vector<std::pair<translation, dps_comp_data>> dps_comp_monsters = {
{ to_translation( "Best" ), { debug_mon, true, false } },
{ to_translation( "Best" ), { pseudo_debug_mon, true, false } },
{ to_translation( "Vs. Agile" ), { mon_zombie_smoker, true, true } },
{ to_translation( "Vs. Armored" ), { mon_zombie_soldier, true, true } },
{ to_translation( "Vs. Mixed" ), { mon_zombie_survivor, false, true } },
Expand Down
7 changes: 7 additions & 0 deletions src/monstergenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1605,6 +1605,13 @@ void mtype::remove_regeneration_modifiers( const JsonObject &jo, const std::stri
void MonsterGenerator::check_monster_definitions() const
{
for( const mtype &mon : mon_templates->get_all() ) {
if( !mon.src.empty() && mon.src.back().second.str() == "dda" ) {
std::string mon_id = mon.id.str();
std::string suffix_id = mon_id.substr( 0, mon_id.find( '_' ) );
if( suffix_id != "mon" && suffix_id != "pseudo" ) {
debugmsg( "monster %s is missing mon_ (or pseudo_) prefix from id", mon.id.c_str() );
}
}
if( mon.harvest.is_null() && !mon.has_flag( mon_flag_ELECTRONIC ) && !mon.id.is_null() ) {
debugmsg( "monster %s has no harvest entry", mon.id.c_str(), mon.harvest.c_str() );
}
Expand Down
4 changes: 2 additions & 2 deletions tests/effect_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static const efftype_id effect_test_fatalism( "test_fatalism" );
static const efftype_id effect_test_int_remove( "test_int_remove" );
static const efftype_id effect_test_vitamineff( "test_vitamineff" );

static const mtype_id debug_mon( "debug_mon" );
static const mtype_id pseudo_debug_mon( "pseudo_debug_mon" );

static const vitamin_id vitamin_test_vitv( "test_vitv" );
static const vitamin_id vitamin_test_vitx( "test_vitx" );
Expand Down Expand Up @@ -736,7 +736,7 @@ static void test_deadliness( const effect &applied, const int expected_dead, con
for( int j = 0; j < 10; ++j ) {
tripoint cursor( i + 20, j + 20, 0 );

mons.push_back( g->place_critter_at( debug_mon, cursor ) );
mons.push_back( g->place_critter_at( pseudo_debug_mon, cursor ) );
// make sure they're there!
CHECK( creatures.creature_at<Creature>( cursor ) != nullptr );
}
Expand Down
6 changes: 3 additions & 3 deletions tests/effective_dps_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
#include "test_data.h"
#include "type_id.h"

static const mtype_id debug_mon( "debug_mon" );
static const mtype_id mon_zombie_smoker( "mon_zombie_smoker" );
static const mtype_id mon_zombie_soldier_no_weakpoints( "mon_zombie_soldier_no_weakpoints" );
static const mtype_id mon_zombie_survivor_no_weakpoints( "mon_zombie_survivor_no_weakpoints" );
static const mtype_id pseudo_debug_mon( "pseudo_debug_mon" );

static const skill_id skill_bashing( "bashing" );
static const skill_id skill_cutting( "cutting" );
Expand Down Expand Up @@ -121,7 +121,7 @@ TEST_CASE( "effective_damage_per_second", "[effective][dps]" )
item good_sword( "test_balanced_sword" );

SECTION( "against a debug monster with no armor or dodge" ) {
monster mummy( debug_mon );
monster mummy( pseudo_debug_mon );

CHECK( clumsy_sword.effective_dps( dummy, mummy ) == Approx( 25.0f ).epsilon( 0.15f ) );
CHECK( good_sword.effective_dps( dummy, mummy ) == Approx( 38.0f ).epsilon( 0.15f ) );
Expand All @@ -143,7 +143,7 @@ TEST_CASE( "effective_damage_per_second", "[effective][dps]" )
}

SECTION( "effect of STR and DEX on damage per second" ) {
monster mummy( debug_mon );
monster mummy( pseudo_debug_mon );

SECTION( "STR 6, DEX 6" ) {
dummy.str_max = 6;
Expand Down
4 changes: 2 additions & 2 deletions tests/melee_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ static const efftype_id effect_sleep( "sleep" );

static const move_mode_id move_mode_prone( "prone" );

static const mtype_id debug_mon( "debug_mon" );
static const mtype_id mon_manhack( "mon_manhack" );
static const mtype_id mon_zombie( "mon_zombie" );
static const mtype_id mon_zombie_hulk( "mon_zombie_hulk" );
static const mtype_id pseudo_debug_mon( "pseudo_debug_mon" );

static const skill_id skill_melee( "melee" );

Expand Down Expand Up @@ -290,7 +290,7 @@ TEST_CASE( "Incapacited_character_can_not_dodge" )
TEST_CASE( "Melee_skill_training_caps", "[melee], [melee_training_cap], [skill]" )
{
standard_npc dude( "TestCharacter", dude_pos, {} );
monster dummy_1( debug_mon );
monster dummy_1( pseudo_debug_mon );
monster zed( mon_zombie );
SkillLevel &level = dude.get_skill_level_object( skill_melee );
REQUIRE( level.knowledgeLevel() == 4 );
Expand Down
13 changes: 13 additions & 0 deletions tests/monster_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,19 @@ static void monster_check()
CHECK( can_catch_player( "mon_zombie_dog", tripoint_south_east ) > 0 );
}

TEST_CASE( "check_mon_id" )
{
for( const mtype &mon : MonsterGenerator::generator().get_all_mtypes() ) {
if( !mon.src.empty() && mon.src.back().second.str() != "dda" ) {
continue;
}
std::string mon_id = mon.id.str();
std::string suffix_id = mon_id.substr( 0, mon_id.find( '_' ) );
INFO( "Now checking the id of " << mon.id.str() );
CHECK( ( suffix_id == "mon" || suffix_id == "pseudo" ) );
}
}

// Write out a map of slope at which monster is moving to time required to reach their destination.
TEST_CASE( "write_slope_to_speed_map_trig", "[.]" )
{
Expand Down
4 changes: 2 additions & 2 deletions tests/vehicle_ramp_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "vpart_position.h"
#include "vpart_range.h"

static const mtype_id debug_mon( "debug_mon" );
static const mtype_id pseudo_debug_mon( "pseudo_debug_mon" );

static void clear_game_and_set_ramp( const int transit_x, bool use_ramp, bool up )
{
Expand Down Expand Up @@ -292,7 +292,7 @@ static void level_out( const vproto_id &veh_id, const bool drop_pos )
CAPTURE( existing_creature->is_monster() );
REQUIRE( !existing_creature );
}
monster *dmon_p = g->place_critter_at( debug_mon, map_starting_point );
monster *dmon_p = g->place_critter_at( pseudo_debug_mon, map_starting_point );
REQUIRE( dmon_p );
monster &dmon = *dmon_p;

Expand Down
Loading

0 comments on commit 5fa102a

Please sign in to comment.