LogicBooleanMixin

A mixin object for ILogic that makes true or false decisions.  There are certain types of logic decisions the game that often require a set of criteria to be fulfilled, in order for that logic to be evaluated as true (or false).  However, there is always the possibility that a plugin module might have a reason to further restrict or expand on a particular logic decision.  The LogicBooleanMixin class allows this to take place.

The class LogicBooleanMixin is a BaseMixin-derived template class that takes a bool value as its one template parameter.  When the LogicBooleanMixin class is called upon to make a decision (via its Decide function), it iterates through all of the mixin string names stored in BaseMixin’s hash map.  Each of these string names must be the name of a piece of ILogic in the RuleEngine.  The LogicBooleanMixin class goes through the mixed-in ILogic, calling each via the RuleEngine.  As soon as one of them returns a value that is the opposite of the boolean template parameter, the LogicBooleanMixin class immediately exits with that value.  If all mixed-in ILogic passes, the boolean template value is returned.

This is all rather abstract, so here’s an example.  Let’s say it’s the beginning of the game and players are placing initial settlements down.  Well, there are some well-known rules for where settlements can and can’t go (like not within one corner of another settlement, not ON another settlement, etc.).  When the game needs to draw available spots for settlements on the board, it needs some way of removing every spot that is illegal to place on.  The perfect situation for LogicBooleanMixin!  The game can just assume that every hex corner is a valid location for a settlement, unless proven otherwise.  It is up to the LogicBooleanMixin to prove otherwise.  So, in actuality, the <LogicPlaceInitialSettlement> class inherits from LogicBooleanMixin with a the template bool parameter set to true.  When the Decide function is called for the class, the LogicBooleanMixin kicks into action.  It iterates through each of the mixed-in hex-corner-deciding ILogic.  Each mixed-in ILogic examines the hex corner it is given and, if it violates that logic, return false, in which case the LogicBooleanMixin returns false for that hex corner, and it cannot be built on.

Derived From

Logic BaseMixin

Project

RulesCore

Include

LogicBooleanMixin.h

Summary
A mixin object for ILogic that makes true or false decisions.
Renders the boolean decision.
Returns the rendered decision of the mixed-in ILogic.

Public

Summary
Renders the boolean decision.

Virtual Functions

Decide

virtual void Decide(const DataObject &input,
DataObject &output)

Renders the boolean decision.  Calls the Execute function to iterate through all of the stored mixin ILogic.

Parameters

inputThe input DataObject.  Must not be empty.
outputThe output DataObject.  Must be empty.  Will be filled with a bool value on the way out that is the rendered decision of the LogicBooleanMixin.

Private

Summary
Returns the rendered decision of the mixed-in ILogic.

Functions

Evaluate

bool Evaluate(const DataObject &input)

Returns the rendered decision of the mixed-in ILogic.  Iterates through each of the mixed-in ILogic names in the BaseMixin hash map.  If a piece of ILogic returns with a value that invalidates the bool template parameter, Evaluate immediately returns with the invalid bool.  If all mixed-in ILogic returns with the same bool value, the original template parameter was valid and it is returned as the rendered decision.

Parameters

inputThe input DataObject.

Returns

boolA bool giving the rendered decision of all mixed-in ILogic.
The interface of a single piece of game logic.
virtual void Decide(const DataObject &input,
DataObject &output)
Renders the boolean decision.
bool Evaluate(const DataObject &input)
Returns the rendered decision of the mixed-in ILogic.
The base class for any IRule or ILogic mixin objects.
The default implementation of the IRuleEngine interface.
The default implementation of ILogic for normal Game actions.
RulesCore is the HOSS of Cities3D.
virtual void Execute(const DataObject &object)=0
Executes a rule.
A generic container for passing any kind of data around.