Sunday 27 September 2015

Game objects as message actors

Last time I was talking about replacing simple string pointers to game object pointers and that's what I did. Now inside the message routine certain glyphs are replaced with object names. There is some uncertain stuff going on with how message routines are called. For now I'm using function overloading which is something I try to always use, but there may be later confusion with routines that have let's say one game object instance as a pointer. At the moment it always has to be something called an action object which simply means stuff creatures use like throwing an object at someone.

When refactoring the player's routines I realized that some of them are going to be moved into Creature class, because the artificial intelligence of creatures will be improved. Creatures are able to pick up and use them. It's a big step from the current engine, but I try to keep it really simple. The good thing with Teemu is that it's a goofy game so there is no need for serious AI code.

Another big refactoring part will be the map routines. As with Kaduria I'm planning to change it to "tile based" implementation where a tile object contains everything: the ground type, objects (items, creature, etc.) and other variables. The current implementation has several layers of maps containing that same stuff, so it's again a big change, but hopefully doesn't require too much work.

Even the Message refactoring itself is quite difficult, because it's not just simple search and replace. Most routines with messages are something that need to be changed so as the actor in the routine can be either player or some other object (usually a monster). As an example, there is a part where (this is probably not a big spoiler) poison arrows start to fly when you trigger a trap. Before the "arrow" was simply a piece of text, but since the object is passed to the message routine I had to make the routine create actual poison arrows (or darts). You can even pick them up if you need poison darts.

No comments: