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