aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/GameRules.cpp
blob: 0e5945207eded789632c33d01916edee1d36a3de (plain)
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
#include "stdafx.h"

#include "GameRules.h"

// 4J: GameRules isn't in use anymore, just routes any requests to app game host options, kept things commented out for context

const int GameRules::RULE_DOFIRETICK = 0;
const int GameRules::RULE_MOBGRIEFING = 1;
const int GameRules::RULE_KEEPINVENTORY = 2;
const int GameRules::RULE_DOMOBSPAWNING = 3;
const int GameRules::RULE_DOMOBLOOT = 4;
const int GameRules::RULE_DOTILEDROPS = 5;
//const int GameRules::RULE_COMMANDBLOCKOUTPUT = 6;
const int GameRules::RULE_NATURAL_REGENERATION = 7;
const int GameRules::RULE_DAYLIGHT = 8;

GameRules::GameRules()
{
	/*registerRule(RULE_DOFIRETICK, L"1");
	registerRule(RULE_MOBGRIEFING, L"1");
	registerRule(RULE_KEEPINVENTORY, L"0");
	registerRule(RULE_DOMOBSPAWNING, L"1");
	registerRule(RULE_DOMOBLOOT, L"1");
	registerRule(RULE_DOTILEDROPS, L"1");
	registerRule(RULE_COMMANDBLOCKOUTPUT, L"1");
	registerRule(RULE_NATURAL_REGENERATION, L"1");
	registerRule(RULE_DAYLIGHT, L"1");*/
}

GameRules::~GameRules()
{
	/*for(AUTO_VAR(it,rules.begin()); it != rules.end(); ++it)
	{
		delete it->second;
	}*/
}

bool GameRules::getBoolean(const int rule)
{
	switch(rule)
	{
	case GameRules::RULE_DOFIRETICK:
		return app.GetGameHostOption(eGameHostOption_FireSpreads);
	case GameRules::RULE_MOBGRIEFING:
		return app.GetGameHostOption(eGameHostOption_MobGriefing);
	case GameRules::RULE_KEEPINVENTORY:
		return app.GetGameHostOption(eGameHostOption_KeepInventory);
	case GameRules::RULE_DOMOBSPAWNING:
		return app.GetGameHostOption(eGameHostOption_DoMobSpawning);
	case GameRules::RULE_DOMOBLOOT:
		return app.GetGameHostOption(eGameHostOption_DoMobLoot);
	case GameRules::RULE_DOTILEDROPS:
		return app.GetGameHostOption(eGameHostOption_DoTileDrops);
	case GameRules::RULE_NATURAL_REGENERATION:
		return app.GetGameHostOption(eGameHostOption_NaturalRegeneration);
	case GameRules::RULE_DAYLIGHT:
		return app.GetGameHostOption(eGameHostOption_DoDaylightCycle);
	default:
		assert(0);
		return false;
	}
}

/*
void GameRules::registerRule(const wstring &name, const wstring &startValue)
{
	rules[name] = new GameRule(startValue);
}

void GameRules::set(const wstring &ruleName, const wstring &newValue)
{
	AUTO_VAR(it, rules.find(ruleName));
	if(it != rules.end() )
	{
		GameRule *gameRule = it->second;
		gameRule->set(newValue);
	}
	else
	{
		registerRule(ruleName, newValue);
	}
}

wstring GameRules::get(const wstring &ruleName)
{
	AUTO_VAR(it, rules.find(ruleName));
	if(it != rules.end() )
	{
		GameRule *gameRule = it->second;
		return gameRule->get();
	}
	return L"";
}

int GameRules::getInt(const wstring &ruleName)
{
	AUTO_VAR(it, rules.find(ruleName));
	if(it != rules.end() )
	{
		GameRule *gameRule = it->second;
		return gameRule->getInt();
	}
	return 0;
}

double GameRules::getDouble(const wstring &ruleName)
{
	AUTO_VAR(it, rules.find(ruleName));
	if(it != rules.end() )
	{
		GameRule *gameRule = it->second;
		return gameRule->getDouble();
	}
	return 0;
}

CompoundTag *GameRules::createTag()
{
	CompoundTag *result = new CompoundTag(L"GameRules");

	for(AUTO_VAR(it,rules.begin()); it != rules.end(); ++it)
	{
		GameRule *gameRule = it->second;
		result->putString(it->first, gameRule->get());
	}

	return result;
}

void GameRules::loadFromTag(CompoundTag *tag)
{
	vector<Tag *> *allTags = tag->getAllTags();
	for (AUTO_VAR(it, allTags->begin()); it != allTags->end(); ++it)
	{
		Tag *ruleTag = *it;
		wstring ruleName = ruleTag->getName();
		wstring value = tag->getString(ruleTag->getName());

		set(ruleName, value);
	}
	delete allTags;
}

// Need to delete returned vector.
vector<wstring> *GameRules::getRuleNames()
{
	vector<wstring> *out = new vector<wstring>();
	for (AUTO_VAR(it, rules.begin()); it != rules.end(); it++) out->push_back(it->first);
	return out;
}

bool GameRules::contains(const wstring &rule)
{
	AUTO_VAR(it, rules.find(rule));
	return it != rules.end();
}

GameRules::GameRule::GameRule(const wstring &startValue)
{
	value = L"";
	booleanValue = false;
	intValue = 0;
	doubleValue = 0.0;
	set(startValue);
}

void GameRules::GameRule::set(const wstring &newValue)
{
	value = newValue;
	booleanValue = _fromString<bool>(newValue);
	intValue = _fromString<int>(newValue);
	doubleValue = _fromString<double>(newValue);
}

wstring GameRules::GameRule::get()
{
	return value;
}

bool GameRules::GameRule::getBoolean()
{
	return booleanValue;
}

int GameRules::GameRule::getInt()
{
	return intValue;
}

double GameRules::GameRule::getDouble()
{
	return doubleValue;
}*/