
Hi everyone,
Last week I outlined some of the tasks that I would have in creating the pioneer wagon, so this week I want to explain some of the basic questions I had to answer when I started programming it, and why.
To begin with, it might be important to mention that I always try to reuse code if possible. This makes it both faster to create new systems, and means that future changes and bug fixes can be done centrally, rather than having to be copy pasted multiple times. So with that in mind, I had of course hoped to reuse the code I am using for the other “units”, i.e. villagers with the pioneer wagon. This would mean I could use the same system to give movement orders as the soldiers, could use a similar UI to what we have for the villagers when the player opens the book, and many more.
However, there are of course many differences between a regular villager and the wagon, which led to some essential questions that needed to be answered to see if it actually made sense to reuse the villagers’ code. Starting with the first important difference: Villagers always have an accommodation, and require food. This is woven quite deeply into the code and affects many different aspects (including how to handle their death or reassignment), so there would need to be a lot of checks that recognize not to run this code for the wagon.
However, this code is also not run for pirates. Pirates have been around pretty much since version 0.1 of the game, and so much of the more complex code has been added with them already in mind - checking if the current person is a pirate, and acting accordingly. Which begs the question: should I treat the wagons, at least for those purposes, as a pirate? This would have been a potentially quick way of creating a wagon that doesn’t require food or an accommodation, but otherwise benefits from many of the mechanics that apply to villagers.
Of course there were many more considerations: Pirates are treated differently by the game not just for their food and accommodation needs, but also for how they handle different tasks (they are all soldier units after all), whether they initialise GUI elements (since players can’t interact with them in the player book, there is no need to have a GUI element after all), and many more aspects. So, making them straight up pirates would simply not be good enough.
Overall, there were a couple more questions that I ended up going through (and discarding): Should wagons be treated as moving buildings instead? (Especially when realising that they will be the accommodation for the 4 villagers they carry until they create their outpost.) Should they instead be a completely new type of unit (and if so, are there additional units in the future that may use similar code, such as the ox carts?), etc, etc.
In the end, I decided that I was indeed going to create all new code for them. I will of course copy a lot of the relevant code from other units, but I think that they are sufficiently unique in how they function, that creating a new unit for them is justified. Creating this code is going fairly well so far, so I will keep you updated!
Until next week!