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