home *** CD-ROM | disk | FTP | other *** search
/ Superpower (Alt) / SUPERPOWER.iso / q / patch / mbq119 / items.qc < prev    next >
Encoding:
Text File  |  1996-09-02  |  27.8 KB  |  1,323 lines

  1. void() W_SetCurrentAmmo;
  2. /* ALL LIGHTS SHOULD BE 0 1 0 IN COLOR ALL OTHER ITEMS SHOULD
  3. BE .8 .3 .4 IN COLOR */
  4.  
  5.  
  6. void() SUB_regen =
  7. {
  8.     self.model = self.mdl;        // restore original model
  9.     self.solid = SOLID_TRIGGER;    // allow it to be touched again
  10.     sound (self, CHAN_VOICE, "items/itembk2.wav", 1, ATTN_NORM);    // play respawn sound
  11.     setorigin (self, self.origin);
  12. };
  13.  
  14.  
  15.  
  16. /*QUAKED noclass (0 0 0) (-8 -8 -8) (8 8 8)
  17. prints a warning message when spawned
  18. */
  19. void() noclass =
  20. {
  21.     dprint ("noclass spawned at");
  22.     dprint (vtos(self.origin));
  23.     dprint ("\n");
  24.     remove (self);
  25. };
  26.  
  27.  
  28.  
  29. /*
  30. ============
  31. PlaceItem
  32.  
  33. plants the object on the floor
  34. ============
  35. */
  36. void() PlaceItem =
  37. {
  38.     local float    oldz;
  39.  
  40.     self.mdl = self.model;        // so it can be restored on respawn
  41.     self.flags = FL_ITEM;        // make extra wide
  42.     self.solid = SOLID_TRIGGER;
  43.     self.movetype = MOVETYPE_TOSS;    
  44.     self.velocity = '0 0 0';
  45.     self.origin_z = self.origin_z + 6;
  46.     oldz = self.origin_z;
  47.     if (!droptofloor())
  48.     {
  49.         dprint ("Bonus item fell out of level at ");
  50.         dprint (vtos(self.origin));
  51.         dprint ("\n");
  52.         remove(self);
  53.         return;
  54.     }
  55. };
  56.  
  57. /*
  58. ============
  59. StartItem
  60.  
  61. Sets the clipping size and plants the object on the floor
  62. ============
  63. */
  64. void() StartItem =
  65. {
  66.     self.nextthink = time + 0.2;    // items start after other solids
  67.     self.think = PlaceItem;
  68. };
  69.  
  70. /*
  71. =========================================================================
  72.  
  73. HEALTH BOX
  74.  
  75. =========================================================================
  76. */
  77. //
  78. // T_Heal: add health to an entity, limiting health to max_health
  79. // "ignore" will ignore max_health limit
  80. //
  81. float (entity e, float healamount, float ignore) T_Heal =
  82. {
  83.     if (e.health <= 0)
  84.         return 0;
  85.     if ((!ignore) && (e.health >= other.max_health))
  86.         return 0;
  87.     healamount = ceil(healamount);
  88.  
  89.     e.health = e.health + healamount;
  90.     if ((!ignore) && (e.health >= other.max_health))
  91.         e.health = other.max_health;
  92.         
  93.     if (e.health > 250)
  94.         e.health = 250;
  95.     return 1;
  96. };
  97.  
  98. /*QUAKED item_health (.3 .3 1) (0 0 0) (32 32 32) rotten megahealth
  99. Health box. Normally gives 25 points.
  100. Rotten box heals 5-10 points,
  101. megahealth will add 100 health, then 
  102. rot you down to your maximum health limit, 
  103. one point per second.
  104. */
  105.  
  106. float    H_ROTTEN = 1;
  107. float    H_MEGA = 2;
  108. .float    healamount, healtype;
  109. void() health_touch;
  110. void() item_megahealth_rot;
  111.  
  112. void() item_health =
  113. {    
  114.     self.touch = health_touch;
  115.  
  116.     if (self.spawnflags & H_ROTTEN)
  117.     {
  118.         precache_model("maps/b_bh10.bsp");
  119.  
  120.         precache_sound("items/r_item1.wav");
  121.         setmodel(self, "maps/b_bh10.bsp");
  122.         self.noise = "items/r_item1.wav";
  123.         self.healamount = 15;
  124.         self.healtype = 0;
  125.     }
  126.     else
  127.     if (self.spawnflags & H_MEGA)
  128.     {
  129.         precache_model("maps/b_bh100.bsp");
  130.         precache_sound("items/r_item2.wav");
  131.         setmodel(self, "maps/b_bh100.bsp");
  132.         self.noise = "items/r_item2.wav";
  133.         self.healamount = 100;
  134.         self.healtype = 2;
  135.     }
  136.     else
  137.     {
  138.         precache_model("maps/b_bh25.bsp");
  139.         precache_sound("items/health1.wav");
  140.         setmodel(self, "maps/b_bh25.bsp");
  141.         self.noise = "items/health1.wav";
  142.         self.healamount = 25;
  143.         self.healtype = 1;
  144.     }
  145.     setsize (self, '0 0 0', '32 32 56');
  146.     StartItem ();
  147. };
  148.  
  149.  
  150. void() health_touch =
  151. {
  152.     local    float amount;
  153.     local    string    s;
  154.     
  155.     if (other.classname != "player")
  156.         return;
  157.     
  158.     if (self.healtype == 2) // Megahealth?  Ignore max_health...
  159.     {
  160.         if (other.health >= 250)
  161.             return;
  162.         if (!T_Heal(other, self.healamount, 1))
  163.             return;
  164.     }
  165.     else
  166.     {
  167.         if (!T_Heal(other, self.healamount, 0))
  168.             return;
  169.     }
  170.     
  171.     sprint(other, "You receive ");
  172.     s = ftos(self.healamount);
  173.     sprint(other, s);
  174.     sprint(other, " health\n");
  175.     
  176. // health touch sound
  177.     sound(other, CHAN_ITEM, self.noise, 1, ATTN_NORM);
  178.  
  179.     stuffcmd (other, "bf\n");
  180.     
  181.     self.model = string_null;
  182.     self.solid = SOLID_NOT;
  183.  
  184.     // Megahealth = rot down the player's super health
  185.     if (self.healtype == 2)
  186.     {
  187.         other.items = other.items | IT_SUPERHEALTH;
  188.         self.nextthink = time + 5;
  189.         self.think = item_megahealth_rot;
  190.         self.owner = other;
  191.     }
  192.     else
  193.     {
  194.         if (deathmatch != 2)        // deathmatch 2 is the silly old rules
  195.         {
  196.             if (deathmatch)
  197.                 self.nextthink = time + 20;
  198.             self.think = SUB_regen;
  199.         }
  200.     }
  201.     
  202.     activator = other;
  203.     SUB_UseTargets();                // fire all targets / killtargets
  204. };    
  205.  
  206. void() item_megahealth_rot =
  207. {
  208.     other = self.owner;
  209.     
  210.     if (other.health > other.max_health)
  211.     {
  212.         other.health = other.health - 1;
  213.         self.nextthink = time + 1;
  214.         return;
  215.     }
  216.  
  217. // it is possible for a player to die and respawn between rots, so don't
  218. // just blindly subtract the flag off
  219.     other.items = other.items - (other.items & IT_SUPERHEALTH);
  220.     
  221.     if (deathmatch == 1)    // deathmatch 2 is silly old rules
  222.     {
  223.         self.nextthink = time + 20;
  224.         self.think = SUB_regen;
  225.     }
  226. };
  227.  
  228. /*
  229. ===============================================================================
  230.  
  231. ARMOR
  232.  
  233. ===============================================================================
  234. */
  235.  
  236. void() armor_touch;
  237.  
  238. void() armor_touch =
  239. {
  240.     local    float    type, value, bit;
  241.     
  242.     if (other.health <= 0)
  243.         return;
  244.     if (other.classname != "player")
  245.         return;
  246.  
  247.     if (self.classname == "item_armor1")
  248.     {
  249.         type = 0.3;
  250.         value = 100;
  251.         bit = IT_ARMOR1;
  252.     }
  253.     if (self.classname == "item_armor2")
  254.     {
  255.         type = 0.6;
  256.         value = 150;
  257.         bit = IT_ARMOR2;
  258.     }
  259.     if (self.classname == "item_armorInv")
  260.     {
  261.         type = 0.8;
  262.         value = 200;
  263.         bit = IT_ARMOR3;
  264.     }
  265.     if (other.armortype*other.armorvalue >= type*value)
  266.         return;
  267.         
  268.     other.armortype = type;
  269.     other.armorvalue = value;
  270.     other.items = other.items - (other.items & (IT_ARMOR1 | IT_ARMOR2 | IT_ARMOR3)) + bit;
  271.  
  272.     self.solid = SOLID_NOT;
  273.     self.model = string_null;
  274.     if (deathmatch == 1)
  275.         self.nextthink = time + 20;
  276.     self.think = SUB_regen;
  277.  
  278.     sprint(other, "You got armor\n");
  279. // armor touch sound
  280.     sound(other, CHAN_ITEM, "items/armor1.wav", 1, ATTN_NORM);
  281.     stuffcmd (other, "bf\n");
  282.     
  283.     activator = other;
  284.     SUB_UseTargets();                // fire all targets / killtargets
  285. };
  286.  
  287.  
  288. /*QUAKED item_armor1 (0 .5 .8) (-16 -16 0) (16 16 32)
  289. */
  290.  
  291. void() item_armor1 =
  292. {
  293.     self.touch = armor_touch;
  294.     precache_model ("progs/armor.mdl");
  295.     setmodel (self, "progs/armor.mdl");
  296.     self.skin = 0;
  297.     setsize (self, '-16 -16 0', '16 16 56');
  298.     StartItem ();
  299. };
  300.  
  301. /*QUAKED item_armor2 (0 .5 .8) (-16 -16 0) (16 16 32)
  302. */
  303.  
  304. void() item_armor2 =
  305. {
  306.     self.touch = armor_touch;
  307.     precache_model ("progs/armor.mdl");
  308.     setmodel (self, "progs/armor.mdl");
  309.     self.skin = 1;
  310.     setsize (self, '-16 -16 0', '16 16 56');
  311.         StartItem ();
  312. };
  313.  
  314. /*QUAKED item_armorInv (0 .5 .8) (-16 -16 0) (16 16 32)
  315. */
  316.  
  317. void() item_armorInv =
  318. {                                  
  319.     self.touch = armor_touch;
  320.     precache_model ("progs/armor.mdl");
  321.     setmodel (self, "progs/armor.mdl");
  322.     self.skin = 2;
  323.     setsize (self, '-16 -16 0', '16 16 56');
  324.     StartItem ();
  325. };
  326.  
  327. /*
  328. ===============================================================================
  329.  
  330. WEAPONS
  331.  
  332. ===============================================================================
  333. */
  334.  
  335. float(float w) RankForWeapon =
  336. {
  337.     if (w == IT_LIGHTNING)
  338.         return 1;
  339.     if (w == IT_ROCKET_LAUNCHER)
  340.         return 2;
  341.     if (w == IT_SUPER_NAILGUN)
  342.         return 3;
  343.     if (w == IT_GRENADE_LAUNCHER)
  344.         return 4;
  345.     if (w == IT_SUPER_SHOTGUN)
  346.         return 5;
  347.     if (w == IT_NAILGUN)
  348.         return 6;
  349.     return 7;
  350. };
  351.  
  352. /*
  353. =============
  354. Deathmatch_Weapon
  355.  
  356. Deathmatch weapon change rules for picking up a weapon
  357.  
  358. .float        ammo_shells, ammo_nails, ammo_rockets, ammo_cells;
  359. =============
  360. */
  361. void(float old, float new) Deathmatch_Weapon =
  362. {
  363.     local float or, nr;
  364.  
  365. // change self.weapon if desired
  366.     or = RankForWeapon (self.weapon);
  367.     nr = RankForWeapon (new);
  368.     if ( nr < or )
  369.         self.weapon = new;
  370. };
  371.  
  372. /*
  373. =============
  374. weapon_touch
  375. =============
  376. */
  377. float() W_BestWeapon;
  378.  
  379. void() weapon_touch =
  380. {
  381.     local    float    hadammo, best, new, old;
  382.     local    entity    stemp;
  383.     local    float    leave;
  384.  
  385.     if (!(other.flags & FL_CLIENT))
  386.         return;
  387.  
  388. // if the player was using his best weapon, change up to the new one if better        
  389.     stemp = self;
  390.     self = other;
  391.     best = W_BestWeapon();
  392.     self = stemp;
  393.  
  394.     if (deathmatch == 2 || coop)
  395.         leave = 1;
  396.     else
  397.         leave = 0;
  398.     
  399.     if (self.classname == "weapon_nailgun")
  400.     {
  401.         if (leave && (other.items & IT_NAILGUN) )
  402.             return;
  403.         hadammo = other.ammo_nails;            
  404.         new = IT_NAILGUN;
  405.         other.ammo_nails = other.ammo_nails + 30;
  406.     }
  407.     else if (self.classname == "weapon_supernailgun")
  408.     {
  409.         if (leave && (other.items & IT_SUPER_NAILGUN) )
  410.             return;
  411.         hadammo = other.ammo_rockets;            
  412.         new = IT_SUPER_NAILGUN;
  413.         other.ammo_nails = other.ammo_nails + 30;
  414.     }
  415.     else if (self.classname == "weapon_supershotgun")
  416.     {
  417.         if (leave && (other.items & IT_SUPER_SHOTGUN) )
  418.             return;
  419.         hadammo = other.ammo_rockets;            
  420.         new = IT_SUPER_SHOTGUN;
  421.         other.ammo_shells = other.ammo_shells + 5;
  422.     }
  423.     else if (self.classname == "weapon_rocketlauncher")
  424.     {
  425.         if (leave && (other.items & IT_ROCKET_LAUNCHER) )
  426.             return;
  427.         hadammo = other.ammo_rockets;            
  428.         new = IT_ROCKET_LAUNCHER;
  429.         other.ammo_rockets = other.ammo_rockets + 5;
  430.     }
  431.     else if (self.classname == "weapon_grenadelauncher")
  432.     {
  433.         if (leave && (other.items & IT_GRENADE_LAUNCHER) )
  434.             return;
  435.         hadammo = other.ammo_rockets;            
  436.         new = IT_GRENADE_LAUNCHER;
  437.         other.ammo_rockets = other.ammo_rockets + 5;
  438.     }
  439.     else if (self.classname == "weapon_lightning")
  440.     {
  441.         if (leave && (other.items & IT_LIGHTNING) )
  442.             return;
  443.         hadammo = other.ammo_rockets;            
  444.         new = IT_LIGHTNING;
  445.         other.ammo_cells = other.ammo_cells + 15;
  446.     }
  447.     else
  448.         objerror ("weapon_touch: unknown classname");
  449.  
  450.     sprint (other, "You got the ");
  451.     sprint (other, self.netname);
  452.     sprint (other, "\n");
  453. // weapon touch sound
  454.     sound (other, CHAN_ITEM, "weapons/pkup.wav", 1, ATTN_NORM);
  455.     stuffcmd (other, "bf\n");
  456.  
  457. // change to the weapon
  458.     old = other.items;
  459.     other.items = other.items | new;
  460.     
  461.     stemp = self;
  462.     self = other;
  463.  
  464.     if (!deathmatch)
  465.         self.weapon = new;
  466.     else
  467.         Deathmatch_Weapon (old, new);
  468.  
  469.     W_SetCurrentAmmo();
  470.  
  471.     self = stemp;
  472.  
  473.     if (leave)
  474.         return;
  475.  
  476. // remove it in single player, or setup for respawning in deathmatch
  477.     self.model = string_null;
  478.     self.solid = SOLID_NOT;
  479.     if (deathmatch == 1)
  480.         self.nextthink = time + 30;
  481.     self.think = SUB_regen;
  482.     
  483.     activator = other;
  484.     SUB_UseTargets();                // fire all targets / killtargets
  485. };
  486.  
  487.  
  488. /*QUAKED weapon_supershotgun (0 .5 .8) (-16 -16 0) (16 16 32)
  489. */
  490.  
  491. void() weapon_supershotgun =
  492. {
  493.     precache_model ("progs/g_shot.mdl");
  494.     setmodel (self, "progs/g_shot.mdl");
  495.     self.weapon = IT_SUPER_SHOTGUN;
  496.     self.netname = "Double-barrelled Shotgun";
  497.     self.touch = weapon_touch;
  498.     setsize (self, '-16 -16 0', '16 16 56');
  499.     StartItem ();
  500. };
  501.  
  502. /*QUAKED weapon_nailgun (0 .5 .8) (-16 -16 0) (16 16 32)
  503. */
  504.  
  505. void() weapon_nailgun =
  506. {
  507.     precache_model ("progs/g_nail.mdl");
  508.     setmodel (self, "progs/g_nail.mdl");
  509.     self.weapon = IT_NAILGUN;
  510.     self.netname = "nailgun";
  511.     self.touch = weapon_touch;
  512.     setsize (self, '-16 -16 0', '16 16 56');
  513.     StartItem ();
  514. };
  515.  
  516. /*QUAKED weapon_supernailgun (0 .5 .8) (-16 -16 0) (16 16 32)
  517. */
  518.  
  519. void() weapon_supernailgun =
  520. {
  521.     precache_model ("progs/g_nail2.mdl");
  522.     setmodel (self, "progs/g_nail2.mdl");
  523.     self.weapon = IT_SUPER_NAILGUN;
  524.     self.netname = "Super Nailgun";
  525.     self.touch = weapon_touch;
  526.     setsize (self, '-16 -16 0', '16 16 56');
  527.     StartItem ();
  528. };
  529.  
  530. /*QUAKED weapon_grenadelauncher (0 .5 .8) (-16 -16 0) (16 16 32)
  531. */
  532.  
  533. void() weapon_grenadelauncher =
  534. {
  535.     precache_model ("progs/g_rock.mdl");
  536.     setmodel (self, "progs/g_rock.mdl");
  537.     self.weapon = 3;
  538.     self.netname = "Grenade Launcher";
  539.     self.touch = weapon_touch;
  540.     setsize (self, '-16 -16 0', '16 16 56');
  541.     StartItem ();
  542. };
  543.  
  544. /*QUAKED weapon_rocketlauncher (0 .5 .8) (-16 -16 0) (16 16 32)
  545. */
  546.  
  547. void() weapon_rocketlauncher =
  548. {
  549.     precache_model ("progs/g_rock2.mdl");
  550.     setmodel (self, "progs/g_rock2.mdl");
  551.     self.weapon = 3;
  552.     self.netname = "Rocket Launcher";
  553.     self.touch = weapon_touch;
  554.     setsize (self, '-16 -16 0', '16 16 56');
  555.     StartItem ();
  556. };
  557.  
  558.  
  559. /*QUAKED weapon_lightning (0 .5 .8) (-16 -16 0) (16 16 32)
  560. */
  561.  
  562. void() weapon_lightning =
  563. {
  564.     precache_model ("progs/g_light.mdl");
  565.     setmodel (self, "progs/g_light.mdl");
  566.     self.weapon = 3;
  567.     self.netname = "Thunderbolt";
  568.     self.touch = weapon_touch;
  569.     setsize (self, '-16 -16 0', '16 16 56');
  570.     StartItem ();
  571. };
  572.  
  573.  
  574. /*
  575. ===============================================================================
  576.  
  577. AMMO
  578.  
  579. ===============================================================================
  580. */
  581.  
  582. void() ammo_touch =
  583. {
  584. local entity    stemp;
  585. local float        best;
  586.  
  587.     if (other.classname != "player")
  588.         return;
  589.     if (other.health <= 0)
  590.         return;
  591.  
  592. // if the player was using his best weapon, change up to the new one if better        
  593.     stemp = self;
  594.     self = other;
  595.     best = W_BestWeapon();
  596.     self = stemp;
  597.  
  598.  
  599. // shotgun
  600.     if (self.weapon == 1)
  601.     {
  602.         if (other.ammo_shells >= 100)
  603.             return;
  604.         other.ammo_shells = other.ammo_shells + self.aflag;
  605.     }
  606.  
  607. // spikes
  608.     if (self.weapon == 2)
  609.     {
  610.         if (other.ammo_nails >= 200)
  611.             return;
  612.         other.ammo_nails = other.ammo_nails + self.aflag;
  613.     }
  614.  
  615. //    rockets
  616.     if (self.weapon == 3)
  617.     {
  618.         if (other.ammo_rockets >= 100)
  619.             return;
  620.         other.ammo_rockets = other.ammo_rockets + self.aflag;
  621.     }
  622.  
  623. //    cells
  624.     if (self.weapon == 4)
  625.     {
  626.         if (other.ammo_cells >= 200)
  627.             return;
  628.         other.ammo_cells = other.ammo_cells + self.aflag;
  629.     }
  630.  
  631.         sprint (other, "You got the ");
  632.     sprint (other, self.netname);
  633.     sprint (other, "\n");
  634. // ammo touch sound
  635.     sound (other, CHAN_ITEM, "weapons/lock4.wav", 1, ATTN_NORM);
  636.     stuffcmd (other, "bf\n");
  637.  
  638. // change to a better weapon if appropriate
  639.  
  640.     if ( other.weapon == best )
  641.     {
  642.         stemp = self;
  643.         self = other;
  644.         self.weapon = W_BestWeapon();
  645.         W_SetCurrentAmmo ();
  646.         self = stemp;
  647.     }
  648.  
  649. // if changed current ammo, update it
  650.     stemp = self;
  651.     self = other;
  652.     W_SetCurrentAmmo();
  653.     self = stemp;
  654.  
  655. // remove it in single player, or setup for respawning in deathmatch
  656.     self.model = string_null;
  657.     self.solid = SOLID_NOT;
  658.     if (deathmatch == 1)
  659.         self.nextthink = time + 30;
  660.     
  661.     self.think = SUB_regen;
  662.  
  663.     activator = other;
  664.     SUB_UseTargets();                // fire all targets / killtargets
  665. };
  666.  
  667.  
  668.  
  669.  
  670. float WEAPON_BIG2 = 1;
  671.  
  672. /*QUAKED item_shells (0 .5 .8) (0 0 0) (32 32 32) big
  673. */
  674.  
  675. void() item_shells =
  676. {
  677.     self.touch = ammo_touch;
  678.  
  679.     if (self.spawnflags & WEAPON_BIG2)
  680.     {
  681.         precache_model ("maps/b_shell1.bsp");
  682.         setmodel (self, "maps/b_shell1.bsp");
  683.         self.aflag = 40;
  684.     }
  685.     else
  686.     {
  687.         precache_model ("maps/b_shell0.bsp");
  688.         setmodel (self, "maps/b_shell0.bsp");
  689.         self.aflag = 20;
  690.     }
  691.     self.weapon = 1;
  692.     self.netname = "shells";
  693.     setsize (self, '0 0 0', '32 32 56');
  694.     StartItem ();
  695. };
  696.  
  697. /*QUAKED item_spikes (0 .5 .8) (0 0 0) (32 32 32) big
  698. */
  699.  
  700. void() item_spikes =
  701. {
  702.     self.touch = ammo_touch;
  703.  
  704.     if (self.spawnflags & WEAPON_BIG2)
  705.     {
  706.         precache_model ("maps/b_nail1.bsp");
  707.         setmodel (self, "maps/b_nail1.bsp");
  708.         self.aflag = 50;
  709.     }
  710.     else
  711.     {
  712.         precache_model ("maps/b_nail0.bsp");
  713.         setmodel (self, "maps/b_nail0.bsp");
  714.         self.aflag = 25;
  715.     }
  716.     self.weapon = 2;
  717.     self.netname = "nails";
  718.     setsize (self, '0 0 0', '32 32 56');
  719.     StartItem ();
  720. };
  721.  
  722. /*QUAKED item_rockets (0 .5 .8) (0 0 0) (32 32 32) big
  723. */
  724.  
  725. void() item_rockets =
  726. {
  727.     self.touch = ammo_touch;
  728.  
  729.     if (self.spawnflags & WEAPON_BIG2)
  730.     {
  731.         precache_model ("maps/b_rock1.bsp");
  732.         setmodel (self, "maps/b_rock1.bsp");
  733.         self.aflag = 10;
  734.     }
  735.     else
  736.     {
  737.         precache_model ("maps/b_rock0.bsp");
  738.         setmodel (self, "maps/b_rock0.bsp");
  739.         self.aflag = 5;
  740.     }
  741.     self.weapon = 3;
  742.     self.netname = "rockets";
  743.     setsize (self, '0 0 0', '32 32 56');
  744.     StartItem ();
  745. };
  746.  
  747.  
  748. /*QUAKED item_cells (0 .5 .8) (0 0 0) (32 32 32) big
  749. */
  750.  
  751. void() item_cells =
  752. {
  753.     self.touch = ammo_touch;
  754.  
  755.     if (self.spawnflags & WEAPON_BIG2)
  756.     {
  757.         precache_model ("maps/b_batt1.bsp");
  758.         setmodel (self, "maps/b_batt1.bsp");
  759.         self.aflag = 12;
  760.     }
  761.     else
  762.     {
  763.         precache_model ("maps/b_batt0.bsp");
  764.         setmodel (self, "maps/b_batt0.bsp");
  765.         self.aflag = 6;
  766.     }
  767.     self.weapon = 4;
  768.     self.netname = "cells";
  769.     setsize (self, '0 0 0', '32 32 56');
  770.     StartItem ();
  771. };
  772.  
  773.  
  774. /*QUAKED item_weapon (0 .5 .8) (0 0 0) (32 32 32) shotgun rocket spikes big
  775. DO NOT USE THIS!!!! IT WILL BE REMOVED!
  776. */
  777.  
  778. float WEAPON_SHOTGUN = 1;
  779. float WEAPON_ROCKET = 2;
  780. float WEAPON_SPIKES = 4;
  781. float WEAPON_BIG = 8;
  782. void() item_weapon =
  783. {
  784.     self.touch = ammo_touch;
  785.  
  786.     if (self.spawnflags & WEAPON_SHOTGUN)
  787.     {
  788.         if (self.spawnflags & WEAPON_BIG)
  789.         {
  790.             precache_model ("maps/b_shell1.bsp");
  791.             setmodel (self, "maps/b_shell1.bsp");
  792.             self.aflag = 40;
  793.         }
  794.         else
  795.         {
  796.             precache_model ("maps/b_shell0.bsp");
  797.             setmodel (self, "maps/b_shell0.bsp");
  798.             self.aflag = 20;
  799.         }
  800.         self.weapon = 1;
  801.         self.netname = "shells";
  802.     }
  803.  
  804.     if (self.spawnflags & WEAPON_SPIKES)
  805.     {
  806.         if (self.spawnflags & WEAPON_BIG)
  807.         {
  808.             precache_model ("maps/b_nail1.bsp");
  809.             setmodel (self, "maps/b_nail1.bsp");
  810.             self.aflag = 40;
  811.         }
  812.         else
  813.         {
  814.             precache_model ("maps/b_nail0.bsp");
  815.             setmodel (self, "maps/b_nail0.bsp");
  816.             self.aflag = 20;
  817.         }
  818.         self.weapon = 2;
  819.         self.netname = "spikes";
  820.     }
  821.  
  822.     if (self.spawnflags & WEAPON_ROCKET)
  823.     {
  824.         if (self.spawnflags & WEAPON_BIG)
  825.         {
  826.             precache_model ("maps/b_rock1.bsp");
  827.             setmodel (self, "maps/b_rock1.bsp");
  828.             self.aflag = 10;
  829.         }
  830.         else
  831.         {
  832.             precache_model ("maps/b_rock0.bsp");
  833.             setmodel (self, "maps/b_rock0.bsp");
  834.             self.aflag = 5;
  835.         }
  836.         self.weapon = 3;
  837.         self.netname = "rockets";
  838.     }
  839.     
  840.     setsize (self, '0 0 0', '32 32 56');
  841.     StartItem ();
  842. };
  843.  
  844.  
  845. /*
  846. ===============================================================================
  847.  
  848. KEYS
  849.  
  850. ===============================================================================
  851. */
  852.  
  853. void() key_touch =
  854. {
  855. local entity    stemp;
  856. local float        best;
  857.  
  858.     if (other.classname != "player")
  859.         return;
  860.     if (other.health <= 0)
  861.         return;
  862.     if (other.items & self.items)
  863.         return;
  864.  
  865.     sprint (other, "You got the ");
  866.     sprint (other, self.netname);
  867.     sprint (other,"\n");
  868.  
  869.     sound (other, CHAN_ITEM, self.noise, 1, ATTN_NORM);
  870.     stuffcmd (other, "bf\n");
  871.     other.items = other.items | self.items;
  872.  
  873.     if (!coop)
  874.     {    
  875.         self.solid = SOLID_NOT;
  876.         self.model = string_null;
  877.     }
  878.  
  879.     activator = other;
  880.     SUB_UseTargets();                // fire all targets / killtargets
  881. };
  882.  
  883.  
  884. void() key_setsounds =
  885. {
  886.     if (world.worldtype == 0)
  887.     {
  888.         precache_sound ("misc/medkey.wav");
  889.         self.noise = "misc/medkey.wav";
  890.     }
  891.     if (world.worldtype == 1)
  892.     {
  893.         precache_sound ("misc/runekey.wav");
  894.         self.noise = "misc/runekey.wav";
  895.     }
  896.     if (world.worldtype == 2)
  897.     {
  898.         precache_sound2 ("misc/basekey.wav");
  899.         self.noise = "misc/basekey.wav";
  900.     }
  901. };
  902.  
  903. /*QUAKED item_key1 (0 .5 .8) (-16 -16 -24) (16 16 32)
  904. SILVER key
  905. In order for keys to work
  906. you MUST set your maps
  907. worldtype to one of the
  908. following:
  909. 0: medieval
  910. 1: metal
  911. 2: base
  912. */
  913.  
  914. void() item_key1 =
  915. {
  916.     if (world.worldtype == 0)
  917.     {
  918.         precache_model ("progs/w_s_key.mdl");
  919.         setmodel (self, "progs/w_s_key.mdl");
  920.         self.netname = "silver key";
  921.     }
  922.     else if (world.worldtype == 1)
  923.     {
  924.         precache_model ("progs/m_s_key.mdl");
  925.         setmodel (self, "progs/m_s_key.mdl");
  926.         self.netname = "silver runekey";
  927.     }
  928.     else if (world.worldtype == 2)
  929.     {
  930.         precache_model2 ("progs/b_s_key.mdl");
  931.         setmodel (self, "progs/b_s_key.mdl");
  932.         self.netname = "silver keycard";
  933.     }
  934.     key_setsounds();
  935.     self.touch = key_touch;
  936.     self.items = IT_KEY1;
  937.     setsize (self, '-16 -16 -24', '16 16 32');
  938.     StartItem ();
  939. };
  940.  
  941. /*QUAKED item_key2 (0 .5 .8) (-16 -16 -24) (16 16 32)
  942. GOLD key
  943. In order for keys to work
  944. you MUST set your maps
  945. worldtype to one of the
  946. following:
  947. 0: medieval
  948. 1: metal
  949. 2: base
  950. */
  951.  
  952. void() item_key2 =
  953. {
  954.     if (world.worldtype == 0)
  955.     {
  956.         precache_model ("progs/w_g_key.mdl");
  957.         setmodel (self, "progs/w_g_key.mdl");
  958.         self.netname = "gold key";
  959.     }
  960.     if (world.worldtype == 1)
  961.     {
  962.         precache_model ("progs/m_g_key.mdl");
  963.         setmodel (self, "progs/m_g_key.mdl");
  964.         self.netname = "gold runekey";
  965.     }
  966.     if (world.worldtype == 2)
  967.     {
  968.         precache_model2 ("progs/b_g_key.mdl");
  969.         setmodel (self, "progs/b_g_key.mdl");
  970.         self.netname = "gold keycard";
  971.     }
  972.     key_setsounds();
  973.     self.touch = key_touch;
  974.     self.items = IT_KEY2;
  975.     setsize (self, '-16 -16 -24', '16 16 32');
  976.     StartItem ();
  977. };
  978.  
  979.  
  980.  
  981. /*
  982. ===============================================================================
  983.  
  984. END OF LEVEL RUNES
  985.  
  986. ===============================================================================
  987. */
  988.  
  989. void() sigil_touch =
  990. {
  991. local entity    stemp;
  992. local float        best;
  993.  
  994.     if (other.classname != "player")
  995.         return;
  996.     if (other.health <= 0)
  997.         return;
  998.  
  999.     centerprint (other, "You got the rune!");
  1000.  
  1001.     sound (other, CHAN_ITEM, self.noise, 1, ATTN_NORM);
  1002.     stuffcmd (other, "bf\n");
  1003.     self.solid = SOLID_NOT;
  1004.     self.model = string_null;
  1005.     serverflags = serverflags | (self.spawnflags & 15);
  1006.     self.classname = "";        // so rune doors won't find it
  1007.     
  1008.     activator = other;
  1009.     SUB_UseTargets();                // fire all targets / killtargets
  1010. };
  1011.  
  1012.  
  1013. /*QUAKED item_sigil (0 .5 .8) (-16 -16 -24) (16 16 32) E1 E2 E3 E4
  1014. End of level sigil, pick up to end episode and return to jrstart.
  1015. */
  1016.  
  1017. void() item_sigil =
  1018. {
  1019.     if (!self.spawnflags)
  1020.         objerror ("no spawnflags");
  1021.  
  1022.     precache_sound ("misc/runekey.wav");
  1023.     self.noise = "misc/runekey.wav";
  1024.  
  1025.     if (self.spawnflags & 1)
  1026.     {
  1027.         precache_model ("progs/end1.mdl");
  1028.         setmodel (self, "progs/end1.mdl");
  1029.     }
  1030.     if (self.spawnflags & 2)
  1031.     {
  1032.         precache_model2 ("progs/end2.mdl");
  1033.         setmodel (self, "progs/end2.mdl");
  1034.     }
  1035.     if (self.spawnflags & 4)
  1036.     {
  1037.         precache_model2 ("progs/end3.mdl");
  1038.         setmodel (self, "progs/end3.mdl");
  1039.     }
  1040.     if (self.spawnflags & 8)
  1041.     {
  1042.         precache_model2 ("progs/end4.mdl");
  1043.         setmodel (self, "progs/end4.mdl");
  1044.     }
  1045.     
  1046.     self.touch = sigil_touch;
  1047.     setsize (self, '-16 -16 -24', '16 16 32');
  1048.     StartItem ();
  1049. };
  1050.  
  1051. /*
  1052. ===============================================================================
  1053.  
  1054. POWERUPS
  1055.  
  1056. ===============================================================================
  1057. */
  1058.  
  1059. void() powerup_touch;
  1060.  
  1061.  
  1062. void() powerup_touch =
  1063. {
  1064. local entity    stemp;
  1065. local float        best;
  1066.  
  1067.     if (other.classname != "player")
  1068.         return;
  1069.     if (other.health <= 0)
  1070.         return;
  1071.  
  1072.     sprint (other, "You got the ");
  1073.     sprint (other, self.netname);
  1074.     sprint (other,"\n");
  1075.  
  1076.     if (deathmatch)
  1077.     {
  1078.         self.mdl = self.model;
  1079.         
  1080.         if ((self.classname == "item_artifact_invulnerability") ||
  1081.             (self.classname == "item_artifact_invisibility"))
  1082.             self.nextthink = time + 60*5;
  1083.         else
  1084.             self.nextthink = time + 60;
  1085.         
  1086.         self.think = SUB_regen;
  1087.     }    
  1088.  
  1089.     sound (other, CHAN_VOICE, self.noise, 1, ATTN_NORM);
  1090.     stuffcmd (other, "bf\n");
  1091.     self.solid = SOLID_NOT;
  1092.     other.items = other.items | self.items;
  1093.     self.model = string_null;
  1094.  
  1095. // do the apropriate action
  1096.     if (self.classname == "item_artifact_envirosuit")
  1097.     {
  1098.         other.rad_time = 1;
  1099.         other.radsuit_finished = time + 30;
  1100.     }
  1101.     
  1102.     if (self.classname == "item_artifact_invulnerability")
  1103.     {
  1104.         other.invincible_time = 1;
  1105.         other.invincible_finished = time + 30;
  1106.     }
  1107.     
  1108.     if (self.classname == "item_artifact_invisibility")
  1109.     {
  1110.         other.invisible_time = 1;
  1111.         other.invisible_finished = time + 30;
  1112.     }
  1113.  
  1114.     if (self.classname == "item_artifact_super_damage")
  1115.     {
  1116.         other.super_time = 1;
  1117.         other.super_damage_finished = time + 30;
  1118.     }    
  1119.  
  1120.     activator = other;
  1121.     SUB_UseTargets();                // fire all targets / killtargets
  1122. };
  1123.  
  1124.  
  1125.  
  1126. /*QUAKED item_artifact_invulnerability (0 .5 .8) (-16 -16 -24) (16 16 32)
  1127. Player is invulnerable for 30 seconds
  1128. */
  1129. void() item_artifact_invulnerability =
  1130. {
  1131.     self.touch = powerup_touch;
  1132.  
  1133.     precache_model ("progs/invulner.mdl");
  1134.     precache_sound ("items/protect.wav");
  1135.     precache_sound ("items/protect2.wav");
  1136.     precache_sound ("items/protect3.wav");
  1137.     self.noise = "items/protect.wav";
  1138.     setmodel (self, "progs/invulner.mdl");
  1139.     self.netname = "Pentagram of Protection";
  1140.     self.items = IT_INVULNERABILITY;
  1141.     setsize (self, '-16 -16 -24', '16 16 32');
  1142.     StartItem ();
  1143. };
  1144.  
  1145. /*QUAKED item_artifact_envirosuit (0 .5 .8) (-16 -16 -24) (16 16 32)
  1146. Player takes no damage from water or slime for 30 seconds
  1147. */
  1148. void() item_artifact_envirosuit =
  1149. {
  1150.     self.touch = powerup_touch;
  1151.  
  1152.     precache_model ("progs/suit.mdl");
  1153.     precache_sound ("items/suit.wav");
  1154.     precache_sound ("items/suit2.wav");
  1155.     self.noise = "items/suit.wav";
  1156.     setmodel (self, "progs/suit.mdl");
  1157.     self.netname = "Biosuit";
  1158.     self.items = IT_SUIT;
  1159.     setsize (self, '-16 -16 -24', '16 16 32');
  1160.     StartItem ();
  1161. };
  1162.  
  1163.  
  1164. /*QUAKED item_artifact_invisibility (0 .5 .8) (-16 -16 -24) (16 16 32)
  1165. Player is invisible for 30 seconds
  1166. */
  1167. void() item_artifact_invisibility =
  1168. {
  1169.     self.touch = powerup_touch;
  1170.  
  1171.     precache_model ("progs/invisibl.mdl");
  1172.     precache_sound ("items/inv1.wav");
  1173.     precache_sound ("items/inv2.wav");
  1174.     precache_sound ("items/inv3.wav");
  1175.     self.noise = "items/inv1.wav";
  1176.     setmodel (self, "progs/invisibl.mdl");
  1177.     self.netname = "Ring of Shadows";
  1178.     self.items = IT_INVISIBILITY;
  1179.     setsize (self, '-16 -16 -24', '16 16 32');
  1180.     StartItem ();
  1181. };
  1182.  
  1183.  
  1184. /*QUAKED item_artifact_super_damage (0 .5 .8) (-16 -16 -24) (16 16 32)
  1185. The next attack from the player will do 4x damage
  1186. */
  1187. void() item_artifact_super_damage =
  1188. {
  1189.     self.touch = powerup_touch;
  1190.  
  1191.     precache_model ("progs/quaddama.mdl");
  1192.     precache_sound ("items/damage.wav");
  1193.     precache_sound ("items/damage2.wav");
  1194.     precache_sound ("items/damage3.wav");
  1195.     self.noise = "items/damage.wav";
  1196.     setmodel (self, "progs/quaddama.mdl");
  1197.     self.netname = "Quad Damage";
  1198.     self.items = IT_QUAD;
  1199.     setsize (self, '-16 -16 -24', '16 16 32');
  1200.     StartItem ();
  1201. };
  1202.  
  1203.  
  1204.  
  1205. /*
  1206. ===============================================================================
  1207.  
  1208. PLAYER BACKPACKS
  1209.  
  1210. ===============================================================================
  1211. */
  1212.  
  1213. void() BackpackTouch =
  1214. {
  1215.     local string    s;
  1216.     local    float    best;
  1217.     local        entity    stemp;
  1218.     
  1219.     if (other.classname != "player")
  1220.         return;
  1221.     if (other.health <= 0)
  1222.         return;
  1223.         
  1224. // if the player was using his best weapon, change up to the new one if better        
  1225.     stemp = self;
  1226.     self = other;
  1227.     best = W_BestWeapon();
  1228.     self = stemp;
  1229.  
  1230. // change weapons
  1231.     other.ammo_shells = other.ammo_shells + self.ammo_shells;
  1232.     other.ammo_nails = other.ammo_nails + self.ammo_nails;
  1233.     other.ammo_rockets = other.ammo_rockets + self.ammo_rockets;
  1234.     other.ammo_cells = other.ammo_cells + self.ammo_cells;
  1235.  
  1236.     other.items = other.items | self.items;
  1237.     
  1238.  
  1239.     sprint (other, "You get ");
  1240.  
  1241.     if (self.ammo_shells)
  1242.     {
  1243.         s = ftos(self.ammo_shells);
  1244.         sprint (other, s);
  1245.         sprint (other, " shells  ");
  1246.     }
  1247.     if (self.ammo_nails)
  1248.     {
  1249.         s = ftos(self.ammo_nails);
  1250.         sprint (other, s);
  1251.         sprint (other, " nails ");
  1252.     }
  1253.     if (self.ammo_rockets)
  1254.     {
  1255.         s = ftos(self.ammo_rockets);
  1256.         sprint (other, s);
  1257.         sprint (other, " rockets  ");
  1258.     }
  1259.     if (self.ammo_cells)
  1260.     {
  1261.         s = ftos(self.ammo_cells);
  1262.         sprint (other, s);
  1263.         sprint (other, " cells  ");
  1264.     }
  1265.     
  1266.     sprint (other, "\n");
  1267. // backpack touch sound
  1268.     sound (other, CHAN_ITEM, "weapons/lock4.wav", 1, ATTN_NORM);
  1269.     stuffcmd (other, "bf\n");
  1270.  
  1271. // change to a better weapon if appropriate
  1272.     if ( other.weapon == best )
  1273.     {
  1274.         stemp = self;
  1275.         self = other;
  1276.         self.weapon = W_BestWeapon();
  1277.         self = stemp;
  1278.     }
  1279.  
  1280.     
  1281.     remove(self);
  1282.     
  1283.     self = other;
  1284.     W_SetCurrentAmmo ();
  1285. };
  1286.  
  1287. /*
  1288. ===============
  1289. DropBackpack
  1290. ===============
  1291. */
  1292. void() DropBackpack =
  1293. {
  1294.     local entity    item;
  1295.  
  1296.     if (!(self.ammo_shells + self.ammo_nails + self.ammo_rockets + self.ammo_cells))
  1297.         return;    // nothing in it
  1298.  
  1299.     item = spawn();
  1300.     item.origin = self.origin - '0 0 24';
  1301.     
  1302.     item.items = self.weapon;
  1303.  
  1304.     item.ammo_shells = self.ammo_shells;
  1305.     item.ammo_nails = self.ammo_nails;
  1306.     item.ammo_rockets = self.ammo_rockets;
  1307.     item.ammo_cells = self.ammo_cells;
  1308.  
  1309.     item.velocity_z = 300;
  1310.     item.velocity_x = -100 + (random() * 200);
  1311.     item.velocity_y = -100 + (random() * 200);
  1312.     
  1313.     item.flags = FL_ITEM;
  1314.     item.solid = SOLID_TRIGGER;
  1315.     item.movetype = MOVETYPE_TOSS;
  1316.     setmodel (item, "progs/backpack.mdl");
  1317.     setsize (item, '-16 -16 0', '16 16 56');
  1318.     item.touch = BackpackTouch;
  1319.     
  1320.     item.nextthink = time + 120;    // remove after 2 minutes
  1321.     item.think = SUB_Remove;
  1322. };
  1323.