X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=contrib%2Fufoaiplug%2Fufoai_level.cpp;fp=contrib%2Fufoaiplug%2Fufoai_level.cpp;h=c7554e4d2c4771858e3b438cd16cd1afa468ca03;hb=9557abbf571aaf6bd9180e05baa209f25ebade3a;hp=3a36b258056cfe4ed9f060f75b3be29603fbdd6a;hpb=0b86577ab8b9bcd3403b77eafc33c2048b147d35;p=xonotic%2Fnetradiant.git diff --git a/contrib/ufoaiplug/ufoai_level.cpp b/contrib/ufoaiplug/ufoai_level.cpp index 3a36b258..c7554e4d 100644 --- a/contrib/ufoaiplug/ufoai_level.cpp +++ b/contrib/ufoaiplug/ufoai_level.cpp @@ -1,20 +1,20 @@ /* -This file is part of GtkRadiant. + This file is part of GtkRadiant. -GtkRadiant is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. + GtkRadiant is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. -GtkRadiant is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + GtkRadiant is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with GtkRadiant; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ + You should have received a copy of the GNU General Public License + along with GtkRadiant; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ #include "ufoai_level.h" #include "ufoai_filters.h" @@ -34,34 +34,29 @@ class Level; */ class EntityFindByClassname : public scene::Graph::Walker { - const char* m_name; - Entity*& m_entity; +const char* m_name; +Entity*& m_entity; public: - EntityFindByClassname(const char* name, Entity*& entity) : m_name(name), m_entity(entity) - { - m_entity = 0; - } - bool pre(const scene::Path& path, scene::Instance& instance) const - { - if(m_entity == 0) - { - Entity* entity = Node_getEntity(path.top()); - if(entity != 0 && string_equal(m_name, entity->getKeyValue("classname"))) - { - m_entity = entity; - } +EntityFindByClassname( const char* name, Entity*& entity ) : m_name( name ), m_entity( entity ){ + m_entity = 0; +} +bool pre( const scene::Path& path, scene::Instance& instance ) const { + if ( m_entity == 0 ) { + Entity* entity = Node_getEntity( path.top() ); + if ( entity != 0 && string_equal( m_name, entity->getKeyValue( "classname" ) ) ) { + m_entity = entity; } - return true; } + return true; +} }; /** * @brief */ -Entity* Scene_FindEntityByClass(const char* name) -{ +Entity* Scene_FindEntityByClass( const char* name ){ Entity* entity = NULL; - GlobalSceneGraph().traverse(EntityFindByClassname(name, entity)); + GlobalSceneGraph().traverse( EntityFindByClassname( name, entity ) ); return entity; } @@ -70,28 +65,24 @@ Entity* Scene_FindEntityByClass(const char* name) */ class EntityFindFlags : public scene::Graph::Walker { - const char *m_classname; - const char *m_flag; - int *m_count; +const char *m_classname; +const char *m_flag; +int *m_count; - public: - EntityFindFlags(const char *classname, const char *flag, int *count) : m_classname(classname), m_flag(flag), m_count(count) - { - } - bool pre(const scene::Path& path, scene::Instance& instance) const - { - const char *str; - Entity* entity = Node_getEntity(path.top()); - if(entity != 0 && string_equal(m_classname, entity->getKeyValue("classname"))) - { - str = entity->getKeyValue(m_flag); - if (string_empty(str)) - { - (*m_count)++; - } - } - return true; +public: +EntityFindFlags( const char *classname, const char *flag, int *count ) : m_classname( classname ), m_flag( flag ), m_count( count ){ +} +bool pre( const scene::Path& path, scene::Instance& instance ) const { + const char *str; + Entity* entity = Node_getEntity( path.top() ); + if ( entity != 0 && string_equal( m_classname, entity->getKeyValue( "classname" ) ) ) { + str = entity->getKeyValue( m_flag ); + if ( string_empty( str ) ) { + ( *m_count )++; } + } + return true; +} }; @@ -100,60 +91,54 @@ class EntityFindFlags : public scene::Graph::Walker */ class EntityFindTeams : public scene::Graph::Walker { - const char *m_classname; - int *m_count; - int *m_team; +const char *m_classname; +int *m_count; +int *m_team; public: - EntityFindTeams(const char *classname, int *count, int *team) : m_classname(classname), m_count(count), m_team(team) - { - } - bool pre(const scene::Path& path, scene::Instance& instance) const - { - const char *str; - Entity* entity = Node_getEntity(path.top()); - if(entity != 0 && string_equal(m_classname, entity->getKeyValue("classname"))) - { - if (m_count) - (*m_count)++; - // now get the highest teamnum - if (m_team) - { - str = entity->getKeyValue("team"); - if (!string_empty(str)) - { - if (atoi(str) > *m_team) - (*m_team) = atoi(str); +EntityFindTeams( const char *classname, int *count, int *team ) : m_classname( classname ), m_count( count ), m_team( team ){ +} +bool pre( const scene::Path& path, scene::Instance& instance ) const { + const char *str; + Entity* entity = Node_getEntity( path.top() ); + if ( entity != 0 && string_equal( m_classname, entity->getKeyValue( "classname" ) ) ) { + if ( m_count ) { + ( *m_count )++; + } + // now get the highest teamnum + if ( m_team ) { + str = entity->getKeyValue( "team" ); + if ( !string_empty( str ) ) { + if ( atoi( str ) > *m_team ) { + ( *m_team ) = atoi( str ); } } } - return true; } + return true; +} }; /** * @brief */ -void get_team_count (const char *classname, int *count, int *team) -{ - GlobalSceneGraph().traverse(EntityFindTeams(classname, count, team)); - globalOutputStream() << "UFO:AI: classname: " << classname << ": #" << (*count) << "\n"; +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) -{ +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) - { + worldspawn = Scene_FindEntityByClass( "worldspawn" ); + if ( !worldspawn ) { globalOutputStream() << "UFO:AI: Could not find worldspawn.\n"; *returnMsg = "Could not find worldspawn"; return; @@ -162,31 +147,28 @@ void assign_default_values_to_worldspawn (bool override, char **returnMsg) *message = '\0'; *str = '\0'; - if (override || string_empty(worldspawn->getKeyValue("maxlevel"))) - { + 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")); + worldspawn->setKeyValue( "maxlevel", "5" ); + snprintf( &message[strlen( message )], sizeof( message ) - 1 - strlen( message ), "Set maxlevel to: %s", worldspawn->getKeyValue( "maxlevel" ) ); } - if (override || string_empty(worldspawn->getKeyValue("maxteams"))) - { - get_team_count("info_player_start", &count, &teams); - if (teams) - { - snprintf(str, sizeof(str) - 1, "%i", teams); - worldspawn->setKeyValue("maxteams", str); - snprintf(&message[strlen(message)], sizeof(message) - 1 - strlen(message), "Set maxteams to: %s", worldspawn->getKeyValue("maxteams")); + if ( override || string_empty( worldspawn->getKeyValue( "maxteams" ) ) ) { + get_team_count( "info_player_start", &count, &teams ); + if ( teams ) { + snprintf( str, sizeof( str ) - 1, "%i", teams ); + worldspawn->setKeyValue( "maxteams", str ); + snprintf( &message[strlen( message )], sizeof( message ) - 1 - strlen( message ), "Set maxteams to: %s", worldspawn->getKeyValue( "maxteams" ) ); } - if (count < 16) - { - snprintf(&message[strlen(message)], sizeof(message) - 1 - strlen(message), "You should at least place 16 info_player_start"); + if ( count < 16 ) { + snprintf( &message[strlen( message )], sizeof( message ) - 1 - strlen( message ), "You should at least place 16 info_player_start" ); } } // no errors - no warnings - if (!strlen(message)) + if ( !strlen( message ) ) { return; + } *returnMsg = message; } @@ -194,14 +176,13 @@ void assign_default_values_to_worldspawn (bool override, char **returnMsg) /** * @brief */ -int check_entity_flags (const char *classname, const char *flag) -{ +int check_entity_flags( const char *classname, const char *flag ){ int count; /* init this with 0 every time we browse the tree */ count = 0; - GlobalSceneGraph().traverse(EntityFindFlags(classname, flag, &count)); + GlobalSceneGraph().traverse( EntityFindFlags( classname, flag, &count ) ); return count; } @@ -209,8 +190,7 @@ int check_entity_flags (const char *classname, const char *flag) * @brief Will check e.g. the map entities for valid values * @todo: check for maxlevel */ -void check_map_values (char **returnMsg) -{ +void check_map_values( char **returnMsg ){ static char message[1024]; int count = 0; int teams = 0; @@ -218,9 +198,8 @@ void check_map_values (char **returnMsg) Entity* worldspawn; char str[64]; - worldspawn = Scene_FindEntityByClass("worldspawn"); - if (!worldspawn) - { + worldspawn = Scene_FindEntityByClass( "worldspawn" ); + if ( !worldspawn ) { globalOutputStream() << "UFO:AI: Could not find worldspawn.\n"; *returnMsg = "Could not find worldspawn"; return; @@ -230,63 +209,74 @@ void check_map_values (char **returnMsg) *str = '\0'; // multiplayer start positions - get_team_count("info_player_start", &count, &teams); - if (!count) - strncat(message, "No multiplayer start positions (info_player_start)\n", sizeof(message) - 1); + get_team_count( "info_player_start", &count, &teams ); + if ( !count ) { + strncat( message, "No multiplayer start positions (info_player_start)\n", sizeof( message ) - 1 ); + } // singleplayer map? count = 0; - get_team_count("info_human_start", &count, NULL); - if (!count) - strncat(message, "No singleplayer start positions (info_human_start)\n", sizeof(message) - 1); + get_team_count( "info_human_start", &count, NULL ); + if ( !count ) { + strncat( message, "No singleplayer start positions (info_human_start)\n", sizeof( message ) - 1 ); + } // singleplayer map? count = 0; - get_team_count("info_2x2_start", &count, NULL); - if (!count) - strncat(message, "No singleplayer start positions for 2x2 units (info_2x2_start)\n", sizeof(message) - 1); + get_team_count( "info_2x2_start", &count, NULL ); + if ( !count ) { + strncat( message, "No singleplayer start positions for 2x2 units (info_2x2_start)\n", sizeof( message ) - 1 ); + } // search for civilians count = 0; - get_team_count("info_civilian_start", &count, NULL); - if (!count) - strncat(message, "No civilian start positions (info_civilian_start)\n", sizeof(message) - 1); + get_team_count( "info_civilian_start", &count, NULL ); + if ( !count ) { + strncat( message, "No civilian start positions (info_civilian_start)\n", sizeof( message ) - 1 ); + } // check maxlevel - if (string_empty(worldspawn->getKeyValue("maxlevel"))) - strncat(message, "Worldspawn: No maxlevel defined\n", sizeof(message) - 1); - else if (atoi(worldspawn->getKeyValue("maxlevel")) > 8) - { - strncat(message, "Worldspawn: Highest maxlevel is 8\n", sizeof(message) - 1); - worldspawn->setKeyValue("maxlevel", "8"); + if ( string_empty( worldspawn->getKeyValue( "maxlevel" ) ) ) { + strncat( message, "Worldspawn: No maxlevel defined\n", sizeof( message ) - 1 ); + } + else if ( atoi( worldspawn->getKeyValue( "maxlevel" ) ) > 8 ) { + strncat( message, "Worldspawn: Highest maxlevel is 8\n", sizeof( message ) - 1 ); + worldspawn->setKeyValue( "maxlevel", "8" ); } - ent_flags = check_entity_flags("func_door", "spawnflags"); - if (ent_flags) - snprintf(&message[strlen(message)], sizeof(message) - 1 - strlen(message), "Found %i func_door with no spawnflags\n", ent_flags); - ent_flags = check_entity_flags("func_breakable", "spawnflags"); - if (ent_flags) - snprintf(&message[strlen(message)], sizeof(message) - 1 - strlen(message), "Found %i func_breakable with no spawnflags\n", ent_flags); - ent_flags = check_entity_flags("misc_sound", "spawnflags"); - if (ent_flags) - snprintf(&message[strlen(message)], sizeof(message) - 1 - strlen(message), "Found %i misc_sound with no spawnflags\n", ent_flags); - ent_flags = check_entity_flags("misc_model", "spawnflags"); - if (ent_flags) - snprintf(&message[strlen(message)], sizeof(message) - 1 - strlen(message), "Found %i misc_model with no spawnflags\n", ent_flags); - ent_flags = check_entity_flags("misc_particle", "spawnflags"); - if (ent_flags) - snprintf(&message[strlen(message)], sizeof(message) - 1 - strlen(message), "Found %i misc_particle with no spawnflags\n", ent_flags); - ent_flags = check_entity_flags("info_player_start", "team"); - if (ent_flags) - snprintf(&message[strlen(message)], sizeof(message) - 1 - strlen(message), "Found %i info_player_start with no team assigned\n!!Teamcount may change after you've fixed this\n", ent_flags); - ent_flags = check_entity_flags("light", "color"); - ent_flags = check_entity_flags("light", "_color"); - if (ent_flags) - snprintf(&message[strlen(message)], sizeof(message) - 1 - strlen(message), "Found %i lights with no color value\n", ent_flags); + ent_flags = check_entity_flags( "func_door", "spawnflags" ); + if ( ent_flags ) { + snprintf( &message[strlen( message )], sizeof( message ) - 1 - strlen( message ), "Found %i func_door with no spawnflags\n", ent_flags ); + } + ent_flags = check_entity_flags( "func_breakable", "spawnflags" ); + if ( ent_flags ) { + snprintf( &message[strlen( message )], sizeof( message ) - 1 - strlen( message ), "Found %i func_breakable with no spawnflags\n", ent_flags ); + } + ent_flags = check_entity_flags( "misc_sound", "spawnflags" ); + if ( ent_flags ) { + snprintf( &message[strlen( message )], sizeof( message ) - 1 - strlen( message ), "Found %i misc_sound with no spawnflags\n", ent_flags ); + } + ent_flags = check_entity_flags( "misc_model", "spawnflags" ); + if ( ent_flags ) { + snprintf( &message[strlen( message )], sizeof( message ) - 1 - strlen( message ), "Found %i misc_model with no spawnflags\n", ent_flags ); + } + ent_flags = check_entity_flags( "misc_particle", "spawnflags" ); + if ( ent_flags ) { + snprintf( &message[strlen( message )], sizeof( message ) - 1 - strlen( message ), "Found %i misc_particle with no spawnflags\n", ent_flags ); + } + ent_flags = check_entity_flags( "info_player_start", "team" ); + if ( ent_flags ) { + snprintf( &message[strlen( message )], sizeof( message ) - 1 - strlen( message ), "Found %i info_player_start with no team assigned\n!!Teamcount may change after you've fixed this\n", ent_flags ); + } + ent_flags = check_entity_flags( "light", "color" ); + ent_flags = check_entity_flags( "light", "_color" ); + if ( ent_flags ) { + snprintf( &message[strlen( message )], sizeof( message ) - 1 - strlen( message ), "Found %i lights with no color value\n", ent_flags ); + } // no errors found - if (!strlen(message)) { - snprintf(message, sizeof(message) - 1, "No errors found - you are ready to compile the map now\n"); + if ( !strlen( message ) ) { + snprintf( message, sizeof( message ) - 1, "No errors found - you are ready to compile the map now\n" ); } *returnMsg = message;