Exemplo n.º 1
0
 void NeighborNeedsSoldiersAction(ref AbstractPlanet planet)
 {
     foreach (AbstractPlanet neigh in planet.adjacentPlanet)
     {
         if (actionHappened)
         {
             continue;
         }
         AbstractPlanet target = null;
         if (neigh.planetOwnership == AbstractPlanet.Ownership.Enemy && neigh.isRequestingSoldiers)
         {
             if (ValidPlanetForTraining(ref planet))
             {
                 planet.TrainSoldiers(true);
             }
             planet.isFeeding        = true;
             planet.planetRequesting = neigh;
             target = neigh;
         }
         else if (neigh.planetOwnership == AbstractPlanet.Ownership.Enemy && neigh.isFeeding)
         {
             if (PlanetInPath(neigh, neigh.planetRequesting) && neigh != neigh.planetRequesting)
             {
                 if (ValidPlanetForTraining(ref planet))
                 {
                     planet.TrainSoldiers(true);
                 }
                 planet.isFeeding        = true;
                 planet.planetRequesting = neigh.planetRequesting;
                 target = neigh;
             }
         }
         if (target)
         {
             ship = planet.CreateShip(AbstractPlanet.Ownership.Enemy);
             if (ship.soldiersOnBoard >= ship.soldierCapacity * 0.1f ||
                 (!CanNewUnitsBeCreated() && ship.soldiersOnBoard > 0))
             {
                 LaunchShip(planet, target, planet.adjacentPaths, ship);
             }
             else if (!ship.GetIsLoading())
             {
                 ship.StartLoadingSoldiersToShip(planet);
             }
             action++;
             actionHappened = true;
         }
     }
 }
Exemplo n.º 2
0
 void BeingAttackedAction(ref AbstractPlanet planet)
 {
     if (planet.isContested)
     {
         if (ValidPlanetForTraining(ref planet))
         {
             planet.TrainSoldiers(true);
         }
         planet.isRequestingSoldiers = true;
         //Unload my ship if I have one
         ship = planet.ships [Indices.SHIP_ENEMY];
         if (ship)
         {
             ship.StopLoadingSoldiersToShip();
             //Send units to nearest neighbor
             if (ship.soldiersOnBoard > 0)
             {
                 AbstractPlanet target = NearestNeighbor(planet);
                 LaunchShip(planet, target, planet.adjacentPaths, ship);
             }
         }
         action++;
         actionHappened = true;
     }
     else
     {
         planet.isRequestingSoldiers = false;
     }
 }
Exemplo n.º 3
0
    void NeighborAttackedAction(ref AbstractPlanet planet)
    {
        foreach (AbstractPlanet neigh in planet.adjacentPlanet)
        {
            if (actionHappened)
            {
                continue;
            }

            if (neigh.isContested && planet.planetOwnership == AbstractPlanet.Ownership.Enemy)               //Is my neighbor planet being attacked
            {
                if (ValidPlanetForTraining(ref planet))
                {
                    planet.TrainSoldiers(true);
                }
                planet.isFeeding = true;
                float totalUnits = neigh.enemySoldiers + neigh.playerSoldiers;
                if (neigh.playerSoldiers / totalUnits > 0.50f)
                {
                    ship = planet.CreateShip(AbstractPlanet.Ownership.Enemy);
                    if (ship.soldiersOnBoard == ship.soldierCapacity ||
                        (!CanNewUnitsBeCreated() && ship.soldiersOnBoard > 0))
                    {
                        LaunchShip(planet, neigh, planet.adjacentPaths, ship);
                    }
                    else if (!ship.GetIsLoading())
                    {
                        ship.StartLoadingSoldiersToShip(planet);
                    }
                }
                action++;
                actionHappened = true;
            }
        }
    }
