]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/monsters/sv_monsters.qc
Merge branch 'Mario/minor_fixes' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / monsters / sv_monsters.qc
index 244652ef95c6cf93b8f884a06dc67b06e4081e18..1635b5cb0d235c6eeb84dac673c18d98e9421e96 100644 (file)
@@ -55,6 +55,8 @@ void monster_dropitem(entity this, entity attacker)
        {
                e.noalign = true;
                StartItem(e, e.monster_loot);
+               if(startitem_failed || wasfreed(e))
+                       return;
                e.gravity = 1;
                setorigin(e, org);
                e.velocity = randomvec() * 175 + '0 0 325';
@@ -452,6 +454,7 @@ void Monster_Attack_Check(entity this, entity targ, .entity weaponentity)
 
        if((!this || !targ)
        || (!this.monster_attackfunc)
+       || (game_stopped)
        || (time < this.attack_finished_single[slot])
        || ((autocvar_g_monsters_target_infront || (this.spawnflags & MONSTERFLAG_INFRONT)) && !monster_facing(this, targ))
        ) { return; }
@@ -589,20 +592,6 @@ vector Monster_Move_Target(entity this, entity targ)
        {
                vector targ_origin = ((this.enemy.absmin + this.enemy.absmax) * 0.5);
                targ_origin = WarpZone_RefSys_TransformOrigin(this.enemy, this, targ_origin); // origin of target as seen by the monster (us)
-               WarpZone_TraceLine(this.origin, targ_origin, MOVE_NOMONSTERS, this);
-
-               // cases where the enemy may have changed their state (don't need to check everything here)
-               if(    (IS_DEAD(this.enemy) || GetResource(this.enemy, RES_HEALTH) < 1)
-                       || (STAT(FROZEN, this.enemy))
-                       || (this.enemy.flags & FL_NOTARGET)
-                       || (this.enemy.alpha < 0.5 && this.enemy.alpha != 0)
-                       || (this.enemy.takedamage == DAMAGE_NO)
-                       || (vdist(this.origin - targ_origin, >, this.target_range))
-                       || ((trace_fraction < 1) && (trace_ent != this.enemy))
-                       )
-               {
-                       this.enemy = NULL;
-               }
 
                if(this.enemy)
                {
@@ -897,6 +886,12 @@ bool Monster_Appear_Check(entity this, Monster monster_id)
 
 void Monster_Reset(entity this)
 {
+       if(this.spawnflags & MONSTERFLAG_SPAWNED)
+       {
+               Monster_Remove(this);
+               return;
+       }
+
        setorigin(this, this.pos1);
        this.angles = this.pos2;
 
@@ -1201,7 +1196,28 @@ void Monster_Frozen_Think(entity this)
 void Monster_Enemy_Check(entity this)
 {
        if(this.enemy)
-               return;
+       {
+               vector targ_origin = ((this.enemy.absmin + this.enemy.absmax) * 0.5);
+               targ_origin = WarpZone_RefSys_TransformOrigin(this.enemy, this, targ_origin); // origin of target as seen by the monster (us)
+               WarpZone_TraceLine(this.origin, targ_origin, MOVE_NOMONSTERS, this);
+
+               // cases where the enemy may have changed their state (don't need to check everything here)
+               if(    (IS_DEAD(this.enemy) || GetResource(this.enemy, RES_HEALTH) < 1)
+                       || (STAT(FROZEN, this.enemy))
+                       || (this.enemy.flags & FL_NOTARGET)
+                       || (this.enemy.alpha < 0.5 && this.enemy.alpha != 0)
+                       || (this.enemy.takedamage == DAMAGE_NO)
+                       || (vdist(this.origin - targ_origin, >, this.target_range))
+                       || ((trace_fraction < 1) && (trace_ent != this.enemy))
+                       )
+               {
+                       this.enemy = NULL;
+               }
+               else
+               {
+                       return;
+               }
+       }
 
        this.enemy = Monster_FindTarget(this);
        if(this.enemy)
@@ -1420,7 +1436,7 @@ bool Monster_Spawn(entity this, bool check_appear, Monster mon)
        if((mon.spawnflags & MONSTER_SIZE_QUAKE) && autocvar_g_monsters_quake_resize && !(this.spawnflags & MONSTERFLAG_RESPAWNED))
                this.scale *= 1.3;
 
-       setsize(this, mon.m_mins * this.scale, mon.m_maxs * this.scale);
+       setsize(this, RoundPerfectVector(mon.m_mins * this.scale), RoundPerfectVector(mon.m_maxs * this.scale));
        this.view_ofs                   = '0 0 0.7' * (this.maxs_z * 0.5);
 
        this.ticrate = bound(sys_frametime, ((!this.ticrate) ? autocvar_g_monsters_think_delay : this.ticrate), 60);