forked from OpenXcom/OpenXcom
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapBlock.cpp
More file actions
158 lines (143 loc) · 3.24 KB
/
Copy pathMapBlock.cpp
File metadata and controls
158 lines (143 loc) · 3.24 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
/*
* Copyright 2010-2013 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 "MapBlock.h"
namespace OpenXcom
{
/**
* MapBlock construction.
*/
MapBlock::MapBlock(RuleTerrain *terrain, std::string name, int size_x, int size_y, MapBlockType type):_terrain(terrain), _name(name), _size_x(size_x), _size_y(size_y), _size_z(0), _type(type), _subType(MT_UNDEFINED), _frequency(1), _timesUsed(0), _maxCount(-1)
{
}
/**
* MapBlock desctruction.
*/
MapBlock::~MapBlock()
{
}
/**
* Loads the map block from a YAML file.
* @param node YAML node.
*/
void MapBlock::load(const YAML::Node &node)
{
_name = node["name"].as<std::string>(_name);
_size_x = node["width"].as<int>(_size_x);
_size_y = node["length"].as<int>(_size_y);
_size_z = node["height"].as<int>(_size_z);
_type = (MapBlockType)node["type"].as<int>(_type);
if (_subType == MT_UNDEFINED)
_subType = (MapBlockType)node["type"].as<int>(_type);
_subType = (MapBlockType)node["subType"].as<int>(_subType);
_frequency = node["frequency"].as<int>(_frequency);
_maxCount = node["maxCount"].as<int>(_maxCount);
}
/**
* Gets the MapBlock name (string).
* @return The name.
*/
std::string MapBlock::getName() const
{
return _name;
}
/**
* Gets the MapBlock size x.
* @return The size x in tiles.
*/
int MapBlock::getSizeX() const
{
return _size_x;
}
/**
* Gets the MapBlock size y.
* @return The size y in tiles.
*/
int MapBlock::getSizeY() const
{
return _size_y;
}
/**
* Sets the MapBlock size z.
* @param size_z The size z.
*/
void MapBlock::setSizeZ(int size_z)
{
_size_z = size_z;
}
/**
* Gets the MapBlock size z.
* @return The size z.
*/
int MapBlock::getSizeZ() const
{
return _size_z;
}
/**
* Gets the type of mapblock.
* @return The mapblock's type.
*/
MapBlockType MapBlock::getType() const
{
return _type;
}
/**
* Gets the secondary type of the mapblock, if the primary type is occupied.
* @return The mapblock's secondary type.
*/
MapBlockType MapBlock::getSubType() const
{
return _subType;
}
/**
* Gets either the remaining uses of the mapblock OR THE FREQUENCY!
* Remaining limits the number of times a mapblock occurs.
* Frequency increases the odds of a mapblock occuring.
* @return int
*/
int MapBlock::getRemainingUses()
{
if (_maxCount == -1)
{
return _frequency;
}
return _maxCount - _timesUsed;
}
/**
* Decreases the remaining uses of a mapblock for this session.
*/
void MapBlock::markUsed()
{
if (_maxCount == -1)
{
return;
}
_timesUsed++;
if (_timesUsed >= _maxCount)
{
_timesUsed = _maxCount;
}
}
/**
* Resets the remaining uses of a mapblock for this session.
*/
void MapBlock::reset()
{
_timesUsed = 0;
}
}