]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/weapons/all.qh
Only spawn a single casing when firing shotgun
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / all.qh
index 429dfbd792d4a9f23d402f3d2d5bc559b498b5b2..fa9d64ab8d238666270e193eb967bd4230c19e0a 100644 (file)
@@ -1,12 +1,12 @@
 #ifndef WEAPONS_ALL_H
 #define WEAPONS_ALL_H
 
-#include "../command/all.qh"
-#include "../stats.qh"
+#include <common/command/all.qh>
+#include <common/stats.qh>
 #include "config.qh"
 
 // weapon sets
-typedef vector WepSet;
+USING(WepSet, vector);
 #ifdef SVQC
 void WriteWepSet(float dest, WepSet w);
 #endif
@@ -21,25 +21,24 @@ WepSet ReadWepSet();
 
 #ifndef MENUQC
 #include "calculations.qh"
-#include "../models/all.qh"
+#include <common/models/all.qh>
 #endif
 
-#include "../util.qh"
+#include <common/util.qh>
 
 #ifdef SVQC
-#include "../../server/bot/aim.qh"
+#include <server/bot/aim.qh>
 #endif
 
 REGISTRY(Weapons, 72) // Increase as needed. Can be up to 72.
 #define Weapons_from(i) _Weapons_from(i, WEP_Null)
 REGISTER_REGISTRY(Weapons)
-STATIC_INIT(WeaponPickup) { FOREACH(Weapons, true, LAMBDA(it.m_pickup = NEW(WeaponPickup, it))); }
+STATIC_INIT(WeaponPickup) { FOREACH(Weapons, true, it.m_pickup = NEW(WeaponPickup, it)); }
 
 .WepSet m_wepset;
 #define WEPSET(id) (WEP_##id.m_wepset)
 #define WepSet_FromWeapon(it) ((it).m_wepset)
 WepSet _WepSet_FromWeapon(int i);
