From 1b12026463b2cfc3a4b9f7061605c7d7ff7bd29d Mon Sep 17 00:00:00 2001 From: Samual Lenks Date: Tue, 10 Dec 2013 00:36:39 -0500 Subject: [PATCH] More work on switching over to using entity field instead of item field for ammo --- qcsrc/common/weapons/w_fireball.qc | 2 +- qcsrc/common/weapons/weapons.qc | 7 +-- qcsrc/server/t_items.qc | 44 +---------------- qcsrc/server/weapons/spawning.qc | 18 ++++++- qcsrc/server/weapons/throwing.qc | 71 +++++++++++++--------------- qcsrc/server/weapons/weaponsystem.qc | 19 ++------ 6 files changed, 55 insertions(+), 106 deletions(-) diff --git a/qcsrc/common/weapons/w_fireball.qc b/qcsrc/common/weapons/w_fireball.qc index d27d565b7..f9956c1e5 100644 --- a/qcsrc/common/weapons/w_fireball.qc +++ b/qcsrc/common/weapons/w_fireball.qc @@ -2,7 +2,7 @@ REGISTER_WEAPON( /* WEP_##id */ FIREBALL, /* function */ w_fireball, -/* ammotype */ ammo_none, // WEAPONTODO +/* ammotype */ ammo_none, /* impulse */ 9, /* flags */ WEP_FLAG_SUPERWEAPON | WEP_TYPE_SPLASH, /* rating */ BOT_PICKUP_RATING_MID, diff --git a/qcsrc/common/weapons/weapons.qc b/qcsrc/common/weapons/weapons.qc index 9ec3b7ec0..501002f28 100644 --- a/qcsrc/common/weapons/weapons.qc +++ b/qcsrc/common/weapons/weapons.qc @@ -239,12 +239,7 @@ void W_RandomWeapons(entity e, float n) e.weapons = result; } -string W_Name(float weaponid) +string W_Name(float weaponid) // WEAPONTODO: make into a macro { return (get_weaponinfo(weaponid)).message; } - -float W_AmmoItemCode(float wpn) -{ - return (get_weaponinfo(wpn)).items & IT_AMMO; // WEAPONTODO -} diff --git a/qcsrc/server/t_items.qc b/qcsrc/server/t_items.qc index f9bb3ff10..c51ea58d9 100644 --- a/qcsrc/server/t_items.qc +++ b/qcsrc/server/t_items.qc @@ -281,54 +281,12 @@ float have_pickup_item(void) if(autocvar_g_pickup_items == 0) return FALSE; if(g_weaponarena) - if(self.weapons || (self.items & IT_AMMO)) + if(self.weapons || (self.items & IT_AMMO)) // no item or ammo pickups in weaponarena return FALSE; } return TRUE; } -floatfield Item_CounterField(float it) -{ - switch(it) - { - case IT_SHELLS: return ammo_shells; - case IT_NAILS: return ammo_nails; - case IT_ROCKETS: return ammo_rockets; - case IT_CELLS: return ammo_cells; - case IT_FUEL: return ammo_fuel; - case IT_5HP: return health; - case IT_25HP: return health; - case IT_HEALTH: return health; - case IT_ARMOR_SHARD: return armorvalue; - case IT_ARMOR: return armorvalue; - // add more things here (health, armor) - default: error("requested item has no counter field"); - } -#ifdef GMQCC - // should never happen - return health; -#endif -} - -string Item_CounterFieldName(float it) -{ - switch(it) - { - case IT_SHELLS: return "shells"; - case IT_NAILS: return "nails"; - case IT_ROCKETS: return "rockets"; - case IT_CELLS: return "cells"; - case IT_FUEL: return "fuel"; - - // add more things here (health, armor) - default: error("requested item has no counter field name"); - } -#ifdef GMQCC - // should never happen - return string_null; -#endif -} - /* float Item_Customize() { diff --git a/qcsrc/server/weapons/spawning.qc b/qcsrc/server/weapons/spawning.qc index 65188fef3..36ac23c96 100644 --- a/qcsrc/server/weapons/spawning.qc +++ b/qcsrc/server/weapons/spawning.qc @@ -19,7 +19,6 @@ void weapon_defaultspawnfunc(float wpn) { entity e; float t; - var .float ammofield; string s; entity oldself; float i, j; @@ -120,6 +119,22 @@ void weapon_defaultspawnfunc(float wpn) if(!self.superweapons_finished) self.superweapons_finished = autocvar_g_balance_superweapons_time; + // if we don't already have ammo, give us some ammo + if(!self.(e.current_ammo)) + { + switch(e.current_ammo) + { + case ammo_shells: self.ammo_shells = cvar("g_pickup_shells_weapon"); break; + case ammo_nails: self.ammo_nails = cvar("g_pickup_nails_weapon"); break; + case ammo_rockets: self.ammo_rockets = cvar("g_pickup_rockets_weapon"); break; + case ammo_cells: self.ammo_cells = cvar("g_pickup_cells_weapon"); break; + case ammo_fuel: self.ammo_fuel = cvar("g_pickup_fuel_weapon"); break; + } + } + + print(sprintf("defaultspawnfunc: current ammo count: %f\n", self.(e.current_ammo))); + + #if 0 if(e.items) { for(i = 0, j = 1; i < 24; ++i, j *= 2) @@ -132,6 +147,7 @@ void weapon_defaultspawnfunc(float wpn) } } } + #endif // pickup anyway if(g_pickup_weapons_anyway) diff --git a/qcsrc/server/weapons/throwing.qc b/qcsrc/server/weapons/throwing.qc index 9559ae8f8..bc64b7371 100644 --- a/qcsrc/server/weapons/throwing.qc +++ b/qcsrc/server/weapons/throwing.qc @@ -20,9 +20,9 @@ void thrown_wep_think() string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo) { entity oldself, wep; - float wa, thisammo, i, j; + float thisammo, i; string s; - var .float ammofield; + var .float ammofield = (get_weaponinfo(wpn)).current_ammo; wep = spawn(); @@ -61,8 +61,8 @@ string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vecto } } - wa = W_AmmoItemCode(wpn); - if(wa == 0) + //wa = W_AmmoItemCode(wpn); + if(ammofield == ammo_none) { oldself = self; self = wep; @@ -88,44 +88,40 @@ string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vecto return string_null; if(doreduce && g_weapon_stay == 2) { - for(i = 0, j = 1; i < 24; ++i, j *= 2) + // if our weapon is loaded, give its load back to the player + if(self.(weapon_load[self.weapon]) > 0) { - if(wa & j) - { - ammofield = Item_CounterField(j); - - // if our weapon is loaded, give its load back to the player - if(self.(weapon_load[self.weapon]) > 0) - { - own.ammofield += self.(weapon_load[self.weapon]); - self.(weapon_load[self.weapon]) = -1; // schedule the weapon for reloading - } - - wep.ammofield = 0; - } + own.ammofield += self.(weapon_load[self.weapon]); + self.(weapon_load[self.weapon]) = -1; // schedule the weapon for reloading } + + wep.ammofield = 0; } else if(doreduce) { - for(i = 0, j = 1; i < 24; ++i, j *= 2) + // if our weapon is loaded, give its load back to the player + if(self.(weapon_load[self.weapon]) > 0) + { + own.ammofield += self.(weapon_load[self.weapon]); + self.(weapon_load[self.weapon]) = -1; // schedule the weapon for reloading + } + + // stuff + thisammo = min(own.ammofield, wep.ammofield); + wep.ammofield = thisammo; + own.ammofield -= thisammo; + + //print(sprintf("W_ThrowNewWeapon: wep ammo count: %f, own ammo count: %f, thisammo = %f\n", wep.ammofield, own.ammofield, thisammo)); + + switch(ammofield) { - if(wa & j) - { - ammofield = Item_CounterField(j); - - // if our weapon is loaded, give its load back to the player - if(self.(weapon_load[self.weapon]) > 0) - { - own.ammofield += self.(weapon_load[self.weapon]); - self.(weapon_load[self.weapon]) = -1; // schedule the weapon for reloading - } - - thisammo = min(own.ammofield, wep.ammofield); - wep.ammofield = thisammo; - own.ammofield -= thisammo; - s = strcat(s, " and ", ftos(thisammo), " ", Item_CounterFieldName(j)); - } + case ammo_shells: s = sprintf("%s and %d shells", s, thisammo); break; + case ammo_nails: s = sprintf("%s and %d nails", s, thisammo); break; + case ammo_rockets: s = sprintf("%s and %d rockets", s, thisammo); break; + case ammo_cells: s = sprintf("%s and %d cells", s, thisammo); break; + case ammo_fuel: s = sprintf("%s and %d fuel", s, thisammo); break; } + s = substring(s, 5, -1); } wep.glowmod = own.weaponentity_glowmod; @@ -140,8 +136,6 @@ string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vecto float W_IsWeaponThrowable(float w) { - float wa; - if (!autocvar_g_pickup_items) return 0; if (g_weaponarena) @@ -153,13 +147,12 @@ float W_IsWeaponThrowable(float w) if(w == 0) return 0; - wa = W_AmmoItemCode(w); if(start_weapons & WepSet_FromWeapon(w)) { // start weapons that take no ammo can't be dropped (this prevents dropping the laser, as long as it continues to use no ammo) if(start_items & IT_UNLIMITED_WEAPON_AMMO) return 0; - if(wa == 0) + if((get_weaponinfo(w)).current_ammo == ammo_none) return 0; } diff --git a/qcsrc/server/weapons/weaponsystem.qc b/qcsrc/server/weapons/weaponsystem.qc index 14886583b..545d36ccc 100644 --- a/qcsrc/server/weapons/weaponsystem.qc +++ b/qcsrc/server/weapons/weaponsystem.qc @@ -661,7 +661,7 @@ void W_WeaponFrame() self.switchingweapon = 0; self.weaponentity.state = WS_CLEAR; self.weaponname = ""; - self.items &= ~IT_AMMO; + //self.items &= ~IT_AMMO; return; } @@ -679,8 +679,8 @@ void W_WeaponFrame() self.switchingweapon = self.switchweapon; entity newwep = get_weaponinfo(self.switchweapon); - self.items &= ~IT_AMMO; - self.items = self.items | (newwep.items & IT_AMMO); + //self.items &= ~IT_AMMO; + //self.items = self.items | (newwep.items & IT_AMMO); // the two weapon entities will notice this has changed and update their models self.weapon = self.switchweapon; @@ -774,19 +774,6 @@ void W_WeaponFrame() bprint("\{1}^1ERROR: undefined weapon think function for ", self.netname, "\n"); } } - -#if 0 - if (self.items & IT_CELLS) - self.currentammo = self.ammo_cells; - else if (self.items & IT_ROCKETS) - self.currentammo = self.ammo_rockets; - else if (self.items & IT_NAILS) - self.currentammo = self.ammo_nails; - else if (self.items & IT_SHELLS) - self.currentammo = self.ammo_shells; - else - self.currentammo = 1; -#endif } void W_AttachToShotorg(entity flash, vector offset) -- 2.39.2