Sign in to follow this  

Unity Special Rules in a Turn Based Entity Component System

This topic is 1824 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,

 

I'm currently planning on implementing a tabletop game in the spirit of Warhammer 40k.

This is a turn based strategy game with lots of special rules.

 

Why a entity component system?

  • Units have special ability, which could be realized each as a component
  • Area effects such as fear, could also be realized as a component indicating that a unit is affected by fear
  • Each race or army type have there own special rules
  • Special rules generally only effect some part of the system, e.g., movement or shooting
  • Ease of integration in Unity (make games not engines wink.png )

So what is the problem?

How to realize the special rules?

Example:

To perform an action two six side dice are rolled and the sum is compared to a threshold.

Lets assume a special ability or effect that modifies this test as follows: instead of two dice three dice are rolled and the highest result is discarded.

Another effect might case that an additional dice is rolled and added to the result.

So the combination would be: roll four dice remove the highest and add the rest up.

 

So in a perfect world the rules do not have to know about each other.

But should be able to override each other such that an ability can cancel out an effect.

 

Would you ...

  • implement the abilities as flag components? And put there effect into each system, e.g. shooting or movement system?
  • put the logic of the ability into the components?
  • have the logic of the ability as another component, where one could have many components of the same type, if the effects can stack?
  • any other ideas?

Of course if you are missing an information please feel free to ask. Also I'm looking forward to suggestions of different approaches.

Share this post


Link to post
Share on other sites
This is just my personal take, but it sounds to me like you really want to write a component system but don't actually know why they are useful or when to use them. Your reasons are square peg/round hole to the extreme.

I think you've picked the wrong tool for the job, or maybe the wrong job for the tool.

Share this post


Link to post
Share on other sites

Very well then.

But what would be the 'right' tool?

Which would be the 'right' method or pattern to use in the above sketched example?

Share this post


Link to post
Share on other sites

Well, if I'm reading you correctly, it seems the issue you have is with event communication.

 

The "Event" that is occurring is a dice roll.

Ignoring everything else,  the event taking place is a dice roll.

 

Now, from what you describe, there are a number of dice-roll types that can occur.  2-dice, 3-dice-subtract-lowest, 4-dice, etc.

Those events must be communicated to all interested components.  The most generic way to do that is to broadcast the type of dice-roll, and then the dice.

 

Broadcast(4-DICE-ROLL_ENUM, 6,3,2,6)  //where the enum tells what kind of roll, and the 4 numbers tell what the rolls were.

 

You can package the message up in a million different ways, the important part is entities and/or their components need to hear about it, and react by changing their internal state, and/or sending out their own messages.  One of the entities/components may score that roll as a hit, and set it's internal state to dead, while sending out a "Died" broadcast message to all the other entities/components.

 

So, to directly answer your question, I guess you would say you "put the logic of the ability into the components".  Because they have to deal with these events as they see fit.

Share this post


Link to post
Share on other sites

[quote name='ApochPiQ' timestamp='1358372763' post='5022315']
Composable rule systems
[/quote]

 

Thank you very much!

 

I'll look into your suggestion and will report back on my progress.

Share this post


Link to post
Share on other sites

I think your problem is just reducing the complexity by separating those dice throws from interpreting them. Why not make make some simple classes to do them and then have each component which needs a different algorithm use its own different instance of that? For example like this:

 

class Dice {
  Rng& rng;
  int sides;
public:
  Dice(Rng& rng_,int sides_);
  int DoThrow() { return rng.GetNumber()%sides+1; }
};

class DiceThrower {
  // some variables to remember how to calc all the throws
public:
  DiceThrower(Dice&);
  SetDiceNumber(int);
  AddExtraDice();
  SetRuleRemoveHighestDice();
// ...
  int DoThrow();
};

class Component {
  virtual ~Component() {}
// ...
};
class MoveComponent:public Component {
  MoveComponent(DiceThrower&);
// ...
};
class ShootingComponent:public Component {
  ShootingComponent(DiceThrower&);
// ...
};

Share this post


Link to post
Share on other sites
If you can give me any good reason whatsoever to write that code in a "component" style instead of just providing a DiceThrower class and using it simply and sanely, I will buy you a six pack of the beverage of your choice.

Share this post


