Skip to content

Commit 7da3a99

Browse files
committed
WIP of xrAI and xrSE_Factory. Headers cleanup. Use range-based for.
1 parent ecb43e8 commit 7da3a99

File tree

7 files changed

+290
-434
lines changed

7 files changed

+290
-434
lines changed

src/utils/xrAI/game_spawn_constructor.cpp

Lines changed: 35 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@
88

99
#include "stdafx.h"
1010
#include "game_spawn_constructor.h"
11-
#include "Common/object_broker.h"
1211
#include "level_spawn_constructor.h"
1312
#include "xrServer_Objects_ALife_All.h"
14-
#include "xrai.h"
15-
#include "server_entity_wrapper.h"
1613
#include "xrAICore/Navigation/graph_engine.h"
1714
#include "xrAICore/Navigation/PatrolPath/patrol_path_storage.h"
15+
#include "xrAI.h"
1816

1917
extern LPCSTR GAME_CONFIG;
2018
extern LPCSTR generate_temp_file_name(LPCSTR header0, LPCSTR header1, string_path& buffer);
@@ -82,40 +80,32 @@ void CGameSpawnConstructor::load_spawns(LPCSTR name, bool no_separator_check)
8280

8381
// load levels
8482
GameGraph::SLevel level;
85-
auto I = m_levels.begin();
86-
auto E = m_levels.end();
87-
for (; I != E; ++I)
83+
for (const auto &i : m_levels)
8884
{
89-
level.m_offset = (*I).m_offset;
90-
level.m_name = (*I).m_name;
91-
level.m_id = (*I).m_id;
92-
Msg("%9s %2d %s", "level", level.id(), *(*I).m_name);
85+
level.m_offset = i.m_offset;
86+
level.m_name = i.m_name;
87+
level.m_id = i.m_id;
88+
Msg("%9s %2d %s", "level", level.id(), *i.m_name);
9389
m_level_spawns.push_back(new CLevelSpawnConstructor(level, this, no_separator_check));
9490
}
9591

9692
string256 temp;
97-
xr_sprintf(temp,
98-
"There are no valid levels (with AI-map and graph) in the section 'levels' in the '%s' to build spawn file "
99-
"from!",
100-
GAME_CONFIG);
93+
xr_sprintf(temp, "There are no valid levels (with AI-map and graph) in the section 'levels' in the '%s' to build spawn file from!", GAME_CONFIG);
10194
R_ASSERT2(!m_level_spawns.empty(), temp);
10295
}
10396

10497
void CGameSpawnConstructor::process_spawns()
10598
{
106-
auto I = m_level_spawns.begin();
107-
auto E = m_level_spawns.end();
108-
for (; I != E; ++I)
99+
for (auto &i: m_level_spawns)
109100
#ifdef NO_MULTITHREADING
110-
(*I)->Execute();
101+
i->Execute();
111102
#else
112-
m_thread_manager.start(*I);
103+
m_thread_manager.start(i);
113104
m_thread_manager.wait();
114105
#endif
115106

116-
I = m_level_spawns.begin();
117-
for (; I != E; ++I)
118-
(*I)->update();
107+
for (auto &i : m_level_spawns)
108+
i->update();
119109

120110
verify_level_changers();
121111
verify_spawns();
@@ -129,20 +119,16 @@ void CGameSpawnConstructor::verify_spawns(ALife::_SPAWN_ID spawn_id)
129119
m_temp0.push_back(spawn_id);
130120

131121
auto vertex = m_spawn_graph->vertex(spawn_id);
132-
auto I = vertex->edges().begin();
133-
auto E = vertex->edges().end();
134-
for (; I != E; ++I)
135-
verify_spawns((*I).vertex_id());
122+
for (const auto &i : vertex->edges())
123+
verify_spawns(i.vertex_id());
136124
}
137125

138126
void CGameSpawnConstructor::verify_spawns()
139127
{
140-
SPAWN_GRAPH::const_vertex_iterator I = m_spawn_graph->vertices().begin();
141-
SPAWN_GRAPH::const_vertex_iterator E = m_spawn_graph->vertices().end();
142-
for (; I != E; ++I)
128+
for (const auto &i : m_spawn_graph->vertices())
143129
{
144130
m_temp0.clear();
145-
verify_spawns((*I).second->vertex_id());
131+
verify_spawns(i.second->vertex_id());
146132
}
147133
}
148134

