Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm working on my first game, and taking the opportunity to brush up my C++ (I want to make as much of it as portable as I can.)

Whilst working on the technology tree and how it affects actors (spaceships, planets, crew, buildings, etc) I can't find a pattern that decouples these entities enough to feel like a clean approach.

Just as an idea, here's the type of effects these actors can have on one another (and techs too)

  • An engineer inside a spaceship boosts its shield
  • A hero in a spaceship in a fleet increases morale
  • A technology improves spaceships' travel distance
  • A building in a planet improves its production

The best I can come up with is the Observer pattern, and basically manage it more or less manually (when a crew member enters a spaceship, fire the event; when a new building is built in a planet, fire the event, etc etc.) but it seems to be too tightly coupled to me.

I would love to get some ideas about how to approach this better.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

I would say that you could probably approach this the same way that RPGs and MMOs handle 'buffs' and 'debuffs', as these are modifiers applied to a base value that can be added or removed based on some condition.

As such, the answers here may help: What's a way to implement a flexible buff/debuff system?

I would warn against an event-driven system for this situation as they are prone to 'drift' when trying to apply and remove complex modifiers. (eg. If you apply a x2 modifier, then a +10 modifier, remove the x2 modifier, then remove the +10 modifier, it's easy to accidentally end up 5 points below where you started.) For this reason, I don't think an Observer pattern is ideal.

Instead, I would poll the values when needed. When checking shields, count the engineers inside. When checking morale, look for heroes in the spaceships in the fleet. If this turns out to perform poorly, you can cache the values or precalculate these queries.

share|improve this answer
    
And all this time I was doing the wrong search! Thank you for the great answer! –  changelog Jul 4 '12 at 8:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.