Project 1935 Devlog #4
The two weeks leading up until this devlog have been tough, struggling with a lack of motivation, not for the project, but motivation in general led to me very rarely getting things done most days, add onto that various problems with networking that I still need to solve. All of that results in this being a relatively short devlog, but it’s okay to realise that sometimes you lose motivation, and to focus on what has actually been achieved, as opposed to what has not.
Building System
So the bulk of the time I actually got work done, it was on the building system. My aim for the game is to have each province house any number of buildings, each building doing something different, whether that be to just increase the province’s resource output, increase province happiness or to actually carry out an action and have its own UI screen such as a Barracks which would facilitate the production of units.
I could spend a long time coming up with ideas for buildings as the possibilities really are endless, but for now I settled on the Barracks, Refinery and Fortress.
I decided to have a Building object in C# that would hold the data associated with each building such as its name, UI object, modifiers and the building’s cost. I then have, on each Province, two lists of buildings, one for inactive buildings and one for active buildings. Now when a building is added to either list, it will carry all of its data with it, including the UI associated with it via the unity inspector.
Now I had the Building objects and had associated them with their UI, all I had to do was to check if the building was the the inactive or active list and then position them in the UI to show as such.
If the building is active, it will be parented to the active panel in the UI.
and if the building is inactive, it will be parented to the inactive panel in the UI.
After that, it was just a matter of changing the building’s Y position depending upon which index they are within their respective lists.
All buildings start within the inactive panel, the above code resulting in the above screenshot initially. The code is called when a province UI is opened, so as to make sure the UI is positioned correctly depending upon which province is open.
Next up was the actual effects the buildings would have on a province, I knew that, using the above system, the only thing that would change between buildings and provinces would be the UI objects and so I could make the buildings have any effect they want without altering other provinces those building objects also reside on.
Starting with the refinery, its job is to boost the provinces modifiers (how many resources they gain per tick/turn/timespan etc). As seen at the start, the building objects have a cost, and a modifiers array with the values in the order of what the values of the provinces are.
Using this, I could check if the province can afford the building by making sure the province values are more than or equal to the cost values, and if so, minus those values from the province values and activate the building by returning true to the province which would remove it from the inactive list and add it to the active list.
I now knew the building could be afforded, all I had to do was add this buildings modifiers onto the provinces modifiers.
The act shown above is the same for all of the buildings, only differing by what actually occurs when the building is purchased.
Right now, I have a hacky solution, being that the check for the type of building using a BuildingType enum is carried out on the Building object, I will probably move this out in the future, but for now it works.
Finally, I needed a way to activate the buildings other than by manually calling it within the code, this obviously meant I needed buttons.
All I needed to do was to run the routine demonstrated above, but when the button was pressed. Initially I just passed in the buildings index within the inactive list to the button’s onClick() function, and hoped for the best. This would work if you activated the very last building in the list, or on the very first try, because once you activate a building, it is removed from the list thus changing the index of all of the other buildings, and the index I pass into the onClick() function was a static number. I tried various solutions until deciding on setting the BuildingType enum of the building via the inspector and then checking which building in the inactive list has that enum, and then activating that building.
Results in
It also works between provinces
Obviously right now, the UI is temporary, but the idea is simple, and it works. Also, the values are arbitrary at the moment, but once the buildings have been given their proper values and costs, it will work as intended as tests have shown.
I hope that when I do have lots more buildings, I can use some sort of scrolling UI, or pagination, but that is for another day.
I did also fix a bunch of bugs and issues, but they are meaningless in a devlog so i’ll leave them out. Thanks for reading this Devlog. Hopefully by the next one I will have regained motivation, and will have a lot more to show.
0 comments