Monday, April 5, 2021

Creating a (mini)map

How can one play a game with such a big map without the help of a minimap? - time to start working on that.

Today I will be creating the base for the minimap, I'll first be mapping out the terrain of the world - buildings and all that will come a little later on.



To color the terrain I just need to sample the game world by the relative coord on the minimap(I made the minimap resolution work per chunk so you'll get the same "pixel per hex" on different map sizes), sounds pretty simple in theory - and luckily this time it is.

I can easily convert the texture [x,y] pixel coord to hex grid (same math used for the mouse position) -> get a hex -> get the texture index for the terrain -> get the terrain texture from the texture array I use in the terrain shader -> average that and stick it in the minimap [x,y].

Viola - minimap!


Oh right... the water... doh!

Ok, so let's say that if a hex is underwater we'll lerp the color to blue-ish by how deep the water is from 1-16 elevation steps


well.. had a feeling the low end won't be enough, maybe we'll force it to be atleast half blue?


Ah - that's better!
Still could use some tweaking though, and I don't think a simple square/inverse square will do.
Time to whip up my favorite solution - AnimationCurve!


It's a subtle change, but I think it's much smoother.

I forgot to mention, those minimaps are on a 35x35 map with a resolution of 8x8 per chunk, here is the same map with different resolutions going from top left to bottom right (1x1, 2x2, 4x4, 8x8, 16x16, 32x32)


I know you can't really see a difference between 8x8 and higher, but I'll be adding a zoom function so that'll be useful then.

You know what? why wait, let's do that now, I think all I need is a ScrollView and a slider.

Here's the difference between 8x8, 16x16, 32x32 and 64x64 - left to right, bottom zoomed out, top zoomed in. (I moved them aside a bit so you can see the area they're zoomed onto)


One thing I think we can add is the clouds, should be simple enough, just like the water - only this time lerping to white instead of blue.


It's a start, I think we can call our good friend the AnimationCurve once again.



Maybe I'll play with the curve a little more, but it's much less aggressive.
 
I think that's good enough for now, when the rest of the game comes a bit further along I'll add in faction-colored building,
I'm thinking about how to display terrain height on the minimap,
Also wondering if and how to add the plants too.

I still need to save a minimap for each map along with the map data to display on the loading menu fast, but I think I'll do that tomorrow - I've spent most of the day working on the UI code and creating a main menu (nothing interesting to hear about) and it's getting late!

And a camera indicator with a click-to-move functionality should also be good, can't forget about that one.



Thanks for reading, and check back soon for more, the next video log should be ready soon along with the next test build!

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!