Monday 14 October 2013

Modelling rural to urban, take two

Kirkcudbright high street, showing development of closes
and pends on runrig.
In an earlier post, I wrote about modelling the change from rural to urban, and I did so in the context of what was a grid based landscape. And that really does not work for me, because artefacts of the grid are bound to show up in the final settled landscape model, and it won't look natural. So although for height-maps I may continue to have an underlying grid - mainly because there's so much code of other people's I can re-use - I'm going back to thinking that for rivers, roads and boundaries and for point features like buildings I need to overlay what is essentially a vector map.

So, going back to populating a game world, the first generation of settlers wander the landscape moderately randomly until they find good farmland. Then they reserve themselves a long quadrilateral, not necessarily perfectly rectangular. The width of that quadrilateral is the approximate width of two building units. Why? It will become clear. The length will be approximately eight to ten building units. The quadrilateral, like a div in HTML, will be laid out with a certain padding, more at the ends, less at the sides, into which other plots may not intrude. The padding at the ends of two facing plots will naturally become a street - actors will traverse it because they may not traverse actual plots. Similarly, padding to the sides of plots will naturally become closes, wynds or alleys.

Settlers will prefer to settle near existing settlements. So a second settler will reserve a similar long quadrilateral either facing or alongside the first, and so on. This gives us a runrig settlement. I was worried about the position of buildings for a while, but I've seen a solution: one does not actually assign building positions until the landscape is rendered; instead, you assign plots 'building scores' - simple numerical values - which are incremented as the occupant of the plot gets more prosperous over time.

When, finally, the landscape is rendered, buildings are constructed as follows. Each plot constructs one building unit at a plot end adjacent to a street. Then, iteratively, for as long as there are remaining building scores, each plot which has remaining building score constructs a new building unit and decrements its building score.

The rules for positioning new units are as follows:
  • Street frontage (at either end of the plot, provided there is a street there) is used first. Recall that a plot is the approximate width of two units.
  • If a building is not already taller than its immediate neighbours, a unit may be added 'upstairs' (up to an absolute limit of N stories, where N is probably four).
  • Where an upstairs unit is on a street frontage and adjacent to a building on a different plot (long side to long side), the unit will extend over the side padding to form a pend.
  • If it's impossible to build up because neighbouring buildings are not yet tall enough, a new ground floor unit will be built behind the street frontage, alongside the close. If one neighbouring plot already has a building on a close, that side of the plot will be favoured.
  • Buildings on a plot behind the street frontage will always be on the same side of the plot.
  • Buildings on a plot behind the street frontage will never be taller than the buildings on that plot on the street frontage.
The rendering of building units will be as described in my note settling a game world - i.e. the materials and details will be related to the local geography, and the materials which would be 'naturally available' in it.

This means that for any plot we need only store the vertices of the plot, and the building score. The first vertice of the plot provided the seed for a random number generator which informs the construction of the building, guaranteeing that it will always be rendered the same. If the economy model continues to be run while the game is in progress, a prosperous non-player character may add additional building units to their plot during the course of the game, but the procedural algorithm sketched above ought to make this natural.

There's an implication that, to allow for non-player characters becoming less prosperous, whether due to action of the market or war or pestilence, buildings ought to be able to fall into ruin, so for each cell model of a 'complete' building there ought to be at least two models of that cell in states of dilapidation, and some form of 'negative building score' to drive that; but this is getting a long way ahead of myself.

No comments:

Creative Commons Licence
The fool on the hill by Simon Brooke is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License