Loading...
Searching...
No Matches
CityBuilderCore.ItemStorage Class Reference

Detailed Description

general container for storage of items, use whenever anything owns items
defines various convenience methods for moving and checking items that abstract its different storage modes

Inheritance diagram for CityBuilderCore.ItemStorage:
CityBuilderCore.IItemContainer

Classes

class  ItemStorageData
 

Public Member Functions

void Clear ()
 removes all items and reservations
 
bool HasItems ()
 returns whether the strorage contains any items
 
bool HasItem (Item item)
 returns whether the strorage contains a particular items
 
bool HasItem (ItemCategory itemCategory)
 returns whether the strorage contains any item in the category
 
bool HasItems (ItemQuantity itemQuantity)
 checks if at least a certain quantity of an item is stored
does not take reservations into account, for that use HasItemsRemaining(Item, int)
 
bool HasItems (Item item, int quantity)
 checks if at least a certain quantity of an item is stored
does not take reservations into account, for that use HasItemsRemaining(Item, int)
 
bool HasItems (ItemCategoryQuantity itemCategoryQuantity)
 checks if at least a certain quantity of an item category is stored
does not take reservations into account, for that use HasItemsRemaining(Item, int)
 
bool HasItems (ItemCategory itemCategory, int quantity)
 checks if at least a certain quantity of an item category is stored
does not take reservations into account, for that use HasItemsRemaining(Item, int)
 
bool HasItems (IEnumerable< ItemQuantity > itemQuantities)
 checks if at least all the quantities passed are stored
 
bool HasItems (IEnumerable< ItemCategoryQuantity > itemCategoryQuantities)
 checks if at least all the quantities passed are stored
 
bool HasItemsRemaining (Item item, int quantity)
 checks if at least a certain quantity of an item is stored and unreserved
 
bool HasItemsRemaining (ItemCategory itemCategory, int quantity)
 checks if at least a certain quantity of an item category is stored and unreserved
 
int GetItemQuantity ()
 calculates the total number of items in the store
 
int GetItemQuantity (Item item)
 calculates the total number of a particular item stored
 
int GetItemQuantity (ItemCategory itemCategory)
 calculates the total number of items in a particular itemCategory(food, ...) stored
 
float GetUnitQuantity (Item item)
 calculates the number of units(Item.UnitSize) stored for an item
ie apples are stored in units of 100, 150 apples are in store > 1.5 units

 
int GetItemQuantityRemaining (Item item)
 calculates the total number of a particular item stored wihtout reservations
 
int GetItemCapacity ()
 calculates the total number of items that may be stored
 
int GetItemCapacity (Item item)
 calculates the total number that may be stored of a particular item
 
int GetItemCapacity (Item item, float ratio)
 calculates the proportional number that may be stored of a particular item
 
int GetItemCapacity (ItemCategory itemCategory)
 calculates the total number of items in a category that may be stored
 
int GetItemCapacity (ItemCategory itemCategory, float ratio)
 calculates the proportional number that may be stored of items in a category
 
int GetItemsOverRatio (Item item, float ratio=1f)
 calculates the quantity of items that is above the ratio
this can never be > 0 for ration 1 since items could use the entire capacity
it would be half the capacity if the storage was full and ratio was 0.5
 
int GetItemCapacityRemaining ()
 calculates how much space is left after removing stored items and reservations
 
int GetItemCapacityRemaining (Item item)
 calculates how many more of a particular item can be stored taking reservations into account
 
int GetItemCapacityRemaining (Item item, float ratio)
 calculates how many more of a particular item can be stored taking reservations into account while limiting capacity to a specified ratio
 
int GetItemCapacityRemaining (ItemCategory itemCategory)
 calculates how many more items in a category can be stored while taking reservations into account
 
int GetItemCapacityRemaining (ItemCategory itemCategory, float ratio)
 calculates how many more items in a category can be stored taking reservations into account while limiting capacity to a specified ratio
 
float GetUnitCapacityRemaining (Item item)
 calculates how many more units(Item.UnitSize) of an items can be stored while subtracting reservations
 
ItemLevel GetItemLevel (Item item)
 retrieves the item level for an item
the item level expresses current storage quantity and capacity
 
