예제 #1
0
/**
 * Build anything in the production queue on the planet.
 */
    public int buildAndProduce(Planet planet)
    {
        Cost allocated = new Cost(planet.getCargo().getIronium(), planet.getCargo().getBoranium(), planet.getCargo().getGermanium(),
                                  planet.getResourcesPerYearAvailable());

        allocated = allocated.add(planet.getQueue().getAllocated());

        int index = 0;

        while (index < planet.getQueue().getItems().Count)
        {
            ProductionQueueItem item = planet.getQueue().getItems()[index];
            Cost costPer             = item.getCostOfOne(planet.getOwner().getRace());
            int  numBuilt            = allocated.divide(costPer);

            if (0 < numBuilt && numBuilt < item.getQuantity())
            {
                allocated = buildItem(planet, item, numBuilt, allocated);

                allocated = allocated.subtract(costPer.multiply(numBuilt));

                if (!autoBuildTypes.Contains(item.getType()))
                {
                    planet.getQueue().getItems()[index].setQuantity(planet.getQueue().getItems()[index].getQuantity() - numBuilt);
                }

                allocated = allocateToQueue(planet.getQueue(), costPer, allocated);
            }
            else if (numBuilt >= item.getQuantity())
            {
                numBuilt  = item.getQuantity();
                allocated = buildItem(planet, item, numBuilt, allocated);

                allocated = allocated.subtract(costPer.multiply(numBuilt));

                if (!autoBuildTypes.Contains(item.getType()))
                {
                    planet.getQueue().getItems().RemoveAt(index);
                    index--;
                }
                planet.getQueue().setAllocated(new Cost());
            }
            else
            {
                allocated = allocateToQueue(planet.getQueue(), costPer, allocated);
                break;
            }
            index++;
        }

        planet.setCargo(new Cargo(allocated.getIronium(), allocated.getBoranium(), allocated.getGermanium(), planet.getCargo().getColonists(),
                                  planet.getCargo().getFuel()));

        return(allocated.getResources());
    }
예제 #2
0
 string GetProductionItemName(ProductionQueueItem pqi)
 {
     if (pqi.getType() != QueueItemType.Fleet)
     {
         return(pqi.getType().ToString());
     }
     else
     {
         return(pqi.getShipDesign().getHullName());
     }
 }
예제 #3
0
/**
 * Build 1 or more items of this production queue item type Adding mines, factories, defenses,
 * etc to planets Building new fleets
 */
    private Cost buildItem(Planet planet, ProductionQueueItem item, int num_built, Cost allocated)
    {
        if (item.getType() == QueueItemType.Mine || item.getType() == QueueItemType.AutoMine)
        {
            planet.setMines(planet.getMines() + num_built);
            Message.mine(planet.getOwner(), planet, num_built);
        }
        else if (item.getType() == QueueItemType.Factory || item.getType() == QueueItemType.AutoFactory)
        {
            planet.setFactories(planet.getFactories() + num_built);
            Message.factory(planet.getOwner(), planet, num_built);
        }
        else if (item.getType() == QueueItemType.Defense || item.getType() == QueueItemType.AutoDefense)
        {
            planet.setDefenses(planet.getDefenses() + num_built);
            Message.defense(planet.getOwner(), planet, num_built);
        }
        else if (item.getType() == QueueItemType.Alchemy || item.getType() == QueueItemType.AutoAlchemy)
        {
            // add the minerals back to our allocated amount
            allocated = allocated.add(new Cost(num_built, num_built, num_built, 0));
        }
        else if (item.getType() == QueueItemType.Terraform || item.getType() == QueueItemType.AutoTerraform)
        {
            Race playerRace = planet.getOwner().getRace();

            int[] distanceFromIdeal = new int[3];
            distanceFromIdeal[0] = planet.getHab().getAtIndex(0) - playerRace.getHabCenter(0);
            distanceFromIdeal[1] = planet.getHab().getAtIndex(1) - playerRace.getHabCenter(1);
            distanceFromIdeal[2] = planet.getHab().getAtIndex(2) - playerRace.getHabCenter(2);

            for (int i = 0; i < 3; i++)
            {
                if (Mathf.Abs(distanceFromIdeal[i]) > item.getQuantity())
                {
                    if (planet.getHab().getAtIndex(i) > playerRace.getHabCenter(i))
                    {
                        planet.getHab().setAtIndex(i, planet.getHab().getAtIndex(i) + (item.getQuantity() * -1));
                    }
                    else if (planet.getHab().getAtIndex(i) < playerRace.getHabCenter(i))
                    {
                        planet.getHab().setAtIndex(i, planet.getHab().getAtIndex(i) + (item.getQuantity()));
                    }
                    Message.terraform(planet.getOwner(), planet, item.getQuantity(), i);
                }
                else
                {
                    Message.noNeedToTerraform(planet.getOwner(), planet, i);
                }
            }
        }
        else if (item.getType() == QueueItemType.Fleet)
        {
            buildFleet(planet, item, num_built);
        }
        else if (item.getType() == QueueItemType.Starbase)
        {
            buildStarbase(planet, item);
        }

        return(allocated);
    }