]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/weapons/selection.qh
Add REPLICATE_APPLYCHANGE macro
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / weapons / selection.qh
index 071a0fea8bcb73fb1b2ebad279b7d26cbdcf3f83..3e28b47455cd0413d1529ab0f779df2f7cfb7f91 100644 (file)
@@ -1,5 +1,16 @@
 #pragma once
 
+#include <common/weapons/_all.qh>
+#include <common/stats.qh>
+
+int autocvar_g_showweaponspawns;
+bool autocvar_g_weaponswitch_debug;
+bool autocvar_g_weaponswitch_debug_alternate;
+
+.int selectweapon; // last selected weapon of the player
+
+.WepSet dual_weapons;
+
 // switch between weapons
 void Send_WeaponComplain(entity e, float wpn, float type);
 
@@ -9,13 +20,14 @@ bool client_hasweapon(entity this, Weapon wpn, .entity weaponentity, float andam
 .int weaponcomplainindex;
 float W_GetCycleWeapon(entity this, string weaponorder, float dir, float imp, float complain, float skipmissing, .entity weaponentity);
 
-#define w_getbestweapon(ent,wepent) Weapons_from(W_GetCycleWeapon(ent, ent.cvar_cl_weaponpriority, 0, -1, false, true, wepent))
+#define w_getbestweapon(ent,wepent) REGISTRY_GET(Weapons, W_GetCycleWeapon(ent, CS_CVAR(ent).cvar_cl_weaponpriority, 0, -1, false, true, wepent))
 
 void W_SwitchWeapon_Force(Player this, Weapon w, .entity weaponentity);
 
 // perform weapon to attack (weaponstate and attack_finished check is here)
 void W_SwitchToOtherWeapon(entity this, .entity weaponentity);
-void W_SwitchWeapon(entity this, Weapon imp, .entity weaponentity);
+bool W_SwitchWeapon(entity this, Weapon imp, .entity weaponentity); // returns false if the player does not have the weapon
+void W_SwitchWeapon_TryOthers(entity this, Weapon imp, .entity weaponentity);
 
 void W_CycleWeapon(entity this, string weaponorder, float dir, .entity weaponentity);
 
@@ -29,3 +41,13 @@ void W_PreviousWeapon(entity this, float list, .entity weaponentity);
 
 // previously used if exists and has ammo, (second) best otherwise
 void W_LastWeapon(entity this, .entity weaponentity);
+
+// fix switchweapon (needed when spectating is disabled, as PutClientInServer comes too early)
+REPLICATE_APPLYCHANGE("cl_weaponpriority",
+       for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
+       {
+               .entity weaponentity = weaponentities[slot];
+               if (this.(weaponentity) && (this.(weaponentity).m_weapon != WEP_Null || slot == 0))
+                       this.(weaponentity).m_switchweapon = w_getbestweapon(this, weaponentity);
+       }
+);