Exemple #1
0
        protected override void Strike(Vector2 Position)
        {
            Basic2DScene scene = (Basic2DScene)GameManager.GetLevel().getCurrentScene();

            foreach (UnitTurret t in scene.Enumerate(typeof(UnitTurret)))
            {
                t.Destroy();
            }

            /*
             * float BulletExplosionDistance = 200;
             * QuadGrid grid = scene.quadGrids.First.Value;
             *
             * for (int i = 0; i < 2; i++)
             *  foreach (Basic2DObject o in grid.Enumerate(Position, new Vector2(BulletExplosionDistance * 2)))
             *      if (o.GetType().IsSubclassOf(typeof(BasicShipGameObject)))
             *      {
             *          BasicShipGameObject s = (BasicShipGameObject)o;
             *          float dist = Vector2.Distance(s.Position.get(), Position) - o.Size.X() / 2;
             *
             *          if (dist < BulletExplosionDistance && s.GetType().IsSubclassOf(typeof(UnitTurret)))
             *          {
             *              UnitTurret t = (UnitTurret)s;
             *              t.Destroy();
             *          }
             *      }
             */
            base.Strike(Position);
        }
Exemple #2
0
        public CameraControls2D(Basic2DScene ParentScene)
        {
#if EDITOR && WINDOWS
            this.TopRightCorner = new Vector2(WorldViewer.self.Size.X, 0);
            this.ParentScene    = ParentScene;
#endif
        }
Exemple #3
0
        public void ApplySnap(bool ApplyToChildren)
        {
            if (ParentScene != null && ParentScene.GetType().IsSubclassOf(typeof(Basic2DScene)))
            {
                Basic2DScene s = (Basic2DScene)ParentScene;
                if (s.GridSize != null)
                {
                    Vector2 GridSize = s.GridSize.get();
                    Vector2 Pos      = Position.get();

                    Position.set(new Vector2((float)Math.Round(Position.get().X / s.GridSize.get().X),
                                             (float)Math.Round(Position.get().Y / s.GridSize.get().Y)) * s.GridSize.get());
                }
            }

            if (ApplyToChildren)
            {
                foreach (GameObject g in HierarchyChildren)
#if EDITOR && WINDOWS
                { if (!ParentLevel.LevelForEditing || !g.EditorSelected)
#endif
                { if (g.GetType().IsSubclassOf(typeof(Basic2DObject)))
                  {
                      Basic2DObject b = (Basic2DObject)g;
                      b.ApplySnap(true);
                  }
                }
            }
        }
Exemple #4
0
 private void PositionChange()
 {
     if (ParentScene != null && ParentScene.GetType().IsSubclassOf(typeof(Basic2DScene)))
     {
         Basic2DScene s = (Basic2DScene)ParentScene;
         if (s.UseGrid.get())
         {
             ApplySnap(false);
         }
     }
 }
Exemple #5
0
        public override void Create()
        {
            CellsX    = new IntValue("CellsX", 100);
            CellsY    = new IntValue("CellsY", 100);
            CellGrid  = new int[100, 100];
            CellAlpha = new float[100, 100];

            CellsX.ChangeEvent = CellsChange;
            CellsY.ChangeEvent = CellsChange;

            AddTag(GameObjectTag.Update);
            AddTag(GameObjectTag._2DOverDraw);

            base.Create();

            Parent2DScene = (Basic2DScene)ParentScene;
            Divisor       = (Parent2DScene.MaxBoundary.get() - Parent2DScene.MinBoundary.get()) / new Vector2(CellsX.get(), CellsY.get());
        }
        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);
        }
 public override void Update(GameTime gameTime)
 {
     /*
      * SparkTimer += gameTime.ElapsedGameTime.Milliseconds;
      * if (SparkTimer > MaxSparkTimer.get())
      * {
      *  SparkTimer -= MaxSparkTimer.get();
      *  ParentLevel.AddObject(new PathfindingFlare(PathFindingManager.self, Rand.r.Next(PathFindingManager.self.CellsX.get()),
      *      Rand.r.Next(PathFindingManager.self.CellsX.get()), 0, 0, Color.getAsColor()));
      * }*/
     if (!WaveFSM.WaveStepState.WeaponsFree)
     {
         Basic2DScene Parent2DScene = (Basic2DScene)ParentScene;
         Vector2      p             = NeutralManager.GetSpawnPosition();
         ParentLevel.AddObject(new PathfindingFlare(PathFindingManager.self,
                                                    (int)((p.X - Parent2DScene.MinBoundary.X()) / PathFindingManager.self.Divisor.X),
                                                    (int)((p.Y - Parent2DScene.MinBoundary.Y()) / PathFindingManager.self.Divisor.Y),
                                                    0, 0, Color.getAsColor()));
     }
     base.Update(gameTime);
 }
Exemple #8
0
        public override void Create()
        {
            Position = new Vector2Value("Position", EditType.Average);

            Size     = new Vector2Value("Size", Vector2.One, EditType.Scalar);
            Rotation = new FloatValue("Angle", RotationChange);
            MoveValuetoFront(Position, Size, Rotation);


#if EDITOR && WINDOWS
            if (ParentScene != null && ParentScene.GetType().IsSubclassOf(typeof(Basic2DScene)))
            {
                Basic2DScene s = (Basic2DScene)ParentScene;
                if (s.GridSize != null)
                {
                    Size.set(s.GridSize.get());
                }
            }
#endif

            base.Create();
        }
        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);
        }
Exemple #10
0
 public ObjectControls2D(Basic2DScene ParentScene)
 {
     this.ParentScene = ParentScene;
 }
Exemple #11
0
 public override void SetParents(Level ParentLevel, SceneObject ParentScene)
 {
     Parent2DScene = ParentScene.GetType().IsSubclassOf(typeof(Basic2DScene)) || ParentScene.GetType().Equals(typeof(Basic2DScene)) ?
                     (Basic2DScene)ParentScene : null;
     base.SetParents(ParentLevel, ParentScene);
 }