public static bool Prefix_OnApplyToArrangement(FormOrder __instance, Formation formation, IFormationArrangement arrangement)
        {
            try
            {
                switch (arrangement)
                {
                case TaleWorlds.MountAndBlade.CircularFormation circularFormation:
                {
                    int?unitCountOf1 = (int?)GetUnitCountOf?.Invoke(null, new object[] { formation });
                    int?fileCount1   = (int?)GetFileCount?.Invoke(__instance, new object[] { unitCountOf1 });
                    if (unitCountOf1.HasValue && fileCount1.HasValue)
                    {
                        int depth = Math.Max(1, (int)Math.Ceiling(unitCountOf1.Value * 1.0 / fileCount1.Value));
                        circularFormation.FormFromDepth(depth);
                        return(false);
                    }

                    float?customWidth = (float?)CustomWidth?.GetValue(__instance);
                    if (!customWidth.HasValue)
                    {
                        return(true);
                    }

                    //circularFormation.FormFromCircumference((float)CustomWidth.GetValue(__instance) -
                    //                                        formation.UnitDiameter);

                    int countWithOverride = formation.OverridenUnitCount ?? circularFormation.UnitCount;
                    int maximumDepth      = GetMaximumDepth(countWithOverride, formation.Distance, formation.Interval,
                                                            formation.UnitDiameter);
                    FormFromCircumference(circularFormation, (float)CustomWidth.GetValue(__instance) -
                                          formation.UnitDiameter, countWithOverride, maximumDepth,
                                          formation.Distance, formation.Interval, formation.UnitDiameter);
                    return(false);
                }
                }

                return(true);
            }
            catch (Exception)
            {
                return(true);
            }
        }
        public void AfterStart2()
        {
            this._started    = true;
            playerTeamAgents = new List <Agent>();
            var scene = this.Mission.Scene;

            if (this.CaptureTheBannerLordParams.skyBrightness >= 0)
            {
                scene.SetSkyBrightness(this.CaptureTheBannerLordParams.skyBrightness);
            }

            if (this.CaptureTheBannerLordParams.rainDensity >= 0)
            {
                scene.SetRainDensity(this.CaptureTheBannerLordParams.rainDensity);
            }

            this.Mission.MissionTeamAIType = Mission.MissionTeamAITypeEnum.FieldBattle;
            this.Mission.SetMissionMode(MissionMode.Battle, true);

            var xInterval      = this.CaptureTheBannerLordParams.soldierXInterval;
            var yInterval      = this.CaptureTheBannerLordParams.soldierYInterval;
            var soldiersPerRow = this.CaptureTheBannerLordParams.soldiersPerRow;

            var startPos        = this.CaptureTheBannerLordParams.FormationPosition;
            var xDir            = this.CaptureTheBannerLordParams.formationDirection;
            var yDir            = this.CaptureTheBannerLordParams.formationDirection.LeftVec();
            var agentDefaultDir = new TL.Vec2(0, 1);
            var useFreeCamera   = this.CaptureTheBannerLordParams.useFreeCamera;

            BasicCharacterObject soldierCharacter = this._game.ObjectManager.GetObject <BasicCharacterObject>(this.CaptureTheBannerLordParams.playerSoldierCharacterId);
            var playerSoldierFormationClass       = soldierCharacter.CurrentFormationClass;

            this.playerTeam = this.Mission.Teams.Add(BattleSideEnum.Attacker, 0xff3f51b5);

            playerTeam.AddTeamAI(new TeamAIGeneral(this.Mission, playerTeam));
            playerTeam.AddTacticOption(new TacticCharge(playerTeam));
            // playerTeam.AddTacticOption(new TacticFullScaleAttack(playerTeam));
            playerTeam.ExpireAIQuerySystem();
            playerTeam.ResetTactic();
            this.Mission.PlayerTeam = playerTeam;

            var playerPosVec2 = startPos + xDir * -10 + yDir * -10;
            var playerPos     = new TL.Vec3(playerPosVec2.x, playerPosVec2.y, 30);

            if (!useFreeCamera)
            {
                var playerMat = TL.Mat3.Identity;
                playerMat.RotateAboutUp(agentDefaultDir.AngleBetween(xDir));
                BasicCharacterObject playerCharacter = this._game.ObjectManager.GetObject <BasicCharacterObject>(this.CaptureTheBannerLordParams.playerCharacterId);
                AgentBuildData       agentBuildData  = new AgentBuildData(new BasicBattleAgentOrigin(playerCharacter))
                                                       .ClothingColor1(0xff3f51b5)
                                                       .ClothingColor2(0xff3f51b5)
                                                       .Banner(Banner.CreateRandomBanner())
                                                       .IsFemale(false)
                                                       .InitialFrame(new TL.MatrixFrame(playerMat, playerPos));
                Agent player = this.Mission.SpawnAgent(agentBuildData, false, 0);
                player.Controller = Agent.ControllerType.Player;
                player.WieldInitialWeapons();
                player.AllowFirstPersonWideRotation();

                Mission.MainAgent = player;
                player.SetTeam(playerTeam, true);
                playerTeam.GetFormation(playerSoldierFormationClass).PlayerOwner = player;
                playerTeam.PlayerOrderController.Owner = player;
                this._playerAgent = player;
            }
            else
            {
                var c = this.CaptureTheBannerLordParams.playerSoldierCount;
                if (c <= 0)
                {
                    this.freeCameraPosition = new TL.Vec3(startPos.x, startPos.y, 30);
                }
                else
                {
                    var rowCount = (c + soldiersPerRow - 1) / soldiersPerRow;
                    var p        = startPos + (System.Math.Min(soldiersPerRow, c) - 1) / 2 * yInterval * yDir - rowCount * xInterval * xDir;
                    this.freeCameraPosition = new TL.Vec3(p.x, p.y, 5);
                }
            }


            BasicCharacterObject enemyCharacter = this._game.ObjectManager.GetObject <BasicCharacterObject>(this.CaptureTheBannerLordParams.enemySoldierCharacterId);

            enemyTeam = this.Mission.Teams.Add(BattleSideEnum.Defender, 0xffff6090);
            enemyTeam.AddTeamAI(new TeamAIGeneral(this.Mission, enemyTeam));
            enemyTeam.AddTacticOption(new TacticCharge(enemyTeam));
            // enemyTeam.AddTacticOption(new TacticFullScaleAttack(enemyTeam));
            enemyTeam.SetIsEnemyOf(playerTeam, true);
            playerTeam.SetIsEnemyOf(enemyTeam, true);
            enemyTeam.ExpireAIQuerySystem();
            enemyTeam.ResetTactic();

            var enemyFormationClass = enemyCharacter.CurrentFormationClass;
            var enemyFormation      = enemyTeam.GetFormation(FormationClass.Ranged);

            {
                float width     = this.getInitialFormationWidth(enemyTeam, enemyFormationClass);
                var   centerPos = startPos + yDir * (width / 2) + xDir * this.CaptureTheBannerLordParams.distance;
                var   wp        = new WorldPosition(scene, centerPos.ToVec3());
                enemyFormation.SetPositioning(wp, -xDir, null);
                enemyFormation.FormOrder = FormOrder.FormOrderCustom(width);
            }

            for (var i = 0; i < this.CaptureTheBannerLordParams.enemySoldierCount; i += 1)
            {
                AgentBuildData enemyBuildData = new AgentBuildData(new BasicBattleAgentOrigin(enemyCharacter))
                                                .ClothingColor1(enemyTeam.Color)
                                                .ClothingColor2(enemyTeam.Color2)
                                                .Banner(enemyTeam.Banner)
                                                .Formation(enemyFormation);


                var agent = this.Mission.SpawnAgent(enemyBuildData);
                agent.SetTeam(enemyTeam, true);
                agent.Formation = enemyFormation;
                agent.SetWatchState(AgentAIStateFlagComponent.WatchState.Alarmed);
            }
            {
                var a = this.Mission.IsOrderShoutingAllowed();
                var b = this.Mission.IsAgentInteractionAllowed();
                var c = GameNetwork.IsClientOrReplay;
                var d = playerTeam.PlayerOrderController.Owner == null;
                ModuleLogger.Log("mission allowed shouting: {0} interaction: {1} {2} {3}", a, b, c, d);
            }
        }