Exemplo n.º 4
0
    void ExpandAction(ref AbstractPlanet planet)
    {
        foreach (AbstractPlanet neigh in planet.adjacentPlanet)
        {
            if (actionHappened)
            {
                continue;
            }
            if (neigh.planetOwnership == AbstractPlanet.Ownership.Neutral && neigh.isContested == false)
            {
                if (planet.GetPlanetType() != AbstractPlanet.PlanetType.Hybrid && planet.GetPlanetType() != AbstractPlanet.PlanetType.Soldier && planet.enemySoldiers == 0)
                {
                    planet.isRequestingSoldiers = true;
                }
                else
                {
                    planet.isRequestingSoldiers = false;
                    planet.planetRequesting     = null;
                    if (ValidPlanetForTraining(ref planet))
                    {
                        planet.TrainSoldiers(true);
                    }
                }


                ship = planet.CreateShip(AbstractPlanet.Ownership.Enemy);
                if (ship.soldiersOnBoard >= 1 ||
                    (!CanNewUnitsBeCreated() && ship.soldiersOnBoard > 0))
                {
                    LaunchShip(planet, neigh, planet.adjacentPaths, ship);
                    planet.TrainSoldiers(false);
                }
                else if (!ship.GetIsLoading())
                {
                    ship.StartLoadingSoldiersToShip(planet);
                }
                action++;
                actionHappened = true;
            }
        }
    }
Exemplo n.º 5
0
    void PlayerNearAction(ref AbstractPlanet planet)
    {
        foreach (AbstractPlanet neigh in planet.adjacentPlanet)
        {
            if (actionHappened)
            {
                continue;
            }

            if (neigh.planetOwnership == AbstractPlanet.Ownership.Player)               //Is there an enemy next to me
            {
                if (ValidPlanetForTraining(ref planet))
                {
                    planet.TrainSoldiers(true);
                }
                planet.isRequestingSoldiers = true;
                //Am I stronger then the enemy, then attack
                int estimatedUnits = (int)Mathf.Max(neigh.rankingScript.currentRank * 50 - 25, 0);

                ship = planet.CreateShip(AbstractPlanet.Ownership.Enemy);
                if ((ship.soldiersOnBoard + planet.enemySoldiers) > (estimatedUnits))
                {
                    if (ship.soldiersOnBoard == ship.soldierCapacity || ship.soldiersOnBoard > estimatedUnits)
                    {
                        LaunchShip(planet, neigh, planet.adjacentPaths, ship);
                    }
                    else if (!ship.GetIsLoading())
                    {
                        ship.StartLoadingSoldiersToShip(planet);
                    }
                }
                else
                {
                    ship.StopLoadingSoldiersToShip();
                }
                action++;
                actionHappened = true;
            }
        }
    }
Exemplo n.º 6
0
    // Update is called once per frame
    void Update()
    {
        thinkTimer += Time.deltaTime;
        if (thinkTimer >= thinkTime)
        {
            //Check if I have a ship with units doing nothing
            CheckShip();
            //Enemy Planet Actions
            for (int i = 0; i < enemyPlanets.Count; i++)
            {
                AbstractPlanet planet = enemyPlanets [i];
                actionHappened = false;
                //Do nothing else if you have no more actions
                if (action > actionsLimit)
                {
                    continue;
                }

                //Can I upgrade
                UpgradeAction(ref planet);

                if (actionHappened)
                {
                    continue;
                }
                //Am I being attacked
                BeingAttackedAction(ref planet);

                if (actionHappened)
                {
                    continue;
                }
                //Is there a player adajacent to me
                PlayerNearAction(ref planet);

                if (actionHappened)
                {
                    continue;
                }

                planet.isRequestingSoldiers = false;
                planet.planetRequesting     = null;
                //Is a planet next to me being attacked
                NeighborAttackedAction(ref planet);

                if (actionHappened)
                {
                    continue;
                }

                planet.isFeeding        = false;
                planet.planetRequesting = null;
                //Does my neighbor need soldiers
                NeighborNeedsSoldiersAction(ref planet);

                if (actionHappened)
                {
                    continue;
                }

                planet.isFeeding        = false;
                planet.planetRequesting = null;
                //Do I want to expand
                ExpandAction(ref planet);

                if (actionHappened)
                {
                    continue;
                }

                //Can I train soldiers with this economy
                if (CanNewUnitsBeCreated())
                {
                    planet.TrainSoldiers(true);
                    action++;
                }
                else
                {
                    planet.TrainSoldiers(false);
                }
            }

            thinkTimer = 0;
            action     = 0;
        }
    }
Exemplo n.º 7
0
 public void CreateSoldiers(bool value)
 {
     Debug.Log("create soldier " + value);
     ManagerScript.Instance.audioManager.PlaySound("ButtonClick");
     planetScript.TrainSoldiers(value);
 }
Exemplo n.º 8
0
 void CreateUnits(AbstractPlanet planet)
 {
     planet.TrainSoldiers(true);
 }