@@ -152,10 +138,9 @@ void CGameSpawnConstructor::verify_level_changers()
152138
return;
153139

154140
Msg("List of the level changers which are invalid for some reasons");
155-
LEVEL_CHANGER_STORAGE::const_iterator I = m_level_changers.begin();
156-
LEVEL_CHANGER_STORAGE::const_iterator E = m_level_changers.end();
157-
for (; I != E; ++I)
158-
Msg("%s", (*I)->name_replace());
141+
142+
for (const auto &i : m_level_changers)
143+
Msg("%s", i->name_replace());
159144

160145
VERIFY2(m_level_changers.empty(), "Some of the level changers setup incorrectly");
161146
}
@@ -222,8 +207,7 @@ void CGameSpawnConstructor::add_story_object(ALife::_STORY_ID id, CSE_ALifeDynam
222207
{
223208
Msg("Object %s, story id %d", object->name_replace(), object->m_story_id);
224209
Msg("Object %s, story id %d", (*I).second->name_replace(), (*I).second->m_story_id);
225-
VERIFY3(I == m_story_objects.end(), "There are several objects which has the same unique story ID, level ",
226-
level_name);
210+
VERIFY3(I == m_story_objects.end(), "There are several objects which has the same unique story ID, level ", level_name);
227211
}
228212

229213
m_story_objects.insert(std::make_pair(id, object));
@@ -242,17 +226,14 @@ void CGameSpawnConstructor::process_actor(LPCSTR start_level_name)
242226
{
243227
m_actor = nullptr;
244228

245-
auto I = m_level_spawns.begin();
246-
auto E = m_level_spawns.end();
247-
for (; I != E; ++I)
229+
for (const auto &i : m_level_spawns)
248230
{
249-
if (!(*I)->actor())
231+
if (!i->actor())
250232
continue;
251233

252-
Msg("Actor is on the level %s",
253-
*game_graph().header().level(game_graph().vertex((*I)->actor()->m_tGraphID)->level_id()).name());
234+
Msg("Actor is on the level %s", *game_graph().header().level(game_graph().vertex(i->actor()->m_tGraphID)->level_id()).name());
254235
VERIFY2(!m_actor, "There must be the SINGLE level with ACTOR!");
255-
m_actor = (*I)->actor();
236+
m_actor = i->actor();
256237
}
257238

258239
R_ASSERT2(m_actor, "There is no ACTOR spawn point!");
@@ -307,30 +288,32 @@ void clear_temp_folder()
307288
{
308289
string_path query;
309290
FS.update_path(query, "$app_data_root$", "temp\\*.*");
291+
string_path path_root;
292+
FS.update_path(path_root, "$app_data_root$", "temp\\");
293+
string_path path_final;
294+
310295
_finddata_t file;
311296
auto handle = _findfirst(query, &file);
312297
if (handle == intptr_t(-1))
313298
return;
314299

315-
typedef xr_vector<shared_str> FILES;
316-
FILES files;
300+
xr_vector<shared_str> files;
317301
do
318302
{
319303
if (file.attrib & _A_SUBDIR)
320304
continue;
321305

322-
files.push_back(file.name);
306+
strconcat(sizeof(path_final), path_final, path_root, file.name);
307+
files.push_back(path_final);
323308
} while (!_findnext(handle, &file));
324309

325310
_findclose(handle);
326311

327-
FILES::const_iterator I = files.begin();
328-
FILES::const_iterator E = files.end();
329-
for (; I != E; ++I)
312+
for (const auto &i : files)
330313
{
331-
if (DeleteFile(**I))
332-
Msg("file %s is successfully deleted", **I);
314+
if (DeleteFile(*i))
315+
Msg("file %s is successfully deleted", *i);
333316
else
334-
Msg("cannot delete file %s", **I);
317+
Msg("cannot delete file %s", *i);
335318
}
336319
}

0 commit comments

Comments
 (0)