コード例 #1
0
        public bool TestFree(Vector2 Position, float Size, int FactionNumber)
        {
            Basic2DScene Parent2DScene = (Basic2DScene)GameManager.GetLevel().getCurrentScene();
            QuadGrid     quad          = Parent2DScene.quadGrids.First.Value;

            foreach (UnitBasic o in FactionManager.SortedUnits[FactionManager.GetTeam(FactionNumber)])
            {
                if (o.GetType().IsSubclassOf(typeof(UnitBuilding)))
                {
                    UnitBuilding s = (UnitBuilding)o;
                    if (Vector2.Distance(Position, o.Position.get()) < (Size + o.Size.X()))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
コード例 #2
0
        public virtual Vector2 GetPlacePosition(int FactionNumber)
        {
            float   BestScore    = -500000;
            Vector2 BestPosition = Vector2.Zero;

            float Distance = 1000;
            float JumpSize = 100;

            Vector2 MinPos = new Vector2(10000);
            Vector2 MaxPos = new Vector2(-10000);

            foreach (MiningPlatform m in GameManager.GetLevel().getCurrentScene().Enumerate(typeof(MiningPlatform)))
            {
                if (m.GetTeam() == FactionManager.GetTeam(FactionNumber) && !m.Dead)
                {
                    MinPos = Vector2.Min(MinPos, m.Position.get() - new Vector2(Distance));
                    MaxPos = Vector2.Max(MaxPos, m.Position.get() + new Vector2(Distance));
                }
            }

            Basic2DScene b = (Basic2DScene)GameManager.GetLevel().getCurrentScene();

            MinPos = Vector2.Max(MinPos, b.MinBoundary.get());
            MaxPos = Vector2.Min(MaxPos, b.MaxBoundary.get());

            for (float x = MinPos.X; x < MaxPos.X; x += JumpSize)
            {
                for (float y = MinPos.Y; y < MaxPos.Y; y += JumpSize)
                {
                    if (TestFree(new Vector2(x, y), TurretSize, FactionNumber) &&
                        PathFindingManager.GetCellValue(new Vector2(x, y)) != PathFindingManager.DeadCell)
                    {
                        float score = 5000;

                        if (GetTurretFragility() != 0)
                        {
                            if (PathFindingManager.CollisionLine(new Vector2(x, y), 1, 0, 3))
                            {
                                score += 100 * GetTurretFragility();
                            }
                            if (PathFindingManager.CollisionLine(new Vector2(x, y), -1, 0, 3))
                            {
                                score += 100 * GetTurretFragility();
                            }
                            if (PathFindingManager.CollisionLine(new Vector2(x, y), 0, 1, 3))
                            {
                                score += 100 * GetTurretFragility();
                            }
                            if (PathFindingManager.CollisionLine(new Vector2(x, y), 0, -1, 3))
                            {
                                score += 100 * GetTurretFragility();
                            }

                            if (PathFindingManager.CollisionLine(new Vector2(x, y), -1, -1, 2))
                            {
                                score += 100 * GetTurretFragility();
                            }
                            if (PathFindingManager.CollisionLine(new Vector2(x, y), 1, -1, 2))
                            {
                                score += 100 * GetTurretFragility();
                            }
                            if (PathFindingManager.CollisionLine(new Vector2(x, y), -1, 1, 2))
                            {
                                score += 100 * GetTurretFragility();
                            }
                            if (PathFindingManager.CollisionLine(new Vector2(x, y), 1, 1, 2))
                            {
                                score += 100 * GetTurretFragility();
                            }
                        }

                        foreach (NeutralSpawn spawn in NeutralManager.SpawnList)
                        {
                            if (PathFindingManager.GetCellValue(spawn.Position.get()) > PathFindingManager.StartingCell - 50 &&
                                PathFindingManager.GetCellValue(spawn.Position.get()) < PathFindingManager.StartingCell - 20 &&
                                PathFindingManager.GetAreaClear(spawn.Position.get()))
                            {
                                if (GetTurretFragility() != 0 && PathFindingManager.CollisionLine(new Vector2(x, y), spawn.Position.get()))
                                {
                                    score += 500 * GetTurretFragility();
                                }

                                if (score > BestScore)
                                {
                                    MiningPlatform NearestMiningPlatform = null;
                                    float          NearestDistance       = 10000;

                                    foreach (MiningPlatform m2 in GameManager.GetLevel().getCurrentScene().Enumerate(typeof(MiningPlatform)))
                                    {
                                        if (m2.GetTeam() == FactionManager.GetTeam(FactionNumber) && !m2.Dead)
                                        {
                                            float d = Vector2.Distance(m2.Position.get(), spawn.Position.get());
                                            if (d < NearestDistance)
                                            {
                                                NearestDistance       = d;
                                                NearestMiningPlatform = m2;
                                            }
                                        }
                                    }

                                    score -= Logic.DistanceLineSegmentToPoint(spawn.Position.get(),
                                                                              NearestMiningPlatform.Position.get(), new Vector2(x, y)) * GetTurretAgression();
                                }
                            }
                        }

                        if (score > BestScore)
                        {
                            Basic2DScene Parent2DScene = (Basic2DScene)GameManager.GetLevel().getCurrentScene();
                            QuadGrid     quad          = Parent2DScene.quadGrids.First.Value;

                            foreach (Basic2DObject o in quad.Enumerate(new Vector2(x, y), new Vector2(200)))
                            {
                                if (o.GetType().IsSubclassOf(typeof(UnitBuilding)))
                                {
                                    UnitBuilding s = (UnitBuilding)o;
                                    if (s.GetTeam() == FactionManager.GetTeam(FactionNumber))
                                    {
                                        float d = Vector2.Distance(o.Position.get(), new Vector2(x, y));
                                        if (d < 2000)
                                        {
                                            score -= (2000 - d) * GetBuildingAvoidence();
                                            if (s.GetType().IsSubclassOf(typeof(MiningPlatform)))
                                            {
                                                score -= (2000 - d) * GetBaseAvoidence();
                                            }
                                            else if (s.GetType().IsSubclassOf(typeof(UnitTurret)))
                                            {
                                                UnitTurret t = (UnitTurret)s;
                                                if (t.MyCard != null)
                                                {
                                                    if (t.MyCard.StrongVs.Equals(StrongVs))
                                                    {
                                                        score -= (2000 - d) * GetTurretAvoidence();
                                                    }
                                                }
                                                else
                                                {
                                                    if (StrongVs.Equals("Heavy"))
                                                    {
                                                        score -= (2000 - d) * GetTurretAvoidence();
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                            if (score > BestScore)
                            {
                                BestScore    = score;
                                BestPosition = new Vector2(x, y);
                            }
                        }
                    }
                }
            }

            return(BestPosition);
        }
コード例 #3
0
        public override void Update(GameTime gameTime)
        {
            if (!Dead)
            {
                if (ShutDownTime > 0 || VirusTime > 0)
                {
                    ShutDownTime = 0;
                    VirusTime    = 0;
                }
                else
                {
                    SearchTime += gameTime.ElapsedGameTime.Milliseconds;

                    if (SearchTime > ProtectionSearchTime)
                    {
                        SearchTime -= ProtectionSearchTime;

                        bool     Found            = false;
                        QuadGrid quad             = Parent2DScene.quadGrids.First.Value;
                        float    NewHealingAmount = HealingAmount;
                        NewHealingAmount -= Heal(HealingAmount) / HealingAmount * HealingReduction;

                        foreach (Basic2DObject o in quad.Enumerate(Position.get(), new Vector2(MaxEngagementDistance * 2)))
                        {
                            if (o.GetType().IsSubclassOf(typeof(UnitBuilding)))
                            {
                                UnitBuilding s = (UnitBuilding)o;
                                if (!s.Dead && s.IsAlly(this) && Vector2.Distance(Position.get(), o.Position.get()) < MaxEngagementDistance)
                                {
                                    if (s.CanBeTargeted())
                                    {
                                        NewHealingAmount -= s.Heal(HealingAmount) / HealingAmount * HealingReduction;
                                    }

                                    Found = true;
                                }
                            }
                        }

                        if (Found)
                        {
                            HealingAmount = NewHealingAmount;

                            SoundManager.Play3DSound("Healing",
                                                     new Vector3(Position.X(), Y, Position.Y()),
                                                     0.75f, 800, 2);

                            Vector3 Position3 = new Vector3(Position.X(), 0, Position.Y());
                            for (int i = 0; i < 30; i++)
                            {
                                ParticleManager.CreateParticle(Position3, Rand.V3() * MaxEngagementDistance / 1000f * 3, ParticleColor, 40, 5);
                            }

                            for (int i = 0; i < 2; i++)
                            {
                                ParticleManager.CreateParticle(Position3, Vector3.Zero, ParticleColor, MaxEngagementDistance * 2, 5);
                                ParticleManager.CreateParticle(Position3, Vector3.Zero, ParticleColor, MaxEngagementDistance * 1, 4);
                            }
                        }
                    }
                }
            }
            base.Update(gameTime);
        }