I continue...

posted in Computer food
Published March 08, 2006
Advertisement
Let's add another 2 hours on the project - two hours and not much code, because I was unable to correctly think.

The new classes in the project are:
  • FightModifier: this class contains informations about the fight modifiers (selected weapon, attack, defense) of a creature. It contains only temporary datas, since they can be invalidated at any moment. As a consequence, FightModifier is populated only when the creature attacks or defends itself.
  • FightModifierPopulator: well, I already told you that I found a job for the InventoryVisitor class, and here it is. FightModifierPopulator inherits InventoryVisitor and implements two visit() method: one for the InventoryObjectWeapon and another one for the InventoryObjectArmor. The informations it gets is then used to populate the creature's FightModifier instance.
  • CreatureHolder: remember the CreatureGroup class? It was handling a group of creature. Now, it handles a group of CreatureHolder, an object that bind a creature to a creature behavior. The CreatureGroup class doesn't change much (the interface now use CreatureHolder instead of Creature, but that's not really a big problem).
  • CreatureBehavior: this abstract class implements the behavior of a creature - ie its intelligence. It is a pure IA based stuff, but it is still very important. For instance, I can't fight if I don't know how the AI-controlled creature will act during the fight - maybe they'll attack, maybe they'll launch a spell or drink a potion, I don't know. Giving this kind of information is the role of the CreatureBehavior class.
  • CreatureAction: CreatureAction instances are strategies that implemente the creatures actions - fight, drink potion, and so on. The implementation of these action is application defined (and probably depends on the game core)


Only a couple a classes, as you see. I've been slow for a stupid reason: I wasn't able to think to put the CreatureBehavior instance outside the Creature class. The problem is that the CreatureBehavior manage actions, and those actions needs to know the Creature class - the implied circular dependency was rather stupid, and I wanted to get rid of it before coding. And then I went in my kitchen and got a drink (fresh water). The light came: the creature doesn't care about its behavior. As a consequence, I can remove the CreatureBehavior from my Creature class and tada, the circular dependency disapear.

And I was very slow at figuring this. My bad.

So far, I've implemented 33 classes, spaning over 51 files representing 51,3 KB and containing 1433 lines of code. That's pretty... weak. Yesterday, I had to deal with a file written by a contractor some yaers ago, and the constructor of the class was 1950 lines long - insane programmers, who open files, show message boxes, asserts everywhere in a constructor but never throw any exception.

Anyway, I have to goto bed now. I'm tired :)
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement
Advertisement