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