From a04a0bc093b1d181012cc562e25581b59de69395 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 17 Jun 2018 18:34:16 +1000 Subject: [PATCH] Use Heal in more places (turrets, trigger_heal, mage, bumblebee, vampirehook) --- qcsrc/common/mapobjects/trigger/heal.qc | 9 ++------ qcsrc/common/monsters/monster/mage.qc | 6 +++-- .../mutator/vampirehook/sv_vampirehook.qc | 6 ++--- qcsrc/common/turrets/cl_turrets.qc | 4 +++- qcsrc/common/turrets/sv_turrets.qc | 16 +++++++++++++ qcsrc/common/vehicles/vehicle/bumblebee.qc | 23 ++++++------------- qcsrc/server/g_damage.qc | 3 ++- 7 files changed, 36 insertions(+), 31 deletions(-) diff --git a/qcsrc/common/mapobjects/trigger/heal.qc b/qcsrc/common/mapobjects/trigger/heal.qc index 61f27a021..fb20ebdba 100644 --- a/qcsrc/common/mapobjects/trigger/heal.qc +++ b/qcsrc/common/mapobjects/trigger/heal.qc @@ -18,14 +18,9 @@ void trigger_heal_touch(entity this, entity toucher) toucher.triggerhealtime = time + this.delay; bool playthesound = (this.spawnflags & HEAL_SOUND_ALWAYS); - if (GetResourceAmount(toucher, RESOURCE_HEALTH) < this.max_health) - { - playthesound = true; - GiveResourceWithLimit(toucher, RESOURCE_HEALTH, GetResourceAmount(this, RESOURCE_HEALTH), this.max_health); - toucher.pauserothealth_finished = max(toucher.pauserothealth_finished, time + autocvar_g_balance_pause_health_rot); - } + bool healed = Heal(toucher, this, GetResourceAmount(this, RESOURCE_HEALTH), this.max_health); - if(playthesound) + if(playthesound || healed) _sound (toucher, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM); } } diff --git a/qcsrc/common/monsters/monster/mage.qc b/qcsrc/common/monsters/monster/mage.qc index b26328a54..a49430fbc 100644 --- a/qcsrc/common/monsters/monster/mage.qc +++ b/qcsrc/common/monsters/monster/mage.qc @@ -234,9 +234,11 @@ void M_Mage_Defend_Heal(entity this) switch(this.skin) { case 0: - GiveResourceWithLimit(it, RESOURCE_HEALTH, autocvar_g_monster_mage_heal_allies, autocvar_g_balance_health_regenstable); + { + Heal(it, this, autocvar_g_monster_mage_heal_allies, autocvar_g_balance_health_regenstable); fx = EFFECT_HEALING; break; + } case 1: { if(GetResourceAmount(this, RESOURCE_CELLS)) GiveResourceWithLimit(it, RESOURCE_CELLS, 1, g_pickup_cells_max); @@ -267,7 +269,7 @@ void M_Mage_Defend_Heal(entity this) else { Send_Effect(EFFECT_HEALING, it.origin, '0 0 0', 1); - GiveResourceWithLimit(it, RESOURCE_HEALTH, autocvar_g_monster_mage_heal_allies, it.max_health); + Heal(it, this, autocvar_g_monster_mage_heal_allies, -1); if(!(it.spawnflags & MONSTERFLAG_INVINCIBLE) && it.sprite) WaypointSprite_UpdateHealth(it.sprite, GetResourceAmount(it, RESOURCE_HEALTH)); } diff --git a/qcsrc/common/mutators/mutator/vampirehook/sv_vampirehook.qc b/qcsrc/common/mutators/mutator/vampirehook/sv_vampirehook.qc index 319b51866..115e6ca91 100644 --- a/qcsrc/common/mutators/mutator/vampirehook/sv_vampirehook.qc +++ b/qcsrc/common/mutators/mutator/vampirehook/sv_vampirehook.qc @@ -27,10 +27,8 @@ MUTATOR_HOOKFUNCTION(vh, GrappleHookThink) thehook.last_dmg = time + autocvar_g_vampirehook_damagerate; thehook.owner.damage_dealt += autocvar_g_vampirehook_damage; Damage(dmgent, thehook, thehook.owner, autocvar_g_vampirehook_damage, WEP_HOOK.m_id, DMG_NOWEP, thehook.origin, '0 0 0'); - if(SAME_TEAM(thehook.owner, thehook.aiment)) - GiveResourceWithLimit(thehook.aiment, RESOURCE_HEALTH, autocvar_g_vampirehook_health_steal, g_pickup_healthsmall_max); - else - GiveResourceWithLimit(thehook.owner, RESOURCE_HEALTH, autocvar_g_vampirehook_health_steal, g_pickup_healthsmall_max); + entity targ = ((SAME_TEAM(thehook.owner, thehook.aiment)) ? thehook.aiment : thehook.owner); + Heal(targ, thehook.owner, autocvar_g_vampirehook_health_steal, g_pickup_healthsmall_max); if(dmgent == thehook.owner) TakeResource(dmgent, RESOURCE_HEALTH, autocvar_g_vampirehook_damage); // FIXME: friendly fire?! diff --git a/qcsrc/common/turrets/cl_turrets.qc b/qcsrc/common/turrets/cl_turrets.qc index fb27cd121..ac68003a6 100644 --- a/qcsrc/common/turrets/cl_turrets.qc +++ b/qcsrc/common/turrets/cl_turrets.qc @@ -425,8 +425,10 @@ NET_HANDLE(ENT_CLIENT_TURRET, bool isnew) float myhp = GetResourceAmount(this, RESOURCE_HEALTH); if(_tmp == 0 && myhp != 0) turret_die(this); - else if(myhp && myhp != _tmp) + else if(myhp && myhp > _tmp) this.helpme = servertime + 10; + else if(myhp && myhp < _tmp) + this.helpme = 0; // we're being healed, don't spam help me waypoints SetResourceAmountExplicit(this, RESOURCE_HEALTH, _tmp); } diff --git a/qcsrc/common/turrets/sv_turrets.qc b/qcsrc/common/turrets/sv_turrets.qc index a02ce07ac..db33ca7cb 100644 --- a/qcsrc/common/turrets/sv_turrets.qc +++ b/qcsrc/common/turrets/sv_turrets.qc @@ -182,6 +182,7 @@ void turret_die(entity this) this.tur_head.solid = this.solid; this.event_damage = func_null; + this.event_heal = func_null; this.takedamage = DAMAGE_NO; SetResourceAmountExplicit(this, RESOURCE_HEALTH, 0); @@ -248,6 +249,8 @@ void turret_damage(entity this, entity inflictor, entity attacker, float damage, { this.event_damage = func_null; this.tur_head.event_damage = func_null; + this.event_heal = func_null; + this.tur_head.event_heal = func_null; this.takedamage = DAMAGE_NO; this.nextthink = time; setthink(this, turret_die); @@ -256,6 +259,17 @@ void turret_damage(entity this, entity inflictor, entity attacker, float damage, this.SendFlags |= TNSF_STATUS; } +bool turret_heal(entity targ, entity inflictor, float amount, float limit) +{ + float true_limit = ((limit >= 0) ? limit : targ.max_health); + if(GetResourceAmount(targ, RESOURCE_HEALTH) <= 0 || GetResourceAmount(targ, RESOURCE_HEALTH) >= true_limit) + return false; + + GiveResourceWithLimit(targ, RESOURCE_HEALTH, amount, true_limit); + targ.SendFlags |= TNSF_STATUS; + return true; +} + void turret_think(entity this); void turret_respawn(entity this) { @@ -268,6 +282,7 @@ void turret_respawn(entity this) this.solid = SOLID_BBOX; this.takedamage = DAMAGE_AIM; this.event_damage = turret_damage; + this.event_heal = turret_heal; this.avelocity = '0 0 0'; this.tur_head.avelocity = this.avelocity; this.tur_head.angles = this.idle_aim; @@ -1360,6 +1375,7 @@ bool turret_initialize(entity this, Turret tur) this.idle_aim = '0 0 0'; this.turret_firecheckfunc = turret_firecheck; this.event_damage = turret_damage; + this.event_heal = turret_heal; this.use = turret_use; this.bot_attack = true; this.nextthink = time + 1; diff --git a/qcsrc/common/vehicles/vehicle/bumblebee.qc b/qcsrc/common/vehicles/vehicle/bumblebee.qc index da21a4bcb..32a5a2ade 100644 --- a/qcsrc/common/vehicles/vehicle/bumblebee.qc +++ b/qcsrc/common/vehicles/vehicle/bumblebee.qc @@ -544,36 +544,27 @@ bool bumblebee_pilot_frame(entity this, float dt) else { if(!IS_DEAD(trace_ent)) + { if((teamplay && trace_ent.team == this.team) || !teamplay) { + if(autocvar_g_vehicle_bumblebee_healgun_hps) + { + float hplimit = ((IS_PLAYER(trace_ent)) ? autocvar_g_vehicle_bumblebee_healgun_hmax : -1); + Heal(trace_ent, this, autocvar_g_vehicle_bumblebee_healgun_hps * dt, hplimit); + } if(IS_VEHICLE(trace_ent)) { if(autocvar_g_vehicle_bumblebee_healgun_sps && trace_ent.vehicle_health <= trace_ent.max_health) trace_ent.vehicle_shield = min(trace_ent.vehicle_shield + autocvar_g_vehicle_bumblebee_healgun_sps * dt, trace_ent.tur_head.max_health); - - if(autocvar_g_vehicle_bumblebee_healgun_hps) - trace_ent.vehicle_health = min(trace_ent.vehicle_health + autocvar_g_vehicle_bumblebee_healgun_hps * dt, trace_ent.max_health); } else if(IS_CLIENT(trace_ent)) { - if(GetResourceAmount(trace_ent, RESOURCE_HEALTH) <= autocvar_g_vehicle_bumblebee_healgun_hmax && autocvar_g_vehicle_bumblebee_healgun_hps) - GiveResourceWithLimit(trace_ent, RESOURCE_HEALTH, autocvar_g_vehicle_bumblebee_healgun_hps * dt, autocvar_g_vehicle_bumblebee_healgun_hmax); - if(GetResourceAmount(trace_ent, RESOURCE_ARMOR) <= autocvar_g_vehicle_bumblebee_healgun_amax && autocvar_g_vehicle_bumblebee_healgun_aps) GiveResourceWithLimit(trace_ent, RESOURCE_ARMOR, autocvar_g_vehicle_bumblebee_healgun_aps * dt, autocvar_g_vehicle_bumblebee_healgun_amax); - - GiveResourceWithLimit(trace_ent, RESOURCE_HEALTH, autocvar_g_vehicle_bumblebee_healgun_hps * dt, autocvar_g_vehicle_bumblebee_healgun_hmax); - } - else if(IS_TURRET(trace_ent)) - { - if(GetResourceAmount(trace_ent, RESOURCE_HEALTH) <= trace_ent.max_health && autocvar_g_vehicle_bumblebee_healgun_hps) - GiveResourceWithLimit(trace_ent, RESOURCE_HEALTH, autocvar_g_vehicle_bumblebee_healgun_hps * dt, trace_ent.max_health); - //else ..hmmm what? ammo? - - trace_ent.SendFlags |= TNSF_STATUS; } } + } } } diff --git a/qcsrc/server/g_damage.qc b/qcsrc/server/g_damage.qc index 728b293e3..cc0c71be5 100644 --- a/qcsrc/server/g_damage.qc +++ b/qcsrc/server/g_damage.qc @@ -1063,7 +1063,7 @@ float RadiusDamage (entity inflictor, entity attacker, float coredamage, float e bool Heal(entity targ, entity inflictor, float amount, float limit) { - if(game_stopped || (IS_CLIENT(targ) && CS(targ).killcount == FRAGS_SPECTATOR) || STAT(FROZEN, targ)) + if(game_stopped || (IS_CLIENT(targ) && CS(targ).killcount == FRAGS_SPECTATOR) || STAT(FROZEN, targ) || IS_DEAD(targ)) return false; bool healed = false; @@ -1071,6 +1071,7 @@ bool Heal(entity targ, entity inflictor, float amount, float limit) healed = targ.event_heal(targ, inflictor, amount, limit); // TODO: additional handling? what if the healing kills them? should this abort if healing would do so etc // TODO: healing fx! + // TODO: armor healing? return healed; } -- 2.39.2