public static void GetSpawnPathPositionsForBattleSides( Path spawnPath, float spawnPathOffset, int battleSize, out Vec2 attackerPosition, out Vec2 attackerDirection, out Vec2 defenderPosition, out Vec2 defenderDirection) { if ((NativeObject)spawnPath == (NativeObject)null) { attackerPosition = Mission.Current.GetSceneMiddleFrame().Origin.AsVec2; attackerDirection = Vec2.Forward; defenderPosition = attackerPosition; defenderDirection = -attackerDirection; } else { float totalLength = spawnPath.GetTotalLength(); float normalizationFactor = 800f / totalLength; float middlePoint = 0.5f + spawnPathOffset; float battleSizeFactor = MissionDeploymentPlan.GetBattleSizeFactor(battleSize, normalizationFactor); float ratioForBattleSide1 = MissionDeploymentPlan.GetSpawnPathRatioForBattleSide(BattleSideEnum.Attacker, battleSizeFactor, middlePoint); float ratioForBattleSide2 = MissionDeploymentPlan.GetSpawnPathRatioForBattleSide(BattleSideEnum.Defender, battleSizeFactor, middlePoint); attackerPosition = spawnPath.GetFrameForDistance(totalLength * ratioForBattleSide1 + spawnPathOffset).origin.AsVec2; defenderPosition = spawnPath.GetFrameForDistance(totalLength * ratioForBattleSide2 - spawnPathOffset).origin.AsVec2; attackerDirection = (defenderPosition - attackerPosition).Normalized(); defenderDirection = -attackerDirection; } }
public void PlanFieldBattleDeploymentAtPosition( Vec2 deployPosition, Vec2 deployDirection, bool isReinforcement = false) { for (int index = 0; index < this._formationDeploymentPlans.Length; ++index) { int formationTroopCount = this._formationTroopCounts[index]; FormationDeploymentPlan formationDeploymentPlan = this._formationDeploymentPlans[index]; FormationDeploymentFlank defaultFlank = formationDeploymentPlan.GetDefaultFlank(this.SpawnWithHorses); (float width2, float depth2) = MissionDeploymentPlan.GetFormationSpawnWidthAndDepth(formationDeploymentPlan.Class, formationTroopCount, !this.SpawnWithHorses); formationDeploymentPlan.SetPlannedDimensions(width2, depth2); formationDeploymentPlan.SetPlannedTroopCount(formationTroopCount); int offset = formationTroopCount > 0 ? 0 : 1; FormationDeploymentOrder deploymentOrder = formationDeploymentPlan.GetDeploymentOrder(offset); this._deploymentFlanks[(int)defaultFlank].Add(deploymentOrder, formationDeploymentPlan); } (float flankWidth, float flankDepth)tuple = this.PlanFlankDeployment(FormationDeploymentFlank.Front, deployPosition, deployDirection, isReinforcement: isReinforcement); float flankWidth1 = tuple.flankWidth; float verticalOffset1 = tuple.flankDepth + 3f; float flankWidth2 = this.PlanFlankDeployment(FormationDeploymentFlank.Rear, deployPosition, deployDirection, verticalOffset1, isReinforcement: isReinforcement).flankWidth; float num = Math.Max(flankWidth1, flankWidth2); float verticalOffset2 = this.ComputeFlankDepth(FormationDeploymentFlank.Front, true) + 3f; float flankWidth3 = this.ComputeFlankWidth(FormationDeploymentFlank.Left); float horizontalOffset1 = (float)(2.0 + 0.5 * ((double)num + (double)flankWidth3)); this.PlanFlankDeployment(FormationDeploymentFlank.Left, deployPosition, deployDirection, verticalOffset2, horizontalOffset1, isReinforcement); float flankWidth4 = this.ComputeFlankWidth(FormationDeploymentFlank.Right); float horizontalOffset2 = (float)(-1.0 * (2.0 + 0.5 * ((double)num + (double)flankWidth4))); this.PlanFlankDeployment(FormationDeploymentFlank.Right, deployPosition, deployDirection, verticalOffset2, horizontalOffset2, isReinforcement); for (int index = 0; index < this._deploymentFlanks.Length; ++index) { this._deploymentFlanks[index].Clear(); } }
public void PlanBattleDeployment( Path spawnPath = null, float spawnPathOffset = 0.0f, int reinforcementBattleSize = 25) { if (this.IsPlanMade) { this.ClearPlan(); } BattleSideDeploymentPlan sideDeploymentPlan1 = this._battleSideDeploymentPlans[1]; BattleSideDeploymentPlan sideDeploymentPlan2 = this._battleSideDeploymentPlans[0]; int battleSize1 = Math.Min(sideDeploymentPlan1.TroopCount, sideDeploymentPlan2.TroopCount); bool isFieldBattle = this._mission.IsFieldBattle; if ((NativeObject)spawnPath != (NativeObject)null) { Vec2 attackerPosition1; Vec2 attackerDirection1; Vec2 defenderPosition1; Vec2 defenderDirection1; MissionDeploymentPlan.GetSpawnPathPositionsForBattleSides(spawnPath, spawnPathOffset, battleSize1, out attackerPosition1, out attackerDirection1, out defenderPosition1, out defenderDirection1); sideDeploymentPlan1.PlanFieldBattleDeploymentAtPosition(attackerPosition1, attackerDirection1); sideDeploymentPlan2.PlanFieldBattleDeploymentAtPosition(defenderPosition1, defenderDirection1); if (reinforcementBattleSize > 0) { int battleSize2 = battleSize1 + reinforcementBattleSize; Vec2 attackerPosition2; Vec2 attackerDirection2; Vec2 defenderPosition2; Vec2 defenderDirection2; MissionDeploymentPlan.GetSpawnPathPositionsForBattleSides(spawnPath, spawnPathOffset, battleSize2, out attackerPosition2, out attackerDirection2, out defenderPosition2, out defenderDirection2); sideDeploymentPlan1.PlanFieldBattleDeploymentAtPosition(attackerPosition2, attackerDirection2, true); sideDeploymentPlan2.PlanFieldBattleDeploymentAtPosition(defenderPosition2, defenderDirection2, true); } } else if (isFieldBattle) { if (this._formationSceneEntries == null) { this.ReadFormationSpawnEntitiesFromScene(true); } sideDeploymentPlan1.PlanFieldBattleDeploymentFromSceneData(battleSize1, this._formationSceneEntries); sideDeploymentPlan2.PlanFieldBattleDeploymentFromSceneData(battleSize1, this._formationSceneEntries); if (reinforcementBattleSize > 0) { int battleSize2 = battleSize1 + reinforcementBattleSize; sideDeploymentPlan1.PlanFieldBattleDeploymentFromSceneData(battleSize2, this._formationSceneEntries, true); sideDeploymentPlan2.PlanFieldBattleDeploymentFromSceneData(battleSize2, this._formationSceneEntries, true); } } else { if (this._formationSceneEntries == null) { this.ReadFormationSpawnEntitiesFromScene(false); } sideDeploymentPlan1.PlanBattleDeploymentFromSceneData(this._formationSceneEntries); sideDeploymentPlan2.PlanBattleDeploymentFromSceneData(this._formationSceneEntries); } this.IsPlanMade = true; }