Of Hexagons and Databases
Weekly Summary
I kicked off this week by finishing up the Fire action. While it was a bit more complicated than initially expected I still managed to get the entire thing completed early in the week. I did, however, have to take a quick refresher on hexagonal grids (thank you Red Blob Games for existing). With that out of the way I took a quick detour with a refactor of something that was bugging me for a while and then dived deep into the next big thing: building!
As expected, this was very complicated. I tried to get straight to it by just coding-away but it quickly became apparent that I needed to reevaluate the entire game mechanic, my code and even how I was dealing with data. I’ll probably write a deep-dive into this entire thing once it’s done but, in the meantime, enjoy this weeks blog entry!
Work Log
Total Time: 12 hours
Features (10 Hours): Completed work on the Fire action: testing, UI, game testing… All done! That took around 4 hours total so, the rest of the “feature time” was spent planning/designing/re-thinking the Build action. The idea here is that squads with “Engineer” units will be able to build certain structures in any given tile; these structures will then modify the stats (attack, defense, movement speed…) of whatever squad is occupying them. I tried to get straight into it but - as expected - this feature required a bit more thought.
Initially, I had planned for a wide variety of structures: Hospitals that healed X injured units per turn, Refuges to decrease how many units get sick, Soldier’s Home* to increase squads morale… But it became apparent that this was over-complicating things (especially for an MVP) while also not providing any interesting gameplay for the players (we already have Medics and Commissars to heal units and increase morale respectively). Instead, I decided to reduce the number of structures to: Roads (increase movement speed), Defense and Offense (which increase defense and attack respectively).
Then there was also the matter of handling data: I’m currently working “JSON” as a “database” (with a looooot of quotes); this was fine for the initial stages of development - since it allowed me to hit the ground running - but now the project is at a point in which having an actual database could help greatly. I’m currently usingDictionary
andList
to store data and a bunch offor
,foreach
and.Select
to retrieve it: it’s making interacting with the data wildly inefficient and the entire codebase very hard to read. I’ve settled on SQLite as a solution and I’ll be looking into implementing it shortly.
So, with that out of the way, I got to actually planning and designing the feature. All-in-all, this took around 6 hours and not a single line of code was produced; still a productive use of time.Refactoring (1 Hours): Unity’s tile system uses
Vector3Int
even though Hexagonal Tilemaps use the “Offset” coordinate system (it simply has thez
coordinate always set to 0). This has been bugging me for a while because it makes reading the code rather confusing:Vector3
is the “World” coordinate andVector3Int
is the “Cell” coordinate. These two types are too close for comfort, can lead to confusion and, to make matters worse: Unity auto-converts from one to the other, rendering the type system useless. Instead, I decided to make “Grid” coordinatesVector2Int
which better represent the actual coordinate system and do cause type failures if used in place ofVector3
. This change didn’t take too long and I expect it will help moving forward.Learning (3 Hours): I spent around 1 hour doing a refresher course on Hexagonal Tilemaps, more specifically: calculating distance (I can’t recommend Red Blob Games enough if you ever need to deal with hex-based tilemaps). I also had some issues with understanding how Unity uses the Offset system but ended up figuring out that they simply flipped rows and columns: x represents the rows and y represents the columns (opposite what anyone with any graph experience would expect). Also spent around 2 hours continuing with “Reluctant Warriors”; I learned how, at one point, soldiers and conscripts in both sides were hopeful/wishful for an armistice or peace treaty but higher-ups didn’t allow it (or even allow for discussing this in public). This seems incredibly sad and further cements the idea that people didn’t want this war or fight for their ideals.
Progress
Fire action is done!
Refactored all
Vector3Int
to beVector2Int
(better representing coordinates in the grid as well as taking full advantage of the type system).Started designing the Build action (and all it entails).
17 new tests.
Issues
I was kind of frustrated when I couldn’t write any code for the Build action this week (even though design, planning, simplifying and improving a feature is “tangible” progress). I simply need to remind myself that all progress is progress, even if I don’t end up actually writing any code.
Next Week
Simply gonna focus on the Build action. If by any miracle I get that done early (very doubtful) I’ll probably start work on implementing SQLite in the project and reorganizing code a bit. See y’all next week!
Foot Notes
* The “Soldier’s Home” was a concept used by the Republican Popular Army. A place where soldiers could go to rest, read, relax and even learn. I thought it was a pretty cool concept to include - since a significant portion of the Spanish population at the time was illiterate - but in the end it felt like over-complicating things (as previously mentioned).