home *** CD-ROM | disk | FTP | other *** search
/ Superpower (Alt) / SUPERPOWER.iso / q / patch / mbq759 / items.qc < prev    next >
Encoding:
Text File  |  1996-08-17  |  30.3 KB  |  1,418 lines

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