-
Notifications
You must be signed in to change notification settings - Fork 0
/
schoolupgrade.h
143 lines (135 loc) · 4.64 KB
/
schoolupgrade.h
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
#ifndef SCHOOLUPGRADE_H
#define SCHOOLUPGRADE_H
#include "json_macros.h"
#include "locationpropertychange.h"
#include "rulechange.h"
#include "location.h"
class SchoolUpgradeLevel {
QList<QString> ActivateRules;
QList<RuleChange> ChangeRuleList;
public:
QString Name;
QString Description;
QString ImagePath;
QString NewLocationName;
QString NewLocationImageFolder;
QString NewLocationDescription;
LocationPropertyChange PropertyChange;
bool CanBeChosen;
int Cost;
int MaintenanceCost;
SchoolUpgradeLevel(QJsonObject *d = NULL)
{
if (d) init(d);
}
void init(QJsonObject *d)
{
for (QJsonObject::iterator it = d->begin(); it != d->end(); ++it) {
__IF_VAR_FROM_JSON_AS(it, Name, toString)
else __IF_VAR_FROM_JSON_AS(it, Description, toString)
else __IF_VAR_FROM_JSON_AS(it, ImagePath, toString)
else __IF_VAR_FROM_JSON_AS(it, NewLocationName, toString)
else __IF_VAR_FROM_JSON_AS(it, NewLocationImageFolder, toString)
else __IF_VAR_FROM_JSON_AS(it, NewLocationDescription, toString)
//LocationPropertyChange PropertyChange
else __IF_VAR_FROM_JSON_AS(it, CanBeChosen, toBool)
else __IF_VAR_FROM_JSON_AS(it, Cost, toInt)
else __IF_VAR_FROM_JSON_AS(it, MaintenanceCost, toInt)
QList<QString> ActivateRules;
//QList<RuleChange> ChangeRuleList
}
}
};
class SchoolUpgrade {
QList<SchoolUpgradeLevel> ListUpgradeLevels;
static size_t schoolupgradeCounter;
size_t thisSchoolUpgradeNr;
public:
QString Name;
QString LocationName;
int CurrentLevel;
/*const Location get_Location() const
{
return Game.GetLocation(LocationName);
}*/
void set_Location(Location* v = NULL)
{
LocationName = v ? v->Name : "";
}
SchoolUpgradeLevel const*const get_CurrentLevelObject() const
{
if (CurrentLevel > -1 && CurrentLevel < ListUpgradeLevels.count())
return &ListUpgradeLevels[CurrentLevel];
return NULL;
}
SchoolUpgradeLevel const*const get_NextLevelObject() const
{
int next = CurrentLevel + 1;
if (next > -1 && next < ListUpgradeLevels.count() && ListUpgradeLevels[next].CanBeChosen)
return &ListUpgradeLevels[next];
return NULL;
}
const QString get_DisplayName() const
{
SchoolUpgradeLevel const*const clo = get_CurrentLevelObject();
SchoolUpgradeLevel const*const nlo = get_NextLevelObject();
if (clo == NULL)
return nlo ? "Purchase " + nlo->Name : "Nothing;";
if (nlo == NULL)
return clo->Name;
return "Upgrade " + clo->Name + " to " + nlo->Name;
}
const QString get_CurrentName() const
{
SchoolUpgradeLevel const*const clo = get_CurrentLevelObject();
return clo ? clo->Name : "Nothing";
}
const QString get_UpgradeName() const
{
SchoolUpgradeLevel const*const nlo = get_NextLevelObject();
return nlo ? nlo->Name : "No upgrade available";
}
const QString get_Description() const
{
SchoolUpgradeLevel const*const clo = get_CurrentLevelObject();
return clo ? clo->Description : "";
}
const QString get_UpgradeDescription() const
{
SchoolUpgradeLevel const*const nlo = get_NextLevelObject();
return nlo ? nlo->Description : "";
}
const int get_MaintenanceCost() const
{
SchoolUpgradeLevel const*const clo = get_CurrentLevelObject();
return clo ? clo->MaintenanceCost : 0;
}
const int get_UpgradeCost() const
{
SchoolUpgradeLevel const*const nlo = get_NextLevelObject();
return nlo ? nlo->Cost : -1;
}
SchoolUpgrade(QJsonObject *d = NULL) : thisSchoolUpgradeNr(schoolupgradeCounter++)
{
if (d) init(d);
}
void init(QJsonObject *d)
{
for (QJsonObject::iterator it = d->begin(); it != d->end(); ++it) {
__IF_VAR_FROM_JSON_AS(it, Name, toString)
else __IF_VAR_FROM_JSON_AS(it, LocationName, toString)
else __IF_VAR_FROM_JSON_AS(it, CurrentLevel, toInt)
//QList<SchoolUpgradeLevel> ListUpgradeLevels
}
}
size_t get_thisSchoolUpgradeNr() const {
return thisSchoolUpgradeNr;
}
};
inline size_t qHash(const SchoolUpgrade &su) {
return su.get_thisSchoolUpgradeNr();
}
inline bool operator==(const SchoolUpgrade su1, const SchoolUpgrade su2){
return su1.get_thisSchoolUpgradeNr() == su2.get_thisSchoolUpgradeNr();
}
#endif // SCHOOLUPGRADE_H