bool FitsItems (IEnumerable< ItemQuantity > itemQuantities)
 checks whether multiple item quantities fit into storage
takes reservations into account
 
bool FitsItems (ItemQuantity itemQuantity)
 checks whether an item quantity fits into storage
takes reservations into account
 
bool FitsItems (Item item, int quantity)
 checks whether a quantity fits into storage
takes reservations into account
 
IEnumerable< ItemGetItems ()
 returns all the kinds of item in the storage
 
IEnumerable< ItemQuantityGetItemQuantities ()
 returns all the items in storage with their current quantity
 
List< ItemQuantityMoveItemsTo (ItemStorage other)
 moves any item into the other storage that will fit
 
List< ItemQuantityMoveItemsTo (ItemStorage other, bool overfill)
 moves any item into the other storage
 
int MoveItemsTo (ItemStorage other, Item item, int maxQuantity=int.MaxValue, bool overfill=false)
 moves quantities of an items to another storage, may be limited by a maximum quantity
 
void AddItems (IEnumerable< ItemQuantity > itemQuantities, bool overfill=false)
 
void RemoveItems (IEnumerable< ItemQuantity > itemQuantities)
 
void RemoveItems (IEnumerable< ItemCategoryQuantity > itemCategoryQuantities)
 
int AddItems (ItemQuantity itemQuantity, bool overfill=false)
 adds items to that storage up to its capacity, remaining quantity is returned
(adding 10 items to a storage that can only fit 4 more will return 6)
 
int AddItems (Item item, int quantity)
 adds items to that storage up to its capacity, remaining quantity is returned
(adding 10 items to a storage that can only fit 4 more will return 6)
 
int AddItems (Item item, int quantity, bool overfill)
 adds items to that storage up to its capacity, remaining quantity is returned
(adding 10 items to a storage that can only fit 4 more will return 6)
 
int RemoveItems (ItemQuantity itemQuantity)
 removes items from storage and returns the remaining quantity if not enough items were present
(removing 4 items from a store that contains only 3 will return 1)
 
int RemoveItems (Item item, int quantity)
 removes items from storage and returns the remaining quantity if not enough items were present
(removing 4 items from a store that contains only 3 will return 1)
 
int RemoveItems (ItemCategoryQuantity itemCategoryQuantity)
 removes items from storage and returns the remaining quantity if not enough items were present
(removing 4 items from a store that contains only 3 will return 1)
 
int RemoveItems (ItemCategory itemCategory, int quantity)
 removes items from storage and returns the remaining quantity if not enough items were present
(removing 4 items from a store that contains only 3 will return 1)
 
void ReserveCapacity (Item item, int quantity)
 reserves capacity for an item that may be delivered in the future
makes sure that capacity is still available when the item arrives
 
void UnreserveCapacity (Item item, int quantity)
 removes a reservation made by ReserveCapacity(Item, int)
should be called when the items arrives or if the delivery got interrupted
 
int GetReservedCapacity (Item item)
 checks how much capacity has been reserved for an item
 
void ReserveQuantity (Item item, int quantity)
 reserves a quantity of an item so it can be collected in the future
makes sure the items dont get removed from somebody else until it is acutally removed
 
void UnreserveQuantity (Item item, int quantity)
 removes a reservation made by ReserveQuantity(Item, int)
should be called when the items are collected or if the pickup was interrupted
 
int GetReservedQuantity (Item item)
 checks how much quantity has been reserved of an item
 
ItemStorage GetActualStorage ()
 returns the proxy store if the store redirects to another one using ItemStorageMode.Global or ItemStorageMode.Store or itself if not
 
string GetDebugText ()
 text that can be displayed for easy debugging
prints out all the item quantities stored
 
string GetItemNames ()
 joins all items names inside the store seperated by comma
 
ItemStorageData SaveData ()
 
void LoadData (ItemStorageData data)
 

Public Attributes

ItemStorageMode Mode = ItemStorageMode.UnitCapped
 
int StackCount
 
int Capacity = 1
 
ItemQuantity[] ItemCapacities
 
ItemStore Store
 
bool PersistStore
 

Properties

bool IsStackedStorage [get]
 
bool IsProxyStorage [get]
 
bool IsListStorage [get]
 
