home *** CD-ROM | disk | FTP | other *** search
/ Phenomenon / Phenomenon.iso / quake / quakec / weapons / homstick / src / weapons.qc < prev    next >
Encoding:
Text File  |  1996-08-07  |  29.4 KB  |  1,411 lines

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