Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
weapon.qh
Go to the documentation of this file.
1#pragma once
2
5#include <common/stats.qh>
6
7#ifdef SVQC
9#endif
10#ifndef SVQC
11 #include <common/util.qh> // for icon_path_from_HUDskin
12#endif
13
15
16const int MAX_WEAPONSLOTS = 2;
18
19int weaponslot(.entity weaponentity)
20{
21 for (int i = 0; i < MAX_WEAPONSLOTS; ++i)
22 if (weaponentities[i] == weaponentity)
23 return i;
24 return 0;
25}
26
27#ifdef GAMEQC
28// weapon states (actor.(weaponentity).state)
29const int WS_CLEAR = 0;
30const int WS_RAISE = 1;
31const int WS_DROP = 2;
32const int WS_INUSE = 3;
33const int WS_READY = 4;
34#endif
35
38 ATTRIB(Weapon, m_id, int, 0);
39#ifdef SVQC
41 ATTRIB(Weapon, m_canonical_spawnfunc, string);
44 {
45 return this;
46 }
47
49#endif
53 ATTRIB(Weapon, impulse, int, -1);
58#ifdef GAMEQC
60 ATTRIB(Weapon, mdl, string, "");
62 ATTRIB(Weapon, m_model, entity);
66 ATTRIB(Weapon, m_muzzleeffect, entity);
67#endif
68#ifdef CSQC
70 ATTRIB(Weapon, w_crosshair, string, "gfx/crosshairmoustache");
76#endif
77 ATTRIB(Weapon, model2, string, "");
79 ATTRIB(Weapon, netname, string, "");
81 ATTRIB(Weapon, m_name, string, "AOL CD Thrower");
84
85#ifdef GAMEQC
86 ATTRIB(Weapon, m_pickup, entity);
87#endif
88
89#ifdef SVQC
91 METHOD(Weapon, wr_setup, void(Weapon this, entity actor, .entity weaponentity)) { }
93 METHOD(Weapon, wr_think, void(Weapon this, entity actor, .entity weaponentity, int fire)) { }
95 METHOD(Weapon, wr_checkammo1, bool(Weapon this, entity actor, .entity weaponentity))
96 {
97 return false;
98 }
99
100 METHOD(Weapon, wr_checkammo2, bool(Weapon this, entity actor, .entity weaponentity))
101 {
102 return false;
103 }
104
105 METHOD(Weapon, wr_aim, void(Weapon this, entity actor, .entity weaponentity)) { }
106#endif
107#ifdef GAMEQC
109 METHOD(Weapon, wr_init, void(Weapon this)) { }
110#endif
111#ifdef SVQC
114 {
115 return NULL;
116 }
117
119 {
120 return NULL;
121 }
122
123 METHOD(Weapon, wr_reload, void(Weapon this, entity actor, .entity weaponentity)) { }
125 METHOD(Weapon, wr_resetplayer, void(Weapon this, entity actor)) { }
127 METHOD(Weapon, wr_impacteffect, void(Weapon this, entity actor)) { }
129 METHOD(Weapon, wr_playerdeath, void(Weapon this, entity actor, .entity weaponentity)) { }
131 METHOD(Weapon, wr_gonethink, void(Weapon this, entity actor, .entity weaponentity)) { }
133 METHOD(Weapon, wr_config, void(Weapon this)) { }
134#endif
135#ifdef GAMEQC
137 METHOD(Weapon, wr_glow, vector(Weapon this, int actor_colors, entity wepent))
138 {
139 return '0 0 0';
140 }
141
142 METHOD(Weapon, wr_zoom, bool(Weapon this, entity actor))
143 {
144 // no weapon specific image for this weapon
145 return false;
146 }
147#endif
148#ifdef CSQC
151 {
152 return false;
153 }
154
156 {
157 return string_null;
158 }
159#endif
160#ifdef SVQC
162 METHOD(Weapon, wr_drop, void(Weapon this, entity actor, .entity weaponentity)) { }
164 METHOD(Weapon, wr_pickup, void(Weapon this, entity actor, .entity weaponentity)) { }
166 METHOD(Weapon, wr_update, void(Weapon this)) { }
167#endif
168#ifdef MENUQC
169 METHOD(Weapon, describe, string(Weapon this))
170 {
171 TC(Weapon, this);
172 return SUPER(Weapon).describe(this);
173 }
174#endif
175#ifndef SVQC
176 METHOD(Weapon, display, void(Weapon this, void(string name, string icon) returns))
177 {
178 returns(this.m_name, icon_path_from_HUDskin(this.model2));
179 }
180#endif
182
183#ifdef SVQC
184
186#define SPAWNFUNC_WEAPON(name, weapon) \
187 spawnfunc(name) \
188 { \
189 weapon_defaultspawnfunc(this, weapon); \
190 }
191
192#else
193
194#define SPAWNFUNC_WEAPON(name, weapon)
195
196#endif
197
198#ifdef GAMEQC
202 ATTRIB(WeaponPickup, m_sound, Sound, SND_WEAPONPICKUP);
203#ifdef SVQC
206 ATTRIB(WeaponPickup, m_pickupevalfunc, float(entity player, entity item), weapon_pickupevalfunc);
207#endif
209 {
211 this.m_weapon = w;
212 this.m_name = w.m_name;
213 this.m_model = w.m_model;
214#ifdef SVQC
216#endif
217 }
218#ifdef SVQC
219 METHOD(WeaponPickup, giveTo, bool(entity this, entity item, entity player))
220 {
221 bool b = Item_GiveTo(item, player);
222 //if (b)
223 //LOG_TRACEF("entity %i picked up %s", player, this.m_name);
224 return b;
225 }
226#endif
228
229#endif
230
231#ifdef SVQC
235
236.OffhandWeapon offhand;
237#endif
238
239#ifdef GAMEQC
240int max_shot_distance = 32768; // determined by world mins/maxs when map loads
241#endif
242
243#ifdef CSQC
245#endif
246
247// weapon flags
248const int WEP_TYPE_OTHER = BIT(0);
249const int WEP_TYPE_SPLASH = BIT(1);
250const int WEP_TYPE_HITSCAN = BIT(2);
251const int WEP_FLAG_CANCLIMB = BIT(3);
252const int WEP_FLAG_NORMAL = BIT(4);
253const int WEP_FLAG_HIDDEN = BIT(5);
254const int WEP_FLAG_RELOADABLE = BIT(6);
255const int WEP_FLAG_SUPERWEAPON = BIT(7);
257const int WEP_TYPE_MELEE_PRI = BIT(9);
258const int WEP_TYPE_MELEE_SEC = BIT(10);
259const int WEP_FLAG_DUALWIELD = BIT(11);
260const int WEP_FLAG_NODUAL = BIT(12);
262const int WEP_FLAG_BLEED = BIT(14);
263const int WEP_FLAG_NOTRUEAIM = BIT(15);
265
266// variables:
268
269#ifdef GAMEQC
270// g_weaponarena type
271enum
272{
284};
285#endif
#define BIT(n)
Only ever assign into the first 24 bits in QC (so max is BIT(23)).
Definition bits.qh:8
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
virtual void offhand_think()
Definition weapon.qh:233
int m_botvalue
Definition pickup.qh:23
ATTRIB(WeaponPickup, m_weapon, Weapon)
virtual void giveTo()
Definition weapon.qh:219
WeaponPickup(Weapon w)
Definition weapon.qh:208
float weapon_pickupevalfunc(entity player, entity item)
int m_itemflags
Definition weapon.qh:204
Sound m_sound
Definition weapon.qh:202
fields which are explicitly/manually set are marked with "M", fields set automatically are marked wit...
Definition weapon.qh:37
int impulse
M: impulse : weapon impulse.
Definition weapon.qh:53
virtual void wr_suicidemessage()
(SERVER) notification number for suicide message (may inspect w_deathtype for details)
Definition weapon.qh:113
virtual void wr_setup()
(SERVER) setup weapon data
Definition weapon.qh:91
virtual void wr_reload()
(SERVER) handles reloading for weapon
Definition weapon.qh:123
virtual void m_spawnfunc_hookreplace()
control what happens when this weapon is spawned
Definition weapon.qh:43
virtual void wr_think()
(SERVER) logic to run every frame
Definition weapon.qh:93
Resource ammo_type
M: ammotype : main ammo type.
Definition weapon.qh:51
string m_name
M: wepname : human readable name.
Definition weapon.qh:81
virtual void wr_impacteffect()
(CLIENT) impact effect for weapon explosion
Definition weapon.qh:127
virtual void wr_update()
(SERVER) update cvar based properties
Definition weapon.qh:166
ATTRIB(Weapon, m_pickup, entity)
virtual void wr_playerdeath()
(SERVER) called whenever a player dies
Definition weapon.qh:129
string w_crosshair
M: crosshair : per-weapon crosshair: "CrosshairImage Size".
Definition weapon.qh:70
vector m_color
M: color : waypointsprite color.
Definition weapon.qh:57
virtual void wr_glow()
(BOTH) weapon specific glow
Definition weapon.qh:137
virtual void wr_drop()
(SERVER) the weapon is dropped
Definition weapon.qh:162
string mdl
M: modelname : name of model (without g_ v_ or h_ prefixes).
Definition weapon.qh:60
ATTRIB(Weapon, m_canonical_spawnfunc, string)
the canonical spawnfunc name
int m_id
Definition weapon.qh:38
virtual void wr_aim()
(SERVER) runs bot aiming code for this weapon
Definition weapon.qh:105
virtual void wr_checkammo2()
(SERVER) checks ammo for weapon second
Definition weapon.qh:100
string netname
M: refname : reference name name.
Definition weapon.qh:79
virtual void wr_zoomdir()
(CLIENT) check whether the weapon should zoom (special handling)
Definition weapon.qh:150
virtual void wr_killmessage()
(SERVER) notification number for kill message (may inspect w_deathtype for details)
Definition weapon.qh:118
ATTRIB(Weapon, m_model, entity)
M: model MDL_id_ITEM.
virtual void wr_zoom()
(BOTH) weapon specific zoom reticle
Definition weapon.qh:142
int spawnflags
M: flags : WEPSPAWNFLAG_... combined.
Definition weapon.qh:55
virtual void wr_pickup()
(SERVER) a weapon is picked up
Definition weapon.qh:164
virtual void wr_init()
(BOTH) precaches models/sounds used by this weapon, also sets up weapon properties
Definition weapon.qh:109
float w_crosshair_size
A: crosshair : per-weapon crosshair size (argument two of "crosshair" field).
Definition weapon.qh:72
virtual void wr_checkammo1()
(SERVER) checks ammo for weapon primary
Definition weapon.qh:95
ATTRIB(Weapon, m_muzzleeffect, entity)
M: flash effect EFFECT_id_MUZZLEFLASH.
virtual void wr_gonethink()
(SERVER) logic to run when weapon is lost
Definition weapon.qh:131
string model2
M: wepimg : "weaponfoobar" side view image file of weapon.
Definition weapon.qh:77
virtual void wr_config()
(SERVER) dump weapon cvars to config in data directory (see: sv_cmd dumpweapons)
Definition weapon.qh:133
entity m_muzzlemodel
M: flash model MDL_id_MUZZLEFLASH.
Definition weapon.qh:64
string m_deprecated_netname
M: deprecated refname : old reference name for compatibility with weapons that were renamed.
Definition weapon.qh:83
virtual void describe()
Definition weapon.qh:169
string w_reticle
A: reticle : per-weapon zoom reticle.
Definition weapon.qh:74
virtual void wr_viewmodel()
(CLIENT) weapon specific view model
Definition weapon.qh:155
float bot_pickupbasevalue
M: rating : bot weapon priority.
Definition weapon.qh:48
virtual void wr_resetplayer()
(SERVER) clears fields that the weapon may use
Definition weapon.qh:125
string m_name
Definition scores.qh:142
const int FL_WEAPON
Definition constants.qh:75
entity() spawn
#define USING(name, T)
Definition _all.inc:72
#define TC(T, sym)
Definition _all.inc:82
string name
Definition menu.qh:30
string string_null
Definition nil.qh:9
#define SUPER(cname)
Definition oo.qh:236
#define CLASS(...)
Definition oo.qh:149
#define ENDCLASS(cname)
Definition oo.qh:286
#define METHOD(cname, name, prototype)
Definition oo.qh:274
#define ATTRIB(...)
Definition oo.qh:152
#define CONSTRUCTOR(cname,...)
Definition oo.qh:217
#define CONSTRUCT(cname,...)
Definition oo.qh:126
#define NULL
Definition post.qh:14
vector
Definition self.qh:96
entity this
Definition self.qh:76
bool Item_GiveTo(entity item, entity player)
Definition items.qc:522
string model2
const int WEP_FLAG_CANCLIMB
can be used for movement
Definition weapon.qh:251
@ WEPARENA_ALL
Definition weapon.qh:276
@ WEPARENA_ALL_AVAILABLE
Definition weapon.qh:277
@ WEPARENA_NONE
Definition weapon.qh:274
@ WEPARENA_EXTENDED_AVAILABLE
Definition weapon.qh:281
@ WEPARENA_STANDARD_AVAILABLE
Definition weapon.qh:279
@ WEPARENA_EXTENDED
Definition weapon.qh:280
@ WEPARENA_DEVALL
Definition weapon.qh:282
@ WEPARENA_STANDARD
Definition weapon.qh:278
@ WEPARENA_DEVALL_AVAILABLE
Definition weapon.qh:283
@ WEPARENA_OFF
Definition weapon.qh:273
@ WEPARENA_CUSTOM
Definition weapon.qh:275
const int MAX_WEAPONSLOTS
Definition weapon.qh:16
const int WEP_FLAG_RELOADABLE
can has reload
Definition weapon.qh:254
string weaponorder_byid
Definition weapon.qh:267
const int WEP_FLAG_NOTRUEAIM
weapon doesn't aim directly at targets
Definition weapon.qh:263
const int WEP_TYPE_HITSCAN
hitscan
Definition weapon.qh:250
const int WS_READY
idle frame
Definition weapon.qh:33
void weapon_defaultspawnfunc(entity this, Weapon e)
Definition spawning.qc:29
const int WEP_TYPE_MELEE_PRI
primary attack is melee swing (for animation)
Definition weapon.qh:257
const int WEP_TYPE_SPLASH
splash damage
Definition weapon.qh:249
int max_shot_distance
Definition weapon.qh:240
entity weaponentities[MAX_WEAPONSLOTS]
Definition weapon.qh:17
const int WS_CLEAR
no weapon selected
Definition weapon.qh:29
int autocvar_cl_tracers_teamcolor
Definition weapon.qh:244
const int WEP_FLAG_BLEED
weapon pierces and causes bleeding (used for damage effects)
Definition weapon.qh:262
const int WS_RAISE
raise frame
Definition weapon.qh:30
const int WEP_FLAG_SUPERWEAPON
powerup timer
Definition weapon.qh:255
const int WS_INUSE
fire state
Definition weapon.qh:32
const int WEP_FLAG_MUTATORBLOCKED
hides from impulse 99 etc. (mutators are allowed to clear this flag)
Definition weapon.qh:256
const int WEP_FLAG_DUALWIELD
weapon can be dual wielded
Definition weapon.qh:259
const int WEP_TYPE_MELEE_SEC
secondary attack is melee swing (for animation)
Definition weapon.qh:258
OffhandWeapon offhand
Definition weapon.qh:236
const int WEP_FLAG_PENETRATEWALLS
weapon has high calibur bullets that can penetrate thick walls (WEAPONTODO)
Definition weapon.qh:261
int weaponslot(.entity weaponentity)
Definition weapon.qh:19
const int WEP_FLAG_NODUAL
weapon doesn't work well with dual wielding (fireball etc just explode on fire), doesn't currently pr...
Definition weapon.qh:260
const int WEP_FLAG_HIDDEN
hides from menu
Definition weapon.qh:253
const int WS_DROP
deselecting frame
Definition weapon.qh:31
vector WepSet
Definition weapon.qh:14
const int WEP_TYPE_OTHER
not for damaging people
Definition weapon.qh:248
const int WEP_FLAG_NORMAL
in "most weapons" set
Definition weapon.qh:252
const int WEP_FLAG_SPECIALATTACK
special attack (not a true weapon); NOTE: if this flag is set then WEP_FLAG_HIDDEN must be set as wel...
Definition weapon.qh:264
Weapon m_weapon
Definition wepent.qh:26