From: Mario Date: Thu, 9 Feb 2017 15:32:42 +0000 (+1000) Subject: Partial support for buffs in target_items entities X-Git-Tag: xonotic-v0.8.2~235 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=9f1b7db1e3034be3219e9a2d2f5189951a48b73d;p=xonotic%2Fxonotic-data.pk3dir.git Partial support for buffs in target_items entities --- diff --git a/qcsrc/common/mutators/mutator/buffs/all.inc b/qcsrc/common/mutators/mutator/buffs/all.inc index 915f95329..943c75594 100644 --- a/qcsrc/common/mutators/mutator/buffs/all.inc +++ b/qcsrc/common/mutators/mutator/buffs/all.inc @@ -1,3 +1,15 @@ +string Buff_UndeprecateName(string buffname) +{ + switch(buffname) + { + case "ammoregen": return "ammo"; + case "haste": case "scout": return "speed"; + case "doubler": return "medic"; + case "invis": return "invisible"; + default: return buffname; + } +} + REGISTER_BUFF(AMMO) { this.m_prettyName = _("Ammo"); this.m_name = "ammo"; diff --git a/qcsrc/common/mutators/mutator/buffs/buffs.qh b/qcsrc/common/mutators/mutator/buffs/buffs.qh index ae76d9f59..81a638ea7 100644 --- a/qcsrc/common/mutators/mutator/buffs/buffs.qh +++ b/qcsrc/common/mutators/mutator/buffs/buffs.qh @@ -64,6 +64,8 @@ STATIC_INIT(REGISTER_BUFFS) { #define BUFF_SPAWNFUNC_Q3TA_COMPAT(o, r) #endif +string Buff_UndeprecateName(string buffname); + REGISTER_BUFF(Null); BUFF_SPAWNFUNCS(random, BUFF_Null) diff --git a/qcsrc/common/mutators/mutator/buffs/sv_buffs.qc b/qcsrc/common/mutators/mutator/buffs/sv_buffs.qc index c02ac5687..b63349e86 100644 --- a/qcsrc/common/mutators/mutator/buffs/sv_buffs.qc +++ b/qcsrc/common/mutators/mutator/buffs/sv_buffs.qc @@ -970,7 +970,8 @@ MUTATOR_HOOKFUNCTION(buffs, PlayerPreThink) } else { - delete(player.buff_model); + if(player.buff_model) + delete(player.buff_model); player.buff_model = NULL; player.effects &= ~(EF_NOSHADOW); diff --git a/qcsrc/common/t_items.qc b/qcsrc/common/t_items.qc index 9aab742d0..79fa97801 100644 --- a/qcsrc/common/t_items.qc +++ b/qcsrc/common/t_items.qc @@ -22,6 +22,8 @@ #include + #include + #include "../lib/warpzone/util_server.qh" #elif defined(CSQC) #include "physics/movetypes/movetypes.qh" @@ -1493,6 +1495,15 @@ spawnfunc(target_items) else if(argv(j) == "fuel_regen") this.items |= ITEM_JetpackRegen.m_itemid; else { + FOREACH(Buffs, it != BUFF_Null, + { + s = Buff_UndeprecateName(argv(j)); + if(s == it.m_name) + { + this.buffs |= (it.m_itemid); + break; + } + }); FOREACH(Weapons, it != WEP_Null, { s = W_UndeprecateName(argv(j)); if(s == it.netname) @@ -1549,6 +1560,7 @@ spawnfunc(target_items) if(this.ammo_fuel != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.ammo_fuel), "fuel"); if(this.health != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.health), "health"); if(this.armorvalue != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.armorvalue), "armor"); + FOREACH(Buffs, it != BUFF_Null, this.netname = sprintf("%s %s%d %s", this.netname, itemprefix, !!(this.buffs & (it.m_itemid)), it.m_name)); FOREACH(Weapons, it != WEP_Null, this.netname = sprintf("%s %s%d %s", this.netname, itemprefix, !!(this.weapons & (it.m_wepset)), it.netname)); } this.netname = strzone(this.netname); @@ -1624,6 +1636,35 @@ float GiveWeapon(entity e, float wpn, float op, float val) return (v0 != v1); } +bool GiveBuff(entity e, Buff thebuff, int op, int val) +{ + bool had_buff = (e.buffs & thebuff.m_itemid); + switch(op) + { + case OP_SET: + if(val > 0) + e.buffs |= thebuff.m_itemid; + else + e.buffs &= ~thebuff.m_itemid; + break; + case OP_MIN: + case OP_PLUS: + if(val > 0) + e.buffs |= thebuff.m_itemid; + break; + case OP_MAX: + if(val <= 0) + e.buffs &= ~thebuff.m_itemid; + break; + case OP_MINUS: + if(val > 0) + e.buffs &= ~thebuff.m_itemid; + break; + } + bool have_buff = (e.buffs & thebuff.m_itemid); + return (had_buff != have_buff); +} + void GiveSound(entity e, float v0, float v1, float t, Sound snd_incr, Sound snd_decr) { if(v1 == v0) @@ -1727,6 +1768,8 @@ float GiveItems(entity e, float beginarg, float endarg) got += GiveValue(e, armorvalue, op, val); case "allweapons": FOREACH(Weapons, it != WEP_Null && !(it.spawnflags & WEP_FLAG_MUTATORBLOCKED), got += GiveWeapon(e, it.m_id, op, val)); + //case "allbuffs": // all buffs makes a player god, do not want! + //FOREACH(Buffs, it != BUFF_Null, got += GiveBuff(e, it.m_itemid, op, val)); case "allammo": got += GiveValue(e, ammo_cells, op, val); got += GiveValue(e, ammo_plasma, op, val); @@ -1785,6 +1828,11 @@ float GiveItems(entity e, float beginarg, float endarg) got += GiveValue(e, ammo_fuel, op, val); break; default: + FOREACH(Buffs, it != BUFF_Null && Buff_UndeprecateName(cmd) == it.m_name, + { + got += GiveBuff(e, it, op, val); + break; + }); FOREACH(Weapons, it != WEP_Null && W_UndeprecateName(cmd) == it.netname, { got += GiveWeapon(e, it.m_id, op, val); break;