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