void DifficultySettingsManager::loadDifficultyNames() {
    // Locate the worldspawn entity
    Entity* worldspawn = Scene_FindEntityByClass("worldspawn");

    // Try to locate the difficulty menu entity, where the default names are defined
    IEntityClassPtr eclass = GlobalEntityClassManager().findClass(
        game::current::getValue<std::string>(GKEY_DIFFICULTY_ENTITYDEF_MENU)
    );

    // greebo: Setup the default difficulty levels using the found entityDef
    int numLevels = game::current::getValue<int>(GKEY_DIFFICULTY_LEVELS);
    for (int i = 0; i < numLevels; i++) {
        std::string nameKey = "diff" + string::to_string(i) + "default";

        // First, try to find a map-specific name
        if (worldspawn != NULL) {
            std::string name = worldspawn->getKeyValue(nameKey);
            if (!name.empty()) {
                // Found a setting on worldspawn, take it
                _difficultyNames.push_back(name);
                continue; // done for this level
            }
        }

        // If the above failed, try to load the default setting
        if (eclass != NULL) {
            EntityClassAttribute attr = eclass->getAttribute(nameKey);

            if (!attr.getValue().empty()) {
                _difficultyNames.push_back(attr.getValue());
                continue;
            }
        }

        // Fall back to a non-empty default
        _difficultyNames.push_back(string::to_string(i));
    }
}
Пример #2
0
/** Find the start position in the map and focus the viewport on it.
 */
void Map::gotoStartPosition() {
    const std::string keyLastCamPos = GlobalRegistry().get(RKEY_LAST_CAM_POSITION);
    const std::string keyLastCamAngle = GlobalRegistry().get(RKEY_LAST_CAM_ANGLE);
    const std::string eClassPlayerStart = GlobalRegistry().get(RKEY_PLAYER_START_ECLASS);

    Vector3 angles(0,0,0);
    Vector3 origin(0,0,0);

    if (m_world_node != NULL) {
        // Retrieve the entity from the worldspawn node
        Entity* worldspawn = Node_getEntity(m_world_node);
        assert(worldspawn != NULL); // This must succeed

        // Try to find a saved "last camera position"
        const std::string savedOrigin = worldspawn->getKeyValue(keyLastCamPos);

        if (savedOrigin != "")
        {
            // Construct the vector out of the std::string
            origin = string::convert<Vector3>(savedOrigin);

            Vector3 angles = string::convert<Vector3>(
                worldspawn->getKeyValue(keyLastCamAngle)
            );

            // Focus the view with the default angle
            focusViews(origin, angles);

            // Remove the saved entity key value so it doesn't appear during map edit
            removeCameraPosition();

            return;
        }
        else
        {
            // Get the player start entity
            Entity* playerStart = Scene_FindEntityByClass(eClassPlayerStart);

            if (playerStart != NULL)
            {
                // Get the entity origin
                origin = string::convert<Vector3>(
                    playerStart->getKeyValue("origin")
                );

                // angua: move the camera upwards a bit
                origin.z() += registry::getValue<float>(RKEY_PLAYER_HEIGHT);

                // Check for an angle key, and use it if present
                try {
                    angles[CAMERA_YAW] = boost::lexical_cast<float>(playerStart->getKeyValue("angle"));
                }
                catch (boost::bad_lexical_cast e) {
                    angles[CAMERA_YAW] = 0;
                }
            }
        }
    }

    // Focus the view with the given parameters
    focusViews(origin, angles);
}
Пример #3
0
void get_team_count( const char *classname, int *count, int *team ){
	GlobalSceneGraph().traverse( EntityFindTeams( classname, count, team ) );
	globalOutputStream() << "UFO:AI: classname: " << classname << ": #" << ( *count ) << "\n";
}

/**
 * @brief Some default values to worldspawn like maxlevel and so on
 */
void assign_default_values_to_worldspawn( bool override, char **returnMsg ){
	static char message[1024];
	Entity* worldspawn;
	int teams = 0;
	int count = 0;
	char str[64];

	worldspawn = Scene_FindEntityByClass( "worldspawn" );
	if ( !worldspawn ) {
		globalOutputStream() << "UFO:AI: Could not find worldspawn.\n";
		*returnMsg = "Could not find worldspawn";
		return;
	}

	*message = '\0';
	*str = '\0';

	if ( override || string_empty( worldspawn->getKeyValue( "maxlevel" ) ) ) {
		// TODO: Get highest brush - a level has 64 units
		worldspawn->setKeyValue( "maxlevel", "5" );
		snprintf( &message[strlen( message )], sizeof( message ) - 1 - strlen( message ), "Set maxlevel to: %s", worldspawn->getKeyValue( "maxlevel" ) );
	}