]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/gamec/cl_weapons.c
message for players that get moved during team balancing
[divverent/nexuiz.git] / data / qcsrc / server / gamec / cl_weapons.c
1 // generic weapons table
2 // add new weapons here
3 void(float wpn, float wrequest) weapon_action =
4 {
5         if (wpn == WEP_LASER)
6                 w_laser(wrequest);
7         else if (wpn == WEP_SHOTGUN)
8                 w_shotgun(wrequest);
9         else if (wpn == WEP_UZI)
10                 w_uzi(wrequest);
11         else if (wpn == WEP_GRENADE_LAUNCHER)
12                 w_glauncher(wrequest);
13         else if (wpn == WEP_ELECTRO)
14                 w_electro(wrequest);
15         else if (wpn == WEP_CRYLINK)
16                 w_crylink(wrequest);
17         else if (wpn == WEP_NEX)
18                 w_nex(wrequest);
19         else if (wpn == WEP_HAGAR)
20                 w_hagar(wrequest);
21         else if (wpn == WEP_ROCKET_LAUNCHER)
22                 w_rlauncher(wrequest);
23 };
24
25 // think function for tossed weapons
26 void() thrown_wep_think
27 {
28         self.solid = SOLID_TRIGGER;
29         self.owner = world;
30         SUB_SetFade(self, time + 20, 1);
31         setorigin(self, self.origin);
32 };
33
34 // toss current weapon
35 void() W_ThrowWeapon
36 {
37         local float w, ammo;
38         local entity wep, e;
39
40         e = self;
41         wep = spawn();
42         self = wep;
43         w = e.weapon;
44         setorigin(wep, e.origin);
45         makevectors(e.angles);
46         wep.classname = "droppedweapon";
47         wep.velocity = e.velocity * 0.5 + v_forward * 750;
48         SUB_SetFade(wep, time + 20, 1);
49
50         if(w == WEP_SHOTGUN)
51         {
52                 w = IT_SHOTGUN;
53                 if(!(e.items & w))
54                 {
55                         remove(wep);
56                         return;
57                 }
58                 weapon_shotgun();
59                 ammo = min(e.ammo_shells, wep.ammo_shells);
60                 wep.ammo_shells = ammo;
61                 e.ammo_shells -= ammo;
62         }
63         else if(w == WEP_UZI)
64         {
65                 w = IT_UZI;
66                 if(!(e.items & w))
67                 {
68                         remove(wep);
69                         return;
70                 }
71                 weapon_uzi();
72                 ammo = min(e.ammo_nails, wep.ammo_nails);
73                 wep.ammo_nails = ammo;
74                 e.ammo_nails -= ammo;
75         }
76         else if(w == WEP_GRENADE_LAUNCHER)
77         {
78                 w = IT_GRENADE_LAUNCHER;
79                 if(!(e.items & w))
80                 {
81                         remove(wep);
82                         return;
83                 }
84                 weapon_grenadelauncher();
85                 ammo = min(e.ammo_rockets, wep.ammo_rockets);
86                 wep.ammo_rockets = ammo;
87                 e.ammo_rockets -= ammo;
88         }
89         else if(w == WEP_ELECTRO)
90         {
91                 w = IT_ELECTRO;
92                 if(!(e.items & w))
93                 {
94                         remove(wep);
95                         return;
96                 }
97                 weapon_electro();
98                 ammo = min(e.ammo_cells, wep.ammo_cells);
99                 wep.ammo_cells = ammo;
100                 e.ammo_cells -= ammo;
101         }
102         else if(w == WEP_CRYLINK)
103         {
104                 w = IT_CRYLINK;
105                 if(!(e.items & w))
106                 {
107                         remove(wep);
108                         return;
109                 }
110                 weapon_crylink();
111                 ammo = min(e.ammo_cells, wep.ammo_cells);
112                 wep.ammo_cells = ammo;
113                 e.ammo_cells -= ammo;
114         }
115         else if(w == WEP_NEX)
116         {
117                 w = IT_NEX;
118                 if(!(e.items & w))
119                 {
120                         remove(wep);
121                         return;
122                 }
123                 weapon_nex();
124                 ammo = min(e.ammo_cells, wep.ammo_cells);
125                 wep.ammo_cells = ammo;
126                 e.ammo_cells -= ammo;
127         }
128         else if(w == WEP_HAGAR)
129         {
130                 w = IT_HAGAR;
131                 if(!(e.items & w))
132                 {
133                         remove(wep);
134                         return;
135                 }
136                 weapon_hagar();
137                 ammo = min(e.ammo_rockets, wep.ammo_rockets);
138                 wep.ammo_rockets = ammo;
139                 e.ammo_rockets -= ammo;
140         }
141         else if(w == WEP_ROCKET_LAUNCHER)
142         {
143                 w = IT_ROCKET_LAUNCHER;
144                 if(!(e.items & w))
145                 {
146                         remove(wep);
147                         return;
148                 }
149                 weapon_rocketlauncher();
150                 ammo = min(e.ammo_rockets, wep.ammo_rockets);
151                 wep.ammo_rockets = ammo;
152                 e.ammo_rockets -= ammo;
153         }
154
155         if(e.items & w)
156                 sprint(e, strcat("You dropped the ^2", wep.netname, "\n"));
157         wep.owner = e;
158         setorigin(wep, wep.origin);
159         wep.nextthink = time + 0.5;
160         wep.think = thrown_wep_think;
161         wep.classname = "droppedweapon";
162         e.items = e.items - (e.items & w);
163         e.switchweapon = w_getbestweapon(e);
164         if (e.switchweapon != e.weapon)
165                 e.cnt = e.weapon;
166         self = e;
167 };
168
169 // switch between weapons
170 void(float imp) W_SwitchWeapon
171 {
172         weapon_hasammo = TRUE;
173         if (!client_hasweapon(self, imp, TRUE))
174         {
175                 if (!weapon_hasammo)
176                         sprint(self, "You don't have any ammo for that weapon\n");
177                 else
178                         sprint(self, "You don't own that weapon\n");
179         }
180         else
181         {
182                 self.cnt = self.weapon;
183                 self.switchweapon = imp;
184         }
185 };
186
187 // next weapon
188 void() W_NextWeapon =
189 {
190         local float weaponwant, maxtries;
191
192         maxtries = WEP_LAST;
193
194         weaponwant = self.switchweapon + 1;
195         if (weaponwant < WEP_FIRST)
196                 weaponwant = WEP_LAST;
197         if (weaponwant > WEP_LAST)
198                 weaponwant = WEP_FIRST;
199         weapon_hasammo = TRUE;
200         while(!client_hasweapon(self, weaponwant, TRUE))
201         {
202                 if(!maxtries)
203                         return;
204                 
205                 maxtries -= 1;
206                 weaponwant = weaponwant + 1;
207                 if (weaponwant < WEP_FIRST)
208                         weaponwant = WEP_LAST;
209                 if (weaponwant > WEP_LAST)
210                         weaponwant = WEP_FIRST;
211         }
212         self.cnt = self.weapon;
213         self.switchweapon = weaponwant;
214 };
215
216 // prev weapon
217 void() W_PreviousWeapon =
218 {
219         local float weaponwant, maxtries;
220
221         maxtries = WEP_LAST;
222         
223         weaponwant = self.switchweapon - 1;
224         if (weaponwant < WEP_FIRST)
225                 weaponwant = WEP_LAST;
226         if (weaponwant > WEP_LAST)
227                 weaponwant = WEP_FIRST;
228         weapon_hasammo = TRUE;
229         while(!client_hasweapon(self, weaponwant, TRUE))
230         {
231                 if(!maxtries)
232                         return;
233                         
234                 maxtries -= 1;
235                 weaponwant = weaponwant - 1;
236                 if (weaponwant < WEP_FIRST)
237                         weaponwant = WEP_LAST;
238                 if (weaponwant > WEP_LAST)
239                         weaponwant = WEP_FIRST;
240         }
241         self.cnt = self.weapon;
242         self.switchweapon = weaponwant;
243 };
244
245 // Bringed back weapon frame
246 void() W_WeaponFrame =
247 {
248         if (!self.weaponentity || self.health <= 0)
249                 return; // Dead player can't use weapons and injure impulse commands
250
251         makevectors(self.v_angle);
252
253         // Change weapon
254         if (self.weapon != self.switchweapon)
255         {
256                 if (self.weaponentity.state == WS_CLEAR)
257                 {
258                         self.weaponentity.state = WS_RAISE;
259                         weapon_action(self.switchweapon, WR_SETUP);
260                         // VorteX: add player model weapon select frame here
261                         // setcustomframe(PlayerWeaponRaise);
262                         weapon_action(self.weapon, WR_UPDATECOUNTS);
263                         weapon_action(self.weapon, WR_RAISE);
264                 }
265                 else if (self.weaponentity.state == WS_READY)
266                 {
267                         sound (self, CHAN_WEAPON, "weapons/weapon_switch.ogg", 1, ATTN_NORM);
268                         self.weaponentity.state = WS_DROP;
269                         // VorteX: add player model weapon deselect frame here
270                         // setcustomframe(PlayerWeaponDrop);
271                         weapon_action(self.weapon, WR_DROP);
272                 }
273         }
274
275         if (self.button0)
276                 weapon_action(self.weapon, WR_FIRE1);
277         if (self.button3)
278                 weapon_action(self.weapon, WR_FIRE2);
279
280         // do weapon think
281         if (time >= self.weapon_nextthink)
282                 if (self.weapon_nextthink > 0)
283                         self.weapon_think();
284
285         // weapon bobbing and script actions
286         local float bobintensity, q1pitching, framespeed, diff;
287         local vector vel, realorg, layer1, boblayer;
288
289         bobintensity = cvar("g_viewweapon_bobintensity"); // weapon bob intensity
290         q1pitching = fabs(cvar("g_viewweapon_q1pitching")); // q1 style of "bob" when looking up and down
291
292         realorg = self.weaponentity.origin + self.weaponentity.view_ofs;
293         realorg = realorg - self.weaponentity.finaldest; // finaldest is last bob position
294
295         // VorteX: actually this is needed for weapon screen offset
296         if (q1pitching)
297         {
298                 self.weaponentity.view_ofs_x = q1pitching*bound(-5.5, self.v_angle_x/45, 5.5);
299                 self.weaponentity.view_ofs_z = q1pitching*bound(-1.5, self.v_angle_x/60, 1.5);
300         }
301
302         // weapon origin interpolation, layer 1
303         if (realorg != self.weaponentity.pos1)
304         {
305                 framespeed = frametime*self.weaponentity.lip*10; // lip is speed of origin changing (of layer1)
306                 diff = vlen(realorg - self.weaponentity.pos1);
307                 // VorteX: add speed modifier (haste)?
308                 layer1 = frametime*10*self.weaponentity.lip*normalize(self.weaponentity.pos1 - realorg);
309                 if (diff <= vlen(layer1))
310                         layer1 = normalize(self.weaponentity.pos1 - realorg)*diff;
311         }
312
313         // weapon bobbing (q3-style)
314         if (self.flags & FL_ONGROUND && self.waterlevel < 2)
315         {
316                 // VorteX: only xy velocity matters
317                 vel_x = self.velocity_x;
318                 vel_y = self.velocity_y;
319                 framespeed = vlen(vel);
320                 // Y axis
321                 diff = bobintensity*framespeed/300;
322                 self.weaponentity.destvec_y = self.weaponentity.destvec_y + frametime*10;
323                 boblayer_y = diff*cos(self.weaponentity.destvec_y + 90);
324                 // Z axis
325                 diff = bobintensity*framespeed/540;
326                 self.weaponentity.destvec_z = self.weaponentity.destvec_z + frametime*20;
327                 boblayer_z = diff*cos(self.weaponentity.destvec_z);
328                 self.weaponentity.finaldest = boblayer;
329         }
330         else if (self.waterlevel > 0)
331         {// swim, all velocity matters
332                 // X axis
333                 framespeed = vlen(self.velocity);
334                 diff = bobintensity*framespeed/100;
335                 self.weaponentity.destvec_x = self.weaponentity.destvec_x + frametime*6;
336                 boblayer_x = diff*cos(self.weaponentity.destvec_x);
337                 self.weaponentity.finaldest = boblayer;
338         }
339         else
340                 self.weaponentity.finaldest = '0 0 0';
341         self.weaponentity.origin = realorg + boblayer + layer1 - self.weaponentity.view_ofs;
342 };