Skip to content

Allow monsters to have different climb/swim/dig speeds #80849

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

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

marilynias
Copy link
Contributor

@marilynias marilynias commented May 6, 2025

Summary

Infrastructure "Allow monsters to have different climb/swim/dig speeds"

Purpose of change

WIP, Feedback very welcome
closes #80846 , closes #80673

previously monster movement calculation would just return hardcoded values, which ignored many possible modifiers. Not happy with my original fix (#80673), I decided to rework how special movements get calculated, by allowing monsters to have movement-skills in those special movement types.

Describe the solution

Make a new optional JSON field for movement skills (every entry is also optional):

...
"move_skills": [ { "climb": 1 }, { "dig": 2 }, { "swim": 3} ],
...

Where having some value allows the monster to do the action and the value itself would say how fast it can do the action.
with the general formula

movecost = (movecost_from*50+ movecost_to *50)/2;

or the less readable, but equivilent

movecost = (movecost_from + movecost_to)*25;

where movecost_from and movecost_to would be tile-movecost if its not climbable/dig-able/swim-able and calculated from the "move_skills" if it can traverse and has the respective move_skills (or for backwards-compatibility the flag) set.

The skills get translated into multipliers as what percentage of some max_obstacle_penalty should be applied.
mod = max_obstacle_penalty - skillvalue * max_obstacle_penalty / 10 (10 is the max skill).
that mod (usually) gets multiplied by the relevant terrain-/furn-cost.

That will drastically change balance, as previously terrain-/furn-cost did not

TODO:

  • docs
  • tests
  • adjust monster::move_to

Example:

    "abstract": "mon_fry",
    ...
    "move_skills": { "swim": 1 },
    "abstract": "mon_fish_small",
    ...
    "move_skills": { "swim": 10 },

image

Misc. changes:

  • only climbers can climb furn with DIFFICULT_Z. Previously the flag didn't get checked for by monsters. (boars could climb ladders??)
  • DIFFICULT_Z climbing scales with climbmod
  • other modifiers like field effects also apply when stepping out of them
  • monsters can ignore the movement penalty from field effects (previously only checked if immune to impassable fields)

Describe alternatives you've considered

Instead of multiplying movecost by the skill-mod, add a flat penalty. But intuitively cost should scale more with difficulty.

Testing

TODO

Additional context

calc_movecost generally only expects valid movements, throwing debugmessages if its not. When thats the case it needs to be filtered out in the pathfinding (if the obstruction is permantend) or move_to (if the obstruction is not permanent) function.

Cataclysm-DDA/src/monmove.cpp

Lines 1888 to 1890 in 93e97e5

const float cost = stagger_adjustment *
static_cast<float>( climbs() &&
here.has_flag( ter_furn_flag::TFLAG_NO_FLOOR, p ) ? calc_climb_cost( pos,

calls monster::calc_climb_cost when the monster climbs and target tile has no floor, but calc_climb_cost then only returns a valid number if the monster flies or there is a floor, so its only usefull for fliers:

Cataclysm-DDA/src/monmove.cpp

Lines 1589 to 1603 in 93e97e5

int monster::calc_climb_cost( const tripoint_bub_ms &f, const tripoint_bub_ms &t ) const
{
if( flies() ) {
return 100;
}
map &here = get_map();
if( climbs() && !here.has_flag( ter_furn_flag::TFLAG_NO_FLOOR, t ) ) {
const int diff = here.climb_difficulty( f );
if( diff <= 10 ) {
return 150;
}
}
return 0;

@github-actions github-actions bot added [JSON] Changes (can be) made in JSON [C++] Changes (can be) made in C++. Previously named `Code` Monsters Monsters both friendly and unfriendly. Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style json-styled JSON lint passed, label assigned by github actions astyled astyled PR, label is assigned by github actions labels May 6, 2025
@marilynias marilynias marked this pull request as draft May 6, 2025 14:27
@KheaHyena
Copy link

Oh wow, this is a pretty nifty addition!

I personally would love to see a system akin to the PC, with Speed and general Movement also apply to monsters (I find it infuriating how a creature can do 4 attacks in a row at lightning speeds, despite one only wanting to translate how fast they can move), but to have consideration for different movement styles is a really nice addition, if not the first step towards the former.
Perhaps even Leap on some creatures, in particular to one's that shouldn't really have it, could be adjusted with this system to allow them to scuttle or run instead.

@marilynias
Copy link
Contributor Author

I personally would love to see a system akin to the PC, with Speed and general Movement also apply to monsters (I find it infuriating how a creature can do 4 attacks in a row at lightning speeds, despite one only wanting to translate how fast they can move), but to have consideration for different movement styles is a really nice addition, if not the first step towards the former. Perhaps even Leap on some creatures, in particular to one's that shouldn't really have it, could be adjusted with this system to allow them to scuttle or run instead.

Definitely out of scope for this PR, but I agree in general. I didnt find how PC implements it though.

calc_climb_cost use mod
@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label May 8, 2025
define max_obstacle_penalty
@github-actions github-actions bot added the Vehicles Vehicles, parts, mechanics & interactions label May 9, 2025
@github-actions github-actions bot added the <Bugfix> This is a fix for a bug (or closes open issue) label May 9, 2025
@marilynias
Copy link
Contributor Author

The core functionality should be ready. Just have to double check some things and write docs/tests.

marilynias added 4 commits May 9, 2025 15:30
Add forced movement to calc
non climbers cannot climb ladders (TFLAG_DIFFICULT_Z)
@github-actions github-actions bot added the Code: Tests Measurement, self-control, statistics, balancing. label May 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions <Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style Code: Tests Measurement, self-control, statistics, balancing. [JSON] Changes (can be) made in JSON json-styled JSON lint passed, label assigned by github actions Monsters Monsters both friendly and unfriendly. Vehicles Vehicles, parts, mechanics & interactions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

opinions on dynamic modifier for monster climb-/dig-/swimspeed?
2 participants