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

feat: JSONize some trap features #3941

Merged
merged 6 commits into from
Dec 24, 2023

Conversation

chaosvolt
Copy link
Member

@chaosvolt chaosvolt commented Dec 18, 2023

Purpose of change

The continues the work started with #3939 to improve trap-related code and add some more eventually. WIP for now.

Describe the solution

C++ changes:

  1. In trap.cpp and trap.h, defined support for trigger_items JSON in trap::load. Uses the same format as drops, instead being items that spawn when the trap is triggered (as opposed to disarmed like drops).
  2. Also in trap.cpp and trap.h, defined function trap::trigger_aftermath. This is used to provide final cleanup for traps, in particular dropping any items on trigger defined in the trap JSON's trigger_items section.
  3. In trapfunc.cpp, converted all trap functions that return true to use trigger_aftermath in them, and removed most hardcoded instances of spawning items or calling remove_trap in them. The random chance of dropping ammo in trapfunc::crossbow, and chance of spears breaking in trapfunc::pit_spikes and trapfunc::pit_glass were also kept special-cased in the function since not yet added to trigger_items. Meanwhile, trapfunc::beartrap, trapfunc::snare_light, and trapfunc::snare_heavy still use the whole "trap is removed early and item is only spawned when the victim is freed" thing, but they still have support for trap cleanup effects if desired.
  4. Per feedback, set it so that double-barrel shotgun traps always unload both barrels instead of picking how many to fire at random based on size/strength. In exchange, it's now done as two separate damage instances, so armor gets applies for both shots.
  5. Added support for the remove_on_trigger bool. If present in a trap's JSON, it will remove the trap when trigger_aftermath applies, so whether any given trap effect is single-use or reusable is fully JSONized (barring stuff like pits turning into other pits, sinkholes converting into pits, and other interactions with trap-conversion or terrain alteration).
  6. Per feedback from Kheir, changed trapfunc::sinkhole so that successfully grappling out of it returns without converting the trap into a pit or other standard cleanup, so that it doesn't spawn a pit in a different tile without leaving the sinkhole still intact.
  7. Modernized damage of shotgun trap based on the base damage of slugs as the minimum, and base damage of buckshot as the maximum. Rigged it to use zero arpen like buckshot but 1.5x damage multiplier like slugs. Also separates the two hits of damage instance instead of pooling it together in one big hit.
  8. Modernized damage of crossbow trap to use stab damage, and use values closer to the base damage of the crossbow with intended bolts.

JSON changes:

  1. In traps.json, converted all the vanilla drops that used to drop hardcoded items when triggered to use trigger_items, with comments pointing out any case where something is still hardcoded in.
  2. In addition, set it so that can alarm traps drop themselves when activated instead of vanishing entirely.
  3. Updated names of shotgun traps to make them easier to tell apart.
  4. Added use of remove_on_trigger to all relevant traps.
  5. Set it so that glass caltrops drop 3 of the component glass shards when triggered.
  6. . Fixed recipe for crossbow trap using 4 times as many bolts if you pick wooden ones.
  7. Added item and recipe definition for a single-barrel variant of the shotgun trap, updating weights and volumes to be closer to the guns they use.
  8. Bumped recipe for double-barrel shotgun trap up a level to level 4, on the basis of it taking a bit more effort to rig it to pull both triggers. Also shifts things so there's a more even spread of trapping options across levels.
  9. Obsoleted half-empty double-barrel trap.

Describe alternatives you've considered

  1. Letting crossbow traps drop their bolts 100% of the time and adding it to trigger_items, on the basis that it already does this 90% of the time anyway.
  2. Renaming drops to disarm_items for clarity?

Testing

  1. Checked affected JSON files for syntax and lint errors.
  2. Compiled and load-tested.
  3. Got some zeds to blunder into crossbow, single shotty, and can alarm traps, expected items drop as a result.
  4. Got a zed to wander into a double-barrel shotgun trap, as expected the trap sometimes drops a double shotty and tripwire, sometimes converts to a partially-depleted shotgun trap instead, and when that's triggered it drops as expected.

Additional context

Support for pipe shotgun traps to be added eventually.

Checklist

@github-actions github-actions bot added the src changes related to source code. label Dec 18, 2023
@scarf005 scarf005 changed the title feat: JSONize some trap features [CR] feat: JSONize some trap features Dec 18, 2023
@scarf005 scarf005 self-assigned this Dec 18, 2023
@github-actions github-actions bot added the JSON related to game datas in JSON format. label Dec 18, 2023
@chaosvolt
Copy link
Member Author

chaosvolt commented Dec 18, 2023

Discovery of the day: successfully evading a sinkhole via a grappling hook or the like spawns a pit at your NEW location, not the old one, and leaves the sinkhole intact. Confirmed in build 2023-12-12-0039 that it's not my code changes doin it.
image

Copy link
Contributor

autofix-ci bot commented Dec 19, 2023

The Autofix app has automatically formatted this Pull Request.

If you edit your PR on web UI, you can ignore this message.
If you edit your PR locally, YOU MUST DO EITHER OF THE FOLLOWING:

  • Run git pull to merge the automated commit into your local copy of the PR branch.
  • Format your code locally, and force push to your PR branch.

If you don't do this, your following work will be based on the old commit, and cause MERGE CONFLICT.

Copy link
Member

@scarf005 scarf005 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but could we document the JSON changes?

@chaosvolt
Copy link
Member Author

Oh yeah I knew I was forgetting something. Do we even have documentation for trap data...?

Copy link
Member

@scarf005 scarf005 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, if the JSON docs for traps are missing then it'd be better as a separate PR.

@scarf005 scarf005 merged commit 2b03784 into cataclysmbnteam:main Dec 24, 2023
13 of 17 checks passed
@chaosvolt chaosvolt deleted the trap-updates-part-2 branch December 24, 2023 04:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
JSON related to game datas in JSON format. src changes related to source code.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants