home *** CD-ROM | disk | FTP | other *** search
/ Quake 'em / QUAKEEM.BIN / quake / programs / homing / weapons.qc < prev    next >
Encoding:
Text File  |  1996-07-27  |  27.7 KB  |  1,364 lines

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