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