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