I'm into a project of a resource-game simulation. What I have to do is...
"If there are enough resources available, the request will be satisfied, and the requested quantities will be subtracted from the available quantities. If there are not enough resources, the animat consumes the available quantities and wait for more resources to be available."
The question is how do I make this possible... To reduce the resource and then hold somewhere what is still needed and reduce it when there are available resources(like a loan)...
Example:
... 100 GOLD NEEDED.... but ... 50 GOLD AVAILABLE...
... REDUCE GOLD BY 50... and wait untill gold>=50 and then
... REDUCE GOLD BY 50...
etc...
Sample Code...
public void feedArmy(){
if(food>=100){
food=food-100;
System.out.println("*Feed Soldiers (-100 Food)");
System.out.println(toString());
}
else{
System.out.println("*Feed Soldiers (-100 Food)");
System.out.println("-Not Enough Food!"); //get loan instead
}
}
(After Edit) BEST SOLUTION FOR NOW:
Actually ... I thought of just reducing the wanted value from the wood and then if the number goes negative I keep the negative value turn it to positive with
Math.abs();
so if the wood is 30 and I want 100... I do 30-100=-70; then loan=-70; ...
then I Math.abs(loan); so that loan=70;
and then I do an if(wood>loan){ wood=wood-loan}
//i might need to put a sleep untill wood is refreshed again... and thats it...
I still have no idea what is that Producer/Consumer stuff...