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