]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/weapons/all.qh
Compact weapon flag checks
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / all.qh
index b86b77fadf4ffc0cb14de612227121f3433c2635..43398e6a5de5b539b9c9cea2b2bf187e10e63fcf 100644 (file)
@@ -1,12 +1,11 @@
-#ifndef WEAPONS_ALL_H
-#define WEAPONS_ALL_H
+#pragma once
 
-#include <common/command/all.qh>
+#include <common/command/_mod.qh>
 #include <common/stats.qh>
 #include "config.qh"
 
-// weapon sets
-USING(WepSet, vector);
+#include "weapon.qh"
+
 #ifdef SVQC
 void WriteWepSet(float dest, WepSet w);
 #endif
@@ -17,24 +16,23 @@ WepSet WepSet_GetFromStat_InMap();
 WepSet ReadWepSet();
 #endif
 
-#include "weapon.qh"
-
-#ifndef MENUQC
+#ifdef GAMEQC
 #include "calculations.qh"
+#include "projectiles.qh"
 #include <common/models/all.qh>
 #endif
 
 #include <common/util.qh>
 
-#ifdef SVQC
-#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, it.m_pickup = NEW(WeaponPickup, it)); }
 
+#ifdef SVQC
+#include <server/bot/api.qh>
+#endif
+
 .WepSet m_wepset;
 #define WEPSET(id) (WEP_##id.m_wepset)
 #define WepSet_FromWeapon(it) ((it).m_wepset)
@@ -66,17 +64,17 @@ GENERIC_COMMAND(dumpweapons, "Dump all weapons into weapons_dump.txt") // WEAPON
             if(wep_config_file >= 0)
             {
                 Dump_Weapon_Settings();
-                LOG_INFO(sprintf("Dumping weapons... File located in ^2data/data/%s^7.\n", filename));
+                LOG_INFOF("Dumping weapons... File located in ^2data/data/%s^7.", filename);
                 fclose(wep_config_file);
                 wep_config_file = -1;
                 wep_config_alsoprint = -1;
             }
             else
             {
-                LOG_INFO(sprintf("^1Error: ^7Could not open file '%s'!\n", filename));
+                LOG_INFOF("^1Error: ^7Could not open file '%s'!", filename);
             }
             #else
-            LOG_INFO(_("Weapons dump command only works with sv_cmd.\n"));
+            LOG_INFO(_("Weapons dump command only works with sv_cmd."));
             #endif
             return;
         }
@@ -84,10 +82,10 @@ GENERIC_COMMAND(dumpweapons, "Dump all weapons into weapons_dump.txt") // WEAPON
         default:
         case CMD_REQUEST_USAGE:
         {
-            LOG_INFO(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " dumpweapons [filename]"));
-            LOG_INFO("  Where 'filename' is the file to write (default is weapons_dump.cfg),\n");
-            LOG_INFO("  if supplied with '-' output to console as well as default,\n");
-            LOG_INFO("  if left blank, it will only write to default.\n");
+            LOG_INFO("Usage:^3 ", GetProgramCommandPrefix(), " dumpweapons [filename]");
+            LOG_INFO("  Where 'filename' is the file to write (default is weapons_dump.cfg),");
+            LOG_INFO("  if supplied with '-' output to console as well as default,");
+            LOG_INFO("  if left blank, it will only write to default.");
             return;
         }
     }
@@ -114,7 +112,8 @@ void W_PROP_think(entity this)
 STATIC_INIT_LATE(W_PROP_reloader)
 {
     entity e = W_PROP_reloader = new_pure(W_PROP_reloader);
-    WITHSELF(e, (setthink(e, W_PROP_think))(e));
+    setthink(e, W_PROP_think);
+    W_PROP_think(e);
 }
 #endif
 
@@ -131,10 +130,12 @@ REGISTER_WEAPON(Null, NEW(Weapon));
 Weapon Weapons_fromstr(string s)
 {
     FOREACH(Weapons, it != WEP_Null && it.netname == s, return it);
-    return NULL;
+    return WEP_Null;
 }
 
 
+#ifdef GAMEQC
+
 // legacy w_prop mappings
 #define X(fld, T) .T fld; .T wepvar_##fld = fld;
 X(switchdelay_drop, float)
@@ -143,12 +144,16 @@ X(weaponreplace, string)
 X(weaponstartoverride, float)
 X(weaponstart, float)
 X(weaponthrowable, float)
+#ifdef SVQC
 X(reload_ammo, float)
