2 This file is part of GtkRadiant.
4 GtkRadiant is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 GtkRadiant is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with GtkRadiant; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #include "ufoai_level.h"
20 #include "ufoai_filters.h"
24 #include "iscenegraph.h"
26 #include "string/string.h"
32 * @brief find entities by class
33 * @note from radiant/map.cpp
35 class EntityFindByClassname : public scene::Graph::Walker
40 EntityFindByClassname(const char* name, Entity*& entity) : m_name(name), m_entity(entity)
44 bool pre(const scene::Path& path, scene::Instance& instance) const
48 Entity* entity = Node_getEntity(path.top());
49 if(entity != 0 && string_equal(m_name, entity->getKeyValue("classname")))
61 Entity* Scene_FindEntityByClass(const char* name)
63 Entity* entity = NULL;
64 GlobalSceneGraph().traverse(EntityFindByClassname(name, entity));
69 * @brief finds start positions
71 class EntityFindTeams : public scene::Graph::Walker
73 const char *m_classname;
78 EntityFindTeams(const char *classname, int *count, int *team) : m_classname(classname), m_count(count), m_team(team)
81 bool pre(const scene::Path& path, scene::Instance& instance) const
84 Entity* entity = Node_getEntity(path.top());
85 if(entity != 0 && string_equal(m_classname, entity->getKeyValue("classname")))
89 // now get the highest teamnum
92 str = entity->getKeyValue("team");
93 if (!string_empty(str))
95 if (atoi(str) > *m_team)
96 (*m_team) = atoi(str);
107 void get_team_count (const char *classname, int *count, int *team)
109 GlobalSceneGraph().traverse(EntityFindTeams(classname, count, team));
110 globalOutputStream() << "UFO:AI: classname: " << classname << ": #" << (*count) << "\n";
114 * @brief Some default values to worldspawn like maxlevel, maxteams and so on
116 void assign_default_values_to_worldspawn (bool override, bool day, char **returnMsg)
118 static char message[1024];
124 worldspawn = Scene_FindEntityByClass("worldspawn");
127 globalOutputStream() << "UFO:AI: Could not find worldspawn.\n";
128 *returnMsg = "Could not find worldspawn";
135 get_team_count("info_player_start", &count, &teams);
137 // TODO: Get highest brush - a level has 64 units
138 worldspawn->setKeyValue("maxlevel", "5");
140 if (string_empty(worldspawn->getKeyValue("maxteams"))
141 || atoi(worldspawn->getKeyValue("maxteams")) != teams)
143 snprintf(str, sizeof(str) - 1, "%i", teams);
144 worldspawn->setKeyValue("maxteams", str);
145 strncat(message, "Worldspawn: Set maxteams to ", sizeof(message) - 1);
146 strncat(message, str, sizeof(message) - 1);
147 strncat(message, "\n", sizeof(message) - 1);
154 worldspawn->setKeyValue("light", "160");
155 worldspawn->setKeyValue("_color", "1 0.8 0.8");
156 worldspawn->setKeyValue("angles", "30 210");
157 worldspawn->setKeyValue("ambient", "0.4 0.4 0.4");
161 if (string_empty(worldspawn->getKeyValue("light")))
163 worldspawn->setKeyValue("light", "160");
164 snprintf(&message[strlen(message)], sizeof(message) - 1 - strlen(message), "Set ambient to: %s", worldspawn->getKeyValue("ambient"));
166 if (string_empty(worldspawn->getKeyValue("_color")))
168 worldspawn->setKeyValue("_color", "1 0.8 0.8");
169 snprintf(&message[strlen(message)], sizeof(message) - 1 - strlen(message), "Set ambient to: %s", worldspawn->getKeyValue("ambient"));
171 if (string_empty(worldspawn->getKeyValue("angles")))
173 worldspawn->setKeyValue("angles", "30 210");
174 snprintf(&message[strlen(message)], sizeof(message) - 1 - strlen(message), "Set ambient to: %s", worldspawn->getKeyValue("ambient"));
176 if (string_empty(worldspawn->getKeyValue("ambient")))
178 worldspawn->setKeyValue("ambient", "0.4 0.4 0.4");
179 snprintf(&message[strlen(message)], sizeof(message) - 1 - strlen(message), "Set ambient to: %s", worldspawn->getKeyValue("ambient"));
187 worldspawn->setKeyValue("light", "60");
188 worldspawn->setKeyValue("_color", "0.8 0.8 1");
189 worldspawn->setKeyValue("angles", "15 60");
190 worldspawn->setKeyValue("ambient", "0.25 0.25 0.275");
194 if (string_empty(worldspawn->getKeyValue("light")))
196 worldspawn->setKeyValue("light", "60");
197 snprintf(&message[strlen(message)], sizeof(message) - 1 - strlen(message), "Set ambient to: %s", worldspawn->getKeyValue("ambient"));
199 if (string_empty(worldspawn->getKeyValue("_color")))
201 worldspawn->setKeyValue("_color", "0.8 0.8 1");
202 snprintf(&message[strlen(message)], sizeof(message) - 1 - strlen(message), "Set ambient to: %s", worldspawn->getKeyValue("ambient"));
204 if (string_empty(worldspawn->getKeyValue("angles")))
206 worldspawn->setKeyValue("angles", "15 60");
207 snprintf(&message[strlen(message)], sizeof(message) - 1 - strlen(message), "Set ambient to: %s", worldspawn->getKeyValue("ambient"));
209 if (string_empty(worldspawn->getKeyValue("ambient")))
211 worldspawn->setKeyValue("ambient", "0.25 0.25 0.275");
212 snprintf(&message[strlen(message)], sizeof(message) - 1 - strlen(message), "Set ambient to: %s", worldspawn->getKeyValue("ambient"));
219 snprintf(&message[strlen(message)], sizeof(message) - 1 - strlen(message),
221 "Set _color to: %s\n"
222 "Set angles to: %s\n"
223 "Set ambient to: %s\n",
224 worldspawn->getKeyValue("light"),
225 worldspawn->getKeyValue("_color"),
226 worldspawn->getKeyValue("angles"),
227 worldspawn->getKeyValue("ambient")
231 // no errors - no warnings
232 if (!strlen(message))
235 *returnMsg = message;
239 * @brief Will check e.g. the map entities for valid values
240 * @todo: Check whether all misc_model and func_breakable have spawnflags
241 * @todo: check for maxlevel
243 void check_map_values (char **returnMsg)
245 static char message[1024];
251 worldspawn = Scene_FindEntityByClass("worldspawn");
254 globalOutputStream() << "UFO:AI: Could not find worldspawn.\n";
255 *returnMsg = "Could not find worldspawn";
262 // multiplayer start positions
263 get_team_count("info_player_start", &count, &teams);
265 strncat(message, "No multiplayer start positions (info_player_start)\n", sizeof(message) - 1);
266 else if (string_empty(worldspawn->getKeyValue("maxteams")))
268 snprintf(message, sizeof(message) - 1, "Worldspawn: No maxteams defined (#info_player_start) (set to: %i)\n", teams);
269 snprintf(str, sizeof(str) - 1, "%i", teams);
270 worldspawn->setKeyValue("maxteams", str);
272 else if (teams != atoi(worldspawn->getKeyValue("maxteams")))
273 snprintf(message, sizeof(message) - 1, "Worldspawn: Settings for maxteams (%s) doesn't match team count (%i)\n", worldspawn->getKeyValue("maxteams"), teams);
277 get_team_count("info_human_start", &count, NULL);
279 strncat(message, "No singleplayer start positions (info_human_start)\n", sizeof(message) - 1);
281 // search for civilians
283 get_team_count("info_civilian_start", &count, NULL);
285 strncat(message, "No civilian start positions (info_civilian_start)\n", sizeof(message) - 1);
288 if (string_empty(worldspawn->getKeyValue("maxlevel")))
289 strncat(message, "Worldspawn: No maxlevel defined\n", sizeof(message) - 1);
290 else if (atoi(worldspawn->getKeyValue("maxlevel")) > 8)
292 strncat(message, "Worldspawn: Highest maxlevel is 8\n", sizeof(message) - 1);
293 worldspawn->setKeyValue("maxlevel", "8");
295 // no errors - no warnings
296 if (!strlen(message))
299 *returnMsg = message;