float outputMultiplier = 10000;
Iterator<Resource> inputResourcesIterator = cityImprovement.getType().getInputResourcesIterator();
if (inputResourcesIterator != null) {
while (inputResourcesIterator.hasNext()) {
Resource resource = inputResourcesIterator.next();
int inputResourceQuantity = colony.getResourceQuantity(resource);
int tempMultiplier = inputResourceQuantity / cityImprovement.getType().getInputQuantity(resource);
if (tempMultiplier < outputMultiplier) {
outputMultiplier = tempMultiplier;
}
}
}
Iterator<Resource> outputResourcesIterator = cityImprovement.getType().getOutputResourcesIterator();
if (outputResourcesIterator != null) {
while (outputResourcesIterator.hasNext()) {
Resource resource = outputResourcesIterator.next();
int out = cityImprovement.getType().getOutputQuantity(resource);
int maxOut = cityImprovement.getType().getMaximumOutputQuantity(resource);
if (cityImprovement.getType().getMaximumWorkers() > 0) {
maxOut = maxOut * cityImprovement.getNumberOfWorkers() / cityImprovement.getType().getMaximumWorkers();
}
if (out * outputMultiplier > maxOut) {
outputMultiplier = (float) maxOut / (float) out;
}
}
}
inputResourcesIterator = cityImprovement.getType().getInputResourcesIterator();
if (inputResourcesIterator != null) {
while (inputResourcesIterator.hasNext()) {
Resource resource = inputResourcesIterator.next();
int resourceAmount = (int) (cityImprovement.getType().getInputQuantity(resource) * outputMultiplier);
Executor.getInstance().execute(new ResourceRemoveCommand(colony, resource, resourceAmount));
}
}
outputResourcesIterator = cityImprovement.getType().getOutputResourcesIterator();
if (outputResourcesIterator != null) {
while (outputResourcesIterator.hasNext()) {
Resource resource = outputResourcesIterator.next();
int resourceAmount = (int) (cityImprovement.getType().getOutputQuantity(resource) * outputMultiplier);
Executor.getInstance().execute(new ResourceAddCommand(colony, resource, resourceAmount));
}
}