This repository was archived by the owner on Jun 21, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproperties.h
More file actions
194 lines (162 loc) · 4.63 KB
/
Copy pathproperties.h
File metadata and controls
194 lines (162 loc) · 4.63 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
/////////////////////////////////////////////////////////////////////////////
// Name: properties.h
// Description: ...
// Author: Alexey Orlov (https://github.com/m110h)
// Last modification: 18/08/2020
// Licence: MIT licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _PROPERTIES_H_
#define _PROPERTIES_H_
#include <map>
#include <list>
#include <wx/string.h>
namespace ProtoPuddle
{
struct Property
{
Property() {}
Property(const Property& src) {
value = src.value;
min = src.min;
max = src.max;
}
Property(int _value, int _min, int _max): value(_value), min(_min), max(_max) {}
Property& operator=(const Property& r) {
if (this == &r) {
return *this;
}
value = r.value;
min = r.min;
max = r.max;
return *this;
}
int value {0};
int min {0};
int max {0};
};
class GlobalProperties
{
public:
GlobalProperties() {}
GlobalProperties(const GlobalProperties& src) {
_properties = src._properties;
}
~GlobalProperties()
{
_properties.clear();
}
GlobalProperties& operator=(const GlobalProperties& r) {
if (this == &r) {
return *this;
}
_properties = r._properties;
return *this;
}
void GetNamesAsList(std::list<wxString> *names)
{
for (auto it=_properties.begin(); it!=_properties.end(); ++it)
{
names->push_back(it->first);
}
}
bool IsExist(const wxString& name)
{
if (_properties.find(name) == _properties.end())
return false;
return true;
}
void SetProperty(const wxString& name, const Property& property)
{
if (IsExist(name))
{
_properties[name] = property;
}
else
{
_properties.insert( std::pair<wxString,Property>(name,property) );
}
}
bool CheckValue(const wxString& name, int value)
{
if (IsExist(name))
{
if (value >= _properties[name].min && value <= _properties[name].max)
{
return true;
}
}
return false;
}
void SetValue(const wxString& name, int value)
{
if (IsExist(name))
{
//_properties.erase(_properties.find(name));
if (value >= _properties[name].min && value <= _properties[name].max)
{
_properties[name].value = value;
}
}
}
int GetValue(const wxString& name)
{
if (IsExist(name))
{
return _properties[name].value;
}
return 0;
}
void SetRange(const wxString& name, int min, int max)
{
if (IsExist(name))
{
_properties[name].min = min;
_properties[name].max = max;
}
}
int GetMin(const wxString& name)
{
if (IsExist(name))
{
return _properties[name].min;
}
return 0;
}
int GetMax(const wxString& name)
{
if (IsExist(name))
{
return _properties[name].max;
}
return 0;
}
int GetQuantity()
{
return static_cast<int>(_properties.size());
}
private:
std::map<wxString,Property> _properties {
{ wxT("sortsOfCell"), Property(5,0,100) },
{ wxT("cellEnergy"), Property(100,1,1000) },
{ wxT("maxDamage"), Property(30,1,500) },
{ wxT("behaviorGenes"), Property(1,1,10) },
{ wxT("minEnergyForDivision"), Property(50,1,1000) },
{ wxT("maxEnergyForDivision"), Property(100,1,1000) },
{ wxT("plants"), Property(0,0,100) },
{ wxT("plantEnergy"), Property(30,1,500) },
{ wxT("meatEnergy"), Property(50,1,500) },
{ wxT("maxAge"), Property(300,1,1000) },
{ wxT("stepsPerSecond"), Property(5,1,60) },
{ wxT("plantsPerStep"), Property(2,0,100) },
{ wxT("worldWidth"), Property(20,4,80) },
{ wxT("worldHeight"), Property(20,4,80) },
{ wxT("plantLifeTime"), Property(20,1,1000) },
{ wxT("meatLifeTime"), Property(20,1,1000) },
{ wxT("movementEnergy"), Property(1,1,100) },
{ wxT("attackEnergy"), Property(2,1,100) },
{ wxT("attackCondition"), Property(10,1,500) },
{ wxT("maxMutationProbability"), Property(50,0,100) }
};
};
}
#endif