Link to post
Share on other sites
If you can give me any good reason whatsoever to write that code in a "component" style instead of just providing a DiceThrower class and using it simply and sanely, I will buy you a six pack of the beverage of your choice.

LOL

 

Ok, I can't do that.    But was thinking about a similar problem for my hex-based war game.   Where like the question above each unit-class can have special rules that exempt them from the "normal" base rules.    Now this can be more complicated that just the number of dice.    To give two different examples...

ALL units move at 6 hexes per turn.    Well except a select number of fast units.   They move 7 per turn.

ALL units calculate attack damage with "formula Y".   Welll except for "maulers" which use "formula Z".

and so on...

 

Initially I thought about just making those flags in my unit data table and the code would just check the flags and deciede what to do.    With all my recent reading though it seemed like a componet system might be a nice way to handle this.

 

I think (please correct me dragongame) this is similar to what the orginal question was about s/he just gave the dice throws as an example.

 

So based on that is going the componet route just overkill?

Share this post


Link to post
Share on other sites
Component systems are a very specific tool for solving a very specific problem.

To wit: components solve the case where you have a lot of common functionality that needs to be recombined in an unpredictable number of combinations, but with consistent rules as to how the combinations should work. A classic example would be building cars. Every car is a collection of a drive train, wheels, body, accessories. A component system lets you assemble a car from any combination of the requisite kinds of parts. I can come along in 6 years and assemble a totally new type of car just by combining the latest and greatest version of each part. The whole totality remains a car; if I want to change gears and start building houses, I need different code. But so long as what I'm building is still a car, my component model serves me well.

What it sound like you want is just a data-driven architecture. A unit has some properties: how many hexes can I move in a turn? Most set this to 6, some set it to 7, or 5, or any other number that you pick. A unit has an assigned damage formula. Again, most use Y, some use Z. Or if you want to introduce Q and J, you can add the formulas as new options and just pick from those (think enumerations here). Hell, if you do it right, all of them use formula K and just provide different coefficients and constants.

A rule of thumb I would suggest regarding component systems: if the vast majority of your component implementations involve less than 10 lines of unique code that is specialized for that component type, you're doing it wrong.

There's nothing bad about simple components, mind you; but most of them are going to be fairly rich, not trivial.

For your case, movement speed is trivial. Damage formula is trivial. In the OP's case, basically everything that would have been a component is really just a function.

Put another way: start your organization by grouping lines of code into routines. Group routines into modules (classes, namespaces, packages, whatever your language of choice considers a cohesive unit). Group the use of modules into components. Group components into entities. Group entities into worlds.

If at any point you don't have enough stuff to make a group (i.e. fewer than 3 of something), stop building additional layers of organizational abstraction.

Share this post


Link to post
Share on other sites

