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

fix: ally-only spells no longer autotarget enemies, fix crash when casting SWAP_POS on a tile with no creature to swap with #5338

Merged
merged 2 commits into from
Sep 10, 2024

Conversation

chaosvolt
Copy link
Member

Checklist

Required

Optional

Purpose of change

This fixes a couple long-running annoyances in spellcasting code I figured out solutions for. Also technically opens up unrestricted controlled teleportation as something spells can do without even needing a new spell function.

Fixes #4216

Describe the solution

C++ changes:

  1. In magic_spell_effect.cpp, changed swap_pos so that it only tries to move any creatures found in the epicenter if there actually is one. If the tile targeted is empty, now instead of the game just imploding like before, it simply warps you over there without any complaints, meaning you can freely use SWAP_POS spells on any tile you want if you write the spell's JSON to permit targeting the ground to just use it for teleportation if you so choose.
  2. In ranged.cpp, set target_ui::choose_initial_target so that spells don't try to autotarget any enemy in range unless they can ACTUALLY be used on hostiles, so you won't be prompted to try and waste your time casting a spell only usable on allies, and likewise making it less annoying trying to heal or buff yourself in the middle of a fight via whatever's kicking your ass trying to run off with your cursor.

Documentation changes:

  1. Updated the explaination of what SWAP_POS does in magic.md.

Describe alternatives you've considered

Adding a spell in Magiclysm that uses SWAP_POS as a full-on blink spell. Robbie and Fox said they have plans already so will leave it to them.

Testing

  1. Compiled and load-tested.
  2. Started up a world with Magiclysm in it as a novice stormshaper.
  3. Tested against both the starter NPC and a zombie, Lightning Bolt will highlight these targets automatically if in range but Windrunning no longer tries to target them.
  4. Tested giving myself Holographic Transposition after temporarily removing the monster restriction and letting me cast it at the ground.
  5. Cast this modified spell and I warp over to the selected tile without any crashes this time, even if the tile is empty.
  6. Zapped starter NPC with it to confirm it also still works fine to just swap with the target.
  7. Also tested temporarily giving Holographic Transposition damage while it was rigged to let me tag an NPC with it, doing so still lets me swap places with them, and simply teleports me on top of their corpse if the damage was lethal.
  8. Checked affected files for syntax and lint errors.

Casual bullying of an NPC with a version of Holographic Transposition temporarily given damage, and it working without issue when the victim dies from it:
image

Additional context

Checked in DDA, as of build 2024-08-30-1256 targeting an invalid tile with a SWAP_POS spell still crashes the game:
image

Even better, a basic attempt to test and confirm if you still auto-target non-allies with Windrunning revealed that the spell I selected on the spellcasting menu ends up not being the spell it tries to cast:
image
image

So I have to try and cast Shocking Lash instead, which ACTUALLY casts Windrunning, and only then can I confirm DDA auto-targets non-allies with ally-only spells.

…sting `SWAP_POS` on a tile with no creature to swap with
@github-actions github-actions bot added docs PRs releated to docs page src changes related to source code. labels Sep 10, 2024
Copy link
Contributor

autofix-ci bot commented Sep 10, 2024

Autofix has formatted code style violation in this PR.

I edit commits locally (e.g: git, github desktop) and want to keep autofix
  1. Run git pull. this will merge the automated commit into your local copy of the PR branch.
  2. Continue working.
I do not want the automated commit
  1. Format your code locally, then commit it.
  2. Run git push --force to force push your branch. This will overwrite the automated commit on remote with your local one.
  3. Continue working.

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

Copy link
Collaborator

@RoyalFox2140 RoyalFox2140 left a comment

Choose a reason for hiding this comment

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

Simple enough, I'm going to be testing it later.

@chaosvolt
Copy link
Member Author

One thing though: maybe I should also make it so SWAP_POS also doesn't teleport the user if the destination is impassible?

@RoyalFox2140
Copy link
Collaborator

I don't know about that. I think that's bad for a few reasons, assuming you can target an unknown area:

  1. You can use it to fish and see where walls are in an unknown area.
  2. You can't see where you should be able to stand in this case, so you'll have a lot of trial and error finding a spot to teleport to.

@chaosvolt
Copy link
Member Author

That's what I mean, I'm asking if I should make it also check whether you're going to get yourself stuck in a wall and if so don't move the caster.

@RoyalFox2140
Copy link
Collaborator

That's what I mean, I'm asking if I should make it also check whether you're going to get yourself stuck in a wall and if so don't move the caster.

I meant that fixing it would make it more annoying to get a valid spot to teleport to without clairvoyance and that you could still use it to fish for where walls are. Getting stuck in a wall doesn't generally kill players as I do it with debug and it doesn't seem to cause damage, but maybe there's something in the code I don't know about. Worst case is you teleport back out.

@chaosvolt
Copy link
Member Author

Ah, fair enough then. Letting the player teleport themselves into walls is easily fixed by just teleporting back out again, or walking out if a valid space is nearby.

@chaosvolt chaosvolt merged commit c14baf8 into cataclysmbnteam:main Sep 10, 2024
12 checks passed
@chaosvolt chaosvolt deleted the bn-can-has-blink-spells branch September 10, 2024 03:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs PRs releated to docs page src changes related to source code.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Game crashes when attempting to use a spell with SWAP_POS that would kill the target
3 participants