MCPcopy Create free account
hub / github.com/NetHack/NetHack / mcalcmove

Function mcalcmove

src/mon.c:1125–1168  ·  view source on GitHub ↗

calculate 'mon's movement for current turn; called from moveloop() */

Source from the content-addressed store, hash-verified

1123
1124/* calculate 'mon's movement for current turn; called from moveloop() */
1125int
1126mcalcmove(
1127 struct monst *mon,
1128 boolean m_moving) /* True: adjust for moving;
1129 * False: just adjust for speed */
1130{
1131 int mmove = mon->data->mmove;
1132 int mmove_adj;
1133
1134 /* Note: MSLOW's `+ 1' prevents slowed speed 1 getting reduced to 0;
1135 * MFAST's `+ 2' prevents hasted speed 1 from becoming a no-op;
1136 * both adjustments have negligible effect on higher speeds.
1137 */
1138 if (mon->mspeed == MSLOW) {
1139 /* slow-monster effects work better against faster monsters: they
1140 lose 1/3 of their speed below 12 but 2/3 of their speed above */
1141 if (mmove < NORMAL_SPEED)
1142 mmove = (2 * mmove + 1) / 3;
1143 else
1144 mmove = 4 + (mmove / 3);
1145 } else if (mon->mspeed == MFAST)
1146 mmove = (4 * mmove + 2) / 3;
1147
1148 if (mon == u.usteed && u.ugallop && svc.context.mv) {
1149 /* increase movement by a factor of 1.5; also increase variance of
1150 movement speed (if it's naturally 24, we don't want it to always
1151 become 36) */
1152 mmove = ((rn2(2) ? 4 : 5) * mmove) / 3;
1153 }
1154
1155 if (m_moving) {
1156 /* Randomly round the monster's speed to a multiple of NORMAL_SPEED.
1157 This makes it impossible for the player to predict when they'll
1158 get a free turn (thus preventing exploits like "melee kiting"),
1159 while retaining guarantees about shopkeepers not being outsped
1160 by a normal-speed player, normal-speed players being unable
1161 to open up a gap when fleeing a normal-speed monster, etc. */
1162 mmove_adj = mmove % NORMAL_SPEED;
1163 mmove -= mmove_adj;
1164 if (rn2(NORMAL_SPEED) < mmove_adj)
1165 mmove += NORMAL_SPEED;
1166 }
1167 return mmove;
1168}
1169
1170/* actions that happen once per ``turn'', regardless of each
1171 individual monster's metabolism; some of these might need to

Callers 3

u_calc_moveamtFunction · 0.85
allmain.cFile · 0.85
worm_moveFunction · 0.85

Calls 1

rn2Function · 0.85

Tested by

no test coverage detected