コード例 #1
0
        private void ResetDefenseTarget()
        {
            Dictionary <MiningPlatform, float> PlatformScores = new Dictionary <MiningPlatform, float>();

            foreach (UnitBasic u in FactionManager.SortedUnits[Parent.ParentController.ParentShip.GetTeam()])
            {
                if (u.GetType().IsSubclassOf(typeof(MiningPlatform)))
                {
                    MiningPlatform m = (MiningPlatform)u;
                    if (!PlatformScores.ContainsKey(m))
                    {
                        PlatformScores.Add(m, 0);

                        foreach (UnitBasic u2 in FactionManager.SortedUnits[Parent.ParentController.ParentShip.GetTeam()])
                        {
                            if (u2.GetType().IsSubclassOf(typeof(UnitTurret)))
                            {
                                UnitTurret t2 = (UnitTurret)u2;
                                if (t2.IsAlly(Parent.ParentController.ParentShip) && !t2.Dead)
                                {
                                    PlatformScores[m] += Vector2.Distance(t2.Position.get(), m.Position.get());
                                }
                            }
                        }
                    }
                }
            }

            MiningPlatform forwardPlatform = PathFindingManager.TraceToMiningPlatform(NeutralManager.GetSpawnPosition(),
                                                                                      Parent.ParentController.ParentShip.GetTeam());

            if (forwardPlatform != null && PlatformScores.ContainsKey(forwardPlatform))
            {
                PlatformScores[forwardPlatform] *= 2;
            }

            float BestScore = 0;

            foreach (MiningPlatform m in PlatformScores.Keys)
            {
                if (PlatformScores[m] > BestScore)
                {
                    CurrentDefenseTarget = m;
                    BestScore            = PlatformScores[m];
                }
            }

            DefenseLocation = PathFindingManager.TraceCellPoint(CurrentDefenseTarget.Position.get(), 10);
        }