yes data driven was the path I was following and then (like many hobby developers I'm sure) got excited about something "new" and started thinking how can I use that?

 

[quote name='ApochPiQ' timestamp='1358476745' post='5022742']
If at any point you don't have enough stuff to make a group (i.e. fewer than 3 of something), stop building additional layers of organizational abstraction.
[/quote]

 

Excellent rule of thumb there....thanks for the tips

Share this post


Link to post
Share on other sites

This topic is 1824 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

Sign in to follow this  

  • Similar Content

    • By Aggrojag
      Hello!
      I'm working on a game that is quite personal to me. It touches on my own depression, obsessions, phobias, etc. It's a narrative driven dark comedy with some small aspects of platforming and puzzle solving. The project is rather small as well. It touches on topics such as suicide, mental illness, family, corruption, free-will, and redemption.
      First, I'm looking for a 2D animator that can compliment the style of the attached image. The player character's animations will be a bit more extensive than a typical platformer. There will be many death animations, and some other strange dealings with the character that will need animation. Other items will include some objects in the world that are in need of animation. All static pieces of art will be handled by the artist that drew the attached image.
      Second, I'm looking for a male voice actor. There will be at minimum two characters that will need to be brought to life through vocals. They are a very core part of the game, though they will never be shown on screen. As a reminder, this is a rather dark comedy, so be prepared for some insanity in your portrayal of these characters. The first voice is that of a game show host's voice, while the other will be a devilish voice (without SFX, I think it cheapens it, does not necessarily need to be a low voice, this is more about the portrayal than how the voice sounds).
      Last, I would love to have an editor on board. More than just avoiding disaster in the writing, I'm looking for someone that can elevate it. There is not a ton of writing that will be in the final project, but it's important enough of an aspect to be trying to bring someone in to help with it.
      To those interested:
      I have a crappy prototype that exists, along with a couple game design docs. More than anything, I'd like to present the project through a voice chat via discord to any interested. Discord - Bobdul Thundercuck#4590
      I do plan to post this on itch.io and wherever else I can put it that makes sense. I fully expect to make nothing off this project, as should you. However, in the case that money is made, a rev share model will be in place.

       
      Edit: Editor position has been filled, title has been changed to reflect this, and crossed out the section detailing this.
    • By William Edmeades
      Hey guys and girls,   Have you ever found yourself trying to apply for a job to be a game developer or a game artist? Maybe a sound engineer or a script writer? Only to not even get an interview due to lack of ‘experience’, teamwork projects or released game titles you have worked on? I have for sure. The game industry is hard and competitive to get into for someone new, especially when you might have a full time job or even have to support a family. So I have come up with an idea and I wanted to throw something out there to see if people could be interested in such an idea.   What if you could be part of a virtual game development company? A place where you can work on projects with a team of people from the internet, soon to be known as your colleagues, which could be from anywhere in the world all working at your own pace when you have time to do as little or as much as you want.   The idea is we can create the power of a company and release titles together. Not only do you then have a released game title you have worked on under your resume, but also work experience, team work skills, and the power of helping each other and learning from each other.    My dream idea is to create a solid place for people to join a party and develop ideas and create games and level up it experience points.   As far as money is concerned, the games would either be released for free or any money would go towards charity, it’s not about making money, it’s about building a career or justness having fun building games and socialising with like minded people.    I want to make something amazing, I think it would benefit me, and I think others who are serious would benefit greatly too.   I await your critasism on the ‘prototype’ idea, I just wanted to see how many people would be interested in such a concept. And if you are very much into the idea, let’s make it happen.   Thanks,   Will. www.feelingterrible.com
    • By red1m3n
      Hi I'm a hobbyist getting together a team to pursue game creation, we'll do both 2D and 3D games, we would definitely build different types of games, and hopefully have a great time doing it. you dont have to have much experience, just enough that you think you can fill the position. I have plenty of ideas for games that I'd love your help with, and am completely open to fulfilling your game ideas . As of right now this is a for fun project thing, but if me and my team are satisfied with our work it can be published to steam or other platforms. 
      The positions I'm currently looking to fill are:
      2D Pixel artist
      3D Modeler 
      C# programmer
      Musician/Sound engineer
      I am currently working on a project it is a 2D Merchant adventure game with survival elements. It does not have a name yet, that's because I'm bad with names. 
       
      If interested please feel free to leave me a PM or email at dealtavu@gmail.com so we can talk more about it..
    • By NDraskovic
      Hey guys,
      Like the title says, I'm trying to find out if it's possible to automatically set which scenes will be built for different platforms. For instance, I have scenes that I want to include when building for PC, but exclude them for mobile platforms. Is it possible to do this automatically (by some settings file, or by coding some editor extension), or do I have to manually (de)select them each time I switch platforms?
      Google just keeps sending me to the documentation sites about the regular publishing, but I can't find information about this problem.
      Thanks in advance
    • By Slack Dragon
      Download here: https://slackdragon.itch.io/dungeon-chop-chop
       
      Dungeon Chop Chop is a Singleplayer / Co-Op Rogue-like Adventure game currently in development. 
      All feedback is greatly appreciated
       
      About:
      An admirable soul tainted by darkness has laid waste to 
      the land. He has robbed civilians of their riches and lurks in 
      a dungeon locked with sorcery and guarded by monsters. 
      With treasure to claim, demons to slay and eternal fame to 
      be won, adventurers travel from far and wide to test their 
      strength against this enemy. 
      Many have tried and not a single one has returned! 
      Will you be the challenger who finally breaks the seal and 
      restore peace to the land? 
       
      Consider supporting us at:     https://www.patreon.com/SlackDragon
      Check us out on Twitter:    https://twitter.com/SlackDragonDevs
      Designers:
      Lead   Shannon Stefan Programmers:
      Lead  Harrison Jack Artists:
      Jerome Tin David





  • Popular Now