ItemStack[] Stacks [get]
 

Events

Action< ItemStorageChanged
 

Member Function Documentation

◆ AddItems() [1/3]

int CityBuilderCore.ItemStorage.AddItems ( Item item,
int quantity )

adds items to that storage up to its capacity, remaining quantity is returned
(adding 10 items to a storage that can only fit 4 more will return 6)

Parameters
itemthe item to add
quantitymaximum quantity to add
Returns
remaining quantity that did not fit

Implements CityBuilderCore.IItemContainer.

◆ AddItems() [2/3]

int CityBuilderCore.ItemStorage.AddItems ( Item item,
int quantity,
bool overfill )
inline

adds items to that storage up to its capacity, remaining quantity is returned
(adding 10 items to a storage that can only fit 4 more will return 6)

Parameters
itemthe item to add
quantitymaximum quantity to add
Returns
remaining quantity that did not fit

◆ AddItems() [3/3]

int CityBuilderCore.ItemStorage.AddItems ( ItemQuantity itemQuantity,
bool overfill = false )

adds items to that storage up to its capacity, remaining quantity is returned
(adding 10 items to a storage that can only fit 4 more will return 6)

Parameters
itemQuantitythe quantity of items to add
Returns
remaining quantity that did not fit

◆ FitsItems() [1/3]

bool CityBuilderCore.ItemStorage.FitsItems ( IEnumerable< ItemQuantity > itemQuantities)

checks whether multiple item quantities fit into storage
takes reservations into account

Parameters
itemQuantitiesthe item quantities to check
Returns
whether the item quantities could be stored

◆ FitsItems() [2/3]

bool CityBuilderCore.ItemStorage.FitsItems ( Item item,
int quantity )
inline

checks whether a quantity fits into storage
takes reservations into account

Parameters
item
quantity
Returns
whether the items could be stored

◆ FitsItems() [3/3]

bool CityBuilderCore.ItemStorage.FitsItems ( ItemQuantity itemQuantity)

checks whether an item quantity fits into storage
takes reservations into account

Parameters
itemQuantitythe item quantity to check
Returns
whether the items could be stored

◆ GetActualStorage()

ItemStorage CityBuilderCore.ItemStorage.GetActualStorage ( )
inline

returns the proxy store if the store redirects to another one using ItemStorageMode.Global or ItemStorageMode.Store or itself if not

Returns
the resolved storage

◆ GetDebugText()

string CityBuilderCore.ItemStorage.GetDebugText ( )
inline

text that can be displayed for easy debugging
prints out all the item quantities stored

Returns

◆ GetItemCapacity() [1/5]

int CityBuilderCore.ItemStorage.GetItemCapacity ( )
inline

calculates the total number of items that may be stored

Returns
total capacity

Implements CityBuilderCore.IItemContainer.

◆ GetItemCapacity() [2/5]

int CityBuilderCore.ItemStorage.GetItemCapacity ( Item item)

calculates the total number that may be stored of a particular item

Parameters
itemitem in question
Returns
total capacity for the item

Implements CityBuilderCore.IItemContainer.

◆ GetItemCapacity() [3/5]

int CityBuilderCore.ItemStorage.GetItemCapacity ( Item item,
float ratio )
inline

calculates the proportional number that may be stored of a particular item

Parameters
itemitem in question
ratiohow much of the capacity may be used (0-1)
Returns
proportional capacity for the item

◆ GetItemCapacity() [4/5]

int CityBuilderCore.ItemStorage.GetItemCapacity ( ItemCategory itemCategory)

calculates the total number of items in a category that may be stored

Parameters
itemCategoryitem category in question
Returns
total capacity of items in the category

Implements CityBuilderCore.IItemContainer.

◆ GetItemCapacity() [5/5]

int CityBuilderCore.ItemStorage.GetItemCapacity ( ItemCategory itemCategory,
float ratio )
inline

calculates the proportional number that may be stored of items in a category

Parameters
itemCategoryitem category in question
ratiohow much of the capacity may be used (0-1)
Returns
proportional capacity for items in a category

◆ GetItemCapacityRemaining() [1/5]

int CityBuilderCore.ItemStorage.GetItemCapacityRemaining ( )
inline

calculates how much space is left after removing stored items and reservations

