From: terencehill Date: Sat, 22 Sep 2018 19:10:33 +0000 (+0200) Subject: Clean up code by avoiding resetting player's health in Unfreeze as it's not needed... X-Git-Tag: xonotic-v0.8.5~1827^2~4 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=bdb8dce93bf95c85d4b803ac61cbe5bd49910ccc;p=xonotic%2Fxonotic-data.pk3dir.git Clean up code by avoiding resetting player's health in Unfreeze as it's not needed in most cases. Don't automatically count alive players in the ft hook of Unfreeze as it's now redundant --- diff --git a/qcsrc/common/gamemodes/gamemode/freezetag/sv_freezetag.qc b/qcsrc/common/gamemodes/gamemode/freezetag/sv_freezetag.qc index 4b9306f0c..42b3b77f5 100644 --- a/qcsrc/common/gamemodes/gamemode/freezetag/sv_freezetag.qc +++ b/qcsrc/common/gamemodes/gamemode/freezetag/sv_freezetag.qc @@ -329,7 +329,7 @@ void ft_RemovePlayer(entity this) { if(!STAT(FROZEN, this)) freezetag_LastPlayerForTeam_Notify(this); - Unfreeze(this); + Unfreeze(this, false); SetResourceAmountExplicit(this, RESOURCE_HEALTH, 0); // neccessary to correctly count alive players freezetag_count_alive_players(); @@ -360,7 +360,7 @@ MUTATOR_HOOKFUNCTION(ft, PlayerDies) if(round_handler_CountdownRunning()) { if(STAT(FROZEN, frag_target)) - Unfreeze(frag_target); + Unfreeze(frag_target, true); freezetag_count_alive_players(); return true; // let the player die so that he can respawn whenever he wants } @@ -378,8 +378,7 @@ MUTATOR_HOOKFUNCTION(ft, PlayerDies) freezetag_LastPlayerForTeam_Notify(frag_target); } else - Unfreeze(frag_target); // remove ice - SetResourceAmountExplicit(frag_target, RESOURCE_HEALTH, 0); // Unfreeze resets health + Unfreeze(frag_target, false); // remove ice frag_target.freezetag_frozen_timeout = -2; // freeze on respawn return true; } @@ -452,8 +451,6 @@ MUTATOR_HOOKFUNCTION(ft, Unfreeze) entity targ = M_ARGV(0, entity); targ.freezetag_frozen_time = 0; targ.freezetag_frozen_timeout = 0; - - freezetag_count_alive_players(); } MUTATOR_HOOKFUNCTION(ft, PlayerPreThink, CBC_ORDER_FIRST) @@ -501,7 +498,7 @@ MUTATOR_HOOKFUNCTION(ft, PlayerPreThink, CBC_ORDER_FIRST) if(STAT(REVIVE_PROGRESS, player) >= 1) { - Unfreeze(player); + Unfreeze(player, false); freezetag_count_alive_players(); if(n == -1) diff --git a/qcsrc/common/monsters/sv_monsters.qc b/qcsrc/common/monsters/sv_monsters.qc index f30c5974a..011e14ca3 100644 --- a/qcsrc/common/monsters/sv_monsters.qc +++ b/qcsrc/common/monsters/sv_monsters.qc @@ -894,7 +894,7 @@ void Monster_Reset(entity this) setorigin(this, this.pos1); this.angles = this.pos2; - Unfreeze(this); // remove any icy remains + Unfreeze(this, false); // remove any icy remains SetResourceAmountExplicit(this, RESOURCE_HEALTH, this.max_health); this.velocity = '0 0 0'; @@ -930,10 +930,7 @@ void Monster_Dead(entity this, entity attacker, float gibbed) this.monster_lifetime = time + 5; if(STAT(FROZEN, this)) - { - Unfreeze(this); // remove any icy remains - SetResourceAmountExplicit(this, RESOURCE_HEALTH, 0); // reset by Unfreeze (TODO) - } + Unfreeze(this, false); // remove any icy remains monster_dropitem(this, attacker); @@ -1160,7 +1157,7 @@ void Monster_Anim(entity this) void Monster_Frozen_Think(entity this) { - if(STAT(FROZEN, this) == 2) + if (STAT(FROZEN, this) == 2) // reviving in progress { STAT(REVIVE_PROGRESS, this) = bound(0, STAT(REVIVE_PROGRESS, this) + this.ticrate * this.revive_speed, 1); SetResourceAmountExplicit(this, RESOURCE_HEALTH, max(1, STAT(REVIVE_PROGRESS, this) * this.max_health)); @@ -1170,9 +1167,9 @@ void Monster_Frozen_Think(entity this) WaypointSprite_UpdateHealth(this.sprite, GetResourceAmount(this, RESOURCE_HEALTH)); if(STAT(REVIVE_PROGRESS, this) >= 1) - Unfreeze(this); + Unfreeze(this, false); } - else if(STAT(FROZEN, this) == 3) + else if (STAT(FROZEN, this) == 3) // ice nade progress until explosion { STAT(REVIVE_PROGRESS, this) = bound(0, STAT(REVIVE_PROGRESS, this) - this.ticrate * this.revive_speed, 1); SetResourceAmountExplicit(this, RESOURCE_HEALTH, max(0, autocvar_g_nades_ice_health + (this.max_health-autocvar_g_nades_ice_health) * STAT(REVIVE_PROGRESS, this))); @@ -1182,14 +1179,12 @@ void Monster_Frozen_Think(entity this) if(GetResourceAmount(this, RESOURCE_HEALTH) < 1) { - Unfreeze(this); - SetResourceAmountExplicit(this, RESOURCE_HEALTH, 0); + Unfreeze(this, false); if(this.event_damage) this.event_damage(this, this, this.frozen_by, 1, DEATH_NADE_ICE_FREEZE.m_id, DMG_NOWEP, this.origin, '0 0 0'); } - else if ( STAT(REVIVE_PROGRESS, this) <= 0 ) - Unfreeze(this); + Unfreeze(this, false); } // otherwise, no revival! diff --git a/qcsrc/common/mutators/mutator/nades/nades.qc b/qcsrc/common/mutators/mutator/nades/nades.qc index 68a3af3ba..ef9be3459 100644 --- a/qcsrc/common/mutators/mutator/nades/nades.qc +++ b/qcsrc/common/mutators/mutator/nades/nades.qc @@ -1355,7 +1355,7 @@ MUTATOR_HOOKFUNCTION(nades, PlayerPreThink) if(STAT(REVIVE_PROGRESS, player) >= 1) { - Unfreeze(player); + Unfreeze(player, false); Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_FREEZETAG_REVIVED, o.netname); Send_Notification(NOTIF_ONE, o, MSG_CENTER, CENTER_FREEZETAG_REVIVE, player.netname); @@ -1468,7 +1468,7 @@ MUTATOR_HOOKFUNCTION(nades, Damage_Calculate) if(autocvar_g_freezetag_revive_nade && STAT(FROZEN, frag_target) && frag_attacker == frag_target && frag_deathtype == DEATH_NADE.m_id) if(time - frag_inflictor.toss_time <= 0.1) { - Unfreeze(frag_target); + Unfreeze(frag_target, false); SetResourceAmount(frag_target, RESOURCE_HEALTH, autocvar_g_freezetag_revive_nade_health); Send_Effect(EFFECT_ICEORGLASS, frag_target.origin, '0 0 0', 3); M_ARGV(4, float) = 0; diff --git a/qcsrc/server/client.qc b/qcsrc/server/client.qc index da0d84979..d927e9c6f 100644 --- a/qcsrc/server/client.qc +++ b/qcsrc/server/client.qc @@ -274,7 +274,7 @@ void PutObserverInServer(entity this) RemoveGrapplingHooks(this); Portal_ClearAll(this); - Unfreeze(this); + Unfreeze(this, false); SetSpectatee(this, NULL); if (this.alivetime) @@ -733,7 +733,7 @@ void PutPlayerInServer(entity this) //spot.target = s; } - Unfreeze(this); + Unfreeze(this, false); MUTATOR_CALLHOOK(PlayerSpawn, this, spot); @@ -1196,7 +1196,7 @@ void ClientDisconnect(entity this) Portal_ClearAll(this); - Unfreeze(this); + Unfreeze(this, false); RemoveGrapplingHooks(this); @@ -2404,16 +2404,16 @@ void PlayerPreThink (entity this) if(IS_PLAYER(this)) { - if (STAT(FROZEN, this) == 2) + if (STAT(FROZEN, this) == 2) // reviving in progress { STAT(REVIVE_PROGRESS, this) = bound(0, STAT(REVIVE_PROGRESS, this) + frametime * this.revive_speed, 1); SetResourceAmountExplicit(this, RESOURCE_HEALTH, max(1, STAT(REVIVE_PROGRESS, this) * start_health)); this.iceblock.alpha = bound(0.2, 1 - STAT(REVIVE_PROGRESS, this), 1); if (STAT(REVIVE_PROGRESS, this) >= 1) - Unfreeze(this); + Unfreeze(this, false); } - else if (STAT(FROZEN, this) == 3) + else if (STAT(FROZEN, this) == 3) // ice nade progress until explosion { STAT(REVIVE_PROGRESS, this) = bound(0, STAT(REVIVE_PROGRESS, this) - frametime * this.revive_speed, 1); SetResourceAmountExplicit(this, RESOURCE_HEALTH, max(0, autocvar_g_nades_ice_health + (start_health-autocvar_g_nades_ice_health) * STAT(REVIVE_PROGRESS, this))); @@ -2426,7 +2426,7 @@ void PlayerPreThink (entity this) this.event_damage(this, this, this.frozen_by, 1, DEATH_NADE_ICE_FREEZE.m_id, DMG_NOWEP, this.origin, '0 0 0'); } else if (STAT(REVIVE_PROGRESS, this) <= 0) - Unfreeze(this); + Unfreeze(this, false); } } diff --git a/qcsrc/server/command/vote.qc b/qcsrc/server/command/vote.qc index 83c62cd2b..1cb26d1fd 100644 --- a/qcsrc/server/command/vote.qc +++ b/qcsrc/server/command/vote.qc @@ -365,7 +365,7 @@ void reset_map(bool dorespawn) if (it.reset2) it.reset2(it); }); - FOREACH_CLIENT(IS_PLAYER(it) && STAT(FROZEN, it), { Unfreeze(it); }); + FOREACH_CLIENT(IS_PLAYER(it) && STAT(FROZEN, it), { Unfreeze(it, false); }); // Moving the player reset code here since the player-reset depends // on spawnpoint entities which have to be reset first --blub diff --git a/qcsrc/server/g_damage.qc b/qcsrc/server/g_damage.qc index eb05e2c85..c2c2b85bc 100644 --- a/qcsrc/server/g_damage.qc +++ b/qcsrc/server/g_damage.qc @@ -529,16 +529,15 @@ void Freeze(entity targ, float revivespeed, int frozen_type, bool show_waypoint) WaypointSprite_Spawn(WP_Frozen, 0, 0, targ, '0 0 64', NULL, targ.team, targ, waypointsprite_attached, true, RADARICON_WAYPOINT); } -void Unfreeze(entity targ) +void Unfreeze(entity targ, bool reset_health) { if(!STAT(FROZEN, targ)) return; - if(STAT(FROZEN, targ) && STAT(FROZEN, targ) != 3) // only reset health if target was frozen - { + if (reset_health && STAT(FROZEN, targ) != 3) // only reset health if target was frozen SetResourceAmount(targ, RESOURCE_HEALTH, ((IS_PLAYER(targ)) ? start_health : targ.max_health)); - targ.pauseregen_finished = time + autocvar_g_balance_pause_health_regen; - } + + targ.pauseregen_finished = time + autocvar_g_balance_pause_health_regen; STAT(FROZEN, targ) = 0; STAT(REVIVE_PROGRESS, targ) = 0; @@ -697,7 +696,7 @@ void Damage(entity targ, entity inflictor, entity attacker, float damage, int de if(deathtype == DEATH_FALL.m_id) if(damage >= autocvar_g_frozen_revive_falldamage) { - Unfreeze(targ); + Unfreeze(targ, false); SetResourceAmount(targ, RESOURCE_HEALTH, autocvar_g_frozen_revive_falldamage_health); Send_Effect(EFFECT_ICEORGLASS, targ.origin, '0 0 0', 3); Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_FREEZETAG_REVIVED_FALL, targ.netname); diff --git a/qcsrc/server/g_damage.qh b/qcsrc/server/g_damage.qh index 617eca198..1d100e7a5 100644 --- a/qcsrc/server/g_damage.qh +++ b/qcsrc/server/g_damage.qh @@ -85,7 +85,7 @@ void Ice_Think(entity this); void Freeze(entity targ, float freeze_time, int frozen_type, bool show_waypoint); -void Unfreeze (entity targ); +void Unfreeze(entity targ, bool reset_health); // NOTE: the .weaponentity parameter can be set to DMG_NOWEP if the attack wasn't caused by a weapon or player void Damage (entity targ, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force); diff --git a/qcsrc/server/player.qc b/qcsrc/server/player.qc index 87005ad4b..a0d622c77 100644 --- a/qcsrc/server/player.qc +++ b/qcsrc/server/player.qc @@ -592,8 +592,7 @@ void PlayerDamage(entity this, entity inflictor, entity attacker, float damage, // when we get here, player actually dies - Unfreeze(this); // remove any icy remains - SetResourceAmountExplicit(this, RESOURCE_HEALTH, 0); // Unfreeze resets health, so we need to set it back + Unfreeze(this, false); // remove any icy remains // clear waypoints WaypointSprite_PlayerDead(this);