home *** CD-ROM | disk | FTP | other *** search
/ Quaker's Paradise / Quakers_Paradise.iso / multip / traps / src / weapons.qc
Encoding:
Text File  |  1997-06-20  |  25.9 KB  |  1,274 lines

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