Exemplo n.º 1
0
        public virtual bool FillCart(Cart cart, InventoryBuilding origin)
        {
            cart.Inventory.RessourceLimit = this.ConnectedInventories[origin].Item2;
            BuildingInventory destination = this.Inventory;
            bool ressourceAdded           = true;

            while (ressourceAdded)
            {
                ressourceAdded = false;
                foreach (RessourceType ressourceType in destination.Incoming)
                {
                    if (origin.Inventory.Outgoing.Contains(ressourceType) && origin.AllowedRessources[this][ressourceType])
                    {
                        if (origin.Inventory.Outgoing.Contains(ressourceType))
                        {
                            if (cart.Inventory.AvailableSpace() > 0)
                            {
                                if (origin.Inventory.GetRessourceAmount(ressourceType) > 0)
                                {
                                    cart.Inventory.AddRessource(ressourceType, 1);
                                    origin.Inventory.RemoveRessource(ressourceType, 1);
                                    ressourceAdded = true;
                                }
                            }
                        }
                    }
                }
            }
            return(!cart.Inventory.IsEmpty());
        }
Exemplo n.º 2
0
 private KeyValuePair <InventoryBuilding, Tuple <HexDirection, int, int> > FindDestination()
 {
     //First check if there is a building which has an empty ressource which can be send.
     foreach (KeyValuePair <InventoryBuilding, Tuple <HexDirection, int, int> > kvp in this.ConnectedInventories)
     {
         InventoryBuilding possibleDestination = kvp.Key;
         foreach (KeyValuePair <RessourceType, bool> kvp2 in AllowedRessources[kvp.Key])
         {
             if (kvp2.Value)
             {
                 if (possibleDestination.Inventory.Storage[kvp2.Key] == 0 && possibleDestination.Inventory.AvailableSpace(kvp2.Key) > 0)
                 {
                     return(kvp);
                 }
             }
         }
     }
     //Then check if a building can be found that has space for any fitting ressourceType
     foreach (KeyValuePair <InventoryBuilding, Tuple <HexDirection, int, int> > kvp in this.ConnectedInventories)
     {
         InventoryBuilding possibleDestination = kvp.Key;
         foreach (KeyValuePair <RessourceType, bool> kvp2 in AllowedRessources[kvp.Key])
         {
             if (kvp2.Value)
             {
                 if (possibleDestination.Inventory.AvailableSpace(kvp2.Key) > 0)
                 {
                     return(kvp);
                 }
             }
         }
     }
     throw new Exception("No fitting destination found");
 }
Exemplo n.º 3
0
 public Cart(InventoryBuilding origin)
 {
     this.Inventory                = new Inventory();
     this.Inventory.Storage        = Inventory.GetDictionaryForAllRessources();
     this.Inventory.RessourceLimit = 2;
     this.Origin      = origin;
     this.Destination = origin;
 }
Exemplo n.º 4
0
 public virtual bool HasEmptyRessource(InventoryBuilding origin)
 {
     foreach (RessourceType ressourceType in origin.Inventory.Outgoing)
     {
         if (this.Inventory.Incoming.Contains(ressourceType))
         {
             if (this.Inventory.GetRessourceAmount(ressourceType) == 0)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Exemplo n.º 5
0
 public Cart(Inventory Inventory, InventoryBuilding Origin, InventoryBuilding Destination)
 {
     this.Inventory   = Inventory;
     this.Origin      = Origin;
     this.Destination = Destination;
 }