]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
More work on switching over to using entity field instead of item field
authorSamual Lenks <samual@xonotic.org>
Tue, 10 Dec 2013 05:36:39 +0000 (00:36 -0500)
committerSamual Lenks <samual@xonotic.org>
Tue, 10 Dec 2013 05:36:39 +0000 (00:36 -0500)
for ammo

qcsrc/common/weapons/w_fireball.qc
qcsrc/common/weapons/weapons.qc
qcsrc/server/t_items.qc
qcsrc/server/weapons/spawning.qc
qcsrc/server/weapons/throwing.qc
qcsrc/server/weapons/weaponsystem.qc

index d27d565b7e5d8488fa6b632e97a3ed565aa7a595..f9956c1e5483892b8c6b9245448254fcbb06eccf 100644 (file)
@@ -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,
index 9ec3b7ec0bac0cda0ea2c850350f48440bd6ffaf..501002f28a4c418a4d2c82f50b6bba321e604520 100644 (file)
@@ -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
-}
index f9bb3ff10b64d173d028a32345c7c63a682e7b40..c51ea58d96afa65d36e868551124e1e8d9699129 100644 (file)
@@ -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()
 {
index 65188fef327696ad3917b0b5d01bf36e5f646d64..36ac23c96ea00b569fb9eb38f2ed07c0d0bbf2b0 100644 (file)
@@ -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)
index 9559ae8f8b80b9082be07c29031f00cba6207f6c..bc64b73713aa83dd25700815c4af2a141ebc17c2 100644 (file)
@@ -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;
        }
 
index 14886583b0119769827b67bdfedc0c99c61e2bc2..545d36ccc9f41e8f27a81be4bb67cfa891e8d97d 100644 (file)
@@ -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)