mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-11-04 04:56:39 +00:00 
			
		
		
		
	Merge pull request #2328 from akortunov/aifix
Use friendly hits only for player's followers
This commit is contained in:
		
						commit
						571094a3ca
					
				
					 2 changed files with 18 additions and 15 deletions
				
			
		| 
						 | 
					@ -64,6 +64,7 @@
 | 
				
			||||||
    Bug #4972: Player is able to use quickkeys while disableplayerfighting is active
 | 
					    Bug #4972: Player is able to use quickkeys while disableplayerfighting is active
 | 
				
			||||||
    Bug #4979: AiTravel maximum range depends on "actors processing range" setting
 | 
					    Bug #4979: AiTravel maximum range depends on "actors processing range" setting
 | 
				
			||||||
    Bug #4980: Drowning mechanics is applied for actors indifferently from distance to player
 | 
					    Bug #4980: Drowning mechanics is applied for actors indifferently from distance to player
 | 
				
			||||||
 | 
					    Bug #4984: "Friendly hits" feature should be used only for player's followers
 | 
				
			||||||
    Feature #2229: Improve pathfinding AI
 | 
					    Feature #2229: Improve pathfinding AI
 | 
				
			||||||
    Feature #3442: Default values for fallbacks from ini file
 | 
					    Feature #3442: Default values for fallbacks from ini file
 | 
				
			||||||
    Feature #3610: Option to invert X axis
 | 
					    Feature #3610: Option to invert X axis
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1476,14 +1476,15 @@ namespace MWMechanics
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    bool MechanicsManager::actorAttacked(const MWWorld::Ptr &target, const MWWorld::Ptr &attacker)
 | 
					    bool MechanicsManager::actorAttacked(const MWWorld::Ptr &target, const MWWorld::Ptr &attacker)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if (target == getPlayer() || !attacker.getClass().isActor())
 | 
					        const MWWorld::Ptr& player = getPlayer();
 | 
				
			||||||
 | 
					        if (target == player || !attacker.getClass().isActor())
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        MWMechanics::CreatureStats& statsTarget = target.getClass().getCreatureStats(target);
 | 
				
			||||||
 | 
					        if (attacker == player)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
            std::set<MWWorld::Ptr> followersAttacker;
 | 
					            std::set<MWWorld::Ptr> followersAttacker;
 | 
				
			||||||
            getActorsSidingWith(attacker, followersAttacker);
 | 
					            getActorsSidingWith(attacker, followersAttacker);
 | 
				
			||||||
 | 
					 | 
				
			||||||
        MWMechanics::CreatureStats& statsTarget = target.getClass().getCreatureStats(target);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (followersAttacker.find(target) != followersAttacker.end())
 | 
					            if (followersAttacker.find(target) != followersAttacker.end())
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                statsTarget.friendlyHit();
 | 
					                statsTarget.friendlyHit();
 | 
				
			||||||
| 
						 | 
					@ -1494,14 +1495,15 @@ namespace MWMechanics
 | 
				
			||||||
                    return false;
 | 
					                    return false;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (canCommitCrimeAgainst(target, attacker))
 | 
					        if (canCommitCrimeAgainst(target, attacker))
 | 
				
			||||||
            commitCrime(attacker, target, MWBase::MechanicsManager::OT_Assault);
 | 
					            commitCrime(attacker, target, MWBase::MechanicsManager::OT_Assault);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        AiSequence& seq = statsTarget.getAiSequence();
 | 
					        AiSequence& seq = statsTarget.getAiSequence();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!attacker.isEmpty() && (attacker.getClass().getCreatureStats(attacker).getAiSequence().isInCombat(target)
 | 
					        if (!attacker.isEmpty()
 | 
				
			||||||
                                    || attacker == getPlayer())
 | 
					            && (attacker.getClass().getCreatureStats(attacker).getAiSequence().isInCombat(target) || attacker == player)
 | 
				
			||||||
            && !seq.isInCombat(attacker))
 | 
					            && !seq.isInCombat(attacker))
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            // Attacker is in combat with us, but we are not in combat with the attacker yet. Time to fight back.
 | 
					            // Attacker is in combat with us, but we are not in combat with the attacker yet. Time to fight back.
 | 
				
			||||||
| 
						 | 
					@ -1512,7 +1514,7 @@ namespace MWMechanics
 | 
				
			||||||
                // he will attack the player only if we will force him (e.g. via StartCombat console command)
 | 
					                // he will attack the player only if we will force him (e.g. via StartCombat console command)
 | 
				
			||||||
                bool peaceful = false;
 | 
					                bool peaceful = false;
 | 
				
			||||||
                std::string script = target.getClass().getScript(target);
 | 
					                std::string script = target.getClass().getScript(target);
 | 
				
			||||||
                if (!script.empty() && target.getRefData().getLocals().hasVar(script, "onpchitme") && attacker == getPlayer())
 | 
					                if (!script.empty() && target.getRefData().getLocals().hasVar(script, "onpchitme") && attacker == player)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    int fight = std::max(0, target.getClass().getCreatureStats(target).getAiSetting(CreatureStats::AI_Fight).getModified());
 | 
					                    int fight = std::max(0, target.getClass().getCreatureStats(target).getAiSetting(CreatureStats::AI_Fight).getModified());
 | 
				
			||||||
                    peaceful = (fight == 0);
 | 
					                    peaceful = (fight == 0);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue