]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/t_items.qc
two big changes:
[divverent/nexuiz.git] / data / qcsrc / server / t_items.qc
1
2 .float max_armorvalue;
3
4 void Item_Respawn (void)
5 {
6         self.model = self.mdl;          // restore original model
7         self.solid = SOLID_TRIGGER;     // allow it to be touched again
8         sound (self, CHAN_VOICE, "misc/itemrespawn.wav", VOL_BASE, ATTN_NORM);  // play respawn sound
9         setorigin (self, self.origin);
10
11         //pointparticles(particleeffectnum("item_respawn"), self.origin + self.mins_z * '0 0 1' + '0 0 48', '0 0 0', 1);
12         pointparticles(particleeffectnum("item_respawn"), self.origin + 0.5 * (self.mins + self.maxs), '0 0 0', 1);
13 }
14
15 void Item_Touch (void)
16 {
17         local entity oldself;
18         local float _switchweapon;
19         local float pickedup;
20         local float it;
21
22         // remove the item if it's currnetly in a NODROP brush or hits a NOIMPACT surface (such as sky)
23         if (((trace_dpstartcontents | trace_dphitcontents) & DPCONTENTS_NODROP) || (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
24         {
25                 remove(self);
26                 return;
27         }
28         if (other.classname != "player")
29                 return;
30         if (other.deadflag)
31                 return;
32         if (self.solid != SOLID_TRIGGER)
33                 return;
34         if (self.owner == other)
35                 return;
36
37         // if nothing happens to other, just return without taking the item
38         pickedup = FALSE;
39         _switchweapon = FALSE;
40
41         if (g_minstagib)
42         {
43                 _switchweapon = TRUE;
44                 if (self.ammo_cells)
45                 {
46                         pickedup = TRUE;
47                         // play some cool sounds ;)
48                         centerprint(other, "\n");
49                         if(other.health <= 5)
50                                 announce(other, "announcer/robotic/lastsecond.ogg");
51                         else if(other.health < 50)
52                                 announce(other, "announcer/robotic/narrowly.ogg");
53                         // sound not available
54                         // else if(self.items == IT_CELLS)
55                         //      play2(other, "announce/robotic/ammo.ogg");
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                         pickedup = TRUE;
68                         // sound not available
69                         // play2(other, "announce/robotic/extra.ogg\nplay2 announce/robotic/_lives.ogg");
70                         other.armorvalue = other.armorvalue + cvar("g_minstagib_extralives");
71                         sprint(other, "^3You picked up some extra lives\n");
72                 }
73
74                 // invis powerup
75                 if (self.strength_finished)
76                 {
77                         pickedup = TRUE;
78                         // sound not available
79                         // play2(other, "announce/robotic/invisible.ogg");
80                         other.strength_finished = max(other.strength_finished, time) + cvar("g_balance_powerup_strength_time");
81                 }
82
83                 // speed powerup
84                 if (self.invincible_finished)
85                 {
86                         pickedup = TRUE;
87                         // sound not available
88                         // play2(other, "announce/robotic/speed.ogg");
89                         other.invincible_finished = max(other.invincible_finished, time) + cvar("g_balance_powerup_strength_time");
90                 }
91         }
92         else
93         {
94                 if (cvar("deathmatch") == 2 || cvar("g_weapon_stay"))
95                 {
96                         if (self.flags & FL_WEAPON && other.items & self.items && self.classname != "droppedweapon")
97                                 return;
98                         if (other.items & self.items && self.flags & FL_TOSSED) // don't let players stack ammo by tossing weapons
99                                 return;
100                 }
101
102                 // in case the player has autoswitch enabled do the following:
103                 // if the player is using their best weapon before items are given, they
104                 // probably want to switch to an even better weapon after items are given
105                 if (other.autoswitch)
106                 if (other.switchweapon == w_getbestweapon(other))
107                         _switchweapon = TRUE;
108
109                 if (self.ammo_shells)
110                 if (other.ammo_shells < g_pickup_shells_max)
111                 {
112                         pickedup = TRUE;
113                         other.ammo_shells = min (other.ammo_shells + self.ammo_shells, g_pickup_shells_max);
114                 }
115                 if (self.ammo_nails)
116                 if (other.ammo_nails < g_pickup_nails_max)
117                 {
118                         pickedup = TRUE;
119                         other.ammo_nails = min (other.ammo_nails + self.ammo_nails, g_pickup_nails_max);
120                 }
121                 if (self.ammo_rockets)
122                 if (other.ammo_rockets < g_pickup_rockets_max)
123                 {
124                         pickedup = TRUE;
125                         other.ammo_rockets = min (other.ammo_rockets + self.ammo_rockets, g_pickup_rockets_max);
126                 }
127                 if (self.ammo_cells)
128                 if (other.ammo_cells < g_pickup_cells_max)
129                 {
130                         pickedup = TRUE;
131                         other.ammo_cells = min (other.ammo_cells + self.ammo_cells, g_pickup_cells_max);
132                 }
133
134                 if (self.flags & FL_WEAPON)
135                 if ((it = self.items - (self.items & other.items)))
136                 {
137                         pickedup = TRUE;
138                         if (it & IT_UZI)                W_GiveWeapon (other, IT_UZI, self.netname);
139                         if (it & IT_SHOTGUN)            W_GiveWeapon (other, IT_SHOTGUN, self.netname);
140                         if (it & IT_GRENADE_LAUNCHER)   W_GiveWeapon (other, IT_GRENADE_LAUNCHER, self.netname);
141                         if (it & IT_ELECTRO)            W_GiveWeapon (other, IT_ELECTRO, self.netname);
142                         if (it & IT_NEX)                W_GiveWeapon (other, IT_NEX, self.netname);
143                         if (it & IT_HAGAR)              W_GiveWeapon (other, IT_HAGAR, self.netname);
144                         if (it & IT_ROCKET_LAUNCHER)    W_GiveWeapon (other, IT_ROCKET_LAUNCHER, self.netname);
145                         if (it & IT_CRYLINK)            W_GiveWeapon (other, IT_CRYLINK, self.netname);
146                 }
147
148                 if (self.strength_finished)
149                 {
150                         pickedup = TRUE;
151                         other.strength_finished = max(other.strength_finished, time) + cvar("g_balance_powerup_strength_time");
152                 }
153                 if (self.invincible_finished)
154                 {
155                         pickedup = TRUE;
156                         other.invincible_finished = max(other.invincible_finished, time) + cvar("g_balance_powerup_invincible_time");
157                 }
158                 //if (self.speed_finished)
159                 //{
160                 //      pickedup = TRUE;
161                 //      other.speed_finished = max(other.speed_finished, time) + cvar("g_balance_powerup_speed_time");
162                 //}
163                 //if (self.slowmo_finished)
164                 //{
165                 //      pickedup = TRUE;
166                 //      other.slowmo_finished = max(other.slowmo_finished, time) + (cvar("g_balance_powerup_slowmo_time") * cvar("g_balance_powerup_slowmo_speed"));
167                 //}
168
169                 if (self.health)
170                 if (other.health < self.max_health)
171                 {
172                         pickedup = TRUE;
173                         other.health = min(other.health + self.health, self.max_health);
174                         other.pauserothealth_finished = max(other.pauserothealth_finished, time + cvar("g_balance_pause_health_rot"));
175                 }
176                 if (self.armorvalue)
177                 if (other.armorvalue < self.max_armorvalue)
178                 {
179                         pickedup = TRUE;
180                         other.armorvalue = min(other.armorvalue + self.armorvalue, self.max_armorvalue);
181                         other.pauserotarmor_finished = max(other.pauserotarmor_finished, time + cvar("g_balance_pause_armor_rot"));
182                 }
183         }
184
185         if (!pickedup)
186                 return;
187
188         sound (self, CHAN_BODY, self.noise, VOL_BASE, ATTN_NORM);
189         sound (other, CHAN_AUTO, self.item_pickupsound, VOL_BASE, ATTN_NORM);
190
191         oldself = self;
192         self = other;
193
194         if (_switchweapon)
195                 self.switchweapon = w_getbestweapon(self);
196         if (self.switchweapon != self.weapon)
197                 self.cnt = self.weapon;
198
199         self = oldself;
200
201         if (self.classname == "droppedweapon")
202                 remove (self);
203         else if(self.flags & FL_WEAPON && (cvar("deathmatch") == 2 || cvar("g_weapon_stay")))
204                 return;
205         else
206         {
207                 self.solid = SOLID_NOT;
208                 self.model = string_null;
209                 self.nextthink = time + self.respawntime;
210                 self.think = Item_Respawn;
211                 setorigin (self, self.origin);
212         }
213 }
214
215 // Savage: used for item garbage-collection
216 // TODO: perhaps nice special effect?
217 void RemoveItem(void) /*FIXDECL*/
218 {
219         remove(self);
220 }
221
222 // pickup evaluation functions
223 // these functions decide how desirable an item is to the bots
224
225 float generic_pickupevalfunc(entity player, entity item) {return item.bot_pickupbasevalue;};
226
227 float weapon_pickupevalfunc(entity player, entity item)
228 {
229         // if we already have the weapon, rate it 1/5th normal value
230         if ((player.items & item.items) == item.items)
231                 return item.bot_pickupbasevalue * 0.2;
232         return item.bot_pickupbasevalue;
233 };
234
235 float commodity_pickupevalfunc(entity player, entity item)
236 {
237         float c;
238         c = 0;
239         // TODO: figure out if the player even has the weapon this ammo is for?
240         // may not affect strategy much though...
241         // find out how much more ammo/armor/health the player can hold
242         if (item.ammo_shells)
243         if (player.ammo_shells < g_pickup_shells_max)
244                 c = c + max(0, 1 - player.ammo_shells / g_pickup_shells_max);
245         if (item.ammo_nails)
246         if (player.ammo_nails < g_pickup_nails_max)
247                 c = c + max(0, 1 - player.ammo_nails / g_pickup_nails_max);
248         if (item.ammo_rockets)
249         if (player.ammo_rockets < g_pickup_rockets_max)
250                 c = c + max(0, 1 - player.ammo_rockets / g_pickup_rockets_max);
251         if (item.ammo_cells)
252         if (player.ammo_cells < g_pickup_cells_max)
253                 c = c + max(0, 1 - player.ammo_cells / g_pickup_cells_max);
254         if (item.armorvalue)
255         if (player.armorvalue < item.max_armorvalue)
256                 c = c + max(0, 1 - player.armorvalue / item.max_armorvalue);
257         if (item.health)
258         if (player.health < item.max_health)
259                 c = c + max(0, 1 - player.health / item.max_health);
260
261         if (cvar("deathmatch") == 2) // weapon stay is on, so weapons the player already has are of no interest
262         if (item.flags & FL_WEAPON)
263         if (self.items & item.items)
264         if (item.classname != "droppedweapon")
265                 c = 0;
266
267         return item.bot_pickupbasevalue * c;
268 };
269
270
271 .float is_item;
272 void StartItem (string itemmodel, string pickupsound, float defaultrespawntime, string itemname, float itemid, float itemflags, float(entity player, entity item) pickupevalfunc, float pickupbasevalue)
273 {
274         startitem_failed = FALSE;
275
276         // is it a dropped weapon?
277         if (self.classname == "droppedweapon")
278         {
279                 // it's a dropped weapon
280                 self.movetype = MOVETYPE_TOSS;
281                 self.solid = SOLID_TRIGGER;
282                 // Savage: remove thrown items after a certain period of time ("garbage collection")
283                 self.think = RemoveItem;
284                 self.nextthink = time + 60;
285                 // don't drop if in a NODROP zone (such as lava)
286                 traceline(self.origin, self.origin, MOVE_NORMAL, self);
287                 if (trace_dpstartcontents & DPCONTENTS_NODROP)
288                 {
289                         startitem_failed = TRUE;
290                         remove(self);
291                         return;
292                 }
293         }
294         else
295         {
296                 // it's a level item
297                 if(self.spawnflags & 1)
298                         self.noalign = 1;
299                 if (self.noalign)
300                         self.movetype = MOVETYPE_NONE;
301                 else
302                         self.movetype = MOVETYPE_TOSS;
303                 self.solid = SOLID_TRIGGER;
304                 // do item filtering according to game mode and other things
305                 if (!self.noalign)
306                 {
307                         // first nudge it off the floor a little bit to avoid math errors
308                         setorigin(self, self.origin + '0 0 1');
309                         // set item size before we spawn a spawnfunc_waypoint
310                         if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
311                                 setsize (self, '-16 -16 0', '16 16 48');
312                         else
313                                 setsize (self, '-16 -16 0', '16 16 32');
314                         // note droptofloor returns FALSE if stuck/or would fall too far
315                         droptofloor();
316                         waypoint_spawnforitem(self);
317                 }
318
319                 if(teams_matter)
320                 {
321                         if(self.notteam)
322                         {
323                                 print("removed non-teamplay ", self.classname, "\n");
324                                 startitem_failed = TRUE;
325                                 remove (self);
326                                 return;
327                         }
328                 }
329                 else
330                 {
331                         if(self.notfree)
332                         {
333                                 print("removed non-FFA ", self.classname, "\n");
334                                 startitem_failed = TRUE;
335                                 remove (self);
336                                 return;
337                         }
338                 }
339
340                 if(self.notq3a)
341                 {
342                         // We aren't TA or something like that, so we keep the Q3A entities
343                         print("removed non-Q3A ", self.classname, "\n");
344                         startitem_failed = TRUE;
345                         remove (self);
346                         return;
347                 }
348
349                 /*
350                  * can't do it that way, as it would break maps
351                  * TODO make a target_give like entity another way, that perhaps has
352                  * the weapon name in a key
353                 if(self.targetname)
354                 {
355                         // target_give not yet supported; maybe later
356                         print("removed targeted ", self.classname, "\n");
357                         startitem_failed = TRUE;
358                         remove (self);
359                         return;
360                 }
361                 */
362
363                 if(cvar("spawn_debug") >= 2)
364                 {
365                         entity otheritem;
366                         for(otheritem = findradius(self.origin, 3); otheritem; otheritem = otheritem.chain)
367                         {
368                                 if(otheritem.is_item)
369                                 {
370                                         dprint("XXX Found duplicated item: ", itemname, vtos(self.origin));
371                                         dprint(" vs ", otheritem.netname, vtos(otheritem.origin), "\n");
372                                         error("Mapper sucks.");
373                                 }
374                         }
375                         self.is_item = TRUE;
376                 }
377
378                 itemsInMap |= itemid;
379
380                 if(g_lms || g_instagib || g_rocketarena)
381                 {
382                         startitem_failed = TRUE;
383                         remove(self);
384                         return;
385                 }
386                 else if (g_minstagib)
387                 {
388                         // don't remove dropped items and powerups
389                         if (self.classname != "minstagib")
390                         {
391                                 startitem_failed = TRUE;
392                                 remove (self);
393                                 return;
394                         }
395                 }
396                 else if ((!cvar("g_pickup_items") || g_nixnex) && itemid != IT_STRENGTH && itemid != IT_INVINCIBLE && itemid != IT_HEALTH)
397                 {
398                         startitem_failed = TRUE;
399                         remove (self);
400                         return;
401                 }
402
403                 precache_model (itemmodel);
404                 precache_sound (pickupsound);
405                 precache_sound ("misc/itemrespawn.wav");
406
407                 if(itemid & (IT_STRENGTH | IT_INVINCIBLE | IT_HEALTH | IT_ARMOR | IT_KEY1 | IT_KEY2 |
408                                         IT_ROCKET_LAUNCHER | IT_HAGAR | IT_NEX | IT_CRYLINK | IT_ELECTRO |
409                                         IT_GRENADE_LAUNCHER | IT_UZI | IT_SHOTGUN | IT_LASER))
410                         self.target = "###item###"; // for finding the nearest item using find()
411         }
412
413         self.bot_pickup = TRUE;
414         self.bot_pickupevalfunc = pickupevalfunc;
415         self.bot_pickupbasevalue = pickupbasevalue;
416         self.mdl = itemmodel;
417         //self.noise = pickupsound;
418         self.item_pickupsound = pickupsound;
419         // let mappers override respawntime
420         if (!self.respawntime)
421                 self.respawntime = defaultrespawntime;
422         self.netname = itemname;
423         self.items = itemid;
424         self.flags = FL_ITEM | itemflags;
425         self.touch = Item_Touch;
426         setmodel (self, self.mdl); // precision set below
427         self.effects |= EF_LOWPRECISION;
428         if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
429                 setsize (self, '-16 -16 0', '16 16 48');
430         else
431                 setsize (self, '-16 -16 0', '16 16 32');
432         if (itemflags & FL_WEAPON)
433         {
434                 // neutral team color for pickup weapons
435                 self.colormap = 160 * 1024 + 160;
436         }
437
438         if (cvar("g_fullbrightitems"))
439                 self.effects = self.effects | EF_FULLBRIGHT;
440 }
441
442 /* replace items in minstagib
443  * IT_STRENGTH   = invisibility
444  * IT_NAILS      = extra lives
445  * IT_INVINCIBLE = speed
446  */
447 void minstagib_items (float itemid)
448 {
449         // we don't want to replace dropped weapons ;)
450         if (self.classname == "droppedweapon")
451         {
452                 self.ammo_cells = 25;
453                 StartItem ("models/weapons/g_nex.md3",
454                         "weapons/weaponpickup.wav", 15,
455                         "Nex Gun", IT_NEX, FL_WEAPON, generic_pickupevalfunc, 1000);
456                 return;
457         }
458
459         local float rnd;
460         self.classname = "minstagib";
461
462         // replace rocket launchers and nex guns with ammo cells
463         if (itemid == IT_CELLS)
464         {
465                 self.ammo_cells = 1;
466                 StartItem ("models/items/a_cells.md3",
467                         "misc/itempickup.wav", 45,
468                         "Nex Ammo", IT_CELLS, 0, generic_pickupevalfunc, 100);
469                 return;
470         }
471
472         // randomize
473         rnd = random() * 3;
474         if (rnd <= 1)
475                 itemid = IT_STRENGTH;
476         else if (rnd <= 2)
477                 itemid = IT_NAILS;
478         else
479                 itemid = IT_INVINCIBLE;
480
481         // replace with invis
482         if (itemid == IT_STRENGTH)
483         {
484                 self.effects = EF_ADDITIVE;
485                 self.strength_finished = 30;
486                 StartItem ("models/items/g_strength.md3",
487                         "misc/powerup.wav", 120,
488                         "Invisibility", IT_STRENGTH, FL_POWERUP, generic_pickupevalfunc, 1000);
489         }
490         // replace with extra lives
491         if (itemid == IT_NAILS)
492         {
493                 self.max_health = 1;
494                 StartItem ("models/items/g_h100.md3",
495                         "misc/megahealth.wav", 120,
496                         "Extralife", IT_NAILS, FL_POWERUP, generic_pickupevalfunc, 1000);
497
498         }
499         // replace with speed
500         if (itemid == IT_INVINCIBLE)
501         {
502                 self.effects = EF_ADDITIVE;
503                 self.invincible_finished = 30;
504                 StartItem ("models/items/g_invincible.md3",
505                         "misc/powerup_shield.wav", 120,
506                         "Speed", IT_INVINCIBLE, FL_POWERUP, generic_pickupevalfunc, 1000);
507         }
508
509 }
510
511 float minst_no_auto_cells;
512 void minst_remove_item (void) {
513         if(minst_no_auto_cells)
514                 remove(self);
515 }
516
517 float weaponswapping;
518
519 void spawnfunc_weapon_shotgun (void);
520 void spawnfunc_weapon_uzi (void) {
521         if(!weaponswapping)
522         if(q3acompat_machineshotgunswap)
523         if(self.classname != "droppedweapon")
524         {
525                 weaponswapping = TRUE;
526                 spawnfunc_weapon_shotgun();
527                 weaponswapping = FALSE;
528                 return;
529         }
530
531         if(!self.ammo_nails)
532                 self.ammo_nails = cvar("g_pickup_nails");
533         StartItem ("models/weapons/g_uzi.md3", "weapons/weaponpickup.wav", 15, W_Name(WEP_UZI), IT_UZI, FL_WEAPON, weapon_pickupevalfunc, 5000);
534         if (self.modelindex) // don't precache if self was removed
535                 weapon_action(WEP_UZI, WR_PRECACHE);
536 }
537
538 void spawnfunc_weapon_shotgun (void) {
539         if(!weaponswapping)
540         if(q3acompat_machineshotgunswap)
541         if(self.classname != "droppedweapon")
542         {
543                 weaponswapping = TRUE;
544                 spawnfunc_weapon_uzi();
545                 weaponswapping = FALSE;
546                 return;
547         }
548
549         if(!self.ammo_shells)
550                 self.ammo_shells = cvar("g_pickup_shells");
551         StartItem ("models/weapons/g_shotgun.md3", "weapons/weaponpickup.wav", 15, W_Name(WEP_SHOTGUN), IT_SHOTGUN, FL_WEAPON, weapon_pickupevalfunc, 2500);
552         if (self.modelindex) // don't precache if self was removed
553                 weapon_action(WEP_SHOTGUN, WR_PRECACHE);
554 }
555
556 void spawnfunc_weapon_grenadelauncher (void)
557 {
558         if(!self.ammo_rockets)
559                 self.ammo_rockets = cvar("g_pickup_rockets");
560         StartItem ("models/weapons/g_gl.md3", "weapons/weaponpickup.wav", 15, W_Name(WEP_GRENADE_LAUNCHER), IT_GRENADE_LAUNCHER, FL_WEAPON, weapon_pickupevalfunc, 5000);
561         if (self.modelindex) // don't precache if self was removed
562                 weapon_action(WEP_GRENADE_LAUNCHER, WR_PRECACHE);
563 }
564
565 void spawnfunc_weapon_electro (void)
566 {
567         if(!self.ammo_cells)
568                 self.ammo_cells = cvar("g_pickup_cells");
569         StartItem ("models/weapons/g_electro.md3", "weapons/weaponpickup.wav", 15, W_Name(WEP_ELECTRO), IT_ELECTRO, FL_WEAPON, weapon_pickupevalfunc, 5000);
570         if (self.modelindex) // don't precache if self was removed
571                 weapon_action(WEP_ELECTRO, WR_PRECACHE);
572 }
573
574 void spawnfunc_weapon_crylink (void)
575 {
576         if(!self.ammo_cells)
577                 self.ammo_cells = cvar("g_pickup_cells");
578         StartItem ("models/weapons/g_crylink.md3", "weapons/weaponpickup.wav", 15, W_Name(WEP_CRYLINK), IT_CRYLINK, FL_WEAPON, weapon_pickupevalfunc, 2500);
579         if (self.modelindex) // don't precache if self was removed
580                 weapon_action(WEP_CRYLINK, WR_PRECACHE);
581 }
582
583 void spawnfunc_weapon_nex (void)
584 {
585         float nextime;
586         if (g_minstagib)
587         {
588                 minstagib_items(IT_CELLS);
589                 self.think = minst_remove_item;
590                 self.nextthink = time + cvar("sys_ticrate");
591                 return;
592         }
593         if(!self.ammo_cells)
594                 self.ammo_cells = cvar("g_pickup_cells");
595         nextime = cvar("g_balance_nex_respawntime_modifier");
596         if(nextime)
597                 nextime = 15 * nextime;
598         else
599                 nextime = 15;
600         StartItem ("models/weapons/g_nex.md3", "weapons/weaponpickup.wav", nextime, W_Name(WEP_NEX), IT_NEX, FL_WEAPON, weapon_pickupevalfunc, 10000);
601         if (self.modelindex) // don't precache if self was removed
602                 weapon_action(WEP_NEX, WR_PRECACHE);
603 }
604
605 void spawnfunc_weapon_hagar (void)
606 {
607         if(!self.ammo_rockets)
608                 self.ammo_rockets = cvar("g_pickup_rockets");
609         StartItem ("models/weapons/g_hagar.md3", "weapons/weaponpickup.wav", 15, W_Name(WEP_HAGAR), IT_HAGAR, FL_WEAPON, weapon_pickupevalfunc, 5000);
610         if (self.modelindex) // don't precache if self was removed
611                 weapon_action(WEP_HAGAR, WR_PRECACHE);
612 }
613
614 void spawnfunc_weapon_rocketlauncher (void)
615 {
616         if (g_minstagib)
617         {
618                 minstagib_items(IT_CELLS);
619                 self.think = minst_remove_item;
620                 self.nextthink = time + cvar("sys_ticrate");
621                 return;
622         }
623         if(!self.ammo_rockets)
624                 self.ammo_rockets = g_pickup_rockets;
625         StartItem ("models/weapons/g_rl.md3", "weapons/weaponpickup.wav", 15, W_Name(WEP_ROCKET_LAUNCHER), IT_ROCKET_LAUNCHER, FL_WEAPON, weapon_pickupevalfunc, 10000);
626         if (self.modelindex) // don't precache if self was removed
627                 weapon_action(WEP_ROCKET_LAUNCHER, WR_PRECACHE);
628 }
629
630 void spawnfunc_item_rockets (void) {
631         if(!self.ammo_rockets)
632                 self.ammo_rockets = g_pickup_rockets;
633         StartItem ("models/items/a_rockets.md3", "misc/itempickup.wav", 15, "rockets", IT_ROCKETS, 0, commodity_pickupevalfunc, 3000);
634 }
635
636 void spawnfunc_item_shells (void);
637 void spawnfunc_item_bullets (void) {
638         if(!weaponswapping)
639         if(q3acompat_machineshotgunswap)
640         if(self.classname != "droppedweapon")
641         {
642                 weaponswapping = TRUE;
643                 spawnfunc_item_shells();
644                 weaponswapping = FALSE;
645                 return;
646         }
647
648         if(!self.ammo_nails)
649                 self.ammo_nails = g_pickup_nails;
650         StartItem ("models/items/a_bullets.mdl", "misc/itempickup.wav", 15, "bullets", IT_NAILS, 0, commodity_pickupevalfunc, 2000);
651 }
652
653 void spawnfunc_item_cells (void) {
654         if(!self.ammo_cells)
655                 self.ammo_cells = g_pickup_cells;
656         StartItem ("models/items/a_cells.md3", "misc/itempickup.wav", 15, "cells", IT_CELLS, 0, commodity_pickupevalfunc, 2000);
657 }
658
659 void spawnfunc_item_shells (void) {
660         if(!weaponswapping)
661         if(q3acompat_machineshotgunswap)
662         if(self.classname != "droppedweapon")
663         {
664                 weaponswapping = TRUE;
665                 spawnfunc_item_bullets();
666                 weaponswapping = FALSE;
667                 return;
668         }
669
670         if(!self.ammo_shells)
671                 self.ammo_shells = g_pickup_shells;
672         StartItem ("models/items/a_shells.md3", "misc/itempickup.wav", 15, "shells", IT_SHELLS, 0, commodity_pickupevalfunc, 500);
673 }
674
675 void spawnfunc_item_armor_small (void) {
676         if(!self.armorvalue)
677                 self.armorvalue = g_pickup_armorsmall;
678         if(!self.max_armorvalue)
679                 self.max_armorvalue = g_pickup_armorsmall_max;
680         StartItem ("models/items/g_a1.md3", "misc/armor1.wav", 15, "5 Armor", IT_ARMOR_SHARD, 0, commodity_pickupevalfunc, 1000);
681 }
682
683 void spawnfunc_item_armor_medium (void) {
684         if(!self.armorvalue)
685                 self.armorvalue = g_pickup_armormedium;
686         if(!self.max_armorvalue)
687                 self.max_armorvalue = g_pickup_armormedium_max;
688         StartItem ("models/items/g_armormedium.md3", "misc/armor1.wav", 30, "25 Armor", IT_ARMOR, 0, commodity_pickupevalfunc, 20000);
689 }
690
691 void spawnfunc_item_armor_large (void) {
692         if(!self.armorvalue)
693                 self.armorvalue = g_pickup_armorlarge;
694         if(!self.max_armorvalue)
695                 self.max_armorvalue = g_pickup_armorlarge_max;
696         StartItem ("models/items/g_a25.md3", "misc/armor25.wav", 30, "100 Armor", IT_ARMOR, 0, commodity_pickupevalfunc, 20000);
697 }
698
699 void spawnfunc_item_health_small (void) {
700         if(!self.max_health)
701                 self.max_health = g_pickup_healthsmall_max;
702         if(!self.health)
703                 self.health = g_pickup_healthsmall;
704         StartItem ("models/items/g_h1.md3", "misc/minihealth.wav", 15, "5 Health", IT_5HP, 0, commodity_pickupevalfunc, 20000);
705 }
706
707 void spawnfunc_item_health_medium (void) {
708         if(!self.max_health)
709                 self.max_health = g_pickup_healthmedium_max;
710         if(!self.health)
711                 self.health = g_pickup_healthmedium;
712         StartItem ("models/items/g_h25.md3", "misc/mediumhealth.wav", 15, "25 Health", IT_25HP, 0, commodity_pickupevalfunc, 20000);
713 }
714
715 void spawnfunc_item_health_large (void) {
716         if(!self.max_health)
717                 self.max_health = g_pickup_healthlarge_max;
718         if(!self.health)
719                 self.health = g_pickup_healthlarge;
720         StartItem ("models/items/g_h50.md3", "misc/mediumhealth.wav", 15, "50 Health", IT_25HP, 0, commodity_pickupevalfunc, 20000);
721 }
722
723 void spawnfunc_item_health_mega (void) {
724         if(!cvar("g_powerup_superhealth"))
725                 return;
726
727         if(g_arena && !cvar("g_arena_powerups"))
728                 return;
729
730         if(g_minstagib) {
731                 minstagib_items(IT_NAILS);
732         } else {
733                 if(!self.max_health)
734                         self.max_health = g_pickup_healthmega_max;
735                 if(!self.health)
736                         self.health = g_pickup_healthmega;
737                 StartItem ("models/items/g_h100.md3", "misc/megahealth.wav", 30, "100 Health", IT_HEALTH, 0, commodity_pickupevalfunc, 20000);
738         }
739 }
740
741 // support old misnamed entities
742 void spawnfunc_item_armor1() { spawnfunc_item_armor_small(); }  // FIXME: in Quake this is green armor, in Nexuiz maps it is an armor shard
743 void spawnfunc_item_armor25() { spawnfunc_item_armor_large(); }
744 void spawnfunc_item_health1() { spawnfunc_item_health_small(); }
745 void spawnfunc_item_health25() { spawnfunc_item_health_medium(); }
746 void spawnfunc_item_health100() { spawnfunc_item_health_mega(); }
747
748 void spawnfunc_item_strength (void) {
749         if(!cvar("g_powerup_strength"))
750                 return;
751
752         if(g_arena && !cvar("g_arena_powerups"))
753                 return;
754
755         if(g_minstagib) {
756                 minstagib_items(IT_STRENGTH);
757         } else {
758                 precache_sound("weapons/strength_fire.wav");
759                 self.strength_finished = 30;
760                 self.effects = EF_ADDITIVE;StartItem ("models/items/g_strength.md3", "misc/powerup.wav", 120, "Strength Powerup", IT_STRENGTH, FL_POWERUP, generic_pickupevalfunc, 100000);
761         }
762 }
763
764 void spawnfunc_item_invincible (void) {
765         if(!cvar("g_powerup_shield"))
766                 return;
767
768         if(g_arena && !cvar("g_arena_powerups"))
769                 return;
770
771         if(g_minstagib) {
772                 minstagib_items(IT_INVINCIBLE);
773         } else {
774                 self.invincible_finished = 30;
775                 self.effects = EF_ADDITIVE;
776                 StartItem ("models/items/g_invincible.md3", "misc/powerup_shield.wav", 120, "Invulnerability", IT_INVINCIBLE, FL_POWERUP, generic_pickupevalfunc, 100000);
777         }
778 }
779 //void item_speed (void) {self.speed_finished = 30;StartItem ("models/items/g_speed.md3", "misc/powerup.wav", 120, "Speed Powerup", IT_SPEED, FL_POWERUP, generic_pickupevalfunc, 10000);}
780 //void item_slowmo (void) {self.slowmo_finished = 30;StartItem ("models/items/g_slowmo.md3", "misc/powerup.wav", 120, "Slow Motion", IT_SLOWMO, FL_POWERUP, generic_pickupevalfunc, 10000);}
781
782 void spawnfunc_item_minst_cells (void) {
783         if (g_minstagib)
784         {
785                 minst_no_auto_cells = 1;
786                 minstagib_items(IT_CELLS);
787         }
788         else
789                 remove(self);
790 }
791
792 // compatibility:
793 void spawnfunc_item_quad (void) {self.classname = "item_strength";spawnfunc_item_strength();}
794
795 void spawnfunc_misc_models (void)
796 {
797         precache_model (self.model);
798         setmodel (self, self.model); // precision set by mapper
799         setsize (self, self.mins, self.maxs);
800 }
801
802 void func_wall_use (void)
803 {
804         if(teams_matter)
805         {
806                 if(activator.team)
807                         self.colormap = (activator.team - 1) * 0x11;
808                 else
809                         self.colormap = 0x00;
810         }
811         else
812                 self.colormap = ceil(random() * 256) - 1;
813         self.colormap |= 1024; // RENDER_COLORMAPPED
814 }
815
816 void spawnfunc_func_wall (void)
817 {
818         precache_model (self.model);
819         setmodel (self, self.model); // precision set by mapper
820         setsize (self, self.mins, self.maxs);
821         self.solid = SOLID_BSP;
822         self.use = func_wall_use;
823 }
824
825 floatfield Item_CounterField(float it)
826 {
827         switch(it)
828         {
829                 case IT_SHELLS:      return ammo_shells;
830                 case IT_NAILS:       return ammo_nails;
831                 case IT_ROCKETS:     return ammo_rockets;
832                 case IT_CELLS:       return ammo_cells;
833                 case IT_5HP:         return health;
834                 case IT_25HP:        return health;
835                 case IT_HEALTH:      return health;
836                 case IT_ARMOR_SHARD: return armorvalue;
837                 case IT_ARMOR:       return armorvalue;
838                 // add more things here (health, armor)
839                 default:             error("requested item has no counter field");
840         }
841 }
842
843 float Item_WeaponCode(float it)
844 {
845         switch(it)
846         {
847                 case IT_LASER:            return WEP_LASER;
848                 case IT_SHOTGUN:          return WEP_SHOTGUN;
849                 case IT_UZI:              return WEP_UZI;
850                 case IT_GRENADE_LAUNCHER: return WEP_GRENADE_LAUNCHER;
851                 case IT_ELECTRO:          return WEP_ELECTRO;
852                 case IT_CRYLINK:          return WEP_CRYLINK;
853                 case IT_NEX:              return WEP_NEX;
854                 case IT_HAGAR:            return WEP_HAGAR;
855                 case IT_ROCKET_LAUNCHER:  return WEP_ROCKET_LAUNCHER;
856                 default:                  return 0;
857         }
858 }
859
860 void Item_SpawnByItemCode(float it)
861 {
862         switch(it)
863         {
864                 case IT_SHOTGUN:          spawnfunc_weapon_shotgun(); break;
865                 case IT_UZI:              spawnfunc_weapon_uzi(); break;
866                 case IT_GRENADE_LAUNCHER: spawnfunc_weapon_grenadelauncher(); break;
867                 case IT_ELECTRO:          spawnfunc_weapon_electro(); break;
868                 case IT_CRYLINK:          spawnfunc_weapon_crylink(); break;
869                 case IT_NEX:              spawnfunc_weapon_nex(); break;
870                 case IT_HAGAR:            spawnfunc_weapon_hagar(); break;
871                 case IT_ROCKET_LAUNCHER:  spawnfunc_weapon_rocketlauncher(); break;
872                 // add all other item spawn functions here
873                 default:
874                         error("requested item can't be spawned");
875         }
876 }