I'm currently working on a clone of an old turn-based strategy game "Stars!" and am looking for solutions to a challenge in game engine implementation.

The premise

The premise of the game is that every player takes control over the entire race of his denizens (called "colonists") and fight other players to conquer the known part of the galaxy. Each player can design their race as they please. The first choices presented when creating a race are those of the Primary Racial Trait (PRT - must select exactly one from a list of 10) and Lesser Racial Traits (LRT - can select any number of them from a list of 14). A PRT usually modifies several aspects of the base game, e.g. sets starting technology level, gives some starting spaceships, controls the availability of certain ship parts and modifies the rules of the game for that player while LRTs provide minor advantages/disadvantages.

A few examples to show the extent of game modifications as well as interactions between them:

  • PRTs can modify the same part of the rules from two directions: Inner Strength PRT - 10% increased strength of defending colonists; War Monger PRT - 10% increased strength of attacking colonists.
  • PRT and LRT can directly modify the same "property" of a race: Jack Of All Trades PRT - +20% maximum planet population; Only Basic Remote Mining LRT - +10% maximum planet population; they cumulate multiplicatively (+32%).
  • LRTs can work conditionally based on other LRTs: Improved Fuel Efficiency grants access to several unique types of engine, where one of them is granted only if another LRT No Ram-Scoop Engines is not chosen.
  • PRT can fundamentally modify the game mechanics: Alternate Reality PRT races do not live on planets but rather in orbiting starbases. Rules of economy (resource production) are completely different for them as they do not build planetary facilities (factories and mines).

Constraints - the challenge

  • Make it possible to design new PRTs and LRTs and put them in the game without much pain.
  • (Induced from previous) They must be in some way decoupled from the main engine (so the core "rules engine" cannot be based on if/switch statements that change flow based on PRT/LRT).

The question

What design patterns would be suitable to this problem of "pluggable modifiers"?

The language is C#, if that helps with suggesting more specific solutions. So far my brain is wandering in the realm of attaching the Traits to events in the engine where it calculates certain properties (so they could modify the output of these calculations), but I don't want to suggest too much.

  • 1
    \$\begingroup\$ Possible duplicate of What's a way to implement a flexible buff/debuff system? \$\endgroup\$ – Sean Middleditch Oct 7 '16 at 21:00
  • \$\begingroup\$ I would think that as you try to decouple your existing PRT and LRT traits from your engine, your pluggable engine will emerge. Each trait should have a value or list of values that act as input for the engine. If you've hard coded the interactions between the traits and the game mechanics, disconnect and rewrite code with variables and functions until every trait option can be plugged in and have the desired effect. I know I'm kind of just restating your question, but I think once you hack through all your code into segments that receive the important data from the traits, add new will b ez \$\endgroup\$ – Neal Davis Oct 7 '16 at 22:02
  • \$\begingroup\$ First step: add a layer of abstraction - you've got a set of game rules and a bunch of entities with properties (e.g. ships, tech, ...). Your racial traits are groups/lists of modifiers. After all traits are selected, you need to iterate over the modifiers and apply them. For resolving conflicts, you could have modifiers override each other by a priority or always apply "allow" modifiers and then "deny" modifiers. E.g. "fuel efficiency" would make ram engine tech available and "no ram" would disable the tech again. \$\endgroup\$ – Exilyth Oct 14 '16 at 22:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.