home *** CD-ROM | disk | FTP | other *** search
/ Quake 'em / QUAKEEM.BIN / quake / programs / jteam092 / combat.qc < prev    next >
Encoding:
Text File  |  1996-08-16  |  6.9 KB  |  306 lines

  1.  
  2. void() T_MissileTouch;
  3. void() info_player_start;
  4. void(entity targ, entity attacker) ClientObituary;
  5.  
  6. void() monster_death_use;
  7.  
  8. //============================================================================
  9.  
  10. /*
  11. ============
  12. CanDamage
  13.  
  14. Returns true if the inflictor can directly damage the target.  Used for
  15. explosions and melee attacks.
  16. ============
  17. */
  18. float(entity targ, entity inflictor) CanDamage =
  19. {
  20. // bmodels need special checking because their origin is 0,0,0
  21.     if (targ.movetype == MOVETYPE_PUSH)
  22.     {
  23.         traceline(inflictor.origin, 0.5 * (targ.absmin + targ.absmax), TRUE, self);
  24.         if (trace_fraction == 1)
  25.             return TRUE;
  26.         if (trace_ent == targ)
  27.             return TRUE;
  28.         return FALSE;
  29.     }
  30.     
  31.     traceline(inflictor.origin, targ.origin, TRUE, self);
  32.     if (trace_fraction == 1)
  33.         return TRUE;
  34.     traceline(inflictor.origin, targ.origin + '15 15 0', TRUE, self);
  35.     if (trace_fraction == 1)
  36.         return TRUE;
  37.     traceline(inflictor.origin, targ.origin + '-15 -15 0', TRUE, self);
  38.     if (trace_fraction == 1)
  39.         return TRUE;
  40.     traceline(inflictor.origin, targ.origin + '-15 15 0', TRUE, self);
  41.     if (trace_fraction == 1)
  42.         return TRUE;
  43.     traceline(inflictor.origin, targ.origin + '15 -15 0', TRUE, self);
  44.     if (trace_fraction == 1)
  45.         return TRUE;
  46.  
  47.     return FALSE;
  48. };
  49.  
  50.  
  51. /*
  52. ============
  53. Killed
  54. ============
  55. */
  56. void(entity targ, entity attacker) Killed =
  57. {
  58.     local entity oself;
  59.  
  60.     oself = self;
  61.     self = targ;
  62.     
  63.     if (self.health < -99)
  64.         self.health = -99;        // don't let sbar look bad if a player
  65.  
  66.     if (self.movetype == MOVETYPE_PUSH || self.movetype == MOVETYPE_NONE)
  67.     {    // doors, triggers, etc
  68.         self.th_die ();
  69.         self = oself;
  70.         return;
  71.     }
  72.  
  73.     self.enemy = attacker;
  74.  
  75. // bump the monster counter
  76.     if (self.flags & FL_MONSTER)
  77.     {
  78.         killed_monsters = killed_monsters + 1;
  79.         WriteByte (MSG_ALL, SVC_KILLEDMONSTER);
  80.     }
  81.  
  82.     ClientObituary(self, attacker);
  83.     
  84.     self.takedamage = DAMAGE_NO;
  85.     self.touch = SUB_Null;
  86.  
  87.     monster_death_use();
  88.     self.th_die ();
  89.     
  90.     self = oself;
  91. };
  92.  
  93.  
  94. // *TEAMPLAY*
  95. // Prototypes
  96.  
  97. float(entity targ, entity inflictor, entity attacker, float damage) TeamArmorDam;
  98. float(entity targ, entity inflictor, entity attacker, float damage) TeamHealthDam;
  99.  
  100. /*
  101. ============
  102. T_Damage
  103.  
  104. The damage is coming from inflictor, but get mad at attacker
  105. This should be the only function that ever reduces health.
  106. ============
  107. */
  108. void(entity targ, entity inflictor, entity attacker, float damage) T_Damage=
  109. {
  110.     local    vector    dir;
  111.     local    entity    oldself;
  112.     local    float    save;
  113.     local    float    take;
  114.  
  115.     if (!targ.takedamage)
  116.         return;
  117.  
  118. // used by buttons and triggers to set activator for target firing
  119.     damage_attacker = attacker;
  120.  
  121. // check for quad damage powerup on the attacker
  122.     if (attacker.super_damage_finished > time)
  123.         damage = damage * 4;
  124.  
  125. // save damage based on the target's armor level
  126.  
  127. // *TEAMPLAY*
  128. // TeamArmorDam returns true iff the attacker can damage the target's armor
  129.  
  130.         if (TeamArmorDam(targ, inflictor, attacker, damage))
  131.                 save = ceil(targ.armortype*damage);
  132.         else
  133.                 save = 0;
  134.  
  135.     if (save >= targ.armorvalue)
  136.     {
  137.         save = targ.armorvalue;
  138.         targ.armortype = 0;    // lost all armor
  139.         targ.items = targ.items - (targ.items & (IT_ARMOR1 | IT_ARMOR2 | IT_ARMOR3));
  140.     }
  141.     
  142.     targ.armorvalue = targ.armorvalue - save;
  143.     take = ceil(damage-save);
  144.  
  145. // add to the damage total for clients, which will be sent as a single
  146. // message at the end of the frame
  147. // FIXME: remove after combining shotgun blasts?
  148.     if (targ.flags & FL_CLIENT)
  149.     {
  150.         targ.dmg_take = targ.dmg_take + take;
  151.         targ.dmg_save = targ.dmg_save + save;
  152.         targ.dmg_inflictor = inflictor;
  153.     }
  154.  
  155. // figure momentum add
  156.     if ( (inflictor != world) && (targ.movetype == MOVETYPE_WALK) )
  157.     {
  158.         dir = targ.origin - (inflictor.absmin + inflictor.absmax) * 0.5;
  159.         dir = normalize(dir);
  160.         targ.velocity = targ.velocity + dir*damage*8;
  161.     }
  162.  
  163. // check for godmode or invincibility
  164.     if (targ.flags & FL_GODMODE)
  165.         return;
  166.     if (targ.invincible_finished >= time)
  167.     {
  168.         if (self.invincible_sound < time)
  169.         {
  170.             sound (targ, CHAN_ITEM, "items/protect3.wav", 1, ATTN_NORM);
  171.             self.invincible_sound = time + 2;
  172.         }
  173.         return;
  174.     }
  175.  
  176. // team play damage avoidance
  177.     if ( (teamplay == 1) && (targ.team > 0)&&(targ.team == attacker.team) )
  178.         return;
  179.  
  180. // *TEAMPLAY*
  181. // TeamHealthDam will return true if the attacker can damage the target's
  182. // health
  183.  
  184.         if (!TeamHealthDam(targ, inflictor, attacker, damage))
  185.                 return;
  186.         
  187. // do the damage
  188.     targ.health = targ.health - take;
  189.             
  190.     if (targ.health <= 0)
  191.     {
  192.         Killed (targ, attacker);
  193.         return;
  194.     }
  195.  
  196. // react to the damage
  197.     oldself = self;
  198.     self = targ;
  199.  
  200.     if ( (self.flags & FL_MONSTER) && attacker != world)
  201.     {
  202.     // get mad unless of the same class (except for soldiers)
  203.         if (self != attacker && attacker != self.enemy)
  204.         {
  205.             if ( (self.classname != attacker.classname) 
  206.             || (self.classname == "monster_army" ) )
  207.             {
  208.                 if (self.enemy.classname == "player")
  209.                     self.oldenemy = self.enemy;
  210.                 self.enemy = attacker;
  211.                 FoundTarget ();
  212.             }
  213.         }
  214.     }
  215.  
  216.     if (self.th_pain)
  217.     {
  218.         self.th_pain (attacker, take);
  219.     // nightmare mode monsters don't go into pain frames often
  220.         if (skill == 3)
  221.             self.pain_finished = time + 5;        
  222.     }
  223.  
  224.     self = oldself;
  225. };
  226.  
  227. /*
  228. ============
  229. T_RadiusDamage
  230. ============
  231. */
  232. void(entity inflictor, entity attacker, float damage, entity ignore) T_RadiusDamage =
  233. {
  234.     local    float     points;
  235.     local    entity    head;
  236.     local    vector    org;
  237.  
  238.     head = findradius(inflictor.origin, damage+40);
  239.     
  240.     while (head)
  241.     {
  242.         if (head != ignore)
  243.         {
  244.             if (head.takedamage)
  245.             {
  246.                 org = head.origin + (head.mins + head.maxs)*0.5;
  247.                 points = 0.5*vlen (inflictor.origin - org);
  248.                 if (points < 0)
  249.                     points = 0;
  250.                 points = damage - points;
  251.                 if (head == attacker)
  252.                     points = points * 0.5;
  253.                 if (points > 0)
  254.                 {
  255.                     if (CanDamage (head, inflictor))
  256.                     {    // shambler takes half damage from all explosions
  257.                         if (head.classname == "monster_shambler")                        
  258.                             T_Damage (head, inflictor, attacker, points*0.5);
  259.                         else
  260.                             T_Damage (head, inflictor, attacker, points);
  261.                     }
  262.                 }
  263.             }
  264.         }
  265.         head = head.chain;
  266.     }
  267. };
  268.  
  269. /*
  270. ============
  271. T_BeamDamage
  272. ============
  273. */
  274. void(entity attacker, float damage) T_BeamDamage =
  275. {
  276.     local    float     points;
  277.     local    entity    head;
  278.     
  279.     head = findradius(attacker.origin, damage+40);
  280.     
  281.     while (head)
  282.     {
  283.         if (head.takedamage)
  284.         {
  285.             points = 0.5*vlen (attacker.origin - head.origin);
  286.             if (points < 0)
  287.                 points = 0;
  288.             points = damage - points;
  289.             if (head == attacker)
  290.                 points = points * 0.5;
  291.             if (points > 0)
  292.             {
  293.                 if (CanDamage (head, attacker))
  294.                 {
  295.                     if (head.classname == "monster_shambler")                        
  296.                         T_Damage (head, attacker, attacker, points*0.5);
  297.                     else
  298.                         T_Damage (head, attacker, attacker, points);
  299.                 }
  300.             }
  301.         }
  302.         head = head.chain;
  303.     }
  304. };
  305.  
  306.