home *** CD-ROM | disk | FTP | other *** search
/ Quake 'em / QUAKEEM.BIN / quake / programs / byomv10 / weapons.qc < prev    next >
Encoding:
Text File  |  1996-08-13  |  28.7 KB  |  1,320 lines

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