]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/gamec/t_items.c
fixed laser switch-to-last-weapon bug
[divverent/nexuiz.git] / data / qcsrc / server / gamec / t_items.c
1 void Item_ClearRespawnEffect (void) {
2         self.effects = self.effects - (self.effects & EF_STARDUST);
3 }
4
5 void Item_Respawn (void)
6 {
7         self.model = self.mdl;          // restore original model
8         self.solid = SOLID_TRIGGER;     // allow it to be touched again
9         sound (self, CHAN_VOICE, "misc/itemrespawn.ogg", 1, ATTN_NORM); // play respawn sound
10         setorigin (self, self.origin);
11
12         // Savage: Add simple Respawn effect and make sure it gets removed
13         self.effects = self.effects | EF_STARDUST;
14         self.think = Item_ClearRespawnEffect;
15         self.nextthink = time + 0.1;
16 }
17
18 void Item_Touch (void)
19 {
20         local entity oldself;
21         local float _switchweapon;
22
23         if (other.classname != "player")
24                 return;
25         if (other.deadflag)
26                 return;
27         if (self.solid != SOLID_TRIGGER)
28                 return;
29         if (self.health && other.health >= other.max_health)
30                 return;
31         // Savage: Remove the respawn effect if still present
32         self.effects = self.effects - (self.effects & EF_STARDUST);
33
34         sound (self, CHAN_BODY, self.noise, 1, ATTN_NORM);
35
36         // in case the player has autoswitch enabled do the following:
37         // if the player is using their best weapon before items are given, they
38         // probably want to switch to an even better weapon after items are given
39         _switchweapon = (other.autoswitch && (other.switchweapon == w_getbestweapon(other)));
40
41         if (cvar("g_minstagib"))
42         {
43                 if (self.ammo_cells)
44                 {
45                         // play some cool sounds ;)
46                         centerprint(other, "\n");
47                         if(other.health <= 5)
48                                 stuffcmd(other, "play2 announcer/robotic/lastsecond.ogg\n");
49                         else if(other.health < 50)
50                                 stuffcmd(other, "play2 announcer/robotic/narrowly.ogg\n");
51                         // sound not available
52                         // else if(self.items == IT_CELLS)
53                         //      stuffcmd(other, "play2 announce/robotic/ammo.ogg\n");
54                         
55                         if (self.items & IT_NEX)
56                                 W_GiveWeapon (other, IT_NEX, "Nex");
57                         if (self.ammo_cells)
58                                 other.ammo_cells = min (other.ammo_cells + cvar("g_minstagib_ammo_drop"), 999);
59                         other.health = 100;
60                 }
61
62                 // extralife powerup
63                 if (self.max_health)
64                 {
65                         // sound not available
66                         // stuffcmd(other, "play2 announce/robotic/extra.ogg\nplay2 announce/robotic/_lives.ogg\n");
67                         other.extralives = other.extralives + cvar("g_minstagib_extralives");
68                         other.armorvalue = other.extralives;
69                         sprint(other, "^3You picked up some extra lives\n");
70                 }
71
72                 // invis powerup
73                 if (self.strength_finished)
74                 {
75                         // sound not available
76                         // stuffcmd(other, "play2 announce/robotic/invisible.ogg\n");
77                         other.strength_finished = max(other.strength_finished, time) + cvar("g_balance_powerup_strength_time");
78                 }
79                 
80                 // speed powerup
81                 if (self.invincible_finished)
82                 {
83                         // sound not available
84                         // stuffcmd(other, "play2 announce/robotic/speed.ogg\n");
85                         other.invincible_finished = max(other.invincible_finished, time) + cvar("g_balance_powerup_strength_time");
86                 }
87         }
88         else
89         {
90                 if (self.ammo_shells)
91                         other.ammo_shells = min (other.ammo_shells + self.ammo_shells, 999);
92                 if (self.ammo_nails)
93                         other.ammo_nails = min (other.ammo_nails + self.ammo_nails, 999);
94                 if (self.ammo_rockets)
95                         other.ammo_rockets = min (other.ammo_rockets + self.ammo_rockets, 999);
96                 if (self.ammo_cells)
97                         other.ammo_cells = min (other.ammo_cells + self.ammo_cells, 999);
98
99                 if (self.items & IT_UZI)                W_GiveWeapon (other, IT_UZI, "Machine gun");
100                 if (self.items & IT_SHOTGUN)            W_GiveWeapon (other, IT_SHOTGUN, "Shotgun");
101                 if (self.items & IT_GRENADE_LAUNCHER)   W_GiveWeapon (other, IT_GRENADE_LAUNCHER, "Mortar");
102                 if (self.items & IT_ELECTRO)            W_GiveWeapon (other, IT_ELECTRO, "Electro");
103                 if (self.items & IT_NEX)                W_GiveWeapon (other, IT_NEX, "Nex");
104                 if (self.items & IT_HAGAR)              W_GiveWeapon (other, IT_HAGAR, "Hagar");
105                 if (self.items & IT_ROCKET_LAUNCHER)    W_GiveWeapon (other, IT_ROCKET_LAUNCHER, "Rocket Launcher");
106                 if (self.items & IT_CRYLINK)            W_GiveWeapon (other, IT_CRYLINK, "Crylink");
107
108                 if (self.strength_finished)
109                         other.strength_finished = max(other.strength_finished, time) + cvar("g_balance_powerup_strength_time");
110                 if (self.invincible_finished)
111                         other.invincible_finished = max(other.invincible_finished, time) + cvar("g_balance_powerup_invincible_time");
112                 //if (self.speed_finished)
113                 //      other.speed_finished = max(other.speed_finished, time) + cvar("g_balance_powerup_speed_time");
114                 //if (self.slowmo_finished)
115                 //      other.slowmo_finished = max(other.slowmo_finished, time) + (cvar("g_balance_powerup_slowmo_time") * cvar("g_balance_powerup_slowmo_speed"));
116
117                 if (self.max_health)
118                 {
119                         other.health = other.health + self.max_health;
120                         other.pauserothealth_finished = max(other.pauserothealth_finished, time + 5);
121                 }
122                 if (self.health && other.health < other.max_health)
123                         other.health = min(other.health + self.health, other.max_health);
124                 if (self.armorvalue)
125                 {
126                         other.armorvalue = other.armorvalue + self.armorvalue;
127                         other.pauserotarmor_finished = max(other.pauserotarmor_finished, time + 5);
128                 }
129         }
130
131         sound (other, CHAN_AUTO, self.item_pickupsound, 1, ATTN_NORM);
132         
133         oldself = self;
134         self = other;
135
136         if (_switchweapon)
137                 self.switchweapon = w_getbestweapon(self);
138         if (self.switchweapon != self.weapon)
139                 self.cnt = self.weapon;
140
141         //w_updateweapon ();
142         //w_updateammo ();
143         weapon_action(self.weapon, WR_UPDATECOUNTS);
144
145         self = oldself;
146
147         if (self.classname == "droppedweapon")
148                 remove (self);
149         else
150         {
151                 self.solid = SOLID_NOT;
152                 self.model = string_null;
153                 self.nextthink = time + self.respawntime;
154                 self.think = Item_Respawn;
155                 setorigin (self, self.origin);
156         }
157 }
158
159 // Savage: used for item garbage-collection
160 // TODO: perhaps nice special effect?
161 void RemoveItem(void) = {
162         remove(self);
163 }
164
165
166 void StartItem (string itemmodel, string pickupsound, float defaultrespawntime, string itemname, float itemid, float itemflags)
167 {
168         if (!cvar("g_pickup_items") && !cvar("g_minstagib") && !cvar("g_lms"))
169         {
170                 remove (self);
171                 return;
172         }
173
174         if (cvar("g_minstagib"))
175         {
176                 // don't remove dropped items and powerups
177                 if (self.classname != "droppedweapon" && 
178                     self.classname != "minstagib")
179                 {
180                         remove (self);
181                         return;
182                 }
183         }
184
185         if(cvar("g_lms") && (self.classname != "droppedweapon"))
186         {
187                 remove(self);
188                 return;
189         }
190
191         if(cvar("g_instagib") || cvar("g_rocketarena"))
192         {
193                 remove(self);
194                 return;
195         }
196
197         self.mdl = itemmodel;
198         //self.noise = pickupsound;
199         self.item_pickupsound = pickupsound;
200         // let mappers override respawntime
201         if (!self.respawntime)
202                 self.respawntime = defaultrespawntime;
203         self.netname = itemname;
204         self.items = itemid;
205         self.flags = FL_ITEM | itemflags;
206         setmodel (self, self.mdl);
207         if (itemflags & FL_WEAPON)
208         {
209                 setorigin (self, self.origin + '0 0 22');
210                 setsize (self, '-12 -12 -12', '12 12 12');
211                 
212                 // neutral team color for pickup weapons
213                 self.colormap = 160 * 1024 + 160;
214         }
215         else
216         {
217                 setorigin (self, self.origin + '0 0 15');
218         //      setsize (self, '-8 -8 -5', '8 8 8');
219         }
220         self.movetype = MOVETYPE_TOSS;
221         self.solid = SOLID_TRIGGER;
222         self.touch = Item_Touch;
223
224         // Savage: remove thrown items after a certain period of time ("garbage collection")
225         if (self.classname == "droppedweapon")
226         {
227                 self.think = RemoveItem;
228                 self.nextthink = time + 60;
229         }
230
231         if (cvar("g_fullbrightitems"))
232                 self.effects = self.effects | EF_FULLBRIGHT;
233
234 }
235
236 /* replace items in minstagib
237  * IT_STRENGTH   = invisibility
238  * IT_NAILS      = extra lives
239  * IT_INVINCIBLE = speed
240  */
241 void minstagib_items (float itemid)
242 {
243         // we don't want to replace dropped weapons ;)
244         if (self.classname == "droppedweapon")
245         {
246                 self.ammo_cells = 25;
247                 StartItem ("models/weapons/g_nex.md3", 
248                         "weapons/weaponpickup.ogg", 15, 
249                         "Nex Gun", IT_NEX, FL_WEAPON);
250                 return;
251         }
252         
253         local float rnd;
254         self.classname = "minstagib";
255         
256         // replace rocket launchers and nex guns with ammo cells
257         if (itemid == IT_CELLS)
258         {
259                 self.ammo_cells = 1;
260                 StartItem ("models/items/a_cells.md3", 
261                         "misc/itempickup.ogg", 45, 
262                         "Nex Ammo", IT_CELLS, 0);
263                 return;
264         }
265
266         // randomize
267         rnd = random() * 3;
268         if (rnd <= 1)
269                 itemid = IT_STRENGTH;
270         else if (rnd <= 2)
271                 itemid = IT_NAILS;
272         else
273                 itemid = IT_INVINCIBLE;
274         
275         // replace with invis
276         if (itemid == IT_STRENGTH)
277         {
278                 self.effects = EF_ADDITIVE;
279                 self.strength_finished = 30;
280                 StartItem ("models/items/g_strength.md3", 
281                         "misc/powerup.ogg", 120, 
282                         "Invisibility", IT_STRENGTH, FL_POWERUP);
283         }
284         // replace with extra lives
285         if (itemid == IT_NAILS)
286         {
287                 self.max_health = 1;
288                 StartItem ("models/items/g_h100.md3", 
289                         "misc/megahealth.ogg", 120, 
290                         "Extralife", IT_NAILS, FL_POWERUP);
291
292         }
293         // replace with ammo
294         if (itemid == IT_INVINCIBLE)
295         {
296                 self.effects = EF_ADDITIVE;
297                 self.invincible_finished = 30;
298                 StartItem ("models/items/g_invincible.md3", 
299                         "misc/powerup_shield.ogg", 120, 
300                         "Speed", IT_INVINCIBLE, FL_POWERUP);
301         }
302
303 }
304
305 void weapon_uzi (void) {
306         self.ammo_nails = 120;
307         StartItem ("models/weapons/g_uzi.md3", "weapons/weaponpickup.ogg", 15, "Uzi", IT_UZI, FL_WEAPON);
308 }
309
310 void weapon_shotgun (void) {
311         self.ammo_shells = 15;
312         StartItem ("models/weapons/g_shotgun.md3", "weapons/weaponpickup.ogg", 15, "Shotgun", IT_SHOTGUN, FL_WEAPON);
313 }
314
315 void weapon_grenadelauncher (void) {
316         self.ammo_rockets = 15;
317         StartItem ("models/weapons/g_gl.md3", "weapons/weaponpickup.ogg", 15, "Grenade Launcher", IT_GRENADE_LAUNCHER, FL_WEAPON);
318 }
319
320 void weapon_electro (void) {
321         self.ammo_cells = 25;
322         StartItem ("models/weapons/g_electro.md3", "weapons/weaponpickup.ogg", 15, "Electro", IT_ELECTRO, FL_WEAPON);
323 }
324
325 void weapon_crylink (void) {
326         self.ammo_cells = 25;
327         StartItem ("models/weapons/g_crylink.md3", "weapons/weaponpickup.ogg", 15, "Crylink", IT_CRYLINK, FL_WEAPON);
328 }
329
330 void weapon_nex (void) {
331         if (cvar("g_minstagib")) {
332                 minstagib_items(IT_CELLS);
333         } else {
334                 self.ammo_cells = 25;
335                 StartItem ("models/weapons/g_nex.md3", "weapons/weaponpickup.ogg", 15, "Nex Gun", IT_NEX, FL_WEAPON);
336         }
337 }
338
339 void weapon_hagar (void) {
340         self.ammo_rockets = 15;
341         StartItem ("models/weapons/g_hagar.md3", "weapons/weaponpickup.ogg", 15, "Hagar", IT_HAGAR, FL_WEAPON);
342 }
343
344 void weapon_rocketlauncher (void) {
345         if (cvar("g_minstagib")) {
346                 minstagib_items(IT_CELLS);
347         } else {
348                 self.ammo_rockets = 15;
349                 StartItem ("models/weapons/g_rl.md3", "weapons/weaponpickup.ogg", 15, "Rocket Launcher", IT_ROCKET_LAUNCHER, FL_WEAPON);
350         }
351 }
352
353 void item_rockets (void) {
354         self.ammo_rockets = 15;
355         StartItem ("models/items/a_rockets.md3", "misc/itempickup.ogg", 15, "rockets", IT_ROCKETS, 0);
356 }
357
358 void item_bullets (void) {
359         self.ammo_nails = 120;
360         StartItem ("models/items/a_bullets.mdl", "misc/itempickup.ogg", 15, "bullets", IT_NAILS, 0);
361 }
362
363 void item_cells (void) {
364         self.ammo_cells = 25;
365         StartItem ("models/items/a_cells.md3", "misc/itempickup.ogg", 15, "cells", IT_CELLS, 0);
366 }
367
368 void item_shells (void) {
369         self.ammo_shells = 15;
370         StartItem ("models/items/a_shells.md3", "misc/itempickup.ogg", 15, "shells", IT_SHELLS, 0);
371 }
372
373 void item_armor1 (void) {
374         self.armorvalue = 5;
375         StartItem ("models/items/g_a1.md3", "misc/armor1.wav", 15, "Armor Shard", 0, 0);
376 }
377
378 void item_armor25 (void) {
379         self.armorvalue = 100;
380         StartItem ("models/items/g_a25.md3", "misc/armor25.wav", 30, "Armor", 0, 0);
381 }
382
383 void item_health1 (void) {
384         self.max_health = 5;
385         StartItem ("models/items/g_h1.md3", "misc/minihealth.ogg", 15, "5 Health", 0, 0);
386 }
387
388 void item_health25 (void) {
389         self.max_health = 25;
390         StartItem ("models/items/g_h25.md3", "misc/mediumhealth.ogg", 15, "25 Health", 0, 0);
391 }
392
393 void item_health100 (void) {
394         if(!cvar("g_powerup_superhealth"))
395                 return;
396         
397         if(cvar("g_minstagib")) {
398                 minstagib_items(IT_NAILS);
399         } else {
400                 self.max_health = 100;
401                 StartItem ("models/items/g_h100.md3", "misc/megahealth.ogg", 30, "100 Health", 0, 0);
402         }
403 }
404
405 void item_strength (void) {
406         if(!cvar("g_powerup_strength"))
407                 return;
408         
409         if(cvar("g_minstagib")) {
410                 minstagib_items(IT_STRENGTH);
411         } else {
412                 self.strength_finished = 30;
413                 self.effects = EF_ADDITIVE;StartItem ("models/items/g_strength.md3", "misc/powerup.ogg", 120, "Strength Powerup", IT_STRENGTH, FL_POWERUP);
414         }
415 }
416
417 void item_invincible (void) {
418         if(!cvar("g_powerup_shield"))
419                 return;
420                 
421         if(cvar("g_minstagib")) {
422                 minstagib_items(IT_INVINCIBLE);
423         } else {
424                 self.invincible_finished = 30;
425                 self.effects = EF_ADDITIVE;
426                 StartItem ("models/items/g_invincible.md3", "misc/powerup_shield.ogg", 120, "Invulnerability", IT_INVINCIBLE, FL_POWERUP);
427         }
428 }
429 //void item_speed (void) {self.speed_finished = 30;StartItem ("models/items/g_speed.md3", "misc/powerup.wav", 120, "Speed Powerup", IT_SPEED, FL_POWERUP);}
430 //void item_slowmo (void) {self.slowmo_finished = 30;StartItem ("models/items/g_slowmo.md3", "misc/powerup.wav", 120, "Slow Motion", IT_SLOWMO, FL_POWERUP);}
431
432 void misc_models (void)
433 {
434         precache_model (self.model);
435         setmodel (self, self.model);
436         setsize (self, self.mins, self.maxs);
437 }
438
439