home *** CD-ROM | disk | FTP | other *** search
/ Quake 'em / QUAKEEM.BIN / quake / programs / plusgren / na_prox.qc < prev    next >
Encoding:
Text File  |  1996-08-10  |  3.8 KB  |  161 lines

  1. /*
  2.  
  3.  ProxGrenade 1.0 Copyright 1996 Niklas Angare (NiAn on undernet) angare@kuai.se.
  4.  
  5.  This code is released for all to learn from, but please do not abuse my
  6.  goodwill by copying large chunks of it. If you want to distribute my code as a
  7.  part of a package, ask me first!
  8.  
  9.  This is a part of PLUSGrenade.
  10.  
  11. */
  12.  
  13. //=============================================================================
  14.  
  15. void() BecomeExplosion;
  16. void() W_FireGrenade;
  17.  
  18. void() ProxGrenadeExplode =
  19. {
  20.     self.owner = self.proxowner;
  21.     T_RadiusDamage (self, self.owner, 120, world);
  22.  
  23.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  24.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  25.     WriteCoord (MSG_BROADCAST, self.origin_x);
  26.     WriteCoord (MSG_BROADCAST, self.origin_y);
  27.     WriteCoord (MSG_BROADCAST, self.origin_z);
  28.  
  29.     BecomeExplosion ();
  30. };
  31.  
  32. void() ProxGrenadePickup =
  33. {
  34.     other.ammo_rockets = other.ammo_rockets + self.ammo_rockets;
  35.     sprint(other, "You got ");
  36.     local string tempstring;
  37.     tempstring = ftos(self.ammo_rockets);
  38.     sprint(other, tempstring);
  39. //    sprint(other, ftos(self.ammo_rockets));
  40.     sprint(other, " rockets\n");
  41.     sound (other, CHAN_ITEM, "weapons/lock4.wav", 1, ATTN_NORM);
  42.     stuffcmd (other, "bf\n");
  43.     remove(self);
  44.     self = other;
  45.     W_SetCurrentAmmo ();
  46. };
  47.  
  48. void() ProxGrenadeTouch =
  49. {
  50.     if (other.takedamage == DAMAGE_AIM)
  51.         if(self.hasbounced) {
  52.             ProxGrenadePickup();
  53.             return;
  54.         }
  55.     if (other == self.proxowner)
  56.         return;        // don't explode on owner
  57.     if (other.takedamage == DAMAGE_AIM)
  58.     {
  59.         ProxGrenadeExplode();
  60.         return;
  61.     }
  62.     sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);    // bounce sound
  63.     if (self.velocity == '0 0 0')
  64.         self.avelocity = '0 0 0';
  65.     self.hasbounced = TRUE;
  66. };
  67.  
  68. void() GrenadeProximity =
  69. {
  70.     local    entity    head;
  71.     local    float    proxrange;
  72.  
  73.     if (self.ttl < time) {
  74.         ProxGrenadeExplode();
  75.         return;
  76.     }
  77.  
  78.     self.nextthink = time + 0.1;
  79.  
  80.     proxrange = 150;
  81.  
  82.     head = findradius(self.origin, proxrange); // Find everything within range
  83.     
  84.     // Search the list for stuff that takes damage
  85.     while (head)
  86.     {
  87.         if (head.takedamage == DAMAGE_AIM)
  88.             if(CanDamage (head, self)) {
  89.                 ProxGrenadeExplode();
  90.                 return;
  91.             }
  92.         head = head.chain;
  93.     }
  94. };
  95.  
  96. void() ProxGrenadeGoLive =
  97. {
  98.     sound (self, CHAN_WEAPON, "weapons/tink1.wav", 1, ATTN_NORM); // it's live!
  99.     self.think = GrenadeProximity;
  100.     GrenadeProximity();
  101. };
  102.  
  103. /*
  104. ================
  105. W_FireProxGrenade
  106. ================
  107. */
  108. void() W_FireProxGrenade =
  109. {
  110.     local    entity missile, mpuff;
  111.     
  112.     if(self.ammo_rockets < 5) {
  113.         sprint(self, "ammo low\n");
  114.         W_FireGrenade();
  115.         return;
  116.     }
  117.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 5;
  118.     
  119.     sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  120.  
  121.     self.punchangle_x = -2;
  122.  
  123.     missile = spawn ();
  124.     missile.proxowner = self;        // This is instead of .owner, so that
  125.     missile.movetype = MOVETYPE_BOUNCE;    //  the grenade can touch its 'owner'
  126.     missile.solid = SOLID_BBOX;        //  If .owner was set, it wouldn't touch
  127.     missile.classname = "grenade";
  128.         
  129. // set missile speed    
  130.  
  131.     makevectors (self.v_angle);
  132.  
  133.     if (self.v_angle_x)
  134.         missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  135.     else
  136.     {
  137.         missile.velocity = aim(self, 10000);
  138.         missile.velocity = missile.velocity * 600;
  139.         missile.velocity_z = 200;
  140.     }
  141.  
  142.     missile.avelocity = '300 300 300';
  143.  
  144.     missile.angles = vectoangles(missile.velocity);
  145.     
  146.     missile.touch = ProxGrenadeTouch;
  147.     
  148. // set missile duration
  149.     missile.nextthink = time + 4;
  150. /*NiAn*/missile.ttl = time + 30;        // explode anyway after 30 secs
  151. /*NiAn*/missile.think = ProxGrenadeGoLive;
  152. /*NiAn*/missile.ammo_rockets = 5;
  153.  
  154.     setmodel (missile, "progs/grenade.mdl");
  155.     setsize (missile, '0 0 0', '0 0 0');        
  156.     setorigin (missile, self.origin);
  157. };
  158.  
  159.  
  160. //=============================================================================
  161.