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