aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/Common/GameRules/GameRuleDefinition.cpp
blob: b63687c22ddefbe8763d2e9db0a12279d901c8d6 (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
#include "stdafx.h"
#include "..\..\WstringLookup.h"
#include "..\..\..\Minecraft.World\StringHelpers.h"
#include "ConsoleGameRules.h"

GameRuleDefinition::GameRuleDefinition()
{
	m_descriptionId = L"";
	m_promptId = L"";
	m_4JDataValue = 0;
}

void GameRuleDefinition::write(DataOutputStream *dos)
{
	// Write EGameRuleType.
	ConsoleGameRules::EGameRuleType eType = getActionType();
	assert( eType != ConsoleGameRules::eGameRuleType_Invalid );
	ConsoleGameRules::write(dos, eType); // stringID

	writeAttributes(dos, 0);
	
	// 4J-JEV: Get children.
	vector<GameRuleDefinition *> *children = new vector<GameRuleDefinition *>();
	getChildren( children );

	// Write children.
	dos->writeInt( children->size() );
	for (AUTO_VAR(it, children->begin()); it != children->end(); it++)
		(*it)->write(dos);
}

void GameRuleDefinition::writeAttributes(DataOutputStream *dos, UINT numAttributes)
{
	dos->writeInt(numAttributes + 3);

	ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_descriptionName);
	dos->writeUTF(m_descriptionId);

	ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_promptName);
	dos->writeUTF(m_promptId);

	ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_dataTag);
	dos->writeUTF(_toString(m_4JDataValue));
}

void GameRuleDefinition::getChildren(vector<GameRuleDefinition *> *children) {}

GameRuleDefinition *GameRuleDefinition::addChild(ConsoleGameRules::EGameRuleType ruleType)
{
#ifndef _CONTENT_PACKAGE
		wprintf(L"GameRuleDefinition: Attempted to add invalid child rule - %d\n", ruleType );
#endif
	return NULL;
}

void GameRuleDefinition::addAttribute(const wstring &attributeName, const wstring &attributeValue)
{
	if(attributeName.compare(L"descriptionName") == 0)
	{
		m_descriptionId = attributeValue;
#ifndef _CONTENT_PACKAGE
		wprintf(L"GameRuleDefinition: Adding parameter descriptionId=%ls\n",m_descriptionId.c_str());
#endif
	}
	else if(attributeName.compare(L"promptName") == 0)
	{
		m_promptId = attributeValue;
#ifndef _CONTENT_PACKAGE
		wprintf(L"GameRuleDefinition: Adding parameter m_promptId=%ls\n",m_promptId.c_str());
#endif
	}
	else if(attributeName.compare(L"dataTag") == 0)
	{
		m_4JDataValue = _fromString<int>(attributeValue);
		app.DebugPrintf("GameRuleDefinition: Adding parameter m_4JDataValue=%d\n",m_4JDataValue);
	}
	else
	{
#ifndef _CONTENT_PACKAGE
		wprintf(L"GameRuleDefinition: Attempted to add invalid attribute: %ls\n", attributeName.c_str());
#endif
	}
}

void GameRuleDefinition::populateGameRule(GameRulesInstance::EGameRulesInstanceType type, GameRule *rule)
{
	GameRule::ValueType value;
	value.b = false;
	rule->setParameter(L"bComplete",value);
}

bool GameRuleDefinition::getComplete(GameRule *rule)
{
	GameRule::ValueType value;
	value = rule->getParameter(L"bComplete");
	return value.b;
}

void GameRuleDefinition::setComplete(GameRule *rule, bool val)
{
	GameRule::ValueType value;
	value = rule->getParameter(L"bComplete");
	value.b = val;
	rule->setParameter(L"bComplete",value);
}

vector<GameRuleDefinition *> *GameRuleDefinition::enumerate()
{
	// Get Vector.
	vector<GameRuleDefinition *> *gRules;
	gRules = new vector<GameRuleDefinition *>();
	gRules->push_back(this);
	getChildren(gRules);
	return gRules;
}

unordered_map<GameRuleDefinition *, int> *GameRuleDefinition::enumerateMap()
{
	unordered_map<GameRuleDefinition *, int> *out 
		= new unordered_map<GameRuleDefinition *, int>();

	int i = 0;
	vector<GameRuleDefinition *> *gRules = enumerate();
	for (AUTO_VAR(it, gRules->begin()); it != gRules->end(); it++)
		out->insert( pair<GameRuleDefinition *, int>( *it, i++ ) );

	return out;
}

GameRulesInstance *GameRuleDefinition::generateNewGameRulesInstance(GameRulesInstance::EGameRulesInstanceType type, LevelRuleset *rules, Connection *connection)
{
	GameRulesInstance *manager = new GameRulesInstance(rules, connection);

	rules->populateGameRule(type, manager);

	return manager;
}

wstring GameRuleDefinition::generateDescriptionString(ConsoleGameRules::EGameRuleType defType, const wstring &description, void *data, int dataLength)
{
	wstring formatted = description;
	switch(defType)
	{
	case ConsoleGameRules::eGameRuleType_CompleteAllRule:
		formatted = CompleteAllRuleDefinition::generateDescriptionString(description,data,dataLength);
		break;
	default:
		break;
	};
	return formatted;
}