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

Function MAI_Fallen

Source/monster.cpp:3376–3446  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3374}
3375
3376void MAI_Fallen(int i)
3377{
3378 int x, y, xpos, ypos;
3379 int m, rad, md;
3380 MonsterStruct *Monst;
3381
3382 if ((DWORD)i >= MAXMONSTERS) {
3383 app_fatal("MAI_Fallen: Invalid monster %d", i);
3384 }
3385 if (monster[i]._mgoal == MGOAL_SHOOT) {
3386 if (monster[i]._mgoalvar1)
3387 monster[i]._mgoalvar1--;
3388 else
3389 monster[i]._mgoal = MGOAL_NORMAL;
3390 }
3391
3392 Monst = &monster[i];
3393 if (monster[i]._mmode != MM_STAND || monster[i]._msquelch == 0) {
3394 return;
3395 }
3396
3397 if (Monst->_mgoal == MGOAL_RETREAT) {
3398 if (!Monst->_mgoalvar1--) {
3399 Monst->_mgoal = MGOAL_NORMAL;
3400 M_StartStand(i, opposite[Monst->_mdir]);
3401 }
3402 }
3403
3404 if (Monst->_mAnimFrame == Monst->_mAnimLen) {
3405 if (random_(113, 4)) {
3406 return;
3407 }
3408 if (!(Monst->_mFlags & MFLAG_NOHEAL)) {
3409 M_StartSpStand(i, Monst->_mdir);
3410 rad = 2 * Monst->_mint + 2;
3411 if (Monst->_mmaxhp - rad >= Monst->_mhitpoints)
3412 Monst->_mhitpoints = rad + Monst->_mhitpoints;
3413 else
3414 Monst->_mhitpoints = Monst->_mmaxhp;
3415 }
3416 rad = 2 * Monst->_mint + 4;
3417 for (y = -rad; y <= rad; y++) {
3418 for (x = -rad; x <= rad; x++) {
3419 if (y >= 0 && y < MAXDUNY && x >= 0 && x < MAXDUNX) {
3420 m = dMonster[x + Monst->_mx][y + Monst->_my];
3421 if (m > 0) {
3422 m--;
3423 if (monster[m]._mAi == AI_FALLEN) {
3424 monster[m]._mgoal = MGOAL_SHOOT;
3425 monster[m]._mgoalvar1 = 30 * Monst->_mint + 105;
3426 }
3427 }
3428 }
3429 }
3430 }
3431 } else if (Monst->_mgoal == MGOAL_RETREAT) {
3432 md = Monst->_mdir;
3433 M_CallWalk(i, md);

Callers 1

MAI_SnotSpilFunction · 0.85

Calls 8

app_fatalFunction · 0.85
M_StartStandFunction · 0.85
random_Function · 0.85
M_StartSpStandFunction · 0.85
M_CallWalkFunction · 0.85
M_StartAttackFunction · 0.85
M_GetDirFunction · 0.85
MAI_SkelSdFunction · 0.85

Tested by

no test coverage detected