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

Function MAI_Scav

Source/monster.cpp:3604–3690  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3602}
3603
3604void MAI_Scav(int i)
3605{
3606 BOOL done;
3607 int x, y;
3608 int _mx, _my;
3609 MonsterStruct *Monst;
3610
3611 if ((DWORD)i >= MAXMONSTERS)
3612 app_fatal("MAI_Scav: Invalid monster %d", i);
3613 Monst = monster + i;
3614 _mx = Monst->_mx;
3615 _my = Monst->_my;
3616 done = FALSE;
3617 if (monster[i]._mmode != MM_STAND)
3618 return;
3619 if (Monst->_mhitpoints < (Monst->_mmaxhp >> 1) && Monst->_mgoal != MGOAL_HEALING) {
3620 if (Monst->leaderflag) {
3621 monster[Monst->leader].packsize--;
3622 Monst->leaderflag = 0;
3623 }
3624 Monst->_mgoal = MGOAL_HEALING;
3625 Monst->_mgoalvar3 = 10;
3626 }
3627 if (Monst->_mgoal == MGOAL_HEALING && Monst->_mgoalvar3 != 0) {
3628 Monst->_mgoalvar3--;
3629 if (dDead[Monst->_mx][Monst->_my]) {
3630 M_StartEat(i);
3631 if (!(Monst->_mFlags & MFLAG_NOHEAL))
3632 Monst->_mhitpoints += 64;
3633 if (Monst->_mhitpoints >= (Monst->_mmaxhp >> 1) + (Monst->_mmaxhp >> 2)) {
3634 Monst->_mgoal = MGOAL_NORMAL;
3635 Monst->_mgoalvar1 = 0;
3636 Monst->_mgoalvar2 = 0;
3637 }
3638 } else {
3639 if (Monst->_mgoalvar1 == 0) {
3640 if (random_(120, 2) != 0) {
3641 for (y = -4; y <= 4 && !done; y++) {
3642 for (x = -4; x <= 4 && !done; x++) {
3643 // BUGFIX: incorrect check of offset against limits of the dungeon
3644 if (y < 0 || y >= MAXDUNY || x < 0 || x >= MAXDUNX)
3645 continue;
3646 done = dDead[Monst->_mx + x][Monst->_my + y] != 0
3647 && LineClearF(
3648 CheckNoSolid,
3649 Monst->_mx,
3650 Monst->_my,
3651 Monst->_mx + x,
3652 Monst->_my + y);
3653 }
3654 }
3655 x--;
3656 y--;
3657 } else {
3658 for (y = 4; y >= -4 && !done; y--) {
3659 for (x = 4; x >= -4 && !done; x--) {
3660 // BUGFIX: incorrect check of offset against limits of the dungeon
3661 if (y < 0 || y >= MAXDUNY || x < 0 || x >= MAXDUNX)

Callers

nothing calls this directly

Calls 7

app_fatalFunction · 0.85
M_StartEatFunction · 0.85
random_Function · 0.85
LineClearFFunction · 0.85
GetDirectionFunction · 0.85
M_CallWalkFunction · 0.85
MAI_SkelSdFunction · 0.85

Tested by

no test coverage detected