Pagina's

Thursday, 4 July 2019

Builders gonna build

Here we are again, in the bus to the office. Time to discuss the progress of Holocene. I did not have too much time for development because I was busy with all kinds of things, but yesterday I had a full evening to spend.

I spent it on some unplanned refactoring and work on the building mechanics. What I wanted to achieve was:

  • Buildings get built by workers interacting with them.
  • More workers mean quicker building.
  • The worker performing the initial building placement action will start building it immediately after placing the object.
  • Once the building is finished,  involved workers will look for another project to work on in their vicinity. 
This all looks quite straightforward, but it brought to light a thinking error in the planning of classes and inheritance. What I have is a structure of WorldObjects. A worldobject is a unit, a  building,  an incomplete building or a resource. These things all inherited from worldobject  because they share a lot, like name, sprite, UI etc.

Now the thinking error occurs one level deeper. Units. There are many kinds of units planned. What I tried to do is make a class for gatherers,  inheriting from Unit. Another one would be builder. This would work, under one condition: it should be either-or. 

That did not turn out to be like this. With a worker being both a gatherer and a builder, it ended up with two names, healths, sprites etc. I haven't seen it causing  problems yet, but I like my objects well-structured, so I started working on my temporary solution.

I now have a worker class, deriving from Unit. That does the job. I do want to replace it by a sort of component system. All building mechanics will go to a dedicated class, so I can have other kinds of unitshelp building without having to copy code. I did not implement it yet, because of time constraints,  but I'll go that way.

Back to the mechanics.  With the extended worker script in place, I got the above aims working. I did not yet test the searching for nearby incomplete buildings yet, but that'll be ok. I can now have builders build.

Three more issues I found:
  • When a building is placed, it did not update the nav mesh. I fixed that by a navmesh obstacle component with Carve turned on.
  • When I drag the building around the screen before placing it, it'll wipe away objects like units. I'll need the collider of the object be trigger so I can prevent that while still getting collision detection to work. We do not need buildings on top of other objects besides the ground.
  • There's a thing with selection when the incomplete building is finally replaced by the complete one. I'll have to look at that one.
Now, the bus is almost there. My last office day before going off to Greece after the weekend. Have a nice day!

No comments:

Post a Comment