Search Unity

[WIP] Manor Lord (Village Simulation game)

Discussion in 'Works In Progress - Archive' started by ensiferum888, Jan 21, 2014.

  1. Ed-Frost

    Ed-Frost

    Joined:
    Sep 10, 2014
    Posts:
    10
    i'll keep an eye out for the moment i can sign up for the testing phase :p even though i dont have that much time, i'll make time to test this game.
     
  2. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    Hi everyone!

    It's been a while since I posted an update I apologize. My event system is finally done or pretty much set so that now I can start writing content on it. The event system is what guides long term and important decisions for the villagers in the game. This can range from a kid that's mad against its father because he was punished to your steward has been stealing from the treasury for years. Pretty much anything but the immediate decisions (like building something or working) is done through the event system.

    For a concrete example this is how the pregnancies are handled by the system Pastebin Link

    I think the system is pretty much self-explanatory but if you have any questions on it feel free to let me know! There are a couple of tweaks I still need to make, for example now there's no way to have OR in conditions, they all must be true or the condition block will return false.

    Also I have no way of going back to a previous event in the event chain, but other than that the system is pretty solid super easy to work with and doesn't yet incur any performance problem.

    I've also started doing textures for my UI here is what the building selection looked like before:


    And what it looks like now:


    It doesn't really show unfortunately but I spent a lot of time making celtic weaving patterns on the round buttons, up close I'm really proud of the texture but they're too small to see any details :(
     
    Thomazml and RavenOfCode like this.
  3. Thomazml

    Thomazml

    Joined:
    May 17, 2015
    Posts:
    15
    Any news? =)
     
  4. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    Hey there Thomazml,

    Nothing really tangible, to be honest I've been a bit swarmed lately and haven't had a chance to work as much as I wanted on the game. I introduced the first iteration of crimes using my event system. The only crime that people commit now is stealing money. Unfortunately one thing I noticed is when the game begins it's only you (noble) and peasants who have no money. The fact that they have no money tends to favor stealing (for those with the right traits anyways) and will only attempt to steal from you.

    This is weird because I had a game where I had 3 Kleptomaniac serfs in my village and I lost about 300g because of thieves. My lord's ruse was so low I never was able to properly identify them so they just kept on doing it. I have introduced a mechanic to Banish people (whether they're guilty of crimes or not) but nothing in place to replace them.

    This is another major pillar of gameplay as aside from rent early medieval lords made their money by collecting the judicial "tax". There were no prison time for crimes, you either payed with money, your life or were cast away. But as with any major add on there will be a ton of tweaking and balancing.

    I still need to properly scale rents, salaries (still debating on paying people based on their production rather than a fixed salary), the maintenance (right now it's only money that dissapears) I'd like to have assigned Masons who can repair and construct more advanced structures.

    There is still a lot to be done but I'm still hoping to release a playable alpha by Christmas hopefully, exclusive to this forum.

    Thank you for your patience :)
     
    RavenOfCode likes this.
  5. BornGodsGame

    BornGodsGame

    Joined:
    Jun 28, 2014
    Posts:
    587
    Just wanted to jump in this thread so I get updates,. This project looks amazing, especially for a 1-man gig working part-time on it. I love city management type games. The game I am working on, not yet announced, has a very light version of resource management, closer probably to WarCraft 2. Definitely want to pick up your game when it is finished.

    Is this going to be a facebook type game, or a single player game?
     
  6. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    Hey Carve_Online, thank you so much for the support it means a lot! Do you have any screenshots or information that you could share on your game?

    It's going to be a standalone PC game right now only building for Windows.
     
  7. BornGodsGame

    BornGodsGame

    Joined:
    Jun 28, 2014
    Posts:
    587
    We are probably a month away from putting up a site and doing the beginnings of PR. I fight the urge because of the UI not being ready yet and I don´t like the idea of ugly screenshots floating around. It is just a single player stand alone game. This is my first game going from start to finish, usually I just do contract jobs, but as the saying goes, this is the game I always wanted to play and I built up enough relationships to where I can beg for help on the stuff I don´t know how to do well.

    I am sure it is not a unique gameplay, but the way I think of it is the lovechild of an Elder Scrolls game and Warcraft 2... or a RTS where you play the only fighting unit in first person view on a really huge map (compared to they typical RTS maps). ..
     
  8. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    Updates

    Good morning everyone!! Last few sessions have been extremely productive in terms of features and portability. First I finally added a production limit on the hunter's cabin, I still need to figure out how to balance the wildlife population. For now every spring there are 50 deers spawned across the map. Your hunters sometimes will have to travel extremely far to get them. But even at that they will hunt enough deers so that you litterally fill your storeage with game meat.

    Right now I don't have a proper sink for the meat or game meat so it gets consumed as food but it's one of the last foods to be consumed as it's more expensive than say fish and bread. Hides I can at least funnel to the tanner to convert them to leather.

    So as naive as it sounds I put a limit on the hunter's cabin. Normal business have a limit so they will stop producing if the nearest barn contains enough resources and their own inventory is full. But normal business produce only one resource at a time. Hunters produce both hides and meat so how do you determine when you reached your limit?

    For now If you set for example 100 meat and 50 hides, it will stop producing when both items have been produced enough. This means you could end up with 500 meat and 50 hides though so I still need to look at alternatives.

    ---------------
    Refactoring the animals AI


    Speaking of hunting, I finally redid the entire AI for the animals. When I first started I made a DeerAI class with a CowAI class as those are the only two animals so far. I wanted to add chickens, pigs, horses, bears and wolves. One problem comes to mind right away, my Hunters have a List<DeerAI> to find the next deer to hunt... my livestock pens have a List<CowAI> to keep track of the assigned cows..

    So I did what I should have done a long time ago. I created the abstract Creature class which contains all the variables and functions that a creature would need. I then have 2 superclasses GrazingAnimal and WildAnimal which contains specific information such as the items dropped on death or the items produced such as milk or eggs. The Creature baseclass contains a field for an AnimalStateMachine class which I can use to give unique behavior to any animal I want. It took me less than an hour to get the Hunter compatible with this new system and shortly I'll redo the LivestockPen code.

    The livestock is probably the oldest piece of unrefactored code I have in this game, it needs to be redone entirely but it should be done quickly.

    So now I can make a DeerStateMachine, a WolfStatemachine and both will be attached to the WildAnimal class. I can create an entire new AI behaviour in less than 10 lines of code now. Of course making the actual model for the animal is another matter :) But I'll finally be able to test a "fighting" mechanic I'd been thinking about for a while now.

    ----
    The Mason's office

    Construction isn't merely stacking stones, a well engineered structure takes as much commitment and efforts as the monks with their colored books. - Valas Lancaster (591, Duke of Highcrest)

    The mason will be required to build more advanced structures. Most of his money will come from repairing the various buildings in your village. The advantage is if all your serfs are busy working you still have a dedicated builder for the basic constructions. This will actually be my very first step for a job that entirely depends on the population and not paid a fixed salary from it's owner. For example right now you have to pay your blacksmith 20g every season regardless of if he works or not. I'm really looking forward to see if that's going to be suitable as I'd love to have a supply and demand based economy where everyone uses everyone's services.

    The mason doesn't actually produce anything tangible but it's there to keep everything running smoothly.

    Wooden Walls:

    Not as expensive and not nearly as effective as stone walls, these can be quickly built and do not require any maintenance.

    -----
    Various updates

    I swear until the new UI is ready this is the last screenshot with that ugly white lifeless interface.

    * I tweaked the water shader to allow transparency, it doesn't really show above but you can sort of see under water, the more alligned with the plane you are the more opaque it becomes.

    * I added an attribute to the event system called hidden_tooltip which was required. Here is the event you receive when someone steals from you:
    Code (CSharp):
    1. Event{
    2.     id = Success_NotDetected_Thief.1
    3.     description = Someone stole from me but I couldn't find the identity of the thief.
    4.    trigger_only = yes
    5.  
    6.    Response{
    7.        name = Ok..
    8.        Actions{
    9.            spend_gold = 50
    10.            set_character_flag = robbed
    11.            FROM = {
    12.                gain_gold = 50
    13.            }
    14.        }
    15.    }
    16. };
    When you would hover the mouse over the response the tooltip would display for example You lose 50 gold, Philip gains 50 gold so even though you're not supposed to know who stole from you the tooltip would spill the beans. So now I can just change this line to hide specific things:
    Code (CSharp):
    1. FROM = {
    2.     hidden_tooltip = {
    3.         gain_gold = 50
    4.     }
    5. }
    * Added the ability to Banish people, of course you're the lord so you can banish whoever you want whenever you want but doing so for no valid reason will cost you some renown and give your residents a statisfaction penalty. If someone has been found guilty of a crime then you can banish them with no penalty.

    ------

    I want to thank everyone for the support, feedback, ideas and comments I have received so far. It's great I'm loving this journey so far!!
     
    Thomazml likes this.
  9. Thomazml

    Thomazml

    Joined:
    May 17, 2015
    Posts:
    15
    Just to post that I'm still coming here once a week to see the progress, don't give up! =D
     
  10. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    Thanks for the unending support Thomazml! I really appreciate.

    I've been spending the last week fixing pathfinding issues, that bug took a LOT of time to track down. I'm pretty sure I solved it now but I'm still keeping an eye out.

    I introduced a new "influence" radius around the buildings on the settlement that will act as the "borders". Wild animals will try not to step on those nodes except for hungry wolves who want to steal your livestock.

    Speaking of which I've started to experiment with combat a bit, so far the only combat interaction there is is between a wolf and someone. All based on the constitution skill, it's safe to assume a peasant will always lose a combat with a wolf one vs one.

    I really don't know how far I'll be pushing it as I really don't want combat to be a central pillar to the game. Economy is being more fleshed out. I start to slowly realizing I cannot simulate every single interaction in the trade. So instead I'm starting to generate income based on stats. The core aspect of the economy has changed considerably.

    Now what happens is the lord of the manor (you) will own every business that is with the land (crop fields, livestock, woodcutting, herb picking, hunting, fishing and mining). Production and craftsmanships based business will be owned by freemen who will have to pay taxes. I was looking for a way to merge a central economy (like we're all used to in games like this with storage areas that are available to everyone) with a free market economy.

    I believe I have found the solution. The blacksmith which is the first business every settlement needs will produce tools by default. You set a certain limit where the blacksmith will dump tools in your storage barns. Say 200, once this limit has been reached, the blacksmith will continue to produce tools but now the tools will be sold and they will earn money that way, They still earn a fraction of the money when they're still handing over the tools to you but it's reduced. This also serves as a tax payment, tools first, then a money payment from the sales they make.

    I really think this is a good direction to take but there is still a ton of testing to do.

    The game is becoming more and more UI centric, and my photoshop skills aren't getting any better. Ah well..
     
    RavenOfCode likes this.
  11. AussieSwissDave

    AussieSwissDave

    Joined:
    Apr 20, 2013
    Posts:
    97
    Great work mate. A couple of questions/suggestions:

    1) For what it's worth, I don't find the current UI to be too ugly. Perhaps give it a little bit of transparency?

    2) Will your animals attack and eat each other, and breed? It could be cool to see an evolving animal population. Things die out or hibernate over winter and your town can struggle for food, although that means you have to be smart in storing lots of meat pre-winter.

    3) The water reflections look amazing, bravo!

    4) Having said that, the edge of the river where it meats the land is too sharp. Is there a way to soften that?

    5) It seems like the rotation orientation of a given tree is always the same. Perhaps randomise it so they look a bit more varied, without having to make new trees.

    6) A minimap? Will be handy when your place gets big!

    7) Any chance of some videos of some people/animals moving around? :)
     
  12. BornGodsGame

    BornGodsGame

    Joined:
    Jun 28, 2014
    Posts:
    587
    Great progress.

    I actually removed inheritance for my creatures, I ended up having to create so many layers of classes that it stopped being useful. " well this gives meat, this gives meat and hides, this gives meat and eggs, this doesn´t give meat, but gives another food source, this doesn´t give meat but gives hides". I am just hardcoding them as I add them.

    I love the detail in your game ´stillborn´!!
     
  13. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    Thank you very much for the nice feedback!!!

    1) Thanks but I want the UI to be textured, I find the textured one bland, there's way too much information that's displayed as text. I realize that UI design is actually a thing (at which I suck) The main white UI you see will most definitely change. I'll possibly remove the Piety mechanic from the game as I haven't really found a use that Renown wouldn't take care of.

    2) So far wolves will attack your livestock or humans, wolves aren't stupid though and if there are more than 4 humans around they'll generally leave the area. The population does not evolve dynamically, every spring offsprings are born (for livestock) and the wildlife population is reset to a certain threshold for example every spring the deer population goes back to 50. This is to make sure your hunter can produce enough meat, if I had a dynamic population within a year or two there wouldn't be enough deers left on the map to feed a single family.

    3) Thanks I'm really proud of that one but I wrote only the reflection and the actual flowmap, the waves and movement are from Skrawk, he's also the guy making Ceto if you hear about that (ocean simulation).

    4) There probably is, I tried wraping my head around depth testing and it doesn't make any sense yet. I'm really into prototyping mechanics still and balancing others. This is something on my todo list but it's pretty far down.

    5) I agree a whole lot with that. The issue is I'm using the terrain system to draw my trees, more specifically my billboard trees, I have no clue how to transition to and from billboards and none of the solutions I tried work. For now the terrain system is good enough for my needs. Having unique rotations is something I would definitely like but not something I absolutely want.

    6) Indeed, I have an old minimap script but it's using the old OnGUI function, and it created a new texture every time I added a building. It had a very big memory impact. I understand the advantages of a minimap but at the same time the goal of the game isn't to get necessairly big. The bigger you get the more money you get but the more people you have to deal with.

    7) I have this video back from July the quality is awful seriously but you get a basic idea. The video is sped up from the capture because of bad framerate and wanting to keep it short. I actually just got a new computer with an Nvidia card so I'll be able to capture decent footage using Shadowplay.

    In the video above the Cropfield UI has changed a lot, the trade screen has changed as well, people now commit crimes (the justice system isn't in place yet) and I don't think I show any animals in the video I'm not sure.

    Thanks again for your time!!
     
    AussieSwissDave likes this.
  14. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    Hey there thanks for the nice comment!!

    I always loved all the small details in games so I'm trying to pack as much as possible to make the world a little more alive (by having dead babies for some reason)

    My inheritance is quite simple though, base class is Creature which holds the specie, the name, movement speed,items dropped on death, etc.

    Then I have a WildCreature which adds aggressiveness and hunger. And a PastureCreature which adds periodic resource (milk, eggs or wool) and a home location. The data itself is simply set in the inspector. So for example I set two different PastureCreature:

    Specie: Cow
    Speed: 4
    OnDeath:
    10 Meat - 5 Hides
    Periodic: 1 Milk
    ---
    Specie: Chicken
    Speed: 2
    OnDeath:
    5 Meat
    Periodic: 1 Egg

    And that's it, I attach the appropriate SkinnedMesh as a children of the prefab and the AI will get the mesh and animator components in the Start method and that's it.

    If I want different behaviors I have a base CreatureStateMachine from which I can derive. All possible actions are part of the base class and the super class just overrides the AssessNeeds method. So I can have new behaviors added extremely quickly in just a few lines of codes.
     
  15. Ed-Frost

    Ed-Frost

    Joined:
    Sep 10, 2014
    Posts:
    10
    hey there,

    any news on the testing phase?

    Ed.
     
  16. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    Hey there Ed,

    I'm sorry for the lack of updates I've been extremely busy these past few weeks. I doubt I'll be able to start a real testing phase before christmas, the game is still in a very early stage. But if you're willing to put up with bugs, UI quirks and an extreme lack of information, send me an email at hugo.mercure@gmail.com and I'll send you a preview build.

    Thank you very much for your interest though :) It's nice to know some people are curious about the game.
     
  17. Ed-Frost

    Ed-Frost

    Joined:
    Sep 10, 2014
    Posts:
    10
    looks amazing :) keep up the good work.
     
    ensiferum888 likes this.
  18. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    Hey everyone!! I captured a video last week to test my new computer's performance, I'm quite satisfied with it. When more features are implemented I'll be able to make a nice trailer hopefully.

    Here's a video showing the first few minutes of the game:
    Link

    Ed has started testing the game and his feedback will make sure I'm really busy on my next sessions! I'll be adding new features soon but will mostly concentrate on bug fixing for a while.
     
    RavenOfCode likes this.
  19. BornGodsGame

    BornGodsGame

    Joined:
    Jun 28, 2014
    Posts:
    587
    Looks amazing.
     
  20. Thomazml

    Thomazml

    Joined:
    May 17, 2015
    Posts:
    15
    News? :3

    hehehe

    Happy new year!
     
  21. Thomazml

    Thomazml

    Joined:
    May 17, 2015
    Posts:
    15
    Nothing new?? Sad, sounded promissing =|
     
  22. Ed-Frost

    Ed-Frost

    Joined:
    Sep 10, 2014
    Posts:
    10
    im also hoping to hear more.... Its been quiet for too long.
     
  23. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    Sorry about that guys!!! I haven't touch the game for 3 weeks, I needed a break. I'm not done with it don't worry!!! I,m taking some time off because every single free time has been dedicated to it for the past 3 years.. I'll come back to it shortly!!
     
    _natty, Adroytus and RavenOfCode like this.
  24. Thomazml

    Thomazml

    Joined:
    May 17, 2015
    Posts:
    15
    Hey, just to say that I'm still cheering for you and your game!
     
  25. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    Hey there Thomazml!!

    Nice to hear from you, Happy New Year! I'm so sorry for the lack of updates, school has really been more difficult than usual this last semestre I didn't get a chance to work a whole lot on the game. I'm currently working on unit movement, more specifically squad based movement. It's a lot harder than I expected lol.

    I'm working on some quality of life improvements as well such as a construction grid on the terrain and markers for building entrances.

    It's still happening lol just a lot slower than I'd like!
     
    RavenOfCode likes this.
  26. Skyfall106

    Skyfall106

    Joined:
    Mar 5, 2017
    Posts:
    132
    Hey man you probs dont know me but Ive been here for a while looking at this game and it sounds really fun! I am making a similar game to you and this game has inspired me alot! I understand you are very busy with shcool and stuff but if you could post another update I would really appreciate it :)
     
  27. cfred

    cfred

    Joined:
    Jul 25, 2014
    Posts:
    8
    Hello from a unity newbie. I'm just a hobbyist, but I have a dream about making some basic game like this, one day in the (far) future.
    I'm wondering about how to make animated crop fields. Do you have various models for each Growth stage, or is there only one model that is animated through all Growth stages?

    Cheers!
     
  28. judah4

    judah4

    Joined:
    Feb 6, 2011
    Posts:
    256
    What I've done before was have some different models for each stage, like seedling, growing, ripe, and dead. And then as I went though the life cycle I scaled the model up until it was time to switch to the new model where it kept growing. Depending on your models it is not a very smooth transition but it works and looks nice for the most part.

    If you know a bit more of programming you can procedural generation would work really well with growing and changing the mesh but that depends on your skill. And also, if you are a 3d modeller an animation/blend shapes that morph the plant through its life cycles would work really well too
     
  29. cfred

    cfred

    Joined:
    Jul 25, 2014
    Posts:
    8
    Thanks for response! I know a bit about programming (on a unity hobbyist level), and I started messing around with blender some weeks ago. I'll try out the different suggestions, and see what happens :)
     
  30. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    Hi there cfred!

    The fields are animated by the shader itself meaning there is no animation for the "growing" of the crops. I use only two models small and big and there is no transition between them it's a bit jarring if you happen to be looking at the field when it changes state but otherwise I've heard no complaints.

    The system for the fields itself has grown over time, at first every crop would be it's own game object (ouch!!) meaning I'd get 600-1200 draw calls per field., It was the first implementation but I was able to work from there and improve the system. Now when a field changes state I combine the meshes together so that I don't have to use 600 game objects per field and only use 2-4 draw calls per field.

    I started using growing animation for my trees and that only lerps the Transform.Scale vector over time.

    I know I haven't given any updates in a while it's just not stuff that I find worth showing, but don't worry good things are coming :)
     
    Skyfall106 and judah4 like this.
  31. Eastep

    Eastep

    Joined:
    May 22, 2015
    Posts:
    1
    I just wanted to hop in and say that I'm really loving what you're doing with the game! It looks great, and I love that somebody is tackling this genre again. I can never get enough of these kinds of games.

    I see that you've written some stuff about how you do events, but what I'm wondering is how you do your parsing. Are you using Unity's TextAsset stuff for it, or are you doing read write file stuff with System.IO? I'm really interested in seeing your implementation for creating the Event objects.

    As the game gets closer to beta testing, I'd also love to throw my name out their for beta testing! :D
     
    Thomazml and Skyfall106 like this.
  32. Skyfall106

    Skyfall106

    Joined:
    Mar 5, 2017
    Posts:
    132
    Is there still any hope for this project?
     
  33. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    Yes there is still hope lol! However I'm having a lot less time to work on it than I'd like :(

    I have a new UI that I started to work on but I'm mostly finishing my skinned mesh baking system, it allows me to have an unlimited combination of clothing, hair and even different colors to all my villagers yet they all share the same material and only have one mesh so I'm really saving on the draw calls while having some difference between villagers.

    I'm also realizing that some of the core mechanics probably shouldn't be a part of my event system so I'm moving them to my internal AI descision making, maybe I'll still set the flags from my event system but the whole event will be processed as an action stack rather than one quick event that happens out of the blue. For example stealing, right now the event system will check for certain conditions and juste fire off an event, I'd much rather have the person actually go to it's target house and steal from there, it would also open up the possibility of getting caught.

    But yeah, I realize that this project's scope is huge for a solo first timer!
     
    Thomazml and Skyfall106 like this.
  34. Skyfall106

    Skyfall106

    Joined:
    Mar 5, 2017
    Posts:
    132
    Haha dont worry man, shoot big or dont shoot at all. The game looks amazing and I understand its hard to balance. When do you think there will be some sort of playable version out?
     
  35. Thomazml

    Thomazml

    Joined:
    May 17, 2015
    Posts:
    15
    Well, is really massive for first game, but the results are nice =)
    And you must have learned alot!
     
  36. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    Indeed I have!! And keep learning stuff every time I try to implement something. For example yesterday I wanted to create a little cart so that people can load up more resources to transport. So I start creating it and realize the scale doesn't work at all even though in Blender it looks fine.

    I realized that a while ago, for some unknown reason my armature in blender was scaled to 0.7 and every piece of clothing was scaled to 1.4 (as a child object). Right now I have about 10 different skinned meshes I can attach to an armature to create different looking NPCs.

    I thought oh that's strange let me just put everything back to (1,1,1). I spent 5 hours trying to get everything back to normal, my animations were all messed up, baking skinned meshes was completely warping my models it was insane lol.

    But I pulled through and managed to get everything working again and this little mishap actually allowed me to have different scale across my models now so villagers aren't all the same size. It will depend on their age, sex as well as traits they have.

    I really want to showcase my system for baking skinned meshes soon as I'm really really proud of it :)

    As far as economy goes I'm still tweaking I accelerated the resources production timers, In a game like this especially where there's a clear time frame (days pass, seasons pass, year pass, people die, people are born) it's difficult to make the economy "realistic". For example if the blacksmith happens to live on the other side of the village he can spend 8-19 days just walking to work. So I'm wondering if I should simplify production to have it based on time (ex produces 30 tools a month) or production based like now where people actually have to go to the forge and spend time making tool. Right now it works for most situations but in cases where people live far from their work it can really tank your production and offset your entire production lines.

    I've decided to scrap the squads in their current implementation and instead made a Barrack work place where you can hire guards for your fief. I'm revisiting combat as well to find out what the best approach is and will be able to share some details about that soon.

    The job system for standard work places is pretty much finished and working without bugs. For example you can tell your blacksmith to keep your storage of tools at 150 so everytime your storage goes below he'll automatically go get the resources to produce more tools. You can also make one time jobs for example ask him to produce 5 long swords as a one time job or to keep a specific amount in your storage at all times.

    I don't want go give to many information because things do change all the time but I'll try my best to make an informative post with screenshots and possibly videos of the current things I'm working on :)
     
    Thomazml and Skyfall106 like this.
  37. ThisIsNik

    ThisIsNik

    Joined:
    Oct 28, 2019
    Posts:
    9
    Hey ensiferum, I read quite a bit about your development, and specifically, about your ambitions to simulate a realistic economy based on individual transactions, from the thread you posted a few years ago here https://forum.unity.com/threads/economy-design-in-a-single-player-simulation-game.353020/.

    I was just wondering, how did the economy sim turn out? Did you manage to create a transactions based economy or did you pivot to a more simplified model?
     
  38. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    Hi FortuneSyn,

    Unfortunately no not to the extent that I'd like. Right now people generate a tiny bit of wealth every month based on their stewardship skills. Having a job increases the base amount by an absolute amount (each job pays the same for now). It's very long and difficult to test different approach as it's hard to tell what consequence a decision can have 30 years in the future.

    I'm thinking about having an income per household rather than per person as right now some family members end up being super rich as they don't have to pay for food.

    For a while I was thinking about having other cities and relationships and trade with them but I'm thinking it's going to be way too hard to implement something "realistic" and fun. So I might just do it the Banished way and have random merchants pop in your town depending on the world conditions.

    So at its current stage it's still extremely basic. It's really difficult to bring together an economy that makes sense for each villager but for the lord as well because as things are right now the lord has no money problems whatsoever!

    To be honest I was more on technical details these past few months and trying to get combat to feel good which I'm still working on :)

    I'm really sorry for the lack of updates but I'd rather keep things under wraps for the time being!
     
  39. oriongu

    oriongu

    Joined:
    Jun 18, 2015
    Posts:
    7
    @ensiferum888 Nooooooooooo, you better give us some updates soon or we will starve !!!! :)
     
  40. ThisIsNik

    ThisIsNik

    Joined:
    Oct 28, 2019
    Posts:
    9
    Thanks for the reply @ensiferum888.

    I'm looking forward to future updates on your project :).
     
  41. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    976
    Such an amazing project, can't wait to play! :)

    Im curious about your state/task machine. It looks really neat, how do you manage interruptions and emergencies, like fires or attacks?

    I am alos working on a game with villager AI (not close to this complex) and I use quite a simple state machine with an Enter, Execute and Exit method:


    Code (CSharp):
    1. public interface IState
    2. {
    3.     int Id { get; set; }
    4.     bool IsEmergency { get; set; }
    5.     bool IsInteruptable { get; set; }
    6.  
    7.     void Enter();
    8.     void Execute();
    9.     void Exit();
    10. }
    To switch state I then do:


    Code (CSharp):
    1. if (currentState != null)
    2.             currentState.Exit();
    3.  
    4.         if (currentState != newState)
    5.         {
    6.             currentState = newState;
    7.             currentState.Enter();
    8.         }
    This works quite well! I don't have the same amount of control you seem to have, but basically Ill set a state, lets say "FindTree", the villager will be in this State until Arriving at a tree, at which point it will change to "WorkTree", and so on. So if there is ever a fire, I simply set state "PutOutFire" on villagers closeby, and "WorkTree" Exit is called, and they run to the fire.

    This also mean I have no queue, which I have not needed yet, but should be possible to add I think. Not sure u can call mine a state machine since I can go from any state to any other state.
     
    Last edited: Jul 11, 2020
  42. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    Hey there @mrCharli3,

    Thank you for the kind words. It's not really a state machine per say it's really a queue of self contained actions. States rarely transition from one another. Instead when the AI is done with their current task I check what's available next, right now it's a priority list but eventually I want to get goal oriented decision making with weights. But for now it just goes down a priority list:

    Is there any immediate danger near me?
    Am I immediately hungry?
    Should I get some food to my house?
    Should I get a new tool?
    Do I need to work?
    Is there anything I need to do for my lord?
    Can I do anything for myself?
    Is there any way I can kill time?

    Whenever they come across a decision that fits their current needs I just pile up micro actions on top of each other so that it looks like they're carrying out a task.

    So here's the interface I use for my human agents:
    Code (CSharp):
    1. public interface AIState {
    2.     void SetUp();
    3.     void StateUpdate();
    4.     void Exit();
    5. }
    6.  
    7. public interface HumainAIState : AIState{  
    8.     void ResetOwner(CitizenAI cs);
    9. }
    And just so it makes more sense here are some important snippets from my StateMachine base class:
    Code (CSharp):
    1. public abstract class StateMachine {
    2.     public CitizenAI cScript;
    3.     public List<HumainAIState> Tasks;
    4.     public bool ShouldAutoUpdate = true;
    5.    
    6.     public bool CurrentlyIdle{get; protected set;}
    7.    
    8.     public StateMachine(CitizenAI cs){
    9.         cScript = cs;
    10.         Tasks = new List<HumainAIState>(15);
    11.     }
    12.    
    13.     public void DoCurrent(){
    14.         if(Tasks.Count > 0){
    15.             Tasks[0].StateUpdate();
    16.         }
    17.         else{
    18.             if(ShouldAutoUpdate){
    19.                 AssessNeeds ();          
    20.             }
    21.         }
    22.     }
    23.    
    24.     public void AddAction(HumainAIState _task){
    25.         if(Tasks.Count == 0){
    26.             Tasks.Add(_task);
    27.             Tasks[0].SetUp();
    28.         }
    29.         else{
    30.             Tasks.Add(_task);
    31.         }
    32.     }
    33.    
    34.     public void AddActionPriority(HumainAIState _task){
    35.         Tasks.Insert(0, _task);
    36.         Tasks[0].SetUp();
    37.     }
    38.    
    39.     public void AddActionPriority(List<HumainAIState> queue){
    40.         Tasks.InsertRange(0, queue);
    41.         Tasks[0].SetUp();
    42.     }
    43.    
    44.     public void DeQueue(){
    45.         if(Tasks.Count > 0){
    46.             Tasks.RemoveAt(0);
    47.             if(Tasks.Count > 0){
    48.                 Tasks[0].SetUp();
    49.             }
    50.         }
    51.     }
    52.    
    53.     public void ClearTasks(){
    54.         while(Tasks.Count > 0){
    55.             Tasks[0].Exit();
    56.         }
    57.         Tasks.Clear();
    58.     }
    59.        
    60.     public abstract void AssessNeeds(){}
    61.    
    62.     public virtual void Dispose(){}
    63. }    
    Notice the base class is abstract so this class cannot be directly instantiated. I'll have a different state machine depending on what social class the agent is. The principle pretty much is "As long as there are tasks in the queue, carry them out, when you're out, look for something to do which will give you another set of actions to carry"

    For example here's what happens when the agent has nothing to do, is healthy and able to work and there is a piece of wall to be built somewhere on your manor:
    Code (CSharp):
    1. public void RegisterToBuildWall(){      
    2.     Duskdale.Construction.Modular.Walls.WallPlacerManager wall = Duskdale.Construction.Modular.Walls.WallPlacerManager.Instance;
    3.     Vector3 wallPos = Vector3.zero;
    4.     if(wall.WallsToBuild.Count > 0){
    5.         Vector3 node = wall.GetNextWallNodeToBuild();
    6.         if(node != Vector3.zero){
    7.             wallPos = node;
    8.             AddAction(new FindShortestPathToBuildWall(wallPos, cScript));
    9.             return;
    10.  
    11.         }
    12.         else{
    13.             Debug.Log("No walls found");
    14.             return;
    15.         }
    16.     }
    17.     cScript.currentStateString = "Going to build wall.";
    18.     AddAction(new PlayAnimAndWait("BendDown", cScript));
    19.     AddAction(new PlayAnim("Build", cScript));
    20.     AddAction(new SetCurrentString(cScript, "Building wall."));
    21.     AddAction(new WaitTimer(5f, cScript));
    22.     AddAction(new BuildWall(wallPos, cScript));
    23.     AddAction(new PlayAnimAndWait("Get_up", cScript));
    24. }
    So you can see here that if there's still a wall part to be built, the agent will first find the shortest path to the wall position (that state will also push a "MoveToPosition" state once the path is found on top of the queue. (using AddActionPriority) then it will play an animation to bend down and wait until the animation finishes. Then it will start the "Build" animation but will immediately jump to the next state which will set the current action string so at that point if you click on the agent you'll see he's building a wall. Then it will get into a state that just waits 5 seconds while the build animation keeps playing. Then it will actually build the missing wall piece, then it will get up and at that point the queue will be empty so the AI will call its AssessNeeds method to find something else to do.

    That's fantastic and it works great but you brought up a very important point, how do I handle interruptions?

    I might be running out of space here so I'll continue on the next post...
     
    mrCharli3 likes this.
  43. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    Action queue interruptions

    Right now the only thing that can really interrupt agent actions is combat, or the presence of hostiles. Remember how when an agent has nothing to do, the State Machine will look for other tasks to carry out. Well I have what I call a super state which acts the same way. So let's revisit the case where our agent has determined it needs to go build a wall piece and they're currently on their way there. The current action queue would look something like this:

    --> [MoveToLocation]
    [PlayAnimAndWait("BendDown")]
    [PlayAnim("Build")]
    [and so on]

    with the arrow indicating the state currently being executed. For example MoveToLocation will DeQueue once the agent is at the destination.

    While the agent is moving they enter the radius of an enemy raider, when that happens the raider will signify its presence to the agent. Each entity in my game whether they're a human or a creature has something I call CombatStats which has plenty of variables one of them is a bool indicating whether the AI is currently in combat. If the flag is currently false I add an action on top of the queue instead of the tail so that it would look like this and the agent is now IN COMBAT:

    --> [CombatState]
    [MoveToLocation]
    [PlayAnimAndWait("BendDown")]
    [PlayAnim("Build")]
    [and so on]

    CombatState is a bit special, as it's the only place where the agent's Combat flag can be set or removed. When this state begins it acts as its own state machine to make decisions. Now let's imagine that there's only one raider, the villager we're looking at is at full health, currently has a weapon and is not a coward the CombatState determines he should engage the raider and fight him. But we're pretty far from him so it will push a new action on top of the queue:

    --> [FollowEntity(Raider)]
    [CombatState]
    [MoveToLocation]
    [PlayAnimAndWait("BendDown")]
    [PlayAnim("Build")]
    [and so on]

    The FollowEntity is like MoveToLocation but it tracks a moving entity instead and has logic to handle enemies and allies, once the agent gets within weapon range of the current target, it dequeues and goes back to combat state:

    --> [CombatState]
    [MoveToLocation]
    [PlayAnimAndWait("BendDown")]
    [PlayAnim("Build")]
    [and so on]

    The combat state will check the current situation, we're still full health, we have a weapon, we're in fighting shape and there's an enemy within weapon range, so let's attack him, this time I'm piling up a few states on the queue:

    --> [PlayAnimAndWait(Sword_ATK_Before)]
    [AttackTarget(Raider)]
    [PlayAnimAndWait(Sword_ATK_After)]
    [CombatState]
    [MoveToLocation]
    [PlayAnimAndWait("BendDown")]
    [PlayAnim("Build")]
    [and so on]

    Here the agent will start swinging its sword, I split the animation in two so that way I can have the hit happen at the correct time, I didn't use animation events because if the animation is not on screen the event does not fire (because of animation culling). So the agent will attack the target, hit points will be deducted and the action queue will make its way back to CombatState.

    Let's say after 3-4 attacks the raider finally dies the CombatState will determine that there are no enemies nearby and it will DeQueue itself from the action queue so the Combat flag will be set to false and the AI will resume its action queue from where it was:

    --> [MoveToLocation]
    [PlayAnimAndWait("BendDown")]
    [PlayAnim("Build")]
    [and so on]

    The CombatState could determine that you're not in fighting shape and send you home or to the nearby safe area (or just the opposite way of where the threat is) and then check for danger.

    So the current action queue is still present it's just that state priorities are able to handle threats and interruptions.

    Honestly I don't know if any of that made sense let me know if you have any more questions.

    Here's a very high level example, in this case I'm sending 10-12 raiders into my village. Raiders will storm your storage barns and try to steal as much valuable items as possible before leaving, they will not attack anyone unless attacked. The problem I currently have is once they fall into attack mode they start attacking your entire village until they either succeed or die, it's a bug I'm still hunting. But you can see that some villagers decide to flee home, and others stay to fight:
     
    mrCharli3 likes this.
  44. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    976
    What a wonderful reply, super interesting! Makes sense for sure :)

    Your task machine is definently more powerful than mine since a state is really just a series of actions, super flexible. While mine each state contains the actions. Which also seems to work fine for me so far, but a bit different. For example when I have a new construction I set an available worker to:

    [FindConstructionSpot]

    Once in that state, they will keep going until they reach the construction, at which point the state changes to:

    [WorkConstruction]

    Where the worker will stay until the construction is complete or is otherwise interupted. Once done I call a "FindNewTask" method that basically just looks for things he can do (I use a general priority system the player can control, so not a per-unit priority). And if there is nothing, he will idle. Which can mean anything from going fishing to just sitting down on a bench :)
     
  45. BornGodsGame

    BornGodsGame

    Joined:
    Jun 28, 2014
    Posts:
    587
    I really like how you are doing the AI. One frustrating thing I remember from Banished ( a semi-similar game) is that houses catching on fire did not interrupt their normal actions. So a villager would walk by their house that is on fire and go to the market to collect firewood.

    In my game, which appears similar to yours, villagers have a bravery check, so some would pass the check and go fight the invaders while others would flee. My next step is to boost the villagers bravery if they have access to armor and/or weapons.
     
    mrCharli3 likes this.
  46. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    976
    Btw, why not just use cull transforms, that way u can use animation events andcull the "heavy" part of the animation? I used to do it in code like you but once I changed to events everything got so much cleaner, and didnt notice any performance impact witha few hundred units.