Пример #3
0
    // Main form
    private void MainFrm_Load(object sender, EventArgs e)
    {
        FormOrder frmO = new FormOrder(this);     // pass a ref of self

        frmO.Show();
    }
        public Order Insert()
        {
            var files = HttpContext.Current.Request.Files;

            if (!Request.Content.IsMimeMultipartContent() || files.Count == 0 || HttpContext.Current.Request.Form.Count == 0)
            {
                return(null);
            }

            var orderFile   = files["Order"];
            var orderOrigin = files["OrderOrigin"];
            var agreement   = files["Agreement"];

            if (orderFile == null)
            {
                return(null);
            }

            var currentDate = DateTime.Now;

            var form = new FormOrder();

            form.siteId = int.Parse(HttpContext.Current.Request.Form.Get("siteId"));
            form.number = HttpContext.Current.Request.Form.Get("number");
            //form.customerid = int.Parse(HttpContext.Current.Request.Form.Get("customerId"));

            var filesListId = ArchiveManager.CreateFilesList("Заявки от заказчика");

            if (ArchiveManager.PutDocument(orderFile.InputStream, new DocumentRequisite()
            {
                date = currentDate,
                fileName = orderFile.FileName,
                market = (MarketPlaceEnum)form.siteId,
                number = form.number,
                section = DocumentSectionEnum.Order,
                type = DocumentTypeEnum.OrderSource
            }, filesListId) < 1)
            {
                return(null);
            }
            if (orderOrigin != null)
            {
                if (ArchiveManager.PutDocument(orderOrigin.InputStream, new DocumentRequisite()
                {
                    date = currentDate,
                    fileName = orderOrigin.FileName,
                    market = (MarketPlaceEnum)form.siteId,
                    number = form.number,
                    section = DocumentSectionEnum.Order,
                    type = DocumentTypeEnum.OrderOriginal
                }, filesListId) < 1)
                {
                    return(null);
                }
            }
            if (agreement != null)
            {
                if (ArchiveManager.PutDocument(agreement.InputStream, new DocumentRequisite()
                {
                    date = currentDate,
                    fileName = agreement.FileName,
                    market = (MarketPlaceEnum)form.siteId,
                    number = form.number,
                    section = DocumentSectionEnum.Order,
                    type = DocumentTypeEnum.AgreementSource
                }, filesListId) < 1)
                {
                    return(null);
                }
            }
            var countShemes = HttpContext.Current.Request.Form.Get("count_shemes");

            if (countShemes != null)
            {
                var countShemesFiles = int.Parse(countShemes);
                if (countShemesFiles > 0)
                {
                    for (var i = 0; i < countShemesFiles; i++)
                    {
                        var sheme = files[string.Format("Sheme{0}", i)];
                        if (sheme != null)
                        {
                            if (ArchiveManager.PutDocument(sheme.InputStream, new DocumentRequisite()
                            {
                                date = currentDate,
                                fileName = sheme.FileName,
                                market = (MarketPlaceEnum)form.siteId,
                                number = form.number,
                                section = DocumentSectionEnum.Order,
                                type = DocumentTypeEnum.Scheme
                            }, filesListId) < 1)
                            {
                                return(null);
                            }
                        }
                    }
                }
            }
            var order = new Order();

            order.Date     = currentDate;
            order.Deadline = currentDate;
            order.Number   = form.number;
            order.statusId = 1;
            //order.customerid = form.customerid;
            order.customerid  = CurrentUser.CustomerId;
            order.siteId      = form.siteId;
            order.filesListId = filesListId;
            var orderId = DataManager.CreateOrder(order, CurrentUser.Id);

            if (orderId != default(int))
            {
                return(order);
            }
            return(null);

            #endregion
        }
        public Order KaspyInsert()
        {
            var files = HttpContext.Current.Request.Files;

            if (!Request.Content.IsMimeMultipartContent() || files.Count == 0 || HttpContext.Current.Request.Form.Count == 0)
            {
                return(null);
            }

            var assignment    = files["assignment"];
            var specification = files["specification"];
            var suppliers     = files["suppliers"];

            if (assignment == null)
            {
                return(null);
            }

            var currentDate = DateTime.Now;

            var form = new FormOrder();

            form.siteId = int.Parse(HttpContext.Current.Request.Form.Get("siteId"));
            form.number = HttpContext.Current.Request.Form.Get("number");
            //form.customerid = int.Parse(HttpContext.Current.Request.Form.Get("customerId"));

            var filesListId = ArchiveManager.CreateFilesList("Заявки от заказчика");

            if (ArchiveManager.PutDocument(assignment.InputStream, new DocumentRequisite()
            {
                date = currentDate,
                fileName = assignment.FileName,
                market = (MarketPlaceEnum)form.siteId,
                number = form.number,
                section = DocumentSectionEnum.Order,
                type = DocumentTypeEnum.OrderSource
            }, filesListId) < 1)
            {
                return(null);
            }
            if (specification != null)
            {
                if (ArchiveManager.PutDocument(specification.InputStream, new DocumentRequisite()
                {
                    date = currentDate,
                    fileName = specification.FileName,
                    market = (MarketPlaceEnum)form.siteId,
                    number = form.number,
                    section = DocumentSectionEnum.Order,
                    type = DocumentTypeEnum.TechSpecs
                }, filesListId) < 1)
                {
                    return(null);
                }
            }
            if (suppliers != null)
            {
                if (ArchiveManager.PutDocument(suppliers.InputStream, new DocumentRequisite()
                {
                    date = currentDate,
                    fileName = suppliers.FileName,
                    market = (MarketPlaceEnum)form.siteId,
                    number = form.number,
                    section = DocumentSectionEnum.Order,
                    type = DocumentTypeEnum.ApplicantsFromCustomer,
                }, filesListId) < 1)
                {
                    return(null);
                }
            }
            var order = new Order();

            order.Date        = currentDate;
            order.Deadline    = currentDate;
            order.Number      = form.number;
            order.statusId    = 1;
            order.customerid  = CurrentUser.CustomerId;
            order.siteId      = form.siteId;
            order.filesListId = filesListId;
            var orderId = DataManager.CreateOrder(order, CurrentUser.Id);

            if (orderId != default(int))
            {
                return(order);
            }
            return(null);
        }
