Let’s have some fences!

Fences have been long on the game’s todo list. Being a really neat feature described by a single word, it comes with a lot of problems to solve. How does one approaches a feature like that?

First the “wants” had to be outlined. Fences might have a number of variants and uses in the game:

  • Short crossable fences can be used to designate grain fields and orchards. Purely aesthetic
  • Medium breakable fences. Can be a weak fortification, slowing down enemy advance. Maybe they can also be used to keep the cattle
  • Tall tough fences can be a better fortification. More expensive and harder to break
  • If we think about it, fences around house building sites are somewhat related too

Next comes the problems and features exploration phase. Here’s a short FAQ I did on fences before starting the work. Each line poses a problem and has a solution below. The FAQ is not final and solutions can be changed to accommodate for unforeseen problems, but for now I’m quite happy to have most of the questions answered:

  • How are fence plans placed
    • New plan type. Placed between tiles. One side must be walkable/reachable. Cursor magnets to nearest edge and outlines it.
  • How fences get built
    • By builder. He arrives on adjacent tile, digs for a while, waits for timber and hammers the fence in place
  • What do fences cost 
    • At least one wood or stone
  • On which side of the fence should the builder remain?
    • Let the fence plan direct from which side it gets built
  • Do builders walk through fences?
    • Maybe they don’t. Let the player manage the sides from which to build.
    • We could allow Builders to walk through fences. But this would break all the immersion and logic. Unless we show Builder hits a fence several times to remove it, walks though and then builds it back again? Builders do walk through small house plan fences though..
  • How fences get demolished?
    • Instantly in a puff of dust
  • How fences get destroyed?
    • Adding hp would be complicated. Let it be just a chance-based instant destruction. 
    • Maybe we can have a breaking animation and fence remainders on the ground?
  • How tough are the fences?
    • We can “roll dice” each hit. Chance of destruction can be linked with warriors attack.
  • How do we discourage extensive fortifications, are they a problem?
    • Likely not. The cost is quite high after all.
  • Whose property fences are?
    • Fences belong to a player (so warriors know whose fences to break and whose to walk around)
  • How do fences interact with houses?
    • Fences should be allowed to make perpendicular contact with houses
    • Fences could be allowed to go alongside house border later on, but likely it’s not needed
  • How to build fenced area for cattle?
    • To become cattle yard it needs to be enclosed
    • Area can be built by builders
  • What is a yard?
    • Any enclosed area of size 4+ touching the house (e.g. side). Max size is .. ?
  • How do animals appear inside the yard
    • Breeder can bring them from the house
  • How do animals disappear from the yard
    • Breeder takes them out
  • How does Breeder carry the animal?
    • Animal goes by itself on a whistle?
    • Animal gets “follow” order?
    • Animal is taken into hands? (as in KaM) 
  • What if fence gets broken?
    • Yard becomes ordinary terrain
    • Animals can walk away
  • What if fence gets restored (or is built around existing animals)
    • Area becomes yard again
    • Breeder can access animals in the yard
  • What if player builds several yards
    • If they are accessible by Breeder – he can use them
  • What if there are odd units/animals in the yard
    • They remain there, if they can not escape
  • How do animals breed?
    • Breeder brings them in
  • What do animals eat
    • Grass and grain brought by Breeder
  • How do animals grow?
    • Cows/Horses grow +1 for each grain eaten
    • Sheep remain at the same size and just grow more wool
  • Do we always need fences 
    • No, if the area is naturally enclosed it should be fine too

This FAQ covered the player-side of things. Having that done the coding could begin. The code was written in a separate SVN branch to allow for easier comparison of before/after and overall changes made.

There was a number of cross-dependent problems in implementing of the fences. Here are some of the solved ones:

  • Fence edges block diagonal unit passability across a vertice between tiles (just like trees and such). However a fence has 2 endpoints, so code had to be updated to let 1 object block 2 vertices.
  • Fences go along tile edges and thus block unit passability. All the passability/pathfinding methods had to be updated to check the edges between tiles for passability
  • Unlike roads and fields, fences need to be built from specified side. Fence plan list had to account for that.
  • Enemy fences should be breakable, so the passability for warriors had to “ignore” the fences and still plan paths through them, knowing that warrior will break the fence on approach.
  • Breaking enemy fences should not interrupt current warriors order
  • Warriors should not break allied fences. Which means the terrain traversability now had to account for player alliances.
  • Breaking a fence should take some time (1-3 hits depending on warriors strength). Had to come up with a simpler formula for that
  • There needs to be support for different fences (visually and mechanically) at least for mapmakers. Thus the fences are planned to have properties and types.
  • Had added dynamic script commands to add or remove a fence.
  • Fences had to have player color markings on them. Since terrain render is already overly complex and overlay render caused some Z-fighting bugs, fences had to be made to render via a different approach that allowed for colors.
  • Refactorings had to be made along the way to adjoin similar methods encountered throughout the code.

Remaining problems and features:

  • Own fences need to be demolishable. There’s still no support for that yet. Not sure if this should be done with a confirmation or not.
  • It would be nice to have own and allied fence lines to be permeable without destruction. Should the gates be added, and if yes – that’s another bunch of problems to solve
  • It would be nice to have fence breaking animation
  • Cattle yards are a whole new can of worms. They will likely be implemented as a separate feature after the fences development is complete.

Fences are available since Alpha r8455. There’s already been some testing going on and a small bunch of bugs fixed.

This entry was posted in Live progress. Bookmark the permalink.

7 Responses to Let’s have some fences!

  1. Lautaro Zualet says:

    but what happens when 10 horses will soon be surrounded by a fence that covers a large area?

  2. The_Crow_ says:

    hi Krom,

    thx for developing this game. Looks very good so far.

    I was wondering what software are you using for the 3D Models of units, buildings and trees? maybe I can help on making some buildings and stuff.

  3. Cluckenstein says:

    This…. This is amazing. At first i wasnt realy interested and was here only because of the KaM remake, but now that the game is more polished and has new ideas(fences, camps etc.) i may even switch to it.

Leave a Reply to Lautaro Zualet Cancel reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.