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