forked from themrdemonized/xray-monolith
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatrol_path_storage.cpp
More file actions
152 lines (117 loc) · 3.77 KB
/
patrol_path_storage.cpp
File metadata and controls
152 lines (117 loc) · 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
////////////////////////////////////////////////////////////////////////////
// Module : patrol_path_storage.cpp
// Created : 15.06.2004
// Modified : 15.06.2004
// Author : Dmitriy Iassenev
// Description : Patrol path storage
////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "patrol_path_storage.h"
#include "patrol_path.h"
#include "patrol_point.h"
#include "levelgamedef.h"
CPatrolPathStorage::~CPatrolPathStorage()
{
delete_data(m_registry);
}
void CPatrolPathStorage::load_raw(const CLevelGraph* level_graph, const CGameLevelCrossTable* cross, const CGameGraph* game_graph, IReader& stream)
{
IReader* chunk = stream.open_chunk(WAY_PATROLPATH_CHUNK);
if (!chunk)
return;
u32 chunk_iterator;
for (IReader* sub_chunk = chunk->open_chunk_iterator(chunk_iterator); sub_chunk; sub_chunk = chunk->open_chunk_iterator(chunk_iterator, sub_chunk))
{
R_ASSERT(sub_chunk->find_chunk(WAYOBJECT_CHUNK_VERSION));
R_ASSERT(sub_chunk->r_u16() == WAYOBJECT_VERSION);
R_ASSERT(sub_chunk->find_chunk(WAYOBJECT_CHUNK_NAME));
shared_str patrol_name;
sub_chunk->r_stringZ(patrol_name);
const_iterator I = m_registry.find(patrol_name);
VERIFY3(I == m_registry.end(), "Duplicated patrol path found", *patrol_name);
m_registry.insert(
std::make_pair(
patrol_name,
&xr_new<CPatrolPath>(patrol_name)->load_raw(level_graph, cross, game_graph, *sub_chunk)
)
);
}
chunk->close();
}
void CPatrolPathStorage::load(IReader& stream)
{
IReader* chunk;
chunk = stream.open_chunk(0);
u32 size = chunk->r_u32();
chunk->close();
m_registry.clear();
PATROL_REGISTRY::value_type pair;
chunk = stream.open_chunk(1);
for (u32 i = 0; i < size; ++i)
{
IReader* chunk1;
chunk1 = chunk->open_chunk(i);
IReader* chunk2;
chunk2 = chunk1->open_chunk(0);
load_data(pair.first, *chunk2);
chunk2->close();
chunk2 = chunk1->open_chunk(1);
load_data(pair.second, *chunk2);
chunk2->close();
chunk1->close();
const_iterator I = m_registry.find(pair.first);
VERIFY3(I == m_registry.end(), "Duplicated patrol path found ", *pair.first);
#ifdef DEBUG
pair.second->name(pair.first);
#endif
m_registry.insert(pair);
}
chunk->close();
}
void CPatrolPathStorage::load_from_config()
{
// Open patrol_paths.ltx
string_path fname;
FS.update_path(fname, "$game_config$", "patrol_paths.ltx");
CInifile* ini_paths = xr_new<CInifile>(fname, TRUE);
Msg("[ASHES] %s initialized", fname);
// Iterate sections. Each section is a unique patrol path
CInifile::Root& paths = ini_paths->sections();
for (CInifile::Root::iterator i = paths.begin(), ie = paths.end(); i != ie; ++i)
{
// Get patrol path name
LPCSTR patrol_name = (*i)->Name.c_str();
Msg("[ASHES] Reading section %s", patrol_name);
// Assert unique
const_iterator exists = m_registry.find(patrol_name);
R_ASSERT2(exists == m_registry.end(), "Duplicated patrol path found", patrol_name);
// Build CPatrolPath object
CPatrolPath* patrol_path = &xr_new<CPatrolPath>(patrol_name)->load_from_config(ini_paths, patrol_name);
// Insert in registry
PATROL_REGISTRY::value_type pair = std::make_pair(patrol_name, patrol_path);
m_registry.insert(pair);
}
Msg("[ASHES] Done reading patrol paths from configs");
xr_delete(ini_paths);
}
void CPatrolPathStorage::save(IWriter& stream)
{
stream.open_chunk(0);
stream.w_u32(m_registry.size());
stream.close_chunk();
stream.open_chunk(1);
PATROL_REGISTRY::iterator I = m_registry.begin();
PATROL_REGISTRY::iterator E = m_registry.end();
for (int i = 0; I != E; ++I, ++i)
{
stream.open_chunk(i);
stream.open_chunk(0);
save_data((*I).first, stream);
stream.close_chunk();
stream.open_chunk(1);
save_data((*I).second, stream);
stream.close_chunk();
stream.close_chunk();
}
stream.close_chunk();
}