Exemplo n.º 1
0
 public void ApplyExercise()
 {
     if (IsTargetPlanetFeasible())
     {
         mParent.AggressiveMove(mUnit, mNextPlanet.Position);
     }
     else
         mNextPlanet = GetNextPlanet();
 }
Exemplo n.º 2
0
        public void ApplyExercise()
        {
            CheckOrRecruitGuards();
            // TODO check for other DS nearby
            Point sector = mParent.mUnitSectorManager.GetSector(mUnit.Position);
            List<IVisible> nearbyUnits = mParent.mUnitSectorManager.GetUnitsAndSurroundings(sector.X, sector.Y, 1);

            int playerDsCounter = mParent.mUnitSectorManager.GetSurroundingPlayerCount(sector.X,
                                                                 sector.Y, 1, typeof(DeathStar));
            if (playerDsCounter > 0)
            {
                DeathStar playerDs = null;
                foreach (IVisible unit in nearbyUnits)
                {
                    if (unit.Allegiance == Allegiance.Player && unit is DeathStar)
                        playerDs = (DeathStar)unit;
                }
                //Debug.Assert(playerDs != null);
                if (playerDs != null && playerDs.MinionCount > 0)
                {
                    mUnit.AttackMinionContainer(playerDs);
                    return;
                }
            }

            if (IsPlanetTargetFeasible())
            {
                // Check if Planet is in range
                if (nearbyUnits.Contains(mPlanetTarget) &&
                    (mUnit.Position-mPlanetTarget.Position).Length() < mUnit.LineOfSight)
                {
                    Debug.WriteLine("DS: Planet target in range!");
                    mUnit.AttackMinionContainer(mPlanetTarget);
                    // check if target can be conquered
                    if (mPlanetTarget.MinionCount == 0 && mUnit.MinionCount > 0)
                        GameObjectManager.GetInstance().MoveMinions(mUnit, mPlanetTarget);
                }
                // else move to target
                else
                    mParent.AggressiveMove(mUnit, mPlanetTarget.Position);
            }
            else
            {
                mUnit.Halt();
                mPlanetTarget = GetNextPlanet();
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Upgrades the Planet to a Deathstar
 /// </summary>
 /// <param name="planet"></param>
 /// <returns>bool: depending on whether the upgrade ws successful or not</returns>
 public bool UpgradeToDeathStar(Planet planet)
 {
     if (planet.DeductDeathstarUpgradeCost() && !HasDeathStar(planet.Allegiance))
       {
     planet.Alive = false;
     RemoveGameObject(planet);
     planet.LinkToDeathStar = CreateDeathStar(planet.Position, planet.Allegiance, planet.MinionCount);
     SetHasDeathStar(true, planet.Allegiance);
     return true;
       }
       return false;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Upgrades the Planet to get the Starfleet Academy upgrade
 /// </summary>
 /// <param name="planet"></param>
 /// <returns>bool: depending on whether the upgrade was successful or not</returns>
 public bool UpgradeStarfleetAcademy(Planet planet)
 {
     return planet.UpgradeStarfleetAcademy();
 }
Exemplo n.º 5
0
 /// <summary>
 /// Upgrades the Planet to become a Satelite Station
 /// </summary>
 /// <param name="planet"></param>
 /// <returns>bool: depending on whether the upgrade was successful or not</returns>
 public bool UpgradeSateliteStation(Planet planet)
 {
     //CreateSatellite(planet);
       return planet.UpgradeSateliteStation();
 }
Exemplo n.º 6
0
 /// <summary>
 /// Upgrades the Planet to get the Planetary shield upgrade
 /// </summary>
 /// <param name="planet"></param>
 /// <returns>bool: depending on whether the upgrade was successful or not</returns>
 public bool UpgradePlanetaryShield(Planet planet)
 {
     return planet.UpgradePlanetaryShield();
 }
Exemplo n.º 7
0
        /// <summary>
        /// Get a Upgrade
        /// </summary>
        /// <param name="planet">Planet Object</param>
        /// <param name="index">Index of the Upgrade</param>
        /// <returns></returns>
        private Upgrade GetUpgrade(Planet planet, int index)
        {
            // StarfleetAcademy
              if (index == 0)
            return new Upgrade
               {
                 mTexture = mUpgradeAcademy,
                 mAvailable = planet.StarfleetAcademyAvailable,
                 mDescription = "Ermöglicht das Entwickeln von Kriegsschiffen",
                 mTyp =
                   "Piloten-Ausbildungslager | (Kosten: " + GlobalValues.GetInstance().StarfleetAcademyUpgradeCost +
                   ", HotKey: X) "
               };
             // MinionBooster
              if (index == 1)
            return new Upgrade
               {
                 mTexture = mUpgradeBooster,
                 mAvailable = planet.MinionBoostUpgradeAvailable,
                 mDescription = "Erhöht die Minion-Produktionsrate des Planeten",
                 mTyp =
                   "Minion-Booster: " +
                   (GlobalValues.GetInstance().MinionBoostIncrementMultiplier *
                    GlobalValues.GetInstance().MinionIncrementPerSecond[planet.PlanetSize]) +
                   " Minions pro Sekunde | (Kosten: " + GlobalValues.GetInstance().MinionBoostUpgradeCost +
                   ", HotKey: C)"
               };
              // SateliteStation
              if (index == 2)
            return new Upgrade
               {
                 mTexture = mUpgradeRadar,
                 mAvailable = planet.SateliteStationUpgradeAvailable,
                 mDescription = "Erhöht das Sichtfeld des Planeten",
                 mTyp =
                   "Sataliten-Station: " +
                   (GlobalValues.GetInstance().SateliteStationLineOfSightIncrement +
                    GlobalValues.GetInstance().PlanetLineOfSight) +
                   "psec | (Kosten: " + GlobalValues.GetInstance().SateliteStationUpgradeCost + ", HotKey: V)"
               };
             // Shield
              if (index == 3)
            return new Upgrade
               {
                 mTexture = mUpgradeShiled,
                 mAvailable = planet.PlanetaryShieldUpgradeAvailable,
                 mDescription = "Ein Schutzschild, der bei Eroberung zuerst durch Minions zerstört werden muss",
                 mTyp =
                   "Schutzschild: " + GlobalValues.GetInstance().PlanetaryShieldShieldValue + " Einheiten | (Kosten: " +
                   GlobalValues.GetInstance().PlanetaryShieldUpgradeCost + ", HotKey: B)"
               };
             // DeathStar
              if (index == 4)
            return new Upgrade
               {
                 mTexture = mUpgradeDeathStar,
                 mAvailable = planet.DeathStarUpgradeAvailable,
                 mDescription = "Entwickelt den Planeten zu einem Deathstar",
                 mTyp = "Deathstar: " + GlobalValues.GetInstance().DeathStarAttackDamage + " Angriff, " +
                        GlobalValues.GetInstance().DeathStarAttackRange + " Reichweite, " +
                        GlobalValues.GetInstance().DeathStarSpeed + " Geschwindigkeit | (Kosten: " +
                        GlobalValues.GetInstance().DeathStarUpgradeCost + ", HotKey: N)"
               };

             // Interceptor
              if (index == 5)
            return new Upgrade
               {
                 mAvailable = planet.InterceptorProductionAvailable,
                 mTexture = mInterceptorPicto,
                 mDescription = "Standarteinheit",
                 mTyp = "Interceptor: " + GlobalValues.GetInstance().InterceptorAttackDamage + " Angriff, " +
                        GlobalValues.GetInstance().InterceptorAttackRange + " Reichweite, " +
                        GlobalValues.GetInstance().InterceptorSpeed + " Geschwindigkeit | (Kosten: " +
                        GlobalValues.GetInstance().InterceptorProductionCost + ", HotKey: 1)"
               };
             // Predator
              if (index == 6)
            return new Upgrade
               {
                 mTexture = mPredatorPicto,
                 mAvailable = planet.PredatorProductionAvailable,
                 mDescription = "Schnelle Erkungungseinheit",
                 mTyp = "Predator: " + GlobalValues.GetInstance().PredatorAttackDamage + " Angriff, " +
                        GlobalValues.GetInstance().PredatorAttackRange + " Reichweite, " +
                        GlobalValues.GetInstance().PredatorSpeed + " Geschwindigkeit | (Kosten: " +
                        GlobalValues.GetInstance().PredatorProductionCost + ", HotKey: 2)"
               };
             // Defender
              if (index == 7)
            return new Upgrade
               {
                 mTexture = mDefenderPicto,
                 mAvailable = planet.DefenderProductionAvailable,
                 mDescription = "Stark bewaffnete Verteidigungseinheit",
                 mTyp = "Defender: " + GlobalValues.GetInstance().DefenderAttackDamage + " Angriff, " +
                        GlobalValues.GetInstance().DefenderAttackRange + " Reichweite, " +
                        GlobalValues.GetInstance().DefenderSpeed + " Geschwindigkeit | (Kosten: " +
                        GlobalValues.GetInstance().DefenderProductionCost + ", HotKey: 3)"
               };

             // If no Upgrade found, return a empty upgrade
              return new Upgrade();
        }
Exemplo n.º 8
0
        /// <summary>
        /// Returns a map instance with objCount many random-placed planets
        /// </summary>
        /// <param name="objCount">number of planets to create</param>
        /// <param name="width">map width</param>
        /// <param name="height">map height</param>
        /// <returns>new map instance</returns>
        public static Map GetRandomInstance(int objCount , int width , int height)
        {
            var map = new Map(width, height);

              // create randomly game objects on the map
              var r = new Random();
               for (int i = 0; i<objCount; i++)
              {
              int x = r.Next(width);
              int y = r.Next(height);
              var planet = new Planet(new Vector2(x, y), Allegiance.Player, PlanetSize.Large, 100);
              map.mInitialGameObjects.Add(planet);
              }
              return map;
        }
Exemplo n.º 9
0
 public bool CreateDefender(Planet planet, Allegiance allegiance)
 {
     if (planet.DeductDefenderCost())
       {
     var defender = mGameObjectFactory.CreateSpaceship(planet, allegiance, GameObjectType.Defender);
     AddUnit(defender);
     return true;
       }
       return false;
 }
Exemplo n.º 10
0
 public BlockEnemyPlanet(SpaceshipAi parent, Planet planet)
 {
     Debug.Assert(planet.Allegiance == Allegiance.Player);
     mPlanet = planet;
     mParent = parent;
 }
Exemplo n.º 11
0
 public Planet CreatePlanet(Vector2 position, Allegiance allegiance, PlanetSize size, int numberOfMinions)
 {
     var unit = new Planet(position, allegiance, size, numberOfMinions);
       return unit;
 }
Exemplo n.º 12
0
 /// <summary>
 /// Contains all the logic for the creation of a spaceship if it is being built near a planet.
 /// As of now the position of the interceptor next to the planet is random. 
 /// </summary>
 /// <param name="planet"></param>
 /// <param name="allegiance"></param>
 /// <param name="type"></param>
 /// <returns></returns>
 public GameObject CreateSpaceship(Planet planet, Allegiance allegiance, GameObjectType type)
 {
     var random = new Random();
       var randomDirectionVector = (new Vector2( (float)random.NextDouble()-0.5f, (float)random.NextDouble() - 0.5f));
       if (randomDirectionVector.Equals(new Vector2(0,0)))
       randomDirectionVector = new Vector2(0,1);
       Vector2 spaceshipPosition = PathFinder.GetInstance().GetFreePosAroundObstruction(planet,
       HelperMethods.GetAbsoluteVectorAngle(randomDirectionVector), typeof(Spaceship));
       return CreateSpaceship(spaceshipPosition, allegiance, type);
 }
Exemplo n.º 13
0
 /// <summary>
 /// If there are minions incomming. Use this method to reduce/ increase the number of minions, that are on this MinionContainer.
 /// </summary>
 /// <param name="incomingMinions"></param>
 /// <param name="allegiance"></param>
 public void ProcessIncomingMinions(int incomingMinions, Allegiance allegiance)
 {
     if (!Alive)
       {
     mNewPlanet.ProcessIncomingMinions(incomingMinions, allegiance);
     return;
       }
       if (Allegiance == allegiance) MinionCount += incomingMinions;
       else
       {
     if (Shield >= incomingMinions)
       Shield -= incomingMinions;
     else if ((Shield + MinionCount) >= incomingMinions)
       MinionCount -= incomingMinions - Shield;
     else
     {
       Alive = false;
       MinionCount = incomingMinions - (MinionCount + Shield);
       mNewPlanet = (Planet)GameObjectManager.GetInstance().ChangeMinionContainerAllegiance(this, allegiance);
     }
       }
 }
Exemplo n.º 14
0
        // ReSharper restore UnusedMember.Local
        // ReSharper disable UnusedMember.Local
        // Sometimes I want to call this test for debugging, so it's okay that it's currently
        // not used.
        private static void ModifyMeshTest()
        {
            /*{
                PathFinder.GetInstance().ClearObstructions();
                int oldScale = GlobalValues.GetInstance().MeshScale;
                GlobalValues.GetInstance().MeshScale = 1;
                Map map1 = new Map(6, 6);
                GameLogic.GetInstance().SetMap(map1);
                NavigationMesh mesh = NavigationMesh.GetTestInstance(1, 1, 6, 6, false);
                mesh.CheckIntegrity();
                PathFinder.GetInstance().SetMesh(mesh);
                Obstruction obstruction = new Obstruction(new Vector2(3, 3), 0);
                PathFinder.GetInstance().AddObstruction(obstruction);
                mesh = PathFinder.GetInstance().GetMesh();
                mesh.CheckIntegrity();
                PathFinder.GetInstance().RemoveObstruction(obstruction);
                mesh = PathFinder.GetInstance().GetMesh();
                mesh.CheckIntegrity();
                GlobalValues.GetInstance().MeshScale = oldScale;
                GameLogic.GetInstance().GetGameStateManager().UnloadGame();
            }
            // ******************* Next test ***********************
            {
                PathFinder.GetInstance().ClearObstructions();
                int oldScale = GlobalValues.GetInstance().MeshScale;
                GlobalValues.GetInstance().MeshScale = 1;
                Map map2 = new Map(8, 8);
                GameLogic.GetInstance().SetMap(map2);
                List<MeshNode> nodes = new List<MeshNode>();
                List<Polygon> polygons = new List<Polygon>();
                polygons.Add(Polygon.CreateRectInstance(new Rectangle(0, 0, 3, 3), nodes, polygons));
                polygons.Add(Polygon.CreateRectInstance(new Rectangle(3, 0, 2, 2), nodes, polygons));
                polygons.Add(Polygon.CreateRectInstance(new Rectangle(5, 0, 3, 3), nodes, polygons));
                polygons.Add(Polygon.CreateRectInstance(new Rectangle(3, 2, 2, 1), nodes, polygons));
                polygons.Add(Polygon.CreateRectInstance(new Rectangle(0, 3, 2, 2), nodes, polygons));
                polygons.Add(Polygon.CreateRectInstance(new Rectangle(2, 3, 1, 2), nodes, polygons));
                polygons.Add(Polygon.CreateRectInstance(new Rectangle(3, 3, 2, 2), nodes, polygons));
                polygons.Add(Polygon.CreateRectInstance(new Rectangle(5, 3, 1, 2), nodes, polygons));
                polygons.Add(Polygon.CreateRectInstance(new Rectangle(6, 3, 2, 2), nodes, polygons));
                polygons.Add(Polygon.CreateRectInstance(new Rectangle(0, 5, 3, 3), nodes, polygons));
                polygons.Add(Polygon.CreateRectInstance(new Rectangle(3, 5, 2, 1), nodes, polygons));
                polygons.Add(Polygon.CreateRectInstance(new Rectangle(5, 5, 3, 3), nodes, polygons));
                polygons.Add(Polygon.CreateRectInstance(new Rectangle(3, 6, 2, 2), nodes, polygons));
                foreach (Polygon p in polygons) p.ImposeOwnership();
                NavigationMesh mesh = new NavigationMesh(polygons, 8, 8);
                PathFinder.GetInstance().SetMesh(mesh);
                mesh.CheckIntegrity();
                PathFinder.GetInstance().AddObstruction(new Obstruction(new Vector2(4, 4), 0));
                mesh = PathFinder.GetInstance().GetMesh();
                mesh.CheckIntegrity();
                List<MeshNode> singleUsedMeshNodes = new List<MeshNode>();
                foreach (Polygon p in mesh.GetPolygons())
                {
                    foreach (MeshNode m in p.GetNodes())
                    {
                        if (m.mPolyOwners.Count < 2) singleUsedMeshNodes.Add(m);
                    }
                }
                Debug.Assert(singleUsedMeshNodes.Count == 4);
                GlobalValues.GetInstance().MeshScale = oldScale;
                GameLogic.GetInstance().GetGameStateManager().UnloadGame();
            }
            // ******************* Next test ***********************
            {
            }*/
            // ******************* Next test ***********************
            {
                PathFinder.GetInstance().ClearObstructions();
                int width = 5000;
                int height = 5000;
                Map map = new Map(width, height);
                NavigationMesh[] mesh = NavigationMeshFactory.GetTestInstance(500, 500, 10, 10, false);
                PathFinder.GetInstance().SetMesh(mesh);
                GameLogic.GetInstance().SetMap(map);
                Random random = new Random();
                List<Planet> planetList = new List<Planet>();

                Debug.WriteLine("ModifyMeshTest will add obstructions with "+GlobalValues.GetInstance().MeshScale+" granularity...");
                for (int i = 0; i < 10; i++)
                {
                    sParent.DrawNow();

                    int x = random.Next(width+1);
                    int y = random.Next(height+1);
                    int planetSizeInt = random.Next(3);
                    PlanetSize planetSize = PlanetSize.Small;
                    switch (planetSizeInt)
                    {
                        case 0:
                            planetSize = PlanetSize.Small;
                            break;
                        case 1:
                            planetSize = PlanetSize.Medium;
                            break;
                        case 2:
                            planetSize = PlanetSize.Large;
                            break;
                    }
                    if (i == 2)
                        Debug.WriteLine("Achtung!");
                    Planet planet = new Planet(new Vector2(x, y), Allegiance.Player, planetSize, 0);
                    GameObjectManager.GetInstance().AddUnit(planet);
                    planetList.Add(planet);
                    Debug.WriteLine("----- "+i+"th added.");
                }
                Debug.WriteLine("Adding obstructions finished. Now removing them...");
                foreach (Planet p in planetList)
                {
                    GameObjectManager.GetInstance().RemoveGameObject(p);
                    Debug.WriteLine("---One removed.---");
                }
                //GameObjectManager.GetInstance().AddUnit(new Interceptor(new Vector2(3700, 2000), Allegiance.Player));
                GameLogic.GetInstance().GetGameStateManager().UnloadGame();
            }
        }
Exemplo n.º 15
0
 private List<Servant> GetOwnPlanetGuards(Planet planet)
 {
     List<Servant> result = new List<Servant>();
     foreach (Servant servant in mAiServants)
     {
         IExercise exercise = servant.mExercise;
         if (exercise is GuardOwnPlanet && ((GuardOwnPlanet)exercise).mPlanet == planet)
             result.Add(servant);
     }
     return result;
 }
Exemplo n.º 16
0
 private List<Servant> GetPlanetBlockers(Planet planet)
 {
     List<Servant> result = new List<Servant>();
     foreach (Servant servant in mAiServants)
     {
         IExercise exercise = servant.mExercise;
         if (exercise is BlockEnemyPlanet && ((BlockEnemyPlanet)exercise).mPlanet == planet)
             result.Add(servant);
     }
     return result;
 }
Exemplo n.º 17
0
 // The following are being passed to the factory
 public bool CreateInterceptor(Planet planet, Allegiance allegiance)
 {
     if (planet.DeductInterceptorCost())
       {
     var interceptor = mGameObjectFactory.CreateSpaceship(planet, allegiance, GameObjectType.Interceptor);
     AddUnit(interceptor);
     return true;
       }
       return false;
 }
Exemplo n.º 18
0
 public static Map GetRandomInstance3(int objCount, int width, int height)
 {
     Map map = new Map(width, height);
       Random r = new Random();
       for (int i=0; i<objCount; i++)
       {
       int allegianceNo = r.Next(3);
       Allegiance allegiance = Allegiance.Neutral;
       switch (allegianceNo)
       {
           case 0:
               allegiance = Allegiance.Player;
               break;
           case 1:
               allegiance = Allegiance.Neutral;
               break;
           case 2:
               allegiance = Allegiance.Computer;
               break;
       }
       int sizeNo = r.Next(3);
       PlanetSize size = PlanetSize.Medium;
       switch (sizeNo)
       {
           case 0:
               size = PlanetSize.Small;
               break;
           case 1:
               size = PlanetSize.Medium;
               break;
           case 2:
               size = PlanetSize.Large;
               break;
       }
       int noOfMinions = r.Next(50);
       int type = r.Next(6);
       int x = r.Next(width);
       int y = r.Next(height);
       Vector2 pos = new Vector2(x, y);
       GameObject unit = null;
       switch (type)
       {
           case 0:
               unit = new Asteroid(pos);
               break;
           case 1:
               unit = new DeathStar(pos, allegiance, noOfMinions);
               break;
           case 2:
               unit = new Defender(pos,allegiance);
               break;
           case 3:
               unit = new Interceptor(pos, allegiance);
               break;
           case 4:
               unit = new Planet(pos, allegiance, size, noOfMinions);
               break;
           case 5:
               unit = new Predator(pos, allegiance);
               break;
       }
       if (unit != null) map.mInitialGameObjects.Add(unit);
       }
       return map;
 }
Exemplo n.º 19
0
 public bool CreatePredator(Planet planet, Allegiance allegiance)
 {
     if (planet.DeductPredatorCost())
       {
     var predator = mGameObjectFactory.CreateSpaceship(planet, allegiance, GameObjectType.Predator);
     AddUnit(predator);
     return true;
       }
       return false;
 }
Exemplo n.º 20
0
 /// <summary>
 /// Upgrades the Planet to get the Minion boost upgrade
 /// </summary>
 /// <param name="planet"></param>
 /// <returns>bool: depending on whether the upgrade was successful or not</returns>
 public bool UpgradeMinionBoost(Planet planet)
 {
     return planet.UpgradeMinionBoost();
 }
Exemplo n.º 21
0
 public GuardOwnPlanet(SpaceshipAi parent, Planet planet)
 {
     Debug.Assert(planet.Allegiance == Allegiance.Computer);
     mPlanet = planet;
     mParent = parent;
 }