home *** CD-ROM | disk | FTP | other *** search
/ Quake 'em / QUAKEEM.BIN / quake / programs / blaste11 / weapons.qc < prev   
Encoding:
Text File  |  1996-07-28  |  28.9 KB  |  1,338 lines

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