home *** CD-ROM | disk | FTP | other *** search
/ Phenomenon / Phenomenon.iso / quake / teamfort / sources / snip_src / source / weapons.qc < prev   
Encoding:
Text File  |  1996-08-29  |  26.7 KB  |  1,369 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 ("weapons/sniper.wav");    // sniper rifle
  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. W_FireSuperShotgun
  281. ================
  282. */
  283. void() W_FireSuperShotgun =
  284. {
  285.     local vector dir;
  286.  
  287.     if (self.currentammo == 1)
  288.     {
  289.         W_FireShotgun ();
  290.         return;
  291.     }
  292.  
  293.     sound (self ,CHAN_WEAPON, "weapons/shotgn2.wav", 1, ATTN_NORM);
  294.  
  295.     self.punchangle_x = -4;
  296.  
  297.     self.currentammo = self.ammo_shells = self.ammo_shells - 2;
  298.     dir = aim (self, 100000);
  299.     FireBullets (14, dir, '0.14 0.08 0');
  300. };
  301.  
  302.  
  303.  
  304. /*
  305. ================
  306. FireSniperBullet
  307. Used by sniper rifle firing (W_FireSniperRifle)
  308. ================
  309. */
  310. void(vector direction, float damage) FireSniperBullet =
  311. {
  312.     local    vector    src;
  313.  
  314.     makevectors(self.v_angle);
  315.  
  316.     src = self.origin + v_forward*10;
  317.     src_z = self.absmin_z + self.size_z * 0.7;
  318.  
  319.     ClearMultiDamage ();
  320.  
  321.    traceline (src, src + direction*2048, FALSE, self);
  322.     if (trace_fraction != 1.0)
  323.        TraceAttack (damage, direction);
  324.  
  325.     ApplyMultiDamage ();
  326. };
  327.  
  328.  
  329. /*
  330. ================
  331. W_FireSniperRifle
  332. ================
  333. */
  334. void() W_FireSniperRifle =
  335. {
  336.     local vector dir;
  337.  
  338.     sound (self ,CHAN_WEAPON, "weapons/sniper.wav", 1, ATTN_NORM);
  339.  
  340.     self.punchangle_x = -2;
  341.  
  342.     self.currentammo = self.ammo_shells = self.ammo_shells - 1;
  343.     dir = aim (self, 100000);
  344.     FireSniperBullet (dir,200);
  345. };
  346.  
  347. /*
  348. ================
  349. W_FireSniperRifle
  350. ================
  351. */
  352. void() W_FireAutoRifle =
  353. {
  354.     local vector dir;
  355.  
  356.     sound (self ,CHAN_WEAPON, "weapons/sniper.wav", 1, ATTN_NORM);
  357.  
  358.     self.punchangle_x = -2;
  359.  
  360.     self.currentammo = self.ammo_shells = self.ammo_shells - 1;
  361.     dir = aim (self, 100000);
  362.     FireSniperBullet (dir,4);
  363. };
  364.  
  365.  
  366. /*
  367. ==============================================================================
  368.  
  369. ROCKETS
  370.  
  371. ==============================================================================
  372. */
  373.  
  374. void()    s_explode1    =    [0,        s_explode2] {};
  375. void()    s_explode2    =    [1,        s_explode3] {};
  376. void()    s_explode3    =    [2,        s_explode4] {};
  377. void()    s_explode4    =    [3,        s_explode5] {};
  378. void()    s_explode5    =    [4,        s_explode6] {};
  379. void()    s_explode6    =    [5,        SUB_Remove] {};
  380.  
  381. void() BecomeExplosion =
  382. {
  383.     self.movetype = MOVETYPE_NONE;
  384.     self.velocity = '0 0 0';
  385.     self.touch = SUB_Null;
  386.     setmodel (self, "progs/s_explod.spr");
  387.     self.solid = SOLID_NOT;
  388.     s_explode1 ();
  389. };
  390.  
  391. void() T_MissileTouch =
  392. {
  393.     local float    damg;
  394.  
  395.     if (other == self.owner)
  396.         return;        // don't explode on owner
  397.  
  398.     if (pointcontents(self.origin) == CONTENT_SKY)
  399.     {
  400.         remove(self);
  401.         return;
  402.     }
  403.  
  404.     damg = 100 + random()*20;
  405.  
  406.     if (other.health)
  407.     {
  408.         if (other.classname == "monster_shambler")
  409.             damg = damg * 0.5;    // mostly immune
  410.         T_Damage (other, self, self.owner, damg );
  411.     }
  412.  
  413.     // don't do radius damage to the other, because all the damage
  414.     // was done in the impact
  415.     T_RadiusDamage (self, self.owner, 120, other);
  416.  
  417. //    sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
  418.     self.origin = self.origin - 8*normalize(self.velocity);
  419.  
  420.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  421.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  422.     WriteCoord (MSG_BROADCAST, self.origin_x);
  423.     WriteCoord (MSG_BROADCAST, self.origin_y);
  424.     WriteCoord (MSG_BROADCAST, self.origin_z);
  425.  
  426.     BecomeExplosion ();
  427. };
  428.  
  429.  
  430.  
  431. /*
  432. ================
  433. W_FireRocket
  434. ================
  435. */
  436. void() W_FireRocket =
  437. {
  438.     local    entity missile, mpuff;
  439.  
  440.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  441.  
  442.     sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
  443.  
  444.     self.punchangle_x = -2;
  445.  
  446.     missile = spawn ();
  447.     missile.owner = self;
  448.     missile.movetype = MOVETYPE_FLYMISSILE;
  449.     missile.solid = SOLID_BBOX;
  450.  
  451. // set missile speed
  452.  
  453.     makevectors (self.v_angle);
  454.     missile.velocity = aim(self, 1000);
  455.     missile.velocity = missile.velocity * 1000;
  456.     missile.angles = vectoangles(missile.velocity);
  457.  
  458.     missile.touch = T_MissileTouch;
  459.  
  460. // set missile duration
  461.     missile.nextthink = time + 5;
  462.     missile.think = SUB_Remove;
  463.  
  464.     setmodel (missile, "progs/missile.mdl");
  465.     setsize (missile, '0 0 0', '0 0 0');
  466.     setorigin (missile, self.origin + v_forward*8 + '0 0 16');
  467. };
  468.  
  469. /*
  470. ===============================================================================
  471.  
  472. LIGHTNING
  473.  
  474. ===============================================================================
  475. */
  476.  
  477. /*
  478. =================
  479. LightningDamage
  480. =================
  481. */
  482. void(vector p1, vector p2, entity from, float damage) LightningDamage =
  483. {
  484.     local entity        e1, e2;
  485.     local vector        f;
  486.  
  487.     f = p2 - p1;
  488.     normalize (f);
  489.     f_x = 0 - f_y;
  490.     f_y = f_x;
  491.     f_z = 0;
  492.     f = f*16;
  493.  
  494.     e1 = e2 = world;
  495.  
  496.     traceline (p1, p2, FALSE, self);
  497.     if (trace_ent.takedamage)
  498.     {
  499.         particle (trace_endpos, '0 0 100', 225, damage*4);
  500.         T_Damage (trace_ent, from, from, damage);
  501.         if (self.classname == "player")
  502.         {
  503.             if (other.classname == "player")
  504.                 trace_ent.velocity_z = trace_ent.velocity_z + 400;
  505.         }
  506.     }
  507.     e1 = trace_ent;
  508.  
  509.     traceline (p1 + f, p2 + f, FALSE, self);
  510.     if (trace_ent != e1 && trace_ent.takedamage)
  511.     {
  512.         particle (trace_endpos, '0 0 100', 225, damage*4);
  513.         T_Damage (trace_ent, from, from, damage);
  514.     }
  515.     e2 = trace_ent;
  516.  
  517.     traceline (p1 - f, p2 - f, FALSE, self);
  518.     if (trace_ent != e1 && trace_ent != e2 && trace_ent.takedamage)
  519.     {
  520.         particle (trace_endpos, '0 0 100', 225, damage*4);
  521.         T_Damage (trace_ent, from, from, damage);
  522.     }
  523. };
  524.  
  525.  
  526. void() W_FireLightning =
  527. {
  528.     local    vector        org;
  529.  
  530.     if (self.ammo_cells < 1)
  531.     {
  532.         self.weapon = W_BestWeapon ();
  533.         W_SetCurrentAmmo ();
  534.         return;
  535.     }
  536.  
  537. // explode if under water
  538.     if (self.waterlevel > 1)
  539.     {
  540.         T_RadiusDamage (self, self, 35*self.ammo_cells, world);
  541.         self.ammo_cells = 0;
  542.         W_SetCurrentAmmo ();
  543.         return;
  544.     }
  545.  
  546.     if (self.t_width < time)
  547.     {
  548.         sound (self, CHAN_WEAPON, "weapons/lhit.wav", 1, ATTN_NORM);
  549.         self.t_width = time + 0.6;
  550.     }
  551.     self.punchangle_x = -2;
  552.  
  553.     self.currentammo = self.ammo_cells = self.ammo_cells - 1;
  554.  
  555.     org = self.origin + '0 0 16';
  556.     
  557.     traceline (org, org + v_forward*600, TRUE, self);
  558.  
  559.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  560.     WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
  561.     WriteEntity (MSG_BROADCAST, self);
  562.     WriteCoord (MSG_BROADCAST, org_x);
  563.     WriteCoord (MSG_BROADCAST, org_y);
  564.     WriteCoord (MSG_BROADCAST, org_z);
  565.     WriteCoord (MSG_BROADCAST, trace_endpos_x);
  566.     WriteCoord (MSG_BROADCAST, trace_endpos_y);
  567.     WriteCoord (MSG_BROADCAST, trace_endpos_z);
  568.  
  569.     LightningDamage (self.origin, trace_endpos + v_forward*4, self, 30);
  570. };
  571.  
  572.  
  573. //=============================================================================
  574.  
  575.  
  576. void() GrenadeExplode =
  577. {
  578.     T_RadiusDamage (self, self.owner, 120, world);
  579.  
  580.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  581.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  582.     WriteCoord (MSG_BROADCAST, self.origin_x);
  583.     WriteCoord (MSG_BROADCAST, self.origin_y);
  584.     WriteCoord (MSG_BROADCAST, self.origin_z);
  585.  
  586.     BecomeExplosion ();
  587. };
  588.  
  589. void() GrenadeTouch =
  590. {
  591.     if (other == self.owner)
  592.         return;        // don't explode on owner
  593.     if (other.takedamage == DAMAGE_AIM)
  594.     {
  595.         GrenadeExplode();
  596.         return;
  597.     }
  598.     sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);    // bounce sound
  599.     if (self.velocity == '0 0 0')
  600.         self.avelocity = '0 0 0';
  601. };
  602.  
  603. /*
  604. ================
  605. W_FireGrenade
  606. ================
  607. */
  608. void() W_FireGrenade =
  609. {
  610.     local    entity missile, mpuff;
  611.     
  612.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  613.     
  614.     sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  615.  
  616.     self.punchangle_x = -2;
  617.  
  618.     missile = spawn ();
  619.     missile.owner = self;
  620.     missile.movetype = MOVETYPE_BOUNCE;
  621.     missile.solid = SOLID_BBOX;
  622.     missile.classname = "grenade";
  623.         
  624. // set missile speed    
  625.  
  626.     makevectors (self.v_angle);
  627.  
  628.     if (self.v_angle_x)
  629.         missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  630.     else
  631.     {
  632.         missile.velocity = aim(self, 10000);
  633.         missile.velocity = missile.velocity * 600;
  634.         missile.velocity_z = 200;
  635.     }
  636.  
  637.     missile.avelocity = '300 300 300';
  638.  
  639.     missile.angles = vectoangles(missile.velocity);
  640.     
  641.     missile.touch = GrenadeTouch;
  642.     
  643. // set missile duration
  644.     missile.nextthink = time + 2.5;
  645.     missile.think = GrenadeExplode;
  646.  
  647.     setmodel (missile, "progs/grenade.mdl");
  648.     setsize (missile, '0 0 0', '0 0 0');        
  649.     setorigin (missile, self.origin);
  650. };
  651.  
  652.  
  653. //=============================================================================
  654.  
  655. void() spike_touch;
  656. void() superspike_touch;
  657.  
  658.  
  659. /*
  660. ===============
  661. launch_spike
  662.  
  663. Used for both the player and the ogre
  664. ===============
  665. */
  666. void(vector org, vector dir) launch_spike =
  667. {
  668.     newmis = spawn ();
  669.     newmis.owner = self;
  670.     newmis.movetype = MOVETYPE_FLYMISSILE;
  671.     newmis.solid = SOLID_BBOX;
  672.  
  673.     newmis.angles = vectoangles(dir);
  674.     
  675.     newmis.touch = spike_touch;
  676.     newmis.classname = "spike";
  677.     newmis.think = SUB_Remove;
  678.     newmis.nextthink = time + 6;
  679.     setmodel (newmis, "progs/spike.mdl");
  680.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  681.     setorigin (newmis, org);
  682.  
  683.     newmis.velocity = dir * 1000;
  684. };
  685.  
  686. void() W_FireSuperSpikes =
  687. {
  688.     local vector    dir;
  689.     local entity    old;
  690.     
  691.     sound (self, CHAN_WEAPON, "weapons/spike2.wav", 1, ATTN_NORM);
  692.     self.attack_finished = time + 0.2;
  693.     self.currentammo = self.ammo_nails = self.ammo_nails - 2;
  694.     dir = aim (self, 1000);
  695.     launch_spike (self.origin + '0 0 16', dir);
  696.     newmis.touch = superspike_touch;
  697.     setmodel (newmis, "progs/s_spike.mdl");
  698.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  699.     self.punchangle_x = -2;
  700. };
  701.  
  702. void(float ox) W_FireSpikes =
  703. {
  704.     local vector    dir;
  705.     local entity    old;
  706.     
  707.     makevectors (self.v_angle);
  708.     
  709.     if (self.ammo_nails >= 2 && self.weapon == IT_SUPER_NAILGUN)
  710.     {
  711.         W_FireSuperSpikes ();
  712.         return;
  713.     }
  714.  
  715.     if (self.ammo_nails < 1)
  716.     {
  717.         self.weapon = W_BestWeapon ();
  718.         W_SetCurrentAmmo ();
  719.         return;
  720.     }
  721.  
  722.     sound (self, CHAN_WEAPON, "weapons/rocket1i.wav", 1, ATTN_NORM);
  723.     self.attack_finished = time + 0.2;
  724.     self.currentammo = self.ammo_nails = self.ammo_nails - 1;
  725.     dir = aim (self, 1000);
  726.     launch_spike (self.origin + '0 0 16' + v_right*ox, dir);
  727.  
  728.     self.punchangle_x = -2;
  729. };
  730.  
  731.  
  732.  
  733. .float hit_z;
  734. void() spike_touch =
  735. {
  736. local float rand;
  737.     if (other == self.owner)
  738.         return;
  739.  
  740.     if (other.solid == SOLID_TRIGGER)
  741.         return;    // trigger field, do nothing
  742.  
  743.     if (pointcontents(self.origin) == CONTENT_SKY)
  744.     {
  745.         remove(self);
  746.         return;
  747.     }
  748.     
  749. // hit something that bleeds
  750.     if (other.takedamage)
  751.     {
  752.         spawn_touchblood (9);
  753.         T_Damage (other, self, self.owner, 9);
  754.     }
  755.     else
  756.     {
  757.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  758.         
  759.         if (self.classname == "wizspike")
  760.             WriteByte (MSG_BROADCAST, TE_WIZSPIKE);
  761.         else if (self.classname == "knightspike")
  762.             WriteByte (MSG_BROADCAST, TE_KNIGHTSPIKE);
  763.         else
  764.             WriteByte (MSG_BROADCAST, TE_SPIKE);
  765.         WriteCoord (MSG_BROADCAST, self.origin_x);
  766.         WriteCoord (MSG_BROADCAST, self.origin_y);
  767.         WriteCoord (MSG_BROADCAST, self.origin_z);
  768.     }
  769.  
  770.     remove(self);
  771.  
  772. };
  773.  
  774. void() superspike_touch =
  775. {
  776. local float rand;
  777.     if (other == self.owner)
  778.         return;
  779.  
  780.     if (other.solid == SOLID_TRIGGER)
  781.         return;    // trigger field, do nothing
  782.  
  783.     if (pointcontents(self.origin) == CONTENT_SKY)
  784.     {
  785.         remove(self);
  786.         return;
  787.     }
  788.     
  789. // hit something that bleeds
  790.     if (other.takedamage)
  791.     {
  792.         spawn_touchblood (18);
  793.         T_Damage (other, self, self.owner, 18);
  794.     }
  795.     else
  796.     {
  797.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  798.         WriteByte (MSG_BROADCAST, TE_SUPERSPIKE);
  799.         WriteCoord (MSG_BROADCAST, self.origin_x);
  800.         WriteCoord (MSG_BROADCAST, self.origin_y);
  801.         WriteCoord (MSG_BROADCAST, self.origin_z);
  802.     }
  803.  
  804.     remove(self);
  805.  
  806. };
  807.  
  808.  
  809. /*
  810. ===============================================================================
  811.  
  812. PLAYER WEAPON USE
  813.  
  814. ===============================================================================
  815. */
  816.  
  817. void() W_SetCurrentAmmo =
  818. {
  819.     player_run ();        // get out of any weapon firing states
  820.  
  821.     self.items = self.items - ( self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS) );
  822.  
  823.     if (self.weapon == IT_AXE)
  824.     {
  825.         self.currentammo = 0;
  826.         self.weaponmodel = "progs/v_axe.mdl";
  827.         self.weaponframe = 0;
  828.     }
  829.     else if (self.weapon == IT_SHOTGUN)
  830.     {
  831.         self.currentammo = self.ammo_shells;
  832.         self.weaponmodel = "progs/v_shot.mdl";
  833.         self.weaponframe = 0;
  834.         self.items = self.items | IT_SHELLS;
  835.     }
  836.     else if (self.weapon == IT_SUPER_SHOTGUN)
  837.     {
  838.         self.currentammo = self.ammo_shells;
  839.         self.weaponmodel = "progs/v_shot2.mdl";
  840.         self.weaponframe = 0;
  841.         self.items = self.items | IT_SHELLS;
  842.     }
  843.     else if (self.weapon == IT_NAILGUN)
  844.     {
  845.         self.currentammo = self.ammo_nails;
  846.         self.weaponmodel = "progs/v_nail.mdl";
  847.         self.weaponframe = 0;
  848.         self.items = self.items | IT_NAILS;
  849.     }
  850.     else if (self.weapon == IT_SUPER_NAILGUN)
  851.     {
  852.         self.currentammo = self.ammo_nails;
  853.         self.weaponmodel = "progs/v_nail2.mdl";
  854.         self.weaponframe = 0;
  855.         self.items = self.items | IT_NAILS;
  856.     }
  857.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  858.     {
  859.         self.currentammo = self.ammo_rockets;
  860.         self.weaponmodel = "progs/v_rock.mdl";
  861.         self.weaponframe = 0;
  862.         self.items = self.items | IT_ROCKETS;
  863.     }
  864.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  865.     {
  866.         self.currentammo = self.ammo_rockets;
  867.         self.weaponmodel = "progs/v_rock2.mdl";
  868.         self.weaponframe = 0;
  869.         self.items = self.items | IT_ROCKETS;
  870.     }
  871.     else if (self.weapon == IT_LIGHTNING)
  872.     {
  873.         self.currentammo = self.ammo_cells;
  874.         self.weaponmodel = "progs/v_light.mdl";
  875.         self.weaponframe = 0;
  876.         self.items = self.items | IT_CELLS;
  877.     }
  878.    else if (self.weapon == IT_EXTRA_WEAPON)
  879.    {
  880.        if (self.secondary_weapon == NIT_SNIPER_RIFLE)
  881.       {
  882.          self.currentammo = self.ammo_shells;
  883.          self.weaponmodel = "progs/v_shot.mdl";
  884.          self.weaponframe = 0;
  885.             self.items = self.items | IT_SHELLS;
  886.  
  887.          sprint(self,"Sniper rifle ready\n");
  888.       }
  889.       else if (self.secondary_weapon == NIT_AUTO_RIFLE)
  890.       {
  891.          self.currentammo = self.ammo_shells;
  892.          self.weaponmodel = "progs/v_shot.mdl";
  893.          self.weaponframe = 0;
  894.             self.items = self.items | IT_SHELLS;
  895.  
  896.           sprint(self,"Rifle on fully auto\n");
  897.       }
  898.  
  899.  
  900.    }
  901.     else
  902.     {
  903.         self.currentammo = 0;
  904.         self.weaponmodel = "";
  905.         self.weaponframe = 0;
  906.     }
  907. };
  908.  
  909. float() W_BestWeapon =
  910. {
  911.     local    float    it;
  912.  
  913.     it = self.items;
  914.  
  915.     if(self.ammo_cells >= 1 && (it & IT_LIGHTNING) )
  916.         return IT_LIGHTNING;
  917.     else if(self.ammo_nails >= 2 && (it & IT_SUPER_NAILGUN) )
  918.         return IT_SUPER_NAILGUN;
  919.     else if(self.ammo_shells >= 2 && (it & IT_SUPER_SHOTGUN) )
  920.         return IT_SUPER_SHOTGUN;
  921.     else if(self.ammo_nails >= 1 && (it & IT_NAILGUN) )
  922.         return IT_NAILGUN;
  923.     else if(self.ammo_shells >= 1 && (it & IT_SHOTGUN) )
  924.         return IT_SHOTGUN;
  925.  
  926. /*
  927.     if(self.ammo_rockets >= 1 && (it & IT_ROCKET_LAUNCHER) )
  928.         return IT_ROCKET_LAUNCHER;
  929.     else if(self.ammo_rockets >= 1 && (it & IT_GRENADE_LAUNCHER) )
  930.         return IT_GRENADE_LAUNCHER;
  931.  
  932. */
  933.  
  934.     return IT_AXE;
  935. };
  936.  
  937. float() W_CheckNoAmmo =
  938. {
  939.     if (self.currentammo > 0)
  940.         return TRUE;
  941.  
  942.     if (self.weapon == IT_AXE)
  943.         return TRUE;
  944.  
  945.     self.weapon = W_BestWeapon ();
  946.  
  947.     W_SetCurrentAmmo ();
  948.  
  949. // drop the weapon down
  950.     return FALSE;
  951. };
  952.  
  953.  
  954.  
  955. /*
  956. ============
  957. W_Attack
  958.  
  959. An attack impulse can be triggered now
  960. ============
  961. */
  962. void()    player_axe1;
  963. void()    player_axeb1;
  964. void()    player_axec1;
  965. void()    player_axed1;
  966. void()    player_shot1;
  967. void()    player_nail1;
  968. void()    player_light1;
  969. void()    player_rocket1;
  970.  
  971. void()    player_autorifle1;
  972.  
  973. void() W_Attack =
  974. {
  975.     local    float    r;
  976.  
  977.     if (!W_CheckNoAmmo ())
  978.         return;
  979.  
  980.     makevectors    (self.v_angle);            // calculate forward angle for velocity
  981.     self.show_hostile = time + 1;    // wake monsters up
  982.  
  983.     if (self.weapon == IT_AXE)
  984.     {
  985.         sound (self, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM);
  986.         r = random();
  987.         if (r < 0.25)
  988.             player_axe1 ();
  989.         else if (r<0.5)
  990.             player_axeb1 ();
  991.         else if (r<0.75)
  992.             player_axec1 ();
  993.         else
  994.             player_axed1 ();
  995.         self.attack_finished = time + 0.5;
  996.     }
  997.     else if (self.weapon == IT_SHOTGUN)
  998.     {
  999.         player_shot1 ();
  1000.         W_FireShotgun ();
  1001.  
  1002.         self.attack_finished = time + 0.5;
  1003.     }
  1004.     else if (self.weapon == IT_SUPER_SHOTGUN)
  1005.     {
  1006.         player_shot1 ();
  1007.         W_FireSuperShotgun ();
  1008.  
  1009.         self.attack_finished = time + 0.7;
  1010.     }
  1011.     else if (self.weapon == IT_NAILGUN)
  1012.     {
  1013.         player_nail1 ();
  1014.     }
  1015.     else if (self.weapon == IT_SUPER_NAILGUN)
  1016.     {
  1017.         player_nail1 ();
  1018.     }
  1019.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  1020.     {
  1021.         player_rocket1();
  1022.         W_FireGrenade();
  1023.         self.attack_finished = time + 0.6;
  1024.     }
  1025.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  1026.     {
  1027.         player_rocket1();
  1028.         W_FireRocket();
  1029.  
  1030.         self.attack_finished = time + 0.8;
  1031.     }
  1032.  
  1033.     else if (self.weapon == IT_LIGHTNING)
  1034.     {
  1035.         player_light1();
  1036.         self.attack_finished = time + 0.1;
  1037.         sound (self, CHAN_AUTO, "weapons/lstart.wav", 1, ATTN_NORM);
  1038.     }
  1039.    else if (self.weapon == IT_EXTRA_WEAPON)
  1040.         if (self.secondary_weapon == NIT_SNIPER_RIFLE)
  1041.        {
  1042.            // player_sniper1 (); (tbd?)
  1043.           player_shot1 ();
  1044.           W_FireSniperRifle ();
  1045.          self.attack_finished = time + 3.0;
  1046.       }
  1047.       else if (self.secondary_weapon == NIT_AUTO_RIFLE)
  1048.       {
  1049.             // player_sniper1 (); (tbd?)
  1050.           player_autorifle1 ();
  1051.          W_FireAutoRifle ();
  1052.          self.attack_finished = time + 0.1;
  1053.       }
  1054.  
  1055. };
  1056.  
  1057. /*
  1058. ============
  1059. W_ChangeWeapon
  1060.  
  1061. ============
  1062. */
  1063. void() W_ChangeWeapon =
  1064. {
  1065.     local    float    it, am, fl;
  1066.  
  1067.     it = self.items;
  1068.     am = 0;
  1069.  
  1070.     if (self.impulse == 1)
  1071.     {
  1072.         fl = IT_AXE;
  1073.     }
  1074.     else if (self.impulse == 2)
  1075.     {
  1076.         fl = IT_SHOTGUN;
  1077.         if (self.ammo_shells < 1)
  1078.             am = 1;
  1079.     }
  1080.     else if (self.impulse == 3)
  1081.     {
  1082.         fl = IT_SUPER_SHOTGUN;
  1083.         if (self.ammo_shells < 2)
  1084.             am = 1;
  1085.     }
  1086.     else if (self.impulse == 4)
  1087.     {
  1088.         fl = IT_NAILGUN;
  1089.         if (self.ammo_nails < 1)
  1090.             am = 1;
  1091.     }
  1092.     else if (self.impulse == 5)
  1093.     {
  1094.         fl = IT_SUPER_NAILGUN;
  1095.         if (self.ammo_nails < 2)
  1096.             am = 1;
  1097.     }
  1098.     else if (self.impulse == 6)
  1099.     {
  1100.         fl = IT_GRENADE_LAUNCHER;
  1101.         if (self.ammo_rockets < 1)
  1102.             am = 1;
  1103.     }
  1104.     else if (self.impulse == 7)
  1105.     {
  1106.         fl = IT_ROCKET_LAUNCHER;
  1107.         if (self.ammo_rockets < 1)
  1108.             am = 1;
  1109.     }
  1110.     else if (self.impulse == 8)
  1111.     {
  1112.         fl = IT_LIGHTNING;
  1113.         if (self.ammo_cells < 1)
  1114.             am = 1;
  1115.     }
  1116.  
  1117.     self.impulse = 0;
  1118.  
  1119.     if (!(self.items & fl))
  1120.     {    // don't have the weapon or the ammo
  1121.         sprint (self, "no weapon.\n");
  1122.         return;
  1123.     }
  1124.  
  1125.     if (am)
  1126.     {    // don't have the ammo
  1127.         sprint (self, "not enough ammo.\n");
  1128.         return;
  1129.     }
  1130.  
  1131. //
  1132. // set weapon, set ammo
  1133. //
  1134.     self.weapon = fl;
  1135.     W_SetCurrentAmmo ();
  1136. };
  1137.  
  1138. /*
  1139. ============
  1140. CheatCommand
  1141. ============
  1142. */
  1143. void() CheatCommand =
  1144. {
  1145.     if (deathmatch || coop)
  1146.         return;
  1147.  
  1148.     self.ammo_rockets = 100;
  1149.     self.ammo_nails = 200;
  1150.     self.ammo_shells = 100;
  1151.     self.items = self.items |
  1152.         IT_AXE |
  1153.         IT_SHOTGUN |
  1154.         IT_SUPER_SHOTGUN |
  1155.         IT_NAILGUN |
  1156.         IT_SUPER_NAILGUN |
  1157.         IT_GRENADE_LAUNCHER |
  1158.         IT_ROCKET_LAUNCHER |
  1159.         IT_KEY1 | IT_KEY2;
  1160.  
  1161.     self.ammo_cells = 200;
  1162.     self.items = self.items | IT_LIGHTNING;
  1163.  
  1164. //    self.weapon = IT_ROCKET_LAUNCHER;
  1165.     self.impulse = 0;
  1166.  
  1167.    self.items = self.items | IT_EXTRA_WEAPON;
  1168.    self.weapon = IT_EXTRA_WEAPON;
  1169.    self.secondary_items = self.secondary_items | NIT_SNIPER_RIFLE | NIT_AUTO_RIFLE;
  1170.    self.secondary_weapon = NIT_SNIPER_RIFLE;
  1171.  
  1172.     W_SetCurrentAmmo ();
  1173. };
  1174.  
  1175. /*
  1176. ============
  1177. CycleWeaponCommand
  1178.  
  1179. Go to the next weapon with ammo
  1180. ============
  1181. */
  1182. void() CycleWeaponCommand =
  1183. {
  1184.     local    float    it, am;
  1185.  
  1186.     it = self.items;
  1187.     self.impulse = 0;
  1188.  
  1189.     while (1)
  1190.     {
  1191.         am = 0;
  1192.  
  1193.         if (self.weapon == IT_AXE)
  1194.         {
  1195.             self.weapon = IT_SHOTGUN;
  1196.             if (self.ammo_shells < 1)
  1197.                 am = 1;
  1198.         }
  1199.         else if (self.weapon == IT_SHOTGUN)
  1200.         {
  1201.             self.weapon = IT_SUPER_SHOTGUN;
  1202.             if (self.ammo_shells < 2)
  1203.                 am = 1;
  1204.         }
  1205.         else if (self.weapon == IT_SUPER_SHOTGUN)
  1206.         {
  1207.             self.weapon = IT_NAILGUN;
  1208.             if (self.ammo_nails < 1)
  1209.                 am = 1;
  1210.         }
  1211.         else if (self.weapon == IT_NAILGUN)
  1212.         {
  1213.             self.weapon = IT_SUPER_NAILGUN;
  1214.             if (self.ammo_nails < 2)
  1215.                 am = 1;
  1216.         }
  1217.         else if (self.weapon == IT_SUPER_NAILGUN)
  1218.         {
  1219.             self.weapon = IT_GRENADE_LAUNCHER;
  1220.             if (self.ammo_rockets < 1)
  1221.                 am = 1;
  1222.         }
  1223.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  1224.         {
  1225.             self.weapon = IT_ROCKET_LAUNCHER;
  1226.             if (self.ammo_rockets < 1)
  1227.                 am = 1;
  1228.         }
  1229.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1230.         {
  1231.             self.weapon = IT_LIGHTNING;
  1232.             if (self.ammo_cells < 1)
  1233.                 am = 1;
  1234.         }
  1235.       else if (self.weapon == IT_LIGHTNING)
  1236.       {
  1237.           self.weapon = IT_EXTRA_WEAPON;
  1238.          self.secondary_weapon = NIT_SNIPER_RIFLE;
  1239.          if (self.ammo_shells < 1)
  1240.              am = 1;
  1241.       }
  1242.       else if (self.weapon == IT_EXTRA_WEAPON)
  1243.       {
  1244.           if (self.secondary_weapon == NIT_SNIPER_RIFLE)
  1245.          {
  1246.              self.secondary_weapon = NIT_AUTO_RIFLE;
  1247.             if (self.ammo_shells < 1)
  1248.                 am = 1;
  1249.          }
  1250.          else if (self.secondary_weapon == NIT_AUTO_RIFLE)
  1251.          {
  1252.              self.weapon = IT_AXE;
  1253.             self.secondary_weapon = 0;
  1254.          }
  1255.       }
  1256.  
  1257.       // check if player actually has the weapon
  1258.       // if not, loop again
  1259.         if ( (self.items & self.weapon) && am == 0)
  1260.         {
  1261.           if (self.weapon == IT_EXTRA_WEAPON)
  1262.          {
  1263.              if (self.secondary_items & self.secondary_weapon)
  1264.             {
  1265.                 W_SetCurrentAmmo ();
  1266.                return;
  1267.             }
  1268.          }
  1269.          else
  1270.          {
  1271.                 W_SetCurrentAmmo ();
  1272.                 return;
  1273.          }
  1274.         }
  1275.  
  1276.     }
  1277.  
  1278. };
  1279.  
  1280. /*
  1281. ============
  1282. ServerflagsCommand
  1283.  
  1284. Just for development
  1285. ============
  1286. */
  1287. void() ServerflagsCommand =
  1288. {
  1289.     serverflags = serverflags * 2 + 1;
  1290. };
  1291.  
  1292. void() QuadCheat =
  1293. {
  1294.     if (deathmatch || coop)
  1295.         return;
  1296.     self.super_time = 1;
  1297.     self.super_damage_finished = time + 30;
  1298.     self.items = self.items | IT_QUAD;
  1299.     dprint ("quad cheat\n");
  1300. };
  1301.  
  1302. /*
  1303. ============
  1304. ImpulseCommands
  1305.  
  1306. ============
  1307. */
  1308. void() ImpulseCommands =
  1309. {
  1310.     if (self.impulse >= 1 && self.impulse <= 8)
  1311.         W_ChangeWeapon ();
  1312.  
  1313.     if (self.impulse == 9)
  1314.         CheatCommand ();
  1315.     if (self.impulse == 10)
  1316.         CycleWeaponCommand ();
  1317.     if (self.impulse == 11)
  1318.         ServerflagsCommand ();
  1319.  
  1320.     if (self.impulse == 255)
  1321.         QuadCheat ();
  1322.  
  1323.     self.impulse = 0;
  1324. };
  1325.  
  1326. /*
  1327. ============
  1328. W_WeaponFrame
  1329.  
  1330. Called every frame so impulse events can be handled as well as possible
  1331. ============
  1332. */
  1333. void() W_WeaponFrame =
  1334. {
  1335.     if (time < self.attack_finished)
  1336.         return;
  1337.  
  1338.     ImpulseCommands ();
  1339.  
  1340. // check for attack
  1341.     if (self.button0)
  1342.     {
  1343.         SuperDamageSound ();
  1344.         W_Attack ();
  1345.     }
  1346. };
  1347.  
  1348. /*
  1349. ========
  1350. SuperDamageSound
  1351.  
  1352. Plays sound if needed
  1353. ========
  1354. */
  1355. void() SuperDamageSound =
  1356. {
  1357.     if (self.super_damage_finished > time)
  1358.     {
  1359.         if (self.super_sound < time)
  1360.         {
  1361.             self.super_sound = time + 1;
  1362.             sound (self, CHAN_BODY, "items/damage3.wav", 1, ATTN_NORM);
  1363.         }
  1364.     }
  1365.     return;
  1366. };
  1367.  
  1368.  
  1369.