public virtual void TeleportUserAgentsToMachine(List <Agent> agentList) { int num1 = 0; bool flag; do { ++num1; flag = false; foreach (Agent agent in agentList) { if (agent.AIMoveToGameObjectIsEnabled()) { flag = true; WorldFrame userFrameForAgent = this.UsableMachine.GetTargetStandingPointOfAIAgent(agent).GetUserFrameForAgent(agent); userFrameForAgent.Rotation.f.z = 0.0f; double num2 = (double)userFrameForAgent.Rotation.f.Normalize(); if ((double)(agent.Position.AsVec2 - userFrameForAgent.Origin.AsVec2).LengthSquared > 9.99999974737875E-05 || (double)(agent.GetMovementDirection() - userFrameForAgent.Rotation.f).LengthSquared > 9.99999974737875E-05) { agent.TeleportToPosition(userFrameForAgent.Origin.GetGroundVec3()); agent.SetMovementDirection(ref userFrameForAgent.Rotation.f); if (GameNetwork.IsServerOrRecorder) { GameNetwork.BeginBroadcastModuleEvent(); GameNetwork.WriteMessage((GameNetworkMessage) new AgentTeleportToFrame(agent, userFrameForAgent.Origin.GetGroundVec3(), userFrameForAgent.Rotation.f.AsVec2)); GameNetwork.EndBroadcastModuleEvent(GameNetwork.EventBroadcastFlags.AddToMissionRecord); } } } } }while (flag && num1 < 10); }
private void ResetOrderPositions() { this._behaviourState = BehaviorRetakeCastleKeyPosition.BehaviourState.UnSet; this._gatheringSide = this.DetermineGatheringSide(); SiegeLane siegeLane = TeamAISiegeComponent.SiegeLanes.FirstOrDefault <SiegeLane>((Func <SiegeLane, bool>)(sl => sl.LaneSide == this._gatheringSide)); WorldFrame defenseWaitFrame = siegeLane.DefensePoints.FirstOrDefault <ICastleKeyPosition>().DefenseWaitFrame; this._gatheringTacticalPos = siegeLane.DefensePoints.FirstOrDefault <ICastleKeyPosition>().WaitPosition; if (this._gatheringTacticalPos != null) { this._gatherOrder = MovementOrder.MovementOrderMove(this._gatheringTacticalPos.Position); this._gatheringFacingOrder = FacingOrder.FacingOrderLookAtEnemy; } else if (defenseWaitFrame.Origin.IsValid) { double num = (double)defenseWaitFrame.Rotation.f.Normalize(); this._gatherOrder = MovementOrder.MovementOrderMove(defenseWaitFrame.Origin); this._gatheringFacingOrder = FacingOrder.FacingOrderLookAtEnemy; } else { this._gatherOrder = MovementOrder.MovementOrderMove(this.formation.QuerySystem.MedianPosition); this._gatheringFacingOrder = FacingOrder.FacingOrderLookAtEnemy; } this._attackOrder = MovementOrder.MovementOrderMove(TeamAISiegeComponent.SiegeLanes.FirstOrDefault <SiegeLane>((Func <SiegeLane, bool>)(sl => sl.LaneSide == this.behaviorSide)).DefensePoints.FirstOrDefault <ICastleKeyPosition>().MiddleFrame.Origin); this._attackFacingOrder = FacingOrder.FacingOrderLookAtEnemy; this.CurrentOrder = this._behaviourState == BehaviorRetakeCastleKeyPosition.BehaviourState.Attacking ? this._attackOrder : this._gatherOrder; this.CurrentFacingOrder = this._behaviourState == BehaviorRetakeCastleKeyPosition.BehaviourState.Attacking ? this._attackFacingOrder : this._gatheringFacingOrder; }
private (float flankWidth, float flankDepth) PlanFlankDeployment( FormationDeploymentFlank flankFlank, Vec2 deployPosition, Vec2 deployDirection, float verticalOffset = 0.0f, float horizontalOffset = 0.0f, bool isReinforcement = false) { Mat3 identity = Mat3.Identity; identity.RotateAboutUp(deployDirection.RotationInRadians); float val1 = 0.0f; float num1 = 0.0f; Vec2 vec2_1 = deployDirection.LeftVec(); foreach (KeyValuePair <FormationDeploymentOrder, FormationDeploymentPlan> keyValuePair in this._deploymentFlanks[(int)flankFlank]) { FormationDeploymentPlan formationDeploymentPlan = keyValuePair.Value; Vec2 vec2_2 = deployPosition - (num1 + verticalOffset) * deployDirection + horizontalOffset * vec2_1; WorldPosition origin = new WorldPosition(Mission.Current.Scene, UIntPtr.Zero, vec2_2.ToVec3(), false); IntPtr navMesh = (IntPtr)origin.GetNavMesh(); WorldFrame worldFrame = new WorldFrame(identity, origin); formationDeploymentPlan.SetFrame(new WorldFrame?(worldFrame), isReinforcement); float num2 = formationDeploymentPlan.PlannedDepth + 3f; num1 += num2; val1 = Math.Max(val1, formationDeploymentPlan.PlannedWidth); } float num3 = Math.Max(num1 - 3f, 0.0f); return(val1, num3); }
public override void AfterStart() { base.AfterStart(); WorldFrame spawnPathFrame = this.Mission.GetSpawnPathFrame(BattleSideEnum.Defender, (int)((double)this._unitCount * 1.5)); this._entity = GameEntity.Instantiate(Mission.Current.Scene, this._isCaravan ? "caravan_scattered_goods_prop" : "villager_scattered_goods_prop", new MatrixFrame(spawnPathFrame.Rotation, spawnPathFrame.Origin.GetGroundVec3())); this._entity.SetMobility(GameEntity.Mobility.dynamic); foreach (GameEntity child in this._entity.GetChildren()) { float height; Vec3 normal; Mission.Current.Scene.GetTerrainHeightAndNormal(child.GlobalPosition.AsVec2, out height, out normal); MatrixFrame globalFrame = child.GetGlobalFrame(); globalFrame.origin.z = height; globalFrame.rotation.u = normal; globalFrame.rotation.Orthonormalize(); child.SetGlobalFrame(globalFrame); } IEnumerable <GameEntity> source = this._entity.GetChildren().Where <GameEntity>((Func <GameEntity, bool>)(c => c.HasTag("caravan_animal_spawn"))); int num = (int)((double)source.Count <GameEntity>() * 0.400000005960464); foreach (GameEntity gameEntity in source) { MatrixFrame globalFrame = gameEntity.GetGlobalFrame(); ItemRosterElement harnessRosterElement = new ItemRosterElement(Game.Current.ObjectManager.GetObject <ItemObject>(!this._isCamelCulture ? (num <= 0 ? this._muleLoadHarnesses[MBRandom.RandomInt(((IEnumerable <string>) this._muleLoadHarnesses).Count <string>())] : this._muleMountableHarnesses[MBRandom.RandomInt(((IEnumerable <string>) this._muleMountableHarnesses).Count <string>())]) : (num <= 0 ? this._camelLoadHarnesses[MBRandom.RandomInt(((IEnumerable <string>) this._camelLoadHarnesses).Count <string>())] : this._camelMountableHarnesses[MBRandom.RandomInt(((IEnumerable <string>) this._camelMountableHarnesses).Count <string>())]))); Agent agent = Mission.Current.SpawnMonster(this._isCamelCulture ? (num-- > 0 ? new ItemRosterElement(Game.Current.ObjectManager.GetObject <ItemObject>("pack_camel")) : new ItemRosterElement(Game.Current.ObjectManager.GetObject <ItemObject>("pack_camel_unmountable"))) : (num-- > 0 ? new ItemRosterElement(Game.Current.ObjectManager.GetObject <ItemObject>("mule")) : new ItemRosterElement(Game.Current.ObjectManager.GetObject <ItemObject>("mule_unmountable"))), harnessRosterElement, globalFrame); agent.SetAgentFlags(agent.GetAgentFlags() & ~AgentFlag.CanWander); } }
private void ResetOrderPositions() { this.behaviorSide = this.DetermineGatheringSide(); SiegeLane siegeLane = TeamAISiegeComponent.SiegeLanes.FirstOrDefault <SiegeLane>((Func <SiegeLane, bool>)(sl => sl.LaneSide == this.behaviorSide)); WorldFrame worldFrame = siegeLane == null ? WorldFrame.Invalid : siegeLane.DefensePoints.FirstOrDefault <ICastleKeyPosition>().DefenseWaitFrame; this._gatheringTacticalPos = siegeLane != null?siegeLane.DefensePoints.FirstOrDefault <ICastleKeyPosition>().WaitPosition : (TacticalPosition)null; if (this._gatheringTacticalPos != null) { this._gatherOrder = MovementOrder.MovementOrderMove(this._gatheringTacticalPos.Position); this._gatheringFacingOrder = FacingOrder.FacingOrderLookAtEnemy; } else if (worldFrame.Origin.IsValid) { double num = (double)worldFrame.Rotation.f.Normalize(); this._gatherOrder = MovementOrder.MovementOrderMove(worldFrame.Origin); this._gatheringFacingOrder = FacingOrder.FacingOrderLookAtEnemy; } else { this._gatherOrder = MovementOrder.MovementOrderMove(this.formation.QuerySystem.MedianPosition); this._gatheringFacingOrder = FacingOrder.FacingOrderLookAtEnemy; } this._attackOrder = MovementOrder.MovementOrderChargeToTarget(this._targetEnemyFormation); this._attackFacingOrder = FacingOrder.FacingOrderLookAtEnemy; this.CurrentOrder = this._behaviourState == BehaviorEliminateEnemyInsideCastle.BehaviourState.Attacking ? this._attackOrder : this._gatherOrder; this.CurrentFacingOrder = this._behaviourState == BehaviorEliminateEnemyInsideCastle.BehaviourState.Attacking ? this._attackFacingOrder : this._gatheringFacingOrder; }
static void Postfix(ref SpawnedItemEntity ____itemToPickUp, ref Agent ___Agent) { if (____itemToPickUp != null && (___Agent.AIStateFlags & Agent.AIStateFlag.UseObjectMoving) != 0) { float num = MissionGameModels.Current.AgentStatCalculateModel.GetInteractionDistance(___Agent) * 3f; WorldFrame userFrameForAgent = ____itemToPickUp.GetUserFrameForAgent(___Agent); ref WorldPosition origin = ref userFrameForAgent.Origin; Vec3 targetPoint = ___Agent.Position; float distanceSq = origin.DistanceSquaredWithLimit(in targetPoint, num * num + 1E-05f); float newDist = -1f; itemPickupDistanceStorage.TryGetValue(___Agent, out newDist); if (newDist == 0f) { itemPickupDistanceStorage[___Agent] = distanceSq; } else { if (distanceSq == newDist) { ___Agent.StopUsingGameObject(isSuccessful: false); itemPickupDistanceStorage.Remove(___Agent); } itemPickupDistanceStorage[___Agent] = distanceSq; } }
protected virtual void CreatePlayer() { this.game.PlayerTroop = Game.Current.ObjectManager.GetObject <BasicCharacterObject>("main_hero"); WorldFrame formationSpawnFrame = this.Mission.GetFormationSpawnFrame(this.Mission.PlayerTeam.Side, this.game.PlayerTroop.DefaultFormationClass, false); Agent agent = this.Mission.SpawnAgent(new AgentBuildData(this.game.PlayerTroop).Team(this.Mission.PlayerTeam).InitialFrame(formationSpawnFrame.ToGroundMatrixFrame()).Controller(Agent.ControllerType.Player)); agent.WieldInitialWeapons(); this.Mission.MainAgent = agent; }
public AttackEntityOrderDetachment(GameEntity targetEntity) { this._targetEntity = targetEntity; this._targetEntityDestructableComponent = this._targetEntity.GetFirstScriptOfType <DestructableComponent>(); this._surroundEntity = this._targetEntity.GetFirstScriptOfType <CastleGate>() == null; this._agents = new List <Agent>(); MatrixFrame globalFrame = this._targetEntity.GetGlobalFrame(); this._frame = new WorldFrame(globalFrame.rotation, new WorldPosition(Mission.Current.Scene, UIntPtr.Zero, globalFrame.origin, false)); this._frame.Rotation.Orthonormalize(); }
public void MoveToUsableGameObject( UsableMissionObject usedObject, Agent.AIScriptedFrameFlags scriptedFrameFlags = Agent.AIScriptedFrameFlags.NoAttack) { this.Agent.AIStateFlags |= Agent.AIStateFlag.UseObjectMoving; this.CurrentlyMovingGameObject = usedObject; usedObject.OnAIMoveToUse(this.Agent); WorldFrame userFrameForAgent = usedObject.GetUserFrameForAgent(this.Agent); this.Agent.SetScriptedPositionAndDirection(ref userFrameForAgent.Origin, userFrameForAgent.Rotation.f.AsVec2.RotationInRadians, false, scriptedFrameFlags); }
public override void OnUse(Agent userAgent) { base.OnUse(userAgent); if (this.LockUserFrames) { WorldFrame userFrameForAgent = this.GetUserFrameForAgent(userAgent); userAgent.SetTargetPositionAndDirection(userFrameForAgent.Origin.AsVec2, userFrameForAgent.Rotation.f); } else { if (!this.LockUserPositions) { return; } userAgent.SetTargetPosition(this.GetUserFrameForAgent(userAgent).Origin.AsVec2); } }
protected virtual void CreateTroop( string troopName, Team troopTeam, int troopCount, bool isReinforcement = false) { BasicCharacterObject characterObject = Game.Current.ObjectManager.GetObject <BasicCharacterObject>(troopName); FormationClass defaultFormationClass = characterObject.DefaultFormationClass; Formation formation = troopTeam.GetFormation(defaultFormationClass); WorldFrame formationSpawnFrame = this.Mission.GetFormationSpawnFrame(troopTeam.Side, defaultFormationClass, isReinforcement); formation.SetPositioning(new WorldPosition?(formationSpawnFrame.Origin), new Vec2?(formationSpawnFrame.Rotation.f.AsVec2)); for (int formationTroopIndex = 0; formationTroopIndex < troopCount; ++formationTroopIndex) { Agent agent = this.Mission.SpawnAgent(new AgentBuildData(characterObject).Team(troopTeam).Formation(formation).FormationTroopCount(troopCount).FormationTroopIndex(formationTroopIndex).ClothingColor1(5398358U)); agent.SetWatchState(AgentAIStateFlagComponent.WatchState.Alarmed); agent.SetAlwaysAttackInMelee(true); this.IncrementDeploymedTroops(troopTeam.Side); } }
private static StrategicArea CreateStrategicArea( Scene scene, WorldPosition position, Vec2 direction, float width, int capacity, BattleSideEnum side) { WorldFrame worldFrame = new WorldFrame(new Mat3() { f = direction.ToVec3(), u = Vec3.Up }, position); GameEntity gameEntity = GameEntity.Instantiate(scene, "strategic_area_autogen", worldFrame.ToNavMeshMatrixFrame()); gameEntity.SetMobility(GameEntity.Mobility.dynamic); StrategicArea firstScriptOfType = gameEntity.GetFirstScriptOfType <StrategicArea>(); firstScriptOfType.InitializeAutogenerated(width, capacity, side); return(firstScriptOfType); }
private void SpawnAgents() { GameEntity gameEntity = Mission.Current.Scene.FindEntityWithTag("attacker_infantry"); foreach (Hero hero in this._needSpawnHeros) { WorldFrame spawnPosition = WorldFrame.Invalid; spawnPosition = new WorldFrame(gameEntity.GetGlobalFrame().rotation, new WorldPosition(gameEntity.Scene, gameEntity.GetGlobalFrame().origin)); SimpleAgentOrigin agentOrigin = new SimpleAgentOrigin(hero.CharacterObject, -1, null, default(UniqueTroopDescriptor)); bool spawnWithHorse = true; Agent agent = Mission.Current.SpawnTroop(agentOrigin, true, false, spawnWithHorse, false, false, 0, 0, true, false, false, null, spawnPosition.ToGroundMatrixFrame()); agent.UpdateSpawnEquipmentAndRefreshVisuals(hero.CivilianEquipment); if (!agent.IsMainAgent) { SimulateAgent(agent); } // agent.SetGuardedAgent(Agent.Main); // Agent.Main } }
private void ResetOrderPositions() { SiegeLane siegeLane = TeamAISiegeComponent.SiegeLanes.FirstOrDefault <SiegeLane>((Func <SiegeLane, bool>)(sl => sl.LaneSide == FormationAI.BehaviorSide.Middle)); WorldFrame worldFrame = (siegeLane != null ? siegeLane.DefensePoints.FirstOrDefault <ICastleKeyPosition>()?.DefenseWaitFrame : new WorldFrame?()) ?? WorldFrame.Invalid; this._gatheringTacticalPos = siegeLane != null?siegeLane.DefensePoints.FirstOrDefault <ICastleKeyPosition>()?.WaitPosition : (TacticalPosition)null; if (this._gatheringTacticalPos != null) { this._gatherOrder = MovementOrder.MovementOrderMove(this._gatheringTacticalPos.Position); } else if (worldFrame.Origin.IsValid) { double num = (double)worldFrame.Rotation.f.Normalize(); this._gatherOrder = MovementOrder.MovementOrderMove(worldFrame.Origin); } else { this._gatherOrder = MovementOrder.MovementOrderMove(this.formation.QuerySystem.MedianPosition); } this._attackOrder = MovementOrder.MovementOrderCharge; this.CurrentOrder = this._calculateShouldStartAttacking ? this._attackOrder : this._gatherOrder; }
public override WorldFrame GetUserFrameForAgent(Agent agent) { if (!this.HasUser && agent.IsAIControlled && (this.MovingAgents.ContainsKey(agent) && this.MovingAgents[agent].CurrentWaypoint < this.WaypointEntities.Count) && !Mission.Current.IsTeleportingAgents) { return(this.WaypointEntities[this.MovingAgents[agent].CurrentWaypoint].WorldFrame); } if (!Mission.Current.IsTeleportingAgents && !this.TranslateUser) { return(agent.GetWorldFrame()); } if (!Mission.Current.IsTeleportingAgents && (this.LockUserFrames || this.LockUserPositions)) { return(base.GetUserFrameForAgent(agent)); } WorldFrame userFrameForAgent = base.GetUserFrameForAgent(agent); MatrixFrame lookFrame = agent.LookFrame; Vec2 vec2_1 = (lookFrame.origin.AsVec2 - userFrameForAgent.Origin.AsVec2).Normalized(); Vec2 vec2_2 = userFrameForAgent.Origin.AsVec2 + agent.GetInteractionDistanceToUsable((IUsable)this) * 0.5f * vec2_1; Mat3 rotation = lookFrame.rotation; userFrameForAgent.Origin.SetVec2(vec2_2); userFrameForAgent.Rotation = rotation; return(userFrameForAgent); }
private void TeleportAgentToPlayer(Agent agentToTeleport, bool spawnOpposite) { var referenceAgent = Agent.Main; Vec3 vec3_2 = referenceAgent.Position + referenceAgent.LookDirection.NormalizedCopy() * 4f; Vec3 vec3_3; if (spawnOpposite) { vec3_3 = vec3_2; vec3_3.z = base.Mission.Scene.GetGroundHeightAtPosition(vec3_3, BodyFlags.CommonCollisionExcludeFlags, true); } else { vec3_3 = Mission.Current.GetRandomPositionAroundPoint(referenceAgent.Position, 2f, 4f, true); vec3_3.z = base.Mission.Scene.GetGroundHeightAtPosition(vec3_3, BodyFlags.CommonCollisionExcludeFlags, true); } WorldFrame worldFrame = new WorldFrame(referenceAgent.Frame.rotation, new WorldPosition(base.Mission.Scene, referenceAgent.Frame.origin)); Vec3 vec3_4 = new Vec3(worldFrame.Origin.AsVec2 - vec3_3.AsVec2, 0f, -1f); agentToTeleport.LookDirection = vec3_4.NormalizedCopy(); agentToTeleport.TeleportToPosition(vec3_3); }
public static void Prefix(ref WorldFrame __result, ref Mission __instance, BattleSideEnum side, FormationClass formationClass, bool isReinforcement, int customAgentCount = -1, float offsetAwayFrom = 0f, bool isSpawningWithHorses = true) { int _usedSpawnPathIndex = (int)ReflectUtils.ReflectField("_usedSpawnPathIndex", __instance); //int _spawnPoints = (int)ReflectUtils.ReflectField("_spawnPoints", __instance); int _agentCount = (int)ReflectUtils.ReflectField("_agentCount", __instance); Path _usedSpawnPath = (Path)ReflectUtils.ReflectField("_usedSpawnPath", __instance); float _randomMiddlePointAddition = (float)ReflectUtils.ReflectField("_randomMiddlePointAddition", __instance); MatrixFrame[] _spawnPoints = (MatrixFrame[])ReflectUtils.ReflectField("_spawnPoints", __instance); int num; if (customAgentCount != -1) { num = customAgentCount; } else { num = _agentCount; } if (_usedSpawnPathIndex < 0) { int num2 = 0; int num3; do { num3 = ((num2 <= 20) ? (MBRandom.RandomInt(3) + 1) : ((num2 - 20) % 3 + 1)); _usedSpawnPath = __instance.Scene.GetPathWithName("spawn_path_0" + num3); num2++; }while (_usedSpawnPath == null && num2 < 24); _usedSpawnPathIndex = num3; _randomMiddlePointAddition = -0.13f + MBRandom.RandomFloat * 0.26f; } else { _usedSpawnPath = __instance.Scene.GetPathWithName("spawn_path_0" + _usedSpawnPathIndex); } if (_usedSpawnPath != null) { _usedSpawnPath.GetPoints(_spawnPoints); float totalLength = _usedSpawnPath.GetTotalLength(); float num4 = 800f / totalLength; float num5 = 0.5f + _randomMiddlePointAddition; float num6 = -1f; if (num > 0) { num6 = 0.04f + 0.08f * (float)Math.Pow((double)(num + (isReinforcement ? 25 : 0)), 0.40000000596046448); num6 *= num4; } num6 = MBMath.ClampFloat(num6, 0.15f, 1f); float num7 = 0f; if (formationClass >= FormationClass.Ranged) { Formation formation = ((side == BattleSideEnum.Attacker) ? __instance.Teams.Attacker : __instance.Teams.Defender).GetFormation(FormationClass.Infantry); num7 += formation.Depth; } if (formationClass >= FormationClass.Cavalry) { Formation formation = ((side == BattleSideEnum.Attacker) ? __instance.Teams.Attacker : __instance.Teams.Defender).GetFormation(FormationClass.Ranged); num7 += formation.Depth; } if (!isSpawningWithHorses && formationClass >= FormationClass.HorseArcher) { Formation formation = ((side == BattleSideEnum.Attacker) ? __instance.Teams.Attacker : __instance.Teams.Defender).GetFormation(FormationClass.Cavalry); num7 += formation.Depth; } float num8 = Math.Max(0f, num5 - 0.44f * num6); float num9 = Math.Min(1f, num5 + 0.44f * num6); MatrixFrame frameForDistance = _usedSpawnPath.GetFrameForDistance(totalLength * num8 - offsetAwayFrom - num7); MatrixFrame frameForDistance2 = _usedSpawnPath.GetFrameForDistance(totalLength * num9 + offsetAwayFrom + num7); MatrixFrame matrixFrame = (side == BattleSideEnum.Attacker) ? frameForDistance2 : frameForDistance; Vec2 v = ((side == BattleSideEnum.Defender) ? frameForDistance2 : frameForDistance).origin.AsVec2 - matrixFrame.origin.AsVec2; v.Normalize(); Mat3 identity = Mat3.Identity; identity.RotateAboutUp(v.RotationInRadians); WorldPosition worldPosition = new WorldPosition(__instance.Scene, UIntPtr.Zero, matrixFrame.origin, false); if (formationClass == FormationClass.NumberOfRegularFormations) { worldPosition.SetVec2(worldPosition.AsVec2 - v * 12f); } if (isSpawningWithHorses && (formationClass == FormationClass.Cavalry || formationClass == FormationClass.HorseArcher)) { WorldPosition worldPosition2 = worldPosition; float num10 = ((side == BattleSideEnum.Attacker) ? __instance.Teams.Attacker : __instance.Teams.Defender).GetFormation(FormationClass.Cavalry).Width * 0.5f; float num11 = Math.Max(((side == BattleSideEnum.Attacker) ? __instance.Teams.Attacker : __instance.Teams.Defender).GetFormation(FormationClass.Infantry).Width, ((side == BattleSideEnum.Attacker) ? __instance.Teams.Attacker : __instance.Teams.Defender).GetFormation(FormationClass.Ranged).Width) * 0.5f; worldPosition2.SetVec2(worldPosition.AsVec2 + ((formationClass == FormationClass.Cavalry) ? v.LeftVec() : v.RightVec()) * (num10 + num11)); if (worldPosition2.GetNavMesh() != UIntPtr.Zero) { worldPosition.SetVec2(worldPosition2.AsVec2); } } __result = new WorldFrame(identity, worldPosition); } if (__instance.IsFieldBattle) { GameEntity gameEntity = __instance.Scene.FindEntityWithTag("defender_" + ((formationClass != FormationClass.NumberOfRegularFormations) ? formationClass.GetName().ToLower() : "infantry")); GameEntity gameEntity2 = __instance.Scene.FindEntityWithTag("attacker_" + ((formationClass != FormationClass.NumberOfRegularFormations) ? formationClass.GetName().ToLower() : "infantry")); if (gameEntity != null && gameEntity2 != null) { Vec3 globalPosition = gameEntity.GlobalPosition; Vec3 v2 = gameEntity2.GlobalPosition - globalPosition; Vec3 arg_4E7_0 = globalPosition; float num12 = v2.Normalize(); float num13 = 1000f / num12; float num14 = 0.08f + 0.08f * (float)Math.Pow((double)(num + (isReinforcement ? 25 : 0)), 0.30000001192092896); num14 *= num13; float num15 = Math.Max(0f, 0.5f - 0.5f * num14); float num16 = Math.Min(1f, 0.5f + 0.5f * num14); Vec3 vec = arg_4E7_0 + v2 * (num12 * num15); Vec3 vec2 = arg_4E7_0 + v2 * (num12 * num16); Vec3 vec3 = (side == BattleSideEnum.Attacker) ? vec2 : vec; Vec3 vec4 = ((side == BattleSideEnum.Defender) ? vec2 : vec) - vec3; vec4.Normalize(); Mat3 identity2 = Mat3.Identity; identity2.RotateAboutUp(vec4.AsVec2.RotationInRadians); WorldPosition origin = new WorldPosition(__instance.Scene, UIntPtr.Zero, vec3, false); __result = new WorldFrame(identity2, origin); } Vec2 v3 = Vec2.Invalid; ICollection <Vec2> value = __instance.Boundaries.First <KeyValuePair <string, ICollection <Vec2> > >().Value; if (value.Count > 0) { v3 = value.Aggregate((a, b) => a + b); v3 *= 1f / (float)value.Count; } WorldPosition origin2 = new WorldPosition(__instance.Scene, UIntPtr.Zero, v3.ToVec3(0f), false); __result = new WorldFrame(Mat3.Identity, origin2); } else { SiegeMissionController expr_609 = __instance.GetMissionBehaviour <SiegeMissionController>(); if (expr_609 != null) { bool arg_614_0 = expr_609.IsSallyOut; } string text = side.ToString().ToLower() + "_" + ((formationClass != FormationClass.NumberOfRegularFormations) ? formationClass.GetName().ToLower() : "infantry"); if (isReinforcement) { text += "_reinforcement"; } GameEntity gameEntity3 = __instance.Scene.FindEntityWithTag(text); if (gameEntity3 != null) { MatrixFrame globalFrame = gameEntity3.GetGlobalFrame(); globalFrame.rotation.OrthonormalizeAccordingToForwardAndKeepUpAsZAxis(); WorldPosition origin3 = new WorldPosition(__instance.Scene, UIntPtr.Zero, globalFrame.origin, false); __result = new WorldFrame(globalFrame.rotation, origin3); } Vec2 v4 = Vec2.Invalid; ICollection <Vec2> value2 = __instance.Boundaries.First <KeyValuePair <string, ICollection <Vec2> > >().Value; if (value2.Count > 0) { v4 = value2.Aggregate((a, b) => a + b); v4 *= 1f / (float)value2.Count; } WorldPosition origin4 = new WorldPosition(__instance.Scene, UIntPtr.Zero, v4.ToVec3(0f), false); __result = new WorldFrame(Mat3.Identity, origin4); } }
protected virtual void OnTick( Func <Agent, bool> isAgentManagedByThisMachineAI, Team potentialUsersTeam, float dt) { this._tickCounter = ++this._tickCounter % 200; foreach (StandingPoint standingPoint in this.UsableMachine.StandingPoints) { if (isAgentManagedByThisMachineAI(standingPoint.UserAgent)) { Agent userAgent = standingPoint.UserAgent; if (this.HasActionCompleted || potentialUsersTeam != null && this.UsableMachine.IsDisabledForBattleSideAI(potentialUsersTeam.Side) || userAgent.IsRunningAway) { this.HandleAgentStopUsingStandingPoint(userAgent, standingPoint); } } List <KeyValuePair <Agent, UsableMissionObject.MoveInfo> > list = standingPoint.MovingAgents.ToList <KeyValuePair <Agent, UsableMissionObject.MoveInfo> >(); List <Agent> agentList = new List <Agent>(); for (int index = list.Count - 1; index >= 0; --index) { Agent key = list[index].Key; if (isAgentManagedByThisMachineAI(key)) { if (this.HasActionCompleted || potentialUsersTeam != null && this.UsableMachine.IsDisabledForBattleSideAI(potentialUsersTeam.Side) || key.IsRunningAway) { this.HandleAgentStopUsingStandingPoint(key, standingPoint); } else { if (standingPoint.HasAlternative() && this.UsableMachine.IsInRangeToCheckAlternativePoints(key)) { StandingPoint pointAlternativeTo = this.UsableMachine.GetBestPointAlternativeTo(standingPoint, key); if (pointAlternativeTo != standingPoint) { standingPoint.OnMoveToStopped(key); key.AIMoveToGameObjectEnable((UsableMissionObject)pointAlternativeTo, this.GetScriptedFrameFlags(key)); if (standingPoint == this.UsableMachine.CurrentlyUsedAmmoPickUpPoint) { this.UsableMachine.CurrentlyUsedAmmoPickUpPoint = pointAlternativeTo; continue; } continue; } } if (standingPoint.HasUserPositionsChanged(key)) { WorldFrame userFrameForAgent = standingPoint.GetUserFrameForAgent(key); string debugString = this.UsableMachine.GameEntity.Name + " Id:" + (object)this.UsableMachine.Id.Id + " " + standingPoint.GameEntity.Name; key.SetScriptedPositionAndDirection(ref userFrameForAgent.Origin, userFrameForAgent.Rotation.f.AsVec2.RotationInRadians, false, this.GetScriptedFrameFlags(key), debugString); } if (!standingPoint.IsDisabled && !standingPoint.HasUser && !key.IsAIPaused() && key.CanReachAndUseObject((UsableMissionObject)standingPoint, standingPoint.GetUserFrameForAgent(key).Origin.GetGroundVec3().DistanceSquared(key.Position))) { key.UseGameObject((UsableMissionObject)standingPoint); key.SetScriptedFlags(key.GetScriptedFlags() & ~standingPoint.DisableScriptedFrameFlags); agentList.Add(key); } } } } } if (!((NativeObject)this._lastActiveWaitStandingPoint != (NativeObject)this.UsableMachine.WaitEntity)) { return; } foreach (Formation formation in potentialUsersTeam.FormationsIncludingSpecial.Where <Formation>((Func <Formation, bool>)(f => f.IsUsingMachine(this.UsableMachine) && f.MovementOrder.OrderEnum == MovementOrder.MovementOrderEnum.FollowEntity && (NativeObject)f.MovementOrder.TargetEntity == (NativeObject)this._lastActiveWaitStandingPoint))) { formation.MovementOrder = !(this is SiegeTowerAI) ? MovementOrder.MovementOrderFollowEntity(this.UsableMachine.WaitEntity) : this.NextOrder; } this._lastActiveWaitStandingPoint = this.UsableMachine.WaitEntity; }