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#else
10 #include <common/util.qh> // for icon_path_from_HUDskin
11#endif
12
14
15const int MAX_WEAPONSLOTS = 2;
17
18int weaponslot(.entity weaponentity)
19{
20 for (int i = 0; i < MAX_WEAPONSLOTS; ++i)
21 if (weaponentities[i] == weaponentity)
22 return i;
23 return 0;
24}
25
26#ifdef GAMEQC
27// weapon states (actor.(weaponentity).state)
28const int WS_CLEAR = 0;
29const int WS_RAISE = 1;
30const int WS_DROP = 2;
31const int WS_INUSE = 3;
32const int WS_READY = 4;
33#endif
34
37 ATTRIB(Weapon, m_id, int, 0);
38#ifdef SVQC
40 ATTRIB(Weapon, m_canonical_spawnfunc, string);
43 {
44 return this;
45 }
46
48#endif
52 ATTRIB(Weapon, impulse, int, -1);
57#ifdef GAMEQC
59 ATTRIB(Weapon, mdl, string, "");
61 ATTRIB(Weapon, m_model, entity);
65 ATTRIB(Weapon, m_muzzleeffect, entity);
66#endif
67#ifdef CSQC
69 ATTRIB(Weapon, w_crosshair, string, "gfx/crosshairmoustache");
75#endif
76 ATTRIB(Weapon, model2, string, "");
78 ATTRIB(Weapon, netname, string, "");
80 ATTRIB(Weapon, m_name, string, "AOL CD Thrower");
83
84#ifdef GAMEQC
85 ATTRIB(Weapon, m_pickup, entity);
86#endif
87
88#ifdef SVQC
90 METHOD(Weapon, wr_setup, void(Weapon this, entity actor, .entity weaponentity)) { }
92 METHOD(Weapon, wr_think, void(Weapon this, entity actor, .entity weaponentity, int fire)) { }
94 METHOD(Weapon, wr_checkammo1, bool(Weapon this, entity actor, .entity weaponentity))
95 {
96 return false;
97 }
98
99 METHOD(Weapon, wr_checkammo2, bool(Weapon this, entity actor, .entity weaponentity))
100 {
101 return false;
102 }
103
104 METHOD(Weapon, wr_aim, void(Weapon this, entity actor, .entity weaponentity)) { }
105#endif
106#ifdef GAMEQC
108 METHOD(Weapon, wr_init, void(Weapon this)) { }
109#endif
110#ifdef SVQC
113 {
114 return NULL;
115 }
116
118 {
119 return NULL;
120 }
121
122 METHOD(Weapon, wr_reload, void(Weapon this, entity actor, .entity weaponentity)) { }
124 METHOD(Weapon, wr_resetplayer, void(Weapon this, entity actor)) { }
126 METHOD(Weapon, wr_impacteffect, void(Weapon this, entity actor)) { }
128 METHOD(Weapon, wr_playerdeath, void(Weapon this, entity actor, .entity weaponentity)) { }
130 METHOD(Weapon, wr_gonethink, void(Weapon this, entity actor, .entity weaponentity)) { }
132 METHOD(Weapon, wr_config, void(Weapon this)) { }
133#endif
134#ifdef GAMEQC
136 METHOD(Weapon, wr_glow, vector(Weapon this, int actor_colors, entity wepent))
137 {
138 return '0 0 0';
139 }
140
141 METHOD(Weapon, wr_zoom, bool(Weapon this, entity actor))
142 {
143 // no weapon specific image for this weapon
144 return false;
145 }
146#endif
147#ifdef CSQC
150 {
151 return false;
152 }
153
155 {
156 return string_null;
157 }
158#endif
159#ifdef SVQC
161 METHOD(Weapon, wr_drop, void(Weapon this, entity actor, .entity weaponentity)) { }
163 METHOD(Weapon, wr_pickup, void(Weapon this, entity actor, .entity weaponentity)) { }
165 METHOD(Weapon, wr_update, void(Weapon this)) { }
166#endif
167#ifdef MENUQC
168 METHOD(Weapon, describe, string(Weapon this))
169 {
170 TC(Weapon, this);
171 return SUPER(Weapon).describe(this);
172 }
173#endif
174#ifndef SVQC
175 METHOD(Weapon, display, void(Weapon this, void(string name, string icon) returns))
176 {
177 returns(this.m_name, icon_path_from_HUDskin(this.model2));
178 }
179#endif
181
182#ifdef SVQC
183
184#define SPAWNFUNC_WEAPON(name, weapon) \
185 spawnfunc(name) \
186 { \
187 this.itemdef = weapon; \
188 InitializeEntity(this, StartItem, INITPRIO_DROPTOFLOOR); \
189 }
190
191#else
192
193#define SPAWNFUNC_WEAPON(name, weapon)
194
195#endif
196
197#ifdef GAMEQC
201 ATTRIB(WeaponPickup, m_sound, Sound, SND_WEAPONPICKUP);
202#ifdef SVQC
205 ATTRIB(WeaponPickup, m_pickupevalfunc, float(entity player, entity item), weapon_pickupevalfunc);
206#endif
208 {
210 this.m_weapon = w;
211 this.m_name = w.m_name;
212 this.m_model = w.m_model;
213#ifdef SVQC
215#endif
216 }
217#ifdef SVQC
218 METHOD(WeaponPickup, giveTo, bool(entity this, entity item, entity player))
219 {
220 bool b = Item_GiveTo(item, player);
221 //if (b)
222 //LOG_TRACEF("entity %i picked up %s", player, this.m_name);
223 return b;
224 }
225#endif
227
228#endif
229
230#ifdef SVQC
234
235.OffhandWeapon offhand;
236#endif
237
238#ifdef GAMEQC
239int max_shot_distance = 32768; // determined by world mins/maxs when map loads
240#endif
241
242#ifdef CSQC
244#endif
245
246// weapon flags
247const int WEP_TYPE_OTHER = BIT(0);
248const int WEP_TYPE_SPLASH = BIT(1);
249const int WEP_TYPE_HITSCAN = BIT(2);
250const int WEP_FLAG_CANCLIMB = BIT(3);
251const int WEP_FLAG_NORMAL = BIT(4);
252const int WEP_FLAG_HIDDEN = BIT(5);
253const int WEP_FLAG_RELOADABLE = BIT(6);
254const int WEP_FLAG_SUPERWEAPON = BIT(7);
256const int WEP_TYPE_MELEE_PRI = BIT(9);
257const int WEP_TYPE_MELEE_SEC = BIT(10);
258const int WEP_FLAG_DUALWIELD = BIT(11);
259const int WEP_FLAG_NODUAL = BIT(12);
261const int WEP_FLAG_BLEED = BIT(14);
262const int WEP_FLAG_NOTRUEAIM = BIT(15);
264
265// variables:
267
268#ifdef GAMEQC
269// g_weaponarena type
270enum
271{
283};
284#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:232
int m_botvalue
Definition pickup.qh:23
ATTRIB(WeaponPickup, m_weapon, Weapon)
virtual void giveTo()
Definition weapon.qh:218
WeaponPickup(Weapon w)
Definition weapon.qh:207
float weapon_pickupevalfunc(entity player, entity item)
int m_itemflags
Definition weapon.qh:203
Sound m_sound
Definition weapon.qh:201
fields which are explicitly/manually set are marked with "M", fields set automatically are marked wit...
Definition weapon.qh:36
int impulse
M: impulse : weapon impulse.
Definition weapon.qh:52
virtual void wr_suicidemessage()
(SERVER) notification number for suicide message (may inspect w_deathtype for details)
Definition weapon.qh:112
virtual void wr_setup()
(SERVER) setup weapon data
Definition weapon.qh:90
virtual void wr_reload()
(SERVER) handles reloading for weapon
Definition weapon.qh:122
virtual void m_spawnfunc_hookreplace()
control what happens when this weapon is spawned
Definition weapon.qh:42
virtual void wr_think()
(SERVER) logic to run every frame
Definition weapon.qh:92
Resource ammo_type
M: ammotype : main ammo type.
Definition weapon.qh:50
string m_name
M: wepname : human readable name.
Definition weapon.qh:80
virtual void wr_impacteffect()
(CLIENT) impact effect for weapon explosion
Definition weapon.qh:126
virtual void wr_update()
(SERVER) update cvar based properties
Definition weapon.qh:165
ATTRIB(Weapon, m_pickup, entity)
virtual void wr_playerdeath()
(SERVER) called whenever a player dies
Definition weapon.qh:128
string w_crosshair
M: crosshair : per-weapon crosshair: "CrosshairImage Size".
Definition weapon.qh:69
vector m_color
M: color : waypointsprite color.
Definition weapon.qh:56
virtual void wr_glow()
(BOTH) weapon specific glow
Definition weapon.qh:136
virtual void wr_drop()
(SERVER) the weapon is dropped
Definition weapon.qh:161
string mdl
M: modelname : name of model (without g_ v_ or h_ prefixes).
Definition weapon.qh:59
ATTRIB(Weapon, m_canonical_spawnfunc, string)
the canonical spawnfunc name
int m_id
Definition weapon.qh:37
virtual void wr_aim()
(SERVER) runs bot aiming code for this weapon
Definition weapon.qh:104
virtual void wr_checkammo2()
(SERVER) checks ammo for weapon second
Definition weapon.qh:99
string netname
M: refname : reference name name.
Definition weapon.qh:78
virtual void wr_zoomdir()
(CLIENT) check whether the weapon should zoom (special handling)
Definition weapon.qh:149
virtual void wr_killmessage()
(SERVER) notification number for kill message (may inspect w_deathtype for details)
Definition weapon.qh:117
ATTRIB(Weapon, m_model, entity)
M: model MDL_id_ITEM.
virtual void wr_zoom()
(BOTH) weapon specific zoom reticle
Definition weapon.qh:141
int spawnflags
M: flags : WEPSPAWNFLAG_... combined.
Definition weapon.qh:54
virtual void wr_pickup()
(SERVER) a weapon is picked up
Definition weapon.qh:163
virtual void wr_init()
(BOTH) precaches models/sounds used by this weapon, also sets up weapon properties
Definition weapon.qh:108
float w_crosshair_size
A: crosshair : per-weapon crosshair size (argument two of "crosshair" field).
Definition weapon.qh:71
virtual void wr_checkammo1()
(SERVER) checks ammo for weapon primary
Definition weapon.qh:94
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:130
string model2
M: wepimg : "weaponfoobar" side view image file of weapon.
Definition weapon.qh:76
virtual void wr_config()
(SERVER) dump weapon cvars to config in data directory (see: sv_cmd dumpweapons)
Definition weapon.qh:132
entity m_muzzlemodel
M: flash model MDL_id_MUZZLEFLASH.
Definition weapon.qh:63
string m_deprecated_netname
M: deprecated refname : old reference name for compatibility with weapons that were renamed.
Definition weapon.qh:82
virtual void describe()
Definition weapon.qh:168
string w_reticle
A: reticle : per-weapon zoom reticle.
Definition weapon.qh:73
virtual void wr_viewmodel()
(CLIENT) weapon specific view model
Definition weapon.qh:154
float bot_pickupbasevalue
M: rating : bot weapon priority.
Definition weapon.qh:47
virtual void wr_resetplayer()
(SERVER) clears fields that the weapon may use
Definition weapon.qh:124
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:523
string model2
const int WEP_FLAG_CANCLIMB
can be used for movement
Definition weapon.qh:250
@ WEPARENA_ALL
Definition weapon.qh:275
@ WEPARENA_ALL_AVAILABLE
Definition weapon.qh:276
@ WEPARENA_NONE
Definition weapon.qh:273
@ WEPARENA_EXTENDED_AVAILABLE
Definition weapon.qh:280
@ WEPARENA_STANDARD_AVAILABLE
Definition weapon.qh:278
@ WEPARENA_EXTENDED
Definition weapon.qh:279
@ WEPARENA_DEVALL
Definition weapon.qh:281
@ WEPARENA_STANDARD
Definition weapon.qh:277
@ WEPARENA_DEVALL_AVAILABLE
Definition weapon.qh:282
@ WEPARENA_OFF
Definition weapon.qh:272
@ WEPARENA_CUSTOM
Definition weapon.qh:274
const int MAX_WEAPONSLOTS
Definition weapon.qh:15
const int WEP_FLAG_RELOADABLE
can has reload
Definition weapon.qh:253
string weaponorder_byid
Definition weapon.qh:266
const int WEP_FLAG_NOTRUEAIM
weapon doesn't aim directly at targets
Definition weapon.qh:262
const int WEP_TYPE_HITSCAN
hitscan
Definition weapon.qh:249
const int WS_READY
idle frame
Definition weapon.qh:32
const int WEP_TYPE_MELEE_PRI
primary attack is melee swing (for animation)
Definition weapon.qh:256
const int WEP_TYPE_SPLASH
splash damage
Definition weapon.qh:248
int max_shot_distance
Definition weapon.qh:239
entity weaponentities[MAX_WEAPONSLOTS]
Definition weapon.qh:16
const int WS_CLEAR
no weapon selected
Definition weapon.qh:28
int autocvar_cl_tracers_teamcolor
Definition weapon.qh:243
const int WEP_FLAG_BLEED
weapon pierces and causes bleeding (used for damage effects)
Definition weapon.qh:261
const int WS_RAISE
raise frame
Definition weapon.qh:29
const int WEP_FLAG_SUPERWEAPON
powerup timer
Definition weapon.qh:254
const int WS_INUSE
fire state
Definition weapon.qh:31
const int WEP_FLAG_MUTATORBLOCKED
hides from impulse 99 etc. (mutators are allowed to clear this flag)
Definition weapon.qh:255
const int WEP_FLAG_DUALWIELD
weapon can be dual wielded
Definition weapon.qh:258
const int WEP_TYPE_MELEE_SEC
secondary attack is melee swing (for animation)
Definition weapon.qh:257
OffhandWeapon offhand
Definition weapon.qh:235
const int WEP_FLAG_PENETRATEWALLS
weapon has high calibur bullets that can penetrate thick walls (WEAPONTODO)
Definition weapon.qh:260
int weaponslot(.entity weaponentity)
Definition weapon.qh:18
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:259
const int WEP_FLAG_HIDDEN
hides from menu
Definition weapon.qh:252
const int WS_DROP
deselecting frame
Definition weapon.qh:30
vector WepSet
Definition weapon.qh:13
const int WEP_TYPE_OTHER
not for damaging people
Definition weapon.qh:247
const int WEP_FLAG_NORMAL
in "most weapons" set
Definition weapon.qh:251
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:263
Weapon m_weapon
Definition wepent.qh:26