Returns
total space left

Implements CityBuilderCore.IItemContainer.

◆ GetItemCapacityRemaining() [2/5]

int CityBuilderCore.ItemStorage.GetItemCapacityRemaining ( Item item)

calculates how many more of a particular item can be stored taking reservations into account

Parameters
itemitem to check
Returns
remaining capacity after removing stored quantity and reservations

Implements CityBuilderCore.IItemContainer.

◆ GetItemCapacityRemaining() [3/5]

int CityBuilderCore.ItemStorage.GetItemCapacityRemaining ( Item item,
float ratio )
inline

calculates how many more of a particular item can be stored taking reservations into account while limiting capacity to a specified ratio

Parameters
itemitem to check
ratiohow much of the capacity may be used (0-1)
Returns
remaining proportional capacity after removing stored quantity and reservations

◆ GetItemCapacityRemaining() [4/5]

int CityBuilderCore.ItemStorage.GetItemCapacityRemaining ( ItemCategory itemCategory)

calculates how many more items in a category can be stored while taking reservations into account

Parameters
itemCategorythe category of items to calculate
Returns
how many more items of the category can be stored

Implements CityBuilderCore.IItemContainer.

◆ GetItemCapacityRemaining() [5/5]

int CityBuilderCore.ItemStorage.GetItemCapacityRemaining ( ItemCategory itemCategory,
float ratio )
inline

calculates how many more items in a category can be stored taking reservations into account while limiting capacity to a specified ratio

Parameters
itemCategoryitem category to check
ratiohow much of the capacity may be used (0-1)
Returns
remaining proportional capacity after removing stored quantity and reservations

◆ GetItemLevel()

ItemLevel CityBuilderCore.ItemStorage.GetItemLevel ( Item item)

retrieves the item level for an item
the item level expresses current storage quantity and capacity

Parameters
itemthe item to check
Returns

◆ GetItemNames()

string CityBuilderCore.ItemStorage.GetItemNames ( )
inline

joins all items names inside the store seperated by comma

Returns

◆ GetItemQuantities()

IEnumerable< ItemQuantity > CityBuilderCore.ItemStorage.GetItemQuantities ( )
inline

returns all the items in storage with their current quantity

Returns
all items with quantities

Implements CityBuilderCore.IItemContainer.

◆ GetItemQuantity() [1/3]

int CityBuilderCore.ItemStorage.GetItemQuantity ( )
inline

calculates the total number of items in the store

Returns
total item count

Implements CityBuilderCore.IItemContainer.

◆ GetItemQuantity() [2/3]

int CityBuilderCore.ItemStorage.GetItemQuantity ( Item item)
inline

calculates the total number of a particular item stored

Parameters
itemthe item to count
Returns
total quantity of item

Implements CityBuilderCore.IItemContainer.

◆ GetItemQuantity() [3/3]

int CityBuilderCore.ItemStorage.GetItemQuantity ( ItemCategory itemCategory)

calculates the total number of items in a particular itemCategory(food, ...) stored

Parameters
itemCategorythe item category to count
Returns
total quantity of items in the ItemCategory

Implements CityBuilderCore.IItemContainer.

◆ GetItemQuantityRemaining()

int CityBuilderCore.ItemStorage.GetItemQuantityRemaining ( Item item)

calculates the total number of a particular item stored wihtout reservations

Parameters
itemthe item to count
Returns
total quantity of unreserved item

◆ GetItems()

IEnumerable< Item > CityBuilderCore.ItemStorage.GetItems ( )
inline

returns all the kinds of item in the storage

Returns
item kinds stored

Implements CityBuilderCore.IItemContainer.

◆ GetItemsOverRatio()

int CityBuilderCore.ItemStorage.GetItemsOverRatio ( Item item,
float ratio = 1f )
inline

calculates the quantity of items that is above the ratio
this can never be > 0 for ration 1 since items could use the entire capacity
it would be half the capacity if the storage was full and ratio was 0.5

Parameters
item
ratio
Returns
items stored above ratio

◆ GetReservedCapacity()

int CityBuilderCore.ItemStorage.GetReservedCapacity ( Item item)
inline

checks how much capacity has been reserved for an item

