Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trap trigger_weight json filed is ignored #41538

Closed
hexagonrecursion opened this issue Jun 23, 2020 · 1 comment · Fixed by #46872
Closed

Trap trigger_weight json filed is ignored #41538

hexagonrecursion opened this issue Jun 23, 2020 · 1 comment · Fixed by #46872
Labels
<Bug> This needs to be fixed [C++] Changes (can be) made in C++. Previously named `Code` Fields / Furniture / Terrain / Traps Objects that are part of the map or its features. [JSON] Changes (can be) made in JSON

Comments

@hexagonrecursion
Copy link
Contributor

hexagonrecursion commented Jun 23, 2020

Describe the bug

While working on #36110 I noticed a strange phenomenon: even though json sets the trigger weight of all traps as 200 grams (see below), the experiments show that the smallest weight that actually triggers a trap is >500 grams.

"id": "tr_beartrap",
"trigger_weight": 200,

After some code spelunking I discovered the cause:

if( effects.count( "HEAVY_HIT" ) ) {
if( here.has_flag( flag_LIQUID, pt ) ) {
sounds::sound( pt, 10, sounds::sound_t::combat, _( "splash!" ), false, "bullet_hit", "hit_water" );
} else {
sounds::sound( pt, 8, sounds::sound_t::combat, _( "thud." ), false, "bullet_hit", "hit_wall" );
}
const trap &tr = here.tr_at( pt );
if( tr.triggered_by_item( dropped_item ) ) {
tr.trigger( pt, nullptr, &dropped_item );
}
}

Cataclysm-DDA/src/ranged.cpp

Lines 1015 to 1017 in c2b5b38

if( weight > 500_gram ) {
proj_effects.insert( "HEAVY_HIT" );
}

Steps To Reproduce

  1. Set up a bear trap
  2. Throw a canvas bag with 165 papers at it ~ 0.5 kg
  3. Note that it did not trigger
  4. Throw a canvas bag with 166 papers at it ~ 0.5 kg
  5. Now it triggers

Expected behavior

Either the game should respect the trigger_weight json field, or this filed should be removed as dead code (every trap that lists trigger_weight sets it to 200 grams).

Screenshots

none

Versions and configuration

  • OS: Linux
    • OS Version: LSB Version: :core-4.1-amd64:core-4.1-noarch; Distributor ID: Fedora; Description: Fedora release 32 (Thirty Two); Release: 32; Codename: ThirtyTwo;
  • Game Version: 0.E-3470-ga87254b [64-bit]
  • Graphics Version: Tiles
  • Game Language: System language []
  • Mods loaded: [
    Dark Days Ahead [dda],
    Disable NPC Needs [no_npc_food]
    ]

Additional context

Does the code have to be this complicated? So many knobs and dials. So much indirection. This is much simpler (pseudocode)

if item.weight() > gram(500):
    trap.trigger()
@hexagonrecursion
Copy link
Contributor Author

hexagonrecursion commented Jun 24, 2020

To clarify my last point:

  1. Fact: drop_or_embed_projectile wants to check whether the thrown item is heavier than a certain threshold, but instead of doing the comparison directly it relies on a different function in a different file to have performed the comparison and have set a flag.
  2. Opinion: I consider this a form of indirection. Moreover: I consider this indirection to be premature.
  3. As far as I can tell the trigger_weight of a trap only affects whether a thrown item can trigger it. It has no effect on whether a monster or the player can trigger it.
  4. Fact: trigger_weight of traps was jsonized
  5. As far as I can tell all traps have the same trigger_weight: 200g
  6. Opinion: I consider jsonization to also be a form of indirection. And also premature in this case.
  7. Fact: this is a very roundabout way of implementing a simple behavior: a thrown item triggers the trap if it is heavier than 500g.
  8. Opinion: This bug went unnoticed for years. I consider this to be evidence that for gameplay purposes this simple behavior is just fine.

@anothersimulacrum anothersimulacrum added [C++] Changes (can be) made in C++. Previously named `Code` [JSON] Changes (can be) made in JSON Fields / Furniture / Terrain / Traps Objects that are part of the map or its features. <Bug> This needs to be fixed labels Jun 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
<Bug> This needs to be fixed [C++] Changes (can be) made in C++. Previously named `Code` Fields / Furniture / Terrain / Traps Objects that are part of the map or its features. [JSON] Changes (can be) made in JSON
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants