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