Beispiel #1
0
    public override void RemoveItem(ItemOrder io)
    {
        if (io.GetItemName() != product)
        {
            Debug.LogError(name + " can't remove " + io.GetItemName());
        }

        AmountStored -= io.amount;
    }
Beispiel #2
0
    public SimplePriorityQueue <Generator> FindGeneratorToAccept(ItemOrder io)
    {
        int    num  = io.amount;
        string item = io.GetItemName();

        GameObject[] objs = GameObject.FindGameObjectsWithTag("Generator");
        SimplePriorityQueue <Generator> queue = new SimplePriorityQueue <Generator>();

        if (objs.Length == 0)
        {
            return(queue);
        }


        foreach (GameObject go in objs)
        {
            Generator gen = go.GetComponent <Generator>();


            //if null, continue
            if (gen == null)
            {
                continue;
            }

            if (!gen.Operational)
            {
                continue;
            }

            int index = gen.IngredientIndex(item);

            //only add to list if it needs this ingredient
            if (index == -1)
            {
                continue;
            }

            //only add to list if it has an entrance
            List <Node> entrancesHere  = GetAdjRoadTiles();
            List <Node> entrancesThere = gen.GetAdjRoadTiles();
            if (entrancesHere.Count == 0 || entrancesThere.Count == 0)
            {
                continue;
            }

            //only add to list if it has none of this item
            if (gen.IngredientNeeded(index) <= 0)
            {
                continue;
            }

            float distance = entrancesHere[0].DistanceTo(entrancesThere[0]);

            queue.Enqueue(gen, distance);
        }

        return(queue);
    }
Beispiel #3
0
 public override void RemoveItem(ItemOrder io)
 {
     if (io.GetItemName() != item)
     {
         Debug.LogError(name + " removed " + io + " in error");
     }
     AmountStored -= io.amount;
 }
Beispiel #4
0
 public override void ReceiveItem(ItemOrder io)
 {
     for (int a = 0; a < ingredientMax.Length; a++)
     {
         if (ingredients[a] == io.GetItemName())
         {
             IngredientAmount[a] += io.amount;
         }
     }
 }
Beispiel #5
0
    public static int GetBasePrice(ItemOrder io)
    {
        string item  = io.GetItemName();
        float  price = 1;

        if (Prices.ContainsKey(item))
        {
            price = Prices[item];
        }
        return((int)(price * io.amount));
    }
Beispiel #6
0
    public override void ReceiveItem(ItemOrder io)
    {
        //if does not accept this type of item, reject
        if (io.type != typeStored)
        {
            Debug.Log(name + " does not store " + io.GetItemName());
        }

        //else remove from queue and add to inventory
        Queue[io.item]     -= io.amount;
        Inventory[io.item] += io.amount;
        UpdateVisibleGoods();
    }
Beispiel #7
0
    public override void ReceiveItem(ItemOrder io)
    {
        if (io.type == ItemType.Meal)
        {
            Hunger         -= io.amount;
            FoodQualCurrent = ResourcesDatabase.GetQuality(io.GetItemName());
        }

        else if (io.type == ItemType.Good)
        {
            Goods[io.item] += io.amount;
        }
    }
Beispiel #8
0
 public override void ReceiveItem(ItemOrder io)
 {
     for (int a = 0; a < IngredientsPer100.Length; a++)
     {
         if (Ingredients[a] == io.GetItemName())
         {
             IngredientsStored[a] += io.amount;
         }
         else
         {
             Debug.LogError(name + " erroneously received " + io.ToString());
         }
     }
 }
Beispiel #9
0
    //NOTE: NEED TO ACCOUNT FOR ITEMORDERS WHICH ARE MORE THAN 400 BY DIVIDING THE AMOUNT AMONG MULTIPLE SLOTS
    public bool CanAccept(ItemOrder io)
    {
        int amountToAcceptTotal = io.amount;

        //if there's a whitelist, check to make sure this item is allowed
        if (whitelist.Length > 0)
        {
            bool whitelisted = false;

            //look at each whitelisted item
            foreach (string s in whitelist)
            {
                if (s.Equals(io.GetItemName()))
                {
                    whitelisted = true;
                }
            }

            if (!whitelisted)
            {
                return(false);
            }
        }

        //make sure that we can accept this type of item
        if (io.type != typeStored)
        {
            return(false);
        }

        for (int i = 0; i < slotCapacity && amountToAcceptTotal == 0; i++)
        {
            int emptySpace  = Slots[i].EmptySpace;
            int amountToTry = amountToAcceptTotal > emptySpace ? emptySpace : amountToAcceptTotal;              //only try to fit as much as we can into this slot
            //	if the amount we're trying is greater than the space we have, only test for the space we have
            ItemOrder forThisSlot = new ItemOrder(amountToTry, io.item, io.type);

            if (Slots[i].CanAccept(io))
            {
                amountToAcceptTotal -= amountToTry;                             //if we can accept this amount, subtract from the total we're trying to get rid of
            }
        }

        return(amountToAcceptTotal == 0);
    }
Beispiel #10
0
 public static float GetBasePrice(ItemOrder io)
 {
     return(GetBasePrice(io.GetItemName(), io.amount));
 }