program a village system in c#

stad_nico

New member
Joined
Jul 6, 2020
Messages
3
Programming Experience
Beginner
I am very new to c# and to programming in general and I have quite a complex idea and I dont know how to do that properly. So my idea is to have a village that the user can build itself, meaning he can build houses, farmlands,... and there are 50 people living in that village. What I thought of was a system like you have an array of tasks and every frame the people that dont have any task assigned choose one from the array. Each object except houses produce something when theres a person at that object, for example when a person is at a farmland, that farmland produces five carrots each five seconds. What I want is something like: a person doesnt have a task, so it chooses for example bringing 50 wood to a house, so that it can be build. That task would require him to search the village for storage rooms that contains wood, then with pathfinding go to the storage room, take that wood and again with pathfinding go back to the house and deliver the wood. Then the person chooses another task like bulding that house, and that task only gets pushed into the task array whem all ressources that are needed to build it are there. Building that house meaning going there and staying there for an amount of time for example five seconds. The pathfinding is not the problem, I already programmed something like that. I really dont have any idea of how to do what I tried to explain above. Anybody who is still reading thank you for your attention, and anybody who really thinks about how to help me, thank you soo much!
 
As with any programming task, the idea is to break the big problem into smaller problems. Try to solve the smaller problem. Quite often, the smaller problem needs to be broken down into yet even smaller problems.

Anyway, it seems like you've already got parts of the problem figured out by needing a task array. I would recommend a Queue<T> or List<T> instead of an array so that you are not bogged down with managing the contents of the array. You simply need a game loop that just keeps track of your villagers and a state machine for each of your villagers so that they are either: working at a location, pathfinding to a location, picking a new task.
 
Looks like you are getting the same advice about breaking down the problem in StackOverflow:
 

Latest posts

Back
Top Bottom