Thursday, April 1, 2021

Finishing the wall & building systems

Last post was mainly about putting variable height on the walls and updating the wall UI a bit, now it's time to finish the rest of the building system and the wall-building connections.

Right now the building system only care about terrain elevation and only allows for building on flat ground
I need to make it care about waterbodies, rivers and up/down hill separately
I also need to tell the game the height of each building/wall and make the wind interact with it
The wall-building connections also need a touch up, the building-side of thing expects a wall of a certain height and the wall are trying to find a height on the buildings (the same height that is used for the wind)



First to give the buildings height, I simply added a byte to each one of the buildings segments/"BuildCoord" (buildings can take multiple tiles and each tile has its own coord and variables) just like I added to the walls, each step is half of the terrain elevation step.

Now the walls can read some height off the building, but having them connect to the very top of the building will hardly do.
What I wanted to do is give the walls a range of heights they can connect to the buildings with, but that proved a bit more tricky(both in code and later on textures on the buildings not lining up) than I initially thought, so I decided to have a fixed height walls can connect to per building segment.

So add another byte, make sure it's less than the building height and let the walls read that for the connection height - done!
I still kinda want to be able to connect at different levels, I might be coming back to this later on.

Integrating this into the wind simulation will be very easy, I already made the grounds for this when created the wind system, just need to add the height from the wall/building (if there is one on the hex) to the variable the wind reads from.
The vision range calculation also uses this variable so buildings will now also block sight. (fog of war)



Now let's start with the terrain elevation, what I'm doing is calculating a height offset for each segment from the buildings pivot (the segment you're "holding" and rotate around while placing the building) and checking if it's in the height range for the segments.

It works pretty well as longs as the terrain isn't too crazy, I think I might need to add a limit for max offset from each of the neighbors instead of the pivot.



To add water into the mix I added two variables (again, per building segments), "minWaterDepth" and "maxWaterDepth", when trying to build it simply checks if the tile's water depth is within this range.



Rivers are a little problematic, they're directional, and taking that into account in the buildCoords is a real hassle (not impossible, just a real headache) I think I'm just going to check if a river exists in a tile, I can always update this part later on if it becomes a real issue.

What this means though is that placing building like the waterwheel can be a bit awkward, take the waterwheel picture for example(pictures below) - what I did here is require 3 tile of river in a row and blocked them on either side, forcing the river to be strait where the wheel is, if the side building was not there the wheel could be place on a zig-zag river and the wheel placement won't make any sense.




All in all most of these changes were pretty simple (as long as you don't overwork yourself and start creating problems instead of solutions - spread your work out people!), the main headache I had was with the wall-building triangulation code - I'll explain more on that when I do the video log and have some visuals so you understand what I'm talking about.




The next step I plan on making is working a bit more on the models (the current ones are mainly for figuring out the building layouts and help me build the code) and finally get to doing the "first"(the "zero-th" entry was mostly for a couple of my testers) entry into the video log and show you what it's all about!


But just so I don't leave you high and dry until then, here are some pictures from a quick little test city I created:



small housing in a row



small housing in alternating rows



medium housing in a whatchamacallit.. cul de sac



medium housing in a row



waterwheel





3 single wall segment, variable height and battlements (middle one selected)



double and triple connections



bottom segment has stairs, rising to a more elevated platform (notice the battlements only protecting who ever is higher up)



small tower



medium tower (this is a single external model, the 3 sides are not from the wall system)



small tower with 3 walls attached to it



small tower surrounded by walls



medium tower with walls attached



city walls, double gatehouse with murderholes and a tower on both sides



other side of city walls, medium tower and walls



middle of city walls, corner with small tower (left is the medium tower, right is the gatehouse)



birds eye view of everything



and also a fishing dock





All the models need a lot more work obviously, but it's starting to take shape! 😁
I also need to make the highlights a little transparent

But that's it for now - thanks for reading and check back soon for more!

No comments:

Post a Comment