Don't know if this question belongs here or the Game Programming forum, but I take my chances here.
I've got an idea of a game similar to Settlers, however I've never made an RTS before and there are some questions I need answered, or suggestions on...
What I mostly can't figure out is how to handle when you give your little people commands. Like tellings one guy to cut a tree and then he performs it, or tell another guy to attack something which he then does.
I've come up with two solutions to this, either just hardcode the whole "cut tree" process into a single or a couple of functions, so that once the command is given, the guy finds a tree, cuts it down, clears it from any branches and then carries the tree to a sawmill or whatever, and then all over again.
Or I could go with a way where each step is a small task. So you basically have a "work" which in this case is called "cut tree", and this "work" has smaller tasks which needs to be performed in a certain order. So for this cut tree example, the first task would be to walk to the closest/random tree. The second task would be to cut it down. The third task would be to clear cut it. The fourth task would be to deliver it to a sawmill. Then the fifth task would either be go home and rest or go back to the first task.
In code, the first example would basically just look like this:
class Character {
void performWork(WorkType ) {
// lots and lots of code, actually this is probably a bad way
// of doing this..
if( workType == CUT_TREE ) {
cutTree();
}
}
void cutTree() {
}
}
Where as the second example would look something like this:
class Work {
void addTask(Task newTask) {}
void performWork() {
// work it's way through each task
}
}
class Task {
void abstract perform(Character chr);
}
class WalkToTask extends Task {
void perform(Character chr) {
// move character to some destination
}
}
class CutTreeTask extends Task {
void perform(Character chr) {
}
}
//.. and so on..
The problem with the second example, is that these task classes would depend alot on the character class. For example, when you start the cut tree task, that task would have to start the characters "cut tree" animation and start the neccessary sounds etc, and there's alot more dependacies which I can't come up with right now. However it seems like a much nicer way, since the Character class wouldn't get so damn huge, like it would if I hardcoded everything it could do into one single class.. Of course I could skip the whole task system, and just keep the work class, and make a work class for every possible command.
Anyways what do you think of my thoughts? Am I attacking this "problem" from the wrong direction? How would you solve this, codewise?
I'm happy if I get anything to get me in the right direction, so links and stuff like that are welcome too. No books tho, I won't buy that hehe, to cheap :P