public void addResourceToCrate(List <RTSCargo> cargo, RTSCargoType type, float amount) { for (int i = 0; i < amount; i++) { cargo.Add(new RTSCargo(RTSCargoType.ironOre)); controller.RemoveResource(RTSCargoType.ironOre); } }
/// <summary> /// Finds resource in target list /// Possible duplicate of RTSResourceContainer.FindResourceContainer /// </summary> /// <param name="cargo"></param> /// <returns>Resource structure of given type, default if not found</returns> public RTSResourceContainer FindResourceContainer(RTSCargoType cargoType) { foreach (var v in target) { if (v.cargo.CargoType == cargoType) { return(v); } } return(default);
/// <summary> /// Adds resource to the inventory /// </summary> /// <param name="type">Resource type</param> public void AddResource(RTSCargoType type) { for (int i = 0; i < resources.Length; i++) { if (resources[i].cargo.CargoType == type) { resources[i].amount++; } } OnResourcesAdded.Invoke(); }
/// <summary> /// Removes resource from the inventory /// </summary> /// <param name="type">Resource type</param> public bool RemoveResource(RTSCargoType type) { for (int i = 0; i < resources.Length; i++) { if (resources[i].cargo.CargoType == type) { if (resources[i].amount > 0) { resources[i].amount--; return(true); } else { return(false); } } } return(false); }
public RTSCargo(RTSCargoType type) { CargoType = type; }