Пример #6
0
        private void Check()
        {
            float time = this.Mission.Time;

            if (this._battlePhase == CPUBenchmarkMissionLogic.BattlePhase.Start && (double)time >= 5.0)
            {
                this.Mission.IsTeleportingAgents = false;
                this._battlePhase = CPUBenchmarkMissionLogic.BattlePhase.ArrowShower;
            }
            else
            {
                if (this._battlePhase == CPUBenchmarkMissionLogic.BattlePhase.Start)
                {
                    return;
                }
                if (!this._isCurPhaseInPlay)
                {
                    Debug.Print("State: " + (object)this._battlePhase, color: Debug.DebugColor.Cyan, debugFilter: 64UL);
                    switch (this._battlePhase)
                    {
                    case CPUBenchmarkMissionLogic.BattlePhase.ArrowShower:
                        this._attLeftRanged.FiringOrder    = FiringOrder.FiringOrderFireAtWill;
                        this._attRightRanged.FiringOrder   = FiringOrder.FiringOrderFireAtWill;
                        this._defLeftBInf.FiringOrder      = FiringOrder.FiringOrderFireAtWill;
                        this._defRightBInf.FiringOrder     = FiringOrder.FiringOrderFireAtWill;
                        this._defMidBInf.FiringOrder       = FiringOrder.FiringOrderFireAtWill;
                        this._defLeftInf.ArrangementOrder  = ArrangementOrder.ArrangementOrderShieldWall;
                        this._defRightInf.ArrangementOrder = ArrangementOrder.ArrangementOrderShieldWall;
                        this._defLeftInf.FormOrder         = FormOrder.FormOrderCustom(35f);
                        this._defRightInf.FormOrder        = FormOrder.FormOrderCustom(35f);
                        this._attLeftInf.ArrangementOrder  = ArrangementOrder.ArrangementOrderShieldWall;
                        this._attRightInf.ArrangementOrder = ArrangementOrder.ArrangementOrderShieldWall;
                        break;

                    case CPUBenchmarkMissionLogic.BattlePhase.MeleePosition:
                        Vec3 vec3_1 = -(this._attLeftInf.OrderPosition.Position - this._defRightInf.OrderPosition.Position);
                        Vec3 vec3_2 = -(this._attRightInf.OrderPosition.Position - this._defLeftInf.OrderPosition.Position);
                        vec3_1.RotateAboutZ((float)Math.PI / 36f);
                        vec3_2.RotateAboutZ(-1f * (float)Math.PI / 36f);
                        this._attLeftInf.MovementOrder  = MovementOrder.MovementOrderMove(new WorldPosition(this.Mission.Scene, this._attLeftInf.OrderPosition.Position + vec3_1));
                        this._attRightInf.MovementOrder = MovementOrder.MovementOrderMove(new WorldPosition(this.Mission.Scene, this._attRightInf.OrderPosition.Position + vec3_2));
                        break;

                    case CPUBenchmarkMissionLogic.BattlePhase.Cav1Pos:
                        Vec3 position1  = this._attLeftRanged.OrderPosition.Position;
                        Vec2 direction1 = this._attLeftRanged.Direction;
                        Vec3 vec3_3     = position1 - 15f * direction1.ToVec3();
                        direction1.RotateCCW(1.570796f);
                        this._attLeftCav.MovementOrder = MovementOrder.MovementOrderMove(new WorldPosition(this.Mission.Scene, vec3_3 + 60f * direction1.ToVec3()));
                        break;

                    case CPUBenchmarkMissionLogic.BattlePhase.Cav1PosDef:
                        MatrixFrame globalFrame1 = this.Mission.Scene.FindEntityWithTag("defend_right").GetGlobalFrame();
                        this._defMidCav.MovementOrder = MovementOrder.MovementOrderMove(new WorldPosition(this.Mission.Scene, globalFrame1.origin + 40f * globalFrame1.rotation.s));
                        break;

                    case CPUBenchmarkMissionLogic.BattlePhase.CavalryPosition:
                        Vec3 position2  = this._attRightRanged.OrderPosition.Position;
                        Vec2 direction2 = this._attRightRanged.Direction;
                        Vec3 vec3_4     = position2 + 20f * direction2.ToVec3();
                        direction2.RotateCCW(-1.570796f);
                        this._attRightCav.MovementOrder = MovementOrder.MovementOrderMove(new WorldPosition(this.Mission.Scene, vec3_4 + 80f * direction2.ToVec3()));
                        this._attLeftInf.MovementOrder  = MovementOrder.MovementOrderCharge;
                        this._attRightInf.MovementOrder = MovementOrder.MovementOrderCharge;
                        this._defLeftBInf.FiringOrder   = FiringOrder.FiringOrderFireAtWill;
                        break;

                    case CPUBenchmarkMissionLogic.BattlePhase.MeleeAttack:
                        this._defLeftInf.FiringOrder       = FiringOrder.FiringOrderFireAtWill;
                        this._defMidBInf.FiringOrder       = FiringOrder.FiringOrderFireAtWill;
                        this._defRightBInf.FiringOrder     = FiringOrder.FiringOrderFireAtWill;
                        this._attLeftInf.ArrangementOrder  = ArrangementOrder.ArrangementOrderLine;
                        this._attRightInf.ArrangementOrder = ArrangementOrder.ArrangementOrderLine;
                        this._attLeftInf.MovementOrder     = MovementOrder.MovementOrderMove(new WorldPosition(this.Mission.Scene, this._defRightInf.GetAveragePositionOfUnits(true, false).ToVec3()));
                        this._attRightInf.MovementOrder    = MovementOrder.MovementOrderMove(new WorldPosition(this.Mission.Scene, this._defLeftInf.GetAveragePositionOfUnits(true, false).ToVec3()));
                        break;

                    case CPUBenchmarkMissionLogic.BattlePhase.RangedAdvance:
                        Vec2 averagePositionOfUnits1 = this._attLeftRanged.GetAveragePositionOfUnits(true, false);
                        Vec3 vec3_5 = averagePositionOfUnits1.ToVec3();
                        averagePositionOfUnits1 = this._attLeftRanged.GetAveragePositionOfUnits(true, false);
                        Vec3 vec3_6 = averagePositionOfUnits1.ToVec3();
                        averagePositionOfUnits1 = this._defRightInf.GetAveragePositionOfUnits(true, false);
                        Vec3 vec3_7    = averagePositionOfUnits1.ToVec3();
                        Vec3 vec3_8    = 0.15f * (vec3_6 - vec3_7);
                        Vec3 position3 = vec3_5 - vec3_8;
                        averagePositionOfUnits1 = this._attRightRanged.GetAveragePositionOfUnits(true, false);
                        Vec3 vec3_9 = averagePositionOfUnits1.ToVec3();
                        averagePositionOfUnits1 = this._attRightRanged.GetAveragePositionOfUnits(true, false);
                        Vec3 vec3_10 = averagePositionOfUnits1.ToVec3();
                        averagePositionOfUnits1 = this._defLeftInf.GetAveragePositionOfUnits(true, false);
                        Vec3 vec3_11   = averagePositionOfUnits1.ToVec3();
                        Vec3 vec3_12   = 0.15f * (vec3_10 - vec3_11);
                        Vec3 position4 = vec3_9 - vec3_12;
                        this._attLeftRanged.MovementOrder  = MovementOrder.MovementOrderMove(new WorldPosition(this.Mission.Scene, position3));
                        this._attRightRanged.MovementOrder = MovementOrder.MovementOrderMove(new WorldPosition(this.Mission.Scene, position4));
                        break;

                    case CPUBenchmarkMissionLogic.BattlePhase.CavalryAdvance:
                        this.Mission.Scene.FindEntityWithTag("attacker_mid").GetGlobalFrame();
                        MatrixFrame globalFrame2 = this.Mission.Scene.FindEntityWithTag("defend_right").GetGlobalFrame();
                        this.Mission.Scene.FindEntityWithTag("defend_left").GetGlobalFrame();
                        Vec3 position5 = globalFrame2.origin + globalFrame2.rotation.s * 68f + 10f * this._attLeftRanged.Direction.ToVec3();
                        this._attLeftCav.MovementOrder = MovementOrder.MovementOrderMove(new WorldPosition(this.Mission.Scene, position5));
                        this._defMidCav.MovementOrder  = MovementOrder.MovementOrderMove(new WorldPosition(this.Mission.Scene, position5));
                        break;

                    case CPUBenchmarkMissionLogic.BattlePhase.CavalryCharge:
                        MatrixFrame globalFrame3 = this.Mission.Scene.FindEntityWithTag("defend_left").GetGlobalFrame();
                        this._defLeftBInf.FacingOrder   = FacingOrder.FacingOrderLookAtDirection((this._attRightCav.CurrentPosition - this._defLeftBInf.CurrentPosition).Normalized());
                        this._defLeftBInf.MovementOrder = MovementOrder.MovementOrderMove(new WorldPosition(this.Mission.Scene, globalFrame3.origin - globalFrame3.rotation.s * 10f));
                        this._attRightCav.MovementOrder = MovementOrder.MovementOrderChargeToTarget(this._defLeftBInf);
                        this._attLeftCav.MovementOrder  = MovementOrder.MovementOrderChargeToTarget(this._attLeftInf);
                        this._defMidCav.MovementOrder   = MovementOrder.MovementOrderChargeToTarget(this._attRightInf);
                        break;

                    case CPUBenchmarkMissionLogic.BattlePhase.CavalryCharge2:
                        this._attRightCav.MovementOrder    = MovementOrder.MovementOrderMove(new WorldPosition(this.Mission.Scene, this._defLeftBInf.OrderPosition.Position));
                        this._attLeftRanged.FiringOrder    = FiringOrder.FiringOrderFireAtWill;
                        this._attLeftRanged.MovementOrder  = MovementOrder.MovementOrderAdvance;
                        this._attRightRanged.FiringOrder   = FiringOrder.FiringOrderFireAtWill;
                        this._attRightRanged.MovementOrder = MovementOrder.MovementOrderAdvance;
                        break;

                    case CPUBenchmarkMissionLogic.BattlePhase.RangedAdvance2:
                        Vec2 averagePositionOfUnits2 = this._attLeftRanged.GetAveragePositionOfUnits(true, false);
                        Vec3 vec3_13 = averagePositionOfUnits2.ToVec3();
                        averagePositionOfUnits2 = this._attLeftRanged.GetAveragePositionOfUnits(true, false);
                        Vec3 vec3_14 = averagePositionOfUnits2.ToVec3();
                        averagePositionOfUnits2 = this._defRightInf.GetAveragePositionOfUnits(true, false);
                        Vec3 vec3_15   = averagePositionOfUnits2.ToVec3();
                        Vec3 vec3_16   = 0.15f * (vec3_14 - vec3_15);
                        Vec3 position6 = vec3_13 - vec3_16;
                        averagePositionOfUnits2 = this._attRightRanged.GetAveragePositionOfUnits(true, false);
                        Vec3 vec3_17 = averagePositionOfUnits2.ToVec3();
                        averagePositionOfUnits2 = this._attRightRanged.GetAveragePositionOfUnits(true, false);
                        Vec3 vec3_18 = averagePositionOfUnits2.ToVec3();
                        averagePositionOfUnits2 = this._defLeftInf.GetAveragePositionOfUnits(true, false);
                        Vec3 vec3_19   = averagePositionOfUnits2.ToVec3();
                        Vec3 vec3_20   = 0.15f * (vec3_18 - vec3_19);
                        Vec3 position7 = vec3_17 - vec3_20;
                        this._attLeftRanged.MovementOrder  = MovementOrder.MovementOrderMove(new WorldPosition(this.Mission.Scene, position6));
                        this._attRightRanged.MovementOrder = MovementOrder.MovementOrderMove(new WorldPosition(this.Mission.Scene, position7));
                        break;

                    case CPUBenchmarkMissionLogic.BattlePhase.FullCharge:
                        using (IEnumerator <Formation> enumerator = this.Mission.AttackerTeam.Formations.GetEnumerator())
                        {
                            while (enumerator.MoveNext())
                            {
                                Formation current = enumerator.Current;
                                if (current != this._attLeftRanged && current != this._attRightRanged && current != this._attRightCav)
                                {
                                    current.MovementOrder = MovementOrder.MovementOrderCharge;
                                }
                            }
                            break;
                        }
                    }
                    this._isCurPhaseInPlay = true;
                }
                else
                {
                    switch (this._battlePhase)
                    {
                    case CPUBenchmarkMissionLogic.BattlePhase.ArrowShower:
                        if ((double)time <= 14.0)
                        {
                            break;
                        }
                        this._isCurPhaseInPlay = false;
                        this._battlePhase      = CPUBenchmarkMissionLogic.BattlePhase.MeleePosition;
                        break;

                    case CPUBenchmarkMissionLogic.BattlePhase.MeleePosition:
                        if ((double)time <= 19.0)
                        {
                            break;
                        }
                        this._isCurPhaseInPlay = false;
                        this._battlePhase      = CPUBenchmarkMissionLogic.BattlePhase.MeleeAttack;
                        break;

                    case CPUBenchmarkMissionLogic.BattlePhase.Cav1Pos:
                        if ((double)time <= 19.0)
                        {
                            break;
                        }
                        this._isCurPhaseInPlay = false;
                        this._battlePhase      = CPUBenchmarkMissionLogic.BattlePhase.Cav1PosDef;
                        break;

                    case CPUBenchmarkMissionLogic.BattlePhase.Cav1PosDef:
                        if ((double)time <= 24.0)
                        {
                            break;
                        }
                        this._isCurPhaseInPlay = false;
                        this._battlePhase      = CPUBenchmarkMissionLogic.BattlePhase.CavalryAdvance;
                        break;

                    case CPUBenchmarkMissionLogic.BattlePhase.CavalryPosition:
                        if ((double)time <= 74.5)
                        {
                            break;
                        }
                        this._isCurPhaseInPlay = false;
                        this._battlePhase      = CPUBenchmarkMissionLogic.BattlePhase.CavalryCharge;
                        break;

                    case CPUBenchmarkMissionLogic.BattlePhase.MeleeAttack:
                        if ((double)time <= 19.0)
                        {
                            break;
                        }
                        this._isCurPhaseInPlay = false;
                        this._battlePhase      = CPUBenchmarkMissionLogic.BattlePhase.Cav1Pos;
                        break;

                    case CPUBenchmarkMissionLogic.BattlePhase.RangedAdvance:
                        if ((double)time <= 60.0)
                        {
                            break;
                        }
                        this._isCurPhaseInPlay = false;
                        this._battlePhase      = CPUBenchmarkMissionLogic.BattlePhase.CavalryPosition;
                        break;

                    case CPUBenchmarkMissionLogic.BattlePhase.CavalryAdvance:
                        if ((double)time <= 30.0)
                        {
                            break;
                        }
                        this._isCurPhaseInPlay = false;
                        this._battlePhase      = CPUBenchmarkMissionLogic.BattlePhase.RangedAdvance;
                        break;

                    case CPUBenchmarkMissionLogic.BattlePhase.CavalryCharge:
                        if ((double)time <= 92.0)
                        {
                            break;
                        }
                        this._isCurPhaseInPlay = false;
                        this._battlePhase      = CPUBenchmarkMissionLogic.BattlePhase.CavalryCharge2;
                        break;

                    case CPUBenchmarkMissionLogic.BattlePhase.CavalryCharge2:
                        if ((double)time <= 93.0)
                        {
                            break;
                        }
                        this._isCurPhaseInPlay = false;
                        this._battlePhase      = CPUBenchmarkMissionLogic.BattlePhase.RangedAdvance2;
                        break;

                    case CPUBenchmarkMissionLogic.BattlePhase.RangedAdvance2:
                        if ((double)time <= 94.0)
                        {
                            break;
                        }
                        this._isCurPhaseInPlay = false;
                        this._battlePhase      = CPUBenchmarkMissionLogic.BattlePhase.FullCharge;
                        break;
                    }
                }
            }
        }
