From 2b4f223566ecd9f654412ca0d2ae73dc7d12db46 Mon Sep 17 00:00:00 2001 From: Yamagi Burmeister Date: Fri, 30 Sep 2011 09:04:35 +0000 Subject: [PATCH] Rework g_monster.c again and add sanity checks. Some minor bugs were fixed too: - Comment two lines back in which were removed by id. They SEEM to bee correct - Slime shouldn't destroy dead monsters (this was lost some versions ago) --- src/game/baseq2/g_monster.c | 905 ++++++++++++++++++++++++------------ 1 file changed, 614 insertions(+), 291 deletions(-) diff --git a/src/game/baseq2/g_monster.c b/src/game/baseq2/g_monster.c index 420bf116..9c98c4e0 100644 --- a/src/game/baseq2/g_monster.c +++ b/src/game/baseq2/g_monster.c @@ -1,150 +1,239 @@ /* -Copyright (C) 1997-2001 Id Software, Inc. + * Copyright (C) 1997-2001 Id Software, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 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. + * + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * ======================================================================= + * + * Monster utility functions. + * + * ======================================================================= + */ -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -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. - -See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ #include "g_local.h" +void monster_start_go(edict_t *self); -// -// monster weapons -// +/* Monster weapons */ -//FIXME monsters should call these with a totally accurate direction -// and we can mess it up based on skill. Spread should be for normal -// and we can tighten or loosen based on skill. We could muck with -// the damages too, but I'm not sure that's such a good idea. -void monster_fire_bullet (edict_t *self, vec3_t start, vec3_t dir, int damage, int kick, int hspread, int vspread, int flashtype) -{ - fire_bullet (self, start, dir, damage, kick, hspread, vspread, MOD_UNKNOWN); +void +monster_fire_bullet(edict_t *self, vec3_t start, vec3_t dir, int damage, + int kick, int hspread, int vspread, int flashtype) +{ + if (!self) + { + return; + } + + fire_bullet(self, start, dir, damage, kick, hspread, vspread, MOD_UNKNOWN); - gi.WriteByte (svc_muzzleflash2); - gi.WriteShort (self - g_edicts); - gi.WriteByte (flashtype); - gi.multicast (start, MULTICAST_PVS); + gi.WriteByte(svc_muzzleflash2); + gi.WriteShort(self - g_edicts); + gi.WriteByte(flashtype); + gi.multicast(start, MULTICAST_PVS); } -void monster_fire_shotgun (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick, int hspread, int vspread, int count, int flashtype) -{ - fire_shotgun (self, start, aimdir, damage, kick, hspread, vspread, count, MOD_UNKNOWN); +void +monster_fire_shotgun(edict_t *self, vec3_t start, vec3_t aimdir, int damage, + int kick, int hspread, int vspread, int count, int flashtype) +{ + if (!self) + { + return; + } + + fire_shotgun(self, start, aimdir, damage, kick, hspread, + vspread, count, MOD_UNKNOWN); - gi.WriteByte (svc_muzzleflash2); - gi.WriteShort (self - g_edicts); - gi.WriteByte (flashtype); - gi.multicast (start, MULTICAST_PVS); + gi.WriteByte(svc_muzzleflash2); + gi.WriteShort(self - g_edicts); + gi.WriteByte(flashtype); + gi.multicast(start, MULTICAST_PVS); } -void monster_fire_blaster (edict_t *self, vec3_t start, vec3_t dir, int damage, int speed, int flashtype, int effect) -{ - fire_blaster (self, start, dir, damage, speed, effect, false); +void +monster_fire_blaster(edict_t *self, vec3_t start, vec3_t dir, int damage, + int speed, int flashtype, int effect) +{ + if (!self) + { + return; + } + + fire_blaster(self, start, dir, damage, speed, effect, false); - gi.WriteByte (svc_muzzleflash2); - gi.WriteShort (self - g_edicts); - gi.WriteByte (flashtype); - gi.multicast (start, MULTICAST_PVS); -} - -void monster_fire_grenade (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int speed, int flashtype) -{ - fire_grenade (self, start, aimdir, damage, speed, 2.5, damage+40); - - gi.WriteByte (svc_muzzleflash2); - gi.WriteShort (self - g_edicts); - gi.WriteByte (flashtype); - gi.multicast (start, MULTICAST_PVS); + gi.WriteByte(svc_muzzleflash2); + gi.WriteShort(self - g_edicts); + gi.WriteByte(flashtype); + gi.multicast(start, MULTICAST_PVS); } -void monster_fire_rocket (edict_t *self, vec3_t start, vec3_t dir, int damage, int speed, int flashtype) -{ - fire_rocket (self, start, dir, damage, speed, damage+20, damage); +void +monster_fire_grenade(edict_t *self, vec3_t start, vec3_t aimdir, + int damage, int speed, int flashtype) +{ + if (!self) + { + return; + } + + fire_grenade(self, start, aimdir, damage, speed, 2.5, damage + 40); - gi.WriteByte (svc_muzzleflash2); - gi.WriteShort (self - g_edicts); - gi.WriteByte (flashtype); - gi.multicast (start, MULTICAST_PVS); -} - -void monster_fire_railgun (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick, int flashtype) -{ - fire_rail (self, start, aimdir, damage, kick); - - gi.WriteByte (svc_muzzleflash2); - gi.WriteShort (self - g_edicts); - gi.WriteByte (flashtype); - gi.multicast (start, MULTICAST_PVS); + gi.WriteByte(svc_muzzleflash2); + gi.WriteShort(self - g_edicts); + gi.WriteByte(flashtype); + gi.multicast(start, MULTICAST_PVS); } -void monster_fire_bfg (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int speed, int kick, float damage_radius, int flashtype) -{ - fire_bfg (self, start, aimdir, damage, speed, damage_radius); +void +monster_fire_rocket(edict_t *self, vec3_t start, vec3_t dir, + int damage, int speed, int flashtype) +{ + if (!self) + { + return; + } + + fire_rocket(self, start, dir, damage, speed, damage + 20, damage); - gi.WriteByte (svc_muzzleflash2); - gi.WriteShort (self - g_edicts); - gi.WriteByte (flashtype); - gi.multicast (start, MULTICAST_PVS); + gi.WriteByte(svc_muzzleflash2); + gi.WriteShort(self - g_edicts); + gi.WriteByte(flashtype); + gi.multicast(start, MULTICAST_PVS); } +void +monster_fire_railgun(edict_t *self, vec3_t start, vec3_t aimdir, + int damage, int kick, int flashtype) +{ + if (!self) + { + return; + } + + fire_rail(self, start, aimdir, damage, kick); + gi.WriteByte(svc_muzzleflash2); + gi.WriteShort(self - g_edicts); + gi.WriteByte(flashtype); + gi.multicast(start, MULTICAST_PVS); +} -// -// Monster utility functions -// +void +monster_fire_bfg(edict_t *self, vec3_t start, vec3_t aimdir, + int damage, int speed, int kick /* unused */, float damage_radius, + int flashtype) +{ + if (!self) + { + return; + } + + fire_bfg(self, start, aimdir, damage, speed, damage_radius); -static void M_FliesOff (edict_t *self) -{ + gi.WriteByte(svc_muzzleflash2); + gi.WriteShort(self - g_edicts); + gi.WriteByte(flashtype); + gi.multicast(start, MULTICAST_PVS); +} + +/* ================================================================== */ + +/* Monster utility functions */ + +static void +M_FliesOff(edict_t *self) +{ + if (!self) + { + return; + } + self->s.effects &= ~EF_FLIES; self->s.sound = 0; } -static void M_FliesOn (edict_t *self) -{ - if (self->waterlevel) +static void +M_FliesOn(edict_t *self) +{ + if (!self) + { return; + } + + if (self->waterlevel) + { + return; + } + self->s.effects |= EF_FLIES; - self->s.sound = gi.soundindex ("infantry/inflies1.wav"); + self->s.sound = gi.soundindex("infantry/inflies1.wav"); self->think = M_FliesOff; self->nextthink = level.time + 60; } -void M_FlyCheck (edict_t *self) -{ - if (self->waterlevel) +void +M_FlyCheck(edict_t *self) +{ + if (!self) + { return; + } + + if (self->waterlevel) + { + return; + } if (random() > 0.5) + { return; + } self->think = M_FliesOn; self->nextthink = level.time + 5 + 10 * random(); } -void AttackFinished (edict_t *self, float time) -{ +void +AttackFinished(edict_t *self, float time) +{ + if (!self) + { + return; + } + self->monsterinfo.attack_finished = level.time + time; } - -void M_CheckGround (edict_t *ent) +void +M_CheckGround(edict_t *ent) { - vec3_t point; - trace_t trace; - - if (ent->flags & (FL_SWIM|FL_FLY)) + vec3_t point; + trace_t trace; + + if (!ent) + { return; + } + + if (ent->flags & (FL_SWIM | FL_FLY)) + { + return; + } if (ent->velocity[2] > 100) { @@ -152,42 +241,52 @@ void M_CheckGround (edict_t *ent) return; } - // if the hull point one-quarter unit down is solid the entity is on ground + /* if the hull point one-quarter unit down + is solid the entity is on ground */ point[0] = ent->s.origin[0]; point[1] = ent->s.origin[1]; point[2] = ent->s.origin[2] - 0.25; - trace = gi.trace (ent->s.origin, ent->mins, ent->maxs, point, ent, MASK_MONSTERSOLID); + trace = gi.trace(ent->s.origin, ent->mins, ent->maxs, point, + ent, MASK_MONSTERSOLID); - // check steepness - if ( trace.plane.normal[2] < 0.7 && !trace.startsolid) + /* check steepness */ + if ((trace.plane.normal[2] < 0.7) && !trace.startsolid) { ent->groundentity = NULL; return; } + /* This two lines were commented out + by id. But why? */ + ent->groundentity = trace.ent; + ent->groundentity_linkcount = trace.ent->linkcount; + if (!trace.startsolid && !trace.allsolid) { - VectorCopy (trace.endpos, ent->s.origin); + VectorCopy(trace.endpos, ent->s.origin); ent->groundentity = trace.ent; ent->groundentity_linkcount = trace.ent->linkcount; - ent->velocity[2] = 0; + ent->velocity[2] = trace.ent->velocity[2]; } } - -void M_CatagorizePosition (edict_t *ent) +void +M_CatagorizePosition(edict_t *ent) { - vec3_t point; - int cont; - - // - // get waterlevel - // - point[0] = ent->s.origin[0]; - point[1] = ent->s.origin[1]; - point[2] = ent->s.origin[2] + ent->mins[2] + 1; - cont = gi.pointcontents (point); + vec3_t point; + int cont; + + if (!ent) + { + return; + } + + /* get waterlevel */ + point[0] = (ent->absmax[0] + ent->absmin[0])/2; + point[1] = (ent->absmax[1] + ent->absmin[1])/2; + point[2] = ent->absmin[2] + 2; + cont = gi.pointcontents(point); if (!(cont & MASK_WATER)) { @@ -199,22 +298,33 @@ void M_CatagorizePosition (edict_t *ent) ent->watertype = cont; ent->waterlevel = 1; point[2] += 26; - cont = gi.pointcontents (point); + cont = gi.pointcontents(point); + if (!(cont & MASK_WATER)) + { return; + } ent->waterlevel = 2; point[2] += 22; - cont = gi.pointcontents (point); + cont = gi.pointcontents(point); + if (cont & MASK_WATER) + { ent->waterlevel = 3; + } } - -void M_WorldEffects (edict_t *ent) +void +M_WorldEffects(edict_t *ent) { - int dmg; - + int dmg; + + if (!ent) + { + return; + } + if (ent->health > 0) { if (!(ent->flags & FL_SWIM)) @@ -224,13 +334,19 @@ void M_WorldEffects (edict_t *ent) ent->air_finished = level.time + 12; } else if (ent->air_finished < level.time) - { // drown! + { + /* drown! */ if (ent->pain_debounce_time < level.time) { dmg = 2 + 2 * floor(level.time - ent->air_finished); + if (dmg > 15) + { dmg = 15; - T_Damage (ent, world, world, vec3_origin, ent->s.origin, vec3_origin, dmg, 0, DAMAGE_NO_ARMOR, MOD_WATER); + } + + T_Damage(ent, world, world, vec3_origin, ent->s.origin, + vec3_origin, dmg, 0, DAMAGE_NO_ARMOR, MOD_WATER); ent->pain_debounce_time = level.time + 1; } } @@ -242,26 +358,34 @@ void M_WorldEffects (edict_t *ent) ent->air_finished = level.time + 9; } else if (ent->air_finished < level.time) - { // suffocate! + { + /* suffocate! */ if (ent->pain_debounce_time < level.time) { dmg = 2 + 2 * floor(level.time - ent->air_finished); + if (dmg > 15) + { dmg = 15; - T_Damage (ent, world, world, vec3_origin, ent->s.origin, vec3_origin, dmg, 0, DAMAGE_NO_ARMOR, MOD_WATER); + } + + T_Damage(ent, world, world, vec3_origin, ent->s.origin, + vec3_origin, dmg, 0, DAMAGE_NO_ARMOR, MOD_WATER); ent->pain_debounce_time = level.time + 1; } } } } - + if (ent->waterlevel == 0) { if (ent->flags & FL_INWATER) - { - gi.sound (ent, CHAN_BODY, gi.soundindex("player/watr_out.wav"), 1, ATTN_NORM, 0); + { + gi.sound(ent, CHAN_BODY, gi.soundindex( + "player/watr_out.wav"), 1, ATTN_NORM, 0); ent->flags &= ~FL_INWATER; } + return; } @@ -270,31 +394,48 @@ void M_WorldEffects (edict_t *ent) if (ent->damage_debounce_time < level.time) { ent->damage_debounce_time = level.time + 0.2; - T_Damage (ent, world, world, vec3_origin, ent->s.origin, vec3_origin, 10*ent->waterlevel, 0, 0, MOD_LAVA); + T_Damage(ent, world, world, vec3_origin, ent->s.origin, + vec3_origin, 10 * ent->waterlevel, 0, 0, MOD_LAVA); } } - if ((ent->watertype & CONTENTS_SLIME) && !(ent->flags & FL_IMMUNE_SLIME)) + + if ((ent->watertype & CONTENTS_SLIME) && !(ent->flags & FL_IMMUNE_SLIME) && !(ent->svflags & SVF_DEADMONSTER)) { if (ent->damage_debounce_time < level.time) { ent->damage_debounce_time = level.time + 1; - T_Damage (ent, world, world, vec3_origin, ent->s.origin, vec3_origin, 4*ent->waterlevel, 0, 0, MOD_SLIME); + T_Damage(ent, world, world, vec3_origin, ent->s.origin, + vec3_origin, 4 * ent->waterlevel, 0, 0, MOD_SLIME); } } - - if ( !(ent->flags & FL_INWATER) ) - { + + if (!(ent->flags & FL_INWATER)) + { if (!(ent->svflags & SVF_DEADMONSTER)) { if (ent->watertype & CONTENTS_LAVA) + { if (random() <= 0.5) - gi.sound (ent, CHAN_BODY, gi.soundindex("player/lava1.wav"), 1, ATTN_NORM, 0); + { + gi.sound(ent, CHAN_BODY, gi.soundindex( + "player/lava1.wav"), 1, ATTN_NORM, 0); + } else - gi.sound (ent, CHAN_BODY, gi.soundindex("player/lava2.wav"), 1, ATTN_NORM, 0); + { + gi.sound(ent, CHAN_BODY, gi.soundindex( + "player/lava2.wav"), 1, ATTN_NORM, 0); + } + } else if (ent->watertype & CONTENTS_SLIME) - gi.sound (ent, CHAN_BODY, gi.soundindex("player/watr_in.wav"), 1, ATTN_NORM, 0); + { + gi.sound(ent, CHAN_BODY, gi.soundindex( + "player/watr_in.wav"), 1, ATTN_NORM, 0); + } else if (ent->watertype & CONTENTS_WATER) - gi.sound (ent, CHAN_BODY, gi.soundindex("player/watr_in.wav"), 1, ATTN_NORM, 0); + { + gi.sound(ent, CHAN_BODY, gi.soundindex( + "player/watr_in.wav"), 1, ATTN_NORM, 0); + } } ent->flags |= FL_INWATER; @@ -302,34 +443,47 @@ void M_WorldEffects (edict_t *ent) } } - -void M_droptofloor (edict_t *ent) +void +M_droptofloor(edict_t *ent) { - vec3_t end; - trace_t trace; - - ent->s.origin[2] += 1; - VectorCopy (ent->s.origin, end); - end[2] -= 256; - - trace = gi.trace (ent->s.origin, ent->mins, ent->maxs, end, ent, MASK_MONSTERSOLID); - - if (trace.fraction == 1 || trace.allsolid) + vec3_t end; + trace_t trace; + + if (!ent) + { return; + } + + ent->s.origin[2] += 1; + VectorCopy(ent->s.origin, end); + end[2] -= 256; - VectorCopy (trace.endpos, ent->s.origin); + trace = gi.trace(ent->s.origin, ent->mins, ent->maxs, end, + ent, MASK_MONSTERSOLID); - gi.linkentity (ent); - M_CheckGround (ent); - M_CatagorizePosition (ent); + if ((trace.fraction == 1) || trace.allsolid) + { + return; + } + + VectorCopy(trace.endpos, ent->s.origin); + + gi.linkentity(ent); + M_CheckGround(ent); + M_CatagorizePosition(ent); } - -void M_SetEffects (edict_t *ent) -{ - ent->s.effects &= ~(EF_COLOR_SHELL|EF_POWERSCREEN); - ent->s.renderfx &= ~(RF_SHELL_RED|RF_SHELL_GREEN|RF_SHELL_BLUE); - +void +M_SetEffects(edict_t *ent) +{ + if (!ent) + { + return; + } + + ent->s.effects &= ~(EF_COLOR_SHELL | EF_POWERSCREEN); + ent->s.renderfx &= ~(RF_SHELL_RED | RF_SHELL_GREEN | RF_SHELL_BLUE); + if (ent->monsterinfo.aiflags & AI_RESURRECTING) { ent->s.effects |= EF_COLOR_SHELL; @@ -337,7 +491,9 @@ void M_SetEffects (edict_t *ent) } if (ent->health <= 0) + { return; + } if (ent->powerarmor_time > level.time) { @@ -353,16 +509,23 @@ void M_SetEffects (edict_t *ent) } } - -void M_MoveFrame (edict_t *self) +void +M_MoveFrame(edict_t *self) { - mmove_t *move; - int index; - + mmove_t *move; + int index; + + if (!self) + { + return; + } + move = self->monsterinfo.currentmove; self->nextthink = level.time + FRAMETIME; - if ((self->monsterinfo.nextframe) && (self->monsterinfo.nextframe >= move->firstframe) && (self->monsterinfo.nextframe <= move->lastframe)) + if ((self->monsterinfo.nextframe) && + (self->monsterinfo.nextframe >= move->firstframe) && + (self->monsterinfo.nextframe <= move->lastframe)) { self->s.frame = self->monsterinfo.nextframe; self->monsterinfo.nextframe = 0; @@ -373,18 +536,21 @@ void M_MoveFrame (edict_t *self) { if (move->endfunc) { - move->endfunc (self); + move->endfunc(self); - // regrab move, endfunc is very likely to change it + /* regrab move, endfunc is very likely to change it */ move = self->monsterinfo.currentmove; - // check for death + /* check for death */ if (self->svflags & SVF_DEADMONSTER) + { return; + } } } - if (self->s.frame < move->firstframe || self->s.frame > move->lastframe) + if ((self->s.frame < move->firstframe) || + (self->s.frame > move->lastframe)) { self->monsterinfo.aiflags &= ~AI_HOLD_FRAME; self->s.frame = move->firstframe; @@ -394,81 +560,118 @@ void M_MoveFrame (edict_t *self) if (!(self->monsterinfo.aiflags & AI_HOLD_FRAME)) { self->s.frame++; + if (self->s.frame > move->lastframe) + { self->s.frame = move->firstframe; + } } } } index = self->s.frame - move->firstframe; - if (move->frame[index].aifunc) { + + if (move->frame[index].aifunc) + { if (!(self->monsterinfo.aiflags & AI_HOLD_FRAME)) - move->frame[index].aifunc (self, move->frame[index].dist * self->monsterinfo.scale); + { + move->frame[index].aifunc(self, + move->frame[index].dist * self->monsterinfo.scale); + } else - move->frame[index].aifunc (self, 0); + { + move->frame[index].aifunc(self, 0); + } } + if (move->frame[index].thinkfunc) - move->frame[index].thinkfunc (self); + { + move->frame[index].thinkfunc(self); + } } +void +monster_think(edict_t *self) +{ + if (!self) + { + return; + } + + M_MoveFrame(self); -void monster_think (edict_t *self) -{ - M_MoveFrame (self); if (self->linkcount != self->monsterinfo.linkcount) { self->monsterinfo.linkcount = self->linkcount; - M_CheckGround (self); + M_CheckGround(self); } - M_CatagorizePosition (self); - M_WorldEffects (self); - M_SetEffects (self); -} + M_CatagorizePosition(self); + M_WorldEffects(self); + M_SetEffects(self); +} /* -================ -monster_use - -Using a monster makes it angry at the current activator -================ -*/ -void monster_use (edict_t *self, edict_t *other, edict_t *activator) -{ + * Using a monster makes it angry + * at the current activator + */ +void +monster_use(edict_t *self, edict_t *other /* unused */, edict_t *activator) +{ + if (!self || !activator) + { + return; + } + if (self->enemy) + { return; + } + if (self->health <= 0) + { return; + } + if (activator->flags & FL_NOTARGET) + { return; + } + if (!(activator->client) && !(activator->monsterinfo.aiflags & AI_GOOD_GUY)) + { return; - - // delay reaction so if the monster is teleported, its sound is still heard + } + + /* delay reaction so if the monster is + teleported, its sound is still heard */ self->enemy = activator; - FoundTarget (self); + FoundTarget(self); } - -void monster_start_go (edict_t *self); - - -void monster_triggered_spawn (edict_t *self) -{ +void +monster_triggered_spawn(edict_t *self) +{ + if (!self) + { + return; + } + self->s.origin[2] += 1; - KillBox (self); + KillBox(self); self->solid = SOLID_BBOX; self->movetype = MOVETYPE_STEP; self->svflags &= ~SVF_NOCLIENT; self->air_finished = level.time + 12; - gi.linkentity (self); + gi.linkentity(self); - monster_start_go (self); + monster_start_go(self); - if (self->enemy && !(self->spawnflags & 1) && !(self->enemy->flags & FL_NOTARGET)) + if (self->enemy && !(self->spawnflags & 1) && + !(self->enemy->flags & FL_NOTARGET)) { - FoundTarget (self); + FoundTarget(self); } else { @@ -476,18 +679,35 @@ void monster_triggered_spawn (edict_t *self) } } -void monster_triggered_spawn_use (edict_t *self, edict_t *other, edict_t *activator) -{ - // we have a one frame delay here so we don't telefrag the guy who activated us +void +monster_triggered_spawn_use(edict_t *self, edict_t *other /* unused */, edict_t *activator) +{ + if (!self || !activator) + { + return; + } + + /* we have a one frame delay here so we + don't telefrag the guy who activated us */ self->think = monster_triggered_spawn; self->nextthink = level.time + FRAMETIME; + if (activator->client) + { self->enemy = activator; + } + self->use = monster_use; } -void monster_triggered_start (edict_t *self) -{ +void +monster_triggered_start(edict_t *self) +{ + if (!self) + { + return; + } + self->solid = SOLID_NOT; self->movetype = MOVETYPE_NONE; self->svflags |= SVF_NOCLIENT; @@ -495,43 +715,53 @@ void monster_triggered_start (edict_t *self) self->use = monster_triggered_spawn_use; } - /* -================ -monster_death_use - -When a monster dies, it fires all of its targets with the current -enemy as activator. -================ -*/ -void monster_death_use (edict_t *self) -{ - self->flags &= ~(FL_FLY|FL_SWIM); + * When a monster dies, it fires all of its targets + * with the current enemy as activator. + */ +void +monster_death_use(edict_t *self) +{ + if (!self) + { + return; + } + + self->flags &= ~(FL_FLY | FL_SWIM); self->monsterinfo.aiflags &= AI_GOOD_GUY; if (self->item) { - Drop_Item (self, self->item); + Drop_Item(self, self->item); self->item = NULL; } if (self->deathtarget) + { self->target = self->deathtarget; + } if (!self->target) + { return; + } - G_UseTargets (self, self->enemy); + G_UseTargets(self, self->enemy); } +/* ================================================================== */ -//============================================================================ - -qboolean monster_start (edict_t *self) -{ +qboolean +monster_start(edict_t *self) +{ + if (!self) + { + return false; + } + if (deathmatch->value) { - G_FreeEdict (self); + G_FreeEdict(self); return false; } @@ -542,7 +772,9 @@ qboolean monster_start (edict_t *self) } if (!(self->monsterinfo.aiflags & AI_GOOD_GUY)) + { level.total_monsters++; + } self->nextthink = level.time + FRAMETIME; self->svflags |= SVF_MONSTER; @@ -550,7 +782,12 @@ qboolean monster_start (edict_t *self) self->takedamage = DAMAGE_AIM; self->air_finished = level.time + 12; self->use = monster_use; - self->max_health = self->health; + + if(!self->max_health) + { + self->max_health = self->health; + } + self->clipmask = MASK_MONSTERSOLID; self->s.skinnum = 0; @@ -558,41 +795,61 @@ qboolean monster_start (edict_t *self) self->svflags &= ~SVF_DEADMONSTER; if (!self->monsterinfo.checkattack) + { self->monsterinfo.checkattack = M_CheckAttack; - VectorCopy (self->s.origin, self->s.old_origin); + } + + VectorCopy(self->s.origin, self->s.old_origin); if (st.item) { - self->item = FindItemByClassname (st.item); + self->item = FindItemByClassname(st.item); + if (!self->item) - gi.dprintf("%s at %s has bad item: %s\n", self->classname, vtos(self->s.origin), st.item); + { + gi.dprintf("%s at %s has bad item: %s\n", self->classname, + vtos(self->s.origin), st.item); + } } - // randomize what frame they start on + /* randomize what frame they start on */ if (self->monsterinfo.currentmove) - self->s.frame = self->monsterinfo.currentmove->firstframe + (rand() % (self->monsterinfo.currentmove->lastframe - self->monsterinfo.currentmove->firstframe + 1)); + { + self->s.frame = self->monsterinfo.currentmove->firstframe + + (rand() % (self->monsterinfo.currentmove->lastframe - + self->monsterinfo.currentmove->firstframe + 1)); + } return true; } -void monster_start_go (edict_t *self) +void +monster_start_go(edict_t *self) { - vec3_t v; - - if (self->health <= 0) + vec3_t v; + + if (!self) + { return; + } + + if (self->health <= 0) + { + return; + } - // check for target to combat_point and change to combattarget + /* check for target to combat_point and change to combattarget */ if (self->target) { - qboolean notcombat; - qboolean fixup; - edict_t *target; + qboolean notcombat; + qboolean fixup; + edict_t *target; target = NULL; notcombat = false; fixup = false; - while ((target = G_Find (target, FOFS(targetname), self->target)) != NULL) + + while ((target = G_Find(target, FOFS(targetname), self->target)) != NULL) { if (strcmp(target->classname, "point_combat") == 0) { @@ -604,26 +861,36 @@ void monster_start_go (edict_t *self) notcombat = true; } } + if (notcombat && self->combattarget) - gi.dprintf("%s at %s has target with mixed types\n", self->classname, vtos(self->s.origin)); + { + gi.dprintf("%s at %s has target with mixed types\n", + self->classname, vtos(self->s.origin)); + } + if (fixup) + { self->target = NULL; + } } - // validate combattarget + /* validate combattarget */ if (self->combattarget) { - edict_t *target; + edict_t *target; target = NULL; - while ((target = G_Find (target, FOFS(targetname), self->combattarget)) != NULL) + + while ((target = G_Find(target, FOFS(targetname), + self->combattarget)) != NULL) { if (strcmp(target->classname, "point_combat") != 0) { - gi.dprintf("%s at (%i %i %i) has a bad combattarget %s : %s at (%i %i %i)\n", - self->classname, (int)self->s.origin[0], (int)self->s.origin[1], (int)self->s.origin[2], - self->combattarget, target->classname, (int)target->s.origin[0], (int)target->s.origin[1], - (int)target->s.origin[2]); + gi.dprintf( "%s at (%i %i %i) has a bad combattarget %s : %s at (%i %i %i)\n", + self->classname, (int)self->s.origin[0], (int)self->s.origin[1], + (int)self->s.origin[2], self->combattarget, target->classname, + (int)target->s.origin[0], (int)target->s.origin[1], + (int)target->s.origin[2]); } } } @@ -631,106 +898,162 @@ void monster_start_go (edict_t *self) if (self->target) { self->goalentity = self->movetarget = G_PickTarget(self->target); + if (!self->movetarget) { - gi.dprintf ("%s can't find target %s at %s\n", self->classname, self->target, vtos(self->s.origin)); + gi.dprintf("%s can't find target %s at %s\n", self->classname, + self->target, vtos(self->s.origin)); self->target = NULL; self->monsterinfo.pausetime = 100000000; - self->monsterinfo.stand (self); + self->monsterinfo.stand(self); } - else if (strcmp (self->movetarget->classname, "path_corner") == 0) + else if (strcmp(self->movetarget->classname, "path_corner") == 0) { - VectorSubtract (self->goalentity->s.origin, self->s.origin, v); + VectorSubtract(self->goalentity->s.origin, self->s.origin, v); self->ideal_yaw = self->s.angles[YAW] = vectoyaw(v); - self->monsterinfo.walk (self); + self->monsterinfo.walk(self); self->target = NULL; } else { self->goalentity = self->movetarget = NULL; self->monsterinfo.pausetime = 100000000; - self->monsterinfo.stand (self); + self->monsterinfo.stand(self); } } else { self->monsterinfo.pausetime = 100000000; - self->monsterinfo.stand (self); + self->monsterinfo.stand(self); } self->think = monster_think; self->nextthink = level.time + FRAMETIME; } - -void walkmonster_start_go (edict_t *self) -{ - if (!(self->spawnflags & 2) && level.time < 1) +void +walkmonster_start_go(edict_t *self) +{ + if (!self) { - M_droptofloor (self); + return; + } + + if (!(self->spawnflags & 2) && (level.time < 1)) + { + M_droptofloor(self); if (self->groundentity) - if (!M_walkmove (self, 0, 0)) - gi.dprintf ("%s in solid at %s\n", self->classname, vtos(self->s.origin)); + { + if (!M_walkmove(self, 0, 0)) + { + gi.dprintf("%s in solid at %s\n", self->classname, + vtos(self->s.origin)); + } + } } - + if (!self->yaw_speed) + { self->yaw_speed = 20; + } + self->viewheight = 25; - monster_start_go (self); + monster_start_go(self); if (self->spawnflags & 2) - monster_triggered_start (self); + { + monster_triggered_start(self); + } } -void walkmonster_start (edict_t *self) -{ +void +walkmonster_start(edict_t *self) +{ + if (!self) + { + return; + } + self->think = walkmonster_start_go; - monster_start (self); + monster_start(self); } - -void flymonster_start_go (edict_t *self) -{ - if (!M_walkmove (self, 0, 0)) - gi.dprintf ("%s in solid at %s\n", self->classname, vtos(self->s.origin)); +void +flymonster_start_go(edict_t *self) +{ + if (!self) + { + return; + } + + if (!M_walkmove(self, 0, 0)) + { + gi.dprintf("%s in solid at %s\n", self->classname, vtos(self->s.origin)); + } if (!self->yaw_speed) + { self->yaw_speed = 10; + } + self->viewheight = 25; - monster_start_go (self); + monster_start_go(self); if (self->spawnflags & 2) - monster_triggered_start (self); + { + monster_triggered_start(self); + } } - -void flymonster_start (edict_t *self) -{ +void +flymonster_start(edict_t *self) +{ + if (!self) + { + return; + } + self->flags |= FL_FLY; self->think = flymonster_start_go; - monster_start (self); + monster_start(self); } - -void swimmonster_start_go (edict_t *self) -{ +void +swimmonster_start_go(edict_t *self) +{ + if (!self) + { + return; + } + if (!self->yaw_speed) + { self->yaw_speed = 10; + } + self->viewheight = 10; - monster_start_go (self); + monster_start_go(self); if (self->spawnflags & 2) - monster_triggered_start (self); + { + monster_triggered_start(self); + } } -void swimmonster_start (edict_t *self) -{ +void +swimmonster_start(edict_t *self) +{ + if (!self) + { + return; + } + self->flags |= FL_SWIM; self->think = swimmonster_start_go; - monster_start (self); + monster_start(self); }