]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Split some non-physics stuff out of Monster_Move
authorMario <mario@smbclan.net>
Tue, 20 Jun 2017 02:10:27 +0000 (12:10 +1000)
committerMario <mario@smbclan.net>
Tue, 20 Jun 2017 02:10:27 +0000 (12:10 +1000)
qcsrc/common/monsters/sv_monsters.qc

index d7147e0bcedfd7bfefb8f3f0dcdf587e018967f8..5307ccd2de7324b0cb9430d3b6481295f04b0dbe 100644 (file)
@@ -701,52 +701,11 @@ void Monster_Move(entity this, float runspeed, float walkspeed, float stpspeed)
        if(this.target2 && this.target2 != "" && this.goalentity.targetname != this.target2)
                this.goalentity = find(NULL, targetname, this.target2);
 
-       if(STAT(FROZEN, this) == 2)
+       if(STAT(FROZEN, this))
        {
-               this.revive_progress = bound(0, this.revive_progress + this.ticrate * this.revive_speed, 1);
-               this.health = max(1, this.revive_progress * this.max_health);
-               this.iceblock.alpha = bound(0.2, 1 - this.revive_progress, 1);
-
-               if(!(this.spawnflags & MONSTERFLAG_INVINCIBLE) && this.sprite)
-                       WaypointSprite_UpdateHealth(this.sprite, this.health);
-
                movelib_brake_simple(this, stpspeed);
                setanim(this, this.anim_idle, true, false, false);
-
-               this.enemy = NULL;
-               this.nextthink = time + this.ticrate;
-
-               if(this.revive_progress >= 1)
-                       Unfreeze(this);
-
-               return;
-       }
-       else if(STAT(FROZEN, this) == 3)
-       {
-               this.revive_progress = bound(0, this.revive_progress - this.ticrate * this.revive_speed, 1);
-               this.health = max(0, autocvar_g_nades_ice_health + (this.max_health-autocvar_g_nades_ice_health) * this.revive_progress );
-
-               if(!(this.spawnflags & MONSTERFLAG_INVINCIBLE) && this.sprite)
-                       WaypointSprite_UpdateHealth(this.sprite, this.health);
-
-               movelib_brake_simple(this, stpspeed);
-               setanim(this, this.anim_idle, true, false, false);
-
-               this.enemy = NULL;
-               this.nextthink = time + this.ticrate;
-
-               if(this.health < 1)
-               {
-                       Unfreeze(this);
-                       this.health = 0;
-                       if(this.event_damage)
-                               this.event_damage(this, this, this.frozen_by, 1, DEATH_NADE_ICE_FREEZE.m_id, this.origin, '0 0 0');
-               }
-
-               else if ( this.revive_progress <= 0 )
-                       Unfreeze(this);
-
-               return;
+               return; // no physics while frozen!
        }
 
        if(this.flags & FL_SWIM)
@@ -810,27 +769,6 @@ void Monster_Move(entity this, float runspeed, float walkspeed, float stpspeed)
        if(DIFF_TEAM(this.monster_follow, this))
                this.monster_follow = NULL;
 
-       if(time >= this.last_enemycheck)
-       {
-               if(!this.enemy)
-               {
-                       this.enemy = Monster_FindTarget(this);
-                       if(this.enemy)
-                       {
-                               WarpZone_RefSys_Copy(this.enemy, this);
-                               WarpZone_RefSys_AddInverse(this.enemy, this); // wz1^-1 ... wzn^-1 receiver
-                               this.moveto = WarpZone_RefSys_TransformOrigin(this.enemy, this, (0.5 * (this.enemy.absmin + this.enemy.absmax)));
-                               this.monster_moveto = '0 0 0';
-                               this.monster_face = '0 0 0';
-
-                               //this.pass_distance = vlen((('1 0 0' * this.enemy.origin_x) + ('0 1 0' * this.enemy.origin_y)) - (('1 0 0' *  this.origin_x) + ('0 1 0' *  this.origin_y)));
-                               Monster_Sound(this, monstersound_sight, 0, false, CH_VOICE);
-                       }
-               }
-
-               this.last_enemycheck = time + 1; // check for enemies every second
-       }
-
        if(this.state == MONSTER_ATTACK_RANGED && IS_ONGROUND(this))
        {
                this.state = 0;
@@ -895,9 +833,6 @@ void Monster_Move(entity this, float runspeed, float walkspeed, float stpspeed)
                turny = bound(turny * -1, shortangle_f(real_angle.y, this.angles.y), turny);
                this.angles_y += turny;
        }
