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

Function MAI_Bat

Source/monster.cpp:3107–3169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3105}
3106
3107void MAI_Bat(int i)
3108{
3109 MonsterStruct *Monst;
3110 int md, v, pnum;
3111 int fx, fy, xd, yd;
3112
3113 if ((DWORD)i >= MAXMONSTERS)
3114 app_fatal("MAI_Bat: Invalid monster %d", i);
3115
3116 Monst = &monster[i];
3117 pnum = Monst->_menemy;
3118 if (Monst->_mmode != MM_STAND || Monst->_msquelch == 0) {
3119 return;
3120 }
3121
3122 xd = Monst->_mx - Monst->_menemyx;
3123 yd = Monst->_my - Monst->_menemyy;
3124 md = GetDirection(Monst->_mx, Monst->_my, Monst->_lastx, Monst->_lasty);
3125 Monst->_mdir = md;
3126 v = random_(107, 100);
3127 if (Monst->_mgoal == MGOAL_RETREAT) {
3128 if (!Monst->_mgoalvar1) {
3129 M_CallWalk(i, opposite[md]);
3130 Monst->_mgoalvar1++;
3131 } else {
3132 if (random_(108, 2))
3133 M_CallWalk(i, left[md]);
3134 else
3135 M_CallWalk(i, right[md]);
3136 Monst->_mgoal = MGOAL_NORMAL;
3137 }
3138 return;
3139 }
3140
3141 fx = Monst->_menemyx;
3142 fy = Monst->_menemyy;
3143 if (Monst->MType->mtype == MT_GLOOM
3144 && (abs(xd) >= 5 || abs(yd) >= 5)
3145 && v < 4 * Monst->_mint + 33
3146 && LineClearF1(PosOkMonst, i, Monst->_mx, Monst->_my, fx, fy)) {
3147 if (AddMissile(Monst->_mx, Monst->_my, fx, fy, md, MIS_RHINO, pnum, i, 0, 0) != -1) {
3148 dMonster[Monst->_mx][Monst->_my] = -(i + 1);
3149 Monst->_mmode = MM_CHARGE;
3150 }
3151 } else if (abs(xd) >= 2 || abs(yd) >= 2) {
3152 if (Monst->_mVar2 > 20 && v < Monst->_mint + 13
3153 || (Monst->_mVar1 == MM_WALK || Monst->_mVar1 == MM_WALK2 || Monst->_mVar1 == MM_WALK3)
3154 && Monst->_mVar2 == 0
3155 && v < Monst->_mint + 63) {
3156 M_CallWalk(i, md);
3157 }
3158 } else if (v < 4 * Monst->_mint + 8) {
3159 M_StartAttack(i);
3160 Monst->_mgoal = MGOAL_RETREAT;
3161 Monst->_mgoalvar1 = 0;
3162 if (Monst->MType->mtype == MT_FAMILIAR) {
3163 AddMissile(Monst->_menemyx, Monst->_menemyy, Monst->_menemyx + 1, 0, -1, MIS_LIGHTNING, 1, i, random_(109, 10) + 1, 0);
3164 }

Callers

nothing calls this directly

Calls 7

app_fatalFunction · 0.85
GetDirectionFunction · 0.85
random_Function · 0.85
M_CallWalkFunction · 0.85
LineClearF1Function · 0.85
AddMissileFunction · 0.85
M_StartAttackFunction · 0.85

Tested by

no test coverage detected