Repository navigation
Expand file tree
/
Copy pathSavedGame.cpp
More file actions
222 lines (202 loc) · 4.59 KB
/
Copy pathSavedGame.cpp
File metadata and controls
222 lines (202 loc) · 4.59 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*
* Copyright 2010 OpenXcom Developers.
*
* This file is part of OpenXcom.
*
* OpenXcom 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 3 of the License, or
* (at your option) any later version.
*
* OpenXcom 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 OpenXcom. If not, see <http://www.gnu.org/licenses/>.
*/
#include "SavedGame.h"
#include "../Engine/RNG.h"
#include "GameTime.h"
#include "Country.h"
#include "Base.h"
#include "Region.h"
#include "Ufo.h"
#include "Waypoint.h"
namespace OpenXcom
{
/**
* Initializes a brand new saved game according to the specified difficulty.
* @param diff Game difficulty.
*/
SavedGame::SavedGame(GameDifficulty diff) : _diff(diff), _funds(0), _countries(), _regions(), _bases(), _ufos(), _craftId(), _waypoints(), _ufoId(1), _waypointId(1)
{
_time = new GameTime(6, 1, 1, 1999, 12, 0, 0);
RNG::init();
}
/**
* Deletes the game content from memory.
*/
SavedGame::~SavedGame()
{
for (std::map<std::string, Country*>::iterator i = _countries.begin(); i != _countries.end(); i++)
{
delete i->second;
}
for (std::map<std::string, Region*>::iterator i = _regions.begin(); i != _regions.end(); i++)
{
delete i->second;
}
for (std::vector<Base*>::iterator i = _bases.begin(); i != _bases.end(); i++)
{
delete *i;
}
for (std::vector<Ufo*>::iterator i = _ufos.begin(); i != _ufos.end(); i++)
{
delete *i;
}
for (std::vector<Waypoint*>::iterator i = _waypoints.begin(); i != _waypoints.end(); i++)
{
delete *i;
}
}
/**
* Returns the player's current funds.
* @return Current funds.
*/
int SavedGame::getFunds() const
{
return _funds;
}
/**
* Changes the player's funds to a new value.
* @param funds New funds.
*/
void SavedGame::setFunds(int funds)
{
_funds = funds;
}
/**
* Gives the player his monthly funds, taking in account
* all maintenance and profit costs.
*/
void SavedGame::monthlyFunding()
{
_funds += getCountryFunding() - getBaseMaintenance();
}
/**
* Returns the current time of the game.
* @return Pointer to the game time.
*/
GameTime *const SavedGame::getTime() const
{
return _time;
}
/**
* Returns the list of countries in the game world.
* @return Pointer to country list.
*/
std::map<std::string, Country*> *const SavedGame::getCountries()
{
return &_countries;
}
/**
* Adds up the monthly funding of all the countries.
* @return Total funding.
*/
int SavedGame::getCountryFunding() const
{
int total = 0;
for (std::map<std::string, Country*>::const_iterator i = _countries.begin(); i != _countries.end(); i++)
{
total += i->second->getFunding();
}
return total;
}
/**
* Returns the list of world regions.
* @return Pointer to region list.
*/
std::map<std::string, Region*> *const SavedGame::getRegions()
{
return &_regions;
}
/**
* Returns the list of player bases.
* @return Pointer to base list.
*/
std::vector<Base*> *const SavedGame::getBases()
{
return &_bases;
}
/**
* Adds up the monthly maintenance of all the bases.
* @return Total maintenance.
*/
int SavedGame::getBaseMaintenance() const
{
int total = 0;
for (std::vector<Base*>::const_iterator i = _bases.begin(); i != _bases.end(); i++)
{
total += (*i)->getMonthlyMaintenace();
}
return total;
}
/**
* Returns the latest craft IDs for each type.
* @return Pointer to ID list.
*/
std::map<std::string, int> *const SavedGame::getCraftIds()
{
return &_craftId;
}
/**
* Returns the list of alien UFOs.
* @return Pointer to UFO list.
*/
std::vector<Ufo*> *const SavedGame::getUfos()
{
return &_ufos;
}
/**
* Returns the latest ufo ID.
* @return Pointer to ID value.
*/
int *const SavedGame::getUfoId()
{
return &_ufoId;
}
/**
* Returns the latest waypoint ID.
* @return Pointer to ID value.
*/
int *const SavedGame::getWaypointId()
{
return &_waypointId;
}
/**
* Returns the list of craft waypoints.
* @return Pointer to waypoint list.
*/
std::vector<Waypoint*> *const SavedGame::getWaypoints()
{
return &_waypoints;
}
/**
* Set battlegame object.
* @param battlegame Pointer to the battlegame object.
*/
void SavedGame::setBattleGame(SavedBattleGame *battlegame)
{
_battlegame = battlegame;
}
/**
* Get pointer to the battlegame object.
* @return Pointer to the battlegame object.
*/
SavedBattleGame *SavedGame::getBattleGame()
{
return _battlegame;
}
}