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