Example #1
bool RequirementGroup::recurseForUnitTime(int &latestTime, std::vector<Requirement>::iterator currentRequirement, int currentStartTime, int currentEndTime, std::set<Unit> &currentUnits)
	// If we have reached the end we have found a time, save it and return
	if(currentRequirement == mUnitRequirements.end())
		latestTime = currentStartTime;
		return true;


	// get a selection of free times for this requirement
	const std::map<int, int> &unitTimes = currentRequirement->earliestUnitTime(currentStartTime, currentEndTime, currentUnits);

	// For each one
	for(std::map<int, int>::const_iterator it = unitTimes.begin(); it != unitTimes.end(); ++it)

		int newEndTime = it->second;
		if(newEndTime != Requirement::maxTime)
			newEndTime += it->first;

		// go to the next requirement with these times to see if it is suitable for the rest too
		if(recurseForUnitTime(latestTime, ++(std::vector<Requirement>::iterator(currentRequirement)), it->first, newEndTime, currentUnits))
			return true;


	return false;