home *** CD-ROM | disk | FTP | other *** search
/ Superpower (Alt) / SUPERPOWER.iso / q / patch / mbq707 / weapons.qc < prev    next >
Encoding:
Text File  |  1996-07-28  |  24.9 KB  |  1,231 lines

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