home *** CD-ROM | disk | FTP | other *** search
/ Quake 'em / QUAKEEM.BIN / quake / programs / headgun / items.qc < prev    next >
Encoding:
Text File  |  1996-08-20  |  28.1 KB  |  1,341 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. void() bound_other_ammo =
  336. {
  337.     if (other.ammo_shells > 100)
  338.         other.ammo_shells = 100;
  339.     if (other.ammo_nails > 200)
  340.         other.ammo_nails = 200;
  341.     if (other.ammo_rockets > 100)
  342.         other.ammo_rockets = 100;        
  343.     if (other.ammo_cells > 100)
  344.         other.ammo_cells = 100;
  345.     if (other.num_heads > 100)
  346.         other.num_heads = 100;
  347. };
  348.  
  349.  
  350. float(float w) RankForWeapon =
  351. {
  352.     if (w == IT_LIGHTNING)
  353.         return 1;
  354.     if (w == IT_ROCKET_LAUNCHER)
  355.         return 2;
  356.     if (w == IT_SUPER_NAILGUN)
  357.         return 3;
  358.     if (w == IT_GRENADE_LAUNCHER)
  359.         return 4;
  360.     if (w == IT_SUPER_SHOTGUN)
  361.         return 5;
  362.     if (w == IT_NAILGUN)
  363.         return 6;
  364.     return 7;
  365. };
  366.  
  367. /*
  368. =============
  369. Deathmatch_Weapon
  370.  
  371. Deathmatch weapon change rules for picking up a weapon
  372.  
  373. .float        ammo_shells, ammo_nails, ammo_rockets, ammo_cells;
  374. =============
  375. */
  376. void(float old, float new) Deathmatch_Weapon =
  377. {
  378.     local float or, nr;
  379.  
  380. // change self.weapon if desired
  381.     or = RankForWeapon (self.weapon);
  382.     nr = RankForWeapon (new);
  383.     if ( nr < or )
  384.         self.weapon = new;
  385. };
  386.  
  387. /*
  388. =============
  389. weapon_touch
  390. =============
  391. */
  392. float() W_BestWeapon;
  393.  
  394. void() weapon_touch =
  395. {
  396.     local    float    hadammo, best, new, old;
  397.     local    entity    stemp;
  398.     local    float    leave;
  399.  
  400.     if (!(other.flags & FL_CLIENT))
  401.         return;
  402.  
  403. // if the player was using his best weapon, change up to the new one if better        
  404.     stemp = self;
  405.     self = other;
  406.     best = W_BestWeapon();
  407.     self = stemp;
  408.  
  409.     if (deathmatch == 2 || coop)
  410.         leave = 1;
  411.     else
  412.         leave = 0;
  413.     
  414.     if (self.classname == "weapon_nailgun")
  415.     {
  416.         if (leave && (other.items & IT_NAILGUN) )
  417.             return;
  418.         hadammo = other.ammo_nails;            
  419.         new = IT_NAILGUN;
  420.         other.ammo_nails = other.ammo_nails + 30;
  421.     }
  422.     else if (self.classname == "weapon_supernailgun")
  423.     {
  424.         if (leave && (other.items & IT_SUPER_NAILGUN) )
  425.             return;
  426.         hadammo = other.ammo_rockets;            
  427.         new = IT_SUPER_NAILGUN;
  428.         other.ammo_nails = other.ammo_nails + 30;
  429.     }
  430.     else if (self.classname == "weapon_supershotgun")
  431.     {
  432.         if (leave && (other.items & IT_SUPER_SHOTGUN) )
  433.             return;
  434.         hadammo = other.ammo_rockets;            
  435.         new = IT_SUPER_SHOTGUN;
  436.         other.ammo_shells = other.ammo_shells + 5;
  437.     }
  438.     else if (self.classname == "weapon_rocketlauncher")
  439.     {
  440.         if (leave && (other.items & IT_ROCKET_LAUNCHER) )
  441.             return;
  442.         hadammo = other.ammo_rockets;            
  443.         new = IT_ROCKET_LAUNCHER;
  444.         other.ammo_rockets = other.ammo_rockets + 5;
  445.     }
  446.     else if (self.classname == "weapon_grenadelauncher")
  447.     {
  448.         if (leave && (other.items & IT_GRENADE_LAUNCHER) )
  449.             return;
  450.         hadammo = other.ammo_rockets;            
  451.         new = IT_GRENADE_LAUNCHER;
  452.         other.ammo_rockets = other.ammo_rockets + 5;
  453.     }
  454.     else if (self.classname == "weapon_lightning")
  455.     {
  456.         if (leave && (other.items & IT_LIGHTNING) )
  457.             return;
  458.         hadammo = other.ammo_rockets;            
  459.         new = IT_LIGHTNING;
  460.         other.ammo_cells = other.ammo_cells + 15;
  461.     }
  462.     else
  463.         objerror ("weapon_touch: unknown classname");
  464.  
  465.     sprint (other, "You got the ");
  466.     sprint (other, self.netname);
  467.     sprint (other, "\n");
  468. // weapon touch sound
  469.     sound (other, CHAN_ITEM, "weapons/pkup.wav", 1, ATTN_NORM);
  470.     stuffcmd (other, "bf\n");
  471.  
  472.     bound_other_ammo ();
  473.  
  474. // change to the weapon
  475.     old = other.items;
  476.     other.items = other.items | new;
  477.     
  478.     stemp = self;
  479.     self = other;
  480.  
  481.     if (!deathmatch)
  482.         self.weapon = new;
  483.     else
  484.         Deathmatch_Weapon (old, new);
  485.  
  486.     W_SetCurrentAmmo();
  487.  
  488.     self = stemp;
  489.  
  490.     if (leave)
  491.         return;
  492.  
  493. // remove it in single player, or setup for respawning in deathmatch
  494.     self.model = string_null;
  495.     self.solid = SOLID_NOT;
  496.     if (deathmatch == 1)
  497.         self.nextthink = time + 30;
  498.     self.think = SUB_regen;
  499.     
  500.     activator = other;
  501.     SUB_UseTargets();                // fire all targets / killtargets
  502. };
  503.  
  504.  
  505. /*QUAKED weapon_supershotgun (0 .5 .8) (-16 -16 0) (16 16 32)
  506. */
  507.  
  508. void() weapon_supershotgun =
  509. {
  510.     precache_model ("progs/g_shot.mdl");
  511.     setmodel (self, "progs/g_shot.mdl");
  512.     self.weapon = IT_SUPER_SHOTGUN;
  513.     self.netname = "Double-barrelled Shotgun";
  514.     self.touch = weapon_touch;
  515.     setsize (self, '-16 -16 0', '16 16 56');
  516.     StartItem ();
  517. };
  518.  
  519. /*QUAKED weapon_nailgun (0 .5 .8) (-16 -16 0) (16 16 32)
  520. */
  521.  
  522. void() weapon_nailgun =
  523. {
  524.     precache_model ("progs/g_nail.mdl");
  525.     setmodel (self, "progs/g_nail.mdl");
  526.     self.weapon = IT_NAILGUN;
  527.     self.netname = "nailgun";
  528.     self.touch = weapon_touch;
  529.     setsize (self, '-16 -16 0', '16 16 56');
  530.     StartItem ();
  531. };
  532.  
  533. /*QUAKED weapon_supernailgun (0 .5 .8) (-16 -16 0) (16 16 32)
  534. */
  535.  
  536. void() weapon_supernailgun =
  537. {
  538.     precache_model ("progs/g_nail2.mdl");
  539.     setmodel (self, "progs/g_nail2.mdl");
  540.     self.weapon = IT_SUPER_NAILGUN;
  541.     self.netname = "Super Nailgun";
  542.     self.touch = weapon_touch;
  543.     setsize (self, '-16 -16 0', '16 16 56');
  544.     StartItem ();
  545. };
  546.  
  547. /*QUAKED weapon_grenadelauncher (0 .5 .8) (-16 -16 0) (16 16 32)
  548. */
  549.  
  550. void() weapon_grenadelauncher =
  551. {
  552.     precache_model ("progs/g_rock.mdl");
  553.     setmodel (self, "progs/g_rock.mdl");
  554.     self.weapon = 3;
  555.     self.netname = "Grenade Launcher";
  556.     self.touch = weapon_touch;
  557.     setsize (self, '-16 -16 0', '16 16 56');
  558.     StartItem ();
  559. };
  560.  
  561. /*QUAKED weapon_rocketlauncher (0 .5 .8) (-16 -16 0) (16 16 32)
  562. */
  563.  
  564. void() weapon_rocketlauncher =
  565. {
  566.     precache_model ("progs/g_rock2.mdl");
  567.     setmodel (self, "progs/g_rock2.mdl");
  568.     self.weapon = 3;
  569.     self.netname = "Rocket Launcher";
  570.     self.touch = weapon_touch;
  571.     setsize (self, '-16 -16 0', '16 16 56');
  572.     StartItem ();
  573. };
  574.  
  575.  
  576. /*QUAKED weapon_lightning (0 .5 .8) (-16 -16 0) (16 16 32)
  577. */
  578.  
  579. void() weapon_lightning =
  580. {
  581.     precache_model ("progs/g_light.mdl");
  582.     setmodel (self, "progs/g_light.mdl");
  583.     self.weapon = 3;
  584.     self.netname = "Thunderbolt";
  585.     self.touch = weapon_touch;
  586.     setsize (self, '-16 -16 0', '16 16 56');
  587.     StartItem ();
  588. };
  589.  
  590. /*
  591. ===============================================================================
  592.  
  593. AMMO
  594.  
  595. ===============================================================================
  596. */
  597.  
  598. void() ammo_touch =
  599. {
  600. local entity    stemp;
  601. local float        best;
  602.  
  603.     if (other.classname != "player")
  604.         return;
  605.     if (other.health <= 0)
  606.         return;
  607.  
  608. // if the player was using his best weapon, change up to the new one if better        
  609.     stemp = self;
  610.     self = other;
  611.     best = W_BestWeapon();
  612.     self = stemp;
  613.  
  614.  
  615. // shotgun
  616.     if (self.weapon == 1)
  617.     {
  618.         if (other.ammo_shells >= 100)
  619.             return;
  620.         other.ammo_shells = other.ammo_shells + self.aflag;
  621.     }
  622.  
  623. // spikes
  624.     if (self.weapon == 2)
  625.     {
  626.         if (other.ammo_nails >= 200)
  627.             return;
  628.         other.ammo_nails = other.ammo_nails + self.aflag;
  629.     }
  630.  
  631. //    rockets
  632.     if (self.weapon == 3)
  633.     {
  634.         if (other.ammo_rockets >= 100)
  635.             return;
  636.         other.ammo_rockets = other.ammo_rockets + self.aflag;
  637.     }
  638.  
  639. //    cells
  640.     if (self.weapon == 4)
  641.     {
  642.         if (other.ammo_cells >= 200)
  643.             return;
  644.         other.ammo_cells = other.ammo_cells + self.aflag;
  645.     }
  646.  
  647.     bound_other_ammo ();
  648.     
  649.     sprint (other, "You got the ");
  650.     sprint (other, self.netname);
  651.     sprint (other, "\n");
  652. // ammo touch sound
  653.     sound (other, CHAN_ITEM, "weapons/lock4.wav", 1, ATTN_NORM);
  654.     stuffcmd (other, "bf\n");
  655.  
  656. // change to a better weapon if appropriate
  657.  
  658.     if ( other.weapon == best )
  659.     {
  660.         stemp = self;
  661.         self = other;
  662.         self.weapon = W_BestWeapon();
  663.         W_SetCurrentAmmo ();
  664.         self = stemp;
  665.     }
  666.  
  667. // if changed current ammo, update it
  668.     stemp = self;
  669.     self = other;
  670.     W_SetCurrentAmmo();
  671.     self = stemp;
  672.  
  673. // remove it in single player, or setup for respawning in deathmatch
  674.     self.model = string_null;
  675.     self.solid = SOLID_NOT;
  676.     if (deathmatch == 1)
  677.         self.nextthink = time + 30;
  678.     
  679.     self.think = SUB_regen;
  680.  
  681.     activator = other;
  682.     SUB_UseTargets();                // fire all targets / killtargets
  683. };
  684.  
  685.  
  686.  
  687.  
  688. float WEAPON_BIG2 = 1;
  689.  
  690. /*QUAKED item_shells (0 .5 .8) (0 0 0) (32 32 32) big
  691. */
  692.  
  693. void() item_shells =
  694. {
  695.     self.touch = ammo_touch;
  696.  
  697.     if (self.spawnflags & WEAPON_BIG2)
  698.     {
  699.         precache_model ("maps/b_shell1.bsp");
  700.         setmodel (self, "maps/b_shell1.bsp");
  701.         self.aflag = 40;
  702.     }
  703.     else
  704.     {
  705.         precache_model ("maps/b_shell0.bsp");
  706.         setmodel (self, "maps/b_shell0.bsp");
  707.         self.aflag = 20;
  708.     }
  709.     self.weapon = 1;
  710.     self.netname = "shells";
  711.     setsize (self, '0 0 0', '32 32 56');
  712.     StartItem ();
  713. };
  714.  
  715. /*QUAKED item_spikes (0 .5 .8) (0 0 0) (32 32 32) big
  716. */
  717.  
  718. void() item_spikes =
  719. {
  720.     self.touch = ammo_touch;
  721.  
  722.     if (self.spawnflags & WEAPON_BIG2)
  723.     {
  724.         precache_model ("maps/b_nail1.bsp");
  725.         setmodel (self, "maps/b_nail1.bsp");
  726.         self.aflag = 50;
  727.     }
  728.     else
  729.     {
  730.         precache_model ("maps/b_nail0.bsp");
  731.         setmodel (self, "maps/b_nail0.bsp");
  732.         self.aflag = 25;
  733.     }
  734.     self.weapon = 2;
  735.     self.netname = "nails";
  736.     setsize (self, '0 0 0', '32 32 56');
  737.     StartItem ();
  738. };
  739.  
  740. /*QUAKED item_rockets (0 .5 .8) (0 0 0) (32 32 32) big
  741. */
  742.  
  743. void() item_rockets =
  744. {
  745.     self.touch = ammo_touch;
  746.  
  747.     if (self.spawnflags & WEAPON_BIG2)
  748.     {
  749.         precache_model ("maps/b_rock1.bsp");
  750.         setmodel (self, "maps/b_rock1.bsp");
  751.         self.aflag = 10;
  752.     }
  753.     else
  754.     {
  755.         precache_model ("maps/b_rock0.bsp");
  756.         setmodel (self, "maps/b_rock0.bsp");
  757.         self.aflag = 5;
  758.     }
  759.     self.weapon = 3;
  760.     self.netname = "rockets";
  761.     setsize (self, '0 0 0', '32 32 56');
  762.     StartItem ();
  763. };
  764.  
  765. /*QUAKED item_cells (0 .5 .8) (0 0 0) (32 32 32) big
  766. */
  767.  
  768. void() item_cells =
  769. {
  770.     self.touch = ammo_touch;
  771.  
  772.     if (self.spawnflags & WEAPON_BIG2)
  773.     {
  774.         precache_model ("maps/b_batt1.bsp");
  775.         setmodel (self, "maps/b_batt1.bsp");
  776.         self.aflag = 12;
  777.     }
  778.     else
  779.     {
  780.         precache_model ("maps/b_batt0.bsp");
  781.         setmodel (self, "maps/b_batt0.bsp");
  782.         self.aflag = 6;
  783.     }
  784.     self.weapon = 4;
  785.     self.netname = "cells";
  786.     setsize (self, '0 0 0', '32 32 56');
  787.     StartItem ();
  788. };
  789.  
  790.  
  791. /*QUAKED item_weapon (0 .5 .8) (0 0 0) (32 32 32) shotgun rocket spikes big
  792. DO NOT USE THIS!!!! IT WILL BE REMOVED!
  793. */
  794.  
  795. float WEAPON_SHOTGUN = 1;
  796. float WEAPON_ROCKET = 2;
  797. float WEAPON_SPIKES = 4;
  798. float WEAPON_BIG = 8;
  799. void() item_weapon =
  800. {
  801.     self.touch = ammo_touch;
  802.  
  803.     if (self.spawnflags & WEAPON_SHOTGUN)
  804.     {
  805.         if (self.spawnflags & WEAPON_BIG)
  806.         {
  807.             precache_model ("maps/b_shell1.bsp");
  808.             setmodel (self, "maps/b_shell1.bsp");
  809.             self.aflag = 40;
  810.         }
  811.         else
  812.         {
  813.             precache_model ("maps/b_shell0.bsp");
  814.             setmodel (self, "maps/b_shell0.bsp");
  815.             self.aflag = 20;
  816.         }
  817.         self.weapon = 1;
  818.         self.netname = "shells";
  819.     }
  820.  
  821.     if (self.spawnflags & WEAPON_SPIKES)
  822.     {
  823.         if (self.spawnflags & WEAPON_BIG)
  824.         {
  825.             precache_model ("maps/b_nail1.bsp");
  826.             setmodel (self, "maps/b_nail1.bsp");
  827.             self.aflag = 40;
  828.         }
  829.         else
  830.         {
  831.             precache_model ("maps/b_nail0.bsp");
  832.             setmodel (self, "maps/b_nail0.bsp");
  833.             self.aflag = 20;
  834.         }
  835.         self.weapon = 2;
  836.         self.netname = "spikes";
  837.     }
  838.  
  839.     if (self.spawnflags & WEAPON_ROCKET)
  840.     {
  841.         if (self.spawnflags & WEAPON_BIG)
  842.         {
  843.             precache_model ("maps/b_rock1.bsp");
  844.             setmodel (self, "maps/b_rock1.bsp");
  845.             self.aflag = 10;
  846.         }
  847.         else
  848.         {
  849.             precache_model ("maps/b_rock0.bsp");
  850.             setmodel (self, "maps/b_rock0.bsp");
  851.             self.aflag = 5;
  852.         }
  853.         self.weapon = 3;
  854.         self.netname = "rockets";
  855.     }
  856.     
  857.     setsize (self, '0 0 0', '32 32 56');
  858.     StartItem ();
  859. };
  860.  
  861.  
  862. /*
  863. ===============================================================================
  864.  
  865. KEYS
  866.  
  867. ===============================================================================
  868. */
  869.  
  870. void() key_touch =
  871. {
  872. local entity    stemp;
  873. local float        best;
  874.  
  875.     if (other.classname != "player")
  876.         return;
  877.     if (other.health <= 0)
  878.         return;
  879.     if (other.items & self.items)
  880.         return;
  881.  
  882.     sprint (other, "You got the ");
  883.     sprint (other, self.netname);
  884.     sprint (other,"\n");
  885.  
  886.     sound (other, CHAN_ITEM, self.noise, 1, ATTN_NORM);
  887.     stuffcmd (other, "bf\n");
  888.     other.items = other.items | self.items;
  889.  
  890.     if (!coop)
  891.     {    
  892.         self.solid = SOLID_NOT;
  893.         self.model = string_null;
  894.     }
  895.  
  896.     activator = other;
  897.     SUB_UseTargets();                // fire all targets / killtargets
  898. };
  899.  
  900.  
  901. void() key_setsounds =
  902. {
  903.     if (world.worldtype == 0)
  904.     {
  905.         precache_sound ("misc/medkey.wav");
  906.         self.noise = "misc/medkey.wav";
  907.     }
  908.     if (world.worldtype == 1)
  909.     {
  910.         precache_sound ("misc/runekey.wav");
  911.         self.noise = "misc/runekey.wav";
  912.     }
  913.     if (world.worldtype == 2)
  914.     {
  915.         precache_sound2 ("misc/basekey.wav");
  916.         self.noise = "misc/basekey.wav";
  917.     }
  918. };
  919.  
  920. /*QUAKED item_key1 (0 .5 .8) (-16 -16 -24) (16 16 32)
  921. SILVER key
  922. In order for keys to work
  923. you MUST set your maps
  924. worldtype to one of the
  925. following:
  926. 0: medieval
  927. 1: metal
  928. 2: base
  929. */
  930.  
  931. void() item_key1 =
  932. {
  933.     if (world.worldtype == 0)
  934.     {
  935.         precache_model ("progs/w_s_key.mdl");
  936.         setmodel (self, "progs/w_s_key.mdl");
  937.         self.netname = "silver key";
  938.     }
  939.     else if (world.worldtype == 1)
  940.     {
  941.         precache_model ("progs/m_s_key.mdl");
  942.         setmodel (self, "progs/m_s_key.mdl");
  943.         self.netname = "silver runekey";
  944.     }
  945.     else if (world.worldtype == 2)
  946.     {
  947.         precache_model2 ("progs/b_s_key.mdl");
  948.         setmodel (self, "progs/b_s_key.mdl");
  949.         self.netname = "silver keycard";
  950.     }
  951.     key_setsounds();
  952.     self.touch = key_touch;
  953.     self.items = IT_KEY1;
  954.     setsize (self, '-16 -16 -24', '16 16 32');
  955.     StartItem ();
  956. };
  957.  
  958. /*QUAKED item_key2 (0 .5 .8) (-16 -16 -24) (16 16 32)
  959. GOLD key
  960. In order for keys to work
  961. you MUST set your maps
  962. worldtype to one of the
  963. following:
  964. 0: medieval
  965. 1: metal
  966. 2: base
  967. */
  968.  
  969. void() item_key2 =
  970. {
  971.     if (world.worldtype == 0)
  972.     {
  973.         precache_model ("progs/w_g_key.mdl");
  974.         setmodel (self, "progs/w_g_key.mdl");
  975.         self.netname = "gold key";
  976.     }
  977.     if (world.worldtype == 1)
  978.     {
  979.         precache_model ("progs/m_g_key.mdl");
  980.         setmodel (self, "progs/m_g_key.mdl");
  981.         self.netname = "gold runekey";
  982.     }
  983.     if (world.worldtype == 2)
  984.     {
  985.         precache_model2 ("progs/b_g_key.mdl");
  986.         setmodel (self, "progs/b_g_key.mdl");
  987.         self.netname = "gold keycard";
  988.     }
  989.     key_setsounds();
  990.     self.touch = key_touch;
  991.     self.items = IT_KEY2;
  992.     setsize (self, '-16 -16 -24', '16 16 32');
  993.     StartItem ();
  994. };
  995.  
  996.  
  997.  
  998. /*
  999. ===============================================================================
  1000.  
  1001. END OF LEVEL RUNES
  1002.  
  1003. ===============================================================================
  1004. */
  1005.  
  1006. void() sigil_touch =
  1007. {
  1008. local entity    stemp;
  1009. local float        best;
  1010.  
  1011.     if (other.classname != "player")
  1012.         return;
  1013.     if (other.health <= 0)
  1014.         return;
  1015.  
  1016.     centerprint (other, "You got the rune!");
  1017.  
  1018.     sound (other, CHAN_ITEM, self.noise, 1, ATTN_NORM);
  1019.     stuffcmd (other, "bf\n");
  1020.     self.solid = SOLID_NOT;
  1021.     self.model = string_null;
  1022.     serverflags = serverflags | (self.spawnflags & 15);
  1023.     self.classname = "";        // so rune doors won't find it
  1024.     
  1025.     activator = other;
  1026.     SUB_UseTargets();                // fire all targets / killtargets
  1027. };
  1028.  
  1029.  
  1030. /*QUAKED item_sigil (0 .5 .8) (-16 -16 -24) (16 16 32) E1 E2 E3 E4
  1031. End of level sigil, pick up to end episode and return to jrstart.
  1032. */
  1033.  
  1034. void() item_sigil =
  1035. {
  1036.     if (!self.spawnflags)
  1037.         objerror ("no spawnflags");
  1038.  
  1039.     precache_sound ("misc/runekey.wav");
  1040.     self.noise = "misc/runekey.wav";
  1041.  
  1042.     if (self.spawnflags & 1)
  1043.     {
  1044.         precache_model ("progs/end1.mdl");
  1045.         setmodel (self, "progs/end1.mdl");
  1046.     }
  1047.     if (self.spawnflags & 2)
  1048.     {
  1049.         precache_model2 ("progs/end2.mdl");
  1050.         setmodel (self, "progs/end2.mdl");
  1051.     }
  1052.     if (self.spawnflags & 4)
  1053.     {
  1054.         precache_model2 ("progs/end3.mdl");
  1055.         setmodel (self, "progs/end3.mdl");
  1056.     }
  1057.     if (self.spawnflags & 8)
  1058.     {
  1059.         precache_model2 ("progs/end4.mdl");
  1060.         setmodel (self, "progs/end4.mdl");
  1061.     }
  1062.     
  1063.     self.touch = sigil_touch;
  1064.     setsize (self, '-16 -16 -24', '16 16 32');
  1065.     StartItem ();
  1066. };
  1067.  
  1068. /*
  1069. ===============================================================================
  1070.  
  1071. POWERUPS
  1072.  
  1073. ===============================================================================
  1074. */
  1075.  
  1076. void() powerup_touch;
  1077.  
  1078.  
  1079. void() powerup_touch =
  1080. {
  1081. local entity    stemp;
  1082. local float        best;
  1083.  
  1084.     if (other.classname != "player")
  1085.         return;
  1086.     if (other.health <= 0)
  1087.         return;
  1088.  
  1089.     sprint (other, "You got the ");
  1090.     sprint (other, self.netname);
  1091.     sprint (other,"\n");
  1092.  
  1093.     if (deathmatch)
  1094.     {
  1095.         self.mdl = self.model;
  1096.         
  1097.         if ((self.classname == "item_artifact_invulnerability") ||
  1098.             (self.classname == "item_artifact_invisibility"))
  1099.             self.nextthink = time + 60*5;
  1100.         else
  1101.             self.nextthink = time + 60;
  1102.         
  1103.         self.think = SUB_regen;
  1104.     }    
  1105.  
  1106.     sound (other, CHAN_VOICE, self.noise, 1, ATTN_NORM);
  1107.     stuffcmd (other, "bf\n");
  1108.     self.solid = SOLID_NOT;
  1109.     other.items = other.items | self.items;
  1110.     self.model = string_null;
  1111.  
  1112. // do the apropriate action
  1113.     if (self.classname == "item_artifact_envirosuit")
  1114.     {
  1115.         other.rad_time = 1;
  1116.         other.radsuit_finished = time + 30;
  1117.     }
  1118.     
  1119.     if (self.classname == "item_artifact_invulnerability")
  1120.     {
  1121.         other.invincible_time = 1;
  1122.         other.invincible_finished = time + 30;
  1123.     }
  1124.     
  1125.     if (self.classname == "item_artifact_invisibility")
  1126.     {
  1127.         other.invisible_time = 1;
  1128.         other.invisible_finished = time + 30;
  1129.     }
  1130.  
  1131.     if (self.classname == "item_artifact_super_damage")
  1132.     {
  1133.         other.super_time = 1;
  1134.         other.super_damage_finished = time + 30;
  1135.     }    
  1136.  
  1137.     activator = other;
  1138.     SUB_UseTargets();                // fire all targets / killtargets
  1139. };
  1140.  
  1141.  
  1142.  
  1143. /*QUAKED item_artifact_invulnerability (0 .5 .8) (-16 -16 -24) (16 16 32)
  1144. Player is invulnerable for 30 seconds
  1145. */
  1146. void() item_artifact_invulnerability =
  1147. {
  1148.     self.touch = powerup_touch;
  1149.  
  1150.     precache_model ("progs/invulner.mdl");
  1151.     precache_sound ("items/protect.wav");
  1152.     precache_sound ("items/protect2.wav");
  1153.     precache_sound ("items/protect3.wav");
  1154.     self.noise = "items/protect.wav";
  1155.     setmodel (self, "progs/invulner.mdl");
  1156.     self.netname = "Pentagram of Protection";
  1157.     self.items = IT_INVULNERABILITY;
  1158.     setsize (self, '-16 -16 -24', '16 16 32');
  1159.     StartItem ();
  1160. };
  1161.  
  1162. /*QUAKED item_artifact_envirosuit (0 .5 .8) (-16 -16 -24) (16 16 32)
  1163. Player takes no damage from water or slime for 30 seconds
  1164. */
  1165. void() item_artifact_envirosuit =
  1166. {
  1167.     self.touch = powerup_touch;
  1168.  
  1169.     precache_model ("progs/suit.mdl");
  1170.     precache_sound ("items/suit.wav");
  1171.     precache_sound ("items/suit2.wav");
  1172.     self.noise = "items/suit.wav";
  1173.     setmodel (self, "progs/suit.mdl");
  1174.     self.netname = "Biosuit";
  1175.     self.items = IT_SUIT;
  1176.     setsize (self, '-16 -16 -24', '16 16 32');
  1177.     StartItem ();
  1178. };
  1179.  
  1180.  
  1181. /*QUAKED item_artifact_invisibility (0 .5 .8) (-16 -16 -24) (16 16 32)
  1182. Player is invisible for 30 seconds
  1183. */
  1184. void() item_artifact_invisibility =
  1185. {
  1186.     self.touch = powerup_touch;
  1187.  
  1188.     precache_model ("progs/invisibl.mdl");
  1189.     precache_sound ("items/inv1.wav");
  1190.     precache_sound ("items/inv2.wav");
  1191.     precache_sound ("items/inv3.wav");
  1192.     self.noise = "items/inv1.wav";
  1193.     setmodel (self, "progs/invisibl.mdl");
  1194.     self.netname = "Ring of Shadows";
  1195.     self.items = IT_INVISIBILITY;
  1196.     setsize (self, '-16 -16 -24', '16 16 32');
  1197.     StartItem ();
  1198. };
  1199.  
  1200.  
  1201. /*QUAKED item_artifact_super_damage (0 .5 .8) (-16 -16 -24) (16 16 32)
  1202. The next attack from the player will do 4x damage
  1203. */
  1204. void() item_artifact_super_damage =
  1205. {
  1206.     self.touch = powerup_touch;
  1207.  
  1208.     precache_model ("progs/quaddama.mdl");
  1209.     precache_sound ("items/damage.wav");
  1210.     precache_sound ("items/damage2.wav");
  1211.     precache_sound ("items/damage3.wav");
  1212.     self.noise = "items/damage.wav";
  1213.     setmodel (self, "progs/quaddama.mdl");
  1214.     self.netname = "Quad Damage";
  1215.     self.items = IT_QUAD;
  1216.     setsize (self, '-16 -16 -24', '16 16 32');
  1217.     StartItem ();
  1218. };
  1219.  
  1220.  
  1221.  
  1222. /*
  1223. ===============================================================================
  1224.  
  1225. PLAYER BACKPACKS
  1226.  
  1227. ===============================================================================
  1228. */
  1229.  
  1230. void() BackpackTouch =
  1231. {
  1232.     local string    s;
  1233.     local    float    best;
  1234.     local        entity    stemp;
  1235.     
  1236.     if (other.classname != "player")
  1237.         return;
  1238.     if (other.health <= 0)
  1239.         return;
  1240.         
  1241. // if the player was using his best weapon, change up to the new one if better        
  1242.     stemp = self;
  1243.     self = other;
  1244.     best = W_BestWeapon();
  1245.     self = stemp;
  1246.  
  1247. // change weapons
  1248.     other.ammo_shells = other.ammo_shells + self.ammo_shells;
  1249.     other.ammo_nails = other.ammo_nails + self.ammo_nails;
  1250.     other.ammo_rockets = other.ammo_rockets + self.ammo_rockets;
  1251.     other.ammo_cells = other.ammo_cells + self.ammo_cells;
  1252.  
  1253.     other.items = other.items | self.items;
  1254.     
  1255.     bound_other_ammo ();
  1256.  
  1257.     sprint (other, "You get ");
  1258.  
  1259.     if (self.ammo_shells)
  1260.     {
  1261.         s = ftos(self.ammo_shells);
  1262.         sprint (other, s);
  1263.         sprint (other, " shells  ");
  1264.     }
  1265.     if (self.ammo_nails)
  1266.     {
  1267.         s = ftos(self.ammo_nails);
  1268.         sprint (other, s);
  1269.         sprint (other, " nails ");
  1270.     }
  1271.     if (self.ammo_rockets)
  1272.     {
  1273.         s = ftos(self.ammo_rockets);
  1274.         sprint (other, s);
  1275.         sprint (other, " rockets  ");
  1276.     }
  1277.     if (self.ammo_cells)
  1278.     {
  1279.         s = ftos(self.ammo_cells);
  1280.         sprint (other, s);
  1281.         sprint (other, " cells  ");
  1282.     }
  1283.     
  1284.     sprint (other, "\n");
  1285. // backpack touch sound
  1286.     sound (other, CHAN_ITEM, "weapons/lock4.wav", 1, ATTN_NORM);
  1287.     stuffcmd (other, "bf\n");
  1288.  
  1289. // change to a better weapon if appropriate
  1290.     if ( other.weapon == best )
  1291.     {
  1292.         stemp = self;
  1293.         self = other;
  1294.         self.weapon = W_BestWeapon();
  1295.         self = stemp;
  1296.     }
  1297.  
  1298.     
  1299.     remove(self);
  1300.     
  1301.     self = other;
  1302.     W_SetCurrentAmmo ();
  1303. };
  1304.  
  1305. /*
  1306. ===============
  1307. DropBackpack
  1308. ===============
  1309. */
  1310. void() DropBackpack =
  1311. {
  1312.     local entity    item;
  1313.  
  1314.     if (!(self.ammo_shells + self.ammo_nails + self.ammo_rockets + self.ammo_cells))
  1315.         return;    // nothing in it
  1316.  
  1317.     item = spawn();
  1318.     item.origin = self.origin - '0 0 24';
  1319.     
  1320.     item.items = self.weapon;
  1321.  
  1322.     item.ammo_shells = self.ammo_shells;
  1323.     item.ammo_nails = self.ammo_nails;
  1324.     item.ammo_rockets = self.ammo_rockets;
  1325.     item.ammo_cells = self.ammo_cells;
  1326.  
  1327.     item.velocity_z = 300;
  1328.     item.velocity_x = -100 + (random() * 200);
  1329.     item.velocity_y = -100 + (random() * 200);
  1330.     
  1331.     item.flags = FL_ITEM;
  1332.     item.solid = SOLID_TRIGGER;
  1333.     item.movetype = MOVETYPE_TOSS;
  1334.     setmodel (item, "progs/backpack.mdl");
  1335.     setsize (item, '-16 -16 0', '16 16 56');
  1336.     item.touch = BackpackTouch;
  1337.     
  1338.     item.nextthink = time + 120;    // remove after 2 minutes
  1339.     item.think = SUB_Remove;
  1340. };
  1341.