Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[WIP] Manor Lord (Village Simulation game)

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

  1. ensiferum888

    ensiferum888

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

    I figured I would update the OP this time. So my project is still going strong even though I can barely work on it one day a week. Recently I rewrote the entire AI. I went from a 2000 lines switch statement in update to a simple finite state machine using interfaces. The whole thing is less than 400 lines and works amazingly.

    It's basically modular blocks that I can push in a queue, it's faster and much easier to add new tasks. I also stumbled on a grass shader http://forum.unity3d.com/threads/shader-moving-trees-grass-in-wind-outside-of-terrain.230911/ that I modified to fade based on distance. At first I was using the Terrain grass system, it looked horrible and took about 30 FPS. I wrote my own grass system using the shader above. It generates 100 patches of 60 000 vertex each in about 6 seconds. The whole thing sways in the wind and doesn't cost any performance (apart from the massive amount of vertex but I'm still running at 100FPS in editor). The shader fades the grass in a linear fashion I'll need to find something so it fades only when it gets to the edge of the last visible patch.

    Now the grass and the crops in the fields all sway in the wind it adds a lot of character to the scene. Below screenshots are taken directly from the editor, in the build there are rocks scattered around the terrain and flowing rivers.

    I reworked the hunger and food system so now people require a lot more food. Also now people will no longer die from starvation, they'll get a massive satisfaction penalty and will start looking for food themselves therefore impacting goods productions in your village.

    I also have a working version of a dynamic quests and event system that parses text files to build possible events. It's super easy to write your own events with triggers and actions. I will feature this system on the next update.

    Here are some screenshots of the game in its current state. All UI panels are still WIP and will most likely change.

    Here's the new grass system from ground level (I now realize my pine trees look silly from this angle)


    The blacksmith repairing some tools


    The Character Sheet - When you click on a villager you'll see this screen, it contains the attributes (Diplomacy, Constitution, Craftsmanship, Stewardship and Ruse), the traits, and also the current satisfaction. More information will be added to this screen. Here you can see the current statisfaction and factors:


    The traits - These are the different physical and personality traits of the character, these are the purple and black squares as I haven't yet made icons.


    The Attributes - Here we're looking at the Stewardship attribute and what traits modify it


    The Budget - This shows you the various income and expanses of your Fief. This screen will change as I find it too basic for now


    Overhead view -
     
    Last edited: Feb 15, 2015
  2. Lostlogic

    Lostlogic

    Joined:
    Sep 6, 2009
    Posts:
    693
    Screenshots or a video would be great. Personally I don' t navigate to external websites until I've seen some kind of media for a game.
     
  3. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    Thanks for the heads up, added a quick imgur album!
     
  4. Anonanimal

    Anonanimal

    Joined:
    Jul 3, 2013
    Posts:
    56
    For some reason I'm reminded of The Guild. That's not a bad thing though. I loved those games... I might even go reinstall one now.

    Anyway, good luck! Keep updating as you go.
     
  5. Lostlogic

    Lostlogic

    Joined:
    Sep 6, 2009
    Posts:
    693
    Yeah, looks good so far.. Good luck!
     
  6. Fappp

    Fappp

    Joined:
    Mar 24, 2014
    Posts:
    8
    Looks a bit like Banished! And that's a good thing :D
     
  7. Cobrryse

    Cobrryse

    Joined:
    Oct 30, 2013
    Posts:
    26
    Looks amazing..I'll have to try playing it. Did you use paid assets?
     
  8. SmellyDogs

    SmellyDogs

    Joined:
    Jul 16, 2013
    Posts:
    387
    Super neat but please make the ground texture higher.
     
  9. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    Thank you very much for the feedback!! I live with my girlfriend, work full time and go to school part time so time isn't really something I have these days. Developpement has been really slow , my current build has a tailor and a basic clothes mechanics, a part from that the web player is pretty up to date.

    I made all my assets in Blender except for the maple trees which were made using the Unity Tree Creator. They are the main culprit for poor performance. In game if you press "H" you'll get a basic help menu with a checkbox to toggle shadows off/on, you can disable them to shave off about 1500 draw calls!

    I'm learning blender (no tutorials) while learning Unity that's why my art direction doesn't really seem to make sense for now. Either I'll get better with time or when the mechanics are all in place I'll pay someone to make assets for me!
     
  10. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    Thank you so much for the feedback!! I agree that the ground texture has been bugging me a lot, I don't know if it's because of mipmaps but the one there is the best one I found so far. I swear my ground texture folder contains around 100 grass textures and they all look like S***, I decided to hold that part for last.

    Any suggestion would be more than welcome!
     
  11. Cobrryse

    Cobrryse

    Joined:
    Oct 30, 2013
    Posts:
    26
    That's cool. I too am trying to teach myself Blender and can't wait to start some 3d projects (I've mostly been doing 2d sidecrollers).
     
  12. kilian277

    kilian277

    Joined:
    Jul 13, 2012
    Posts:
    54
    Look very promising !

    The world needs more citybuilders with a vibe like this.
    Personally i find that the citybuilders released by those big companies suck really bad.

    I wish you goodluck with your project !
     
  13. PJRM

    PJRM

    Joined:
    Mar 4, 2013
    Posts:
    303
    Look very good!
    But it remind me the game Banished

    well... keep going.
     
  14. georetro

    georetro

    Joined:
    Jan 18, 2013
    Posts:
    218
    Looks awesome and loads of people have already said this but.... It looks like the game Banished :D The building system looks awesome!
     
  15. sootie8

    sootie8

    Joined:
    Mar 25, 2014
    Posts:
    233
    I like these kinds of sim games :D. The job, government and resources tab can't be changed when the game is pause though. This game would be awesome on mobile.
     
  16. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    Hey there thanks for the tip, I had those components use their own deltatime now so you can toggle them even when the game is paused. Same goes for the citizen info tab. I agree it would be nice on mobile but right now you're looking at 2500 draw calls when the game starts, it's the trees (mainly their shadow) that's causing this I need to find a more gentle shader..
     
  17. joshua-lyness

    joshua-lyness

    Joined:
    Jul 30, 2013
    Posts:
    8
    Check out Andrew price, he does really good blender tutorials! He has taught me loads! His website is blender guru and they have a facebook page.
    Josh :)
     
  18. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    I've been taking some time recently to rework all my artwork. When I first started I didn't take scale into consideration and pretty much just played in blender until I got the shape I wanted. What that gave was buildings that didn't fit with each other, some houses would be twice as large as others with the same stats.

    In a grid based game this is not ideal, plus the actual artwork was not to my liking so I started redoing everything. I also started implementing jobs and wages, here are a couple of screenshots:

    Building the Forge and peasants hovels.


    When starting off you should have enough tools to build hovels for all the famillies on your lands, but you'll quickly need the service of a blacksmith, the smith will produce new tools and repair existing ones. Tools encompasses building materials as well as actual tools to work.

    Designing field areas:


    Farming is the only work that any villager can do without any training. This usually represented 90% of the peasant work force in the middle ages, it won't be the case here but will still play a significant role.

    Some workers being trained:


    This is how you get people to take on new jobs in your settlement. You first must build the structure that unlocks the job, for example you build a Forge you get to train one blacksmith. You must pay a fee to train the person and wait a certain amount of time before they're able to take on the new work.

    The expanses tab:


    Most jobs on your lands will require you to pay the worker a seasonal salary which can be seen here. Each job can have its salary set by you. Most of your subjects are Serfs and in so owe you work so you don't necessarily have to pay them. Specialty jobs like Blacksmith or Physician will require you to provide a salary to the worker.

    The Forge and Hovels are finished:


    These small one room houses are very simple, offer a small inventory to their owners and provide you with no taxes at all. A hovel will houses members of one familly, when you allow travellers to stay on your lands for winter they will provide extra work force and maybe purchase some items from the populace.

    The Woodcutter and Forester together:


    The most important resource after your workers is without doubt the wood. Wood is used to build structures, and provide heat during winter.

    The village so far:


    The fields are ready for harvest:


    Right before winter the fields will be harvested by the farmers. You don't pay the farmers a seasonal wages, they're expected to work the fields of your lands for you and provide you with a part of their harvest.

    Obligatory winter shot:



    By the way what's the proper way to post updates here, should I edit the OP or should I just post updates here instead?

    Thank you for your time.
     
    bayunanda likes this.
  19. makoto_snkw

    makoto_snkw

    Joined:
    Aug 14, 2013
    Posts:
    340
    Nice game, this is my fav genre.
     
  20. judah4

    judah4

    Joined:
    Feb 6, 2011
    Posts:
    256
    This reminds me so much of Banished. It looks really good.
     
  21. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    Good day everyone!

    Just a small update, there is now a world map for trade agreements. I did not incorporate the notion of trade route yet, what happens is a merchant from another province (or yours) will get to your city and offer trade. Same if you reach out to other provinces there are no permanent agreements (i.e provide Norham with 500 units of wood/year) I'm still not sure if I'll try that.

    Here is the map:


    Here is the current trading window(there are no prices yet):


    I changed the way people handle hunger. Basically every season people will make an inventory of what they have in their houses, if they don't have enough food to last at least a complete season they'll go get more food from the storage barns. When they're hungry they will not have to stop work to go home to eat, instead the food is automatically taken from their house inventory.

    This enables them to waste less time travelling and eating rather than producing resources. When the game begins you also have a Manor House already built for you and your familly:


    Terrain looks quite boring here but I added an erosion procedure during game creation which makes the whole scene much nicer. I also generally build near rivers but for the past few weeks I've been working with a waterless terrain.

    I also remade the hunter:
     
  22. makoto_snkw

    makoto_snkw

    Joined:
    Aug 14, 2013
    Posts:
    340
    Nice progress.
    When can we play the demo? :D
     
  23. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    Not quite yet, I'm planning on recording a video of it soon though.

    Thanks for the kind words :)
     
  24. makoto_snkw

    makoto_snkw

    Joined:
    Aug 14, 2013
    Posts:
    340
    What's the update?

    Erm... are this game become "Banished" at Steam?
     
  25. wbakunis

    wbakunis

    Joined:
    Jan 28, 2014
    Posts:
    50
    Yea, this looks way too similar to Banished. Its' almost as if you just created a new UI for the game.
     
  26. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    Hey there, sorry for the lack of updates, lately there hasn't been any screenshot worthy additions to the game. Here's what I've been working on:

    - I wrote a traits and stats system for the villagers based on Crusader Kings, personality traits will influence relations between people and their ability to accomplish tasks.
    -There is now a council that you can form which will aid you in different aspects of managing your village such as the Reeve, Sheriff, Guild master and Steward.
    - A new mechanic has been added that is Renown, renown is gained through certain events and owning certain buildings. It will be spendable on certain decisions and diplomacy options.
    - I have a system that parses events and character traits from text files at run time so that now people will be able to write their own quests.
    - Lately I've been converting all my UI from OnGUI to the new Unity 4.6 GUI, performance increased dramatically but most of it is still using the default sprite textures (here's a teaser)


    Yes I agree, looking at the screenshots that's what I would think as well. And I won't lie, this project started out as a full fledged banished clone (even though it wasn't out yet). But there are many things that differ to make it stand out from Banished.
    • People do not age 4 times faster, your town expansion doesn't rely on births but mainly immigration. This in turn is controlled by the average quality of life in your manor as well as it's renown.
    • Money is involved in most transactions, you can pay to purchase goods or trade them for other goods (based on their value). Buildings costs maintenance for its owner.
    • There's a lot more micro management required when initially setting up the businesses. Each villager has 5 stats each modified by character traits (you probably don't want to have a maimed person in your personal guard)
    • You'll be able to own certain business but in order to keep your population happy you'll need to sell or give some of the business to merchants. This will in turn increase the renown of your town and attract more people (residents and travelers)
    • Businesses work a bit like in banished, for example in the screenshot above you can see the Windmill, the miller will grab wheat from the storage barn and create flour from it. Each business has two storages, one for you the Lord of the Manor, this is their Tithe. This is what they'll deposit in the storage barns to be used by you or the other villagers. The other is their own inventory which traveling merchants can buy. So business will provide your people with resources but will also be a source of monetary revenue for its owner.
    • There are events popping every now and then based on the character traits of your lord and the current town status, these events will help forge relations between you and your population.
    • I'm still tinkering with the idea of combat, I've already made a system to build walls like in the game Stronghold but I don't know if I'd like realtime or turn based combat so it's still on hold.
    I used to be mad when people said it looked like Banished but it's true I can't deny it. I'm just looking forward to have either something playable or make a video just to show people how different it actually plays from Banished.

    But thanks for taking the time to write to me.

    Have a great day!
     
    makoto_snkw and wbakunis like this.
  27. IRS-Remi

    IRS-Remi

    Joined:
    Jan 3, 2015
    Posts:
    14
    First, what a wonderful job! I think you are on a good way.

    I searched someone who created his own city-builder, I found him! ^^ In fact, me too, i would want to create a city-builder game but just to understand how does it work (don't worry I won't compete you ^^). So I try something simple but I have not a very good idea of how really make it. Can you share your secrets?

    For example in your scripts, are your citizens and buildings all in a list and each frame updates those lists?
    How citizens are link to a house and a work place?
    Can you explain how you design it?
    (Yes it is simple questions, but I am just beginning)

    It is just to help me to start with a very simple idea of game design =)
    Thank you!
     
  28. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    Good morning Aferal,

    Thank you very much for the kind words! I would be happy to explain how I went about creating this project and I don't really worry about competition, if you can make a game like this but better by all means go for it!

    You are right it all seems pretty simple, and it is it's just a lot of code. So far I have about 23 000 lines of codes spread in about 180 files. This is excluding the pathfinding (which is without doubt the most important part of a game like this). For that I'm using the amazing A* pathfinding project that you can find here.

    I'm not using lists to Update, each citizen has it's own finite state machine that runs on their AI script. Each building that requires updates also have their own update methods. To be honest I haven't tried centralizing the update into one master script because as of now that's not the bottleneck, the renderer is.

    For example the only thing that's happening in the houses update method is to consume one unit of wood every 30 seconds if the temperature is below a certain level. For the citizen it gets a bit more complicated, for now I'm still using a switch statement for the actions to do in update depending on what the person is supposed to be doing. But I'm considering moving to abstract classes or interfaces eventually.

    Each citizen has 2 AI, one for immediate decisions like should I work? Am I hungry? Am I injured? This is what's taken care of in the Update method, when a certain task is done the AI goes down a priority list to determine the next task and then do that. The second AI is called much less often and takes care of longer term decisions such as Do I have enough money to upgrade my house? Can I afford to purchase a business? Should I kill my father so that I can inherit his possessions? Can I steal something valuable from my neighbor? etc. These events probably won't be visible to the player but sometimes you'll get a notice that it happened.

    Each citizen has a Transform component for its house and one for its work place. When you build a new business for example the Forge, it belongs to you. You can then hire someone with a high enough Craftsmanship skill to work there. If you want your village to grow you'll need to sell or give out business to Merchants (or craftsman with a high Stewardship skill). When you no longer own a business you do not have to pay it's employees or building maintenance but you also no longer make money from the sales. The business will still provide your town with a number of resources that you can sell or let your population use.

    There is a lot going on in this game, let me know if you have some specific questions I'll do my best to answer!

    Have a great day!
     
  29. Sykoo

    Sykoo

    Joined:
    Jul 25, 2014
    Posts:
    1,394
    This looks really good! Keep it up :)
     
  30. IRS-Remi

    IRS-Remi

    Joined:
    Jan 3, 2015
    Posts:
    14
    So if I understand, you just Instantiate your citizen when they arrive in your town and Instantiate your buildings when you spawn one?
     
  31. Sykoo

    Sykoo

    Joined:
    Jul 25, 2014
    Posts:
    1,394
    That's a useful and great method to use. I think he is using that, if not - I wonder why so I'll comment here to follow up ^^
     
  32. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    Thank you very much for the comment :)

    Yes absolutely! Object pooling doesn't seem like a good idea for this kind of game as I would need to hold several instances of buildings in memory that might never be built.

    Each building is made up of 3 prefabs:
    • Placement: This is created when the user wants to place the building, it follows the mouse and checks if the position is valid.
    • Construction: This prefab contains the necessary construction resources, and different meshes of the construction process.
    • Done: This is the finished building it uses the same Mesh as the placement prefab but a different shader.
     
  33. IRS-Remi

    IRS-Remi

    Joined:
    Jan 3, 2015
    Posts:
    14
    Thank you Ensiferum for this information!
    I will try =)
     
  34. IRS-Remi

    IRS-Remi

    Joined:
    Jan 3, 2015
    Posts:
    14
    Hello Ensiferum,

    When you have your citizens in your map and they don't have their house, how do they find their house? You must use a script on your citizen, isn't it? But how do you find a free house and how do you link this citizen to his home?

    Thank you for your answers!
     
  35. ensiferum888

    ensiferum888

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

    I have a singleton script which handles all constructions and work places and house, basically any building. When a house is built it registers with this script.

    Then on my citizen AI I hold a reference to HouseScript which is the main script on my houses buildings. My CitizenAI looks like this:

    Code (CSharp):
    1. //HouseScript for this Agent
    2. public HouseScript houseScript;
    3.  
    4. //Family script
    5. public FamilyNode family;
    6.  
    7. public bool HasHome(){
    8.     return this.houseScript != null;
    9. }
    10.  
    11. public bool HouseAvailable(){
    12.     return BuildingManager.Instance.AvailableHouses.Count > 0;
    13. }
    14.  
    15.  
    16. //This gets called when the first member of the familly finds an empty house
    17. public void AssignInitialHouse(HouseScript hs){
    18.     if(hs.Register(this)){
    19.         this.houseScript = hs;
    20.         //this will call the AssignHouse method below on all family members
    21.         this.family.AssignHouseToImmediateFamily(hs);
    22.     }
    23. }
    24.  
    25. //This gets called by the initial house member, so once someone finds a house it automatically assigns his/her spouse and children
    26. public void AssignHouse(HouseScript hs){
    27.     if(hs.Register(this)){
    28.         this.houseScript = hs;
    29.     }
    30. }
    As soon as a house gets one member it will remove itself from the AvailableHouses list. The only way someone can live there is if the owner of the house is immediate family or good friend.
     
  36. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    Updated OP, bumping thread!
     
  37. Teila

    Teila

    Joined:
    Jan 13, 2013
    Posts:
    6,932
    This looks great!! I love these kinds of games. :) I want to play!
     
  38. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    Thanks for your support Teila!

    It won't be like your standard city-building where your goal is to cover the entire map. One because there's way too much going on and because that's not the experience I want to create. The game takes place in a fictional universe but it's heavily influenced by the dark ages more specifically the viking invasion of the British isles. Succesfully managing a village of a few hundred residents should be difficult. Right now I'm working on the sandbox mode where you make your own goals but I'm thinking about incorporating scenarios with clear success conditions.

    I'll eventually need beta testers for some number crunching, when the time comes I'll post the details here.
     
    Teila likes this.
  39. Wrymnn

    Wrymnn

    Joined:
    Sep 24, 2014
    Posts:
    373
    Hi, the game looks really amazing man, also how did you make the citizens animations/models? Since characters are the hardest part of 3Dmodeling to master. So if you made them yourself, you are pretty good at modeling/texturing.
     
  40. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    Thank you! I used the UniHuman blender plug in to create a low poly base mesh and armature for my citizens. I redid the topology to further reduce poly count and remove unnecessary bones. I then duplicated the base mesh to create a female version. Added clothes and hair (right now every single male is bald). I created animations for the male using blender, then I simply dragged them on the Animation Controller of the female SkinnedMesh and that's it. The villagers are about 960 tris each. It's good enough but I'd like to save enough money to get Pro so I can use LOD for them because it's completely useless to have 1000 tris models when all you can see is a little blob on the screen.

    Again thank you for the kind words :)
     
  41. joshua-lyness

    joshua-lyness

    Joined:
    Jul 30, 2013
    Posts:
    8
    Hi mr awesome City builder, this looks insane! I'm making a low poly style modern city builder (won't compete with yours and is targeted at mobile) I'm still in the asset making stage in blender, and haven't even looked at the coding part yet, and I've forgotten most of it.

    I've been planning the mechanics of the game, and how people will interact, but I have an issue that you might be willing to help me find a solution to. See, your people I presume follow paths to get back to their house, but how do you make them follow paths back home? How do you even begin to make them so that? I just don't understand. Like in Gta when it plots the quickest path to get to the set location. How? Please help me, and I'm grateful for anything. Keep up the good work, this looks really good! You are really talented (he says, massively sucking up...)
     
  42. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    Hey there @joshua.lyness,

    First off I don't worry too much about competition, this is how better games are made!! Pathfinding is probably one of the most important parts of this kind of game. When I first picked up Unity I had no idea how to implement this. I kept reading on the A* pathfinding algorithm on Wikipedia and it didn't make any sense.

    I decided a ready made solution, the A* Pathfinding Project made by the very talented Aron Granberg: http://arongranberg.com/astar/features

    This is one of the few assets I didn't make myself I'm using. You can use the free version but even at 100$ the pro version is worth every penny. It's a bit hard to setup at first but once you get it going it's amazing.

    The documentation is fairly easy to understand but you should put your movement code in Update and not FixedUpdate.

    It gets a bit more complicated when you want to make modifications to the existing graph for example prioritize using roads and prevent walking through buildings. But he also has a tutorial for this.

    At the end of the day going somewhere is as easy as doing:
    Code (CSharp):
    1. seeker.StartPath(_myTransform.position, target, OnPathComplete)
    2.  
    3.  
    Thank you for the great feedback and good luck on your project! Feel free to send me a private message if you have any issues with aron's pathfinding I've gotten quite good with it!
     
  43. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    Dynamic Events
    Today I will give you a little glimpse of my event system in the game. The events are stored in a txt file that is parsed by the quest engine at startup. Every 30 seconds or so it will test every single event on every single citizen in the game. Right now the load is offloaded in a coroutine but eventually this will be done on a separate thread.

    Let's take this event for example(I used the CSharp tag to keep the formatting but this is just a regular txt file):

    Code (CSharp):
    1. Event{
    2.     id = 3
    3.     description = My Liege, I noticed you had no one aiding you with the peasants and farmers. Surely it must be a lot of work. Perhaps I could be of assistance, I wish to be named your Reeve.
    4.     player_only = yes
    5.  
    6.     MTTH = {
    7.         month = 1
    8.         modifier = {
    9.             has_trait = ambitious
    10.             factor = 0.5
    11.         }
    12.     }
    13.  
    14.     Conditions{
    15.         diplomacy = 12
    16.         reeve_unlocked = true
    17.         reeve_assigned = false
    18.     }
    19.  
    20.     Response{
    21.         name = $FROM$ is my new Reeve.
    22.         Actions{
    23.             FROM = {
    24.                 opinion = opinion_on_council
    25.                 assign_council = reeve
    26.             }
    27.         }
    28.     }
    29.  
    30.     Response{
    31.         name = I'd rather elect a Reeve myself, but I'll consider it.
    32.         Actions{
    33.             FROM = {
    34.                 random_list{
    35.                     0.1 = {
    36.                         opinion = opinion_denied_from_council
    37.                     }
    38.                 }
    39.             }
    40.         }
    41.     }
    42. };
    Alright these are fairly easy to understand, the ID is used for quickly looking for events in a dictionary. Description is the text that will appear to the player.
    player_only = yes indicates that the person receiving this event will always be the player (the manor lord)

    An event usually a person calling the event, and a person receiving the event. This tag allows me to save time by already knowing who will receive it.

    MTTH stands for meantime to happen, when the conditions of the events have been met this is how long we'll wait until the event triggers. I'd like to have a little more random options now because now if anyone is over 12 diplomacy you're 100% certain to receive this event within one month so I need to figure a way to fuzz the odds some more.

    Conditions are again very straightforward, they will make sure the person calling the event (FROM) meets the conditions.

    The flag reeve_assigned and reeve_unlocked are global flags.

    The Response tags outline what each possible responses will do. In this case the actions are only done on the person calling the event which is why they're enclosed within a FROM = { } block. You can create random lists or fire actions regardless of chance. You can have certain conditions modify the chance of something happening using the modifier = { } object.

    This is what it looks like in game, the quest system found that Isac had over 12 diplomacy, the reeve position was available and unfulfilled. The text will be evaluated to match the name of the caller and all the tool tips are built dynamically by the system when the event gets fired.


    In order to add content I only have to add a few lines of text in my file and the quest system will take care of the rest. This will enable me to quickly add content and allow players to create their own events.

    Stay tuned for more!
     
  44. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    Upgrade to Unity5
    So it turns out that upgrading to Unity5 has been less of a problem I thought it would be. I had to fiddle a lot with my snow shader to get it to work again, and especially the terrain one. I was using the ats snow suite which is an amazing pack sadly it seems it's no longer being supported by the dev.

    Aside from that most of my shaders were still working fine, no scripts error. I do not use physics except to intercept raycasts from the mouse so no issues there. I noticed a slightly slower performance in the editor, but better in the actual build so I don't know what's up, perhaps it's all those sweet pro features slowing down the editor.

    Speaking of which, after 18 hours of intense googling, forum lurking, trial and errors, I manged to get reflections working on a custom flow map shader, see for yourself:

    First attempt:


    After 15 hours:


    Not much has change functionality wise except now each social class has it's own unique AI meaning that the lord will not plow the fields, peasants will not hunt (unless allowed) etc. It's easier now to break down possible actions for each social class. A year ago I had no idea what derived classes were, I can honestly say working on this project is definitely turning me into a better programmer. I recently redid the trade window to include the resource icons (still need to make most of them)


    I added another Peasant house, and a Weaver which will turn Flax seeds into cloth (can also turn Wool into Wool Cloth)

    I also added Depth of Field image effect which is based on the height of the camera:


    Of course it will be possible to disable the effect.

    I'm still having an issue with hunger people eat way too much or factories are not producing enough. I'll need to balance the production vs needs and values and this is going to be real tough.
     
  45. Deleted User

    Deleted User

    Guest

    Thanks for referring me to this thread! Very interesting to see your event system breakdown. I have two big questions.

    How does the system handle the MTTH currently? Does it just check all the possible events, and then say "trigger this in a month?" Does that mean that all events are theoretically guaranteed to fire in your current implementation?

    I'm very interested to know how you're handling the tooltips. Handling it at the script level sounds a little more complicated, but quite ingenious.
     
  46. ensiferum888

    ensiferum888

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

    In the current implementation yes, if the conditions are met the event will fire within it's mean time to happen for sure (unless the citizen that's triggering it dies before it gets launched). I think I have a good base for a system like this but there is not enough randomness, it's very common to begin a new game and have at least one peasant who's going to have 12 diplomacy or more. So every time I play I get a pop up for someone asking me to be the reeve. I'm still on the lookout for some way to add another degree of randomness to it while retaining a certain control.

    Right now the system has been thrown together quickly for prototyping purposes, it's far from perfect. I have a coroutine that checks for eligible events in a loop. Once a quest is deemed ready I put it in a wrapper class that has the Event, the caller and the receiver as well as a timer . For example in my game a season (3 months) is 600 seconds, so a month is 200 seconds, a week is about 50 seconds and a day about 7 seconds.

    The MeanTimeToHappen is placed within its own class and has the ability to check modifiers against the calling villager to modify the time it would take for the event to launch like so:

    Code (CSharp):
    1. [System.Serializable]
    2.     public class MeanTimeToHappen{
    3.         public float DelayBeforeStart;
    4.         public Modifier[] Mods;
    5.        
    6.         public MeanTimeToHappen(float _avgDelay, Modifier[] _mod){
    7.             this.DelayBeforeStart = _avgDelay;
    8.             this.Mods = _mod;
    9.         }
    10.        
    11.         public MeanTimeToHappen(float _avgDelay){
    12.             this.DelayBeforeStart = _avgDelay;
    13.             this.Mods = null;
    14.         }
    15.        
    16.         public float GetEventTime(){
    17.             float factor = 1f;
    18.             if(Mods != null){
    19.                 for(int i = 0 ; i < Mods.Length ; i++){
    20.                     factor *= Mods[i].GetFactor();
    21.                 }
    22.             }
    23.             return factor * DelayBeforeStart;
    24.         }
    25.        
    26.         public float GetEventTime(CitizenAI cs){
    27.             float factor = 1f;
    28.             if(Mods != null){
    29.                 for(int i = 0 ; i < Mods.Length ; i++){
    30.                     factor *= Mods[i].GetFactor(cs);
    31.                 }
    32.             }
    33.             return factor * DelayBeforeStart;
    34.         }
    35.     }
    Then my update loop simply decrements the timer for the given event, when it reaches zero launch the event:

    Code (CSharp):
    1. void Update(){
    2.         for(int i = 0 ; i < ActiveQuests.Count ; i++){
    3.             ActiveQuests[i].Timer -= Time.deltaTime;
    4.             if(ActiveQuests[i].Timer < 0f){
    5.                 PrepareEventForLaunch(ActiveQuests[i]);
    6.             }
    7.         }
    8.        
    9.         if(QuestsReadyToLaunch.Count > 0 && !DisplayingEvent){
    10.             TriggerEvent(QuestsReadyToLaunch[0]);
    11.         }
    12.     }
    Yesterday I tested a build of the game with 145 citizens active and this system induced little to no lag at all even though it does tons of string comparisons. Of course having 150 skinned mesh on the screen is another matter.

    To evaluate the tool tips at run time again I'm taking a very basic approach (I'm not really a decent programmer). I'm simply comparing flags in my Actions, this is done only once per event when it fires and gets displayed to the player again trying to minimize the amount of allocation created by all these concats. The EventResponse class has a method for this:

    Code (CSharp):
    1. public string GetActionToolTip(QuestLauncher ql){
    2.             string toolTip = "";
    3.             for(int i = 0 ; i < AllActions.Count ; i++){      
    4.                 toolTip += StringDisplay.Evaluate(StringDisplay.GetActionString(AllActions[i]), ql);
    5.             }
    6.             if(RandomActions.Count > 0){
    7.                 toolTip += "One of the following will occur:\n";
    8.                 for(int i = 0 ; i < RandomActions.Count ; i++){
    9.                     for(int k = 0 ; k < RandomActions[i].PossibleActions.Count ; k++){
    10.                         toolTip += StringDisplay.Evaluate(StringDisplay.GetActionString(RandomActions[i].PossibleActions[k]), ql);
    11.                     }
    12.                 }
    13.             }
    14.             return toolTip;
    15.         }
    QuestLauncher is the wrapper class I was refering to earlier, it contains the root and from variables so I can assign them to tooltips Evaluate is very simple it will look for any $ $ enclosed text and replace it with the appropriate villager name. Here's what GetActionString does (omitted a lot of code)

    Code (CSharp):
    1. public static string GetActionString(PairContainer EventAction){
    2.         string key = EventAction.Key;
    3.         string value = EventAction.Value;
    4.         float chance = EventAction.chance;
    5.         //...
    6.         else if(key == "opinion"){          
    7.             string chanceString = "<color=#ADDA74>" + (chance * 100).ToString("#0") + "</color>";
    8.             OpinionContainer c;
    9.             if(OpinionDB.OpinionDictionary.TryGetValue(value, out c)){
    10.                 string color = "green";
    11.                 if(c.modifier < 0){
    12.                     color = "red";
    13.                 }
    14.                 string result = EventAction.target + "'s satisfaction changes by <color=" +color + ">" + c.modifier + "</color>";
    15.                
    16.                 if(c.seasons > 0){
    17.                     result += " for <color=#ADDA74>" + c.seasons + "</color> seasons.";
    18.                 }
    19.                
    20.                 if(chance == 1f){
    21.                     return EventAction.target + result + "\n";
    22.                 }
    23.                 else{
    24.                     return chanceString + "%: " + result + "\n";
    25.                 }          
    26.             }
    27.         }
    28.         return "";
    29.     }
    I'm very sorry if this was a lot of code, maybe you wanted a simple answer. Please feel free to ask any questions I love to answer them as it also allows me to see my code from a different angle and perhaps notice weird stuff.

    Thank you for your interest!
     
  47. Deleted User

    Deleted User

    Guest

    This is awesome. Appreciate your humility that maybe this is something that can be thrown together quickly with some imperfections, but it really helps clarify the whole system, and it gives me some ideas for how to approach a similar system.

    Thanks a lot!
     
  48. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    Just finished a blog post on how I go about saving/loading this kind of game!
    http://manorlordgame.blogspot.ca/

    There has been some questions in the past on how to achieve this I thought some of you might be interested!
     
  49. ariusdb222

    ariusdb222

    Joined:
    Jan 25, 2015
    Posts:
    88
    Very interesting game, keep up the good work!!
     
    ensiferum888 likes this.
  50. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    Thank you very much for the feedback! There isn't much to show these days as I'm mainly working on back end stuff (mainly saving and loading and all the issues it brings out) and it's also the end of semester in school so exams and stuff.

    I'll update within the next few weeks!!