Пример #7
0
        private void SetupFormations()
        {
            MatrixFrame globalFrame1 = this.Mission.Scene.FindEntityWithTag("defend_right").GetGlobalFrame();
            MatrixFrame globalFrame2 = this.Mission.Scene.FindEntityWithTag("defend_mid").GetGlobalFrame();
            MatrixFrame globalFrame3 = this.Mission.Scene.FindEntityWithTag("defend_left").GetGlobalFrame();
            MatrixFrame globalFrame4 = this.Mission.Scene.FindEntityWithTag("attacker_right").GetGlobalFrame();
            MatrixFrame globalFrame5 = this.Mission.Scene.FindEntityWithTag("attacker_mid").GetGlobalFrame();
            MatrixFrame globalFrame6 = this.Mission.Scene.FindEntityWithTag("attacker_left").GetGlobalFrame();

            this._defLeftInf     = this.Mission.DefenderTeam.GetFormation(FormationClass.Infantry);
            this._defMidCav      = this.Mission.DefenderTeam.GetFormation(FormationClass.Ranged);
            this._defRightInf    = this.Mission.DefenderTeam.GetFormation(FormationClass.Cavalry);
            this._defLeftBInf    = this.Mission.DefenderTeam.GetFormation(FormationClass.HorseArcher);
            this._defMidBInf     = this.Mission.DefenderTeam.GetFormation(FormationClass.NumberOfDefaultFormations);
            this._defRightBInf   = this.Mission.DefenderTeam.GetFormation(FormationClass.HeavyInfantry);
            this._attLeftInf     = this.Mission.AttackerTeam.GetFormation(FormationClass.Infantry);
            this._attRightInf    = this.Mission.AttackerTeam.GetFormation(FormationClass.Ranged);
            this._attLeftRanged  = this.Mission.AttackerTeam.GetFormation(FormationClass.Cavalry);
            this._attRightRanged = this.Mission.AttackerTeam.GetFormation(FormationClass.HorseArcher);
            this._attLeftCav     = this.Mission.AttackerTeam.GetFormation(FormationClass.NumberOfDefaultFormations);
            this._attRightCav    = this.Mission.AttackerTeam.GetFormation(FormationClass.LightCavalry);
            int   num1 = this._defenderInfCount / 6;
            float num2 = (float)this._defenderInfCount / 3.8f;
            int   num3 = 0;
            int   num4 = this._attackerInfCount / 2;
            int   num5 = 0;
            int   num6 = this._attackerRangedCount / 2;
            int   num7 = 0;
            int   num8 = this._attackerCavCount / 2;
            int   num9 = 0;

            foreach (Agent agent in (IEnumerable <Agent>) this.Mission.Agents)
            {
                if (agent.Team != null && agent.Character != null)
                {
                    ++this._agentCounts[(int)agent.Team.Side];
                    if (agent.Team.IsDefender)
                    {
                        if (agent.Character.DefaultFormationClass == FormationClass.Cavalry)
                        {
                            agent.Formation = this._defMidCav;
                        }
                        else if ((double)num3 < (double)num2)
                        {
                            ++num3;
                            agent.Formation = this._defLeftInf;
                        }
                        else if ((double)num3 < (double)num2 * 2.0)
                        {
                            ++num3;
                            agent.Formation = this._defRightInf;
                        }
                        else if ((double)num3 < (double)num2 * 2.0 + (double)num1)
                        {
                            ++num3;
                            agent.Formation = this._defLeftBInf;
                        }
                        else if ((double)num3 < (double)num2 * 2.0 + (double)(num1 * 2))
                        {
                            ++num3;
                            agent.Formation = this._defMidBInf;
                        }
                        else
                        {
                            agent.Formation = this._defRightBInf;
                        }
                    }
                    else if (agent.Team.IsAttacker)
                    {
                        switch (agent.Character.DefaultFormationClass)
                        {
                        case FormationClass.Infantry:
                            if (num5 < num4)
                            {
                                ++num5;
                                agent.Formation = this._attLeftInf;
                                continue;
                            }
                            agent.Formation = this._attRightInf;
                            continue;

                        case FormationClass.Ranged:
                            if (num7 < num6)
                            {
                                ++num7;
                                agent.Formation = this._attLeftRanged;
                                continue;
                            }
                            agent.Formation = this._attRightRanged;
                            continue;

                        case FormationClass.Cavalry:
                            if (num9 < num8)
                            {
                                ++num9;
                                agent.Formation = this._attLeftCav;
                                continue;
                            }
                            agent.Formation = this._attRightCav;
                            continue;

                        default:
                            continue;
                        }
                    }
                }
            }
            this.Mission.IsTeleportingAgents      = true;
            this._defLeftInf.ArrangementOrder     = ArrangementOrder.ArrangementOrderLine;
            this._defMidCav.ArrangementOrder      = ArrangementOrder.ArrangementOrderLine;
            this._defRightInf.ArrangementOrder    = ArrangementOrder.ArrangementOrderLine;
            this._defLeftBInf.ArrangementOrder    = ArrangementOrder.ArrangementOrderLine;
            this._defMidBInf.ArrangementOrder     = ArrangementOrder.ArrangementOrderLine;
            this._defRightBInf.ArrangementOrder   = ArrangementOrder.ArrangementOrderLine;
            this._attLeftInf.ArrangementOrder     = ArrangementOrder.ArrangementOrderLine;
            this._attRightInf.ArrangementOrder    = ArrangementOrder.ArrangementOrderLine;
            this._attLeftRanged.ArrangementOrder  = ArrangementOrder.ArrangementOrderLoose;
            this._attRightRanged.ArrangementOrder = ArrangementOrder.ArrangementOrderLoose;
            this._attLeftCav.ArrangementOrder     = ArrangementOrder.ArrangementOrderLine;
            this._attRightCav.ArrangementOrder    = ArrangementOrder.ArrangementOrderLine;
            this._defLeftInf.FormOrder            = FormOrder.FormOrderCustom(35f);
            this._defMidCav.FormOrder             = FormOrder.FormOrderCustom(30f);
            this._defRightInf.FormOrder           = FormOrder.FormOrderCustom(35f);
            this._defLeftBInf.FormOrder           = FormOrder.FormOrderCustom(25f);
            this._defMidBInf.FormOrder            = FormOrder.FormOrderCustom(25f);
            this._defRightBInf.FormOrder          = FormOrder.FormOrderCustom(25f);
            this._attLeftInf.FormOrder            = FormOrder.FormOrderCustom(25f);
            this._attRightInf.FormOrder           = FormOrder.FormOrderCustom(25f);
            this._attLeftRanged.FormOrder         = FormOrder.FormOrderCustom(50f);
            this._attRightRanged.FormOrder        = FormOrder.FormOrderCustom(50f);
            this._attLeftCav.FormOrder            = FormOrder.FormOrderCustom(30f);
            this._attRightCav.FormOrder           = FormOrder.FormOrderCustom(30f);
            this._defLeftInf.SetPositioning(new WorldPosition?(new WorldPosition(this.Mission.Scene, globalFrame3.origin + globalFrame3.rotation.f * 20f * 1.125f + 8f * globalFrame3.rotation.s)));
            this._defMidCav.SetPositioning(new WorldPosition?(new WorldPosition(this.Mission.Scene, globalFrame2.origin - globalFrame2.rotation.f * 20f)));
            this._defRightInf.SetPositioning(new WorldPosition?(new WorldPosition(this.Mission.Scene, globalFrame1.origin + globalFrame1.rotation.f * 20f * 1.125f - 8f * globalFrame1.rotation.s)));
            this._defLeftBInf.SetPositioning(new WorldPosition?(new WorldPosition(this.Mission.Scene, globalFrame3.origin - globalFrame3.rotation.s * 10f)));
            this._defMidBInf.SetPositioning(new WorldPosition?(new WorldPosition(this.Mission.Scene, globalFrame2.origin)));
            this._defRightBInf.SetPositioning(new WorldPosition?(new WorldPosition(this.Mission.Scene, globalFrame1.origin + globalFrame1.rotation.s * 10f)));
            Vec3 vec3_1 = globalFrame5.origin - globalFrame6.origin;
            Vec3 vec3_2 = globalFrame5.origin - globalFrame4.origin;

            this._attLeftInf.SetPositioning(new WorldPosition?(new WorldPosition(this.Mission.Scene, globalFrame6.origin + 0.65f * vec3_1)));
            this._attRightInf.SetPositioning(new WorldPosition?(new WorldPosition(this.Mission.Scene, globalFrame4.origin + 0.65f * vec3_2)));
            this._attLeftRanged.SetPositioning(new WorldPosition?(new WorldPosition(this.Mission.Scene, globalFrame6.origin + globalFrame6.rotation.f * 20f - 0.3f * vec3_1)));
            this._attRightRanged.SetPositioning(new WorldPosition?(new WorldPosition(this.Mission.Scene, globalFrame4.origin + globalFrame4.rotation.f * 20f - 0.3f * vec3_2)));
            this._attLeftCav.SetPositioning(new WorldPosition?(new WorldPosition(this.Mission.Scene, globalFrame6.origin - globalFrame6.rotation.f * 20f * 0.1f - globalFrame6.rotation.s * 25f)));
            this._attRightCav.SetPositioning(new WorldPosition?(new WorldPosition(this.Mission.Scene, globalFrame4.origin - globalFrame4.rotation.f * 20f * 0.1f + globalFrame4.rotation.s * 25f)));
            this._defLeftInf.MovementOrder     = MovementOrder.MovementOrderMove(this._defLeftInf.OrderPosition);
            this._defMidCav.MovementOrder      = MovementOrder.MovementOrderMove(this._defMidCav.OrderPosition);
            this._defRightInf.MovementOrder    = MovementOrder.MovementOrderMove(this._defRightInf.OrderPosition);
            this._defLeftBInf.MovementOrder    = MovementOrder.MovementOrderMove(this._defLeftBInf.OrderPosition);
            this._defMidBInf.MovementOrder     = MovementOrder.MovementOrderMove(this._defMidBInf.OrderPosition);
            this._defRightBInf.MovementOrder   = MovementOrder.MovementOrderMove(this._defRightBInf.OrderPosition);
            this._attLeftInf.MovementOrder     = MovementOrder.MovementOrderMove(this._attLeftInf.OrderPosition);
            this._attRightInf.MovementOrder    = MovementOrder.MovementOrderMove(this._attRightInf.OrderPosition);
            this._attLeftRanged.MovementOrder  = MovementOrder.MovementOrderMove(this._attLeftRanged.OrderPosition);
            this._attRightRanged.MovementOrder = MovementOrder.MovementOrderMove(this._attRightRanged.OrderPosition);
            this._attLeftCav.MovementOrder     = MovementOrder.MovementOrderMove(this._attLeftCav.OrderPosition);
            this._attRightCav.MovementOrder    = MovementOrder.MovementOrderMove(this._attRightCav.OrderPosition);
            foreach (Formation formation in this.Mission.AttackerTeam.Formations)
            {
                formation.ReleaseFormationFromAI();
                formation.FiringOrder = FiringOrder.FiringOrderHoldYourFire;
            }
            foreach (Formation formation in this.Mission.DefenderTeam.Formations)
            {
                formation.ReleaseFormationFromAI();
                formation.FiringOrder = FiringOrder.FiringOrderHoldYourFire;
            }
            this._formationsSetUp = true;
        }
        public static bool Prefix_MoveToLineSegment(
            IEnumerable <Formation> formations,
            Dictionary <Formation, Formation> simulationFormations,
            WorldPosition TargetLineSegmentBegin,
            WorldPosition TargetLineSegmentEnd,
            OnOrderIssuedDelegate OnOrderIssued,
            Dictionary <Formation, float> actualWidths,
            Dictionary <Formation, int> actualUnitSpacings,
            bool isFormationLayoutVertical)
        {
            try
            {
                foreach (Formation formation in formations)
                {
                    if (actualUnitSpacings.TryGetValue(formation, out var num))
                    {
                        formation.SetPositioning(new WorldPosition?(), new Vec2?(), num);
                    }
                    if (actualWidths.TryGetValue(formation, out var customWidth))
                    {
                        formation.FormOrder = FormOrder.FormOrderCustom(customWidth);
                    }
                }
                formations = GetSortedFormations(formations, isFormationLayoutVertical);
                OrderController.SimulateNewOrderWithPositionAndDirection(formations, simulationFormations, TargetLineSegmentBegin, TargetLineSegmentEnd, out var formationChanges, out var isLineShort, isFormationLayoutVertical);
                foreach ((Formation element, int unitSpacingReduction, float customWidth1, Vec2 direction, WorldPosition position) in formationChanges)
                {
                    int   oldUnitSpacing = element.UnitSpacing;
                    float oldWidth       = element.Width;
                    if (unitSpacingReduction > 0)
                    {
                        // change minimum unit spacing from 0 to 1 in circle arrangement.
                        int newUnitSpacing = Math.Max(oldUnitSpacing - unitSpacingReduction,
                                                      element.ArrangementOrder.OrderType == OrderType.ArrangementCircular ? 1 : 0);
                        element.SetPositioning(new WorldPosition?(), new Vec2?(), newUnitSpacing);
                        if (element.UnitSpacing != oldUnitSpacing)
                        {
                            actualUnitSpacings[element] = oldUnitSpacing;
                        }
                    }
                    if (Math.Abs(element.Width - (double)customWidth1) > 0.1f)
                    {
                        element.FormOrder = FormOrder.FormOrderCustom(customWidth1);
                        if (isLineShort)
                        {
                            actualWidths[element] = oldWidth;
                        }
                    }
                    if (!isLineShort)
                    {
                        element.MovementOrder = MovementOrder.MovementOrderMove(position);
                        element.FacingOrder   = FacingOrder.FacingOrderLookAtDirection(direction);
                        element.FormOrder     = FormOrder.FormOrderCustom(customWidth1);
                        if (OnOrderIssued != null)
                        {
                            IEnumerable <Formation> singleFormation = Enumerable.Repeat(element, 1);
                            OnOrderIssued(OrderType.Move, singleFormation, (object)position);
                            OnOrderIssued(OrderType.LookAtDirection, singleFormation, (object)direction);
                            OnOrderIssued(OrderType.FormCustom, singleFormation, (object)customWidth1);
                        }
                    }
                    else
                    {
                        Formation largestFormation = formations.MaxBy(f => f.CountOfUnitsWithoutDetachedOnes);
                        switch (OrderController.GetActiveFacingOrderOf(largestFormation))
                        {
                        case OrderType.LookAtEnemy:
                            element.MovementOrder = MovementOrder.MovementOrderMove(position);
                            if (OnOrderIssued != null)
                            {
                                IEnumerable <Formation> local_20 = Enumerable.Repeat(element, 1);
                                OnOrderIssued(OrderType.Move, local_20, (object)position);
                                OnOrderIssued(OrderType.LookAtEnemy, local_20, Array.Empty <object>());
                            }
                            continue;

                        case OrderType.LookAtDirection:
                            element.MovementOrder = MovementOrder.MovementOrderMove(position);
                            element.FacingOrder   = FacingOrder.FacingOrderLookAtDirection(direction);
                            if (OnOrderIssued != null)
                            {
                                IEnumerable <Formation> local_21 = Enumerable.Repeat(element, 1);
                                OnOrderIssued(OrderType.Move, local_21, (object)position);
                                OnOrderIssued(OrderType.LookAtDirection, local_21, (object)largestFormation.Direction);
                            }
                            continue;

                        default:
                            continue;
                        }
                    }
                }

                return(false);
            }
            catch (Exception)
            {
                return(true);
            }
        }
Пример #9
0
        public static void showOrder()
        {
            FormOrder form = new FormOrder();

            form.Show();
        }