I think one method to implement something like this could be event-driven. This means, you will have points in your code where specific events are called. It must be somewhat extended to allow to pass parameters, but I think it’s not uncommon that event-systems can handle parameters.
First you will have to define some events in your code that can happen. This is the position where you thought of all the if
-conditions. E.g. when a player kills somebody, an event for killing somebody will be raised.
I do not know Team Fortress 2, but it’s a shooter, so I choose some shooter examples. In the code examples the first parameters always is the event name and the later ones are an indefinite list of parameters (this event takes).
- player kills another player (
callEvent('kills-player', curPlayer)
)
- player just disarmed a bomb (
callEvent('disarms-bomb', curPlayer)
)
- player reached point X (
callEvent('reaches-point', curPlayer, somePointOnMap)
)
- player saved another players live (
callEvent('saved-player', curPlayer, rescuedPlayer)
)
So it’s not boolean variables throughout your code, but specific events that will be called.
It’s now up to a totally different programmer at a totally different position in the code to either use or not use these events (called listening to them). You might also save events in a database to be able to count them (and give awards when something occured 10 times). This will also be done by the programmer who catches the events with a method like the following. It takes:
- the event-name as first parameter
- a lambda-function to handle the event as the second parameter. The lambda-function can catch all arguments we passed to the event handler before.
Code example:
listenToEvent('kills-player', function(player) {
database.incrementKillPlayerCount(player);
if (database.killPlayerCount(player) == 10) {
player.awardWithAchievement("You killed 10 enemies!");
}
});
So this little function can now cope with events that were raised in a totally different place of th code. And it will award a player with the correct achievement if needed.
Addition
As it sounds like TF2's system was very flexible: You might also implement the event-system in a manner that it watches for several situations to occur within the same time or within a timespan. Of course you had to change it a little to maintain a small buffer or similar for several seconds or milliseconds and then map calls like listenToEvent(array('kills-player', 'disarms-bomb') function() {})
to the buffer.