[Research] Listen to MobileParty goto point and engage party

Users who are viewing this thread

-Andreas

Recruit
Hi,

I've been trying to find an event to subscribe to whenever a MobileParty is given a new goto order.
This includes the methods:
SetMoveGoToPoint(), SetMoveGoToSettlement(), SetMoveGoAroundParty(), SetMoveEscortParty(), SetMovePatrolAroundPoint(), SetMovePatrolAroundSettlement(), SetMoveRaidSettlement(), SetMoveBesiegeSettlement(), SetMoveDefendSettlement(), SetMoveGoAroundParty(), SetMoveEngageParty() and finally SetMoveModeHold().

The player and Ai logic is seperated, as the player is obviously giving his orders himself by clicking around on the map using a mouse. The Ai on the other hand, gets his next order based on some internal Ai logic. I've traced the goto calls for the player's MobileParty to the class MapScreen.cs from one of the native modules, SandBox. The MapScreen class is implementing the interface IMapStateHandler, that requires the BeforeTick() method. The implemented logic of BeforeTick() determines if some camera animation is playing, and if there's none, HandleMouse() inside MapScreen.cs is invoked. HandleMouse() will be responsible for figuring out what the player has actually clicked on the campaign map. This information is passed to HandleLeftMouseButtonClick(), that orders the player's MobileParty to either engage, goto settlement or point etc. based on the actual parameters passed.

This essentially means there's no events associated with moving MobileParty's around, as far as I can tell. Somewhat of a solution could be to include the Harmony library, and actually inject a bit of code to all of the methods mentioned above. But ... That doesn't provide the actual MobileParty in question, but only that some party were given a new order, not a handle to the party in question.

Does anyone have any suggestion as to listen to all of these methods for both the Ai parties as well as the player's party?
Any comment is appreciated at this point, thanks.
(You must excuse me if this is the wrong place for this. I consider this research, and not an actual modding question so having posted on the 'Modding Q&A board' limits any discussion on the subject)

/Andreas
 
I've been trying to find an event to subscribe to whenever a MobileParty is given a new goto order.
There is no such event. AI decides where to go and what to do in the TaleWorlds.CampaignSystem.SandBox.CampaignBehaviors.AiBehaviors.AiPartyThinkBehavior.PartyHourlyAiTick(MobileParty mobileParty) method.
But you can read current AiBehavior and see where npc is going.
For example
C#:
        private void OnHourlyTickEvent(MobileParty mobileParty)
        {

...

            if (mobileParty.DefaultBehavior == AiBehavior.PatrolAroundPoint)
            {
                Settlement target = mobileParty.TargetSettlement;
                InformationManager.DisplayMessage(new InformationMessage(mobileParty.LeaderHero.Name + " patrolling around " + target.Name));
            }

Also, you can change AI priorities
C#:
        private void OnAiHourlyTickEvent(MobileParty mobileParty, PartyThinkParams thinkParams)
        {
...
            Settlement target = SettlementHelper.FindNearestSettlementToMapPoint(mobileParty, s => s.OwnerClan == Clan.PlayerClan && s.Notables.Any(n => n.GetRelationWithPlayer() < 1));

            AIBehaviorTuple patrol = new AIBehaviorTuple(target, AiBehavior.PatrolAroundPoint, false);
            float weight = 0;
            thinkParams.AIBehaviorScores.TryGetValue(patrol, out weight);
            thinkParams.AIBehaviorScores[patrol] = weight + 0.6f;
        }

I hope it helps.
 
Back
Top Bottom