]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon.qh
Accept balance hash change
[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 glow */
121     METHOD(Weapon, wr_glow, vector(Weapon this, entity actor)) { return '0 0 0'; }
122     /** (SERVER) the weapon is dropped */
123     METHOD(Weapon, wr_drop, void(Weapon this, entity actor)) {}
124     /** (SERVER) a weapon is picked up */
125     METHOD(Weapon, wr_pickup, void(Weapon this, entity actor)) {}
126     /** (SERVER) update cvar based properties */
127     METHOD(Weapon, wr_update, void(Weapon this)) {}
128         METHOD(Weapon, display, void(entity this, void(string name, string icon) returns)) {
129                 returns(this.m_name, this.model2 ? sprintf("/gfx/hud/%s/%s", cvar_string("menu_skin"), this.model2) : string_null);
130         }
131 ENDCLASS(Weapon)
132
133 #include <common/items/_mod.qh>
134 CLASS(WeaponPickup, Pickup)
135     ATTRIB(WeaponPickup, m_weapon, Weapon);
136     ATTRIB(WeaponPickup, m_name, string);
137 #ifdef GAMEQC
138     ATTRIB(WeaponPickup, m_sound, Sound, SND_WEAPONPICKUP);
139 #endif
140 #ifdef SVQC
141     ATTRIB(WeaponPickup, m_itemflags, int, FL_WEAPON);
142     float weapon_pickupevalfunc(entity player, entity item);
143     ATTRIB(WeaponPickup, m_pickupevalfunc, float(entity player, entity item), weapon_pickupevalfunc);
144 #endif
145     CONSTRUCTOR(WeaponPickup, Weapon w) {
146         CONSTRUCT(WeaponPickup);
147         this.m_weapon = w;
148         this.m_name = w.m_name;
149 #ifdef GAMEQC
150         this.m_model = w.m_model;
151 #endif
152 #ifdef SVQC
153         this.m_botvalue = w.bot_pickupbasevalue;
154 #endif
155     }
156 #ifdef SVQC
157     METHOD(WeaponPickup, giveTo, bool(entity this, entity item, entity player))
158     {
159         bool b = Item_GiveTo(item, player);
160         if (b) {
161             LOG_TRACEF("entity %i picked up %s", player, this.m_name);
162         }
163         return b;
164     }
165 #endif
166 ENDCLASS(WeaponPickup)
167
168 CLASS(OffhandWeapon, Object)
169     METHOD(OffhandWeapon, offhand_think, void(OffhandWeapon this, entity player, bool key_pressed)) {}
170 ENDCLASS(OffhandWeapon)
171
172 #ifdef SVQC
173 .OffhandWeapon offhand;
174 #endif
175
176 const int MAX_SHOT_DISTANCE = 32768;
177
178 // weapon flags
179 const int WEP_TYPE_OTHER          =  0x00; // not for damaging people
180 const int WEP_TYPE_SPLASH         =  0x01; // splash damage
181 const int WEP_TYPE_HITSCAN        =  0x02; // hitscan
182 const int WEP_TYPEMASK            =  0x0F;
183 const int WEP_FLAG_CANCLIMB       =  0x10; // can be used for movement
184 const int WEP_FLAG_NORMAL         =  0x20; // in "most weapons" set
185 const int WEP_FLAG_HIDDEN         =  0x40; // hides from menu
186 const int WEP_FLAG_RELOADABLE     =  0x80; // can has reload
187 const int WEP_FLAG_SUPERWEAPON    = 0x100; // powerup timer
188 const int WEP_FLAG_MUTATORBLOCKED = 0x200; // hides from impulse 99 etc. (mutators are allowed to clear this flag)
189 const int WEP_TYPE_MELEE_PRI      = 0x400; // primary attack is melee swing (for animation)
190 const int WEP_TYPE_MELEE_SEC      = 0x800; // secondary attack is melee swing (for animation)
191
192 // variables:
193 string weaponorder_byid;
194
195 // functions:
196 string W_FixWeaponOrder(string order, float complete);
197 string W_UndeprecateName(string s);
198 string W_NameWeaponOrder(string order);
199 string W_NumberWeaponOrder(string order);
200 string W_FixWeaponOrder_BuildImpulseList(string o);
201 string W_FixWeaponOrder_AllowIncomplete(entity this, string order);
202 string W_FixWeaponOrder_ForceComplete(string order);
203 void W_RandomWeapons(entity e, float n);
204
205 string GetAmmoPicture(.int ammotype);
206
207 #ifdef CSQC
208 .int GetAmmoFieldFromNum(int i);
209 int GetAmmoStat(.int ammotype);
210 #endif
211
212 string W_Sound(string w_snd);
213 string W_Model(string w_mdl);