• Advertisement
Sign in to follow this  

Unity Special Rules in a Turn Based Entity Component System

This topic is 1827 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
Advertisement
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
Sign in to follow this  

  • Advertisement
  • Advertisement
  • Popular Now

  • Advertisement
  • Similar Content

    • By Affgoo
      https://play.google.com/store/apps/details?id=com.NE.Alien
      still a lot of work to do, but its pretty stable  please let me know what you think <3
      Atlas Sentry is a game of destroy everything. Using your turret, simply swivel and shoot your way to victory, upgrading your weapons to unleash destruction on the variety of spaceships. The bigger your combo’s the more score you get! Earn silver as you play and then purchase new weapons and abilities to better deal with your enemy. Different enemies use different tactics and weapons, work out your own priorities in their destruction order. 

      Features: 
      **2 different game modes 
      **A level select mode with 20 difficult levels including a final boss, can you defeat it? **Arcade mode of endless destruction, how long will you last? 
      **High scores to compete against others, see who can take the top spot. 
       
    • By Chamferbox
      Chamferbox, a mini game asset store has just opened with some nice game assets, 
      Here you can find a free greek statue asset 

      Also check their dragon, zombie dragon and scorpion monster out:



      They're running the Grand Opening Sale, it's 30% off for all items, but for gamedev member, you can use this coupon code:
      GRANDOPEN
      to get 50% off prices What are you waiting for, go to
      http://chamferbox.com
      and get those models now!

      View full story
    • By Dafu
      FES Retro Game Framework is now available on the Unity Asset Store for your kind consideration!
      FES was born when I set out to start a retro pixel game project. I was looking around for an engine to try next. I tried a number of things, from GameMaker, to Fantasy Consoles, to MonoGame and Godot and then ended up back at Unity. Unity is just unbeatable in it's cross-platform support, and ease of deployment, but it sure as heck gets in the way of proper retro pixel games!
      So I poured over the Unity pipeline and found the lowest levels I could tie into and bring up a new retro game engine inside of Unity, but with a completely different source-code-only, classic game-loop retro blitting and bleeping API. Months of polishing and tweaking later I ended up with FES.
      Some FES features:
      Pixel perfect rendering RGB and Indexed color mode, with palette swapping support Primitive shape rendering, lines, rectangles, ellipses, pixels Multi-layered tilemaps with TMX file support Offscreen rendering Text rendering, with text alignment, overflow settings, and custom pixel font support Clipping Sound and Music APIs Simplified Input handling Wide pixel support (think Atari 2600) Post processing and transition effects, such as scanlines, screen wipes, screen shake, fade, pixelate and more Deploy to all Unity supported platforms I've put in lots of hours into a very detail documentation, you can flip through it here to get an better glimpse at the features and general overview: http://www.pixeltrollgames.com/fes/docs/index.html
      FES is carefully designed and well optimized (see live stress test demo below). Internally it uses batching, it chunks tilemaps, is careful about memory allocations, and tries to be smart about any heavy operations.
      Please have a quick look at the screenshots and live demos below and let me know what you think! I'd love to hear some opinions, feedback and questions!
      I hope I've tickled your retro feels!



      More images at: https://imgur.com/a/LFMAc
      Live demo feature reel: https://simmer.io/@Dafu/fes
      Live blitting stress test: https://simmer.io/@Dafu/fes-drawstress
      Unity Asset Store: https://www.assetstore.unity3d.com/#!/content/102064

      View full story
    • By DevdogUnity

      Ho ho ho
      Tis the season of Christmas surprises, and we have a awesome one for you! 🎅  
      Sponsored by all your favorite Unity Asset Store developers, Nordic Game Jam, Pocket Gamer Connects, and co-hosted by Game Analytics, we (Joris and I – Devdog) are launching the second edition of our yearly Christmas Giveaway Calendar for all Unity game developers!
      You can already now sign up right here.
       
      So what’s this all about?
      For the past weeks, we’ve been collecting sponsored gifts related to Unity (asset vouchers, product keys, conference tickets etc.), and throughout each day of December leading up to Christmas Day on the 25th, we will be sending out these sponsored gifts as early gamedev Christmas presents via e-mail to hundreds of lucky winners.
      The total prize pool is at $35,000, with over 1200 presents donated by the awesome sponsors!
       
      Merry Christmas from Devdog, Game Analytics, and every single one of the sponsors.

      View full story
    • By sveta_itseez3D
      itSeez3D, a leading developer of mobile 3d scanning software, announced today a new SDK for its automatic 3D avatar generation technology, Avatar SDK for Unity. The Avatar SDK for Unity is a robust plug-n-play toolset which enables developers and creatives to integrate realistic user-generated 3D avatars into their Unity-based applications. SDK users can allow players to create their own avatars in the application or integrate the SDK into their own production processes for character design and animation.
      “Virtual avatars have recently become increasingly popular, especially in sports games and social VR apps. With the advance of VR and AR, the demand to get humans into the digital world is only increasing”, said Victor Erukhimov, itSeez3D CEO. “Our new Avatar SDK for Unity makes it super-easy to bring the avatar technology into any Unity-based game or VR/AR experience. With the Avatar SDK for Unity now every developer can bring face scanning technology into their games and allow players to create their own personalized in-game avatars, making the gameplay much more exciting and immersive.”
      Key features of the Avatar SDK for Unity:
      Automatic generation of a color 3D face model from a single selfie photo in 5-10 seconds (!). Works best with selfies, but can be used with any portrait photo.
      Shape and texture of the head model are unique for each person, synthesized with a deep learning algorithm crafted by computer vision experts
      Head models support runtime blendshape facial animations (45 different expressions)
      Generated 3D heads include eyes, mouth, and teeth
      Algorithms synthesize 3D meshes in mid-poly resolution, ~12k vertices, and ~24k triangles
      Six predefined hairstyles with hair-recoloring feature (many more available on request)
      Avatar generation API can be used in design-time and in run-time, which means you can allow users to create their own avatars in your game
      Cloud version is cross-platform, and offline version currently works on PCs with 64-bit Windows (support for more platforms is coming soon)
      Well-documented samples showcasing the functionality.
       
      Availability
      The Avatar SDK for Unity is offered in two modes - “Cloud” and “Offline”. The “Cloud” version is available at http://avatarsdk.com/ and the “Offline” version is available by request at support@itseez3d.com.
      ###
      About itSeez3D
      At itSeez3D, we are working on the computer vision technology that turns mobile devices into powerful 3D scanners. itSeez3D has developed the world's first mobile 3D scanning application that allows to create high-resolution photorealistic 3D models of people's' faces, bodies and objects. The application is available for iOS and Windows OS mobile devices powered with 3D cameras. In 2016 the company introduced Avatar SDK that creates a realistic 3D model of a face from a single selfie photo. To learn more about itSeez3D scanning software and 3D avatar creation technology, please visit www.itseez3d.com and www.avatarsdk.com.

      View full story
  • Advertisement