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