• Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By Francisco Tufr
      Hi everyone! I'm currently working on a series of books about 2D Shader Development.

      The idea is to synthesize a bunch of techniques that are specifically useful for 2D, even if they work on 3D as well.

      I released the first book last week. It's 4.99 on Amazon or free on the series website, https://www.2dshaders.com

      This is an independent initiative, I don't work for any publisher whatsoever. The contents of the books are the result of a 4-year span where I started teaching this in Argentina and USA, always making the workshop better. Now I'm expanding it to make more sense in book form.

      I'd love to hear your opinions on the idea and if you get the book let me know what you think.

      By the way, the examples are in Unity, but the concepts from the book should be easily transferable to any graphics api/engine.

      Hope you like it!
    • By Kai Keeper
      I finished this game a while ago, now I'm trying to make an introduction video before I put it on Steam, looking for feedback.
      I have already got some feedback from other people, and this is what they felt or some of the things I think the video doesn't do a good job: 1. I don't understand the core concept of the game. I think another video that explains the core concept of this game would be better.
      2. I feel that the video was too long, it showed way too many features.
      If you feel the same way, please let me know. If you have any other suggestions/feedback please don't hold back.
    • By fgp069
      Hi there, this is my first time posting, but have been a long-time lurker in this community. I am currently developing a 3D game engine using a deferred renderer and OpenGL.
      I have successfully implemented recursive portals (and mirrors) in my engine utilizing the stencil buffer to mask out regions of the screen. This solution is very favorable as I am able to have dozens of separate views drawn at once without needing to worry about requiring multiple G-buffers for each individual (sub)view. I also benefit with being able to perform post processing effects over all views, only needing to apply them over what is visible (one pass per-section with stencil masking for no risk of overdraw).
      Now presently I am pondering ways of dealing with in-game camera displays (for an example think of the monitors from Half-Life 2). In the past I've handled these by rendering from the camera's perspective onto separate render target, and then in the final shading pass applying it as a texture. However I was greatly disappointed with the performance and the inability to combine with post-processing effects (or at least the way I do presently with portals). Another concern being that I wish to have scenes containing several unique camera screens at once (such as a security CCTV room), without needing to worry about the associated vram usage of having several G-Buffers.
      I wanted to ask more experienced members of this community if it would be possible to handle them in a similar fashion as I do with portals, but with the difference being for them to be transformed so they take on the appearance of a flat 2D surface. Would anybody with a more comprehensive understanding of matrix maths be able to tell me if this idea is feasible or not, and if so could come up with a possible solution?
      I hope all this makes enough sense. Any possible insight would be greatly appreciated!
    • By RoKabium Games
      While looking out for that pesky Terrator, our little alien is doing a bit of relaxed mining down on the new gas planet "Lelantos" this weekend.... 
      #gamedev #indiedev #madewithunity #screenshotsaturday
    • By vividgamer
      I have a native iOS game (objective c, XCode build) which I am considering to port to other platforms.
      Core gameplay is based on solely on geographical maps, and custom drawing over maps. It also has Core Data. This part is complete in development.
      What is not done yet is: monetization, gamification (leaderboards, challenges) and multiplayer functionality.
      As I think more about it, I am tempted to think if this is the right time to move to a cross platform tool such as Unity. But before dedicating time to port my 5 years side-project effort in Objective C, I really want to know if its worth it.
      - Does Unity support such plugins / assets that will fulfill all my above requirements?
      - Unity Personal seems to have only 20 concurrent users - is it too costly scaling if I decide for extending to web and android platforms?
      - What is the general workflow involved in publishing to iOS, Android, PC, and web platforms while using Unity? I mean to ask about various points of signing stuff, paying fees and getting certified.
      - How long will it really take to port my entire Objective C project into Unity? I am somewhat familiar with C# but I am finding it hard fidgeting with Unity IDE as lot of things are focused around FPS and 3D while my game is still 2d - not much action involved. I seem bit overwhelmed by the list of features I see there. All in all, I do not want to lose my momentum while still making sure its portable to everywhere.
      - Any assets I could use (for free to try basis in debug) that are relevant for my game?
      - Last but not the least, are there any costs that I need to be paying upfront to Unity, for using it (apart from their monthly subscription model)? I don't understand their costing for multiplayer in conjunction with their subscription fees - if someone could kindly elaborate.
      Thanks in advance for your time reading a newbie
  • Advertisement
  • Advertisement

City building game inner workings

Recommended Posts


without going into any details I am looking for any articles or blogs or advice about city building and RTS games in general. I tried to search for these on my own, but would like to see your input also. I want to make a very simple version of a game like Banished or Kingdoms and Castles,  where I would be able to place like two types of buildings, make farms and cut trees for resources while controlling a single worker. I have some problem understanding how these games works in the back-end: how various data can be stored about the map and objects, how grids works, implementing work system (like a little cube (human) walks to a tree and cuts it) and so on. I am also pretty confident in my programming capabilities for such a game. Sorry if I make any mistakes, English is not my native language.

Thank you in advance.

Edited by GytisDev

