CleverRaven / Cataclysm-DDA

Cataclysm - Dark Days Ahead. A turn-based survival game set in a post-apocalyptic world.
http://cataclysmdda.org
Other
10.72k stars 4.21k forks source link

Two `effect_type` with the same `id` are not detected #78226

Open RedMisao opened 5 days ago

RedMisao commented 5 days ago

Describe the bug

Title. In other words, two effects with the same ID aren't detected by the game. In other words, it doesn't prevent loading, like it happens for other JSON types with the same ID.

Attach save file

N/A, this should cause an error and it is not, so it's undetectable unless you're looking for it in the repo

Steps to reproduce

Either load this as a mod, or copy and paste the two effects somewhere in data\json\effects.json

[
  {
    "type": "MOD_INFO",
    "id": "TEST_MOD",
    "name": "TEST MOD",
    "authors": [ "TEST MOD" ],
    "description": "TEST MOD.",
    "category": "AAA",
    "dependencies": [ "dda" ]
  },
  {
    "id": "effect_1",
    "type": "effect_type",
    "name": [ "" ],
    "desc": [ "" ],
    "max_intensity": 1,
    "max_effective_intensity": 1
  },
  {
    "id": "effect_1",
    "type": "effect_type",
    "name": [ "" ],
    "desc": [ "" ],
    "max_intensity": 1,
    "max_effective_intensity": 1
  }
]

Expected behavior

I expected the game not loading, with the usual: "Error: id (struct type) has two definitions from the same source (mod)!"

Screenshots

N/A, the game seems to not detect it.

Versions and configuration

Additional context

Adding names and descriptions makes no difference.

Could be related to #51456, seems effect_type are handled different from other objects?

ZhilkinSerg commented 5 days ago

There are two duplicates so far:

Search "    "id": "(took_antihistamine|star_vampire_blood_drink)"" (4 hits in 2 files of 5449 searched) [RegEx]
  C:\Projects\Cataclysm-DDA\data\json\effects.json (3 hits)
    Line 3384:     "id": "took_antihistamine",
    Line 4979:     "id": "star_vampire_blood_drink",
    Line 4996:     "id": "star_vampire_blood_drink",
  C:\Projects\Cataclysm-DDA\data\json\obsoletion_and_migration_0.I\obsolete_effect.json (1 hit)
    Line  72:     "id": "took_antihistamine",
ZhilkinSerg commented 5 days ago

We can at least report duplicates to the debug.log:

diff --git a/src/effect.cpp b/src/effect.cpp
index 8c8d7eba02..1686ba70ee 100644
--- a/src/effect.cpp
+++ b/src/effect.cpp
@@ -1510,6 +1510,9 @@ void load_effect_type( const JsonObject &jo, const std::string_view src )
 {
     effect_type new_etype;
     new_etype.id = efftype_id( jo.get_string( "id" ) );
+    if( effect_types.find( new_etype.id ) != effect_types.end() ) {
+        DebugLog( D_WARNING, DC_ALL ) << "Error duplicate effect id found:" << new_etype.id.str();
+    }

     if( jo.has_member( "name" ) ) {
         for( const JsonValue entry : jo.get_array( "name" ) ) {