forked from HaloMods/SparkEdit
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Encounters.cpp
170 lines (131 loc) · 4.24 KB
/
Encounters.cpp
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// Encounters.cpp: implementation of the CEncounters class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "sparkedit.h"
#include "Encounters.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CEncounters::CEncounters()
{
m_pEncounters = NULL;
m_pEncounterInfo = NULL;
m_ActiveEncounter = 0;
m_ActiveSquad = 0;
m_Magic = 0;
m_Version = 0;
m_pMapFile = NULL;
m_EncounterCount = 0;
}
CEncounters::~CEncounters()
{
Cleanup();
}
void CEncounters::Initialize(CFile *pMapFile, int magic, UINT version)
{
m_pMapFile = pMapFile;
m_Magic = magic;
m_Version = version;
}
void CEncounters::Cleanup()
{
for(int i=0; i<m_EncounterCount; i++)
{
for(int j=0; j<m_pEncounters[i].Squads.Count; j++)
{
delete [] m_pEncounterInfo[i].ppSquadSpawns[j];
}
delete [] m_pEncounterInfo[i].ppSquadSpawns;
delete [] m_pEncounterInfo[i].pSquads;
}
if(m_pEncounters)
delete [] m_pEncounters;
m_pEncounters = NULL;
if(m_pEncounterInfo)
delete [] m_pEncounterInfo;
m_pEncounterInfo = NULL;
m_ActiveEncounter = 0;
m_ActiveSquad = 0;
m_EncounterCount = 0;
m_Magic = 0;
m_Version = 0;
m_pMapFile = NULL;
}
void CEncounters::LoadEncounters(REFLEXIVE EncInfo)
{
int i, j;
ENC_SQUAD *pSquad;
if(EncInfo.Count > 0)
{
m_EncounterCount = EncInfo.Count;
m_pEncounters = new ENCOUNTER[EncInfo.Count];
m_pEncounterInfo= new ENCOUNTER_INFO[EncInfo.Count];
m_pMapFile->Seek(EncInfo.Offset, 0);
m_pMapFile->Read(m_pEncounters, sizeof(ENCOUNTER)*EncInfo.Count);
ZeroMemory(m_pEncounterInfo, sizeof(ENCOUNTER_INFO)*EncInfo.Count);
for(i=0; i<EncInfo.Count; i++)
{
//Load Squads
if(m_pEncounters[i].Squads.Count > 0)
{
m_pEncounters[i].Squads.Offset -= m_Magic;
m_pEncounterInfo[i].pSquads = new ENC_SQUAD[m_pEncounters[i].Squads.Count];
m_pEncounterInfo[i].ppSquadSpawns = new ENC_SQUAD_SPAWN*[m_pEncounters[i].Squads.Count];
ZeroMemory(m_pEncounterInfo[i].ppSquadSpawns, m_pEncounters[i].Squads.Count*sizeof(ENC_SQUAD_SPAWN*));
m_pMapFile->Seek(m_pEncounters[i].Squads.Offset, 0);
m_pMapFile->Read(m_pEncounterInfo[i].pSquads, sizeof(ENC_SQUAD)*m_pEncounters[i].Squads.Count);
for(j=0; j<m_pEncounters[i].Squads.Count; j++)
{
pSquad = &m_pEncounterInfo[i].pSquads[j];
if(pSquad->StartLocations.Count > 0)
{
pSquad->StartLocations.Offset -= m_Magic;
m_pEncounterInfo[i].ppSquadSpawns[j] = new ENC_SQUAD_SPAWN[pSquad->StartLocations.Count];
m_pMapFile->Seek(pSquad->StartLocations.Offset, 0);
m_pMapFile->Read(m_pEncounterInfo[i].ppSquadSpawns[j], sizeof(ENC_SQUAD_SPAWN)*pSquad->StartLocations.Count);
}
}
}
if(m_pEncounters[i].Platoons.Count > 0)
m_pEncounters[i].Platoons.Offset -= m_Magic;
if(m_pEncounters[i].FiringPositions.Count > 0)
m_pEncounters[i].FiringPositions.Offset -= m_Magic;
if(m_pEncounters[i].PlayerStartLocations.Count > 0)
m_pEncounters[i].PlayerStartLocations.Offset -= m_Magic;
}
}
// AnalyzeFileSection(m_pMapFile, m_Header.Encounters.Offset,
// (m_Header.Squads.Offset - m_Header.Encounters.Offset), m_Magic);
}
void CEncounters::ActivateSquad(int encounter, int squad)
{
m_ActiveEncounter = encounter;
m_ActiveSquad = squad;
}
int CEncounters::GetEncounterCount()
{
return(m_EncounterCount);
}
int CEncounters::GetSquadCount(int EncounterIndex)
{
int squad_count = 0;
if(EncounterIndex < m_EncounterCount)
squad_count = m_pEncounters[EncounterIndex].Squads.Count;
return(squad_count);
}
void CEncounters::GetSquadSpawnCoord(int index, float *pCoord)
{
memcpy(pCoord, &m_pEncounterInfo[m_ActiveEncounter].ppSquadSpawns[m_ActiveSquad][index].x, 16);
}
int CEncounters::GetSquadSpawnCount(int encounter, int squad)
{
int spawn_count = 0;
spawn_count = m_pEncounterInfo[encounter].pSquads[squad].StartLocations.Count;
return(spawn_count);
}