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