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

Function sync_monster

Source/sync.cpp:225–281  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

223}
224
225void sync_monster(int pnum, const TSyncMonster *p)
226{
227 int i, ndx, md, mdx, mdy;
228 DWORD delta;
229
230 ndx = p->_mndx;
231
232 if (monster[ndx]._mhitpoints == 0) {
233 return;
234 }
235
236 for (i = 0; i < nummonsters; i++) {
237 if (monstactive[i] == ndx) {
238 break;
239 }
240 }
241
242 delta = abs(plr[myplr].WorldX - monster[ndx]._mx) + abs(plr[myplr].WorldY - monster[ndx]._my);
243 if (delta > 255) {
244 delta = 255;
245 }
246
247 if (delta < p->_mdelta || (delta == p->_mdelta && pnum > myplr)) {
248 return;
249 }
250 if (monster[ndx]._mfutx == p->_mx && monster[ndx]._mfuty == p->_my) {
251 return;
252 }
253 if (monster[ndx]._mmode == MM_CHARGE || monster[ndx]._mmode == MM_STONE) {
254 return;
255 }
256
257 mdx = abs(monster[ndx]._mx - p->_mx);
258 mdy = abs(monster[ndx]._my - p->_my);
259 if (mdx <= 2 && mdy <= 2) {
260 if (monster[ndx]._mmode < MM_WALK || monster[ndx]._mmode > MM_WALK3) {
261 md = GetDirection(monster[ndx]._mx, monster[ndx]._my, p->_mx, p->_my);
262 if (DirOK(ndx, md)) {
263 M_ClearSquares(ndx);
264 dMonster[monster[ndx]._mx][monster[ndx]._my] = ndx + 1;
265 M_WalkDir(ndx, md);
266 monster[ndx]._msquelch = UCHAR_MAX;
267 }
268 }
269 } else if (dMonster[p->_mx][p->_my] == 0) {
270 M_ClearSquares(ndx);
271 dMonster[p->_mx][p->_my] = ndx + 1;
272 monster[ndx]._mx = p->_mx;
273 monster[ndx]._my = p->_my;
274 decode_enemy(ndx, p->_menemy);
275 md = GetDirection(p->_mx, p->_my, monster[ndx]._menemyx, monster[ndx]._menemyy);
276 M_StartStand(ndx, md);
277 monster[ndx]._msquelch = UCHAR_MAX;
278 }
279
280 decode_enemy(ndx, p->_menemy);
281}
282

Callers 1

sync_updateFunction · 0.85

Calls 6

GetDirectionFunction · 0.85
DirOKFunction · 0.85
M_ClearSquaresFunction · 0.85
M_WalkDirFunction · 0.85
decode_enemyFunction · 0.85
M_StartStandFunction · 0.85

Tested by

no test coverage detected