diff options
Diffstat (limited to 'src/baseq2/g_ai.c')
-rw-r--r-- | src/baseq2/g_ai.c | 549 |
1 files changed, 218 insertions, 331 deletions
diff --git a/src/baseq2/g_ai.c b/src/baseq2/g_ai.c index 52e5048..a4828b4 100644 --- a/src/baseq2/g_ai.c +++ b/src/baseq2/g_ai.c @@ -8,7 +8,7 @@ of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. @@ -21,10 +21,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "g_local.h" -qboolean FindTarget (edict_t *self); +qboolean FindTarget(edict_t *self); extern cvar_t *maxclients; -qboolean ai_checkattack (edict_t *self, float dist); +qboolean ai_checkattack(edict_t *self, float dist); qboolean enemy_vis; qboolean enemy_infront; @@ -47,7 +47,7 @@ will be null. In coop games, sight_client will cycle between the clients. ================= */ -void AI_SetSightClient (void) +void AI_SetSightClient(void) { edict_t *ent; int start, check; @@ -58,21 +58,18 @@ void AI_SetSightClient (void) start = level.sight_client - g_edicts; check = start; - while (1) - { + while (1) { check++; if (check > game.maxclients) check = 1; ent = &g_edicts[check]; if (ent->inuse && ent->health > 0 - && !(ent->flags & FL_NOTARGET) ) - { + && !(ent->flags & FL_NOTARGET)) { level.sight_client = ent; return; // got one } - if (check == start) - { + if (check == start) { level.sight_client = NULL; return; // nobody to see } @@ -89,9 +86,9 @@ Move the specified distance at current facing. This replaces the QC functions: ai_forward, ai_back, ai_pain, and ai_painforward ============== */ -void ai_move (edict_t *self, float dist) +void ai_move(edict_t *self, float dist) { - M_walkmove (self, self->s.angles[YAW], dist); + M_walkmove(self, self->s.angles[YAW], dist); } @@ -103,50 +100,41 @@ Used for standing around and looking for players Distance is for slight position adjustments needed by the animations ============== */ -void ai_stand (edict_t *self, float dist) +void ai_stand(edict_t *self, float dist) { vec3_t v; if (dist) - M_walkmove (self, self->s.angles[YAW], dist); + M_walkmove(self, self->s.angles[YAW], dist); - if (self->monsterinfo.aiflags & AI_STAND_GROUND) - { - if (self->enemy) - { - VectorSubtract (self->enemy->s.origin, self->s.origin, v); + if (self->monsterinfo.aiflags & AI_STAND_GROUND) { + if (self->enemy) { + VectorSubtract(self->enemy->s.origin, self->s.origin, v); self->ideal_yaw = vectoyaw(v); - if (self->s.angles[YAW] != self->ideal_yaw && self->monsterinfo.aiflags & AI_TEMP_STAND_GROUND) - { + if (self->s.angles[YAW] != self->ideal_yaw && self->monsterinfo.aiflags & AI_TEMP_STAND_GROUND) { self->monsterinfo.aiflags &= ~(AI_STAND_GROUND | AI_TEMP_STAND_GROUND); - self->monsterinfo.run (self); + self->monsterinfo.run(self); } - M_ChangeYaw (self); - ai_checkattack (self, 0); - } - else - FindTarget (self); + M_ChangeYaw(self); + ai_checkattack(self, 0); + } else + FindTarget(self); return; } - if (FindTarget (self)) + if (FindTarget(self)) return; - - if (level.time > self->monsterinfo.pausetime) - { - self->monsterinfo.walk (self); + + if (level.time > self->monsterinfo.pausetime) { + self->monsterinfo.walk(self); return; } - if (!(self->spawnflags & 1) && (self->monsterinfo.idle) && (level.time > self->monsterinfo.idle_time)) - { - if (self->monsterinfo.idle_time) - { - self->monsterinfo.idle (self); + if (!(self->spawnflags & 1) && (self->monsterinfo.idle) && (level.time > self->monsterinfo.idle_time)) { + if (self->monsterinfo.idle_time) { + self->monsterinfo.idle(self); self->monsterinfo.idle_time = level.time + 15 + random() * 15; - } - else - { + } else { self->monsterinfo.idle_time = level.time + random() * 15; } } @@ -160,23 +148,19 @@ ai_walk The monster is walking it's beat ============= */ -void ai_walk (edict_t *self, float dist) +void ai_walk(edict_t *self, float dist) { - M_MoveToGoal (self, dist); + M_MoveToGoal(self, dist); // check for noticing a player - if (FindTarget (self)) + if (FindTarget(self)) return; - if ((self->monsterinfo.search) && (level.time > self->monsterinfo.idle_time)) - { - if (self->monsterinfo.idle_time) - { - self->monsterinfo.search (self); + if ((self->monsterinfo.search) && (level.time > self->monsterinfo.idle_time)) { + if (self->monsterinfo.idle_time) { + self->monsterinfo.search(self); self->monsterinfo.idle_time = level.time + 15 + random() * 15; - } - else - { + } else { self->monsterinfo.idle_time = level.time + random() * 15; } } @@ -191,16 +175,16 @@ Turns towards target and advances Use this call with a distnace of 0 to replace ai_face ============== */ -void ai_charge (edict_t *self, float dist) +void ai_charge(edict_t *self, float dist) { vec3_t v; - VectorSubtract (self->enemy->s.origin, self->s.origin, v); + VectorSubtract(self->enemy->s.origin, self->s.origin, v); self->ideal_yaw = vectoyaw(v); - M_ChangeYaw (self); + M_ChangeYaw(self); if (dist) - M_walkmove (self, self->s.angles[YAW], dist); + M_walkmove(self, self->s.angles[YAW], dist); } @@ -212,15 +196,15 @@ don't move, but turn towards ideal_yaw Distance is for slight position adjustments needed by the animations ============= */ -void ai_turn (edict_t *self, float dist) +void ai_turn(edict_t *self, float dist) { if (dist) - M_walkmove (self, self->s.angles[YAW], dist); + M_walkmove(self, self->s.angles[YAW], dist); - if (FindTarget (self)) + if (FindTarget(self)) return; - - M_ChangeYaw (self); + + M_ChangeYaw(self); } @@ -261,13 +245,13 @@ returns the range catagorization of an entity reletive to self 3 only triggered by damage ============= */ -int range (edict_t *self, edict_t *other) +int range(edict_t *self, edict_t *other) { vec3_t v; float len; - VectorSubtract (self->s.origin, other->s.origin, v); - len = VectorLength (v); + VectorSubtract(self->s.origin, other->s.origin, v); + len = VectorLength(v); if (len < MELEE_DISTANCE) return RANGE_MELEE; if (len < 500) @@ -284,18 +268,18 @@ visible returns 1 if the entity is visible to self, even if not infront () ============= */ -qboolean visible (edict_t *self, edict_t *other) +qboolean visible(edict_t *self, edict_t *other) { vec3_t spot1; vec3_t spot2; trace_t trace; - VectorCopy (self->s.origin, spot1); + VectorCopy(self->s.origin, spot1); spot1[2] += self->viewheight; - VectorCopy (other->s.origin, spot2); + VectorCopy(other->s.origin, spot2); spot2[2] += other->viewheight; - trace = gi.trace (spot1, vec3_origin, vec3_origin, spot2, self, MASK_OPAQUE); - + trace = gi.trace(spot1, vec3_origin, vec3_origin, spot2, self, MASK_OPAQUE); + if (trace.fraction == 1.0) return qtrue; return qfalse; @@ -309,17 +293,17 @@ infront returns 1 if the entity is in front (in sight) of self ============= */ -qboolean infront (edict_t *self, edict_t *other) +qboolean infront(edict_t *self, edict_t *other) { vec3_t vec; float dot; vec3_t forward; - - AngleVectors (self->s.angles, forward, NULL, NULL); - VectorSubtract (other->s.origin, self->s.origin, vec); - VectorNormalize (vec); - dot = DotProduct (vec, forward); - + + AngleVectors(self->s.angles, forward, NULL, NULL); + VectorSubtract(other->s.origin, self->s.origin, vec); + VectorNormalize(vec); + dot = DotProduct(vec, forward); + if (dot > 0.3) return qtrue; return qfalse; @@ -328,27 +312,26 @@ qboolean infront (edict_t *self, edict_t *other) //============================================================================ -void HuntTarget (edict_t *self) +void HuntTarget(edict_t *self) { vec3_t vec; self->goalentity = self->enemy; if (self->monsterinfo.aiflags & AI_STAND_GROUND) - self->monsterinfo.stand (self); + self->monsterinfo.stand(self); else - self->monsterinfo.run (self); - VectorSubtract (self->enemy->s.origin, self->s.origin, vec); + self->monsterinfo.run(self); + VectorSubtract(self->enemy->s.origin, self->s.origin, vec); self->ideal_yaw = vectoyaw(vec); // wait a while before first attack if (!(self->monsterinfo.aiflags & AI_STAND_GROUND)) - AttackFinished (self, 1); + AttackFinished(self, 1); } -void FoundTarget (edict_t *self) +void FoundTarget(edict_t *self) { // let other monsters see this monster for a while - if (self->enemy->client) - { + if (self->enemy->client) { level.sight_entity = self; level.sight_entity_framenum = level.framenum; level.sight_entity->light_level = 128; @@ -359,17 +342,15 @@ void FoundTarget (edict_t *self) VectorCopy(self->enemy->s.origin, self->monsterinfo.last_sighting); self->monsterinfo.trail_time = level.time; - if (!self->combattarget) - { - HuntTarget (self); + if (!self->combattarget) { + HuntTarget(self); return; } self->goalentity = self->movetarget = G_PickTarget(self->combattarget); - if (!self->movetarget) - { + if (!self->movetarget) { self->goalentity = self->movetarget = self->enemy; - HuntTarget (self); + HuntTarget(self); gi.dprintf("%s at %s, combattarget %s not found\n", self->classname, vtos(self->s.origin), self->combattarget); return; } @@ -383,7 +364,7 @@ void FoundTarget (edict_t *self) self->monsterinfo.pausetime = 0; // run for it - self->monsterinfo.run (self); + self->monsterinfo.run(self); } @@ -404,16 +385,14 @@ checked each frame. This means multi player games will have slightly slower noticing monsters. ============ */ -qboolean FindTarget (edict_t *self) +qboolean FindTarget(edict_t *self) { edict_t *client; qboolean heardit; int r; - if (self->monsterinfo.aiflags & AI_GOOD_GUY) - { - if (self->goalentity && self->goalentity->inuse && self->goalentity->classname) - { + if (self->monsterinfo.aiflags & AI_GOOD_GUY) { + if (self->goalentity && self->goalentity->inuse && self->goalentity->classname) { if (strcmp(self->goalentity->classname, "target_actor") == 0) return qfalse; } @@ -434,26 +413,18 @@ qboolean FindTarget (edict_t *self) // but not weapon impact/explosion noises heardit = qfalse; - if ((level.sight_entity_framenum >= (level.framenum - 1)) && !(self->spawnflags & 1) ) - { + if ((level.sight_entity_framenum >= (level.framenum - 1)) && !(self->spawnflags & 1)) { client = level.sight_entity; - if (client->enemy == self->enemy) - { + if (client->enemy == self->enemy) { return qfalse; } - } - else if (level.sound_entity_framenum >= (level.framenum - 1)) - { + } else if (level.sound_entity_framenum >= (level.framenum - 1)) { client = level.sound_entity; heardit = qtrue; - } - else if (!(self->enemy) && (level.sound2_entity_framenum >= (level.framenum - 1)) && !(self->spawnflags & 1) ) - { + } else if (!(self->enemy) && (level.sound2_entity_framenum >= (level.framenum - 1)) && !(self->spawnflags & 1)) { client = level.sound2_entity; heardit = qtrue; - } - else - { + } else { client = level.sight_client; if (!client) return qfalse; // no clients to get mad at @@ -466,29 +437,22 @@ qboolean FindTarget (edict_t *self) if (client == self->enemy) return qtrue; // JDC qfalse; - if (client->client) - { + if (client->client) { if (client->flags & FL_NOTARGET) return qfalse; - } - else if (client->svflags & SVF_MONSTER) - { + } else if (client->svflags & SVF_MONSTER) { if (!client->enemy) return qfalse; if (client->enemy->flags & FL_NOTARGET) return qfalse; - } - else if (heardit) - { + } else if (heardit) { if (client->owner->flags & FL_NOTARGET) return qfalse; - } - else + } else return qfalse; - if (!heardit) - { - r = range (self, client); + if (!heardit) { + r = range(self, client); if (r == RANGE_FAR) return qfalse; @@ -499,62 +463,47 @@ qboolean FindTarget (edict_t *self) if (client->light_level <= 5) return qfalse; - if (!visible (self, client)) - { + if (!visible(self, client)) { return qfalse; } - if (r == RANGE_NEAR) - { - if (client->show_hostile < level.time && !infront (self, client)) - { + if (r == RANGE_NEAR) { + if (client->show_hostile < level.time && !infront(self, client)) { return qfalse; } - } - else if (r == RANGE_MID) - { - if (!infront (self, client)) - { + } else if (r == RANGE_MID) { + if (!infront(self, client)) { return qfalse; } } self->enemy = client; - if (strcmp(self->enemy->classname, "player_noise") != 0) - { + if (strcmp(self->enemy->classname, "player_noise") != 0) { self->monsterinfo.aiflags &= ~AI_SOUND_TARGET; - if (!self->enemy->client) - { + if (!self->enemy->client) { self->enemy = self->enemy->enemy; - if (!self->enemy->client) - { + if (!self->enemy->client) { self->enemy = NULL; return qfalse; } } } - } - else // heardit - { + } else { // heardit vec3_t temp; - if (self->spawnflags & 1) - { - if (!visible (self, client)) + if (self->spawnflags & 1) { + if (!visible(self, client)) return qfalse; - } - else - { + } else { if (!gi.inPHS(self->s.origin, client->s.origin)) return qfalse; } - VectorSubtract (client->s.origin, self->s.origin, temp); + VectorSubtract(client->s.origin, self->s.origin, temp); - if (VectorLength(temp) > 1000) // too far to hear - { + if (VectorLength(temp) > 1000) { // too far to hear return qfalse; } @@ -564,7 +513,7 @@ qboolean FindTarget (edict_t *self) return qfalse; self->ideal_yaw = vectoyaw(temp); - M_ChangeYaw (self); + M_ChangeYaw(self); // hunt the sound for a bit; hopefully find the real player self->monsterinfo.aiflags |= AI_SOUND_TARGET; @@ -574,10 +523,10 @@ qboolean FindTarget (edict_t *self) // // got one // - FoundTarget (self); + FoundTarget(self); if (!(self->monsterinfo.aiflags & AI_SOUND_TARGET) && (self->monsterinfo.sight)) - self->monsterinfo.sight (self, self->enemy); + self->monsterinfo.sight(self, self->enemy); return qtrue; } @@ -604,32 +553,30 @@ qboolean FacingIdeal(edict_t *self) //============================================================================= -qboolean M_CheckAttack (edict_t *self) +qboolean M_CheckAttack(edict_t *self) { vec3_t spot1, spot2; float chance; trace_t tr; - if (self->enemy->health > 0) - { - // see if any entities are in the way of the shot - VectorCopy (self->s.origin, spot1); + if (self->enemy->health > 0) { + // see if any entities are in the way of the shot + VectorCopy(self->s.origin, spot1); spot1[2] += self->viewheight; - VectorCopy (self->enemy->s.origin, spot2); + VectorCopy(self->enemy->s.origin, spot2); spot2[2] += self->enemy->viewheight; - tr = gi.trace (spot1, NULL, NULL, spot2, self, CONTENTS_SOLID|CONTENTS_MONSTER|CONTENTS_SLIME|CONTENTS_LAVA|CONTENTS_WINDOW); + tr = gi.trace(spot1, NULL, NULL, spot2, self, CONTENTS_SOLID | CONTENTS_MONSTER | CONTENTS_SLIME | CONTENTS_LAVA | CONTENTS_WINDOW); // do we have a clear shot? if (tr.ent != self->enemy) return qfalse; } - + // melee attack - if (enemy_range == RANGE_MELEE) - { + if (enemy_range == RANGE_MELEE) { // don't always melee in easy mode - if (skill->value == 0 && (rand()&3) ) + if (skill->value == 0 && (rand() & 3)) return qfalse; if (self->monsterinfo.melee) self->monsterinfo.attack_state = AS_MELEE; @@ -637,35 +584,26 @@ qboolean M_CheckAttack (edict_t *self) self->monsterinfo.attack_state = AS_MISSILE; return qtrue; } - + // missile attack if (!self->monsterinfo.attack) return qfalse; - + if (level.time < self->monsterinfo.attack_finished) return qfalse; - + if (enemy_range == RANGE_FAR) return qfalse; - if (self->monsterinfo.aiflags & AI_STAND_GROUND) - { + if (self->monsterinfo.aiflags & AI_STAND_GROUND) { chance = 0.4; - } - else if (enemy_range == RANGE_MELEE) - { + } else if (enemy_range == RANGE_MELEE) { chance = 0.2; - } - else if (enemy_range == RANGE_NEAR) - { + } else if (enemy_range == RANGE_NEAR) { chance = 0.1; - } - else if (enemy_range == RANGE_MID) - { + } else if (enemy_range == RANGE_MID) { chance = 0.02; - } - else - { + } else { return qfalse; } @@ -674,15 +612,13 @@ qboolean M_CheckAttack (edict_t *self) else if (skill->value >= 2) chance *= 2; - if (random () < chance) - { + if (random() < chance) { self->monsterinfo.attack_state = AS_MISSILE; - self->monsterinfo.attack_finished = level.time + 2*random(); + self->monsterinfo.attack_finished = level.time + 2 * random(); return qtrue; } - if (self->flags & FL_FLY) - { + if (self->flags & FL_FLY) { if (random() < 0.3) self->monsterinfo.attack_state = AS_SLIDING; else @@ -703,11 +639,10 @@ Turn and close until within an angle to launch a melee attack void ai_run_melee(edict_t *self) { self->ideal_yaw = enemy_yaw; - M_ChangeYaw (self); + M_ChangeYaw(self); - if (FacingIdeal(self)) - { - self->monsterinfo.melee (self); + if (FacingIdeal(self)) { + self->monsterinfo.melee(self); self->monsterinfo.attack_state = AS_STRAIGHT; } } @@ -723,11 +658,10 @@ Turn in place until within an angle to launch a missile attack void ai_run_missile(edict_t *self) { self->ideal_yaw = enemy_yaw; - M_ChangeYaw (self); + M_ChangeYaw(self); - if (FacingIdeal(self)) - { - self->monsterinfo.attack (self); + if (FacingIdeal(self)) { + self->monsterinfo.attack(self); self->monsterinfo.attack_state = AS_STRAIGHT; } }; @@ -743,20 +677,20 @@ Strafe sideways, but stay at aproximately the same range void ai_run_slide(edict_t *self, float distance) { float ofs; - + self->ideal_yaw = enemy_yaw; - M_ChangeYaw (self); + M_ChangeYaw(self); if (self->monsterinfo.lefty) ofs = 90; else ofs = -90; - - if (M_walkmove (self, self->ideal_yaw + ofs, distance)) + + if (M_walkmove(self, self->ideal_yaw + ofs, distance)) return; - + self->monsterinfo.lefty = 1 - self->monsterinfo.lefty; - M_walkmove (self, self->ideal_yaw - ofs, distance); + M_walkmove(self, self->ideal_yaw - ofs, distance); } @@ -768,23 +702,19 @@ Decides if we're going to attack or do something else used by ai_run and ai_stand ============= */ -qboolean ai_checkattack (edict_t *self, float dist) +qboolean ai_checkattack(edict_t *self, float dist) { vec3_t temp; qboolean hesDeadJim; // this causes monsters to run blindly to the combat point w/o firing - if (self->goalentity) - { + if (self->goalentity) { if (self->monsterinfo.aiflags & AI_COMBAT_POINT) return qfalse; - if (self->monsterinfo.aiflags & AI_SOUND_TARGET) - { - if ((level.time - self->enemy->teleport_time) > 5.0) - { - if (self->goalentity == self->enemy) - { + if (self->monsterinfo.aiflags & AI_SOUND_TARGET) { + if ((level.time - self->enemy->teleport_time) > 5.0) { + if (self->goalentity == self->enemy) { if (self->movetarget) self->goalentity = self->movetarget; else @@ -793,9 +723,7 @@ qboolean ai_checkattack (edict_t *self, float dist) self->monsterinfo.aiflags &= ~AI_SOUND_TARGET; if (self->monsterinfo.aiflags & AI_TEMP_STAND_GROUND) self->monsterinfo.aiflags &= ~(AI_STAND_GROUND | AI_TEMP_STAND_GROUND); - } - else - { + } else { self->show_hostile = level.time + 1; return qfalse; } @@ -806,57 +734,41 @@ qboolean ai_checkattack (edict_t *self, float dist) // see if the enemy is dead hesDeadJim = qfalse; - if ((!self->enemy) || (!self->enemy->inuse)) - { + if ((!self->enemy) || (!self->enemy->inuse)) { hesDeadJim = qtrue; - } - else if (self->monsterinfo.aiflags & AI_MEDIC) - { - if (self->enemy->health > 0) - { + } else if (self->monsterinfo.aiflags & AI_MEDIC) { + if (self->enemy->health > 0) { hesDeadJim = qtrue; self->monsterinfo.aiflags &= ~AI_MEDIC; } - } - else - { - if (self->monsterinfo.aiflags & AI_BRUTAL) - { + } else { + if (self->monsterinfo.aiflags & AI_BRUTAL) { if (self->enemy->health <= -80) hesDeadJim = qtrue; - } - else - { + } else { if (self->enemy->health <= 0) hesDeadJim = qtrue; } } - if (hesDeadJim) - { + if (hesDeadJim) { self->enemy = NULL; - // FIXME: look all around for other targets - if (self->oldenemy && self->oldenemy->health > 0) - { + // FIXME: look all around for other targets + if (self->oldenemy && self->oldenemy->health > 0) { self->enemy = self->oldenemy; self->oldenemy = NULL; - HuntTarget (self); - } - else - { - if (self->movetarget) - { + HuntTarget(self); + } else { + if (self->movetarget) { self->goalentity = self->movetarget; - self->monsterinfo.walk (self); - } - else - { + self->monsterinfo.walk(self); + } else { // we need the pausetime otherwise the stand code // will just revert to walking with no target and // the monsters will wonder around aimlessly trying // to hunt the world entity self->monsterinfo.pausetime = level.time + 100000000; - self->monsterinfo.stand (self); + self->monsterinfo.stand(self); } return qtrue; } @@ -866,10 +778,9 @@ qboolean ai_checkattack (edict_t *self, float dist) // check knowledge of enemy enemy_vis = visible(self, self->enemy); - if (enemy_vis) - { + if (enemy_vis) { self->monsterinfo.search_time = level.time + 5; - VectorCopy (self->enemy->s.origin, self->monsterinfo.last_sighting); + VectorCopy(self->enemy->s.origin, self->monsterinfo.last_sighting); } // look for other coop players here @@ -881,20 +792,18 @@ qboolean ai_checkattack (edict_t *self, float dist) enemy_infront = infront(self, self->enemy); enemy_range = range(self, self->enemy); - VectorSubtract (self->enemy->s.origin, self->s.origin, temp); + VectorSubtract(self->enemy->s.origin, self->s.origin, temp); enemy_yaw = vectoyaw(temp); // JDC self->ideal_yaw = enemy_yaw; - if (self->monsterinfo.attack_state == AS_MISSILE) - { - ai_run_missile (self); + if (self->monsterinfo.attack_state == AS_MISSILE) { + ai_run_missile(self); return qtrue; } - if (self->monsterinfo.attack_state == AS_MELEE) - { - ai_run_melee (self); + if (self->monsterinfo.attack_state == AS_MELEE) { + ai_run_melee(self); return qtrue; } @@ -902,7 +811,7 @@ qboolean ai_checkattack (edict_t *self, float dist) if (!enemy_vis) return qfalse; - return self->monsterinfo.checkattack (self); + return self->monsterinfo.checkattack(self); } @@ -913,7 +822,7 @@ ai_run The monster has an enemy it is trying to kill ============= */ -void ai_run (edict_t *self, float dist) +void ai_run(edict_t *self, float dist) { vec3_t v; edict_t *tempgoal; @@ -927,58 +836,52 @@ void ai_run (edict_t *self, float dist) vec3_t left_target, right_target; // if we're going to a combat point, just proceed - if (self->monsterinfo.aiflags & AI_COMBAT_POINT) - { - M_MoveToGoal (self, dist); + if (self->monsterinfo.aiflags & AI_COMBAT_POINT) { + M_MoveToGoal(self, dist); return; } - if (self->monsterinfo.aiflags & AI_SOUND_TARGET) - { - VectorSubtract (self->s.origin, self->enemy->s.origin, v); - if (VectorLength(v) < 64) - { + if (self->monsterinfo.aiflags & AI_SOUND_TARGET) { + VectorSubtract(self->s.origin, self->enemy->s.origin, v); + if (VectorLength(v) < 64) { self->monsterinfo.aiflags |= (AI_STAND_GROUND | AI_TEMP_STAND_GROUND); - self->monsterinfo.stand (self); + self->monsterinfo.stand(self); return; } - M_MoveToGoal (self, dist); + M_MoveToGoal(self, dist); - if (!FindTarget (self)) + if (!FindTarget(self)) return; } - if (ai_checkattack (self, dist)) + if (ai_checkattack(self, dist)) return; - if (self->monsterinfo.attack_state == AS_SLIDING) - { - ai_run_slide (self, dist); + if (self->monsterinfo.attack_state == AS_SLIDING) { + ai_run_slide(self, dist); return; } - if (enemy_vis) - { + if (enemy_vis) { // if (self.aiflags & AI_LOST_SIGHT) // dprint("regained sight\n"); - M_MoveToGoal (self, dist); + M_MoveToGoal(self, dist); self->monsterinfo.aiflags &= ~AI_LOST_SIGHT; - VectorCopy (self->enemy->s.origin, self->monsterinfo.last_sighting); + VectorCopy(self->enemy->s.origin, self->monsterinfo.last_sighting); self->monsterinfo.trail_time = level.time; return; } // coop will change to another enemy if visible - if (coop->value) - { // FIXME: insane guys get mad with this, which causes crashes! - if (FindTarget (self)) + if (coop->value) { + // FIXME: insane guys get mad with this, which causes crashes! + if (FindTarget(self)) return; } - if ((self->monsterinfo.search_time) && (level.time > (self->monsterinfo.search_time + 20))) - { - M_MoveToGoal (self, dist); + if ((self->monsterinfo.search_time) && (level.time > (self->monsterinfo.search_time + 20))) { + M_MoveToGoal(self, dist); self->monsterinfo.search_time = 0; // dprint("search timeout\n"); return; @@ -990,8 +893,7 @@ void ai_run (edict_t *self, float dist) new = qfalse; - if (!(self->monsterinfo.aiflags & AI_LOST_SIGHT)) - { + if (!(self->monsterinfo.aiflags & AI_LOST_SIGHT)) { // just lost sight of the player, decide where to go first // dprint("lost sight of player, last seen at "); dprint(vtos(self.last_sighting)); dprint("\n"); self->monsterinfo.aiflags |= (AI_LOST_SIGHT | AI_PURSUIT_LAST_SEEN); @@ -999,35 +901,28 @@ void ai_run (edict_t *self, float dist) new = qtrue; } - if (self->monsterinfo.aiflags & AI_PURSUE_NEXT) - { + if (self->monsterinfo.aiflags & AI_PURSUE_NEXT) { self->monsterinfo.aiflags &= ~AI_PURSUE_NEXT; // dprint("reached current goal: "); dprint(vtos(self.origin)); dprint(" "); dprint(vtos(self.last_sighting)); dprint(" "); dprint(ftos(vlen(self.origin - self.last_sighting))); dprint("\n"); // give ourself more time since we got this far self->monsterinfo.search_time = level.time + 5; - if (self->monsterinfo.aiflags & AI_PURSUE_TEMP) - { + if (self->monsterinfo.aiflags & AI_PURSUE_TEMP) { // dprint("was temp goal; retrying original\n"); self->monsterinfo.aiflags &= ~AI_PURSUE_TEMP; marker = NULL; - VectorCopy (self->monsterinfo.saved_goal, self->monsterinfo.last_sighting); + VectorCopy(self->monsterinfo.saved_goal, self->monsterinfo.last_sighting); new = qtrue; - } - else if (self->monsterinfo.aiflags & AI_PURSUIT_LAST_SEEN) - { + } else if (self->monsterinfo.aiflags & AI_PURSUIT_LAST_SEEN) { self->monsterinfo.aiflags &= ~AI_PURSUIT_LAST_SEEN; - marker = PlayerTrail_PickFirst (self); - } - else - { - marker = PlayerTrail_PickNext (self); + marker = PlayerTrail_PickFirst(self); + } else { + marker = PlayerTrail_PickNext(self); } - if (marker) - { - VectorCopy (marker->s.origin, self->monsterinfo.last_sighting); + if (marker) { + VectorCopy(marker->s.origin, self->monsterinfo.last_sighting); self->monsterinfo.trail_time = marker->timestamp; self->s.angles[YAW] = self->ideal_yaw = marker->s.angles[YAW]; // dprint("heading is "); dprint(ftos(self.ideal_yaw)); dprint("\n"); @@ -1037,71 +932,63 @@ void ai_run (edict_t *self, float dist) } } - VectorSubtract (self->s.origin, self->monsterinfo.last_sighting, v); + VectorSubtract(self->s.origin, self->monsterinfo.last_sighting, v); d1 = VectorLength(v); - if (d1 <= dist) - { + if (d1 <= dist) { self->monsterinfo.aiflags |= AI_PURSUE_NEXT; dist = d1; } - VectorCopy (self->monsterinfo.last_sighting, self->goalentity->s.origin); + VectorCopy(self->monsterinfo.last_sighting, self->goalentity->s.origin); - if (new) - { + if (new) { // gi.dprintf("checking for course correction\n"); tr = gi.trace(self->s.origin, self->mins, self->maxs, self->monsterinfo.last_sighting, self, MASK_PLAYERSOLID); - if (tr.fraction < 1) - { - VectorSubtract (self->goalentity->s.origin, self->s.origin, v); + if (tr.fraction < 1) { + VectorSubtract(self->goalentity->s.origin, self->s.origin, v); d1 = VectorLength(v); center = tr.fraction; - d2 = d1 * ((center+1)/2); + d2 = d1 * ((center + 1) / 2); self->s.angles[YAW] = self->ideal_yaw = vectoyaw(v); AngleVectors(self->s.angles, v_forward, v_right, NULL); VectorSet(v, d2, -16, 0); - G_ProjectSource (self->s.origin, v, v_forward, v_right, left_target); + G_ProjectSource(self->s.origin, v, v_forward, v_right, left_target); tr = gi.trace(self->s.origin, self->mins, self->maxs, left_target, self, MASK_PLAYERSOLID); left = tr.fraction; VectorSet(v, d2, 16, 0); - G_ProjectSource (self->s.origin, v, v_forward, v_right, right_target); + G_ProjectSource(self->s.origin, v, v_forward, v_right, right_target); tr = gi.trace(self->s.origin, self->mins, self->maxs, right_target, self, MASK_PLAYERSOLID); right = tr.fraction; - center = (d1*center)/d2; - if (left >= center && left > right) - { - if (left < 1) - { + center = (d1 * center) / d2; + if (left >= center && left > right) { + if (left < 1) { VectorSet(v, d2 * left * 0.5, -16, 0); - G_ProjectSource (self->s.origin, v, v_forward, v_right, left_target); + G_ProjectSource(self->s.origin, v, v_forward, v_right, left_target); // gi.dprintf("incomplete path, go part way and adjust again\n"); } - VectorCopy (self->monsterinfo.last_sighting, self->monsterinfo.saved_goal); + VectorCopy(self->monsterinfo.last_sighting, self->monsterinfo.saved_goal); self->monsterinfo.aiflags |= AI_PURSUE_TEMP; - VectorCopy (left_target, self->goalentity->s.origin); - VectorCopy (left_target, self->monsterinfo.last_sighting); - VectorSubtract (self->goalentity->s.origin, self->s.origin, v); + VectorCopy(left_target, self->goalentity->s.origin); + VectorCopy(left_target, self->monsterinfo.last_sighting); + VectorSubtract(self->goalentity->s.origin, self->s.origin, v); self->s.angles[YAW] = self->ideal_yaw = vectoyaw(v); // gi.dprintf("adjusted left\n"); // debug_drawline(self.origin, self.last_sighting, 152); - } - else if (right >= center && right > left) - { - if (right < 1) - { + } else if (right >= center && right > left) { + if (right < 1) { VectorSet(v, d2 * right * 0.5, 16, 0); - G_ProjectSource (self->s.origin, v, v_forward, v_right, right_target); + G_ProjectSource(self->s.origin, v, v_forward, v_right, right_target); // gi.dprintf("incomplete path, go part way and adjust again\n"); } - VectorCopy (self->monsterinfo.last_sighting, self->monsterinfo.saved_goal); + VectorCopy(self->monsterinfo.last_sighting, self->monsterinfo.saved_goal); self->monsterinfo.aiflags |= AI_PURSUE_TEMP; - VectorCopy (right_target, self->goalentity->s.origin); - VectorCopy (right_target, self->monsterinfo.last_sighting); - VectorSubtract (self->goalentity->s.origin, self->s.origin, v); + VectorCopy(right_target, self->goalentity->s.origin); + VectorCopy(right_target, self->monsterinfo.last_sighting); + VectorSubtract(self->goalentity->s.origin, self->s.origin, v); self->s.angles[YAW] = self->ideal_yaw = vectoyaw(v); // gi.dprintf("adjusted right\n"); // debug_drawline(self.origin, self.last_sighting, 152); @@ -1110,7 +997,7 @@ void ai_run (edict_t *self, float dist) // else gi.dprintf("course was fine\n"); } - M_MoveToGoal (self, dist); + M_MoveToGoal(self, dist); G_FreeEdict(tempgoal); |