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