Ok, how about unit AI?
I’ve been thinking about using a stack of states. Here’s my description of the idea (which I posted on the forum of the rts game project):
[quote]I’ve been thinking about tackling the unit behavior AI.
This is something I’ve never really done before. What I am thinking about is using a stack containing the states (state=the ai logic) the unit could be doing.
A collector could have a stack of (topmost is what the collector is doing right now):
Code:
DeployOnProtostar
WaitForOrders
AutomaticallyCollectNearestProtomatter
WaitForOrders
AutomaticallyDeployOnNearestAvailableProtostar
Reset
This could be a stack of a collector that the player has ordered to deploy on a certain protostar. The DeployOnProtostar AI state makes the collector move to a clicked on protostar and deploy there. It also contains logic to check if some other unit has deployed there first, and if so, that state is popped off the stack and WaitForOrders state is activated.
Once the collector has waited 1 minute without any human interference, it will pop the WaitForOrders state and activate the AutomaticallyCollectNearestProtomatter state.
Once it cannot find any nearby protomatter (all been collected), it will go into yet another WaitForOrders state.
Once that’s done, it will execute the AutomaticallyDeployOnNearestAvailableProtostar state. This will try to find nearby available protostar, and deploy on it. If it can’t find anything, it will go to the bottommost state.
The bottommost state is the fail-safe state and is never removed. It will reset the stack with a certain set of states (e.g. AutomaticallyCollectNearestProtomatter, WaitForOrders, AutomaticallyDeployOnNearestAvailableProtostar). In effect, it will go into a loop.
Makes sense?
[/quote]