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