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

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