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