home *** CD-ROM | disk | FTP | other *** search
/ Quake 'em / QUAKEEM.BIN / quake / programs / flares / flares.qc < prev    next >
Encoding:
Text File  |  1996-08-07  |  29.7 KB  |  1,426 lines

  1. /*
  2.  
  3. Modified Weapons.QC code to give the player flares in Quake
  4.  
  5. 8/1/96 Steve Bond       - wedge@nuc.net
  6.  
  7. Check out QUAKE COMMAND - http://www.nuc.net/quake
  8.  
  9. */
  10. void (entity targ, entity inflictor, entity attacker, float damage) T_Damage;
  11. void () player_run;
  12. void(entity bomb, entity attacker, float rad, entity ignore) T_RadiusDamage;
  13. void(vector org, vector vel, float damage) SpawnBlood;
  14. void() SuperDamageSound;
  15.  
  16.  
  17. // called by worldspawn
  18. void() W_Precache =
  19. {
  20.     precache_model ("progs/laser.mdl"); // Enforcer laser for flare
  21.     precache_sound ("misc/power.wav");  // new rocket explosion
  22.     
  23.     precache_sound ("weapons/r_exp3.wav");  // new rocket explosion
  24.     precache_sound ("weapons/rocket1i.wav");        // spike gun
  25.     precache_sound ("weapons/sgun1.wav");
  26.     precache_sound ("weapons/guncock.wav"); // player shotgun
  27.     precache_sound ("weapons/ric1.wav");    // ricochet (used in c code)
  28.     precache_sound ("weapons/ric2.wav");    // ricochet (used in c code)
  29.     precache_sound ("weapons/ric3.wav");    // ricochet (used in c code)
  30.     precache_sound ("weapons/spike2.wav");  // super spikes
  31.     precache_sound ("weapons/tink1.wav");   // spikes tink (used in c code)
  32.     precache_sound ("weapons/grenade.wav"); // grenade launcher
  33.     precache_sound ("weapons/bounce.wav");          // grenade bounce
  34.     precache_sound ("weapons/shotgn2.wav"); // super shotgun
  35. };
  36.  
  37. float() crandom =
  38. {
  39.     return 2*(random() - 0.5);
  40. };
  41.  
  42. /*
  43. ================
  44. W_FireAxe
  45. ================
  46. */
  47. void() W_FireAxe =
  48. {
  49.     local   vector  source;
  50.     local   vector  org;
  51.  
  52.     source = self.origin + '0 0 16';
  53.     traceline (source, source + v_forward*64, FALSE, self);
  54.     if (trace_fraction == 1.0)
  55.         return;
  56.     
  57.     org = trace_endpos - v_forward*4;
  58.  
  59.     if (trace_ent.takedamage)
  60.     {
  61.         trace_ent.axhitme = 1;
  62.         SpawnBlood (org, '0 0 0', 20);
  63.         T_Damage (trace_ent, self, self, 20);
  64.     }
  65.     else
  66.     {       // hit wall
  67.         sound (self, CHAN_WEAPON, "player/axhit2.wav", 1, ATTN_NORM);
  68.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  69.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  70.         WriteCoord (MSG_BROADCAST, org_x);
  71.         WriteCoord (MSG_BROADCAST, org_y);
  72.         WriteCoord (MSG_BROADCAST, org_z);
  73.     }
  74. };
  75.  
  76.  
  77. //============================================================================
  78.  
  79.  
  80. vector() wall_velocity =
  81. {
  82.     local vector    vel;
  83.     
  84.     vel = normalize (self.velocity);
  85.     vel = normalize(vel + v_up*(random()- 0.5) + v_right*(random()- 0.5));
  86.     vel = vel + 2*trace_plane_normal;
  87.     vel = vel * 200;
  88.     
  89.     return vel;
  90. };
  91.  
  92.  
  93. /*
  94. ================
  95. SpawnMeatSpray
  96. ================
  97. */
  98. void(vector org, vector vel) SpawnMeatSpray =
  99. {
  100.     local   entity missile, mpuff;
  101.     local   vector  org;
  102.  
  103.     missile = spawn ();
  104.     missile.owner = self;
  105.     missile.movetype = MOVETYPE_BOUNCE;
  106.     missile.solid = SOLID_NOT;
  107.  
  108.     makevectors (self.angles);
  109.  
  110.     missile.velocity = vel;
  111.     missile.velocity_z = missile.velocity_z + 250 + 50*random();
  112.  
  113.     missile.avelocity = '3000 1000 2000';
  114.     
  115. // set missile duration
  116.     missile.nextthink = time + 1;
  117.     missile.think = SUB_Remove;
  118.  
  119.     setmodel (missile, "progs/zom_gib.mdl");
  120.     setsize (missile, '0 0 0', '0 0 0');            
  121.     setorigin (missile, org);
  122. };
  123.  
  124. /*
  125. ================
  126. SpawnBlood
  127. ================
  128. */
  129. void(vector org, vector vel, float damage) SpawnBlood =
  130. {
  131.     particle (org, vel*0.1, 73, damage*2);
  132. };
  133.  
  134. /*
  135. ================
  136. spawn_touchblood
  137. ================
  138. */
  139. void(float damage) spawn_touchblood =
  140. {
  141.     local vector    vel;
  142.  
  143.     vel = wall_velocity () * 0.2;
  144.     SpawnBlood (self.origin + vel*0.01, vel, damage);
  145. };
  146.  
  147.  
  148. /*
  149. ================
  150. SpawnChunk
  151. ================
  152. */
  153. void(vector org, vector vel) SpawnChunk =
  154. {
  155.     particle (org, vel*0.02, 0, 10);
  156. };
  157.  
  158. /*
  159. ==============================================================================
  160.  
  161. MULTI-DAMAGE
  162.  
  163. Collects multiple small damages into a single damage
  164.  
  165. ==============================================================================
  166. */
  167.  
  168. entity  multi_ent;
  169. float   multi_damage;
  170.  
  171. void() ClearMultiDamage =
  172. {
  173.     multi_ent = world;
  174.     multi_damage = 0;
  175. };
  176.  
  177. void() ApplyMultiDamage =
  178. {
  179.     if (!multi_ent)
  180.         return;
  181.     T_Damage (multi_ent, self, self, multi_damage);
  182. };
  183.  
  184. void(entity hit, float damage) AddMultiDamage =
  185. {
  186.     if (!hit)
  187.         return;
  188.     
  189.     if (hit != multi_ent)
  190.     {
  191.         ApplyMultiDamage ();
  192.         multi_damage = damage;
  193.         multi_ent = hit;
  194.     }
  195.     else
  196.         multi_damage = multi_damage + damage;
  197. };
  198.  
  199. /*
  200. ==============================================================================
  201.  
  202. BULLETS
  203.  
  204. ==============================================================================
  205. */
  206.  
  207. /*
  208. ================
  209. TraceAttack
  210. ================
  211. */
  212. void(float damage, vector dir) TraceAttack =
  213. {
  214.     local   vector  vel, org;
  215.     
  216.     vel = normalize(dir + v_up*crandom() + v_right*crandom());
  217.     vel = vel + 2*trace_plane_normal;
  218.     vel = vel * 200;
  219.  
  220.     org = trace_endpos - dir*4;
  221.  
  222.     if (trace_ent.takedamage)
  223.     {
  224.         SpawnBlood (org, vel*0.2, damage);
  225.         AddMultiDamage (trace_ent, damage);
  226.     }
  227.     else
  228.     {
  229.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  230.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  231.         WriteCoord (MSG_BROADCAST, org_x);
  232.         WriteCoord (MSG_BROADCAST, org_y);
  233.         WriteCoord (MSG_BROADCAST, org_z);
  234.     }
  235. };
  236.  
  237. /*
  238. ================
  239. FireBullets
  240.  
  241. Used by shotgun, super shotgun, and enemy soldier firing
  242. Go to the trouble of combining multiple pellets into a single damage call.
  243. ================
  244. */
  245. void(float shotcount, vector dir, vector spread) FireBullets =
  246. {
  247.     local   vector direction;
  248.     local   vector  src;
  249.     
  250.     makevectors(self.v_angle);
  251.  
  252.     src = self.origin + v_forward*10;
  253.     src_z = self.absmin_z + self.size_z * 0.7;
  254.  
  255.     ClearMultiDamage ();
  256.     while (shotcount > 0)
  257.     {
  258.         direction = dir + crandom()*spread_x*v_right + crandom()*spread_y*v_up;
  259.  
  260.         traceline (src, src + direction*2048, FALSE, self);
  261.         if (trace_fraction != 1.0)
  262.             TraceAttack (4, direction);
  263.  
  264.         shotcount = shotcount - 1;
  265.     }
  266.     ApplyMultiDamage ();
  267. };
  268.  
  269. /*
  270. ================
  271. W_FireShotgun
  272. ================
  273. */
  274. void() W_FireShotgun =
  275. {
  276.     local vector dir;
  277.  
  278.     sound (self, CHAN_WEAPON, "weapons/guncock.wav", 1, ATTN_NORM); 
  279.  
  280.     self.punchangle_x = -2;
  281.     
  282.     self.currentammo = self.ammo_shells = self.ammo_shells - 1;
  283.     dir = aim (self, 100000);
  284.     FireBullets (6, dir, '0.04 0.04 0');
  285. };
  286.  
  287.  
  288. /*
  289. ================
  290. W_FireSuperShotgun
  291. ================
  292. */
  293. void() W_FireSuperShotgun =
  294. {
  295.     local vector dir;
  296.  
  297.     if (self.currentammo == 1)
  298.     {
  299.         W_FireShotgun ();
  300.         return;
  301.     }
  302.         
  303.     sound (self ,CHAN_WEAPON, "weapons/shotgn2.wav", 1, ATTN_NORM); 
  304.  
  305.     self.punchangle_x = -4;
  306.     
  307.     self.currentammo = self.ammo_shells = self.ammo_shells - 2;
  308.     dir = aim (self, 100000);
  309.     FireBullets (14, dir, '0.14 0.08 0');
  310. };
  311.  
  312.  
  313. /*
  314. ==============================================================================
  315.  
  316. ROCKETS
  317.  
  318. ==============================================================================
  319. */
  320.  
  321. void()  s_explode1      =       [0,             s_explode2] {};
  322. void()  s_explode2      =       [1,             s_explode3] {};
  323. void()  s_explode3      =       [2,             s_explode4] {};
  324. void()  s_explode4      =       [3,             s_explode5] {};
  325. void()  s_explode5      =       [4,             s_explode6] {};
  326. void()  s_explode6      =       [5,             SUB_Remove] {};
  327.  
  328. void() BecomeExplosion =
  329. {
  330.     self.movetype = MOVETYPE_NONE;
  331.     self.velocity = '0 0 0';
  332.     self.touch = SUB_Null;
  333.     setmodel (self, "progs/s_explod.spr");
  334.     self.solid = SOLID_NOT;
  335.     s_explode1 ();
  336. };
  337.  
  338. void() T_MissileTouch =
  339. {
  340.     local float     damg;
  341.  
  342.     if (other == self.owner)
  343.         return;         // don't explode on owner
  344.  
  345.     if (pointcontents(self.origin) == CONTENT_SKY)
  346.     {
  347.         remove(self);
  348.         return;
  349.     }
  350.  
  351.     damg = 100 + random()*20;
  352.     
  353.     if (other.health)
  354.     {
  355.         if (other.classname == "monster_shambler")
  356.             damg = damg * 0.5;      // mostly immune
  357.         T_Damage (other, self, self.owner, damg );
  358.     }
  359.  
  360.     // don't do radius damage to the other, because all the damage
  361.     // was done in the impact
  362.     T_RadiusDamage (self, self.owner, 120, other);
  363.  
  364. //      sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
  365.     self.origin = self.origin - 8*normalize(self.velocity);
  366.  
  367.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  368.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  369.     WriteCoord (MSG_BROADCAST, self.origin_x);
  370.     WriteCoord (MSG_BROADCAST, self.origin_y);
  371.     WriteCoord (MSG_BROADCAST, self.origin_z);
  372.  
  373.     BecomeExplosion ();
  374. };
  375.  
  376.  
  377.  
  378. /*
  379. ================
  380. W_FireRocket
  381. ================
  382. */
  383. void() W_FireRocket =
  384. {
  385.     local   entity missile, mpuff;
  386.     
  387.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  388.     
  389.     sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
  390.  
  391.     self.punchangle_x = -2;
  392.  
  393.     missile = spawn ();
  394.     missile.owner = self;
  395.     missile.movetype = MOVETYPE_FLYMISSILE;
  396.     missile.solid = SOLID_BBOX;
  397.         
  398. // set missile speed    
  399.  
  400.     makevectors (self.v_angle);
  401.     missile.velocity = aim(self, 1000);
  402.     missile.velocity = missile.velocity * 1000;
  403.     missile.angles = vectoangles(missile.velocity);
  404.     
  405.     missile.touch = T_MissileTouch;
  406.     
  407. // set missile duration
  408.     missile.nextthink = time + 5;
  409.     missile.think = SUB_Remove;
  410.  
  411.     setmodel (missile, "progs/missile.mdl");
  412.     setsize (missile, '0 0 0', '0 0 0');            
  413.     setorigin (missile, self.origin + v_forward*8 + '0 0 16');
  414. };
  415.  
  416. /*
  417. ===============================================================================
  418.  
  419. LIGHTNING
  420.  
  421. ===============================================================================
  422. */
  423.  
  424. /*
  425. =================
  426. LightningDamage
  427. =================
  428. */
  429. void(vector p1, vector p2, entity from, float damage) LightningDamage =
  430. {
  431.     local entity            e1, e2;
  432.     local vector            f;
  433.     
  434.     f = p2 - p1;
  435.     normalize (f);
  436.     f_x = 0 - f_y;
  437.     f_y = f_x;
  438.     f_z = 0;
  439.     f = f*16;
  440.  
  441.     e1 = e2 = world;
  442.  
  443.     traceline (p1, p2, FALSE, self);
  444.     if (trace_ent.takedamage)
  445.     {
  446.         particle (trace_endpos, '0 0 100', 225, damage*4);
  447.         T_Damage (trace_ent, from, from, damage);
  448.         if (self.classname == "player")
  449.         {
  450.             if (other.classname == "player")
  451.                 trace_ent.velocity_z = trace_ent.velocity_z + 400;
  452.         }
  453.     }
  454.     e1 = trace_ent;
  455.  
  456.     traceline (p1 + f, p2 + f, FALSE, self);
  457.     if (trace_ent != e1 && trace_ent.takedamage)
  458.     {
  459.         particle (trace_endpos, '0 0 100', 225, damage*4);
  460.         T_Damage (trace_ent, from, from, damage);
  461.     }
  462.     e2 = trace_ent;
  463.  
  464.     traceline (p1 - f, p2 - f, FALSE, self);
  465.     if (trace_ent != e1 && trace_ent != e2 && trace_ent.takedamage)
  466.     {
  467.         particle (trace_endpos, '0 0 100', 225, damage*4);
  468.         T_Damage (trace_ent, from, from, damage);
  469.     }
  470. };
  471.  
  472.  
  473. void() W_FireLightning =
  474. {
  475.     local   vector          org;
  476.  
  477.     if (self.ammo_cells < 1)
  478.     {
  479.         self.weapon = W_BestWeapon ();
  480.         W_SetCurrentAmmo ();
  481.         return;
  482.     }
  483.  
  484. // explode if under water
  485.     if (self.waterlevel > 1)
  486.     {
  487.         T_RadiusDamage (self, self, 35*self.ammo_cells, world);
  488.         self.ammo_cells = 0;
  489.         W_SetCurrentAmmo ();
  490.         return;
  491.     }
  492.  
  493.     if (self.t_width < time)
  494.     {
  495.         sound (self, CHAN_WEAPON, "weapons/lhit.wav", 1, ATTN_NORM);
  496.         self.t_width = time + 0.6;
  497.     }
  498.     self.punchangle_x = -2;
  499.  
  500.     self.currentammo = self.ammo_cells = self.ammo_cells - 1;
  501.  
  502.     org = self.origin + '0 0 16';
  503.     
  504.     traceline (org, org + v_forward*600, TRUE, self);
  505.  
  506.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  507.     WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
  508.     WriteEntity (MSG_BROADCAST, self);
  509.     WriteCoord (MSG_BROADCAST, org_x);
  510.     WriteCoord (MSG_BROADCAST, org_y);
  511.     WriteCoord (MSG_BROADCAST, org_z);
  512.     WriteCoord (MSG_BROADCAST, trace_endpos_x);
  513.     WriteCoord (MSG_BROADCAST, trace_endpos_y);
  514.     WriteCoord (MSG_BROADCAST, trace_endpos_z);
  515.  
  516.     LightningDamage (self.origin, trace_endpos + v_forward*4, self, 30);
  517. };
  518.  
  519.  
  520. //=============================================================================
  521.  
  522.  
  523. void() GrenadeExplode =
  524. {
  525.     T_RadiusDamage (self, self.owner, 120, world);
  526.  
  527.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  528.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  529.     WriteCoord (MSG_BROADCAST, self.origin_x);
  530.     WriteCoord (MSG_BROADCAST, self.origin_y);
  531.     WriteCoord (MSG_BROADCAST, self.origin_z);
  532.  
  533.     BecomeExplosion ();
  534. };
  535.  
  536. void() GrenadeTouch =
  537. {
  538.     if (other == self.owner)
  539.         return;         // don't explode on owner
  540.     if (other.takedamage == DAMAGE_AIM)
  541.     {
  542.         GrenadeExplode();
  543.         return;
  544.     }
  545.     sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);  // bounce sound
  546.     if (self.velocity == '0 0 0')
  547.         self.avelocity = '0 0 0';
  548. };
  549.  
  550. /*
  551. ================
  552. W_FireGrenade
  553. ================
  554. */
  555. void() W_FireGrenade =
  556. {
  557.     local   entity missile, mpuff;
  558.     
  559.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  560.     
  561.     sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  562.  
  563.     self.punchangle_x = -2;
  564.  
  565.     missile = spawn ();
  566.     missile.owner = self;
  567.     missile.movetype = MOVETYPE_BOUNCE;
  568.     missile.solid = SOLID_BBOX;
  569.     missile.classname = "grenade";
  570.         
  571. // set missile speed    
  572.  
  573.     makevectors (self.v_angle);
  574.  
  575.     if (self.v_angle_x)
  576.         missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  577.     else
  578.     {
  579.         missile.velocity = aim(self, 10000);
  580.         missile.velocity = missile.velocity * 600;
  581.         missile.velocity_z = 200;
  582.     }
  583.  
  584.     missile.avelocity = '300 300 300';
  585.  
  586.     missile.angles = vectoangles(missile.velocity);
  587.     
  588.     missile.touch = GrenadeTouch;
  589.     
  590. // set missile duration
  591.     missile.nextthink = time + 2.5;
  592.     missile.think = GrenadeExplode;
  593.  
  594.     setmodel (missile, "progs/grenade.mdl");
  595.     setsize (missile, '0 0 0', '0 0 0');            
  596.     setorigin (missile, self.origin);
  597. };
  598.  
  599.  
  600. //=============================================================================
  601.  
  602. void() flare_touch;
  603. void() flare_bright;
  604. void() flare_dim;
  605.  
  606. void() spike_touch;
  607. void() superspike_touch;
  608.  
  609.  
  610.  
  611.  
  612. /*
  613. =========================================================================
  614. Flares Code Begins Here.
  615. =========================================================================
  616. */
  617.  
  618. /*
  619. ================================
  620. launch_flare
  621.  
  622. rework of id's launch_spike code
  623. ================================
  624. */
  625. void(vector org, vector dir) launch_flare =
  626. {
  627.     local   entity  missile;
  628.  
  629.     missile = spawn ();
  630.     missile.owner = self;
  631.     missile.movetype = MOVETYPE_FLYMISSILE;
  632.     missile.solid = SOLID_BBOX;
  633.  
  634.     missile.angles = vectoangles(dir);
  635.     
  636. // go to flare_touch if the flare touches anything
  637.     missile.touch = flare_touch;
  638.         missile.classname = "flare";
  639.  
  640. // go to flare_bright when the flare's think time is up
  641.     missile.think = flare_bright;
  642.  
  643. // 3 seconds until flare goes bright
  644.     missile.nextthink = time + 3;
  645.  
  646. // The LASER.MDL makes a decent flare
  647.     setmodel (missile, "progs/laser.mdl");
  648.     setsize (missile, VEC_ORIGIN, VEC_ORIGIN);               
  649.     setorigin (missile, org);
  650.     missile.velocity = dir * 1000;
  651.  
  652. // Make the flare dim. (.effects is an 8-bit register)
  653.         missile.effects=EF_DIMLIGHT;
  654.  
  655. };
  656.  
  657. /*
  658. ============================
  659. flare_touch
  660.  
  661. rework of id's spike_touch()
  662. ============================
  663. */
  664. void() flare_touch =
  665. {
  666. local float rand;
  667.     if (other == self.owner)
  668.         return;
  669.  
  670.         if (other.classname == "door" || other.classname == "plat")
  671.                 {
  672.                 remove(self);
  673.                 return;
  674.                 }
  675.  
  676.     if (other.solid == SOLID_TRIGGER)
  677.         return; // trigger field, do nothing
  678.  
  679.     if (pointcontents(self.origin) == CONTENT_SKY)
  680.     {
  681.         remove(self);
  682.         return;
  683.     }
  684.     
  685. // has the flare hit something that bleeds?
  686.     if (other.takedamage)
  687.     {
  688.                 // If so, spawn some blood
  689.         spawn_touchblood (9);
  690.                 // also do one point of damage    
  691.         T_Damage (other, self, self.owner, 1);
  692.  
  693. /*
  694. Don't remove the flare unless it is still flying. Otherwise, monsters or
  695. other players can come up and 'pull' your flare out of the wall
  696. */
  697.           if (self.velocity != '0 0 0')
  698.             remove(self);
  699.     }
  700.     else
  701.     {
  702.         // Write information to the network
  703.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  704.         WriteByte (MSG_BROADCAST, TE_SPIKE);
  705.         WriteCoord (MSG_BROADCAST, self.origin_x);
  706.         WriteCoord (MSG_BROADCAST, self.origin_y);
  707.         WriteCoord (MSG_BROADCAST, self.origin_z);
  708.     }
  709.  
  710. //Stop the flare, but do not remove it.
  711.     self.movetype = MOVETYPE_NONE;
  712. // Fix it so that flare only partially embeds itself (thanks, Luke)
  713.         self.origin = self.origin - self.velocity * 0.005;
  714.          self.velocity = '0 0 0';
  715.     self.touch = SUB_Null;
  716. };
  717.  
  718.  
  719. /*
  720. ==============================
  721. flare_bright()
  722.  
  723. This function makes the flare
  724. emit brighter light
  725. ==============================
  726. */
  727.  
  728. void() flare_bright =
  729. {
  730.     local vector    vel;
  731. // Make the flare get BRIGHT by setting .effects bit       
  732.         self.effects=EF_BRIGHTLIGHT;
  733. // Give it 10 seconds at maximum intensity
  734.     self.nextthink = time + 10;
  735. // After 10 seconds, call flare_dim
  736.     self.think = flare_dim;
  737. // Play a sound for flare ignition
  738.     sound (self, CHAN_WEAPON, "misc/power.wav", 1, ATTN_NORM);
  739.     
  740. // Set up some red and yellow sparks
  741.     vel = '0 0 150';
  742.     particle (self.origin+vel*0.01,vel,111,150);
  743.         vel = '0 0 120';
  744.     particle (self.origin+vel*0.01,vel,73,200);
  745.  
  746.  
  747.  
  748. /*
  749. ==============================
  750. flare_dim()
  751.  
  752. This function makes the flare
  753. go dim again
  754. ==============================
  755. */
  756. };
  757.  
  758. void() flare_dim =
  759. {
  760. // Make the flare get dim by setting .effects bit        
  761.         self.effects=EF_DIMLIGHT;
  762. // Give it 15 seconds before burnout
  763.     self.nextthink = time + 15;
  764. // After 15 seconds remove the flare from the game
  765.     self.think = SUB_Remove;
  766. };
  767.  
  768.  
  769.  
  770.  
  771.  
  772. /*
  773. ===================================================================
  774. End of Flare Code  -    Steve Bond 8/1/96
  775. ===================================================================
  776. */
  777.  
  778.  
  779.  
  780. /*
  781. ===============
  782. launch_spike
  783.  
  784. Used for both the player and the ogre
  785. ===============
  786. */
  787. void(vector org, vector dir) launch_spike =
  788. {
  789.     newmis = spawn ();
  790.     newmis.owner = self;
  791.     newmis.movetype = MOVETYPE_FLYMISSILE;
  792.     newmis.solid = SOLID_BBOX;
  793.  
  794.     newmis.angles = vectoangles(dir);
  795.     
  796.     newmis.touch = spike_touch;
  797.     newmis.classname = "spike";
  798.     newmis.think = SUB_Remove;
  799.     newmis.nextthink = time + 6;
  800.     setmodel (newmis, "progs/spike.mdl");
  801.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);               
  802.     setorigin (newmis, org);
  803.  
  804.     newmis.velocity = dir * 1000;
  805. };
  806.  
  807. void() W_FireSuperSpikes =
  808. {
  809.     local vector    dir;
  810.     local entity    old;
  811.     
  812.     sound (self, CHAN_WEAPON, "weapons/spike2.wav", 1, ATTN_NORM);
  813.     self.attack_finished = time + 0.2;
  814.     self.currentammo = self.ammo_nails = self.ammo_nails - 2;
  815.     dir = aim (self, 1000);
  816.     launch_spike (self.origin + '0 0 16', dir);
  817.     newmis.touch = superspike_touch;
  818.     setmodel (newmis, "progs/s_spike.mdl");
  819.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);               
  820.     self.punchangle_x = -2;
  821. };
  822.  
  823. void(float ox) W_FireFlare =
  824. {
  825.     local vector    dir;
  826.     local entity    old;
  827.     
  828.     makevectors (self.v_angle);
  829.     
  830.     sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  831.     self.attack_finished = time + 0.5;
  832.     dir = aim (self, 1000);
  833.     launch_flare (self.origin + '0 0 24' + v_right*ox, dir);
  834.  
  835.     self.punchangle_x = -2;
  836. };
  837.  
  838. void(float ox) W_FireSpikes =
  839. {
  840.     local vector    dir;
  841.     local entity    old;
  842.     
  843.     makevectors (self.v_angle);
  844.     
  845.     if (self.ammo_nails >= 2 && self.weapon == IT_SUPER_NAILGUN)
  846.     {
  847.         W_FireSuperSpikes ();
  848.         return;
  849.     }
  850.  
  851.     if (self.ammo_nails < 1)
  852.     {
  853.         self.weapon = W_BestWeapon ();
  854.         W_SetCurrentAmmo ();
  855.         return;
  856.     }
  857.  
  858.     sound (self, CHAN_WEAPON, "weapons/rocket1i.wav", 1, ATTN_NORM);
  859.     self.attack_finished = time + 0.2;
  860.     self.currentammo = self.ammo_nails = self.ammo_nails - 1;
  861.     dir = aim (self, 1000);
  862.     launch_spike (self.origin + '0 0 16' + v_right*ox, dir);
  863.  
  864.     self.punchangle_x = -2;
  865. };
  866.  
  867.  
  868.  
  869. .float hit_z;
  870. void() spike_touch =
  871. {
  872. local float rand;
  873.     if (other == self.owner)
  874.         return;
  875.  
  876.     if (other.solid == SOLID_TRIGGER)
  877.         return; // trigger field, do nothing
  878.  
  879.     if (pointcontents(self.origin) == CONTENT_SKY)
  880.     {
  881.         remove(self);
  882.         return;
  883.     }
  884.     
  885. // hit something that bleeds
  886.     if (other.takedamage)
  887.     {
  888.         spawn_touchblood (9);
  889.         T_Damage (other, self, self.owner, 9);
  890.     }
  891.     else
  892.     {
  893.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  894.         
  895.         if (self.classname == "wizspike")
  896.             WriteByte (MSG_BROADCAST, TE_WIZSPIKE);
  897.         else if (self.classname == "knightspike")
  898.             WriteByte (MSG_BROADCAST, TE_KNIGHTSPIKE);
  899.         else
  900.             WriteByte (MSG_BROADCAST, TE_SPIKE);
  901.         WriteCoord (MSG_BROADCAST, self.origin_x);
  902.         WriteCoord (MSG_BROADCAST, self.origin_y);
  903.         WriteCoord (MSG_BROADCAST, self.origin_z);
  904.     }
  905.  
  906.     remove(self);
  907.  
  908. };
  909.  
  910. void() superspike_touch =
  911. {
  912. local float rand;
  913.     if (other == self.owner)
  914.         return;
  915.  
  916.     if (other.solid == SOLID_TRIGGER)
  917.         return; // trigger field, do nothing
  918.  
  919.     if (pointcontents(self.origin) == CONTENT_SKY)
  920.     {
  921.         remove(self);
  922.         return;
  923.     }
  924.     
  925. // hit something that bleeds
  926.     if (other.takedamage)
  927.     {
  928.         spawn_touchblood (18);
  929.         T_Damage (other, self, self.owner, 18);
  930.     }
  931.     else
  932.     {
  933.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  934.         WriteByte (MSG_BROADCAST, TE_SUPERSPIKE);
  935.         WriteCoord (MSG_BROADCAST, self.origin_x);
  936.         WriteCoord (MSG_BROADCAST, self.origin_y);
  937.         WriteCoord (MSG_BROADCAST, self.origin_z);
  938.     }
  939.  
  940.     remove(self);
  941.  
  942. };
  943.  
  944.  
  945. /*
  946. ===============================================================================
  947.  
  948. PLAYER WEAPON USE
  949.  
  950. ===============================================================================
  951. */
  952.  
  953. void() W_SetCurrentAmmo =
  954. {
  955.     player_run ();          // get out of any weapon firing states
  956.  
  957.     self.items = self.items - ( self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS) );
  958.     
  959.     if (self.weapon == IT_AXE)
  960.     {
  961.         self.currentammo = 0;
  962.         self.weaponmodel = "progs/v_axe.mdl";
  963.         self.weaponframe = 0;
  964.     }
  965.     else if (self.weapon == IT_SHOTGUN)
  966.     {
  967.         self.currentammo = self.ammo_shells;
  968.         self.weaponmodel = "progs/v_shot.mdl";
  969.         self.weaponframe = 0;
  970.         self.items = self.items | IT_SHELLS;
  971.     }
  972.     else if (self.weapon == IT_SUPER_SHOTGUN)
  973.     {
  974.         self.currentammo = self.ammo_shells;
  975.         self.weaponmodel = "progs/v_shot2.mdl";
  976.         self.weaponframe = 0;
  977.         self.items = self.items | IT_SHELLS;
  978.     }
  979.     else if (self.weapon == IT_NAILGUN)
  980.     {
  981.         self.currentammo = self.ammo_nails;
  982.         self.weaponmodel = "progs/v_nail.mdl";
  983.         self.weaponframe = 0;
  984.         self.items = self.items | IT_NAILS;
  985.     }
  986.     else if (self.weapon == IT_SUPER_NAILGUN)
  987.     {
  988.         self.currentammo = self.ammo_nails;
  989.         self.weaponmodel = "progs/v_nail2.mdl";
  990.         self.weaponframe = 0;
  991.         self.items = self.items | IT_NAILS;
  992.     }
  993.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  994.     {
  995.         self.currentammo = self.ammo_rockets;
  996.         self.weaponmodel = "progs/v_rock.mdl";
  997.         self.weaponframe = 0;
  998.         self.items = self.items | IT_ROCKETS;
  999.     }
  1000.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  1001.     {
  1002.         self.currentammo = self.ammo_rockets;
  1003.         self.weaponmodel = "progs/v_rock2.mdl";
  1004.         self.weaponframe = 0;
  1005.         self.items = self.items | IT_ROCKETS;
  1006.     }
  1007.     else if (self.weapon == IT_LIGHTNING)
  1008.     {
  1009.         self.currentammo = self.ammo_cells;
  1010.         self.weaponmodel = "progs/v_light.mdl";
  1011.         self.weaponframe = 0;
  1012.         self.items = self.items | IT_CELLS;
  1013.     }
  1014.     else
  1015.     {
  1016.         self.currentammo = 0;
  1017.         self.weaponmodel = "";
  1018.         self.weaponframe = 0;
  1019.     }
  1020. };
  1021.  
  1022. float() W_BestWeapon =
  1023. {
  1024.     local   float   it;
  1025.     
  1026.     it = self.items;
  1027.  
  1028.     if(self.ammo_cells >= 1 && (it & IT_LIGHTNING) )
  1029.         return IT_LIGHTNING;
  1030.     else if(self.ammo_nails >= 2 && (it & IT_SUPER_NAILGUN) )
  1031.         return IT_SUPER_NAILGUN;
  1032.     else if(self.ammo_shells >= 2 && (it & IT_SUPER_SHOTGUN) )
  1033.         return IT_SUPER_SHOTGUN;
  1034.     else if(self.ammo_nails >= 1 && (it & IT_NAILGUN) )
  1035.         return IT_NAILGUN;
  1036.     else if(self.ammo_shells >= 1 && (it & IT_SHOTGUN) )
  1037.         return IT_SHOTGUN;
  1038.         
  1039. /*
  1040.     if(self.ammo_rockets >= 1 && (it & IT_ROCKET_LAUNCHER) )
  1041.         return IT_ROCKET_LAUNCHER;
  1042.     else if(self.ammo_rockets >= 1 && (it & IT_GRENADE_LAUNCHER) )
  1043.         return IT_GRENADE_LAUNCHER;
  1044.  
  1045. */
  1046.  
  1047.     return IT_AXE;
  1048. };
  1049.  
  1050. float() W_CheckNoAmmo =
  1051. {
  1052.     if (self.currentammo > 0)
  1053.         return TRUE;
  1054.  
  1055.     if (self.weapon == IT_AXE)
  1056.         return TRUE;
  1057.     
  1058.     self.weapon = W_BestWeapon ();
  1059.  
  1060.     W_SetCurrentAmmo ();
  1061.     
  1062. // drop the weapon down
  1063.     return FALSE;
  1064. };
  1065.  
  1066. /*
  1067. ============
  1068. W_Attack
  1069.  
  1070. An attack impulse can be triggered now
  1071. ============
  1072. */
  1073. void()  player_axe1;
  1074. void()  player_axeb1;
  1075. void()  player_axec1;
  1076. void()  player_axed1;
  1077. void()  player_shot1;
  1078. void()  player_nail1;
  1079. void()  player_light1;
  1080. void()  player_rocket1;
  1081.  
  1082. void() W_Attack =
  1083. {
  1084.     local   float   r;
  1085.  
  1086.     if (!W_CheckNoAmmo ())
  1087.         return;
  1088.  
  1089.     makevectors     (self.v_angle);                 // calculate forward angle for velocity
  1090.     self.show_hostile = time + 1;   // wake monsters up
  1091.  
  1092.     if (self.weapon == IT_AXE)
  1093.     {
  1094.         sound (self, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM);
  1095.         r = random();
  1096.         if (r < 0.25)
  1097.             player_axe1 ();
  1098.         else if (r<0.5)
  1099.             player_axeb1 ();
  1100.         else if (r<0.75)
  1101.             player_axec1 ();
  1102.         else
  1103.             player_axed1 ();
  1104.         self.attack_finished = time + 0.5;
  1105.     }
  1106.     else if (self.weapon == IT_SHOTGUN)
  1107.     {
  1108.         player_shot1 ();
  1109.         W_FireShotgun ();
  1110.         self.attack_finished = time + 0.5;
  1111.     }
  1112.     else if (self.weapon == IT_SUPER_SHOTGUN)
  1113.     {
  1114.         player_shot1 ();
  1115.         W_FireSuperShotgun ();
  1116.         self.attack_finished = time + 0.7;
  1117.     }
  1118.     else if (self.weapon == IT_NAILGUN)
  1119.     {
  1120.         player_nail1 ();
  1121.     }
  1122.     else if (self.weapon == IT_SUPER_NAILGUN)
  1123.     {
  1124.         player_nail1 ();
  1125.     }
  1126.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  1127.     {
  1128.         player_rocket1();
  1129.         W_FireGrenade();
  1130.         self.attack_finished = time + 0.6;
  1131.     }
  1132.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  1133.     {
  1134.         player_rocket1();
  1135.         W_FireRocket();
  1136.         self.attack_finished = time + 0.8;
  1137.     }
  1138.     else if (self.weapon == IT_LIGHTNING)
  1139.     {
  1140.         player_light1();
  1141.         self.attack_finished = time + 0.1;
  1142.         sound (self, CHAN_AUTO, "weapons/lstart.wav", 1, ATTN_NORM);
  1143.     }
  1144. };
  1145.  
  1146. /*
  1147. ============
  1148. W_ChangeWeapon
  1149.  
  1150. ============
  1151. */
  1152. void() W_ChangeWeapon =
  1153. {
  1154.     local   float   it, am, fl;
  1155.     
  1156.     it = self.items;
  1157.     am = 0;
  1158.     
  1159.     if (self.impulse == 1)
  1160.     {
  1161.         fl = IT_AXE;
  1162.     }
  1163.     else if (self.impulse == 2)
  1164.     {
  1165.         fl = IT_SHOTGUN;
  1166.         if (self.ammo_shells < 1)
  1167.             am = 1;
  1168.     }
  1169.     else if (self.impulse == 3)
  1170.     {
  1171.         fl = IT_SUPER_SHOTGUN;
  1172.         if (self.ammo_shells < 2)
  1173.             am = 1;
  1174.     }               
  1175.     else if (self.impulse == 4)
  1176.     {
  1177.         fl = IT_NAILGUN;
  1178.         if (self.ammo_nails < 1)
  1179.             am = 1;
  1180.     }
  1181.     else if (self.impulse == 5)
  1182.     {
  1183.         fl = IT_SUPER_NAILGUN;
  1184.         if (self.ammo_nails < 2)
  1185.             am = 1;
  1186.     }
  1187.     else if (self.impulse == 6)
  1188.     {
  1189.         fl = IT_GRENADE_LAUNCHER;
  1190.         if (self.ammo_rockets < 1)
  1191.             am = 1;
  1192.     }
  1193.     else if (self.impulse == 7)
  1194.     {
  1195.         fl = IT_ROCKET_LAUNCHER;
  1196.         if (self.ammo_rockets < 1)
  1197.             am = 1;
  1198.     }
  1199.     else if (self.impulse == 8)
  1200.     {
  1201.         fl = IT_LIGHTNING;
  1202.         if (self.ammo_cells < 1)
  1203.             am = 1;
  1204.     }
  1205.  
  1206.     self.impulse = 0;
  1207.     
  1208.     if (!(self.items & fl))
  1209.     {       // don't have the weapon or the ammo
  1210.         sprint (self, "no weapon.\n");
  1211.         return;
  1212.     }
  1213.     
  1214.     if (am)
  1215.     {       // don't have the ammo
  1216.         sprint (self, "not enough ammo.\n");
  1217.         return;
  1218.     }
  1219.  
  1220. //
  1221. // set weapon, set ammo
  1222. //
  1223.     self.weapon = fl;               
  1224.     W_SetCurrentAmmo ();
  1225. };
  1226.  
  1227. /*
  1228. ============
  1229. CheatCommand
  1230. ============
  1231. */
  1232. void() CheatCommand =
  1233. {
  1234.     if (deathmatch || coop)
  1235.         return;
  1236.  
  1237.     self.ammo_rockets = 100;
  1238.     self.ammo_nails = 200;
  1239.     self.ammo_shells = 100;
  1240.     self.items = self.items | 
  1241.         IT_AXE |
  1242.         IT_SHOTGUN |
  1243.         IT_SUPER_SHOTGUN |
  1244.         IT_NAILGUN |
  1245.         IT_SUPER_NAILGUN |
  1246.         IT_GRENADE_LAUNCHER |
  1247.         IT_ROCKET_LAUNCHER |
  1248.         IT_KEY1 | IT_KEY2;
  1249.  
  1250.     self.ammo_cells = 200;
  1251.     self.items = self.items | IT_LIGHTNING;
  1252.  
  1253.     self.weapon = IT_ROCKET_LAUNCHER;
  1254.     self.impulse = 0;
  1255.     W_SetCurrentAmmo ();
  1256. };
  1257.  
  1258. /*
  1259. ============
  1260. CycleWeaponCommand
  1261.  
  1262. Go to the next weapon with ammo
  1263. ============
  1264. */
  1265. void() CycleWeaponCommand =
  1266. {
  1267.     local   float   it, am;
  1268.     
  1269.     it = self.items;
  1270.     self.impulse = 0;
  1271.     
  1272.     while (1)
  1273.     {
  1274.         am = 0;
  1275.  
  1276.         if (self.weapon == IT_LIGHTNING)
  1277.         {
  1278.             self.weapon = IT_AXE;
  1279.         }
  1280.         else if (self.weapon == IT_AXE)
  1281.         {
  1282.             self.weapon = IT_SHOTGUN;
  1283.             if (self.ammo_shells < 1)
  1284.                 am = 1;
  1285.         }
  1286.         else if (self.weapon == IT_SHOTGUN)
  1287.         {
  1288.             self.weapon = IT_SUPER_SHOTGUN;
  1289.             if (self.ammo_shells < 2)
  1290.                 am = 1;
  1291.         }               
  1292.         else if (self.weapon == IT_SUPER_SHOTGUN)
  1293.         {
  1294.             self.weapon = IT_NAILGUN;
  1295.             if (self.ammo_nails < 1)
  1296.                 am = 1;
  1297.         }
  1298.         else if (self.weapon == IT_NAILGUN)
  1299.         {
  1300.             self.weapon = IT_SUPER_NAILGUN;
  1301.             if (self.ammo_nails < 2)
  1302.                 am = 1;
  1303.         }
  1304.         else if (self.weapon == IT_SUPER_NAILGUN)
  1305.         {
  1306.             self.weapon = IT_GRENADE_LAUNCHER;
  1307.             if (self.ammo_rockets < 1)
  1308.                 am = 1;
  1309.         }
  1310.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  1311.         {
  1312.             self.weapon = IT_ROCKET_LAUNCHER;
  1313.             if (self.ammo_rockets < 1)
  1314.                 am = 1;
  1315.         }
  1316.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1317.         {
  1318.             self.weapon = IT_LIGHTNING;
  1319.             if (self.ammo_cells < 1)
  1320.                 am = 1;
  1321.         }
  1322.     
  1323.         if ( (self.items & self.weapon) && am == 0)
  1324.         {
  1325.             W_SetCurrentAmmo ();
  1326.             return;
  1327.         }
  1328.     }
  1329.  
  1330. };
  1331.  
  1332. /*
  1333. ============
  1334. ServerflagsCommand
  1335.  
  1336. Just for development
  1337. ============
  1338. */
  1339. void() ServerflagsCommand =
  1340. {
  1341.     serverflags = serverflags * 2 + 1;
  1342. };
  1343.  
  1344. void() QuadCheat =
  1345. {
  1346.     if (deathmatch || coop)
  1347.         return;
  1348.     self.super_time = 1;
  1349.     self.super_damage_finished = time + 30;
  1350.     self.items = self.items | IT_QUAD;
  1351.     dprint ("quad cheat\n");
  1352. };
  1353.  
  1354. /*
  1355. ============
  1356. ImpulseCommands
  1357.  
  1358. ============
  1359. */
  1360. void() ImpulseCommands =
  1361. {
  1362.     if (self.impulse >= 1 && self.impulse <= 8)
  1363.         W_ChangeWeapon ();
  1364.  
  1365.     if (self.impulse == 9)
  1366.         CheatCommand ();
  1367.     
  1368.     if (self.impulse == 10)
  1369.         CycleWeaponCommand ();
  1370.     if (self.impulse == 11)
  1371.         ServerflagsCommand ();
  1372.  
  1373.         if (self.impulse == 30)
  1374.         W_FireFlare ();
  1375.  
  1376.  
  1377.     if (self.impulse == 255)
  1378.         QuadCheat ();
  1379.         
  1380.     self.impulse = 0;
  1381. };
  1382.  
  1383. /*
  1384. ============
  1385. W_WeaponFrame
  1386.  
  1387. Called every frame so impulse events can be handled as well as possible
  1388. ============
  1389. */
  1390. void() W_WeaponFrame =
  1391. {
  1392.     if (time < self.attack_finished)
  1393.         return;
  1394.  
  1395.     ImpulseCommands ();
  1396.     
  1397. // check for attack
  1398.     if (self.button0)
  1399.     {
  1400.         SuperDamageSound ();
  1401.         W_Attack ();
  1402.     }
  1403. };
  1404.  
  1405. /*
  1406. ========
  1407. SuperDamageSound
  1408.  
  1409. Plays sound if needed
  1410. ========
  1411. */
  1412. void() SuperDamageSound =
  1413. {
  1414.     if (self.super_damage_finished > time)
  1415.     {
  1416.         if (self.super_sound < time)
  1417.         {
  1418.             self.super_sound = time + 1;
  1419.             sound (self, CHAN_BODY, "items/damage3.wav", 1, ATTN_NORM);
  1420.         }
  1421.     }
  1422.     return;
  1423. };
  1424.  
  1425.  
  1426.