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