

Violence, and he would not share it with these stinking beasts. You can also add recuring tasks - the easiest way will probably be to just add the task with timeout again to the graph each time it is done.MacGyvers_Mullet Rognar:(11 November 2007) sword slid through the goblin's throat and the dying creature fell You can also add priorities to nodes, and the task may be to find such ordering, among all orderings that fullfil the dependencies, that has the bigger priority nodes performed first. In such case the algorithm should probably indicate to the player that these tasks can't be done. It's also possible that there are no way to sort a graph topographicaly - this happens when there are cycles in the graph (you have no wood, to get wood you need to chop a tree, to chop tree you need axe, to make axe you need wood). Now, there are many such orderings usually (because some nodes have no dependences and can be put anywhere, and some nodes have the same dependences and aren't dependent on each other so they can be in any order between themselves, and any node can be put in any place after it's dependencies are done, and before nodes depending on it are done ). You want to do all the tasks, so you need to produce SOME ordering of the nodes that is topographicaly OK (the depending nodes are after the nodes they depend on). You have a graph, each node is a task that needs to be done, and some nodes depend on some other nodes (this is represented by an edge in the graph from depending node to the node it depends on). So this is basicaly topographical sorting problem. if unit dies at ANY step, the resource he locked must be released)


In case of deliveries e.g.: WorkTask operates with a WorkPlan. If you can make sequences pretty general, there's not much of a spaghetti code.
Lager dwarf fortress ascii code#
Whether you implement this in code or in an external file like XML is up to you. Logically, you can represent these commands as a flow chart, that is run from the top each time, and what you do depends on whether you answer yes/no at each step. It's easy to get stuck in loops, since there is no state and no awareness of being stuck.No state - you can run this list from the top for any dwarf in any state, and the dwarf will just Do the Right Thing TM.Flexible - you can freely decompose this list, add items, remove items, combine items.Am I carrying wood? Yes: go to a stockpile.Am I carrying wood, and at a stockpile? Yes: drop it off.What I suggest though is to break the list into steps, with each step having prerequisite(s), and then you run the entire command in reverse. So my question is, how do I implement a command ordering system like dwarf fortress and avoiding spaghetti code at the same time? are there any data structures that I need to study? Do I need to put the command sequence on a separate xml file?Īt first you see that your commands are in the form of a list, so your first instinct might be to recreate that structure, and each dwarf will run through that list in sequence. What I'm afraid of is how this would get messy when I create more orders like this: 1 which goes from idle state to reaching the destination tile of the tree. I already have a stack command working no. What is the most elegant way to implement a command ordering system for AI? for example in dwarf fortress when you mark a forested area for wood cutting, the dwarfs then would do the following sequence:
