diff --git a/Assets/Scripts/City.cs b/Assets/Scripts/City.cs index 8cb47e3da408a2bce610a8336315573397eba7e1..9ceb0a4efc073e8532b2c3b75ec2a3f1257a4c3e 100644 --- a/Assets/Scripts/City.cs +++ b/Assets/Scripts/City.cs @@ -17,7 +17,7 @@ public class City : MonoBehaviour * Kayttaa resurssia r, maaran 'amount' verran (amount >= 0). * Voidaan kayttaa maximissaan sen verran resursseja mita niita on kaytossa. */ - public void useResource(Resource r, int amount) + public void UseResource(Resource r, int amount) { if (amount<0) { @@ -26,12 +26,13 @@ public class City : MonoBehaviour ResourcePool[] lista = gameObject.GetComponents<ResourcePool>(); for (int i = 0; i < lista.Length; i++) { - if (lista[i].getResource().GetType().Equals(r.GetType())) + if (lista[i].GetResource().GetType().Equals(r.GetType())) { - lista[i].useResource(amount); + lista[i].UseResource(amount); } } } + /** * Lisaa resurssia r, maaran 'amount' verran (amount >= 0). @@ -39,7 +40,7 @@ public class City : MonoBehaviour * ts. jos nykyinen resurssimaara + lisatty maara >= maximikapasiteetti * niin uusi resurssimaara = maximikapasiteetti */ - public void addResource(Resource r, int amount) + public void AddResource(Resource r, int amount) { if (amount<0) { @@ -49,14 +50,26 @@ public class City : MonoBehaviour for (int i = 0; i < lista.Length; i++) { - if (lista[i].getResource().GetType().Equals(r.GetType())) + if (lista[i].GetResource().GetType().Equals(r.GetType())) { - lista[i].addResource(amount); + lista[i].AddResource(amount); return; } } ResourcePool respool = gameObject.AddComponent<ResourcePool>(); - respool.setResource(r); - respool.addResource(amount); + respool.SetResource(r); + respool.AddResource(amount); + } + + /** + * Lisaa kaikkien resurssipoolien maxKapasiteettia x:n verran + */ + public void IncreaseCapacity(int x) + { + ResourcePool[] lista = gameObject.GetComponents<ResourcePool>(); + for (int i = 0; i < lista.Length; i++) + { + lista[i].SetCapacity(x); + } } } diff --git a/Assets/Scripts/ResourcePool.cs b/Assets/Scripts/ResourcePool.cs index da4ec052a8c32be22dfb77681c135f6b8517bb96..c4d6843f04a4841d78f252e0cb0f6c297f7e6037 100644 --- a/Assets/Scripts/ResourcePool.cs +++ b/Assets/Scripts/ResourcePool.cs @@ -18,19 +18,19 @@ public class ResourcePool : MonoBehaviour void Start() { } - public void setResource(Resource r) + public void SetResource(Resource r) { this.r = r; } - public Resource getResource() + public Resource GetResource() { return r; } /** * Kayttaa resurssia maaran X verran */ - public void useResource(int x) + public void UseResource(int x) { if (this.amount - x <= 0) { @@ -44,7 +44,7 @@ public class ResourcePool : MonoBehaviour /** * Lisaa resurssia maaran X verran */ - public void addResource(int x) + public void AddResource(int x) { if (this.amount + x >= this.maxCapacity) { @@ -55,4 +55,8 @@ public class ResourcePool : MonoBehaviour this.amount += x; } } + public void SetCapacity(int x) + { + this.maxCapacity += x; + } }