Parameters
itemthe item in question
Returns
the capacity that has been reserved for the given item

◆ GetReservedQuantity()

int CityBuilderCore.ItemStorage.GetReservedQuantity ( Item item)

checks how much quantity has been reserved of an item

Parameters
itemthe item in question
Returns
the quantity that has been reserved of the item

◆ GetUnitCapacityRemaining()

float CityBuilderCore.ItemStorage.GetUnitCapacityRemaining ( Item item)
inline

calculates how many more units(Item.UnitSize) of an items can be stored while subtracting reservations

Parameters
itemitem to calculate
Returns
units of the items that can still be stored

◆ GetUnitQuantity()

float CityBuilderCore.ItemStorage.GetUnitQuantity ( Item item)

calculates the number of units(Item.UnitSize) stored for an item
ie apples are stored in units of 100, 150 apples are in store > 1.5 units

Parameters
item
Returns

◆ HasItem() [1/2]

bool CityBuilderCore.ItemStorage.HasItem ( Item item)
inline

returns whether the strorage contains a particular items

Parameters
itemthe item to check for
Returns
whether the storage has any of the specified item

◆ HasItem() [2/2]

bool CityBuilderCore.ItemStorage.HasItem ( ItemCategory itemCategory)
inline

returns whether the strorage contains any item in the category

Parameters
itemCategorythe item category to check for
Returns
whether the storage has any of the specified item

◆ HasItems() [1/7]

bool CityBuilderCore.ItemStorage.HasItems ( )
inline

returns whether the strorage contains any items

Returns
true if any items are stored

◆ HasItems() [2/7]

bool CityBuilderCore.ItemStorage.HasItems ( IEnumerable< ItemCategoryQuantity > itemCategoryQuantities)

checks if at least all the quantities passed are stored

Parameters
itemCategoryQuantitiesthe quantities to check
Returns
if at least the quantity of the item is stored

◆ HasItems() [3/7]

bool CityBuilderCore.ItemStorage.HasItems ( IEnumerable< ItemQuantity > itemQuantities)

checks if at least all the quantities passed are stored

Parameters
itemQuantitiesthe quantities to check
Returns
if at least the quantity of the item is stored

◆ HasItems() [4/7]

bool CityBuilderCore.ItemStorage.HasItems ( Item item,
int quantity )
inline

checks if at least a certain quantity of an item is stored
does not take reservations into account, for that use HasItemsRemaining(Item, int)

Parameters
itemthe item to look for
quantitythe minimum qantity
Returns
if at least the quantity of the item is stored

◆ HasItems() [5/7]

bool CityBuilderCore.ItemStorage.HasItems ( ItemCategory itemCategory,
int quantity )
inline

checks if at least a certain quantity of an item category is stored
does not take reservations into account, for that use HasItemsRemaining(Item, int)

Parameters
itemCategorythe item category to look for
quantitythe minimum qantity
Returns
if at least the quantity of the item is stored

◆ HasItems() [6/7]

bool CityBuilderCore.ItemStorage.HasItems ( ItemCategoryQuantity itemCategoryQuantity)

checks if at least a certain quantity of an item category is stored
does not take reservations into account, for that use HasItemsRemaining(Item, int)

Parameters
itemCategoryQuantitythe item category and quantity to look for
Returns
if at least the quantity of the item is stored

◆ HasItems() [7/7]

bool CityBuilderCore.ItemStorage.HasItems ( ItemQuantity itemQuantity)

checks if at least a certain quantity of an item is stored
does not take reservations into account, for that use HasItemsRemaining(Item, int)

Parameters
itemQuantitythe quantity of item to check
Returns
if at least the quantity of the item is stored

◆ HasItemsRemaining() [1/2]

bool CityBuilderCore.ItemStorage.HasItemsRemaining ( Item item,
int quantity )
inline

checks if at least a certain quantity of an item is stored and unreserved

Parameters
itemthe item to look for
quantitythe minimum qantity
Returns
if at least the quantity of the item is stored and not reserved

◆ HasItemsRemaining() [2/2]

bool CityBuilderCore.ItemStorage.HasItemsRemaining ( ItemCategory itemCategory,
int quantity )
inline

checks if at least a certain quantity of an item category is stored and unreserved

