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