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

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