Share this post

Link to post
Share on other sites

If I get this right, you're struggling with the algorithmic part of making the 'workers' which are essentially simple AI-controlled characters that obey relatively complex instructions originating from the player?

Making a worker that works fine is not terribly challenging, however, making one that remains workable as your game development progresses (and complexifies) requires some preparation work and a good idea of where you're going.


Share this post

Link to post
Share on other sites

There are quite a few methods to approach this but the most simplistic one is usually based on the idea of breaking everything in the world into actions which produce state changes.  Banished is probably the most simplistic of the games until you get into the market and home management portions of things so I'll use that as an example.  If you ignore everything except one building, things become simple though you have to think of the solution in a kind of odd manner.  Let's take the fishery as an example.  The fishery is placed near water and it contains one action from then on: "create a fish".  Since in Banished you assign workers to buildings (well you set the number and the game selects the specific entities) the first step is pretty easy, on every game update the workers check their assigned building for an action if they don't have one already.  Since the fishery always contains "create a fish" as an action the worker will always have one copy of that action in their queue.  We'll ignore the other items such as get warm, go eat, sleep etc but they are also in the queue and that's where the priority portion comes in later.

Every action has a required state, what it 'does' code and a final state change to make on completion.  The required state for create a fish is 'in the building', it's 'does' code is simply wait 'x' seconds and the resulting state change is '+1 fish to inventory'.  So, the entity tries to run the 'does' code but finds that the requirement 'in the building' is not satisfied.  The entity looks in a table of actions for one which has a result of 'in a building', it should find a 'path to building' action with the desired result.  So, the entity code moves the "create a fish" action to be a child of a new copy of "path to building" and starts running that action.  "Path to building" has a required state: "has path to building", it searches the actions and finds "create path", pushes "path to building" to a child of a new copy of that and starts running it.  "Create path" has no requirements and results in either success, which sets the path on the entity workspace, or fails and takes all it's children with it potentially telling the user or the building about the failure.  Assuming there is a path though, it assigns it to the entity workspace as the state change portion of the action and then replaces itself in the queue with it's child "path to building" which can now start running, as such the entity starts following the path.  Each update the "in building" check is updated and when it changes, pop "path to building" off and replace it with "create a fish" which now starts running.  "Create a fish" simply puts the entity to sleep for 'x' seconds and when complete it performs "+1 fish" state change.  Bingo, a chain of events broken into fairly simple concepts which can be explained to the entity with a fairly trivial algorithm.

That's the very "basics" of how you can solve the "do things" portion of the problem.  It is actually fairly simple though some of the code is not trivial.  Where things start getting more complicated, and as Orymus3 said, how to make it work through out the game evolution, is when you start adding multiple competing needs to the entities.  In Banished again, each entity has competing needs such as: stock my houses inventory, eat, sleep, procreate, get warm, get healthy, etc.  At this point you start assigning priorities to the actions in each entity and as such your balancing nightmare commences.  You need to start considering things like action velocity (i.e. I've started this action so it should get a boost to priority for a while before other things interrupt it), absolute interrupts such as hey that's a fricken tornado I should run away, etc.

In more complicated games, Kingdom's and Castles I'm not sure of, you have multi-step production chains and things get *really* damned complicated.  For instance in an older game I can't remember the name of, you had fields of wheat which you harvested, wheat was then used in a mill to produce flour, which was then taken to a bakery, which when combined with entities and other ingredients could produce different types of food.  That game left a lot of the priority setting to the player and it was really difficult to get things working smoothly because the AI didn't consider time spent pathing, waiting for the mill to not be in use, etc very well when considering which actions were most efficient.  Lately I believe a modified Monte Carlo Tree Search could be modified to handle such things but that's getting pretty advanced and you should probably stick to the Banished like simple model till you get a handle on some of the trickier bits.

Hope I didn't trivialize this too much to make sense.  If I did though and you need further expansion on bits and pieces, let me know.

Share this post

Link to post
Share on other sites
2 hours ago, All8Up said:

Hope I didn't trivialize this too much to make sense.  If I did though and you need further expansion on bits and pieces, let me know.

No, you didn't. It was really interesting read and I am saving it for later, thank you!

Share this post

Link to post
Share on other sites

You might refer to the game "Stronghold". Awesome game. Also i dont think Kingdoms and Castles needs less advanced AI  that Kingdoms and Castles, that game is pretty basic.

I use a finite-state machine. So a worker has only one state at each moment:

1. Go to workplace
2. Work
3. Drop-off goods (at stockpile)

So depending on the current state, different code is run for the worker. If its in state "Go to workplace" it will find a good path to the workplace (and once done) actually move towards it. If it's close enough to its workplace it will change the state to "work". Then different code will be excecuted instead.

You can add more states and control how they change between each other. If the worker needs to get food for it's house (as in banished) you can add:

4. Refill food stocks

This will be jumped to (from any state) if the stock in the house is close to zero. Change the state and remember what state the worker was on. When it has refilled the house, change back to the state it was on (or possibly "go to workplace" if needed).

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement