MCPcopy Create free account
hub / github.com/demoth/jake2 / ai_checkattack

Method ai_checkattack

game/src/main/java/jake2/game/GameAI.java:116–219  ·  view source on GitHub ↗

Decides if we're going to attack or do something else used by ai_run and ai_stand. .enemy Will be world if not currently angry at anyone. .movetarget The next path spot to walk toward. If .enemy, ignore .movetarget. When an enemy is killed, the monster will try to return to it's path. .hunt_time

(SubgameEntity self, float dist, GameExportsImpl gameExports)

Source from the content-addressed store, hash-verified

114 * walkmove(angle, speed) primitive is all or nothing
115 */
116 public static boolean ai_checkattack(SubgameEntity self, float dist, GameExportsImpl gameExports) {
117
118 boolean hesDeadJim;
119
120 // this causes monsters to run blindly to the combat point w/o firing
121 if (self.goalentity != null) {
122 if ((self.monsterinfo.aiflags & GameDefines.AI_COMBAT_POINT) != 0)
123 return false;
124
125 if ((self.monsterinfo.aiflags & GameDefines.AI_SOUND_TARGET) != 0) {
126 if ((gameExports.level.time - self.enemy.teleport_time) > 5.0) {
127 if (self.goalentity == self.enemy)
128 if (self.movetarget != null)
129 self.goalentity = self.movetarget;
130 else
131 self.goalentity = null;
132 self.monsterinfo.aiflags &= ~GameDefines.AI_SOUND_TARGET;
133 if ((self.monsterinfo.aiflags & GameDefines.AI_TEMP_STAND_GROUND) != 0)
134 self.monsterinfo.aiflags &= ~(GameDefines.AI_STAND_GROUND | GameDefines.AI_TEMP_STAND_GROUND);
135 } else {
136 self.show_hostile = (int) gameExports.level.time + 1;
137 return false;
138 }
139 }
140 }
141
142 gameExports.enemy_vis = false;
143
144 // see if the enemy is dead
145 hesDeadJim = false;
146 if ((null == self.enemy) || (!self.enemy.inuse)) {
147 hesDeadJim = true;
148 } else if ((self.monsterinfo.aiflags & GameDefines.AI_MEDIC) != 0) {
149 if (self.enemy.health > 0) {
150 hesDeadJim = true;
151 self.monsterinfo.aiflags &= ~GameDefines.AI_MEDIC;
152 }
153 } else {
154 if ((self.monsterinfo.aiflags & GameDefines.AI_BRUTAL) != 0) {
155 if (self.enemy.health <= -80)
156 hesDeadJim = true;
157 } else {
158 if (self.enemy.health <= 0)
159 hesDeadJim = true;
160 }
161 }
162
163 if (hesDeadJim) {
164 self.enemy = null;
165 // FIXME: look all around for other targets
166 if (self.oldenemy != null && self.oldenemy.health > 0) {
167 self.enemy = self.oldenemy;
168 self.oldenemy = null;
169 HuntTarget(self, gameExports);
170 } else {
171 if (self.movetarget != null) {
172 self.goalentity = self.movetarget;
173 self.monsterinfo.walk.think(self, gameExports);

Callers 1

aiMethod · 0.95

Calls 10

HuntTargetMethod · 0.95
visibleMethod · 0.95
VectorCopyMethod · 0.95
infrontMethod · 0.95
rangeMethod · 0.95
VectorSubtractMethod · 0.95
vectoyawMethod · 0.95
ai_run_missileMethod · 0.95
ai_run_meleeMethod · 0.95
thinkMethod · 0.45

Tested by

no test coverage detected