-STATIC_INIT(WepSets) { FOREACH(Weapons, true, LAMBDA(it.m_wepset = _WepSet_FromWeapon(it.m_id))); }
 
 GENERIC_COMMAND(dumpweapons, "Dump all weapons into weapons_dump.txt") // WEAPONTODO: make this work with other progs than just server
 {
@@ -96,27 +95,32 @@ GENERIC_COMMAND(dumpweapons, "Dump all weapons into weapons_dump.txt") // WEAPON
 
 #ifdef SVQC
 entity W_PROP_reloader;
-float autocvar_w_prop_interval = 0;
-.void(Weapon this) wr_net;
-void W_PROP_reload()
+float autocvar_w_prop_interval = 5;
+.void(Weapon this, int) wr_net;
+void W_PROP_reload(int chan, entity to)
 {
-    SELFPARAM();
-    this.nextthink = time + autocvar_w_prop_interval;
+    W_PROP_reloader.nextthink = time + autocvar_w_prop_interval;
+    msg_entity = to;
     FOREACH(Weapons, true, {
         it.wr_update(it);
-        void(Weapon) f = it.wr_net;
-        if (f) f(it);
+        void(Weapon, int) f = it.wr_net;
+        if (f) f(it, chan);
     });
 }
+void W_PROP_think(entity this)
+{
+    W_PROP_reload(MSG_ALL, NULL);
+}
 STATIC_INIT_LATE(W_PROP_reloader)
 {
-    entity e = W_PROP_reloader = new(W_PROP_reloader);
-    make_pure(e);
-    WITH(entity, self, e, (e.think = W_PROP_reload)());
+    entity e = W_PROP_reloader = new_pure(W_PROP_reloader);
+    setthink(e, W_PROP_think);
+    W_PROP_think(e);
 }
 #endif
 
-#define REGISTER_WEAPON(...) EVAL(OVERLOAD(REGISTER_WEAPON, __VA_ARGS__))
+#define REGISTER_WEAPON(...) EVAL_REGISTER_WEAPON(OVERLOAD(REGISTER_WEAPON, __VA_ARGS__))
+#define EVAL_REGISTER_WEAPON(...) __VA_ARGS__
 #define REGISTER_WEAPON_2(id, inst) REGISTER(Weapons, WEP, id, m_id, inst)
 /** TODO: deprecated - remove */
 #define REGISTER_WEAPON_3(id, sname, inst) \
@@ -125,6 +129,11 @@ STATIC_INIT_LATE(W_PROP_reloader)
 
 REGISTER_WEAPON(Null, NEW(Weapon));
 
+Weapon Weapons_fromstr(string s)
+{
+    FOREACH(Weapons, it != WEP_Null && it.netname == s, return it);
+    return NULL;
+}
 
 
 // legacy w_prop mappings
@@ -197,8 +206,7 @@ X(reload_time, float)
             noref entity b = this.baseline; \
             if (!b) \
             { \
-                b = this.baseline = new(baseline); \
-                make_pure(b); \
+                b = this.baseline = new_pure(baseline); \
                 b.baseline_target = this; \
             }
         #ifdef SVQC
@@ -241,28 +249,22 @@ X(reload_time, float)
         #define W_NET_END() }
     #elif defined(SVQC)
         #define W_NET_BEGIN(class) \
-            METHOD(class, wr_net, void(class this)) \
+            METHOD(class, wr_net, void(class this, int chan)) \
             { \
-                int chan = MSG_INIT; \
-                for (;;) \
+                bool commit = false; \
+                int i = 0;
+    #define _W_NET(class, fld, T, wepname) \
                 { \
-                    bool commit = false; \
-                    int i = 0;
-        #define _W_NET(class, fld, T, wepname) \
+                    ++i; \
+                    T it = this.wepvar_##fld; \
+                    if (chan == MSG_ONE || it != this.baseline.wepvar_##fld) \
                     { \
-                        ++i; \
-                        T it = this.wepvar_##fld; \
-                        if (it != this.baseline.wepvar_##fld) \
-                        { \
-                            if (!commit) { commit = true; WriteHeader(chan, WeaponUpdate); WriteByte(chan, this.m_id); } \
-                            WriteByte(chan, i); Write_##T(chan, it); \
-                        } \
-                    }
-        #define W_NET_END() \
-                    if (commit) WriteByte(chan, 0); \
-                    if (chan == MSG_INIT) chan = MSG_ALL; \
-                    else break; \
-                } \
+                        if (!commit) { commit = true; WriteHeader(chan, WeaponUpdate); WriteByte(chan, this.m_id); } \
+                        WriteByte(chan, i); Write_##T(chan, it); \
+                    } \
+                }
+    #define W_NET_END() \
+                if (commit) WriteByte(chan, 0); \
             }
     #else
         #define W_NET_BEGIN(class)
@@ -297,22 +299,22 @@ REGISTRY_CHECK(Weapons)
 
 STATIC_INIT(register_weapons_done)
 {
-    FOREACH(Weapons, true, LAMBDA(
-        it.m_id = i;
-        WepSet set = it.m_wepset;
+       string inaccessible = "";
+    FOREACH(Weapons, true, {
+        WepSet set = it.m_wepset = _WepSet_FromWeapon(it.m_id = i);
         WEPSET_ALL |= set;
         if ((it.spawnflags) & WEP_FLAG_SUPERWEAPON) WEPSET_SUPERWEAPONS |= set;
-        it.weapon = it.m_id;
         it.weapons = set;
         if (it == WEP_Null) continue;
         int imp = WEP_IMPULSE_BEGIN + it.m_id - 1;
         if (imp <= WEP_IMPULSE_END)
             localcmd(sprintf("alias weapon_%s \"impulse %d\"\n", it.netname, imp));
         else
-            LOG_TRACEF("Impulse limit exceeded, weapon will not be directly accessible: %s\n", it.netname);
-    ));
+               inaccessible = strcat(inaccessible, "\n", it.netname);
+    });
+    if (inaccessible) LOG_TRACEF("Impulse limit exceeded, weapon(s) will not be directly accessible: %s\n", inaccessible);
     #ifdef CSQC
-    FOREACH(Weapons, true, LAMBDA(it.wr_init(it)));
+    FOREACH(Weapons, true, it.wr_init(it));
     #endif
     weaponorder_byid = "";
     for (int i = Weapons_MAX - 1; i >= 1; --i)
@@ -325,13 +327,14 @@ STATIC_INIT(register_weapons_done)
 
 .entity weaponchild;
 .entity exteriorweaponentity;
-.vector weaponentity_glowmod;
+vector weaponentity_glowmod(Weapon wep, int c)
+{
+    vector g;
+    if (!(g = wep.wr_glow(wep))) g = colormapPaletteColor(c & 0x0F, true) * 2;
+    return g;
+}
 
 //.int weapon; // current weapon
-#ifdef SVQC
-.int switchweapon = _STAT(SWITCHWEAPON);
-.int switchingweapon = _STAT(SWITCHINGWEAPON);
-#endif
 .string weaponname; // name of .weapon
 
 .vector spawnorigin; // for casings
@@ -355,7 +358,7 @@ ENUMCLASS_END(WFRAME)
 .WFRAME wframe;
 
 vector shotorg_adjust_values(vector vecs, bool y_is_right, bool visual, int algn);
-void CL_WeaponEntity_SetModel(entity this, string name);
+void CL_WeaponEntity_SetModel(entity this, string name, bool _anim);
 #endif
 
 #endif