#include "pickup.qh"
#ifdef SVQC
#include <common/t_items.qh>
+ #include <server/resources.qh>
#endif
+#if 1
.int ammo_none;
.int ammo_shells;
.int ammo_nails;
.int ammo_plasma;
.int ammo_fuel;
#endif
+#endif
#ifdef SVQC
PROPERTY(float, g_pickup_ammo_anyway);
PROPERTY(int, g_pickup_nails);
void ammo_bullets_init(Pickup this, entity item)
{
- if(!item.ammo_nails)
- item.ammo_nails = g_pickup_nails;
+ if(!GetResourceAmount(item, RESOURCE_BULLETS))
+ SetResourceAmountExplicit(item, RESOURCE_BULLETS, g_pickup_nails);
}
#endif
PROPERTY(int, g_pickup_cells);
void ammo_cells_init(Pickup this, entity item)
{
- if(!item.ammo_cells)
- item.ammo_cells = g_pickup_cells;
+ if(!GetResourceAmount(item, RESOURCE_CELLS))
+ SetResourceAmountExplicit(item, RESOURCE_CELLS, g_pickup_cells);
}
#endif
REGISTER_ITEM(Cells, Ammo) {
PROPERTY(int, g_pickup_plasma);
void ammo_plasma_init(Pickup this, entity item)
{
- if(!item.ammo_plasma)
- item.ammo_plasma = g_pickup_plasma;
+ if(!GetResourceAmount(item, RESOURCE_PLASMA))
+ SetResourceAmountExplicit(item, RESOURCE_PLASMA, g_pickup_plasma);
}
#endif
REGISTER_ITEM(Plasma, Ammo) {
PROPERTY(int, g_pickup_rockets);
void ammo_rockets_init(Pickup this, entity item)
{
- if(!item.ammo_rockets)
- item.ammo_rockets = g_pickup_rockets;
+ if(!GetResourceAmount(item, RESOURCE_ROCKETS))
+ SetResourceAmountExplicit(item, RESOURCE_ROCKETS, g_pickup_rockets);
}
#endif
REGISTER_ITEM(Rockets, Ammo) {
PROPERTY(int, g_pickup_shells);
void ammo_shells_init(Pickup this, entity item)
{
- if(!item.ammo_shells)
- item.ammo_shells = g_pickup_shells;
+ if(!GetResourceAmount(item, RESOURCE_SHELLS))
+ SetResourceAmountExplicit(item, RESOURCE_SHELLS, g_pickup_shells);
}
#endif
PROPERTY(int, g_pickup_fuel_jetpack);
void powerup_jetpack_init(Pickup this, entity item)
{
- if(!item.ammo_fuel)
- item.ammo_fuel = g_pickup_fuel_jetpack;
+ if(!GetResourceAmount(item, RESOURCE_FUEL))
+ SetResourceAmountExplicit(item, RESOURCE_FUEL, g_pickup_fuel_jetpack);
}
#endif
PROPERTY(int, g_pickup_fuel);
void ammo_fuel_init(Pickup this, entity item)
{
- if(!item.ammo_fuel)
- item.ammo_fuel = g_pickup_fuel;
+ if(!GetResourceAmount(item, RESOURCE_FUEL))
+ SetResourceAmountExplicit(item, RESOURCE_FUEL, g_pickup_fuel);
}
#endif
REGISTER_ITEM(JetpackFuel, Ammo) {
int autocvar_g_instagib_ammo_drop;
void ammo_vaporizercells_init(Pickup this, entity item)
{
- if(!item.ammo_cells)
- item.ammo_cells = autocvar_g_instagib_ammo_drop;
+ if(!GetResourceAmount(item, RESOURCE_CELLS))
+ SetResourceAmountExplicit(item, RESOURCE_CELLS, autocvar_g_instagib_ammo_drop);
}
#endif
REGISTER_ITEM(VaporizerCells, Ammo) {
#ifdef SVQC
if (!(ITEMS_STAT(this) & IT_UNLIMITED_WEAPON_AMMO))
- this.ammo_fuel -= PHYS_JETPACK_FUEL(this) * dt * fvel * f;
+ SetResourceAmountExplicit(this, RESOURCE_FUEL, GetResourceAmount(this, RESOURCE_FUEL) - PHYS_JETPACK_FUEL(this) * dt * fvel * f);
ITEMS_STAT(this) |= IT_USING_JETPACK;
if(item.itemdef.instanceOfWeaponPickup)
{
entity ammo = NULL;
- if(item.ammo_shells) { need_shells = true; ammo = ITEM_Shells; }
- else if(item.ammo_nails) { need_nails = true; ammo = ITEM_Bullets; }
- else if(item.ammo_rockets) { need_rockets = true; ammo = ITEM_Rockets; }
- else if(item.ammo_cells) { need_cells = true; ammo = ITEM_Cells; }
- else if(item.ammo_plasma) { need_plasma = true; ammo = ITEM_Plasma; }
- else if(item.ammo_fuel) { need_fuel = true; ammo = ITEM_JetpackFuel; }
+ if(GetResourceAmount(item, RESOURCE_SHELLS)) { need_shells = true; ammo = ITEM_Shells; }
+ else if(GetResourceAmount(item, RESOURCE_BULLETS)) { need_nails = true; ammo = ITEM_Bullets; }
+ else if(GetResourceAmount(item, RESOURCE_ROCKETS)) { need_rockets = true; ammo = ITEM_Rockets; }
+ else if(GetResourceAmount(item, RESOURCE_CELLS)) { need_cells = true; ammo = ITEM_Cells; }
+ else if(GetResourceAmount(item, RESOURCE_PLASMA)) { need_plasma = true; ammo = ITEM_Plasma; }
+ else if(GetResourceAmount(item, RESOURCE_FUEL)) { need_fuel = true; ammo = ITEM_JetpackFuel; }
if(!ammo)
return 0;
float noammorating = 0.5;
- if ((need_shells) && (item.ammo_shells) && (GetResourceAmount(player, RESOURCE_SHELLS) < g_pickup_shells_max))
- c = item.ammo_shells / max(noammorating, GetResourceAmount(player, RESOURCE_SHELLS));
+ if ((need_shells) && GetResourceAmount(item, RESOURCE_SHELLS) && (GetResourceAmount(player, RESOURCE_SHELLS) < g_pickup_shells_max))
+ c = GetResourceAmount(item, RESOURCE_SHELLS) / max(noammorating, GetResourceAmount(player, RESOURCE_SHELLS));
- if ((need_nails) && (item.ammo_nails) && (GetResourceAmount(player, RESOURCE_BULLETS) < g_pickup_nails_max))
- c = item.ammo_nails / max(noammorating, GetResourceAmount(player, RESOURCE_BULLETS));
+ if ((need_nails) && GetResourceAmount(item, RESOURCE_BULLETS) && (GetResourceAmount(player, RESOURCE_BULLETS) < g_pickup_nails_max))
+ c = GetResourceAmount(item, RESOURCE_BULLETS) / max(noammorating, GetResourceAmount(player, RESOURCE_BULLETS));
- if ((need_rockets) && (item.ammo_rockets) && (GetResourceAmount(player, RESOURCE_ROCKETS) < g_pickup_rockets_max))
- c = item.ammo_rockets / max(noammorating, GetResourceAmount(player, RESOURCE_ROCKETS));
+ if ((need_rockets) && GetResourceAmount(item, RESOURCE_ROCKETS) && (GetResourceAmount(player, RESOURCE_ROCKETS) < g_pickup_rockets_max))
+ c = GetResourceAmount(item, RESOURCE_ROCKETS) / max(noammorating, GetResourceAmount(player, RESOURCE_ROCKETS));
- if ((need_cells) && (item.ammo_cells) && (GetResourceAmount(player, RESOURCE_CELLS) < g_pickup_cells_max))
- c = item.ammo_cells / max(noammorating, GetResourceAmount(player, RESOURCE_CELLS));
+ if ((need_cells) && GetResourceAmount(item, RESOURCE_CELLS) && (GetResourceAmount(player, RESOURCE_CELLS) < g_pickup_cells_max))
+ c = GetResourceAmount(item, RESOURCE_CELLS) / max(noammorating, GetResourceAmount(player, RESOURCE_CELLS));
- if ((need_plasma) && (item.ammo_plasma) && (GetResourceAmount(player, RESOURCE_PLASMA) < g_pickup_plasma_max))
- c = item.ammo_plasma / max(noammorating, GetResourceAmount(player, RESOURCE_PLASMA));
+ if ((need_plasma) && GetResourceAmount(item, RESOURCE_PLASMA) && (GetResourceAmount(player, RESOURCE_PLASMA) < g_pickup_plasma_max))
+ c = GetResourceAmount(item, RESOURCE_PLASMA) / max(noammorating, GetResourceAmount(player, RESOURCE_PLASMA));
- if ((need_fuel) && (item.ammo_fuel) && (GetResourceAmount(player, RESOURCE_FUEL) < g_pickup_fuel_max))
- c = item.ammo_fuel / max(noammorating, GetResourceAmount(player, RESOURCE_FUEL));
+ if ((need_fuel) && GetResourceAmount(item, RESOURCE_FUEL) && (GetResourceAmount(player, RESOURCE_FUEL) < g_pickup_fuel_max))
+ c = GetResourceAmount(item, RESOURCE_FUEL) / max(noammorating, GetResourceAmount(player, RESOURCE_FUEL));
rating *= min(c, 2);
if(wpn)
this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, this.superweapons_finished * boolean(this.items & IT_SUPERWEAPON), "superweapons");
this.netname = sprintf("%s %s%d %s", this.netname, itemprefix, boolean(this.items & ITEM_Jetpack.m_itemid), "jetpack");
this.netname = sprintf("%s %s%d %s", this.netname, itemprefix, boolean(this.items & ITEM_JetpackRegen.m_itemid), "fuel_regen");
- if(this.ammo_shells != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.ammo_shells), "shells");
- if(this.ammo_nails != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.ammo_nails), "nails");
- if(this.ammo_rockets != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.ammo_rockets), "rockets");
- if(this.ammo_cells != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.ammo_cells), "cells");
- if(this.ammo_plasma != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.ammo_plasma), "plasma");
- if(this.ammo_fuel != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.ammo_fuel), "fuel");
+ if(GetResourceAmount(this, RESOURCE_SHELLS) != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, GetResourceAmount(this, RESOURCE_SHELLS)), "shells");
+ if(GetResourceAmount(this, RESOURCE_BULLETS) != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, GetResourceAmount(this, RESOURCE_BULLETS)), "nails");
+ if(GetResourceAmount(this, RESOURCE_ROCKETS) != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, GetResourceAmount(this, RESOURCE_ROCKETS)), "rockets");
+ if(GetResourceAmount(this, RESOURCE_CELLS) != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, GetResourceAmount(this, RESOURCE_CELLS)), "cells");
+ if(GetResourceAmount(this, RESOURCE_PLASMA) != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, GetResourceAmount(this, RESOURCE_PLASMA)), "plasma");
+ if(GetResourceAmount(this, RESOURCE_FUEL) != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, GetResourceAmount(this, RESOURCE_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, !!(STAT(BUFFS, this) & (it.m_itemid)), it.m_name));
else if(v0 > v1)
e.(regenfield) = max(e.(regenfield), time + regentime);
}
+bool GiveResourceValue(entity e, int resource_type, int op, int val)
+{
+ int v0 = GetResourceAmount(e, resource_type);
+ switch (op)
+ {
+ case OP_SET:
+ SetResourceAmount(e, resource_type, val);
+ break;
+ case OP_MIN:
+ SetResourceAmount(e, resource_type, max(v0, val)); // min 100 cells = at least 100 cells
+ break;
+ case OP_MAX:
+ SetResourceAmount(e, resource_type, min(v0, val));
+ break;
+ case OP_PLUS:
+ SetResourceAmount(e, resource_type, v0 + val);
+ break;
+ case OP_MINUS:
+ SetResourceAmount(e, resource_type, v0 - val);
+ break;
+ }
+ int v1 = GetResourceAmount(e, resource_type);
+ return v0 != v1;
+}
+
float GiveItems(entity e, float beginarg, float endarg)
{
float got, i, val, op;
PREGIVE(e, strength_finished);
PREGIVE(e, invincible_finished);
PREGIVE(e, superweapons_finished);
- PREGIVE(e, ammo_nails);
- PREGIVE(e, ammo_cells);
- PREGIVE(e, ammo_plasma);
- PREGIVE(e, ammo_shells);
- PREGIVE(e, ammo_rockets);
- PREGIVE(e, ammo_fuel);
+ PREGIVE_RESOURCE(e, RESOURCE_BULLETS);
+ PREGIVE_RESOURCE(e, RESOURCE_CELLS);
+ PREGIVE_RESOURCE(e, RESOURCE_PLASMA);
+ PREGIVE_RESOURCE(e, RESOURCE_SHELLS);
+ PREGIVE_RESOURCE(e, RESOURCE_ROCKETS);
+ PREGIVE_RESOURCE(e, RESOURCE_FUEL);
PREGIVE(e, armorvalue);
PREGIVE(e, health);
//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);
- got += GiveValue(e, ammo_shells, op, val);
- got += GiveValue(e, ammo_nails, op, val);
- got += GiveValue(e, ammo_rockets, op, val);
- got += GiveValue(e, ammo_fuel, op, val);
+ got += GiveResourceValue(e, RESOURCE_CELLS, op, val);
+ got += GiveResourceValue(e, RESOURCE_PLASMA, op, val);
+ got += GiveResourceValue(e, RESOURCE_SHELLS, op, val);
+ got += GiveResourceValue(e, RESOURCE_BULLETS, op, val);
+ got += GiveResourceValue(e, RESOURCE_ROCKETS, op, val);
+ got += GiveResourceValue(e, RESOURCE_FUEL, op, val);
break;
case "unlimited_ammo":
got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val);
got += GiveValue(e, superweapons_finished, op, val);
break;
case "cells":
- got += GiveValue(e, ammo_cells, op, val);
+ got += GiveResourceValue(e, RESOURCE_CELLS, op, val);
break;
case "plasma":
- got += GiveValue(e, ammo_plasma, op, val);
+ got += GiveResourceValue(e, RESOURCE_PLASMA, op, val);
break;
case "shells":
- got += GiveValue(e, ammo_shells, op, val);
+ got += GiveResourceValue(e, RESOURCE_SHELLS, op, val);
break;
case "nails":
case "bullets":
- got += GiveValue(e, ammo_nails, op, val);
+ got += GiveResourceValue(e, RESOURCE_BULLETS, op, val);
break;
case "rockets":
- got += GiveValue(e, ammo_rockets, op, val);
+ got += GiveResourceValue(e, RESOURCE_ROCKETS, op, val);
break;
case "health":
got += GiveValue(e, health, op, val);
got += GiveValue(e, armorvalue, op, val);
break;
case "fuel":
- got += GiveValue(e, ammo_fuel, op, val);
+ got += GiveResourceValue(e, RESOURCE_FUEL, op, val);
break;
default:
FOREACH(Buffs, it != BUFF_Null && Buff_UndeprecateName(cmd) == it.m_name,
POSTGIVE_VALUE(e, strength_finished, 1, SND_POWERUP, SND_POWEROFF);
POSTGIVE_VALUE(e, invincible_finished, 1, SND_Shield, SND_POWEROFF);
//POSTGIVE_VALUE(e, superweapons_finished, 1, SND_Null, SND_Null);
- POSTGIVE_VALUE(e, ammo_nails, 0, SND_ITEMPICKUP, SND_Null);
- POSTGIVE_VALUE(e, ammo_cells, 0, SND_ITEMPICKUP, SND_Null);
- POSTGIVE_VALUE(e, ammo_plasma, 0, SND_ITEMPICKUP, SND_Null);
- POSTGIVE_VALUE(e, ammo_shells, 0, SND_ITEMPICKUP, SND_Null);
- POSTGIVE_VALUE(e, ammo_rockets, 0, SND_ITEMPICKUP, SND_Null);
- POSTGIVE_VALUE_ROT(e, ammo_fuel, 1, pauserotfuel_finished, autocvar_g_balance_pause_fuel_rot, pauseregen_finished, autocvar_g_balance_pause_fuel_regen, SND_ITEMPICKUP, SND_Null);
+ POSTGIVE_RESOURCE(e, RESOURCE_BULLETS, 0, SND_ITEMPICKUP, SND_Null);
+ POSTGIVE_RESOURCE(e, RESOURCE_CELLS, 0, SND_ITEMPICKUP, SND_Null);
+ POSTGIVE_RESOURCE(e, RESOURCE_PLASMA, 0, SND_ITEMPICKUP, SND_Null);
+ POSTGIVE_RESOURCE(e, RESOURCE_SHELLS, 0, SND_ITEMPICKUP, SND_Null);
+ POSTGIVE_RESOURCE(e, RESOURCE_ROCKETS, 0, SND_ITEMPICKUP, SND_Null);
+ POSTGIVE_RESOURCE_ROT(e, RESOURCE_FUEL, 1, pauserotfuel_finished, autocvar_g_balance_pause_fuel_rot, pauseregen_finished, autocvar_g_balance_pause_fuel_regen, SND_ITEMPICKUP, SND_Null);
POSTGIVE_VALUE_ROT(e, armorvalue, 1, pauserotarmor_finished, autocvar_g_balance_pause_armor_rot, pauseregen_finished, autocvar_g_balance_pause_health_regen, SND_ARMOR25, SND_Null);
POSTGIVE_VALUE_ROT(e, health, 1, pauserothealth_finished, autocvar_g_balance_pause_health_rot, pauseregen_finished, autocvar_g_balance_pause_health_regen, SND_MEGAHEALTH, SND_Null);
#define PREGIVE_WEAPONS(e) WepSet save_weapons; save_weapons = STAT(WEAPONS, e)
#define PREGIVE(e,f) float save_##f; save_##f = (e).f
+#define PREGIVE_RESOURCE(e,f) float save_##f = GetResourceAmount((e), (f))
#define POSTGIVE_WEAPON(e,b,snd_incr,snd_decr) GiveSound((e), !!(save_weapons & WepSet_FromWeapon(b)), !!(STAT(WEAPONS, e) & WepSet_FromWeapon(b)), 0, snd_incr, snd_decr)
#define POSTGIVE_BIT(e,f,b,snd_incr,snd_decr) GiveSound((e), save_##f & (b), (e).f & (b), 0, snd_incr, snd_decr)
+#define POSTGIVE_RESOURCE(e,f,t,snd_incr,snd_decr) GiveSound((e), save_##f, GetResourceAmount((e), (f)), t, snd_incr, snd_decr)
+#define POSTGIVE_RESOURCE_ROT(e,f,t,rotfield,rottime,regenfield,regentime,snd_incr,snd_decr) GiveRot((e),save_##f,GetResourceAmount((e),(f)),rotfield,rottime,regenfield,regentime);GiveSound((e),save_##f,GetResourceAmount((e),(f)),t,snd_incr,snd_decr)
#define POSTGIVE_VALUE(e,f,t,snd_incr,snd_decr) GiveSound((e), save_##f, (e).f, t, snd_incr, snd_decr)
#define POSTGIVE_VALUE_ROT(e,f,t,rotfield,rottime,regenfield,regentime,snd_incr,snd_decr) GiveRot((e), save_##f, (e).f, rotfield, rottime, regenfield, regentime); GiveSound((e), save_##f, (e).f, t, snd_incr, snd_decr)
{
if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
{
- if( actor.ammo_fuel >= (time - actor.(weaponentity).hook_time_fueldecrease) * hooked_fuel )
+ if( GetResourceAmount(actor, RESOURCE_FUEL) >= (time - actor.(weaponentity).hook_time_fueldecrease) * hooked_fuel )
{
W_DecreaseAmmo(thiswep, actor, (time - actor.(weaponentity).hook_time_fueldecrease) * hooked_fuel, weaponentity);
actor.(weaponentity).hook_time_fueldecrease = time;
}
else
{
- actor.ammo_fuel = 0;
+ SetResourceAmount(actor, RESOURCE_FUEL, 0);
actor.(weaponentity).hook_state |= HOOK_REMOVING;
if(actor.(weaponentity).m_weapon != WEP_Null) // offhand
W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
if (!thiswep.ammo_factor) return true;
if(actor.(weaponentity).hook)
- return actor.ammo_fuel > 0;
+ return GetResourceAmount(actor, RESOURCE_FUEL) > 0;
- return actor.ammo_fuel >= WEP_CVAR_PRI(hook, ammo);
+ return GetResourceAmount(actor, RESOURCE_FUEL) >= WEP_CVAR_PRI(hook, ammo);
}
METHOD(Hook, wr_checkammo2, bool(Hook thiswep, entity actor, .entity weaponentity))
{
} else if(WEP_CVAR(vaporizer, reload_ammo) && actor.(weaponentity).clip_load < vaporizer_ammo) { // forced reload
thiswep.wr_reload(thiswep, actor, weaponentity);
}
- if((fire & 1) && (actor.ammo_cells || !autocvar_g_rm) && !forbidWeaponUse(actor))
+ if((fire & 1) && (GetResourceAmount(actor, RESOURCE_CELLS) || !autocvar_g_rm) && !forbidWeaponUse(actor))
{
if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(vaporizer, refire)))
{
weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(vaporizer, animtime), w_ready);
}
}
- if((fire & 2) || ((fire & 1) && !actor.ammo_cells && autocvar_g_rm))
+ if((fire & 2) || ((fire & 1) && !GetResourceAmount(actor, RESOURCE_CELLS) && autocvar_g_rm))
{
if((autocvar_g_rm && autocvar_g_rm_laser) || autocvar_g_rm_laser == 2)
{
// Jetpack navigation
if(this.navigation_jetpack_goal)
if(this.goalcurrent==this.navigation_jetpack_goal)
- if(this.ammo_fuel)
+ if(GetResourceAmount(this, RESOURCE_FUEL))
{
if(autocvar_bot_debug_goalstack)
{
if (item.health && player.health <= this.health) {return true;}
if (item.armorvalue && player.armorvalue <= this.armorvalue) {return true;}
if (STAT(WEAPONS, item) && !(STAT(WEAPONS, player) & STAT(WEAPONS, item))) {return true;}
- if (item.ammo_shells && GetResourceAmount(player, RESOURCE_SHELLS) <= GetResourceAmount(this, RESOURCE_SHELLS)) {return true;}
- if (item.ammo_nails && GetResourceAmount(player, RESOURCE_BULLETS) <= GetResourceAmount(this, RESOURCE_BULLETS)) {return true;}
- if (item.ammo_rockets && GetResourceAmount(player, RESOURCE_ROCKETS) <= GetResourceAmount(this, RESOURCE_ROCKETS)) {return true;}
- if (item.ammo_cells && GetResourceAmount(player, RESOURCE_CELLS) <= GetResourceAmount(this, RESOURCE_CELLS)) {return true;}
- if (item.ammo_plasma && GetResourceAmount(player, RESOURCE_PLASMA) <= GetResourceAmount(this, RESOURCE_PLASMA)) {return true;}
+ if (GetResourceAmount(item, RESOURCE_SHELLS) && GetResourceAmount(player, RESOURCE_SHELLS) <= GetResourceAmount(this, RESOURCE_SHELLS)) {return true;}
+ if (GetResourceAmount(item, RESOURCE_BULLETS) && GetResourceAmount(player, RESOURCE_BULLETS) <= GetResourceAmount(this, RESOURCE_BULLETS)) {return true;}
+ if (GetResourceAmount(item, RESOURCE_ROCKETS) && GetResourceAmount(player, RESOURCE_ROCKETS) <= GetResourceAmount(this, RESOURCE_ROCKETS)) {return true;}
+ if (GetResourceAmount(item, RESOURCE_CELLS) && GetResourceAmount(player, RESOURCE_CELLS) <= GetResourceAmount(this, RESOURCE_CELLS)) {return true;}
+ if (GetResourceAmount(item, RESOURCE_PLASMA) && GetResourceAmount(player, RESOURCE_PLASMA) <= GetResourceAmount(this, RESOURCE_PLASMA)) {return true;}
if (item.itemdef.instanceOfPowerup) {return true;}
return false;
t += xydistance / autocvar_g_jetpack_maxspeed_side;
fuel = t * autocvar_g_jetpack_fuel * 0.8;
- LOG_DEBUG("jetpack ai: required fuel ", ftos(fuel), " this.ammo_fuel ", ftos(this.ammo_fuel));
+ LOG_DEBUG("jetpack ai: required fuel ", ftos(fuel), ", have ", ftos(GetResourceAmount(this, RESOURCE_FUEL)));
// enough fuel ?
- if(this.ammo_fuel>fuel || (this.items & IT_UNLIMITED_WEAPON_AMMO))
+ if(GetResourceAmount(this, RESOURCE_FUEL) > fuel || (this.items & IT_UNLIMITED_WEAPON_AMMO))
{
// Estimate cost
// (as onground costs calculation is mostly based on distances, here we do the same establishing some relationship
minf = autocvar_g_balance_fuel_regenstable;
limitf = GetResourceLimit(this, RESOURCE_FUEL);
- this.ammo_fuel = CalcRotRegen(this.ammo_fuel, minf, autocvar_g_balance_fuel_regen, autocvar_g_balance_fuel_regenlinear, frametime * (time > this.pauseregen_finished) * ((this.items & ITEM_JetpackRegen.m_itemid) != 0), maxf, autocvar_g_balance_fuel_rot, autocvar_g_balance_fuel_rotlinear, frametime * (time > this.pauserotfuel_finished), limitf);
+ SetResourceAmount(this, RESOURCE_FUEL, CalcRotRegen(GetResourceAmount(this, RESOURCE_FUEL), minf, autocvar_g_balance_fuel_regen, autocvar_g_balance_fuel_regenlinear,
+ frametime * (time > this.pauseregen_finished) * ((this.items & ITEM_JetpackRegen.m_itemid) != 0),
+ maxf, autocvar_g_balance_fuel_rot, autocvar_g_balance_fuel_rotlinear, frametime * (time > this.pauserotfuel_finished), limitf));
}
// Ugly hack to make sure the health and armor don't go beyond hard limit.
// TODO: Remove this hack when all code uses GivePlayerHealth and
PS(this) = PS(spectatee);
this.armortype = spectatee.armortype;
this.armorvalue = spectatee.armorvalue;
- this.ammo_cells = spectatee.ammo_cells; // TODO: these will be a part of inventory, so no need to worry about setting them later!
- this.ammo_plasma = spectatee.ammo_plasma;
- this.ammo_shells = spectatee.ammo_shells;
- this.ammo_nails = spectatee.ammo_nails;
- this.ammo_rockets = spectatee.ammo_rockets;
- this.ammo_fuel = spectatee.ammo_fuel;
+ SetResourceAmountExplicit(this, RESOURCE_CELLS, GetResourceAmount(spectatee, RESOURCE_CELLS));
+ SetResourceAmountExplicit(this, RESOURCE_PLASMA, GetResourceAmount(spectatee, RESOURCE_PLASMA));
+ SetResourceAmountExplicit(this, RESOURCE_SHELLS, GetResourceAmount(spectatee, RESOURCE_SHELLS));
+ SetResourceAmountExplicit(this, RESOURCE_BULLETS, GetResourceAmount(spectatee, RESOURCE_BULLETS));
+ SetResourceAmountExplicit(this, RESOURCE_ROCKETS, GetResourceAmount(spectatee, RESOURCE_ROCKETS));
+ SetResourceAmountExplicit(this, RESOURCE_FUEL, GetResourceAmount(spectatee, RESOURCE_FUEL));
this.effects = spectatee.effects & EFMASK_CHEAP; // eat performance
this.health = spectatee.health;
CS(this).impulse = 0;
}
this.items_added = 0;
- if ((this.items & ITEM_Jetpack.m_itemid) && ((this.items & ITEM_JetpackRegen.m_itemid) || this.ammo_fuel >= 0.01))
+ if ((this.items & ITEM_Jetpack.m_itemid) && ((this.items & ITEM_JetpackRegen.m_itemid) || GetResourceAmount(this, RESOURCE_FUEL) >= 0.01))
this.items_added |= IT_FUEL;
this.items |= this.items_added;
IL_EACH(g_items, it.targetname == this.target,
{
if (it.classname == "weapon_devastator") {
- this.ammo_rockets += it.count * WEP_CVAR(devastator, ammo);
+ SetResourceAmountExplicit(this, RESOURCE_ROCKETS, GetResourceAmount(this, RESOURCE_ROCKETS) + it.count * WEP_CVAR_PRI(devastator, ammo)); // WEAPONTODO
this.netname = cons(this.netname, "devastator");
}
else if (it.classname == "weapon_vortex") {
- this.ammo_cells += it.count * WEP_CVAR_PRI(vortex, ammo); // WEAPONTODO
+ SetResourceAmountExplicit(this, RESOURCE_CELLS, GetResourceAmount(this, RESOURCE_CELLS) + it.count * WEP_CVAR_PRI(vortex, ammo)); // WEAPONTODO
this.netname = cons(this.netname, "vortex");
}
else if (it.classname == "weapon_electro") {
- this.ammo_cells += it.count * WEP_CVAR_PRI(electro, ammo); // WEAPONTODO
+ SetResourceAmountExplicit(this, RESOURCE_CELLS, GetResourceAmount(this, RESOURCE_CELLS) + it.count * WEP_CVAR_PRI(electro, ammo)); // WEAPONTODO
this.netname = cons(this.netname, "electro");
}
else if (it.classname == "weapon_hagar") {
- this.ammo_rockets += it.count * WEP_CVAR_PRI(hagar, ammo); // WEAPONTODO
+ SetResourceAmountExplicit(this, RESOURCE_ROCKETS, GetResourceAmount(this, RESOURCE_ROCKETS) + it.count * WEP_CVAR_PRI(hagar, ammo)); // WEAPONTODO
this.netname = cons(this.netname, "hagar");
}
else if (it.classname == "weapon_crylink") {
- this.ammo_cells += it.count * WEP_CVAR_PRI(crylink, ammo);
+ SetResourceAmountExplicit(this, RESOURCE_CELLS, GetResourceAmount(this, RESOURCE_CELLS) + it.count * WEP_CVAR_PRI(crylink, ammo)); // WEAPONTODO
this.netname = cons(this.netname, "crylink");
}
else if (it.classname == "weapon_mortar") {
- this.ammo_rockets += it.count * WEP_CVAR_PRI(mortar, ammo); // WEAPONTODO
+ SetResourceAmountExplicit(this, RESOURCE_ROCKETS, GetResourceAmount(this, RESOURCE_ROCKETS) + it.count * WEP_CVAR_PRI(mortar, ammo)); // WEAPONTODO
this.netname = cons(this.netname, "mortar");
}
else if (it.classname == "item_armor_mega")
return e.(resource_field);
}
+bool SetResourceAmountExplicit(entity e, int resource_type, float amount)
+{
+ .float resource_field = GetResourceField(resource_type);
+ if (e.(resource_field) != amount)
+ {
+ e.(resource_field) = amount;
+ return true;
+ }
+ return false;
+}
+
void SetResourceAmount(entity e, int resource_type, float amount)
{
bool forbid = MUTATOR_CALLHOOK(SetResourceAmount, e, resource_type, amount);
amount_wasted = amount - max_amount;
amount = max_amount;
}
- .float resource_field = GetResourceField(resource_type);
- if (e.(resource_field) != amount)
+ bool changed = SetResourceAmountExplicit(e, resource_type, amount);
+ if (changed)
{
- e.(resource_field) = amount;
MUTATOR_CALLHOOK(ResourceAmountChanged, e, resource_type, amount);
}
if (amount_wasted == 0)
/// \return Current amount of resource the given entity has.
float GetResourceAmount(entity e, int resource_type);
+/// \brief Sets the resource amount of an entity without calling any hooks.
+/// \param[in,out] e Entity to adjust.
+/// \param[in] resource_type Type of the resource (a RESOURCE_* constant).
+/// \param[in] amount Amount of resource to set.
+/// \return Boolean for whether the ammo amount was changed
+bool SetResourceAmountExplicit(entity e, int resource_type, float amount);
+
/// \brief Sets the current amount of resource the given entity will have.
/// \param[in,out] e Entity to adjust.
/// \param[in] resource_type Type of the resource (a RESOURCE_* constant).