]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/weapons/all.qc
Weapons: split registration and base weapon definitions
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / all.qc
index 72c92471a9c537435aaeb29ed20072303c7700a3..0b441022c4ebf5900a8896a8dba5c5cb9dfb8bf6 100644 (file)
@@ -9,7 +9,6 @@
        #include "../constants.qh"
        #include "../stats.qh"
        #include "../../warpzonelib/anglestransform.qh"
-       #include "../../warpzonelib/mathlib.qh"
        #include "../../warpzonelib/common.qh"
        #include "../../warpzonelib/client.qh"
        #include "../util.qh"
@@ -25,7 +24,6 @@
        #include "../../dpdefs/progsdefs.qh"
     #include "../../dpdefs/dpextensions.qh"
     #include "../../warpzonelib/anglestransform.qh"
-    #include "../../warpzonelib/mathlib.qh"
     #include "../../warpzonelib/common.qh"
     #include "../../warpzonelib/util_server.qh"
     #include "../../warpzonelib/server.qh"
 #ifndef MENUQC
 #include "calculations.qc"
 #endif
+#define IMPLEMENTATION
 #include "all.inc"
+#undef IMPLEMENTATION
 
 // WEAPON PLUGIN SYSTEM
-entity weapon_info[WEP_MAXCOUNT];
-entity dummy_weapon_info;
 
 #if WEP_MAXCOUNT > 72
 # error Kein Weltraum links auf dem Gerät
@@ -149,90 +147,6 @@ WepSet ReadWepSet()
 }
 #endif
 
-void register_weapon(
-       int id,
-       WepSet bit,
-       bool(int) func,
-       .int ammotype,
-       int i,
-       int weapontype,
-       float pickupbasevalue,
-       vector clr,
-       string modelname,
-       string simplemdl,
-       string crosshair,
-       string wepimg,
-       string refname,
-       string wepname)
-{
-       entity e;
-       weapon_info[id - 1] = e = spawn();
-       e.classname = "weapon_info";
-       e.weapon = id;
-       e.weapons = bit;
-       e.weapon_func = func;
-       e.ammo_field = ammotype;
-       e.impulse = i;
-       e.spawnflags = weapontype;
-       e.bot_pickupbasevalue = pickupbasevalue;
-       e.wpcolor = clr;
-       e.wpmodel = strzone(strcat("wpn-", ftos(id)));
-       e.mdl = modelname;
-       e.model = strzone(strcat("models/weapons/g_", modelname, ".md3"));
-       e.w_simplemdl = strzone(simplemdl); // simpleitems weapon model/image
-       e.w_crosshair = strzone(car(crosshair));
-       string s = cdr(crosshair);
-       e.w_crosshair_size = ((s != "") ? stof(s) : 1); // so that we can scale the crosshair from code (for compat)
-       e.model2 = strzone(wepimg);
-       e.netname = refname;
-       e.message = wepname;
-
-       #ifdef CSQC
-       func(WR_INIT);
-       #endif
-}
-bool w_null(int dummy)
-{
-       return 0;
-}
-void register_weapons_done()
-{
-       dummy_weapon_info = spawn();
-       dummy_weapon_info.classname = "weapon_info";
-       dummy_weapon_info.weapon = 0; // you can recognize dummies by this
-       dummy_weapon_info.weapons = '0 0 0';
-       dummy_weapon_info.netname = "";
-       dummy_weapon_info.message = "AOL CD Thrower";
-       dummy_weapon_info.weapon_func = w_null;
-       dummy_weapon_info.wpmodel = "";
-       dummy_weapon_info.mdl = "";
-       dummy_weapon_info.model = "";
-       dummy_weapon_info.spawnflags = 0;
-       dummy_weapon_info.impulse = -1;
-       dummy_weapon_info.bot_pickupbasevalue = 0;
-       dummy_weapon_info.ammo_field = ammo_none;
-
-       dummy_weapon_info.w_crosshair = "gfx/crosshair1";
-       dummy_weapon_info.w_crosshair_size = 1;
-       dummy_weapon_info.model2 = "";
-
-       int i;
-       weaponorder_byid = "";
-       for(i = WEP_MAXCOUNT; i >= 1; --i)
-               if(weapon_info[i-1])
-                       weaponorder_byid = strcat(weaponorder_byid, " ", ftos(i));
-       weaponorder_byid = strzone(substring(weaponorder_byid, 1, strlen(weaponorder_byid) - 1));
-}
-entity get_weaponinfo(int id)
-{
-       entity w;
-       if(id < WEP_FIRST || id > WEP_LAST)
-               return dummy_weapon_info;
-       w = weapon_info[id - 1];
-       if(w)
-               return w;
-       return dummy_weapon_info;
-}
 string W_FixWeaponOrder(string order, float complete)
 {
        return fixPriorityList(order, WEP_FIRST, WEP_LAST, 230 - WEP_FIRST, complete);
@@ -353,14 +267,14 @@ void W_RandomWeapons(entity e, float n)
 
 string GetAmmoPicture(.int ammotype)
 {
-       switch(ammotype)
+       switch (ammotype)
        {
-               case ammo_shells:  return "ammo_shells";
-               case ammo_nails:   return "ammo_bullets";
-               case ammo_rockets: return "ammo_rockets";
-               case ammo_cells:   return "ammo_cells";
-               case ammo_plasma:  return "ammo_cells";
-               case ammo_fuel:    return "ammo_fuel";
+               case ammo_shells:  return ITEM_Shells.m_icon;
+               case ammo_nails:   return ITEM_Bullets.m_icon;
+               case ammo_rockets: return ITEM_Rockets.m_icon;
+               case ammo_cells:   return ITEM_Cells.m_icon;
+               case ammo_plasma:  return ITEM_Plasma.m_icon;
+               case ammo_fuel:    return ITEM_JetpackFuel.m_icon;
                default: return ""; // wtf, no ammo type?
        }
 }
@@ -394,4 +308,36 @@ int GetAmmoStat(.int ammotype)
        }
 }
 #endif
+
+string W_Sound(string w_snd)
+{
+       #define extensions(X) X(wav) X(ogg)
+       #define tryext(ext) { if (fexists(strcat("sound/", output = strcat("weapons/", w_snd, "."#ext)))) break; }
+       string output;
+       do {
+               extensions(tryext);
+               #undef tryext
+               #undef extensions
+               output = strcat("weapons/", w_snd);
+       } while (0);
+
+#ifdef SVQC
+       MUTATOR_CALLHOOK(WeaponSound, w_snd, output);
+       return weapon_sound_output;
+#else
+       return output;
+#endif
+}
+
+string W_Model(string w_mdl)
+{
+       string output = strcat("models/weapons/", w_mdl);
+#ifdef SVQC
+       MUTATOR_CALLHOOK(WeaponModel, w_mdl, output);
+       return weapon_model_output;
+#else
+       return output;
+#endif
+}
+
 #endif