-.float reloading_ammo = reload_ammo;
+const .float reloading_ammo = reload_ammo;
 X(reload_time, float)
-.float reloading_time = reload_time;
+const .float reloading_time = reload_time;
+#endif
 #undef X
 
+#endif
+
 
 
 #define W_PROPS(L, class, prefix) \
@@ -166,12 +171,17 @@ X(reload_time, float)
     #define W_PROP_BOTH(class, fld, T, wepname) \
             W_PROP_PRI(class, fld, T, wepname) \
             W_PROP_SEC(class, fld, T, wepname)
-    #define W_PROP_BEGIN(class)
-        #define _W_PROP(class, fld, T, wepname) \
-            /* static */ T _W_PROP_CVAR(wepname, fld); \
-            ATTRIB(class, wepvar_##fld, T, _W_PROP_CVAR(wepname, fld));
-        #define _W_PROP_CVAR(wepname, fld) autocvar_g_balance_##wepname##_##fld
-    #define W_PROP_END()
+       #define W_PROP_BEGIN(class)
+               #ifdef GAMEQC
+                       #define _W_PROP(class, fld, T, wepname) \
+                               /* static */ T _W_PROP_CVAR(wepname, fld); \
+                               ATTRIB(class, wepvar_##fld, T, _W_PROP_CVAR(wepname, fld));
+                       #define _W_PROP_CVAR(wepname, fld) autocvar_g_balance_##wepname##_##fld
+               #else
+                       #define _W_PROP(class, fld, T, wepname)
+                       #define _W_PROP_CVAR(wepname, fld)
+               #endif
+       #define W_PROP_END()
 
 
 
@@ -182,13 +192,15 @@ X(reload_time, float)
     #define W_CONFIG_BOTH(class, fld, T, wepname) \
             W_CONFIG_PRI(class, fld, T, wepname) \
             W_CONFIG_SEC(class, fld, T, wepname)
-    #define W_CONFIG_BEGIN(class) METHOD(class, wr_config, void(class this)) {
-        #ifdef SVQC
-            #define _W_CONFIG(class, fld, T, wepname) if (#wepname == this.netname) WEP_CONFIG_WRITE_CVARS(wepname, fld, T);
-        #else
-            #define _W_CONFIG(class, fld, T, wepname)
-        #endif
-    #define W_CONFIG_END() }
+       #ifdef SVQC
+               #define W_CONFIG_BEGIN(class) METHOD(class, wr_config, void(class this)) {
+                       #define _W_CONFIG(class, fld, T, wepname) if (#wepname == this.netname) WEP_CONFIG_WRITE_CVARS(wepname, fld, T);
+               #define W_CONFIG_END() }
+       #else
+               #define W_CONFIG_BEGIN(class)
+                       #define _W_CONFIG(class, fld, T, wepname)
+               #define W_CONFIG_END()
+       #endif
 
 
     #define W_UPDATE(class, wepname, fld, T, m)     W_UPDATE_##m(class, fld, T, wepname)
@@ -198,27 +210,33 @@ X(reload_time, float)
     #define W_UPDATE_BOTH(class, fld, T, wepname) \
             W_UPDATE_PRI(class, fld, T, wepname) \
             W_UPDATE_SEC(class, fld, T, wepname)
-    .entity baseline, baseline_target;
-    #define W_UPDATE_BEGIN(class) \
-        METHOD(class, wr_update, void(class this)) \
-        { \
-            noref entity b = this.baseline; \
-            if (!b) \
-            { \
-                b = this.baseline = new_pure(baseline); \
-                b.baseline_target = this; \
-            }
-        #ifdef SVQC
-            #define _W_UPDATE(class, fld, T, wepname) \
-                { \
-                    T it = _W_PROP_CVAR(wepname, fld); \
-                    b.wepvar_##fld = this.wepvar_##fld; \
-                    this.wepvar_##fld = it; \
-                }
-        #else
-            #define _W_UPDATE(class, fld, T, wepname)
-        #endif
-    #define W_UPDATE_END() }
+       #ifdef GAMEQC
+               .entity baseline, baseline_target;
+               #define W_UPDATE_BEGIN(class) \
+                       METHOD(class, wr_update, void(class this)) \
+                       { \
+                               noref entity b = this.baseline; \
+                               if (!b) \
+                               { \
+                                       b = this.baseline = new_pure(baseline); \
+                                       b.baseline_target = this; \
+                               }
+                       #ifdef SVQC
+                               #define _W_UPDATE(class, fld, T, wepname) \
+                                       { \
+                                               T it = _W_PROP_CVAR(wepname, fld); \
+                                               b.wepvar_##fld = this.wepvar_##fld; \
+                                               this.wepvar_##fld = it; \
+                                       }
+                       #else
+                               #define _W_UPDATE(class, fld, T, wepname)
+                       #endif
+               #define W_UPDATE_END() }
+       #else
+               #define W_UPDATE_BEGIN(class)
+                       #define _W_UPDATE(class, fld, T, wepname)
+               #define W_UPDATE_END()
+       #endif
 
 
     #define W_NET(class, wepname, fld, T, m)     W_NET_##m(class, fld, T, wepname)
@@ -228,8 +246,8 @@ X(reload_time, float)
     #define W_NET_BOTH(class, fld, T, wepname) \
             W_NET_PRI(class, fld, T, wepname) \
             W_NET_SEC(class, fld, T, wepname)
-    REGISTER_NET_TEMP(WeaponUpdate)
     #if defined(CSQC)
+        REGISTER_NET_TEMP(WeaponUpdate)
         #define W_NET_BEGIN(class) METHOD(class, wr_net, void(class this, int i)) { int n = 0;
             #define _W_NET(class, fld, T, wepname) \
             { \
@@ -247,12 +265,13 @@ X(reload_time, float)
             }
         #define W_NET_END() }
     #elif defined(SVQC)
+        REGISTER_NET_TEMP(WeaponUpdate)
         #define W_NET_BEGIN(class) \
             METHOD(class, wr_net, void(class this, int chan)) \
             { \
                 bool commit = false; \
                 int i = 0;
-    #define _W_NET(class, fld, T, wepname) \
+            #define _W_NET(class, fld, T, wepname) \
                 { \
                     ++i; \
                     T it = this.wepvar_##fld; \
@@ -262,9 +281,7 @@ X(reload_time, float)
                         WriteByte(chan, i); Write_##T(chan, it); \
                     } \
                 }
-    #define W_NET_END() \
-                if (commit) WriteByte(chan, 0); \
-            }
+        #define W_NET_END() if (commit) WriteByte(chan, 0); }
     #else
         #define W_NET_BEGIN(class)
             #define _W_NET(class, fld, T, wepname)
@@ -298,18 +315,19 @@ REGISTRY_CHECK(Weapons)
 
 STATIC_INIT(register_weapons_done)
 {
+       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.weapons = set;
+        if (it.spawnflags & WEP_FLAG_SUPERWEAPON) WEPSET_SUPERWEAPONS |= 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", inaccessible);
     #ifdef CSQC
     FOREACH(Weapons, true, it.wr_init(it));
     #endif
@@ -320,17 +338,19 @@ STATIC_INIT(register_weapons_done)
     weaponorder_byid = strzone(substring(weaponorder_byid, 1, -1));
 }
 
-#ifndef MENUQC
+#ifdef GAMEQC
 
 .entity weaponchild;
 .entity exteriorweaponentity;
-vector weaponentity_glowmod(Weapon wep, int c)
+vector weaponentity_glowmod(Weapon wep, entity actor, int c, entity wepent)
 {
     vector g;
-    if (!(g = wep.wr_glow(wep))) g = colormapPaletteColor(c & 0x0F, true) * 2;
+    if (!(g = wep.wr_glow(wep, actor, wepent))) g = colormapPaletteColor(c & 0x0F, true) * 2;
     return g;
 }
 
+.int m_gunalign;
+
 //.int weapon; // current weapon
 .string weaponname; // name of .weapon
 
@@ -354,8 +374,17 @@ ENUMCLASS_END(WFRAME)
 
 .WFRAME wframe;
 
+#ifdef SVQC
+    #define G_SHOOTFROMFIXEDORIGIN autocvar_g_shootfromfixedorigin
+#elif defined(CSQC)
+    string autocvar_cl_shootfromfixedorigin;
+    #define G_SHOOTFROMFIXEDORIGIN autocvar_cl_shootfromfixedorigin
+#endif
+
 vector shotorg_adjust_values(vector vecs, bool y_is_right, bool visual, int algn);
 void CL_WeaponEntity_SetModel(entity this, string name, bool _anim);
-#endif
 
+#ifdef SVQC
+void wframe_send(entity actor, entity weaponentity, vector a, bool restartanim);
+#endif
 #endif