MCPcopy Create free account
hub / github.com/diasurgical/devilution / M_Enemy

Function M_Enemy

Source/monster.cpp:1118–1195  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1116}
1117
1118void M_Enemy(int i)
1119{
1120 int j;
1121 int mi, pnum;
1122 int dist, best_dist;
1123 int _menemy;
1124 BOOL sameroom, bestsameroom;
1125 MonsterStruct *Monst;
1126 BYTE enemyx, enemyy;
1127
1128 _menemy = -1;
1129 best_dist = -1;
1130 bestsameroom = 0;
1131 Monst = monster + i;
1132 if (!(Monst->_mFlags & MFLAG_GOLEM)) {
1133 for (pnum = 0; pnum < MAX_PLRS; pnum++) {
1134 if (!plr[pnum].plractive || currlevel != plr[pnum].plrlevel || plr[pnum]._pLvlChanging || (plr[pnum]._pHitPoints == 0 && gbMaxPlayers != 1))
1135 continue;
1136 if (dTransVal[Monst->_mx][Monst->_my] == dTransVal[plr[pnum].WorldX][plr[pnum].WorldY])
1137 sameroom = TRUE;
1138 else
1139 sameroom = FALSE;
1140 if (abs(Monst->_mx - plr[pnum].WorldX) > abs(Monst->_my - plr[pnum].WorldY))
1141 dist = Monst->_mx - plr[pnum].WorldX;
1142 else
1143 dist = Monst->_my - plr[pnum].WorldY;
1144 dist = abs(dist);
1145 if ((sameroom && !bestsameroom)
1146 || ((sameroom || !bestsameroom) && dist < best_dist)
1147 || (_menemy == -1)) {
1148 Monst->_mFlags &= ~MFLAG_TARGETS_MONSTER;
1149 _menemy = pnum;
1150 enemyx = plr[pnum]._px;
1151 enemyy = plr[pnum]._py;
1152 best_dist = dist;
1153 bestsameroom = sameroom;
1154 }
1155 }
1156 }
1157 for (j = 0; j < nummonsters; j++) {
1158 mi = monstactive[j];
1159 if (mi == i)
1160 continue;
1161 if (monster[mi]._mx == 1 && monster[mi]._my == 0)
1162 continue;
1163 if (M_Talker(mi) && monster[mi].mtalkmsg)
1164 continue;
1165 if (!(Monst->_mFlags & MFLAG_GOLEM)
1166 && ((abs(monster[mi]._mx - Monst->_mx) >= 2 || abs(monster[mi]._my - Monst->_my) >= 2) && !M_Ranged(i)
1167 || (!(Monst->_mFlags & MFLAG_GOLEM) && !(monster[mi]._mFlags & MFLAG_GOLEM)))) {
1168 continue;
1169 }
1170 sameroom = dTransVal[Monst->_mx][Monst->_my] == dTransVal[monster[mi]._mx][monster[mi]._my];
1171 if (abs(Monst->_mx - monster[mi]._mx) > abs(Monst->_my - monster[mi]._my))
1172 dist = Monst->_mx - monster[mi]._mx;
1173 else
1174 dist = Monst->_my - monster[mi]._my;
1175 dist = abs(dist);

Callers 5

M_StartStandFunction · 0.85
M_DoStandFunction · 0.85
MAI_GargFunction · 0.85
MAI_GolumFunction · 0.85
SpawnGolumFunction · 0.85

Calls 2

M_TalkerFunction · 0.85
M_RangedFunction · 0.85

Tested by

no test coverage detected