void NeighborDensityFactoryDataModel::ReadCustomRule(ifstream * stream, map<string, LevelFactory*>* previousFactories, NeighborDensityFactory* factory)
	{
		string currentLine;
		// Get the rule factory name.
		getline(*stream, currentLine);
		// Get the corresponding factory.
		LevelFactory* ruleFactory = GetFactoryByName(currentLine, previousFactories);

		if (ruleFactory == NULL)
		{
			throw new std::invalid_argument("Cannot have a null factory as a rule.");
		}

		// Rule to be added.
		Rule* newRule = new Rule(ruleFactory);

		getline(*stream, currentLine);

		// Fill the conditions of the Rule. Until the "End of Rule" marker is met.
		while (currentLine != "End AddConditions")
		{
			Vector3 fetchCoordinates = UtilityReaderWriter::ReadVector3(stream);
			bool expectedValue = UtilityReaderWriter::ReadBool(stream);

			// Add the new condition to the Rule.
			newRule->AddCondition(fetchCoordinates, expectedValue);

			getline(*stream, currentLine);
		}

		factory->AddRule(newRule);
	}
Example #2
0
Rule *Rule::duplicate()
{
    Rule *rule = new Rule(get_type(), get_name() + " (copy)", get_specialType());

    for (Condition *cond: conds)
    {
        Condition *newcond = cond->duplicate();
        rule->AddCondition(newcond);
    }

    for (Action *act: actions)
    {
        Action *newact = act->duplicate();
        rule->AddAction(newact);
    }

    return rule;
}