]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapons.qh
little reorganization
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapons.qh
1 #ifndef MENUQC
2 #include "calculations.qh"
3 #endif
4
5 const float MAX_SHOT_DISTANCE = 32768;
6
7 const float BOT_PICKUP_RATING_LOW  =  2500;
8 const float BOT_PICKUP_RATING_MID  =  5000;
9 const float BOT_PICKUP_RATING_HIGH = 10000;
10
11 const float WEP_TYPE_OTHER          =  0x00; // not for damaging people
12 const float WEP_TYPE_SPLASH         =  0x01; // splash damage
13 const float WEP_TYPE_HITSCAN        =  0x02; // hitscan
14 const float WEP_TYPEMASK            =  0x0F;
15 const float WEP_FLAG_CANCLIMB       =  0x10; // can be used for movement
16 const float WEP_FLAG_NORMAL         =  0x20; // in "most weapons" set
17 const float WEP_FLAG_HIDDEN         =  0x40; // hides from menu
18 const float WEP_FLAG_RELOADABLE     =  0x80; // can has reload
19 const float WEP_FLAG_SUPERWEAPON    = 0x100; // powerup timer
20 const float WEP_FLAG_MUTATORBLOCKED = 0x200; // hides from impulse 99 etc. (mutators are allowed to clear this flag)
21
22 // weapon requests // WEAPONTODO: give these better descriptions
23 const float WR_SETUP          =  1; // (SERVER) setup weapon data
24 const float WR_THINK          =  2; // (SERVER) logic to run every frame
25 const float WR_CHECKAMMO1     =  3; // (SERVER) checks ammo for weapon
26 const float WR_CHECKAMMO2     =  4; // (SERVER) checks ammo for weapon
27 const float WR_AIM            =  5; // (SERVER) runs bot aiming code for this weapon
28 const float WR_INIT           =  6; // (BOTH)   precaches models/sounds used by this weapon
29 const float WR_SUICIDEMESSAGE =  7; // (SERVER) notification number for suicide message (may inspect w_deathtype for details)
30 const float WR_KILLMESSAGE    =  8; // (SERVER) notification number for kill message (may inspect w_deathtype for details)
31 const float WR_RELOAD         =  9; // (SERVER) does not need to do anything
32 const float WR_RESETPLAYER    = 10; // (SERVER) does not need to do anything
33 const float WR_IMPACTEFFECT   = 11; // (CLIENT) impact effect
34 const float WR_SWITCHABLE     = 12; // (CLIENT) impact effect
35 const float WR_PLAYERDEATH    = 13; // (SERVER) does not need to do anything
36 const float WR_GONETHINK      = 14; // (SERVER) logic to run every frame, also if no longer having the weapon as long as the switch away has not been performed
37 const float WR_CONFIG         = 15; // (ALL)
38 const float WR_ZOOMRETICLE    = 16; // (CLIENT) weapon specific zoom reticle
39
40 // variables:
41 string weaponorder_byid;
42
43 // Weapon sets
44 typedef vector WepSet;
45 WepSet WepSet_FromWeapon(float a);
46 #ifdef SVQC
47 void WepSet_AddStat();
48 void WriteWepSet(float dest, WepSet w);
49 #endif
50 #ifdef CSQC
51 WepSet WepSet_GetFromStat();
52 WepSet ReadWepSet();
53 #endif
54
55 // Weapon name macros
56 #define WEP_FIRST 1
57 #define WEP_MAXCOUNT 24 // Increase as needed. Can be up to three times as much.
58 float WEP_COUNT;
59 float WEP_LAST;
60 WepSet WEPSET_ALL;
61 WepSet WEPSET_SUPERWEAPONS;
62
63 // functions:
64 entity get_weaponinfo(float id);
65 string W_FixWeaponOrder(string order, float complete);
66 string W_NameWeaponOrder(string order);
67 string W_NumberWeaponOrder(string order);
68 string W_FixWeaponOrder_BuildImpulseList(string o);
69 string W_FixWeaponOrder_AllowIncomplete(string order);
70 string W_FixWeaponOrder_ForceComplete(string order);
71
72 void W_RandomWeapons(entity e, float n);
73
74 string W_Name(float weaponid);
75
76 #ifdef CSQC
77 .float GetAmmoFieldFromNum(float i);
78 string GetAmmoPicture(.float ammotype);
79 float GetAmmoStat(.float ammotype);
80 #endif
81
82 // ammo types
83 .float ammo_shells;
84 .float ammo_nails;
85 .float ammo_rockets;
86 .float ammo_cells;
87 .float ammo_fuel;
88 .float ammo_none;
89
90 // other useful macros
91 #define WEP_ACTION(wpn,wrequest) (get_weaponinfo(wpn)).weapon_func(wrequest)
92 #define AMMO_VAL(wpn) ((get_weaponinfo(wpn)).ammo_field)
93
94 // =====================
95 //  Weapon Registration
96 // =====================
97
98 // create cvars for weapon settings
99 #define WEP_ADD_CVAR_NONE(wepname,name) [[last]] float autocvar_g_balance_##wepname##_##name;
100
101 #define WEP_ADD_CVAR_PRI(wepname,name) WEP_ADD_CVAR_NONE(wepname, primary_##name)
102 #define WEP_ADD_CVAR_SEC(wepname,name) WEP_ADD_CVAR_NONE(wepname, secondary_##name)
103 #define WEP_ADD_CVAR_BOTH(wepname,name) \
104         WEP_ADD_CVAR_PRI(wepname, name) \
105         WEP_ADD_CVAR_SEC(wepname, name)
106
107 #define WEP_ADD_CVAR(wepid,wepname,mode,name) WEP_ADD_CVAR_##mode(wepname, name)
108
109 // create properties for weapon settings
110 #define WEP_ADD_PROP(wepid,wepname,type,prop,name) \
111         .type ##prop; \
112         [[last]] type autocvar_g_balance_##wepname##_##name;
113
114 // read cvars from weapon settings
115 #define WEP_CVAR(wepname,name) autocvar_g_balance_##wepname##_##name
116 #define WEP_CVAR_PRI(wepname,name) WEP_CVAR(wepname, primary_##name)
117 #define WEP_CVAR_SEC(wepname,name) WEP_CVAR(wepname, secondary_##name)
118 #define WEP_CVAR_BOTH(wepname,isprimary,name) ((isprimary) ? WEP_CVAR_PRI(wepname, name) : WEP_CVAR_SEC(wepname, name))
119
120 // set initialization values for weapon settings
121 #define WEP_SKIPCVAR(unuseda,unusedb,unusedc,unusedd) /* skip cvars */
122 #define WEP_SET_PROP(wepid,wepname,type,prop,name) get_weaponinfo(WEP_##wepid).##prop = autocvar_g_balance_##wepname##_##name;
123
124 float w_null(float dummy);
125 void register_weapon(float id, WepSet bit, float(float) func, .float ammotype, float i, float weapontype, float pickupbasevalue, vector clr, string modelname, string shortname, string wname);
126 void register_weapons_done();
127
128 // entity properties of weaponinfo:
129 .float weapon; // WEP_...
130 .WepSet weapons; // WEPSET_...
131 .string netname; // short name
132 .string message; // human readable name
133 .float items; // IT_... // WEAPONTODO: I thought I removed items from weapons... ?
134 .float(float) weapon_func; // w_...
135 .vector wpcolor; // waypointsprite color
136 .string mdl; // modelname without g_, v_, w_
137 .string model; // full name of g_ model
138 .float spawnflags; // WEPSPAWNFLAG_... combined
139 .float impulse; // weapon impulse
140 .float bot_pickupbasevalue; // bot weapon priority
141 .string model2; // wpn- sprite name
142 ..float ammo_field; // main ammo field
143
144 // note: the fabs call is just there to hide "if result is constant" warning
145 #define REGISTER_WEAPON_2(id,bit,func,ammotype,i,weapontype,pickupbasevalue,clr,modelname,shortname,wname) \
146         float id; \
147         WepSet bit; \
148         float func(float); \
149         void RegisterWeapons_##id() \
150         { \
151                 WEP_LAST = (id = WEP_FIRST + WEP_COUNT); \
152                 bit = WepSet_FromWeapon(id); \
153                 WEPSET_ALL |= bit; \
154                 if((weapontype) & WEP_FLAG_SUPERWEAPON) \
155                         WEPSET_SUPERWEAPONS |= bit; \
156                 ++WEP_COUNT; \
157                 register_weapon(id,bit,func,ammotype,i,weapontype,pickupbasevalue,clr,modelname,shortname,wname); \
158         } \
159         ACCUMULATE_FUNCTION(RegisterWeapons, RegisterWeapons_##id)
160 #ifdef MENUQC
161 #define REGISTER_WEAPON(id,func,ammotype,i,weapontype,pickupbasevalue,clr,modelname,shortname,wname) \
162         REGISTER_WEAPON_2(WEP_##id,WEPSET_##id,w_null,ammotype,i,weapontype,pickupbasevalue,clr,modelname,shortname,wname)
163 #else
164 #define REGISTER_WEAPON(id,func,ammotype,i,weapontype,pickupbasevalue,clr,modelname,shortname,wname) \
165         REGISTER_WEAPON_2(WEP_##id,WEPSET_##id,func,ammotype,i,weapontype,pickupbasevalue,clr,modelname,shortname,wname)
166 #endif
167
168 #include "all.qh"
169
170 #undef WEP_ADD_CVAR_MO_PRI
171 #undef WEP_ADD_CVAR_MO_SEC
172 #undef WEP_ADD_CVAR_MO_BOTH
173 #undef WEP_ADD_CVAR_MO_NONE
174 #undef WEP_ADD_CVAR
175 #undef WEP_ADD_PROP
176 #undef REGISTER_WEAPON
177
178 ACCUMULATE_FUNCTION(RegisterWeapons, register_weapons_done);