Skip to content

un-magic-number monster movecost calculation #80673

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 5 commits into
base: master
Choose a base branch
from

Conversation

marilynias
Copy link
Contributor

@marilynias marilynias commented Apr 22, 2025

Summary

Infrastructure "un-magic-number monset movecost calculation."

Purpose of change

while working on #80555 (which I cannot reproduce with "circular distances" enabled) I found this Monstrosity:

Cataclysm-DDA/src/monmove.cpp

Lines 1619 to 1671 in 02f75a2

int monster::calc_movecost( const tripoint &f, const tripoint &t ) const
{
int movecost = 0;
map &here = get_map();
const int source_cost = here.move_cost( f );
const int dest_cost = here.move_cost( t );
// Digging and flying monsters ignore terrain cost
if( flies() || ( digging() && here.has_flag( ter_furn_flag::TFLAG_DIGGABLE, t ) ) ) {
movecost = 100;
// Swimming monsters move super fast in water
} else if( swims() ) {
if( here.has_flag( ter_furn_flag::TFLAG_SWIMMABLE, f ) ) {
movecost += 25;
} else {
movecost += 50 * here.move_cost( f );
}
if( here.has_flag( ter_furn_flag::TFLAG_SWIMMABLE, t ) ) {
movecost += 25;
} else {
movecost += 50 * here.move_cost( t );
}
} else if( can_submerge() ) {
// No-breathe monsters have to walk underwater slowly
if( here.has_flag( ter_furn_flag::TFLAG_SWIMMABLE, f ) ) {
movecost += 250;
} else {
movecost += 50 * here.move_cost( f );
}
if( here.has_flag( ter_furn_flag::TFLAG_SWIMMABLE, t ) ) {
movecost += 250;
} else {
movecost += 50 * here.move_cost( t );
}
movecost /= 2;
} else if( climbs() ) {
if( here.has_flag( ter_furn_flag::TFLAG_CLIMBABLE, f ) ) {
movecost += 150;
} else {
movecost += 50 * here.move_cost( f );
}
if( here.has_flag( ter_furn_flag::TFLAG_CLIMBABLE, t ) ) {
movecost += 150;
} else {
movecost += 50 * here.move_cost( t );
}
movecost /= 2;
} else {
movecost = ( ( 50 * source_cost ) + ( 50 * dest_cost ) ) / 2.0;
}
return movecost;
}

Describe the solution

un-hardcode the monster::calc_movecost method. Make use of the existing map::combined_movecost method with arguments to be able to ignore terrain/furn/field penalties, and add the desired penalty in calc_movecost.

When ignoring terrain cost, add modifier to ensure movecost matches pre-PR values.

  • Swimming (25)
  • climbing (150)
  • Submerged walking (originally 250, but should be handled by terrain cost)
  • digging (100)
  • flying (100)

Describe alternatives you've considered

Being able to separately ignore 'from' and 'to' tile. Currently it doesn't matter if only one or both tiles can be ignored.

Testing

TODO: create CI

Additional context

rl_dist actually checks for trigdist and returns it, but since it returns int there a 1-tile diagonal distance of 1.41 gets floored to 1 (probable issue of #71699). I believe it makes sense to make it return float.

@marilynias marilynias marked this pull request as draft April 22, 2025 13:32
@github-actions github-actions bot added [C++] Changes (can be) made in C++. Previously named `Code` <Bugfix> This is a fix for a bug (or closes open issue) json-styled JSON lint passed, label assigned by github actions astyled astyled PR, label is assigned by github actions labels Apr 22, 2025
@marilynias marilynias changed the title rework mon_move un-magic-number monster movecost calculation to allow diagonal costs Apr 22, 2025
@akrieger
Copy link
Member

Please remove the IWYU submodule from the PR entirely. Not just commit a deletion but remove it from the commit history also, please.

@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Apr 25, 2025
@marilynias marilynias marked this pull request as ready for review April 25, 2025 07:06
@marilynias marilynias marked this pull request as draft April 25, 2025 07:06
@github-actions github-actions bot added Code: Tests Measurement, self-control, statistics, balancing. Monsters Monsters both friendly and unfriendly. BasicBuildPassed This PR builds correctly, label assigned by github actions and removed BasicBuildPassed This PR builds correctly, label assigned by github actions labels Apr 25, 2025
@marilynias marilynias marked this pull request as ready for review April 25, 2025 13:10
@marilynias marilynias marked this pull request as draft April 25, 2025 13:10
@github-actions github-actions bot removed the BasicBuildPassed This PR builds correctly, label assigned by github actions label Apr 25, 2025
@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Apr 25, 2025
@marilynias marilynias marked this pull request as ready for review April 25, 2025 14:22
@marilynias marilynias marked this pull request as draft April 25, 2025 14:22
@github-actions github-actions bot removed the BasicBuildPassed This PR builds correctly, label assigned by github actions label Apr 25, 2025
@marilynias marilynias changed the title un-magic-number monster movecost calculation to allow diagonal costs un-magic-number monster movecost calculation Apr 28, 2025
@github-actions github-actions bot added Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style BasicBuildPassed This PR builds correctly, label assigned by github actions labels Apr 29, 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-styled JSON lint passed, label assigned by github actions Monsters Monsters both friendly and unfriendly.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants