From: Mario Date: Tue, 20 Jun 2017 02:10:27 +0000 (+1000) Subject: Split some non-physics stuff out of Monster_Move X-Git-Tag: xonotic-v0.8.5~2717 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=648c50d32630631baf6624e1473209ed17d08bd2;p=xonotic%2Fxonotic-data.pk3dir.git Split some non-physics stuff out of Monster_Move --- diff --git a/qcsrc/common/monsters/sv_monsters.qc b/qcsrc/common/monsters/sv_monsters.qc index d7147e0bc..5307ccd2d 100644 --- a/qcsrc/common/monsters/sv_monsters.qc +++ b/qcsrc/common/monsters/sv_monsters.qc @@ -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);