Example #1
0
        public static void M_ReactToDamage(edict_t targ, edict_t attacker)
        {
            if (null != attacker.client && 0 != (attacker.svflags & Defines.SVF_MONSTER))
            {
                return;
            }

            if (attacker == targ || attacker == targ.enemy)
            {
                return;
            }

            // if we are a good guy monster and our attacker is a player
            // or another good guy, do not get mad at them
            if (0 != (targ.monsterinfo.aiflags & Defines.AI_GOOD_GUY))
            {
                if (attacker.client != null || (attacker.monsterinfo.aiflags & Defines.AI_GOOD_GUY) != 0)
                {
                    return;
                }
            }

            // we now know that we are not both good guys

            // if attacker is a client, get mad at them because he's good and we're
            // not
            if (attacker.client != null)
            {
                targ.monsterinfo.aiflags &= ~Defines.AI_SOUND_TARGET;

                // this can only happen in coop (both new and old enemies are
                // clients)
                // only switch if can't see the current enemy
                if (targ.enemy != null && targ.enemy.client != null)
                {
                    if (GameUtil.visible(targ, targ.enemy))
                    {
                        targ.oldenemy = attacker;

                        return;
                    }

                    targ.oldenemy = targ.enemy;
                }

                targ.enemy = attacker;

                if (0 == (targ.monsterinfo.aiflags & Defines.AI_DUCKED))
                {
                    GameUtil.FoundTarget(targ);
                }

                return;
            }

            // it's the same base (walk/swim/fly) type and a different classname and
            // it's not a tank
            // (they spray too much), get mad at them
            if ((targ.flags & (Defines.FL_FLY | Defines.FL_SWIM)) == (attacker.flags & (Defines.FL_FLY | Defines.FL_SWIM)) &&
                !targ.classname.Equals(attacker.classname) &&
                !attacker.classname.Equals("monster_tank") &&
                !attacker.classname.Equals("monster_supertank") &&
                !attacker.classname.Equals("monster_makron") &&
                !attacker.classname.Equals("monster_jorg"))
            {
                if (targ.enemy != null && targ.enemy.client != null)
                {
                    targ.oldenemy = targ.enemy;
                }

                targ.enemy = attacker;

                if (0 == (targ.monsterinfo.aiflags & Defines.AI_DUCKED))
                {
                    GameUtil.FoundTarget(targ);
                }
            }

            // if they *meant* to shoot us, then shoot back
            else if (attacker.enemy == targ)
            {
                if (targ.enemy != null && targ.enemy.client != null)
                {
                    targ.oldenemy = targ.enemy;
                }

                targ.enemy = attacker;

                if (0 == (targ.monsterinfo.aiflags & Defines.AI_DUCKED))
                {
                    GameUtil.FoundTarget(targ);
                }
            }

            // otherwise get mad at whoever they are mad at (help our buddy) unless
            // it is us!
            else if (attacker.enemy != null && attacker.enemy != targ)
            {
                if (targ.enemy != null && targ.enemy.client != null)
                {
                    targ.oldenemy = targ.enemy;
                }

                targ.enemy = attacker.enemy;

                if (0 == (targ.monsterinfo.aiflags & Defines.AI_DUCKED))
                {
                    GameUtil.FoundTarget(targ);
                }
            }
        }