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