]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon.qh
Merge branch 'master' into Mirio/balance
[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     /** M: wepimg    : "weaponfoobar" side view image file of weapon. WEAPONTODO: Move out of skin files, move to common files */
79     ATTRIB(Weapon, model2, string, "");
80     /** M: refname   : reference name name */
81     ATTRIB(Weapon, netname, string, "");
82     /** M: wepname   : human readable name */
83     ATTRIB(Weapon, m_name, string, "AOL CD Thrower");
84
85     ATTRIB(Weapon, m_pickup, entity);
86
87     /** (SERVER) setup weapon data */
88     METHOD(Weapon, wr_setup, void(Weapon this, entity actor)) {}
89     /** (SERVER) logic to run every frame */
90     METHOD(Weapon, wr_think, void(Weapon this, entity actor, .entity weaponentity, int fire)) {}
91     /** (SERVER) checks ammo for weapon primary */
92     METHOD(Weapon, wr_checkammo1, bool(Weapon this, entity actor)) {return false;}
93     /** (SERVER) checks ammo for weapon second */
94     METHOD(Weapon, wr_checkammo2, bool(Weapon this, entity actor)) {return false;}
95     /** (SERVER) runs bot aiming code for this weapon */
96     METHOD(Weapon, wr_aim, void(Weapon this, entity actor)) {}
97     /** (BOTH)   precaches models/sounds used by this weapon, also sets up weapon properties */
98     METHOD(Weapon, wr_init, void(Weapon this)) {}
99     /** (SERVER) notification number for suicide message (may inspect w_deathtype for details) */
100     METHOD(Weapon, wr_suicidemessage, entity(Weapon this)) {return NULL;}
101     /** (SERVER) notification number for kill message (may inspect w_deathtype for details) */
102     METHOD(Weapon, wr_killmessage, entity(Weapon this)) {return NULL;}
103     /** (SERVER) handles reloading for weapon */
104     METHOD(Weapon, wr_reload, void(Weapon this, entity actor, .entity weaponentity)) {}
105     /** (SERVER) clears fields that the weapon may use */
106     METHOD(Weapon, wr_resetplayer, void(Weapon this, entity actor)) {}
107     /** (CLIENT) impact effect for weapon explosion */
108     METHOD(Weapon, wr_impacteffect, void(Weapon this, entity actor)) {}
109     /** (SERVER) called whenever a player dies */
110     METHOD(Weapon, wr_playerdeath, void(Weapon this, entity actor, .entity weaponentity)) {}
111     /** (SERVER) logic to run when weapon is lost */
112     METHOD(Weapon, wr_gonethink, void(Weapon this, entity actor, .entity weaponentity)) {}
113     /** (ALL)    dump weapon cvars to config in data directory (see: sv_cmd dumpweapons) */
114     METHOD(Weapon, wr_config, void(Weapon this)) {}
115     /** (CLIENT) weapon specific zoom reticle */
116     METHOD(Weapon, wr_zoomreticle, bool(Weapon this)) {
117         // no weapon specific image for this weapon
118         return false;
119     }
120     /** (CLIENT) weapon specific view model */
121     METHOD(Weapon, wr_viewmodel, string(Weapon this, entity wep)) { return string_null; }
122     /** (CLIENT) weapon specific glow */
123     METHOD(Weapon, wr_glow, vector(Weapon this, entity actor)) { return '0 0 0'; }
124     /** (SERVER) the weapon is dropped */
125     METHOD(Weapon, wr_drop, void(Weapon this, entity actor)) {}
126     /** (SERVER) a weapon is picked up */
127     METHOD(Weapon, wr_pickup, void(Weapon this, entity actor)) {}
128     /** (SERVER) update cvar based properties */
129     METHOD(Weapon, wr_update, void(Weapon this)) {}
130         METHOD(Weapon, display, void(entity this, void(string name, string icon) returns)) {
131                 returns(this.m_name, this.model2 ? sprintf("/gfx/hud/%s/%s", cvar_string("menu_skin"), this.model2) : string_null);
132         }
133 ENDCLASS(Weapon)
134
135 #include <common/items/_mod.qh>
136 CLASS(WeaponPickup, Pickup)
137     ATTRIB(WeaponPickup, m_weapon, Weapon);
138     ATTRIB(WeaponPickup, m_name, string);
139 #ifdef GAMEQC
140     ATTRIB(WeaponPickup, m_sound, Sound, SND_WEAPONPICKUP);
141 #endif
142 #ifdef SVQC
143     ATTRIB(WeaponPickup, m_itemflags, int, FL_WEAPON);
144     float weapon_pickupevalfunc(entity player, entity item);
145     ATTRIB(WeaponPickup, m_pickupevalfunc, float(entity player, entity item), weapon_pickupevalfunc);
146 #endif
147     CONSTRUCTOR(WeaponPickup, Weapon w) {
148         CONSTRUCT(WeaponPickup);
149         this.m_weapon = w;
150         this.m_name = w.m_name;
151 #ifdef GAMEQC
152         this.m_model = w.m_model;
153 #endif
154 #ifdef SVQC
155         this.m_botvalue = w.bot_pickupbasevalue;
156 #endif
157     }
158 #ifdef SVQC
159     METHOD(WeaponPickup, giveTo, bool(entity this, entity item, entity player))
160     {
161         bool b = Item_GiveTo(item, player);
162         if (b) {
163             LOG_TRACEF("entity %i picked up %s", player, this.m_name);
164         }
165         return b;
166     }
167 #endif
168 ENDCLASS(WeaponPickup)
169
170 CLASS(OffhandWeapon, Object)
171     METHOD(OffhandWeapon, offhand_think, void(OffhandWeapon this, entity player, bool key_pressed)) {}
172 ENDCLASS(OffhandWeapon)
173
174 #ifdef SVQC
175 .OffhandWeapon offhand;
176 #endif
177
178 const int MAX_SHOT_DISTANCE = 32768;
179
180 // weapon flags
181 const int WEP_TYPE_OTHER          =  0x00; // not for damaging people
182 const int WEP_TYPE_SPLASH         =  0x01; // splash damage
183 const int WEP_TYPE_HITSCAN        =  0x02; // hitscan
184 const int WEP_TYPEMASK            =  0x0F;
185 const int WEP_FLAG_CANCLIMB       =  0x10; // can be used for movement
186 const int WEP_FLAG_NORMAL         =  0x20; // in "most weapons" set
187 const int WEP_FLAG_HIDDEN         =  0x40; // hides from menu
188 const int WEP_FLAG_RELOADABLE     =  0x80; // can has reload
189 const int WEP_FLAG_SUPERWEAPON    = 0x100; // powerup timer
190 const int WEP_FLAG_MUTATORBLOCKED = 0x200; // hides from impulse 99 etc. (mutators are allowed to clear this flag)
191 const int WEP_TYPE_MELEE_PRI      = 0x400; // primary attack is melee swing (for animation)
192 const int WEP_TYPE_MELEE_SEC      = 0x800; // secondary attack is melee swing (for animation)
193
194 // variables:
195 string weaponorder_byid;
196
197 // functions:
198 string W_FixWeaponOrder(string order, float complete);
199 string W_UndeprecateName(string s);
200 string W_NameWeaponOrder(string order);
201 string W_NumberWeaponOrder(string order);
202 string W_FixWeaponOrder_BuildImpulseList(string o);
203 string W_FixWeaponOrder_AllowIncomplete(entity this, string order);
204 string W_FixWeaponOrder_ForceComplete(string order);
205 void W_RandomWeapons(entity e, float n);
206
207 string GetAmmoPicture(.int ammotype);
208
209 #ifdef CSQC
210 .int GetAmmoFieldFromNum(int i);
211 int GetAmmoStat(.int ammotype);
212 #endif
213
214 string W_Sound(string w_snd);
215 string W_Model(string w_mdl);