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