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