Parameters
itemCategorythe item category to look for
quantitythe minimum qantity
Returns
if at least the quantity of the item is stored and not reserved

◆ MoveItemsTo() [1/3]

List< ItemQuantity > CityBuilderCore.ItemStorage.MoveItemsTo ( ItemStorage other)

moves any item into the other storage that will fit

Parameters
otherstorage that receives the items
Returns
the item quantity that have been moved

◆ MoveItemsTo() [2/3]

List< ItemQuantity > CityBuilderCore.ItemStorage.MoveItemsTo ( ItemStorage other,
bool overfill )
inline

moves any item into the other storage

Parameters
otherstorage that receives the items
overfillwhether exceeding the targets capacity is allowed
Returns
the item quantity that have been moved

◆ MoveItemsTo() [3/3]

int CityBuilderCore.ItemStorage.MoveItemsTo ( ItemStorage other,
Item item,
int maxQuantity = int::MaxValue,
bool overfill = false )
inline

moves quantities of an items to another storage, may be limited by a maximum quantity

Parameters
otherthe receiving storage
itemthe items to move
maxQuantitythe maximum quantity that may be moved
Returns
the actual quantity moved

◆ RemoveItems() [1/4]

int CityBuilderCore.ItemStorage.RemoveItems ( Item item,
int quantity )
inline

removes items from storage and returns the remaining quantity if not enough items were present
(removing 4 items from a store that contains only 3 will return 1)

Parameters
itemthe item to remove
quantitythe maximum quantity to remove
Returns
remaining quantity not removed

Implements CityBuilderCore.IItemContainer.

◆ RemoveItems() [2/4]

int CityBuilderCore.ItemStorage.RemoveItems ( ItemCategory itemCategory,
int quantity )
inline

removes items from storage and returns the remaining quantity if not enough items were present
(removing 4 items from a store that contains only 3 will return 1)

Parameters
itemCategorythe itemCategory to remove
quantitythe maximum quantity to remove
Returns
remaining quantity not removed

◆ RemoveItems() [3/4]

int CityBuilderCore.ItemStorage.RemoveItems ( ItemCategoryQuantity itemCategoryQuantity)

removes items from storage and returns the remaining quantity if not enough items were present
(removing 4 items from a store that contains only 3 will return 1)

Parameters
itemCategoryQuantitythe itemCategoryQuantity to remove
Returns
remaining quantity not removed

◆ RemoveItems() [4/4]

int CityBuilderCore.ItemStorage.RemoveItems ( ItemQuantity itemQuantity)

removes items from storage and returns the remaining quantity if not enough items were present
(removing 4 items from a store that contains only 3 will return 1)

Parameters
itemQuantitythe quantity of item to remove
Returns
remaining quantity not removed

◆ ReserveCapacity()

void CityBuilderCore.ItemStorage.ReserveCapacity ( Item item,
int quantity )
inline

reserves capacity for an item that may be delivered in the future
makes sure that capacity is still available when the item arrives

Parameters
itemthe item to reserve
quantityquantity of the item to reserve

Implements CityBuilderCore.IItemContainer.

◆ ReserveQuantity()

void CityBuilderCore.ItemStorage.ReserveQuantity ( Item item,
int quantity )
inline

reserves a quantity of an item so it can be collected in the future
makes sure the items dont get removed from somebody else until it is acutally removed

Parameters
itemthe item to reserve quantity for
quantitythe quantity to reserve

Implements CityBuilderCore.IItemContainer.

◆ UnreserveCapacity()

void CityBuilderCore.ItemStorage.UnreserveCapacity ( Item item,
int quantity )
inline

removes a reservation made by ReserveCapacity(Item, int)
should be called when the items arrives or if the delivery got interrupted

Parameters
itemthe item to unreseve
quantityquantity of the item to unreserve

Implements CityBuilderCore.IItemContainer.

◆ UnreserveQuantity()

void CityBuilderCore.ItemStorage.UnreserveQuantity ( Item item,
int quantity )
inline

removes a reservation made by ReserveQuantity(Item, int)
should be called when the items are collected or if the pickup was interrupted

Parameters
itemthe item to unreserve quantity for
quantitythe quantity to unreserve

Implements CityBuilderCore.IItemContainer.