itch.io is community of indie game creators and players

Devlogs

Refactoring Neutral hand and alliances

Knights Province - Alpha 12
A downloadable game

Making AI to attack neutral aggressive animals (and their dens) proved to be more complicated than I thought. Why is that?

Existing AI attacks work quite simple - AI has a list of attacks it needs to run at certain times (or periods), which are "nearest unit", "nearest house", "go to location". Then AI checks if it has enough troops and launches the attack. To this time, I have planned for neutral hand to own both inert and hostile animals and houses. Which means that in order for AI to attack "any" enemy, it needs to check all enemy hands assets and also to check all neutral hand's assets individually (to pick only hostile ones). Which is sub-optimal both from programming and from code-design point of view (especially the "individual" alliance setting).

Hence I'm looking into splitting neutral hand into two separate hands: inert and hostile, so that alliance settings between hands become simple again (either "ally" or "enemy"). Rules go like in order of priority:

  • Hand is always ally to itself
  • Neutral Inert hand (Ni) will be ally to anyone
  • Neutral Hostile hand (Nh) will be enemy for anyone (except self and inert)
  • All other alliances are governed by mapmaker and mission setup (except listed above)
  • And I get rid of that temp "it depends" alliance setting )

New problems arise though. Currently in Game and in MapEd all hands are tightly packed and each hand can be of any type atm. It's a good time to fix this too. E.g. you can have 1 human hand and 7 separate neutral hands. Which is a waste of space really. Now there needs to be up to 2 different neutral hands - Ni and Nh (if hand has no assets it gets skipped). Still tightly packed on save and always on the right side of the hands palette in MapEd. Reordering hands is a bit complicated since hands hold a lot of cross-references (e.g. Goals/Objectives/Alliances/etc). Processing example goes like so: load a map into MapEd with 1/2/3/Nh hands. Append 8 more hands. Make the last hand Ni. Swap hands around for Ni and Nh to occupy the 11th and 12th slot. Do the map editing. Remove hands without assets before saving.

Another complication: previously I stored hand type in 2 fields in mission data: allowHuman and allowAI. 4 combinations of which described 4 hand types that were - Human, AI, Skirmish and Neutral. Now 5th type is needed, to split Neutral. For that I'm planning to add allowNeutralType flag/command.

There are other minor issues of course (and some bigger ones I haven't stumbled upon yet), but overall I'm feeling confident and happy about this refactoring - it will make things a bit more complicated in one small area (Ni and Nh management),but much more simple in other broader areas (since larger parts of the game work with alliances).

On to the refactoring! )

Download Knights Province - Alpha 12
Leave a comment