Ejemplo n.º 1
0
    /// <summary>
    /// convert a particular amount of startResources into endResources
    /// </summary>
    // TODO: write test for this
    public override void perform(Creature creature, Ecosystem eco)
    {
        // don't produce more than the creature can store
        foreach (string key in endResources.Keys)
        {
            CreatureResource resource     = creature.storedResources[key];
            float            storageSpace = resource.maxLevel - resource.currentLevel;
            float            toProduce    = amtToProduce * endResources[key];
            if (storageSpace < toProduce)
            {
                amtToProduce = storageSpace / endResources[key];
            }
        }


        // determine how much of the products can actually be produced
        // amount produced is the full amount intended, unless overriden below by a limiting reactant
        float actualAmtProduced = amtToProduce;

        foreach (string resource in startResources.Keys)
        {
            float multipleNeeded   = startResources[resource];
            float amtOfResRequired = amtToProduce * multipleNeeded;
            // if the creature doesn't have enough of a particular resource
            float actualStored = creature.storedResources[resource].currentLevel;
            // if there is not enough of the resource to produce the full amount
            if (actualStored < amtOfResRequired)
            {
                // calculate how much the resource can produce
                float amtProducedByRes = actualStored / multipleNeeded;
                // if that amount is less than the current amount actually produced, update the current amount
                if (amtProducedByRes < actualAmtProduced)
                {
                    actualAmtProduced = amtProducedByRes;
                }
            }
        }

        /* use the amount that can actaully be produced to update resource values */

        // update reactant levels
        foreach (string resource in startResources.Keys)
        {
            float amtUsed = startResources[resource] * actualAmtProduced;
            creature.storedResources[resource].currentLevel -= amtUsed;
        }

        // update product levels
        foreach (string resource in endResources.Keys)
        {
            float amtCreated = endResources[resource] * actualAmtProduced;
            creature.storedResources[resource].currentLevel += amtCreated;
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Accesses land via neighborIndex, and attemps to consume resource.
    /// </summary>
    public override void perform(Creature creature, Ecosystem eco)
    {
        Land land = creature.neighborLands[neighborIndex];

        if (!land.isDummy)
        {
            CreatureResource creatRes     = creature.storedResources[resourceToConsume];
            float            storageSpace = creatRes.maxLevel - creatRes.currentLevel;
            float            consumed     = land.attemptResourceConsumption(resourceToConsume, timeCost, creature.abilities[resourceToConsume].level, storageSpace);

            if (storageSpace < consumed)
            {
                creature.storedResources[resourceToConsume].currentLevel = creature.storedResources[resourceToConsume].maxLevel;
            }
            // Only consume resource if creature has space for it
            else
            {
                creature.storedResources[resourceToConsume].currentLevel += consumed;
            }
        }
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Deposit resource on neighbor land.
    /// </summary>
    public override void perform(Creature creature, Ecosystem eco)
    {
        Land land = creature.neighborLands[neighborIndex];

        if (!land.isDummy)
        {
            CreatureResource creatRes = creature.storedResources[resourceToDeposit];

            float actualAmtDeposited;

            if (creatRes.currentLevel < amountToDeposit)
            {
                actualAmtDeposited = creatRes.currentLevel;
            }
            else
            {
                actualAmtDeposited = amountToDeposit;
            }
            creatRes.currentLevel -= actualAmtDeposited;
            land.depositResource(resourceToDeposit, actualAmtDeposited);
        }
    }
 public ResourceEditor(CreatureResource _resource)
 {
     resource = _resource;
 }