home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Exec 3 / CD_Magazyn_EXEC_nr_3.iso / Internet / Strony_WWW / Quake / patches / Qboost4_qc.lha / Qboost4_qc / weapons.qc < prev    next >
Text File  |  1999-06-28  |  27KB  |  1,406 lines

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