]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon.qh
Merge branch 'master' into Mario/wepent_experimental
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon.qh
1 #pragma once
2
3 #include <common/items/item/pickup.qh>
4 #include <common/stats.qh>
5
6 #ifdef SVQC
7 #include <common/effects/qc/all.qh>
8 #endif
9
10 const int MAX_WEAPONSLOTS = 2;
11 .entity weaponentities[MAX_WEAPONSLOTS];
12
13 int weaponslot(.entity weaponentity)
14 {
15         for (int i = 0; i < MAX_WEAPONSLOTS; ++i)
16         {
17                 if (weaponentities[i] == weaponentity)
18                 {
19                         return i;
20                 }
21         }
22         return 0;
23 }
24
25 // weapon states (actor.(weaponentity).state)
26 /** no weapon selected */
27 const int WS_CLEAR  = 0;
28 /** raise frame */
29 const int WS_RAISE  = 1;
30 /** deselecting frame */
31 const int WS_DROP   = 2;
32 /** fire state */
33 const int WS_INUSE  = 3;
34 /** idle frame */
35 const int WS_READY  = 4;
36
37 #ifdef SVQC
38 .int ammo_shells;
39 .int ammo_nails;
40 .int ammo_rockets;
41 .int ammo_cells;
42 .int ammo_plasma = _STAT(PLASMA);
43 .int ammo_fuel = _STAT(FUEL);
44 .int ammo_none;
45 #else
46 .int ammo_shells;
47 .int ammo_nails;
48 .int ammo_rockets;
49 .int ammo_cells;
50 .int ammo_plasma;
51 .int ammo_fuel;
52 .int ammo_none;
53 #endif
54
55 /** fields which are explicitly/manually set are marked with "M", fields set automatically are marked with "A" */
56 CLASS(Weapon, Object)
57         ATTRIB(Weapon, m_id, int, 0);
58     /** A: WEPSET_id : WEPSET_... */
59     ATTRIB(Weapon, weapons, WepSet, '0 0 0');
60     /** M: ammotype  : main ammo field */
61     ATTRIB(Weapon, ammo_field, .int, ammo_none);
62     /** M: impulse   : weapon impulse */
63     ATTRIB(Weapon, impulse, int, -1);
64     /** M: flags     : WEPSPAWNFLAG_... combined */
65     ATTRIB(Weapon, spawnflags, int, 0);
66     /** M: rating    : bot weapon priority */
67     ATTRIB(Weapon, bot_pickupbasevalue, float, 0);
68     /** M: color     : waypointsprite color */
69     ATTRIB(Weapon, wpcolor, vector, '0 0 0');
70     /** M: modelname : name of model (without g_ v_ or h_ prefixes) */
71     ATTRIB(Weapon, mdl, string, "");
72     /** M: model MDL_id_ITEM */
73     ATTRIB(Weapon, m_model, entity);
74     /** M: crosshair : per-weapon crosshair: "CrosshairImage Size" */
75     ATTRIB(Weapon, w_crosshair, string, "gfx/crosshair1");
76     /** A: crosshair : per-weapon crosshair size (argument two of "crosshair" field) */
77     ATTRIB(Weapon, w_crosshair_size, float, 1);
78     /** A: reticle   : per-weapon zoom reticle */
79     ATTRIB(Weapon, w_reticle, string, "");
80     /** M: wepimg    : "weaponfoobar" side view image file of weapon. WEAPONTODO: Move out of skin files, move to common files */
81     ATTRIB(Weapon, model2, string, "");
82     /** M: refname   : reference name name */
83     ATTRIB(Weapon, netname, string, "");
84     /** M: wepname   : human readable name */
85     ATTRIB(Weapon, m_name, string, "AOL CD Thrower");
86
87     ATTRIB(Weapon, m_pickup, entity);
88
89     /** (SERVER) setup weapon data */
90     METHOD(Weapon, wr_setup, void(Weapon this, entity actor, .entity weaponentity)) {}
91     /** (SERVER) logic to run every frame */
92     METHOD(Weapon, wr_think, void(Weapon this, entity actor, .entity weaponentity, int fire)) {}
93     /** (SERVER) checks ammo for weapon primary */
94     METHOD(Weapon, wr_checkammo1, bool(Weapon this, entity actor, .entity weaponentity)) {return false;}
95     /** (SERVER) checks ammo for weapon second */
96     METHOD(Weapon, wr_checkammo2, bool(Weapon this, entity actor, .entity weaponentity)) {return false;}
97     /** (SERVER) runs bot aiming code for this weapon */
98     METHOD(Weapon, wr_aim, void(Weapon this, entity actor, .entity weaponentity)) {}
99     /** (BOTH)   precaches models/sounds used by this weapon, also sets up weapon properties */
100     METHOD(Weapon, wr_init, void(Weapon this)) {}
101     /** (SERVER) notification number for suicide message (may inspect w_deathtype for details) */
102     METHOD(Weapon, wr_suicidemessage, entity(Weapon this)) {return NULL;}
103     /** (SERVER) notification number for kill message (may inspect w_deathtype for details) */
104     METHOD(Weapon, wr_killmessage, entity(Weapon this)) {return NULL;}
105     /** (SERVER) handles reloading for weapon */
106     METHOD(Weapon, wr_reload, void(Weapon this, entity actor, .entity weaponentity)) {}
107     /** (SERVER) clears fields that the weapon may use */
108     METHOD(Weapon, wr_resetplayer, void(Weapon this, entity actor)) {}
109     /** (CLIENT) impact effect for weapon explosion */
110     METHOD(Weapon, wr_impacteffect, void(Weapon this, entity actor)) {}
111     /** (SERVER) called whenever a player dies */
112     METHOD(Weapon, wr_playerdeath, void(Weapon this, entity actor, .entity weaponentity)) {}
113     /** (SERVER) logic to run when weapon is lost */
114     METHOD(Weapon, wr_gonethink, void(Weapon this, entity actor, .entity weaponentity)) {}
115     /** (ALL)    dump weapon cvars to config in data directory (see: sv_cmd dumpweapons) */
116     METHOD(Weapon, wr_config, void(Weapon this)) {}
117     /** (BOTH) weapon specific zoom reticle */
118     METHOD(Weapon, wr_zoom, bool(Weapon this, entity actor)) {
119         // no weapon specific image for this weapon
120         return false;
121     }
122     /** (CLIENT) weapon specific view model */
123     METHOD(Weapon, wr_viewmodel, string(Weapon this, entity wep)) { return string_null; }
124     /** (CLIENT) weapon specific glow */
125     METHOD(Weapon, wr_glow, vector(Weapon this, entity actor, entity wepent)) { return '0 0 0'; }
126     /** (SERVER) the weapon is dropped */
127     METHOD(Weapon, wr_drop, void(Weapon this, entity actor, .entity weaponentity)) {}
128     /** (SERVER) a weapon is picked up */
129     METHOD(Weapon, wr_pickup, void(Weapon this, entity actor, .entity weaponentity)) {}
130     /** (SERVER) update cvar based properties */
131     METHOD(Weapon, wr_update, void(Weapon this)) {}
132         METHOD(Weapon, display, void(entity this, void(string name, string icon) returns)) {
133                 returns(this.m_name, this.model2 ? sprintf("/gfx/hud/%s/%s", cvar_string("menu_skin"), this.model2) : string_null);
134         }
135 ENDCLASS(Weapon)
136
137 #include <common/items/_mod.qh>
138 CLASS(WeaponPickup, Pickup)
139     ATTRIB(WeaponPickup, m_weapon, Weapon);
140     ATTRIB(WeaponPickup, m_name, string);
141 #ifdef GAMEQC
142     ATTRIB(WeaponPickup, m_sound, Sound, SND_WEAPONPICKUP);
143 #endif
144 #ifdef SVQC
145     ATTRIB(WeaponPickup, m_itemflags, int, FL_WEAPON);
146     float weapon_pickupevalfunc(entity player, entity item);
147     ATTRIB(WeaponPickup, m_pickupevalfunc, float(entity player, entity item), weapon_pickupevalfunc);
148 #endif
149     CONSTRUCTOR(WeaponPickup, Weapon w) {
150         CONSTRUCT(WeaponPickup);
151         this.m_weapon = w;
152         this.m_name = w.m_name;
153 #ifdef GAMEQC
154         this.m_model = w.m_model;
155 #endif
156 #ifdef SVQC
157         this.m_botvalue = w.bot_pickupbasevalue;
158 #endif
159     }
160 #ifdef SVQC
161     METHOD(WeaponPickup, giveTo, bool(entity this, entity item, entity player))
162     {
163         bool b = Item_GiveTo(item, player);
164         if (b) {
165             LOG_TRACEF("entity %i picked up %s", player, this.m_name);
166         }
167         return b;
168     }
169 #endif
170 ENDCLASS(WeaponPickup)
171
172 CLASS(OffhandWeapon, Object)
173     METHOD(OffhandWeapon, offhand_think, void(OffhandWeapon this, entity player, bool key_pressed)) {}
174 ENDCLASS(OffhandWeapon)
175
176 #ifdef SVQC
177 .OffhandWeapon offhand;
178 #endif
179
180 #ifdef GAMEQC
181 int max_shot_distance = 32768; // determined by world mins/maxs when map loads
182 #endif
183
184 // weapon flags
185 const int WEP_TYPE_OTHER          =  0x00; // not for damaging people
186 const int WEP_TYPE_SPLASH         =  0x01; // splash damage
187 const int WEP_TYPE_HITSCAN        =  0x02; // hitscan
188 const int WEP_TYPEMASK            =  0x0F;
189 const int WEP_FLAG_CANCLIMB       =  0x10; // can be used for movement
190 const int WEP_FLAG_NORMAL         =  0x20; // in "most weapons" set
191 const int WEP_FLAG_HIDDEN         =  0x40; // hides from menu
192 const int WEP_FLAG_RELOADABLE     =  0x80; // can has reload
193 const int WEP_FLAG_SUPERWEAPON    = 0x100; // powerup timer
194 const int WEP_FLAG_MUTATORBLOCKED = 0x200; // hides from impulse 99 etc. (mutators are allowed to clear this flag)
195 const int WEP_TYPE_MELEE_PRI      = 0x400; // primary attack is melee swing (for animation)
196 const int WEP_TYPE_MELEE_SEC      = 0x800; // secondary attack is melee swing (for animation)
197
198 // variables:
199 string weaponorder_byid;
200
201 // functions:
202 string W_FixWeaponOrder(string order, float complete);
203 string W_UndeprecateName(string s);
204 string W_NameWeaponOrder(string order);
205 string W_NumberWeaponOrder(string order);
206 string W_FixWeaponOrder_BuildImpulseList(string o);
207 string W_FixWeaponOrder_AllowIncomplete(entity this, string order);
208 string W_FixWeaponOrder_ForceComplete(string order);
209 void W_RandomWeapons(entity e, float n);
210
211 string GetAmmoPicture(.int ammotype);
212
213 #ifdef CSQC
214 .int GetAmmoFieldFromNum(int i);
215 int GetAmmoStat(.int ammotype);
216 #endif
217
218 string W_Sound(string w_snd);
219 string W_Model(string w_mdl);