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 {
23 if (weaponentities[i] == weaponentity)
24 {
25 return i;
26 }
27 }
28 return 0;
29}
30
31// weapon states (actor.(weaponentity).state)
33const int WS_CLEAR = 0;
35const int WS_RAISE = 1;
37const int WS_DROP = 2;
39const int WS_INUSE = 3;
41const int WS_READY = 4;
42
45 ATTRIB(Weapon, m_id, int, 0);
47 ATTRIB(Weapon, m_canonical_spawnfunc, string);
53 ATTRIB(Weapon, impulse, int, -1);
61 ATTRIB(Weapon, mdl, string, "");
62#ifdef GAMEQC
64 ATTRIB(Weapon, m_model, entity);
68 ATTRIB(Weapon, m_muzzleeffect, entity);
69#endif
71 ATTRIB(Weapon, w_crosshair, string, "gfx/crosshairmoustache");
77 ATTRIB(Weapon, model2, string, "");
79 ATTRIB(Weapon, netname, string, "");
81 ATTRIB(Weapon, m_name, string, "AOL CD Thrower");
84
85 ATTRIB(Weapon, m_pickup, entity);
86
88 METHOD(Weapon, wr_setup, void(Weapon this, entity actor, .entity weaponentity)) {}
90 METHOD(Weapon, wr_think, void(Weapon this, entity actor, .entity weaponentity, int fire)) {}
92 METHOD(Weapon, wr_checkammo1, bool(Weapon this, entity actor, .entity weaponentity)) {return false;}
94 METHOD(Weapon, wr_checkammo2, bool(Weapon this, entity actor, .entity weaponentity)) {return false;}
96 METHOD(Weapon, wr_aim, void(Weapon this, entity actor, .entity weaponentity)) {}
98 METHOD(Weapon, wr_init, void(Weapon this)) {}
104 METHOD(Weapon, wr_reload, void(Weapon this, entity actor, .entity weaponentity)) {}
106 METHOD(Weapon, wr_resetplayer, void(Weapon this, entity actor)) {}
108 METHOD(Weapon, wr_impacteffect, void(Weapon this, entity actor)) {}
110 METHOD(Weapon, wr_playerdeath, void(Weapon this, entity actor, .entity weaponentity)) {}
112 METHOD(Weapon, wr_gonethink, void(Weapon this, entity actor, .entity weaponentity)) {}
114 METHOD(Weapon, wr_config, void(Weapon this)) {}
116 METHOD(Weapon, wr_zoom, bool(Weapon this, entity actor)) {
117 // no weapon specific image for this weapon
118 return false;
119 }
120
121 METHOD(Weapon, wr_zoomdir, bool(Weapon this)) {return false;}
123 METHOD(Weapon, wr_viewmodel, string(Weapon this, entity wep)) { return string_null; }
125 METHOD(Weapon, wr_glow, vector(Weapon this, int actor_colors, entity wepent)) { return '0 0 0'; }
127 METHOD(Weapon, wr_drop, void(Weapon this, entity actor, .entity weaponentity)) {}
129 METHOD(Weapon, wr_pickup, void(Weapon this, entity actor, .entity weaponentity)) {}
131 METHOD(Weapon, wr_update, void(Weapon this)) {}
132#ifdef MENUQC
133 METHOD(Weapon, describe, string(Weapon this))
134 {
135 TC(Weapon, this);
136 return SUPER(Weapon).describe(this);
137 }
138#endif
139#ifndef SVQC
140 METHOD(Weapon, display, void(Weapon this, void(string name, string icon) returns))
141 {
142 returns(this.m_name, icon_path_from_HUDskin(this.model2));
143 }
144#endif
146
147#ifdef SVQC
148
150#define SPAWNFUNC_WEAPON(name, weapon) \
151 spawnfunc(name) { weapon_defaultspawnfunc(this, weapon); }
152
153#else
154
155#define SPAWNFUNC_WEAPON(name, weapon)
156
157#endif
158
159#include <common/items/_mod.qh>
163#ifdef GAMEQC
164 ATTRIB(WeaponPickup, m_sound, Sound, SND_WEAPONPICKUP);
165#endif
166#ifdef SVQC
169 ATTRIB(WeaponPickup, m_pickupevalfunc, float(entity player, entity item), weapon_pickupevalfunc);
170#endif
173 this.m_weapon = w;
174 this.m_name = w.m_name;
175#ifdef GAMEQC
176 this.m_model = w.m_model;
177#endif
178#ifdef SVQC
180#endif
181 }
182#ifdef SVQC
183 METHOD(WeaponPickup, giveTo, bool(entity this, entity item, entity player))
184 {
185 bool b = Item_GiveTo(item, player);
186 //if (b) {
187 //LOG_TRACEF("entity %i picked up %s", player, this.m_name);
188 //}
189 return b;
190 }
191#endif
193
197
198#ifdef SVQC
199.OffhandWeapon offhand;
200#endif
201
202#ifdef GAMEQC
203int max_shot_distance = 32768; // determined by world mins/maxs when map loads
204#endif
205
206#ifdef CSQC
208#endif
209
210// weapon flags
211const int WEP_TYPE_OTHER = BIT(0); // not for damaging people
212const int WEP_TYPE_SPLASH = BIT(1); // splash damage
213const int WEP_TYPE_HITSCAN = BIT(2); // hitscan
214const int WEP_FLAG_CANCLIMB = BIT(3); // can be used for movement
215const int WEP_FLAG_NORMAL = BIT(4); // in "most weapons" set
216const int WEP_FLAG_HIDDEN = BIT(5); // hides from menu
217const int WEP_FLAG_RELOADABLE = BIT(6); // can has reload
218const int WEP_FLAG_SUPERWEAPON = BIT(7); // powerup timer
219const int WEP_FLAG_MUTATORBLOCKED = BIT(8); // hides from impulse 99 etc. (mutators are allowed to clear this flag)
220const int WEP_TYPE_MELEE_PRI = BIT(9); // primary attack is melee swing (for animation)
221const int WEP_TYPE_MELEE_SEC = BIT(10); // secondary attack is melee swing (for animation)
222const int WEP_FLAG_DUALWIELD = BIT(11); // weapon can be dual wielded
223const int WEP_FLAG_NODUAL = BIT(12); // weapon doesn't work well with dual wielding (fireball etc just explode on fire), doesn't currently prevent anything
224const int WEP_FLAG_PENETRATEWALLS = BIT(13); // weapon has high calibur bullets that can penetrate thick walls (WEAPONTODO)
225const int WEP_FLAG_BLEED = BIT(14); // weapon pierces and causes bleeding (used for damage effects)
226const int WEP_FLAG_NOTRUEAIM = BIT(15); // weapon doesn't aim directly at targets
227const int WEP_FLAG_SPECIALATTACK = BIT(16); // special attack (not a true weapon); NOTE: if this flag is set then WEP_FLAG_HIDDEN must be set as well
228
229// variables:
#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:195
int m_botvalue
Definition pickup.qh:23
ATTRIB(WeaponPickup, m_weapon, Weapon)
virtual void giveTo()
Definition weapon.qh:183
WeaponPickup(Weapon w)
Definition weapon.qh:171
float weapon_pickupevalfunc(entity player, entity item)
int m_itemflags
Definition weapon.qh:167
Sound m_sound
Definition weapon.qh:164
fields which are explicitly/manually set are marked with "M", fields set automatically are marked wit...
Definition weapon.qh:44
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:100
virtual void wr_setup()
(SERVER) setup weapon data
Definition weapon.qh:88
virtual void wr_reload()
(SERVER) handles reloading for weapon
Definition weapon.qh:104
virtual void m_spawnfunc_hookreplace()
control what happens when this weapon is spawned
Definition weapon.qh:49
virtual void wr_think()
(SERVER) logic to run every frame
Definition weapon.qh:90
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:108
virtual void wr_update()
(SERVER) update cvar based properties
Definition weapon.qh:131
ATTRIB(Weapon, m_pickup, entity)
virtual void wr_playerdeath()
(SERVER) called whenever a player dies
Definition weapon.qh:110
string w_crosshair
M: crosshair : per-weapon crosshair: "CrosshairImage Size".
Definition weapon.qh:71
vector m_color
M: color : waypointsprite color.
Definition weapon.qh:59
virtual void wr_glow()
(BOTH) weapon specific glow
Definition weapon.qh:125
virtual void wr_drop()
(SERVER) the weapon is dropped
Definition weapon.qh:127
string mdl
M: modelname : name of model (without g_ v_ or h_ prefixes)
Definition weapon.qh:61
ATTRIB(Weapon, m_canonical_spawnfunc, string)
the canonical spawnfunc name
int m_id
Definition weapon.qh:45
virtual void wr_aim()
(SERVER) runs bot aiming code for this weapon
Definition weapon.qh:96
virtual void wr_checkammo2()
(SERVER) checks ammo for weapon second
Definition weapon.qh:94
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:121
virtual void wr_killmessage()
(SERVER) notification number for kill message (may inspect w_deathtype for details)
Definition weapon.qh:102
ATTRIB(Weapon, m_model, entity)
M: model MDL_id_ITEM.
virtual void wr_zoom()
(BOTH) weapon specific zoom reticle
Definition weapon.qh:116
int spawnflags
M: flags : WEPSPAWNFLAG_... combined.
Definition weapon.qh:55
virtual void wr_pickup()
(SERVER) a weapon is picked up
Definition weapon.qh:129
virtual void wr_init()
(BOTH) precaches models/sounds used by this weapon, also sets up weapon properties
Definition weapon.qh:98
float w_crosshair_size
A: crosshair : per-weapon crosshair size (argument two of "crosshair" field)
Definition weapon.qh:73
virtual void wr_checkammo1()
(SERVER) checks ammo for weapon primary
Definition weapon.qh:92
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:112
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:114
entity m_muzzlemodel
M: flash model MDL_id_MUZZLEFLASH.
Definition weapon.qh:66
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:133
string w_reticle
A: reticle : per-weapon zoom reticle.
Definition weapon.qh:75
virtual void wr_viewmodel()
(CLIENT) weapon specific view model
Definition weapon.qh:123
float bot_pickupbasevalue
M: rating : bot weapon priority.
Definition weapon.qh:57
virtual void wr_resetplayer()
(SERVER) clears fields that the weapon may use
Definition weapon.qh:106
string m_name
Definition scores.qh:142
const int FL_WEAPON
Definition constants.qh:83
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:231
#define CLASS(...)
Definition oo.qh:145
#define ENDCLASS(cname)
Definition oo.qh:281
#define METHOD(cname, name, prototype)
Definition oo.qh:269
#define ATTRIB(...)
Definition oo.qh:148
#define CONSTRUCTOR(cname,...)
Definition oo.qh:213
#define CONSTRUCT(cname,...)
Definition oo.qh:123
#define NULL
Definition post.qh:14
vector
Definition self.qh:92
entity this
Definition self.qh:72
bool Item_GiveTo(entity item, entity player)
Definition items.qc:528
string model2
const int WEP_FLAG_CANCLIMB
Definition weapon.qh:214
const int MAX_WEAPONSLOTS
Definition weapon.qh:16
const int WEP_FLAG_RELOADABLE
Definition weapon.qh:217
string weaponorder_byid
Definition weapon.qh:230
const int WEP_FLAG_NOTRUEAIM
Definition weapon.qh:226
const int WEP_TYPE_HITSCAN
Definition weapon.qh:213
const int WS_READY
idle frame
Definition weapon.qh:41
void weapon_defaultspawnfunc(entity this, Weapon e)
Definition spawning.qc:30
const int WEP_TYPE_MELEE_PRI
Definition weapon.qh:220
const int WEP_TYPE_SPLASH
Definition weapon.qh:212
int max_shot_distance
Definition weapon.qh:203
entity weaponentities[MAX_WEAPONSLOTS]
Definition weapon.qh:17
const int WS_CLEAR
no weapon selected
Definition weapon.qh:33
int autocvar_cl_tracers_teamcolor
Definition weapon.qh:207
const int WEP_FLAG_BLEED
Definition weapon.qh:225
const int WS_RAISE
raise frame
Definition weapon.qh:35
const int WEP_FLAG_SUPERWEAPON
Definition weapon.qh:218
const int WS_INUSE
fire state
Definition weapon.qh:39
const int WEP_FLAG_MUTATORBLOCKED
Definition weapon.qh:219
const int WEP_FLAG_DUALWIELD
Definition weapon.qh:222
vector WepSet
Definition weapon.qh:14
const int WEP_TYPE_MELEE_SEC
Definition weapon.qh:221
OffhandWeapon offhand
Definition weapon.qh:199
const int WEP_FLAG_PENETRATEWALLS
Definition weapon.qh:224
int weaponslot(.entity weaponentity)
Definition weapon.qh:19
const int WEP_FLAG_NODUAL
Definition weapon.qh:223
const int WEP_FLAG_HIDDEN
Definition weapon.qh:216
const int WS_DROP
deselecting frame
Definition weapon.qh:37
const int WEP_TYPE_OTHER
Definition weapon.qh:211
const int WEP_FLAG_NORMAL
Definition weapon.qh:215
const int WEP_FLAG_SPECIALATTACK
Definition weapon.qh:227
Weapon m_weapon
Definition wepent.qh:26