void DifficultySettings::parseFromMapEntity(Entity* entity) {
    // Construct the prefix for the desired difficulty level
    std::string diffPrefix = "diff_" + string::to_string(_level) + "_";
    std::string prefix = diffPrefix + "change_";

    Entity::KeyValuePairs spawnargs = entity->getKeyValuePairs(prefix);

    for (Entity::KeyValuePairs::iterator i = spawnargs.begin();
         i != spawnargs.end(); ++i)
    {
        const std::string& key = i->first;
        const std::string& value = i->second;

        if (value.empty()) {
            continue; // empty spawnarg attribute => invalid
        }

        // Get the index from the string's tail
        std::string indexStr = key.substr(prefix.length());

        std::string className = entity->getKeyValue(diffPrefix + "class_" + indexStr);
        SettingPtr setting = createSetting(className);
        setting->spawnArg = value;
        setting->argument = entity->getKeyValue(diffPrefix + "arg_" + indexStr);

        // This has been parsed from the default entityDef
        setting->isDefault = false;

        // Interpret/parse the argument string
        setting->parseAppType();
    }

    clearTreeModel();
    updateTreeModel();
}
void ConversationEntity::clearEntity(Entity* entity) {
	// Get all keyvalues matching the "obj" prefix.
	Entity::KeyValuePairs keyValues = entity->getKeyValuePairs("conv_");

	for (Entity::KeyValuePairs::const_iterator i = keyValues.begin();
		 i != keyValues.end(); ++i)
	{
		// Set the spawnarg to empty, which is equivalent to a removal
		entity->setKeyValue(i->first, "");
	}
}
예제 #3
0
void ObjectiveEntity::readMissionLogic(Entity& ent)
{
	// Find the success logic strings
	Entity::KeyValuePairs successLogics = ent.getKeyValuePairs(KV_SUCCESS_LOGIC);

	for (Entity::KeyValuePairs::const_iterator kv = successLogics.begin();
		 kv != successLogics.end(); kv++)
	{
		std::string postfix = kv->first.substr(KV_SUCCESS_LOGIC.size());

		if (postfix.empty()) {
			// Empty postfix means that we've found the default logic
			LogicPtr logic = getMissionLogic(-1);
			logic->successLogic = kv->second;
		}
		else if (string::starts_with(postfix, "_diff_"))
		{
			// We seem to have a difficulty-related logic, get the level
			int level = string::convert<int>(postfix.substr(6), INVALID_LEVEL_INDEX);

			if (level == INVALID_LEVEL_INDEX) {
				rError() << "[ObjectivesEditor]: Cannot parse difficulty-specific " <<
					"logic strings: " << kv->second << std::endl;
				continue;
			}

			LogicPtr logic = getMissionLogic(level);
			logic->successLogic = kv->second;
		}
	}

	// Find the failure logic strings
	Entity::KeyValuePairs failureLogics = ent.getKeyValuePairs(KV_FAILURE_LOGIC);

	for (Entity::KeyValuePairs::const_iterator kv = failureLogics.begin();
		 kv != failureLogics.end(); kv++)
	{
		std::string postfix = kv->first.substr(KV_FAILURE_LOGIC.size());

		if (postfix.empty()) {
			// Empty postfix means that we've found the default logic
			LogicPtr logic = getMissionLogic(-1);
			logic->failureLogic = kv->second;
		}
		else if (string::starts_with(postfix, "_diff_"))
		{
			// We seem to have a difficulty-related logic, get the level
			int level = string::convert<int>(postfix.substr(6), INVALID_LEVEL_INDEX);

			if (level == INVALID_LEVEL_INDEX) {
				rError() << "[ObjectivesEditor]: Cannot parse difficulty-specific " <<
					"logic strings: " << kv->second << std::endl;
				continue;
			}

			LogicPtr logic = getMissionLogic(level);
			logic->failureLogic = kv->second;
		}
	}
}
예제 #4
0
void ObjectiveEntity::readObjectiveConditions(Entity& ent)
{
	_objConditions.clear(); // remove any previously parsed conditions

	Entity::KeyValuePairs condSpawnargs = ent.getKeyValuePairs(OBJ_COND_PREFIX);

	static const boost::regex objCondExpr(OBJ_COND_PREFIX + "(\\d+)_(.*)");

	for (Entity::KeyValuePairs::const_iterator kv = condSpawnargs.begin();
		 kv != condSpawnargs.end(); kv++)
	{
		boost::smatch results;

		if (!boost::regex_match(kv->first, results, objCondExpr))
		{
			continue; // No match, abort
		}

		int index = string::convert<int>(results[1]);

		// Valid indices are [1..infinity)
		if (index < 1) 
		{
			continue; // invalid index, continue
		}

		const ObjectiveConditionPtr& cond = getOrCreateObjectiveCondition(index);

		std::string postfix = results[2];

		if (postfix == "src_mission")
		{
			cond->sourceMission = string::convert<int>(kv->second);
		}
		else if (postfix == "src_obj")
		{
			cond->sourceObjective = string::convert<int>(kv->second);
		}
		else if (postfix == "src_state")
		{
			int val = string::convert<int>(kv->second);

			if (val >= Objective::INCOMPLETE && val < Objective::NUM_STATES)
			{
				cond->sourceState = static_cast<Objective::State>(val);
			}
			else
			{
				rWarning() << "Unsupported objective condition source state encountered: " 
					<< kv->second << std::endl;
			}
		}
		else if (postfix == "target_obj")
		{
			cond->targetObjective = string::convert<int>(kv->second);
		}
		else if (postfix == "type")
		{
			if (kv->second == "changestate")
			{
				cond->type = ObjectiveCondition::CHANGE_STATE;
			}
			else if (kv->second == "changevisibility")
			{
				cond->type = ObjectiveCondition::CHANGE_VISIBILITY;
			}
			else if (kv->second == "changemandatory")
			{
				cond->type = ObjectiveCondition::CHANGE_MANDATORY;
			}
			else
			{
				rWarning() << "Unsupported objective condition type encountered: " 
					<< kv->second << std::endl;
			}
		}
		else if (postfix == "value")
		{
			cond->value = string::convert<int>(kv->second);
		}
	}
}