-
-       .entity weaponentity = weaponentities[0]; // TODO?
-       Monster_Attack_Check(this, this.enemy, weaponentity);
 }
 
 void Monster_Remove(entity this)
@@ -1209,6 +1144,64 @@ void Monster_Anim(entity this)
        */
 }
 
+void Monster_Frozen_Think(entity this)
+{
+       if(STAT(FROZEN, this) == 2)
+       {
+               this.revive_progress = bound(0, this.revive_progress + this.ticrate * this.revive_speed, 1);
+               this.health = max(1, this.revive_progress * this.max_health);
+               this.iceblock.alpha = bound(0.2, 1 - this.revive_progress, 1);
+
+               if(!(this.spawnflags & MONSTERFLAG_INVINCIBLE) && this.sprite)
+                       WaypointSprite_UpdateHealth(this.sprite, this.health);
+
+               if(this.revive_progress >= 1)
+                       Unfreeze(this);
+       }
+       else if(STAT(FROZEN, this) == 3)
+       {
+               this.revive_progress = bound(0, this.revive_progress - this.ticrate * this.revive_speed, 1);
+               this.health = max(0, autocvar_g_nades_ice_health + (this.max_health-autocvar_g_nades_ice_health) * this.revive_progress );
+
+               if(!(this.spawnflags & MONSTERFLAG_INVINCIBLE) && this.sprite)
+                       WaypointSprite_UpdateHealth(this.sprite, this.health);
+
+               if(this.health < 1)
+               {
+                       Unfreeze(this);
+                       this.health = 0;
+                       if(this.event_damage)
+                               this.event_damage(this, this, this.frozen_by, 1, DEATH_NADE_ICE_FREEZE.m_id, this.origin, '0 0 0');
+               }
+
+               else if ( this.revive_progress <= 0 )
+                       Unfreeze(this);
+       }
+       // otherwise, no revival!
+
+       this.enemy = NULL; // TODO: save enemy, and attack when revived?
+}
+
+void Monster_Enemy_Check(entity this)
+{
+       if(!this.enemy)
+       {
+               this.enemy = Monster_FindTarget(this);
+               if(this.enemy)
+               {
+                       WarpZone_RefSys_Copy(this.enemy, this);
+                       WarpZone_RefSys_AddInverse(this.enemy, this); // wz1^-1 ... wzn^-1 receiver
+                       // update move target immediately?
+                       this.moveto = WarpZone_RefSys_TransformOrigin(this.enemy, this, (0.5 * (this.enemy.absmin + this.enemy.absmax)));
+                       this.monster_moveto = '0 0 0';
+                       this.monster_face = '0 0 0';
+
+                       //this.pass_distance = vlen((('1 0 0' * this.enemy.origin_x) + ('0 1 0' * this.enemy.origin_y)) - (('1 0 0' *  this.origin_x) + ('0 1 0' *  this.origin_y)));
+                       Monster_Sound(this, monstersound_sight, 0, false, CH_VOICE);
+               }
+       }
+}
+
 void Monster_Think(entity this)
 {
        setthink(this, Monster_Think);
@@ -1220,10 +1213,23 @@ void Monster_Think(entity this)
                return;
        }
 
+       if(STAT(FROZEN, this))
+               Monster_Frozen_Think(this);
+       else if(time >= this.last_enemycheck)
+       {
+               Monster_Enemy_Check(this);
+               this.last_enemycheck = time + 1; // check for enemies every second
+       }
+
        Monster mon = Monsters_from(this.monsterid);
        if(mon.mr_think(mon, this))
+       {
                Monster_Move(this, this.speed2, this.speed, this.stopspeed);
 
+               .entity weaponentity = weaponentities[0]; // TODO?
+               Monster_Attack_Check(this, this.enemy, weaponentity);
+       }
+
        Monster_Anim(this);
 
        CSQCMODEL_AUTOUPDATE(this);