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

Function MAI_Counselor

Source/monster.cpp:4113–4183  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4111}
4112
4113void MAI_Counselor(int i)
4114{
4115 int mx, my, fx, fy;
4116 int dist, md, v;
4117 MonsterStruct *Monst;
4118
4119 if ((DWORD)i >= MAXMONSTERS)
4120 app_fatal("MAI_Counselor: Invalid monster %d", i);
4121 if (monster[i]._mmode == MM_STAND && monster[i]._msquelch != 0) {
4122 Monst = monster + i;
4123 fx = Monst->_menemyx;
4124 fy = Monst->_menemyy;
4125 mx = Monst->_mx - fx;
4126 my = Monst->_my - fy;
4127 md = GetDirection(Monst->_mx, Monst->_my, Monst->_lastx, Monst->_lasty);
4128 if (Monst->_msquelch < UCHAR_MAX)
4129 MonstCheckDoors(i);
4130 v = random_(121, 100);
4131 if (Monst->_mgoal == MGOAL_RETREAT) {
4132 if (Monst->_mgoalvar1++ <= 3)
4133 M_CallWalk(i, opposite[md]);
4134 else {
4135 Monst->_mgoal = MGOAL_NORMAL;
4136 M_StartFadein(i, md, TRUE);
4137 }
4138 } else if (Monst->_mgoal == MGOAL_MOVE) {
4139 if (abs(mx) > abs(my))
4140 dist = abs(mx);
4141 else
4142 dist = abs(my);
4143 if ((abs(mx) >= 2 || abs(my) >= 2) && Monst->_msquelch == UCHAR_MAX && dTransVal[Monst->_mx][Monst->_my] == dTransVal[fx][fy]) {
4144 if (Monst->_mgoalvar1++ < 2 * dist || !DirOK(i, md)) {
4145 M_RoundWalk(i, md, &Monst->_mgoalvar2);
4146 } else {
4147 Monst->_mgoal = MGOAL_NORMAL;
4148 M_StartFadein(i, md, TRUE);
4149 }
4150 } else {
4151 Monst->_mgoal = MGOAL_NORMAL;
4152 M_StartFadein(i, md, TRUE);
4153 }
4154 } else if (Monst->_mgoal == MGOAL_NORMAL) {
4155 if (abs(mx) >= 2 || abs(my) >= 2) {
4156 if (v < 5 * (Monst->_mint + 10) && LineClear(Monst->_mx, Monst->_my, fx, fy)) {
4157 M_StartRAttack(i, counsmiss[Monst->_mint], Monst->mMinDamage + random_(77, Monst->mMaxDamage - Monst->mMinDamage + 1));
4158 } else if (random_(124, 100) < 30) {
4159 Monst->_mgoal = MGOAL_MOVE;
4160 Monst->_mgoalvar1 = 0;
4161 M_StartFadeout(i, md, FALSE);
4162 } else
4163 M_StartDelay(i, random_(105, 10) + 2 * (5 - Monst->_mint));
4164 } else {
4165 Monst->_mdir = md;
4166 if (Monst->_mhitpoints < (Monst->_mmaxhp >> 1)) {
4167 Monst->_mgoal = MGOAL_RETREAT;
4168 Monst->_mgoalvar1 = 0;
4169 M_StartFadeout(i, md, FALSE);
4170 } else if (Monst->_mVar1 == MM_DELAY

Callers 2

MAI_ZharFunction · 0.85
MAI_LazurusFunction · 0.85

Calls 13

app_fatalFunction · 0.85
GetDirectionFunction · 0.85
MonstCheckDoorsFunction · 0.85
random_Function · 0.85
M_CallWalkFunction · 0.85
M_StartFadeinFunction · 0.85
DirOKFunction · 0.85
M_RoundWalkFunction · 0.85
LineClearFunction · 0.85
M_StartRAttackFunction · 0.85
M_StartFadeoutFunction · 0.85
M_StartDelayFunction · 0.85

Tested by

no test coverage detected