format .Client/Common/GameRules

This commit is contained in:
Tropical 2026-03-22 01:15:44 -05:00
parent 6c92bc0be8
commit 87b4af678b
51 changed files with 4286 additions and 4229 deletions

View file

@ -4,62 +4,59 @@
#include "../../Minecraft.World/Headers/net.minecraft.world.item.enchantment.h" #include "../../Minecraft.World/Headers/net.minecraft.world.item.enchantment.h"
#include "AddEnchantmentRuleDefinition.h" #include "AddEnchantmentRuleDefinition.h"
AddEnchantmentRuleDefinition::AddEnchantmentRuleDefinition() AddEnchantmentRuleDefinition::AddEnchantmentRuleDefinition() {
{
m_enchantmentId = m_enchantmentLevel = 0; m_enchantmentId = m_enchantmentLevel = 0;
} }
void AddEnchantmentRuleDefinition::writeAttributes(DataOutputStream *dos, unsigned int numAttributes) void AddEnchantmentRuleDefinition::writeAttributes(DataOutputStream* dos,
{ unsigned int numAttributes) {
GameRuleDefinition::writeAttributes(dos, numAttributes + 2); GameRuleDefinition::writeAttributes(dos, numAttributes + 2);
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_enchantmentId); ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_enchantmentId);
dos->writeUTF( _toString( m_enchantmentId ) ); dos->writeUTF(_toString(m_enchantmentId));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_enchantmentLevel); ConsoleGameRules::write(dos,
dos->writeUTF( _toString( m_enchantmentLevel ) ); ConsoleGameRules::eGameRuleAttr_enchantmentLevel);
dos->writeUTF(_toString(m_enchantmentLevel));
} }
void AddEnchantmentRuleDefinition::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue) void AddEnchantmentRuleDefinition::addAttribute(
{ const std::wstring& attributeName, const std::wstring& attributeValue) {
if(attributeName.compare(L"enchantmentId") == 0) if (attributeName.compare(L"enchantmentId") == 0) {
{
int value = _fromString<int>(attributeValue); int value = _fromString<int>(attributeValue);
if(value < 0) value = 0; if (value < 0) value = 0;
if(value >= 256) value = 255; if (value >= 256) value = 255;
m_enchantmentId = value; m_enchantmentId = value;
app.DebugPrintf("AddEnchantmentRuleDefinition: Adding parameter enchantmentId=%d\n",m_enchantmentId); app.DebugPrintf(
} "AddEnchantmentRuleDefinition: Adding parameter enchantmentId=%d\n",
else if(attributeName.compare(L"enchantmentLevel") == 0) m_enchantmentId);
{ } else if (attributeName.compare(L"enchantmentLevel") == 0) {
int value = _fromString<int>(attributeValue); int value = _fromString<int>(attributeValue);
if(value < 0) value = 0; if (value < 0) value = 0;
m_enchantmentLevel = value; m_enchantmentLevel = value;
app.DebugPrintf("AddEnchantmentRuleDefinition: Adding parameter enchantmentLevel=%d\n",m_enchantmentLevel); app.DebugPrintf(
} "AddEnchantmentRuleDefinition: Adding parameter "
else "enchantmentLevel=%d\n",
{ m_enchantmentLevel);
} else {
GameRuleDefinition::addAttribute(attributeName, attributeValue); GameRuleDefinition::addAttribute(attributeName, attributeValue);
} }
} }
bool AddEnchantmentRuleDefinition::enchantItem(std::shared_ptr<ItemInstance> item) bool AddEnchantmentRuleDefinition::enchantItem(
{ std::shared_ptr<ItemInstance> item) {
bool enchanted = false; bool enchanted = false;
if (item != NULL) if (item != NULL) {
{
// 4J-JEV: Ripped code from enchantmenthelpers // 4J-JEV: Ripped code from enchantmenthelpers
// Maybe we want to add an addEnchantment method to EnchantmentHelpers // Maybe we want to add an addEnchantment method to EnchantmentHelpers
if (item->id == Item::enchantedBook_Id) if (item->id == Item::enchantedBook_Id) {
{ Item::enchantedBook->addEnchantment(
Item::enchantedBook->addEnchantment( item, new EnchantmentInstance(m_enchantmentId, m_enchantmentLevel) ); item,
} new EnchantmentInstance(m_enchantmentId, m_enchantmentLevel));
else if (item->isEnchantable()) } else if (item->isEnchantable()) {
{ Enchantment* e = Enchantment::enchantments[m_enchantmentId];
Enchantment *e = Enchantment::enchantments[m_enchantmentId];
if(e != NULL && e->category->canEnchant(item->getItem())) if (e != NULL && e->category->canEnchant(item->getItem())) {
{
int level = std::min(e->getMaxLevel(), m_enchantmentLevel); int level = std::min(e->getMaxLevel(), m_enchantmentLevel);
item->enchant(e, m_enchantmentLevel); item->enchant(e, m_enchantmentLevel);
enchanted = true; enchanted = true;

View file

@ -4,8 +4,7 @@
class ItemInstance; class ItemInstance;
class AddEnchantmentRuleDefinition : public GameRuleDefinition class AddEnchantmentRuleDefinition : public GameRuleDefinition {
{
private: private:
int m_enchantmentId; int m_enchantmentId;
int m_enchantmentLevel; int m_enchantmentLevel;
@ -13,11 +12,14 @@ private:
public: public:
AddEnchantmentRuleDefinition(); AddEnchantmentRuleDefinition();
virtual ConsoleGameRules::EGameRuleType getActionType() { return ConsoleGameRules::eGameRuleType_AddEnchantment; } virtual ConsoleGameRules::EGameRuleType getActionType() {
return ConsoleGameRules::eGameRuleType_AddEnchantment;
}
virtual void writeAttributes(DataOutputStream *, unsigned int numAttrs); virtual void writeAttributes(DataOutputStream*, unsigned int numAttrs);
virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue); virtual void addAttribute(const std::wstring& attributeName,
const std::wstring& attributeValue);
bool enchantItem(std::shared_ptr<ItemInstance> item); bool enchantItem(std::shared_ptr<ItemInstance> item);
}; };

View file

@ -6,121 +6,109 @@
#include "AddItemRuleDefinition.h" #include "AddItemRuleDefinition.h"
#include "AddEnchantmentRuleDefinition.h" #include "AddEnchantmentRuleDefinition.h"
AddItemRuleDefinition::AddItemRuleDefinition() AddItemRuleDefinition::AddItemRuleDefinition() {
{
m_itemId = m_quantity = m_auxValue = m_dataTag = 0; m_itemId = m_quantity = m_auxValue = m_dataTag = 0;
m_slot = -1; m_slot = -1;
} }
void AddItemRuleDefinition::writeAttributes(DataOutputStream *dos, unsigned int numAttrs) void AddItemRuleDefinition::writeAttributes(DataOutputStream* dos,
{ unsigned int numAttrs) {
GameRuleDefinition::writeAttributes(dos, numAttrs + 5); GameRuleDefinition::writeAttributes(dos, numAttrs + 5);
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_itemId); ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_itemId);
dos->writeUTF( _toString( m_itemId ) ); dos->writeUTF(_toString(m_itemId));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_quantity); ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_quantity);
dos->writeUTF( _toString( m_quantity ) ); dos->writeUTF(_toString(m_quantity));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_auxValue); ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_auxValue);
dos->writeUTF( _toString( m_auxValue ) ); dos->writeUTF(_toString(m_auxValue));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_dataTag); ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_dataTag);
dos->writeUTF( _toString( m_dataTag ) ); dos->writeUTF(_toString(m_dataTag));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_slot); ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_slot);
dos->writeUTF( _toString( m_slot ) ); dos->writeUTF(_toString(m_slot));
} }
void AddItemRuleDefinition::getChildren(std::vector<GameRuleDefinition *> *children) void AddItemRuleDefinition::getChildren(
{ std::vector<GameRuleDefinition*>* children) {
GameRuleDefinition::getChildren( children ); GameRuleDefinition::getChildren(children);
for (AUTO_VAR(it, m_enchantments.begin()); it != m_enchantments.end(); it++) for (AUTO_VAR(it, m_enchantments.begin()); it != m_enchantments.end(); it++)
children->push_back( *it ); children->push_back(*it);
} }
GameRuleDefinition *AddItemRuleDefinition::addChild(ConsoleGameRules::EGameRuleType ruleType) GameRuleDefinition* AddItemRuleDefinition::addChild(
{ ConsoleGameRules::EGameRuleType ruleType) {
GameRuleDefinition *rule = NULL; GameRuleDefinition* rule = NULL;
if(ruleType == ConsoleGameRules::eGameRuleType_AddEnchantment) if (ruleType == ConsoleGameRules::eGameRuleType_AddEnchantment) {
{
rule = new AddEnchantmentRuleDefinition(); rule = new AddEnchantmentRuleDefinition();
m_enchantments.push_back((AddEnchantmentRuleDefinition *)rule); m_enchantments.push_back((AddEnchantmentRuleDefinition*)rule);
} } else {
else
{
#ifndef _CONTENT_PACKAGE #ifndef _CONTENT_PACKAGE
//wprintf(L"AddItemRuleDefinition: Attempted to add invalid child rule - %d\n", ruleType ); // wprintf(L"AddItemRuleDefinition: Attempted to add invalid child rule
// - %d\n", ruleType );
#endif #endif
} }
return rule; return rule;
} }
void AddItemRuleDefinition::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue) void AddItemRuleDefinition::addAttribute(const std::wstring& attributeName,
{ const std::wstring& attributeValue) {
if(attributeName.compare(L"itemId") == 0) if (attributeName.compare(L"itemId") == 0) {
{
int value = _fromString<int>(attributeValue); int value = _fromString<int>(attributeValue);
m_itemId = value; m_itemId = value;
//app.DebugPrintf(2,"AddItemRuleDefinition: Adding parameter itemId=%d\n",m_itemId); // app.DebugPrintf(2,"AddItemRuleDefinition: Adding parameter
} // itemId=%d\n",m_itemId);
else if(attributeName.compare(L"quantity") == 0) } else if (attributeName.compare(L"quantity") == 0) {
{
int value = _fromString<int>(attributeValue); int value = _fromString<int>(attributeValue);
m_quantity = value; m_quantity = value;
//app.DebugPrintf(2,"AddItemRuleDefinition: Adding parameter quantity=%d\n",m_quantity); // app.DebugPrintf(2,"AddItemRuleDefinition: Adding parameter
} // quantity=%d\n",m_quantity);
else if(attributeName.compare(L"auxValue") == 0) } else if (attributeName.compare(L"auxValue") == 0) {
{
int value = _fromString<int>(attributeValue); int value = _fromString<int>(attributeValue);
m_auxValue = value; m_auxValue = value;
//app.DebugPrintf(2,"AddItemRuleDefinition: Adding parameter auxValue=%d\n",m_auxValue); // app.DebugPrintf(2,"AddItemRuleDefinition: Adding parameter
} // auxValue=%d\n",m_auxValue);
else if(attributeName.compare(L"dataTag") == 0) } else if (attributeName.compare(L"dataTag") == 0) {
{
int value = _fromString<int>(attributeValue); int value = _fromString<int>(attributeValue);
m_dataTag = value; m_dataTag = value;
//app.DebugPrintf(2,"AddItemRuleDefinition: Adding parameter dataTag=%d\n",m_dataTag); // app.DebugPrintf(2,"AddItemRuleDefinition: Adding parameter
} // dataTag=%d\n",m_dataTag);
else if(attributeName.compare(L"slot") == 0) } else if (attributeName.compare(L"slot") == 0) {
{
int value = _fromString<int>(attributeValue); int value = _fromString<int>(attributeValue);
m_slot = value; m_slot = value;
//app.DebugPrintf(2,"AddItemRuleDefinition: Adding parameter slot=%d\n",m_slot); // app.DebugPrintf(2,"AddItemRuleDefinition: Adding parameter
} // slot=%d\n",m_slot);
else } else {
{
GameRuleDefinition::addAttribute(attributeName, attributeValue); GameRuleDefinition::addAttribute(attributeName, attributeValue);
} }
} }
bool AddItemRuleDefinition::addItemToContainer(std::shared_ptr<Container> container, int slotId) bool AddItemRuleDefinition::addItemToContainer(
{ std::shared_ptr<Container> container, int slotId) {
bool added = false; bool added = false;
if(Item::items[m_itemId] != NULL) if (Item::items[m_itemId] != NULL) {
{ int quantity =
int quantity = std::min(m_quantity, Item::items[m_itemId]->getMaxStackSize()); std::min(m_quantity, Item::items[m_itemId]->getMaxStackSize());
std::shared_ptr<ItemInstance> newItem = std::shared_ptr<ItemInstance>(new ItemInstance(m_itemId,quantity,m_auxValue) ); std::shared_ptr<ItemInstance> newItem = std::shared_ptr<ItemInstance>(
new ItemInstance(m_itemId, quantity, m_auxValue));
newItem->set4JData(m_dataTag); newItem->set4JData(m_dataTag);
for(AUTO_VAR(it, m_enchantments.begin()); it != m_enchantments.end(); ++it) for (AUTO_VAR(it, m_enchantments.begin()); it != m_enchantments.end();
{ ++it) {
(*it)->enchantItem(newItem); (*it)->enchantItem(newItem);
} }
if(m_slot >= 0 && m_slot < container->getContainerSize() ) if (m_slot >= 0 && m_slot < container->getContainerSize()) {
{ container->setItem(m_slot, newItem);
container->setItem( m_slot, newItem );
added = true; added = true;
} } else if (slotId >= 0 && slotId < container->getContainerSize()) {
else if(slotId >= 0 && slotId < container->getContainerSize() ) container->setItem(slotId, newItem);
{
container->setItem( slotId, newItem );
added = true; added = true;
} } else if (std::dynamic_pointer_cast<Inventory>(container) != NULL) {
else if(std::dynamic_pointer_cast<Inventory>(container) != NULL) added =
{ std::dynamic_pointer_cast<Inventory>(container)->add(newItem);
added = std::dynamic_pointer_cast<Inventory>(container)->add(newItem);
} }
} }
return added; return added;

View file

@ -5,26 +5,29 @@
class Container; class Container;
class AddEnchantmentRuleDefinition; class AddEnchantmentRuleDefinition;
class AddItemRuleDefinition : public GameRuleDefinition class AddItemRuleDefinition : public GameRuleDefinition {
{
private: private:
int m_itemId; int m_itemId;
int m_quantity; int m_quantity;
int m_auxValue; int m_auxValue;
int m_dataTag; int m_dataTag;
int m_slot; int m_slot;
std::vector<AddEnchantmentRuleDefinition *> m_enchantments; std::vector<AddEnchantmentRuleDefinition*> m_enchantments;
public: public:
AddItemRuleDefinition(); AddItemRuleDefinition();
virtual void writeAttributes(DataOutputStream *, unsigned int numAttributes); virtual void writeAttributes(DataOutputStream*, unsigned int numAttributes);
virtual void getChildren(std::vector<GameRuleDefinition *> *children); virtual void getChildren(std::vector<GameRuleDefinition*>* children);
virtual ConsoleGameRules::EGameRuleType getActionType() { return ConsoleGameRules::eGameRuleType_AddItem; } virtual ConsoleGameRules::EGameRuleType getActionType() {
return ConsoleGameRules::eGameRuleType_AddItem;
}
virtual GameRuleDefinition *addChild(ConsoleGameRules::EGameRuleType ruleType); virtual GameRuleDefinition* addChild(
virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue); ConsoleGameRules::EGameRuleType ruleType);
virtual void addAttribute(const std::wstring& attributeName,
const std::wstring& attributeValue);
bool addItemToContainer(std::shared_ptr<Container> container, int slotId); bool addItemToContainer(std::shared_ptr<Container> container, int slotId);
}; };

View file

@ -9,10 +9,10 @@
#include "LevelGenerationOptions.h" #include "LevelGenerationOptions.h"
#include "ConsoleSchematicFile.h" #include "ConsoleSchematicFile.h"
ApplySchematicRuleDefinition::ApplySchematicRuleDefinition(LevelGenerationOptions *levelGenOptions) ApplySchematicRuleDefinition::ApplySchematicRuleDefinition(
{ LevelGenerationOptions* levelGenOptions) {
m_levelGenOptions = levelGenOptions; m_levelGenOptions = levelGenOptions;
m_location = Vec3::newPermanent(0,0,0); m_location = Vec3::newPermanent(0, 0, 0);
m_locationBox = NULL; m_locationBox = NULL;
m_totalBlocksChanged = 0; m_totalBlocksChanged = 0;
m_totalBlocksChangedLighting = 0; m_totalBlocksChangedLighting = 0;
@ -22,16 +22,15 @@ ApplySchematicRuleDefinition::ApplySchematicRuleDefinition(LevelGenerationOption
m_schematic = NULL; m_schematic = NULL;
} }
ApplySchematicRuleDefinition::~ApplySchematicRuleDefinition() ApplySchematicRuleDefinition::~ApplySchematicRuleDefinition() {
{
app.DebugPrintf("Deleting ApplySchematicRuleDefinition.\n"); app.DebugPrintf("Deleting ApplySchematicRuleDefinition.\n");
if(!m_completed) m_levelGenOptions->releaseSchematicFile(m_schematicName); if (!m_completed) m_levelGenOptions->releaseSchematicFile(m_schematicName);
m_schematic = NULL; m_schematic = NULL;
delete m_location; delete m_location;
} }
void ApplySchematicRuleDefinition::writeAttributes(DataOutputStream *dos, unsigned int numAttrs) void ApplySchematicRuleDefinition::writeAttributes(DataOutputStream* dos,
{ unsigned int numAttrs) {
GameRuleDefinition::writeAttributes(dos, numAttrs + 5); GameRuleDefinition::writeAttributes(dos, numAttrs + 5);
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_filename); ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_filename);
@ -44,60 +43,62 @@ void ApplySchematicRuleDefinition::writeAttributes(DataOutputStream *dos, unsign
dos->writeUTF(_toString(m_location->z)); dos->writeUTF(_toString(m_location->z));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_rot); ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_rot);
switch (m_rotation) switch (m_rotation) {
{ case ConsoleSchematicFile::eSchematicRot_0:
case ConsoleSchematicFile::eSchematicRot_0: dos->writeUTF(_toString( 0 )); break; dos->writeUTF(_toString(0));
case ConsoleSchematicFile::eSchematicRot_90: dos->writeUTF(_toString( 90 )); break; break;
case ConsoleSchematicFile::eSchematicRot_180: dos->writeUTF(_toString( 180 )); break; case ConsoleSchematicFile::eSchematicRot_90:
case ConsoleSchematicFile::eSchematicRot_270: dos->writeUTF(_toString( 270 )); break; dos->writeUTF(_toString(90));
break;
case ConsoleSchematicFile::eSchematicRot_180:
dos->writeUTF(_toString(180));
break;
case ConsoleSchematicFile::eSchematicRot_270:
dos->writeUTF(_toString(270));
break;
} }
} }
void ApplySchematicRuleDefinition::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue) void ApplySchematicRuleDefinition::addAttribute(
{ const std::wstring& attributeName, const std::wstring& attributeValue) {
if(attributeName.compare(L"filename") == 0) if (attributeName.compare(L"filename") == 0) {
{
m_schematicName = attributeValue; m_schematicName = attributeValue;
//app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter filename=%s\n",m_schematicName.c_str()); // app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter
// filename=%s\n",m_schematicName.c_str());
if(!m_schematicName.empty()) if (!m_schematicName.empty()) {
{ if (m_schematicName
if(m_schematicName.substr( m_schematicName.length() - 4, m_schematicName.length()).compare(L".sch") != 0) .substr(m_schematicName.length() - 4,
{ m_schematicName.length())
.compare(L".sch") != 0) {
m_schematicName.append(L".sch"); m_schematicName.append(L".sch");
} }
m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName); m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName);
} }
} } else if (attributeName.compare(L"x") == 0) {
else if(attributeName.compare(L"x") == 0)
{
m_location->x = _fromString<int>(attributeValue); m_location->x = _fromString<int>(attributeValue);
if( ((int)abs(m_location->x))%2 != 0) m_location->x -=1; if (((int)abs(m_location->x)) % 2 != 0) m_location->x -= 1;
//app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter x=%f\n",m_location->x); // app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter
} // x=%f\n",m_location->x);
else if(attributeName.compare(L"y") == 0) } else if (attributeName.compare(L"y") == 0) {
{
m_location->y = _fromString<int>(attributeValue); m_location->y = _fromString<int>(attributeValue);
if( ((int)abs(m_location->y))%2 != 0) m_location->y -= 1; if (((int)abs(m_location->y)) % 2 != 0) m_location->y -= 1;
if(m_location->y < 0) m_location->y = 0; if (m_location->y < 0) m_location->y = 0;
//app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter y=%f\n",m_location->y); // app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter
} // y=%f\n",m_location->y);
else if(attributeName.compare(L"z") == 0) } else if (attributeName.compare(L"z") == 0) {
{
m_location->z = _fromString<int>(attributeValue); m_location->z = _fromString<int>(attributeValue);
if(((int)abs(m_location->z))%2 != 0) m_location->z -= 1; if (((int)abs(m_location->z)) % 2 != 0) m_location->z -= 1;
//app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter z=%f\n",m_location->z); // app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter
} // z=%f\n",m_location->z);
else if(attributeName.compare(L"rot") == 0) } else if (attributeName.compare(L"rot") == 0) {
{
int degrees = _fromString<int>(attributeValue); int degrees = _fromString<int>(attributeValue);
while(degrees < 0) degrees += 360; while (degrees < 0) degrees += 360;
while(degrees >= 360) degrees -= 360; while (degrees >= 360) degrees -= 360;
float quad = degrees/90; float quad = degrees / 90;
degrees = (int)(quad + 0.5f); degrees = (int)(quad + 0.5f);
switch(degrees) switch (degrees) {
{
case 1: case 1:
m_rotation = ConsoleSchematicFile::eSchematicRot_90; m_rotation = ConsoleSchematicFile::eSchematicRot_90;
break; break;
@ -114,25 +115,23 @@ void ApplySchematicRuleDefinition::addAttribute(const std::wstring &attributeNam
break; break;
}; };
//app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter rot=%d\n",m_rotation); // app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter
} // rot=%d\n",m_rotation);
else if(attributeName.compare(L"dim") == 0) } else if (attributeName.compare(L"dim") == 0) {
{
m_dimension = _fromString<int>(attributeValue); m_dimension = _fromString<int>(attributeValue);
if(m_dimension > 1 || m_dimension < -1) m_dimension = 0; if (m_dimension > 1 || m_dimension < -1) m_dimension = 0;
//app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter dimension=%d\n",m_dimension); // app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter
} // dimension=%d\n",m_dimension);
else } else {
{
GameRuleDefinition::addAttribute(attributeName, attributeValue); GameRuleDefinition::addAttribute(attributeName, attributeValue);
} }
} }
void ApplySchematicRuleDefinition::updateLocationBox() void ApplySchematicRuleDefinition::updateLocationBox() {
{ if (m_schematic == NULL)
if(m_schematic == NULL) m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName); m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName);
m_locationBox = AABB::newPermanent(0,0,0,0,0,0); m_locationBox = AABB::newPermanent(0, 0, 0, 0, 0, 0);
m_locationBox->x0 = m_location->x; m_locationBox->x0 = m_location->x;
m_locationBox->y0 = m_location->y; m_locationBox->y0 = m_location->y;
@ -140,8 +139,7 @@ void ApplySchematicRuleDefinition::updateLocationBox()
m_locationBox->y1 = m_location->y + m_schematic->getYSize(); m_locationBox->y1 = m_location->y + m_schematic->getYSize();
switch(m_rotation) switch (m_rotation) {
{
case ConsoleSchematicFile::eSchematicRot_90: case ConsoleSchematicFile::eSchematicRot_90:
case ConsoleSchematicFile::eSchematicRot_270: case ConsoleSchematicFile::eSchematicRot_270:
m_locationBox->x1 = m_location->x + m_schematic->getZSize(); m_locationBox->x1 = m_location->x + m_schematic->getZSize();
@ -156,93 +154,100 @@ void ApplySchematicRuleDefinition::updateLocationBox()
}; };
} }
void ApplySchematicRuleDefinition::processSchematic(AABB *chunkBox, LevelChunk *chunk) void ApplySchematicRuleDefinition::processSchematic(AABB* chunkBox,
{ LevelChunk* chunk) {
if( m_completed ) return; if (m_completed) return;
if(chunk->level->dimension->id != m_dimension) return; if (chunk->level->dimension->id != m_dimension) return;
PIXBeginNamedEvent(0, "Processing ApplySchematicRuleDefinition"); PIXBeginNamedEvent(0, "Processing ApplySchematicRuleDefinition");
if(m_schematic == NULL) m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName); if (m_schematic == NULL)
m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName);
if(m_locationBox == NULL) updateLocationBox(); if (m_locationBox == NULL) updateLocationBox();
if(chunkBox->intersects( m_locationBox )) if (chunkBox->intersects(m_locationBox)) {
{ m_locationBox->y1 =
m_locationBox->y1 = std::min((double)Level::maxBuildHeight, m_locationBox->y1 ); std::min((double)Level::maxBuildHeight, m_locationBox->y1);
#ifdef _DEBUG #ifdef _DEBUG
app.DebugPrintf("Applying schematic %ls to chunk (%d,%d)\n",m_schematicName.c_str(),chunk->x, chunk->z); app.DebugPrintf("Applying schematic %ls to chunk (%d,%d)\n",
m_schematicName.c_str(), chunk->x, chunk->z);
#endif #endif
PIXBeginNamedEvent(0,"Applying blocks and data"); PIXBeginNamedEvent(0, "Applying blocks and data");
m_totalBlocksChanged += m_schematic->applyBlocksAndData(chunk, chunkBox, m_locationBox, m_rotation); m_totalBlocksChanged += m_schematic->applyBlocksAndData(
chunk, chunkBox, m_locationBox, m_rotation);
PIXEndNamedEvent(); PIXEndNamedEvent();
// Add the tileEntities // Add the tileEntities
PIXBeginNamedEvent(0,"Applying tile entities"); PIXBeginNamedEvent(0, "Applying tile entities");
m_schematic->applyTileEntities(chunk, chunkBox, m_locationBox, m_rotation); m_schematic->applyTileEntities(chunk, chunkBox, m_locationBox,
m_rotation);
PIXEndNamedEvent(); PIXEndNamedEvent();
// TODO This does not take into account things that go outside the bounds of the world // TODO This does not take into account things that go outside the
int targetBlocks = (m_locationBox->x1 - m_locationBox->x0) // bounds of the world
* (m_locationBox->y1 - m_locationBox->y0) int targetBlocks = (m_locationBox->x1 - m_locationBox->x0) *
* (m_locationBox->z1 - m_locationBox->z0); (m_locationBox->y1 - m_locationBox->y0) *
if( (m_totalBlocksChanged == targetBlocks) && (m_totalBlocksChangedLighting == targetBlocks) ) (m_locationBox->z1 - m_locationBox->z0);
{ if ((m_totalBlocksChanged == targetBlocks) &&
(m_totalBlocksChangedLighting == targetBlocks)) {
m_completed = true; m_completed = true;
//m_levelGenOptions->releaseSchematicFile(m_schematicName); // m_levelGenOptions->releaseSchematicFile(m_schematicName);
//m_schematic = NULL; // m_schematic = NULL;
} }
} }
PIXEndNamedEvent(); PIXEndNamedEvent();
} }
void ApplySchematicRuleDefinition::processSchematicLighting(AABB *chunkBox, LevelChunk *chunk) void ApplySchematicRuleDefinition::processSchematicLighting(AABB* chunkBox,
{ LevelChunk* chunk) {
if( m_completed ) return; if (m_completed) return;
if(chunk->level->dimension->id != m_dimension) return; if (chunk->level->dimension->id != m_dimension) return;
PIXBeginNamedEvent(0, "Processing ApplySchematicRuleDefinition (lighting)"); PIXBeginNamedEvent(0, "Processing ApplySchematicRuleDefinition (lighting)");
if(m_schematic == NULL) m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName); if (m_schematic == NULL)
m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName);
if(m_locationBox == NULL) updateLocationBox(); if (m_locationBox == NULL) updateLocationBox();
if(chunkBox->intersects( m_locationBox )) if (chunkBox->intersects(m_locationBox)) {
{ m_locationBox->y1 =
m_locationBox->y1 = std::min((double)Level::maxBuildHeight, m_locationBox->y1 ); std::min((double)Level::maxBuildHeight, m_locationBox->y1);
#ifdef _DEBUG #ifdef _DEBUG
app.DebugPrintf("Applying schematic %ls to chunk (%d,%d)\n",m_schematicName.c_str(),chunk->x, chunk->z); app.DebugPrintf("Applying schematic %ls to chunk (%d,%d)\n",
m_schematicName.c_str(), chunk->x, chunk->z);
#endif #endif
PIXBeginNamedEvent(0,"Patching lighting"); PIXBeginNamedEvent(0, "Patching lighting");
m_totalBlocksChangedLighting += m_schematic->applyLighting(chunk, chunkBox, m_locationBox, m_rotation); m_totalBlocksChangedLighting += m_schematic->applyLighting(
chunk, chunkBox, m_locationBox, m_rotation);
PIXEndNamedEvent(); PIXEndNamedEvent();
// TODO This does not take into account things that go outside the bounds of the world // TODO This does not take into account things that go outside the
int targetBlocks = (m_locationBox->x1 - m_locationBox->x0) // bounds of the world
* (m_locationBox->y1 - m_locationBox->y0) int targetBlocks = (m_locationBox->x1 - m_locationBox->x0) *
* (m_locationBox->z1 - m_locationBox->z0); (m_locationBox->y1 - m_locationBox->y0) *
if( (m_totalBlocksChanged == targetBlocks) && (m_totalBlocksChangedLighting == targetBlocks) ) (m_locationBox->z1 - m_locationBox->z0);
{ if ((m_totalBlocksChanged == targetBlocks) &&
(m_totalBlocksChangedLighting == targetBlocks)) {
m_completed = true; m_completed = true;
//m_levelGenOptions->releaseSchematicFile(m_schematicName); // m_levelGenOptions->releaseSchematicFile(m_schematicName);
//m_schematic = NULL; // m_schematic = NULL;
} }
} }
PIXEndNamedEvent(); PIXEndNamedEvent();
} }
bool ApplySchematicRuleDefinition::checkIntersects(int x0, int y0, int z0, int x1, int y1, int z1) bool ApplySchematicRuleDefinition::checkIntersects(int x0, int y0, int z0,
{ int x1, int y1, int z1) {
if( m_locationBox == NULL ) updateLocationBox(); if (m_locationBox == NULL) updateLocationBox();
return m_locationBox->intersects(x0,y0,z0,x1,y1,z1); return m_locationBox->intersects(x0, y0, z0, x1, y1, z1);
} }
int ApplySchematicRuleDefinition::getMinY() int ApplySchematicRuleDefinition::getMinY() {
{ if (m_locationBox == NULL) updateLocationBox();
if( m_locationBox == NULL ) updateLocationBox();
return m_locationBox->y0; return m_locationBox->y0;
} }
void ApplySchematicRuleDefinition::reset() void ApplySchematicRuleDefinition::reset() {
{
m_totalBlocksChanged = 0; m_totalBlocksChanged = 0;
m_totalBlocksChangedLighting = 0; m_totalBlocksChangedLighting = 0;
m_completed = false; m_completed = false;

View file

@ -8,14 +8,13 @@ class LevelChunk;
class LevelGenerationOptions; class LevelGenerationOptions;
class GRFObject; class GRFObject;
class ApplySchematicRuleDefinition : public GameRuleDefinition class ApplySchematicRuleDefinition : public GameRuleDefinition {
{
private: private:
LevelGenerationOptions *m_levelGenOptions; LevelGenerationOptions* m_levelGenOptions;
std::wstring m_schematicName; std::wstring m_schematicName;
ConsoleSchematicFile *m_schematic; ConsoleSchematicFile* m_schematic;
Vec3 *m_location; Vec3* m_location;
AABB *m_locationBox; AABB* m_locationBox;
ConsoleSchematicFile::ESchematicRotation m_rotation; ConsoleSchematicFile::ESchematicRotation m_rotation;
int m_dimension; int m_dimension;
@ -24,17 +23,21 @@ private:
bool m_completed; bool m_completed;
void updateLocationBox(); void updateLocationBox();
public: public:
ApplySchematicRuleDefinition(LevelGenerationOptions *levelGenOptions); ApplySchematicRuleDefinition(LevelGenerationOptions* levelGenOptions);
~ApplySchematicRuleDefinition(); ~ApplySchematicRuleDefinition();
virtual ConsoleGameRules::EGameRuleType getActionType() { return ConsoleGameRules::eGameRuleType_ApplySchematic; } virtual ConsoleGameRules::EGameRuleType getActionType() {
return ConsoleGameRules::eGameRuleType_ApplySchematic;
}
virtual void writeAttributes(DataOutputStream *dos, unsigned int numAttrs); virtual void writeAttributes(DataOutputStream* dos, unsigned int numAttrs);
virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue); virtual void addAttribute(const std::wstring& attributeName,
const std::wstring& attributeValue);
void processSchematic(AABB *chunkBox, LevelChunk *chunk); void processSchematic(AABB* chunkBox, LevelChunk* chunk);
void processSchematicLighting(AABB *chunkBox, LevelChunk *chunk); void processSchematicLighting(AABB* chunkBox, LevelChunk* chunk);
bool checkIntersects(int x0, int y0, int z0, int x1, int y1, int z1); bool checkIntersects(int x0, int y0, int z0, int x1, int y1, int z1);
int getMinY(); int getMinY();

View file

@ -2,15 +2,14 @@
#include "../../Minecraft.World/Util/StringHelpers.h" #include "../../Minecraft.World/Util/StringHelpers.h"
#include "BiomeOverride.h" #include "BiomeOverride.h"
BiomeOverride::BiomeOverride() BiomeOverride::BiomeOverride() {
{
m_tile = 0; m_tile = 0;
m_topTile = 0; m_topTile = 0;
m_biomeId = 0; m_biomeId = 0;
} }
void BiomeOverride::writeAttributes(DataOutputStream *dos, unsigned int numAttrs) void BiomeOverride::writeAttributes(DataOutputStream* dos,
{ unsigned int numAttrs) {
GameRuleDefinition::writeAttributes(dos, numAttrs + 3); GameRuleDefinition::writeAttributes(dos, numAttrs + 3);
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_biomeId); ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_biomeId);
@ -21,39 +20,30 @@ void BiomeOverride::writeAttributes(DataOutputStream *dos, unsigned int numAttrs
dos->writeUTF(_toString(m_topTile)); dos->writeUTF(_toString(m_topTile));
} }
void BiomeOverride::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue) void BiomeOverride::addAttribute(const std::wstring& attributeName,
{ const std::wstring& attributeValue) {
if(attributeName.compare(L"tileId") == 0) if (attributeName.compare(L"tileId") == 0) {
{
int value = _fromString<int>(attributeValue); int value = _fromString<int>(attributeValue);
m_tile = value; m_tile = value;
app.DebugPrintf("BiomeOverride: Adding parameter tileId=%d\n",m_tile); app.DebugPrintf("BiomeOverride: Adding parameter tileId=%d\n", m_tile);
} } else if (attributeName.compare(L"topTileId") == 0) {
else if(attributeName.compare(L"topTileId") == 0)
{
int value = _fromString<int>(attributeValue); int value = _fromString<int>(attributeValue);
m_topTile = value; m_topTile = value;
app.DebugPrintf("BiomeOverride: Adding parameter topTileId=%d\n",m_topTile); app.DebugPrintf("BiomeOverride: Adding parameter topTileId=%d\n",
} m_topTile);
else if(attributeName.compare(L"biomeId") == 0) } else if (attributeName.compare(L"biomeId") == 0) {
{
int value = _fromString<int>(attributeValue); int value = _fromString<int>(attributeValue);
m_biomeId = value; m_biomeId = value;
app.DebugPrintf("BiomeOverride: Adding parameter biomeId=%d\n",m_biomeId); app.DebugPrintf("BiomeOverride: Adding parameter biomeId=%d\n",
} m_biomeId);
else } else {
{
GameRuleDefinition::addAttribute(attributeName, attributeValue); GameRuleDefinition::addAttribute(attributeName, attributeValue);
} }
} }
bool BiomeOverride::isBiome(int id) bool BiomeOverride::isBiome(int id) { return m_biomeId == id; }
{
return m_biomeId == id;
}
void BiomeOverride::getTileValues(std::uint8_t &tile, std::uint8_t &topTile) void BiomeOverride::getTileValues(std::uint8_t& tile, std::uint8_t& topTile) {
{ if (m_tile != 0) tile = m_tile;
if(m_tile != 0) tile = m_tile; if (m_topTile != 0) topTile = m_topTile;
if(m_topTile != 0) topTile = m_topTile;
} }

View file

@ -1,10 +1,9 @@
#pragma once #pragma once
//using namespace std; // using namespace std;
#include "GameRuleDefinition.h" #include "GameRuleDefinition.h"
class BiomeOverride : public GameRuleDefinition class BiomeOverride : public GameRuleDefinition {
{
private: private:
std::uint8_t m_topTile; std::uint8_t m_topTile;
std::uint8_t m_tile; std::uint8_t m_tile;
@ -13,11 +12,14 @@ private:
public: public:
BiomeOverride(); BiomeOverride();
virtual ConsoleGameRules::EGameRuleType getActionType() { return ConsoleGameRules::eGameRuleType_BiomeOverride; } virtual ConsoleGameRules::EGameRuleType getActionType() {
return ConsoleGameRules::eGameRuleType_BiomeOverride;
}
virtual void writeAttributes(DataOutputStream *dos, unsigned int numAttrs); virtual void writeAttributes(DataOutputStream* dos, unsigned int numAttrs);
virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue); virtual void addAttribute(const std::wstring& attributeName,
const std::wstring& attributeValue);
bool isBiome(int id); bool isBiome(int id);
void getTileValues(std::uint8_t &tile, std::uint8_t &topTile); void getTileValues(std::uint8_t& tile, std::uint8_t& topTile);
}; };

View file

@ -6,95 +6,90 @@
#include "../../Minecraft.World/Network/Connection.h" #include "../../Minecraft.World/Network/Connection.h"
#include "../../Minecraft.World/Headers/net.minecraft.network.packet.h" #include "../../Minecraft.World/Headers/net.minecraft.network.packet.h"
CollectItemRuleDefinition::CollectItemRuleDefinition() CollectItemRuleDefinition::CollectItemRuleDefinition() {
{
m_itemId = 0; m_itemId = 0;
m_auxValue = 0; m_auxValue = 0;
m_quantity = 0; m_quantity = 0;
} }
CollectItemRuleDefinition::~CollectItemRuleDefinition() CollectItemRuleDefinition::~CollectItemRuleDefinition() {}
{
}
void CollectItemRuleDefinition::writeAttributes(DataOutputStream *dos, unsigned int numAttributes) void CollectItemRuleDefinition::writeAttributes(DataOutputStream* dos,
{ unsigned int numAttributes) {
GameRuleDefinition::writeAttributes(dos, numAttributes + 3); GameRuleDefinition::writeAttributes(dos, numAttributes + 3);
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_itemId); ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_itemId);
dos->writeUTF( _toString( m_itemId ) ); dos->writeUTF(_toString(m_itemId));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_auxValue); ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_auxValue);
dos->writeUTF( _toString( m_auxValue ) ); dos->writeUTF(_toString(m_auxValue));
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_quantity); ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_quantity);
dos->writeUTF( _toString( m_quantity ) ); dos->writeUTF(_toString(m_quantity));
} }
void CollectItemRuleDefinition::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue) void CollectItemRuleDefinition::addAttribute(
{ const std::wstring& attributeName, const std::wstring& attributeValue) {
if(attributeName.compare(L"itemId") == 0) if (attributeName.compare(L"itemId") == 0) {
{
m_itemId = _fromString<int>(attributeValue); m_itemId = _fromString<int>(attributeValue);
app.DebugPrintf("CollectItemRule: Adding parameter itemId=%d\n",m_itemId); app.DebugPrintf("CollectItemRule: Adding parameter itemId=%d\n",
} m_itemId);
else if(attributeName.compare(L"auxValue") == 0) } else if (attributeName.compare(L"auxValue") == 0) {
{
m_auxValue = _fromString<int>(attributeValue); m_auxValue = _fromString<int>(attributeValue);
app.DebugPrintf("CollectItemRule: Adding parameter m_auxValue=%d\n",m_auxValue); app.DebugPrintf("CollectItemRule: Adding parameter m_auxValue=%d\n",
} m_auxValue);
else if(attributeName.compare(L"quantity") == 0) } else if (attributeName.compare(L"quantity") == 0) {
{
m_quantity = _fromString<int>(attributeValue); m_quantity = _fromString<int>(attributeValue);
app.DebugPrintf("CollectItemRule: Adding parameter m_quantity=%d\n",m_quantity); app.DebugPrintf("CollectItemRule: Adding parameter m_quantity=%d\n",
} m_quantity);
else } else {
{
GameRuleDefinition::addAttribute(attributeName, attributeValue); GameRuleDefinition::addAttribute(attributeName, attributeValue);
} }
} }
int CollectItemRuleDefinition::getGoal() int CollectItemRuleDefinition::getGoal() { return m_quantity; }
{
return m_quantity;
}
int CollectItemRuleDefinition::getProgress(GameRule *rule) int CollectItemRuleDefinition::getProgress(GameRule* rule) {
{
GameRule::ValueType value = rule->getParameter(L"iQuantity"); GameRule::ValueType value = rule->getParameter(L"iQuantity");
return value.i; return value.i;
} }
void CollectItemRuleDefinition::populateGameRule(GameRulesInstance::EGameRulesInstanceType type, GameRule *rule) void CollectItemRuleDefinition::populateGameRule(
{ GameRulesInstance::EGameRulesInstanceType type, GameRule* rule) {
GameRule::ValueType value; GameRule::ValueType value;
value.i = 0; value.i = 0;
rule->setParameter(L"iQuantity",value); rule->setParameter(L"iQuantity", value);
GameRuleDefinition::populateGameRule(type, rule); GameRuleDefinition::populateGameRule(type, rule);
} }
bool CollectItemRuleDefinition::onCollectItem(GameRule *rule, std::shared_ptr<ItemInstance> item) bool CollectItemRuleDefinition::onCollectItem(
{ GameRule* rule, std::shared_ptr<ItemInstance> item) {
bool statusChanged = false; bool statusChanged = false;
if(item != NULL && item->id == m_itemId && item->getAuxValue() == m_auxValue && item->get4JData() == m_4JDataValue) if (item != NULL && item->id == m_itemId &&
{ item->getAuxValue() == m_auxValue &&
if(!getComplete(rule)) item->get4JData() == m_4JDataValue) {
{ if (!getComplete(rule)) {
GameRule::ValueType value = rule->getParameter(L"iQuantity"); GameRule::ValueType value = rule->getParameter(L"iQuantity");
int quantityCollected = (value.i += item->count); int quantityCollected = (value.i += item->count);
rule->setParameter(L"iQuantity",value); rule->setParameter(L"iQuantity", value);
statusChanged = true; statusChanged = true;
if(quantityCollected >= m_quantity) if (quantityCollected >= m_quantity) {
{
setComplete(rule, true); setComplete(rule, true);
app.DebugPrintf("Completed CollectItemRule with info - itemId:%d, auxValue:%d, quantity:%d, dataTag:%d\n", m_itemId,m_auxValue,m_quantity,m_4JDataValue); app.DebugPrintf(
"Completed CollectItemRule with info - itemId:%d, "
"auxValue:%d, quantity:%d, dataTag:%d\n",
m_itemId, m_auxValue, m_quantity, m_4JDataValue);
if(rule->getConnection() != NULL) if (rule->getConnection() != NULL) {
{ rule->getConnection()->send(
rule->getConnection()->send( std::shared_ptr<UpdateGameRuleProgressPacket>( new UpdateGameRuleProgressPacket(getActionType(), this->m_descriptionId, m_itemId, m_auxValue, this->m_4JDataValue,NULL,0))); std::shared_ptr<UpdateGameRuleProgressPacket>(
new UpdateGameRuleProgressPacket(
getActionType(), this->m_descriptionId,
m_itemId, m_auxValue, this->m_4JDataValue, NULL,
0)));
} }
} }
} }
@ -102,15 +97,19 @@ bool CollectItemRuleDefinition::onCollectItem(GameRule *rule, std::shared_ptr<It
return statusChanged; return statusChanged;
} }
std::wstring CollectItemRuleDefinition::generateXml(std::shared_ptr<ItemInstance> item) std::wstring CollectItemRuleDefinition::generateXml(
{ std::shared_ptr<ItemInstance> item) {
// 4J Stu - This should be kept in sync with the GameRulesDefinition.xsd // 4J Stu - This should be kept in sync with the GameRulesDefinition.xsd
std::wstring xml = L""; std::wstring xml = L"";
if(item != NULL) if (item != NULL) {
{ xml = L"<CollectItemRule itemId=\"" + _toString<int>(item->id) +
xml = L"<CollectItemRule itemId=\"" + _toString<int>(item->id) + L"\" quantity=\"SET\" descriptionName=\"OPTIONAL\" promptName=\"OPTIONAL\""; L"\" quantity=\"SET\" descriptionName=\"OPTIONAL\" "
if(item->getAuxValue() != 0) xml += L" auxValue=\"" + _toString<int>(item->getAuxValue()) + L"\""; L"promptName=\"OPTIONAL\"";
if(item->get4JData() != 0) xml += L" dataTag=\"" + _toString<int>(item->get4JData()) + L"\""; if (item->getAuxValue() != 0)
xml +=
L" auxValue=\"" + _toString<int>(item->getAuxValue()) + L"\"";
if (item->get4JData() != 0)
xml += L" dataTag=\"" + _toString<int>(item->get4JData()) + L"\"";
xml += L"/>\n"; xml += L"/>\n";
} }
return xml; return xml;

View file

@ -6,8 +6,7 @@ class Pos;
class UseTileRuleDefinition; class UseTileRuleDefinition;
class ItemInstance; class ItemInstance;
class CollectItemRuleDefinition : public GameRuleDefinition class CollectItemRuleDefinition : public GameRuleDefinition {
{
private: private:
// These values should map directly to the xsd definition for this Rule // These values should map directly to the xsd definition for this Rule
int m_itemId; int m_itemId;
@ -18,23 +17,27 @@ public:
CollectItemRuleDefinition(); CollectItemRuleDefinition();
~CollectItemRuleDefinition(); ~CollectItemRuleDefinition();
ConsoleGameRules::EGameRuleType getActionType() { return ConsoleGameRules::eGameRuleType_CollectItemRule; } ConsoleGameRules::EGameRuleType getActionType() {
return ConsoleGameRules::eGameRuleType_CollectItemRule;
}
virtual void writeAttributes(DataOutputStream *, unsigned int numAttributes); virtual void writeAttributes(DataOutputStream*, unsigned int numAttributes);
virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue); virtual void addAttribute(const std::wstring& attributeName,
const std::wstring& attributeValue);
virtual int getGoal(); virtual int getGoal();
virtual int getProgress(GameRule *rule); virtual int getProgress(GameRule* rule);
virtual int getIcon() { return m_itemId; } virtual int getIcon() { return m_itemId; }
virtual int getAuxValue() { return m_auxValue; } virtual int getAuxValue() { return m_auxValue; }
void populateGameRule(GameRulesInstance::EGameRulesInstanceType type, GameRule *rule); void populateGameRule(GameRulesInstance::EGameRulesInstanceType type,
GameRule* rule);
bool onCollectItem(GameRule *rule, std::shared_ptr<ItemInstance> item); bool onCollectItem(GameRule* rule, std::shared_ptr<ItemInstance> item);
static std::wstring generateXml(std::shared_ptr<ItemInstance> item); static std::wstring generateXml(std::shared_ptr<ItemInstance> item);
private: private:
//static std::wstring generateXml(CollectItemRuleDefinition *ruleDef); // static std::wstring generateXml(CollectItemRuleDefinition *ruleDef);
}; };

View file

@ -5,39 +5,38 @@
#include "../../Minecraft.World/Network/Connection.h" #include "../../Minecraft.World/Network/Connection.h"
#include "../../Minecraft.World/Headers/net.minecraft.network.packet.h" #include "../../Minecraft.World/Headers/net.minecraft.network.packet.h"
void CompleteAllRuleDefinition::getChildren(std::vector<GameRuleDefinition *> *children) void CompleteAllRuleDefinition::getChildren(
{ std::vector<GameRuleDefinition*>* children) {
CompoundGameRuleDefinition::getChildren(children); CompoundGameRuleDefinition::getChildren(children);
} }
bool CompleteAllRuleDefinition::onUseTile(GameRule *rule, int tileId, int x, int y, int z) bool CompleteAllRuleDefinition::onUseTile(GameRule* rule, int tileId, int x,
{ int y, int z) {
bool statusChanged = CompoundGameRuleDefinition::onUseTile(rule,tileId,x,y,z); bool statusChanged =
if(statusChanged) updateStatus(rule); CompoundGameRuleDefinition::onUseTile(rule, tileId, x, y, z);
if (statusChanged) updateStatus(rule);
return statusChanged; return statusChanged;
} }
bool CompleteAllRuleDefinition::onCollectItem(GameRule *rule, std::shared_ptr<ItemInstance> item) bool CompleteAllRuleDefinition::onCollectItem(
{ GameRule* rule, std::shared_ptr<ItemInstance> item) {
bool statusChanged = CompoundGameRuleDefinition::onCollectItem(rule,item); bool statusChanged = CompoundGameRuleDefinition::onCollectItem(rule, item);
if(statusChanged) updateStatus(rule); if (statusChanged) updateStatus(rule);
return statusChanged; return statusChanged;
} }
void CompleteAllRuleDefinition::updateStatus(GameRule *rule) void CompleteAllRuleDefinition::updateStatus(GameRule* rule) {
{
int goal = 0; int goal = 0;
int progress = 0; int progress = 0;
for(AUTO_VAR(it, rule->m_parameters.begin()); it != rule->m_parameters.end(); ++it) for (AUTO_VAR(it, rule->m_parameters.begin());
{ it != rule->m_parameters.end(); ++it) {
if(it->second.isPointer) if (it->second.isPointer) {
{
goal += it->second.gr->getGameRuleDefinition()->getGoal(); goal += it->second.gr->getGameRuleDefinition()->getGoal();
progress += it->second.gr->getGameRuleDefinition()->getProgress(it->second.gr); progress += it->second.gr->getGameRuleDefinition()->getProgress(
it->second.gr);
} }
} }
if(rule->getConnection() != NULL) if (rule->getConnection() != NULL) {
{
PacketData data; PacketData data;
data.goal = goal; data.goal = goal;
data.progress = progress; data.progress = progress;
@ -45,22 +44,27 @@ void CompleteAllRuleDefinition::updateStatus(GameRule *rule)
int icon = -1; int icon = -1;
int auxValue = 0; int auxValue = 0;
if(m_lastRuleStatusChanged != NULL) if (m_lastRuleStatusChanged != NULL) {
{
icon = m_lastRuleStatusChanged->getIcon(); icon = m_lastRuleStatusChanged->getIcon();
auxValue = m_lastRuleStatusChanged->getAuxValue(); auxValue = m_lastRuleStatusChanged->getAuxValue();
m_lastRuleStatusChanged = NULL; m_lastRuleStatusChanged = NULL;
} }
rule->getConnection()->send( std::shared_ptr<UpdateGameRuleProgressPacket>( new UpdateGameRuleProgressPacket(getActionType(), this->m_descriptionId,icon, auxValue, 0,&data,sizeof(PacketData)))); rule->getConnection()->send(
std::shared_ptr<UpdateGameRuleProgressPacket>(
new UpdateGameRuleProgressPacket(
getActionType(), this->m_descriptionId, icon, auxValue, 0,
&data, sizeof(PacketData))));
} }
app.DebugPrintf("Updated CompleteAllRule - Completed %d of %d\n", progress, goal); app.DebugPrintf("Updated CompleteAllRule - Completed %d of %d\n", progress,
goal);
} }
std::wstring CompleteAllRuleDefinition::generateDescriptionString(const std::wstring &description, void *data, int dataLength) std::wstring CompleteAllRuleDefinition::generateDescriptionString(
{ const std::wstring& description, void* data, int dataLength) {
PacketData *values = (PacketData *)data; PacketData* values = (PacketData*)data;
std::wstring newDesc = description; std::wstring newDesc = description;
newDesc = replaceAll(newDesc,L"{*progress*}",_toString<int>(values->progress)); newDesc =
newDesc = replaceAll(newDesc,L"{*goal*}",_toString<int>(values->goal)); replaceAll(newDesc, L"{*progress*}", _toString<int>(values->progress));
newDesc = replaceAll(newDesc, L"{*goal*}", _toString<int>(values->goal));
return newDesc; return newDesc;
} }

View file

@ -2,25 +2,27 @@
#include "CompoundGameRuleDefinition.h" #include "CompoundGameRuleDefinition.h"
class CompleteAllRuleDefinition : public CompoundGameRuleDefinition class CompleteAllRuleDefinition : public CompoundGameRuleDefinition {
{
private: private:
typedef struct _packetData typedef struct _packetData {
{
int goal; int goal;
int progress; int progress;
} PacketData; } PacketData;
public: public:
ConsoleGameRules::EGameRuleType getActionType() { return ConsoleGameRules::eGameRuleType_CompleteAllRule; } ConsoleGameRules::EGameRuleType getActionType() {
return ConsoleGameRules::eGameRuleType_CompleteAllRule;
}
virtual void getChildren(std::vector<GameRuleDefinition *> *children); virtual void getChildren(std::vector<GameRuleDefinition*>* children);
virtual bool onUseTile(GameRule *rule, int tileId, int x, int y, int z); virtual bool onUseTile(GameRule* rule, int tileId, int x, int y, int z);
virtual bool onCollectItem(GameRule *rule, std::shared_ptr<ItemInstance> item); virtual bool onCollectItem(GameRule* rule,
std::shared_ptr<ItemInstance> item);
static std::wstring generateDescriptionString(const std::wstring &description, void *data, int dataLength); static std::wstring generateDescriptionString(
const std::wstring& description, void* data, int dataLength);
private: private:
void updateStatus(GameRule *rule); void updateStatus(GameRule* rule);
}; };

View file

@ -4,86 +4,76 @@
#include "CompoundGameRuleDefinition.h" #include "CompoundGameRuleDefinition.h"
#include "ConsoleGameRules.h" #include "ConsoleGameRules.h"
CompoundGameRuleDefinition::CompoundGameRuleDefinition() CompoundGameRuleDefinition::CompoundGameRuleDefinition() {
{
m_lastRuleStatusChanged = NULL; m_lastRuleStatusChanged = NULL;
} }
CompoundGameRuleDefinition::~CompoundGameRuleDefinition() CompoundGameRuleDefinition::~CompoundGameRuleDefinition() {
{ for (AUTO_VAR(it, m_children.begin()); it != m_children.end(); ++it) {
for(AUTO_VAR(it, m_children.begin()); it != m_children.end(); ++it)
{
delete (*it); delete (*it);
} }
} }
void CompoundGameRuleDefinition::getChildren(std::vector<GameRuleDefinition *> *children) void CompoundGameRuleDefinition::getChildren(
{ std::vector<GameRuleDefinition*>* children) {
GameRuleDefinition::getChildren(children); GameRuleDefinition::getChildren(children);
for (AUTO_VAR(it, m_children.begin()); it != m_children.end(); it++) for (AUTO_VAR(it, m_children.begin()); it != m_children.end(); it++)
children->push_back(*it); children->push_back(*it);
} }
GameRuleDefinition *CompoundGameRuleDefinition::addChild(ConsoleGameRules::EGameRuleType ruleType) GameRuleDefinition* CompoundGameRuleDefinition::addChild(
{ ConsoleGameRules::EGameRuleType ruleType) {
GameRuleDefinition *rule = NULL; GameRuleDefinition* rule = NULL;
if(ruleType == ConsoleGameRules::eGameRuleType_CompleteAllRule) if (ruleType == ConsoleGameRules::eGameRuleType_CompleteAllRule) {
{
rule = new CompleteAllRuleDefinition(); rule = new CompleteAllRuleDefinition();
} } else if (ruleType == ConsoleGameRules::eGameRuleType_CollectItemRule) {
else if(ruleType == ConsoleGameRules::eGameRuleType_CollectItemRule)
{
rule = new CollectItemRuleDefinition(); rule = new CollectItemRuleDefinition();
} } else if (ruleType == ConsoleGameRules::eGameRuleType_UseTileRule) {
else if(ruleType == ConsoleGameRules::eGameRuleType_UseTileRule)
{
rule = new UseTileRuleDefinition(); rule = new UseTileRuleDefinition();
} } else if (ruleType == ConsoleGameRules::eGameRuleType_UpdatePlayerRule) {
else if(ruleType == ConsoleGameRules::eGameRuleType_UpdatePlayerRule)
{
rule = new UpdatePlayerRuleDefinition(); rule = new UpdatePlayerRuleDefinition();
} } else {
else
{
#ifndef _CONTENT_PACKAGE #ifndef _CONTENT_PACKAGE
wprintf(L"CompoundGameRuleDefinition: Attempted to add invalid child rule - %d\n", ruleType ); wprintf(
L"CompoundGameRuleDefinition: Attempted to add invalid child rule "
L"- %d\n",
ruleType);
#endif #endif
} }
if(rule != NULL) m_children.push_back(rule); if (rule != NULL) m_children.push_back(rule);
return rule; return rule;
} }
void CompoundGameRuleDefinition::populateGameRule(GameRulesInstance::EGameRulesInstanceType type, GameRule *rule) void CompoundGameRuleDefinition::populateGameRule(
{ GameRulesInstance::EGameRulesInstanceType type, GameRule* rule) {
GameRule *newRule = NULL; GameRule* newRule = NULL;
int i = 0; int i = 0;
for(AUTO_VAR(it, m_children.begin()); it != m_children.end(); ++it) for (AUTO_VAR(it, m_children.begin()); it != m_children.end(); ++it) {
{ newRule = new GameRule(*it, rule->getConnection());
newRule = new GameRule(*it, rule->getConnection() ); (*it)->populateGameRule(type, newRule);
(*it)->populateGameRule(type,newRule);
GameRule::ValueType value; GameRule::ValueType value;
value.gr = newRule; value.gr = newRule;
value.isPointer = true; value.isPointer = true;
// Somehow add the newRule to the current rule // Somehow add the newRule to the current rule
rule->setParameter(L"rule" + _toString<int>(i),value); rule->setParameter(L"rule" + _toString<int>(i), value);
++i; ++i;
} }
GameRuleDefinition::populateGameRule(type, rule); GameRuleDefinition::populateGameRule(type, rule);
} }
bool CompoundGameRuleDefinition::onUseTile(GameRule *rule, int tileId, int x, int y, int z) bool CompoundGameRuleDefinition::onUseTile(GameRule* rule, int tileId, int x,
{ int y, int z) {
bool statusChanged = false; bool statusChanged = false;
for(AUTO_VAR(it, rule->m_parameters.begin()); it != rule->m_parameters.end(); ++it) for (AUTO_VAR(it, rule->m_parameters.begin());
{ it != rule->m_parameters.end(); ++it) {
if(it->second.isPointer) if (it->second.isPointer) {
{ bool changed = it->second.gr->getGameRuleDefinition()->onUseTile(
bool changed = it->second.gr->getGameRuleDefinition()->onUseTile(it->second.gr,tileId,x,y,z); it->second.gr, tileId, x, y, z);
if(!statusChanged && changed) if (!statusChanged && changed) {
{ m_lastRuleStatusChanged =
m_lastRuleStatusChanged = it->second.gr->getGameRuleDefinition(); it->second.gr->getGameRuleDefinition();
statusChanged = true; statusChanged = true;
} }
} }
@ -91,17 +81,18 @@ bool CompoundGameRuleDefinition::onUseTile(GameRule *rule, int tileId, int x, in
return statusChanged; return statusChanged;
} }
bool CompoundGameRuleDefinition::onCollectItem(GameRule *rule, std::shared_ptr<ItemInstance> item) bool CompoundGameRuleDefinition::onCollectItem(
{ GameRule* rule, std::shared_ptr<ItemInstance> item) {
bool statusChanged = false; bool statusChanged = false;
for(AUTO_VAR(it, rule->m_parameters.begin()); it != rule->m_parameters.end(); ++it) for (AUTO_VAR(it, rule->m_parameters.begin());
{ it != rule->m_parameters.end(); ++it) {
if(it->second.isPointer) if (it->second.isPointer) {
{ bool changed =
bool changed = it->second.gr->getGameRuleDefinition()->onCollectItem(it->second.gr,item); it->second.gr->getGameRuleDefinition()->onCollectItem(
if(!statusChanged && changed) it->second.gr, item);
{ if (!statusChanged && changed) {
m_lastRuleStatusChanged = it->second.gr->getGameRuleDefinition(); m_lastRuleStatusChanged =
it->second.gr->getGameRuleDefinition();
statusChanged = true; statusChanged = true;
} }
} }
@ -109,10 +100,9 @@ bool CompoundGameRuleDefinition::onCollectItem(GameRule *rule, std::shared_ptr<I
return statusChanged; return statusChanged;
} }
void CompoundGameRuleDefinition::postProcessPlayer(std::shared_ptr<Player> player) void CompoundGameRuleDefinition::postProcessPlayer(
{ std::shared_ptr<Player> player) {
for(AUTO_VAR(it, m_children.begin()); it != m_children.end(); ++it) for (AUTO_VAR(it, m_children.begin()); it != m_children.end(); ++it) {
{
(*it)->postProcessPlayer(player); (*it)->postProcessPlayer(player);
} }
} }

View file

@ -2,22 +2,26 @@
#include "GameRuleDefinition.h" #include "GameRuleDefinition.h"
class CompoundGameRuleDefinition : public GameRuleDefinition class CompoundGameRuleDefinition : public GameRuleDefinition {
{
protected: protected:
std::vector<GameRuleDefinition *> m_children; std::vector<GameRuleDefinition*> m_children;
protected: protected:
GameRuleDefinition *m_lastRuleStatusChanged; GameRuleDefinition* m_lastRuleStatusChanged;
public: public:
CompoundGameRuleDefinition(); CompoundGameRuleDefinition();
virtual ~CompoundGameRuleDefinition(); virtual ~CompoundGameRuleDefinition();
virtual void getChildren(std::vector<GameRuleDefinition *> *children); virtual void getChildren(std::vector<GameRuleDefinition*>* children);
virtual GameRuleDefinition *addChild(ConsoleGameRules::EGameRuleType ruleType); virtual GameRuleDefinition* addChild(
ConsoleGameRules::EGameRuleType ruleType);
virtual void populateGameRule(GameRulesInstance::EGameRulesInstanceType type, GameRule *rule); virtual void populateGameRule(
GameRulesInstance::EGameRulesInstanceType type, GameRule* rule);
virtual bool onUseTile(GameRule *rule, int tileId, int x, int y, int z); virtual bool onUseTile(GameRule* rule, int tileId, int x, int y, int z);
virtual bool onCollectItem(GameRule *rule, std::shared_ptr<ItemInstance> item); virtual bool onCollectItem(GameRule* rule,
std::shared_ptr<ItemInstance> item);
virtual void postProcessPlayer(std::shared_ptr<Player> player); virtual void postProcessPlayer(std::shared_ptr<Player> player);
}; };

View file

@ -1,14 +1,14 @@
#pragma once #pragma once
//#include " // #include "
class ConsoleGameRules class ConsoleGameRules {
{
public: public:
enum EGameRuleType enum EGameRuleType {
{
eGameRuleType_Invalid = -1, eGameRuleType_Invalid = -1,
eGameRuleType_Root = 0, // This is the top level rule that defines a game mode, this is used to generate data for new players eGameRuleType_Root =
0, // This is the top level rule that defines a game mode, this is
// used to generate data for new players
eGameRuleType_LevelGenerationOptions, eGameRuleType_LevelGenerationOptions,
eGameRuleType_ApplySchematic, eGameRuleType_ApplySchematic,
@ -34,8 +34,7 @@ public:
eGameRuleType_Count eGameRuleType_Count
}; };
enum EGameRuleAttr enum EGameRuleAttr {
{
eGameRuleAttr_Invalid = -1, eGameRuleAttr_Invalid = -1,
eGameRuleAttr_descriptionName = 0, eGameRuleAttr_descriptionName = 0,
@ -106,15 +105,14 @@ public:
eGameRuleAttr_Count eGameRuleAttr_Count
}; };
static void write(DataOutputStream *dos, ConsoleGameRules::EGameRuleType eType) static void write(DataOutputStream* dos,
{ ConsoleGameRules::EGameRuleType eType) {
dos->writeInt(eType); dos->writeInt(eType);
} }
static void write(DataOutputStream *dos, ConsoleGameRules::EGameRuleAttr eAttr) static void write(DataOutputStream* dos,
{ ConsoleGameRules::EGameRuleAttr eAttr) {
dos->writeInt(static_cast<int>(eGameRuleType_Count) + dos->writeInt(static_cast<int>(eGameRuleType_Count) +
static_cast<int>(eAttr)); static_cast<int>(eAttr));
} }
}; };

View file

@ -7,56 +7,49 @@
#include "../../Minecraft.World/Util/StringHelpers.h" #include "../../Minecraft.World/Util/StringHelpers.h"
#include "../../Minecraft.World/Headers/net.minecraft.h" #include "../../Minecraft.World/Headers/net.minecraft.h"
ConsoleGenerateStructure::ConsoleGenerateStructure() : StructurePiece(0) ConsoleGenerateStructure::ConsoleGenerateStructure() : StructurePiece(0) {
{
m_x = m_y = m_z = 0; m_x = m_y = m_z = 0;
boundingBox = NULL; boundingBox = NULL;
orientation = Direction::NORTH; orientation = Direction::NORTH;
m_dimension = 0; m_dimension = 0;
} }
void ConsoleGenerateStructure::getChildren(std::vector<GameRuleDefinition *> *children) void ConsoleGenerateStructure::getChildren(
{ std::vector<GameRuleDefinition*>* children) {
GameRuleDefinition::getChildren(children); GameRuleDefinition::getChildren(children);
for(AUTO_VAR(it, m_actions.begin()); it != m_actions.end(); it++) for (AUTO_VAR(it, m_actions.begin()); it != m_actions.end(); it++)
children->push_back( *it ); children->push_back(*it);
} }
GameRuleDefinition *ConsoleGenerateStructure::addChild(ConsoleGameRules::EGameRuleType ruleType) GameRuleDefinition* ConsoleGenerateStructure::addChild(
{ ConsoleGameRules::EGameRuleType ruleType) {
GameRuleDefinition *rule = NULL; GameRuleDefinition* rule = NULL;
if(ruleType == ConsoleGameRules::eGameRuleType_GenerateBox) if (ruleType == ConsoleGameRules::eGameRuleType_GenerateBox) {
{
rule = new XboxStructureActionGenerateBox(); rule = new XboxStructureActionGenerateBox();
m_actions.push_back((XboxStructureActionGenerateBox *)rule); m_actions.push_back((XboxStructureActionGenerateBox*)rule);
} } else if (ruleType == ConsoleGameRules::eGameRuleType_PlaceBlock) {
else if(ruleType == ConsoleGameRules::eGameRuleType_PlaceBlock)
{
rule = new XboxStructureActionPlaceBlock(); rule = new XboxStructureActionPlaceBlock();
m_actions.push_back((XboxStructureActionPlaceBlock *)rule); m_actions.push_back((XboxStructureActionPlaceBlock*)rule);
} } else if (ruleType == ConsoleGameRules::eGameRuleType_PlaceContainer) {
else if(ruleType == ConsoleGameRules::eGameRuleType_PlaceContainer)
{
rule = new XboxStructureActionPlaceContainer(); rule = new XboxStructureActionPlaceContainer();
m_actions.push_back((XboxStructureActionPlaceContainer *)rule); m_actions.push_back((XboxStructureActionPlaceContainer*)rule);
} } else if (ruleType == ConsoleGameRules::eGameRuleType_PlaceSpawner) {
else if(ruleType == ConsoleGameRules::eGameRuleType_PlaceSpawner)
{
rule = new XboxStructureActionPlaceSpawner(); rule = new XboxStructureActionPlaceSpawner();
m_actions.push_back((XboxStructureActionPlaceSpawner *)rule); m_actions.push_back((XboxStructureActionPlaceSpawner*)rule);
} } else {
else
{
#ifndef _CONTENT_PACKAGE #ifndef _CONTENT_PACKAGE
wprintf(L"ConsoleGenerateStructure: Attempted to add invalid child rule - %d\n", ruleType ); wprintf(
L"ConsoleGenerateStructure: Attempted to add invalid child rule - "
L"%d\n",
ruleType);
#endif #endif
} }
return rule; return rule;
} }
void ConsoleGenerateStructure::writeAttributes(DataOutputStream *dos, unsigned int numAttrs) void ConsoleGenerateStructure::writeAttributes(DataOutputStream* dos,
{ unsigned int numAttrs) {
GameRuleDefinition::writeAttributes(dos, numAttrs + 5); GameRuleDefinition::writeAttributes(dos, numAttrs + 5);
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x); ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x);
@ -72,98 +65,86 @@ void ConsoleGenerateStructure::writeAttributes(DataOutputStream *dos, unsigned i
dos->writeUTF(_toString(m_dimension)); dos->writeUTF(_toString(m_dimension));
} }
void ConsoleGenerateStructure::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue) void ConsoleGenerateStructure::addAttribute(
{ const std::wstring& attributeName, const std::wstring& attributeValue) {
if(attributeName.compare(L"x") == 0) if (attributeName.compare(L"x") == 0) {
{
int value = _fromString<int>(attributeValue); int value = _fromString<int>(attributeValue);
m_x = value; m_x = value;
app.DebugPrintf("ConsoleGenerateStructure: Adding parameter x=%d\n",m_x); app.DebugPrintf("ConsoleGenerateStructure: Adding parameter x=%d\n",
} m_x);
else if(attributeName.compare(L"y") == 0) } else if (attributeName.compare(L"y") == 0) {
{
int value = _fromString<int>(attributeValue); int value = _fromString<int>(attributeValue);
m_y = value; m_y = value;
app.DebugPrintf("ConsoleGenerateStructure: Adding parameter y=%d\n",m_y); app.DebugPrintf("ConsoleGenerateStructure: Adding parameter y=%d\n",
} m_y);
else if(attributeName.compare(L"z") == 0) } else if (attributeName.compare(L"z") == 0) {
{
int value = _fromString<int>(attributeValue); int value = _fromString<int>(attributeValue);
m_z = value; m_z = value;
app.DebugPrintf("ConsoleGenerateStructure: Adding parameter z=%d\n",m_z); app.DebugPrintf("ConsoleGenerateStructure: Adding parameter z=%d\n",
} m_z);
else if(attributeName.compare(L"orientation") == 0) } else if (attributeName.compare(L"orientation") == 0) {
{
int value = _fromString<int>(attributeValue); int value = _fromString<int>(attributeValue);
orientation = value; orientation = value;
app.DebugPrintf("ConsoleGenerateStructure: Adding parameter orientation=%d\n",orientation); app.DebugPrintf(
} "ConsoleGenerateStructure: Adding parameter orientation=%d\n",
else if(attributeName.compare(L"dim") == 0) orientation);
{ } else if (attributeName.compare(L"dim") == 0) {
m_dimension = _fromString<int>(attributeValue); m_dimension = _fromString<int>(attributeValue);
if(m_dimension > 1 || m_dimension < -1) m_dimension = 0; if (m_dimension > 1 || m_dimension < -1) m_dimension = 0;
app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter dimension=%d\n",m_dimension); app.DebugPrintf(
} "ApplySchematicRuleDefinition: Adding parameter dimension=%d\n",
else m_dimension);
{ } else {
GameRuleDefinition::addAttribute(attributeName, attributeValue); GameRuleDefinition::addAttribute(attributeName, attributeValue);
} }
} }
BoundingBox* ConsoleGenerateStructure::getBoundingBox() BoundingBox* ConsoleGenerateStructure::getBoundingBox() {
{ if (boundingBox == NULL) {
if(boundingBox == NULL)
{
// Find the max bounds // Find the max bounds
int maxX, maxY, maxZ; int maxX, maxY, maxZ;
maxX = maxY = maxZ = 1; maxX = maxY = maxZ = 1;
for(AUTO_VAR(it, m_actions.begin()); it != m_actions.end(); ++it) for (AUTO_VAR(it, m_actions.begin()); it != m_actions.end(); ++it) {
{ ConsoleGenerateStructureAction* action = *it;
ConsoleGenerateStructureAction *action = *it; maxX = std::max(maxX, action->getEndX());
maxX = std::max(maxX,action->getEndX()); maxY = std::max(maxY, action->getEndY());
maxY = std::max(maxY,action->getEndY()); maxZ = std::max(maxZ, action->getEndZ());
maxZ = std::max(maxZ,action->getEndZ());
} }
boundingBox = new BoundingBox(m_x, m_y, m_z, m_x + maxX, m_y + maxY, m_z + maxZ); boundingBox =
new BoundingBox(m_x, m_y, m_z, m_x + maxX, m_y + maxY, m_z + maxZ);
} }
return boundingBox; return boundingBox;
} }
bool ConsoleGenerateStructure::postProcess(Level *level, Random *random, BoundingBox *chunkBB) bool ConsoleGenerateStructure::postProcess(Level* level, Random* random,
{ BoundingBox* chunkBB) {
if(level->dimension->id != m_dimension) return false; if (level->dimension->id != m_dimension) return false;
for(AUTO_VAR(it, m_actions.begin()); it != m_actions.end(); ++it) for (AUTO_VAR(it, m_actions.begin()); it != m_actions.end(); ++it) {
{ ConsoleGenerateStructureAction* action = *it;
ConsoleGenerateStructureAction *action = *it;
switch(action->getActionType()) switch (action->getActionType()) {
{ case ConsoleGameRules::eGameRuleType_GenerateBox: {
case ConsoleGameRules::eGameRuleType_GenerateBox: XboxStructureActionGenerateBox* genBox =
{ (XboxStructureActionGenerateBox*)action;
XboxStructureActionGenerateBox *genBox = (XboxStructureActionGenerateBox *)action; genBox->generateBoxInLevel(this, level, chunkBB);
genBox->generateBoxInLevel(this,level,chunkBB); } break;
} case ConsoleGameRules::eGameRuleType_PlaceBlock: {
break; XboxStructureActionPlaceBlock* pPlaceBlock =
case ConsoleGameRules::eGameRuleType_PlaceBlock: (XboxStructureActionPlaceBlock*)action;
{ pPlaceBlock->placeBlockInLevel(this, level, chunkBB);
XboxStructureActionPlaceBlock *pPlaceBlock = (XboxStructureActionPlaceBlock *)action; } break;
pPlaceBlock->placeBlockInLevel(this,level,chunkBB); case ConsoleGameRules::eGameRuleType_PlaceContainer: {
} XboxStructureActionPlaceContainer* pPlaceContainer =
break; (XboxStructureActionPlaceContainer*)action;
case ConsoleGameRules::eGameRuleType_PlaceContainer: pPlaceContainer->placeContainerInLevel(this, level, chunkBB);
{ } break;
XboxStructureActionPlaceContainer *pPlaceContainer = (XboxStructureActionPlaceContainer *)action; case ConsoleGameRules::eGameRuleType_PlaceSpawner: {
pPlaceContainer->placeContainerInLevel(this,level,chunkBB); XboxStructureActionPlaceSpawner* pPlaceSpawner =
} (XboxStructureActionPlaceSpawner*)action;
break; pPlaceSpawner->placeSpawnerInLevel(this, level, chunkBB);
case ConsoleGameRules::eGameRuleType_PlaceSpawner: } break;
{
XboxStructureActionPlaceSpawner *pPlaceSpawner = (XboxStructureActionPlaceSpawner *)action;
pPlaceSpawner->placeSpawnerInLevel(this,level,chunkBB);
}
break;
default: default:
break; break;
}; };
@ -172,12 +153,9 @@ bool ConsoleGenerateStructure::postProcess(Level *level, Random *random, Boundin
return false; return false;
} }
bool ConsoleGenerateStructure::checkIntersects(int x0, int y0, int z0, int x1, int y1, int z1) bool ConsoleGenerateStructure::checkIntersects(int x0, int y0, int z0, int x1,
{ int y1, int z1) {
return getBoundingBox()->intersects(x0,y0,z0,x1,y1,z1); return getBoundingBox()->intersects(x0, y0, z0, x1, y1, z1);
} }
int ConsoleGenerateStructure::getMinY() int ConsoleGenerateStructure::getMinY() { return getBoundingBox()->y0; }
{
return getBoundingBox()->y0;
}

View file

@ -9,28 +9,35 @@ class ConsoleGenerateStructureAction;
class XboxStructureActionPlaceContainer; class XboxStructureActionPlaceContainer;
class GRFObject; class GRFObject;
class ConsoleGenerateStructure : public GameRuleDefinition, public StructurePiece class ConsoleGenerateStructure : public GameRuleDefinition,
{ public StructurePiece {
private: private:
int m_x, m_y, m_z; int m_x, m_y, m_z;
std::vector<ConsoleGenerateStructureAction *> m_actions; std::vector<ConsoleGenerateStructureAction*> m_actions;
int m_dimension; int m_dimension;
public: public:
ConsoleGenerateStructure(); ConsoleGenerateStructure();
virtual ConsoleGameRules::EGameRuleType getActionType() { return ConsoleGameRules::eGameRuleType_GenerateStructure; } virtual ConsoleGameRules::EGameRuleType getActionType() {
return ConsoleGameRules::eGameRuleType_GenerateStructure;
}
virtual void getChildren(std::vector<GameRuleDefinition *> *children); virtual void getChildren(std::vector<GameRuleDefinition*>* children);
virtual GameRuleDefinition *addChild(ConsoleGameRules::EGameRuleType ruleType); virtual GameRuleDefinition* addChild(
ConsoleGameRules::EGameRuleType ruleType);
virtual void writeAttributes(DataOutputStream *dos, unsigned int numAttrs); virtual void writeAttributes(DataOutputStream* dos, unsigned int numAttrs);
virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue); virtual void addAttribute(const std::wstring& attributeName,
const std::wstring& attributeValue);
// StructurePiece // StructurePiece
virtual BoundingBox *getBoundingBox(); virtual BoundingBox* getBoundingBox();
virtual bool postProcess(Level *level, Random *random, BoundingBox *chunkBB); virtual bool postProcess(Level* level, Random* random,
BoundingBox* chunkBB);
void createContainer(XboxStructureActionPlaceContainer *action, Level *level, BoundingBox *chunkBB); void createContainer(XboxStructureActionPlaceContainer* action,
Level* level, BoundingBox* chunkBB);
bool checkIntersects(int x0, int y0, int z0, int x1, int y1, int z1); bool checkIntersects(int x0, int y0, int z0, int x1, int y1, int z1);

View file

@ -2,8 +2,7 @@
#include "GameRuleDefinition.h" #include "GameRuleDefinition.h"
class ConsoleGenerateStructureAction : public GameRuleDefinition class ConsoleGenerateStructureAction : public GameRuleDefinition {
{
public: public:
virtual int getEndX() = 0; virtual int getEndX() = 0;
virtual int getEndY() = 0; virtual int getEndY() = 0;

View file

@ -1,5 +1,5 @@
#pragma once #pragma once
//using namespace std; // using namespace std;
#define XBOX_SCHEMATIC_ORIGINAL_VERSION 1 #define XBOX_SCHEMATIC_ORIGINAL_VERSION 1
#define XBOX_SCHEMATIC_CURRENT_VERSION 2 #define XBOX_SCHEMATIC_CURRENT_VERSION 2
@ -14,16 +14,15 @@ class LevelChunk;
class AABB; class AABB;
class Vec3; class Vec3;
class ConsoleSchematicFile class ConsoleSchematicFile {
{
public: public:
enum ESchematicRotation enum ESchematicRotation {
{
eSchematicRot_0, eSchematicRot_0,
eSchematicRot_90, eSchematicRot_90,
eSchematicRot_180, eSchematicRot_180,
eSchematicRot_270 eSchematicRot_270
}; };
private: private:
int m_refCount; int m_refCount;
@ -32,8 +31,7 @@ public:
void decrementRefCount() { --m_refCount; } void decrementRefCount() { --m_refCount; }
bool shouldDelete() { return m_refCount <= 0; } bool shouldDelete() { return m_refCount <= 0; }
typedef struct _XboxSchematicInitParam typedef struct _XboxSchematicInitParam {
{
wchar_t name[64]; wchar_t name[64];
int startX; int startX;
int startY; int startY;
@ -45,18 +43,18 @@ public:
Compression::ECompressionTypes compressionType; Compression::ECompressionTypes compressionType;
_XboxSchematicInitParam() _XboxSchematicInitParam() {
{ ZeroMemory(name, 64 * (sizeof(wchar_t)));
ZeroMemory(name,64*(sizeof(wchar_t)));
startX = startY = startZ = endX = endY = endZ = 0; startX = startY = startZ = endX = endY = endZ = 0;
bSaveMobs = false; bSaveMobs = false;
compressionType = Compression::eCompressionType_None; compressionType = Compression::eCompressionType_None;
} }
} XboxSchematicInitParam; } XboxSchematicInitParam;
private: private:
int m_xSize, m_ySize, m_zSize; int m_xSize, m_ySize, m_zSize;
std::vector<std::shared_ptr<TileEntity> > m_tileEntities; std::vector<std::shared_ptr<TileEntity> > m_tileEntities;
std::vector< std::pair<Vec3 *, CompoundTag *> > m_entities; std::vector<std::pair<Vec3*, CompoundTag*> > m_entities;
public: public:
byteArray m_data; byteArray m_data;
@ -69,22 +67,42 @@ public:
int getYSize() { return m_ySize; } int getYSize() { return m_ySize; }
int getZSize() { return m_zSize; } int getZSize() { return m_zSize; }
void save(DataOutputStream *dos); void save(DataOutputStream* dos);
void load(DataInputStream *dis); void load(DataInputStream* dis);
__int64 applyBlocksAndData(LevelChunk *chunk, AABB *chunkBox, AABB *destinationBox, ESchematicRotation rot); __int64 applyBlocksAndData(LevelChunk* chunk, AABB* chunkBox,
__int64 applyLighting(LevelChunk *chunk, AABB *chunkBox, AABB *destinationBox, ESchematicRotation rot); AABB* destinationBox, ESchematicRotation rot);
void applyTileEntities(LevelChunk *chunk, AABB *chunkBox, AABB *destinationBox, ESchematicRotation rot); __int64 applyLighting(LevelChunk* chunk, AABB* chunkBox,
AABB* destinationBox, ESchematicRotation rot);
void applyTileEntities(LevelChunk* chunk, AABB* chunkBox,
AABB* destinationBox, ESchematicRotation rot);
static void generateSchematicFile(DataOutputStream* dos, Level* level,
int xStart, int yStart, int zStart,
int xEnd, int yEnd, int zEnd,
bool bSaveMobs,
Compression::ECompressionTypes);
static void setBlocksAndData(LevelChunk* chunk, byteArray blockData,
byteArray dataData, byteArray data, int x0,
int y0, int z0, int x1, int y1, int z1,
int& blocksP, int& dataP, int& blockLightP,
int& skyLightP);
static void generateSchematicFile(DataOutputStream *dos, Level *level, int xStart, int yStart, int zStart, int xEnd, int yEnd, int zEnd, bool bSaveMobs, Compression::ECompressionTypes);
static void setBlocksAndData(LevelChunk *chunk, byteArray blockData, byteArray dataData, byteArray data, int x0, int y0, int z0, int x1, int y1, int z1, int &blocksP, int &dataP, int &blockLightP, int &skyLightP);
private: private:
void save_tags(DataOutputStream *dos); void save_tags(DataOutputStream* dos);
void load_tags(DataInputStream *dis); void load_tags(DataInputStream* dis);
static void getBlocksAndData(LevelChunk *chunk, byteArray *data, int x0, int y0, int z0, int x1, int y1, int z1, int &blocksP, int &dataP, int &blockLightP, int &skyLightP); static void getBlocksAndData(LevelChunk* chunk, byteArray* data, int x0,
static std::vector<std::shared_ptr<TileEntity> > *getTileEntitiesInRegion(LevelChunk *chunk, int x0, int y0, int z0, int x1, int y1, int z1); int y0, int z0, int x1, int y1, int z1,
int& blocksP, int& dataP, int& blockLightP,
int& skyLightP);
static std::vector<std::shared_ptr<TileEntity> >* getTileEntitiesInRegion(
LevelChunk* chunk, int x0, int y0, int z0, int x1, int y1, int z1);
void chunkCoordToSchematicCoord(AABB *destinationBox, int chunkX, int chunkZ, ESchematicRotation rot, int &schematicX, int &schematicZ); void chunkCoordToSchematicCoord(AABB* destinationBox, int chunkX,
void schematicCoordToChunkCoord(AABB *destinationBox, double schematicX, double schematicZ, ESchematicRotation rot, double &chunkX, double &chunkZ); int chunkZ, ESchematicRotation rot,
int& schematicX, int& schematicZ);
void schematicCoordToChunkCoord(AABB* destinationBox, double schematicX,
double schematicZ, ESchematicRotation rot,
double& chunkX, double& chunkZ);
}; };

View file

@ -1,45 +1,37 @@
#include "../../Minecraft.World/Platform/stdafx.h" #include "../../Minecraft.World/Platform/stdafx.h"
#include "ConsoleGameRules.h" #include "ConsoleGameRules.h"
GameRule::GameRule(GameRuleDefinition *definition, Connection *connection) GameRule::GameRule(GameRuleDefinition* definition, Connection* connection) {
{
m_definition = definition; m_definition = definition;
m_connection = connection; m_connection = connection;
} }
GameRule::~GameRule() GameRule::~GameRule() {
{ for (AUTO_VAR(it, m_parameters.begin()); it != m_parameters.end(); ++it) {
for(AUTO_VAR(it, m_parameters.begin()); it != m_parameters.end(); ++it) if (it->second.isPointer) {
{
if(it->second.isPointer)
{
delete it->second.gr; delete it->second.gr;
} }
} }
} }
GameRule::ValueType GameRule::getParameter(const std::wstring &parameterName) GameRule::ValueType GameRule::getParameter(const std::wstring& parameterName) {
{ if (m_parameters.find(parameterName) == m_parameters.end()) {
if(m_parameters.find(parameterName) == m_parameters.end())
{
#ifndef _CONTENT_PACKAGE #ifndef _CONTENT_PACKAGE
wprintf(L"WARNING: Parameter %ls was not set before being fetched\n", parameterName.c_str()); wprintf(L"WARNING: Parameter %ls was not set before being fetched\n",
parameterName.c_str());
__debugbreak(); __debugbreak();
#endif #endif
} }
return m_parameters[parameterName]; return m_parameters[parameterName];
} }
void GameRule::setParameter(const std::wstring &parameterName,ValueType value) void GameRule::setParameter(const std::wstring& parameterName,
{ ValueType value) {
if(m_parameters.find(parameterName) == m_parameters.end()) if (m_parameters.find(parameterName) == m_parameters.end()) {
{
#ifndef _CONTENT_PACKAGE #ifndef _CONTENT_PACKAGE
wprintf(L"Adding parameter %ls to GameRule\n", parameterName.c_str()); wprintf(L"Adding parameter %ls to GameRule\n", parameterName.c_str());
#endif #endif
} } else {
else
{
#ifndef _CONTENT_PACKAGE #ifndef _CONTENT_PACKAGE
wprintf(L"Setting parameter %ls for GameRule\n", parameterName.c_str()); wprintf(L"Setting parameter %ls for GameRule\n", parameterName.c_str());
#endif #endif
@ -47,48 +39,42 @@ void GameRule::setParameter(const std::wstring &parameterName,ValueType value)
m_parameters[parameterName] = value; m_parameters[parameterName] = value;
} }
GameRuleDefinition *GameRule::getGameRuleDefinition() GameRuleDefinition* GameRule::getGameRuleDefinition() { return m_definition; }
{
return m_definition; void GameRule::onUseTile(int tileId, int x, int y, int z) {
m_definition->onUseTile(this, tileId, x, y, z);
}
void GameRule::onCollectItem(std::shared_ptr<ItemInstance> item) {
m_definition->onCollectItem(this, item);
} }
void GameRule::onUseTile(int tileId, int x, int y, int z) { m_definition->onUseTile(this,tileId,x,y,z); } void GameRule::write(DataOutputStream* dos) {
void GameRule::onCollectItem(std::shared_ptr<ItemInstance> item) { m_definition->onCollectItem(this,item); }
void GameRule::write(DataOutputStream *dos)
{
// Find required parameters. // Find required parameters.
dos->writeInt(m_parameters.size()); dos->writeInt(m_parameters.size());
for (AUTO_VAR(it, m_parameters.begin()); it != m_parameters.end(); it++) for (AUTO_VAR(it, m_parameters.begin()); it != m_parameters.end(); it++) {
{
std::wstring pName = (*it).first; std::wstring pName = (*it).first;
ValueType vType = (*it).second; ValueType vType = (*it).second;
dos->writeUTF( (*it).first ); dos->writeUTF((*it).first);
dos->writeBoolean( vType.isPointer ); dos->writeBoolean(vType.isPointer);
if (vType.isPointer) if (vType.isPointer)
vType.gr->write(dos); vType.gr->write(dos);
else else
dos->writeLong( vType.i64 ); dos->writeLong(vType.i64);
} }
} }
void GameRule::read(DataInputStream *dis) void GameRule::read(DataInputStream* dis) {
{
int savedParams = dis->readInt(); int savedParams = dis->readInt();
for (int i = 0; i < savedParams; i++) for (int i = 0; i < savedParams; i++) {
{
std::wstring pNames = dis->readUTF(); std::wstring pNames = dis->readUTF();
ValueType vType = getParameter(pNames); ValueType vType = getParameter(pNames);
if (dis->readBoolean()) if (dis->readBoolean()) {
{
vType.gr->read(dis); vType.gr->read(dis);
} } else {
else
{
vType.isPointer = false; vType.isPointer = false;
vType.i64 = dis->readLong(); vType.i64 = dis->readLong();
setParameter(pNames, vType); setParameter(pNames, vType);

View file

@ -1,5 +1,5 @@
#pragma once #pragma once
//using namespace std; // using namespace std;
#include <unordered_map> #include <unordered_map>
@ -8,55 +8,54 @@ class GameRuleDefinition;
class Connection; class Connection;
// A game rule maintains the state for one particular definition // A game rule maintains the state for one particular definition
class GameRule class GameRule {
{
public: public:
typedef struct _ValueType typedef struct _ValueType {
{ union {
union{
__int64 i64; __int64 i64;
int i; int i;
char c; char c;
bool b; bool b;
float f; float f;
double d; double d;
GameRule *gr; GameRule* gr;
}; };
bool isPointer; bool isPointer;
_ValueType() _ValueType() {
{
i64 = 0; i64 = 0;
isPointer = false; isPointer = false;
} }
} ValueType; } ValueType;
private: private:
GameRuleDefinition *m_definition; GameRuleDefinition* m_definition;
Connection *m_connection; Connection* m_connection;
public: public:
typedef std::unordered_map<std::wstring,ValueType> stringValueMapType; typedef std::unordered_map<std::wstring, ValueType> stringValueMapType;
stringValueMapType m_parameters; // These are the members of this rule that maintain it's state stringValueMapType m_parameters; // These are the members of this rule that
// maintain it's state
public: public:
GameRule(GameRuleDefinition *definition, Connection *connection = NULL); GameRule(GameRuleDefinition* definition, Connection* connection = NULL);
virtual ~GameRule(); virtual ~GameRule();
Connection *getConnection() { return m_connection; } Connection* getConnection() { return m_connection; }
ValueType getParameter(const std::wstring &parameterName); ValueType getParameter(const std::wstring& parameterName);
void setParameter(const std::wstring &parameterName,ValueType value); void setParameter(const std::wstring& parameterName, ValueType value);
GameRuleDefinition *getGameRuleDefinition(); GameRuleDefinition* getGameRuleDefinition();
// All the hooks go here // All the hooks go here
void onUseTile(int tileId, int x, int y, int z); void onUseTile(int tileId, int x, int y, int z);
void onCollectItem(std::shared_ptr<ItemInstance> item); void onCollectItem(std::shared_ptr<ItemInstance> item);
// 4J-JEV: For saving. // 4J-JEV: For saving.
//CompoundTag *toTags(std::unordered_map<GameRuleDefinition *, int> *map); // CompoundTag *toTags(std::unordered_map<GameRuleDefinition *, int> *map);
//static GameRule *fromTags(Connection *c, CompoundTag *cTag, std::vector<GameRuleDefinition *> *grds); // static GameRule *fromTags(Connection *c, CompoundTag *cTag,
// std::vector<GameRuleDefinition *> *grds);
void write(DataOutputStream *dos); void write(DataOutputStream* dos);
void read(DataInputStream *dos); void read(DataInputStream* dos);
}; };

View file

@ -3,37 +3,37 @@
#include "../../Minecraft.World/Util/StringHelpers.h" #include "../../Minecraft.World/Util/StringHelpers.h"
#include "ConsoleGameRules.h" #include "ConsoleGameRules.h"
GameRuleDefinition::GameRuleDefinition() GameRuleDefinition::GameRuleDefinition() {
{
m_descriptionId = L""; m_descriptionId = L"";
m_promptId = L""; m_promptId = L"";
m_4JDataValue = 0; m_4JDataValue = 0;
} }
void GameRuleDefinition::write(DataOutputStream *dos) void GameRuleDefinition::write(DataOutputStream* dos) {
{
// Write EGameRuleType. // Write EGameRuleType.
ConsoleGameRules::EGameRuleType eType = getActionType(); ConsoleGameRules::EGameRuleType eType = getActionType();
assert( eType != ConsoleGameRules::eGameRuleType_Invalid ); assert(eType != ConsoleGameRules::eGameRuleType_Invalid);
ConsoleGameRules::write(dos, eType); // stringID ConsoleGameRules::write(dos, eType); // stringID
writeAttributes(dos, 0); writeAttributes(dos, 0);
// 4J-JEV: Get children. // 4J-JEV: Get children.
std::vector<GameRuleDefinition *> *children = new std::vector<GameRuleDefinition *>(); std::vector<GameRuleDefinition*>* children =
getChildren( children ); new std::vector<GameRuleDefinition*>();
getChildren(children);
// Write children. // Write children.
dos->writeInt( children->size() ); dos->writeInt(children->size());
for (AUTO_VAR(it, children->begin()); it != children->end(); it++) for (AUTO_VAR(it, children->begin()); it != children->end(); it++)
(*it)->write(dos); (*it)->write(dos);
} }
void GameRuleDefinition::writeAttributes(DataOutputStream *dos, unsigned int numAttributes) void GameRuleDefinition::writeAttributes(DataOutputStream* dos,
{ unsigned int numAttributes) {
dos->writeInt(numAttributes + 3); dos->writeInt(numAttributes + 3);
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_descriptionName); ConsoleGameRules::write(dos,
ConsoleGameRules::eGameRuleAttr_descriptionName);
dos->writeUTF(m_descriptionId); dos->writeUTF(m_descriptionId);
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_promptName); ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_promptName);
@ -43,106 +43,106 @@ void GameRuleDefinition::writeAttributes(DataOutputStream *dos, unsigned int num
dos->writeUTF(_toString(m_4JDataValue)); dos->writeUTF(_toString(m_4JDataValue));
} }
void GameRuleDefinition::getChildren(std::vector<GameRuleDefinition *> *children) {} void GameRuleDefinition::getChildren(
std::vector<GameRuleDefinition*>* children) {}
GameRuleDefinition *GameRuleDefinition::addChild(ConsoleGameRules::EGameRuleType ruleType) GameRuleDefinition* GameRuleDefinition::addChild(
{ ConsoleGameRules::EGameRuleType ruleType) {
#ifndef _CONTENT_PACKAGE #ifndef _CONTENT_PACKAGE
wprintf(L"GameRuleDefinition: Attempted to add invalid child rule - %d\n", ruleType ); wprintf(L"GameRuleDefinition: Attempted to add invalid child rule - %d\n",
ruleType);
#endif #endif
return NULL; return NULL;
} }
void GameRuleDefinition::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue) void GameRuleDefinition::addAttribute(const std::wstring& attributeName,
{ const std::wstring& attributeValue) {
if(attributeName.compare(L"descriptionName") == 0) if (attributeName.compare(L"descriptionName") == 0) {
{
m_descriptionId = attributeValue; m_descriptionId = attributeValue;
#ifndef _CONTENT_PACKAGE #ifndef _CONTENT_PACKAGE
wprintf(L"GameRuleDefinition: Adding parameter descriptionId=%ls\n",m_descriptionId.c_str()); wprintf(L"GameRuleDefinition: Adding parameter descriptionId=%ls\n",
m_descriptionId.c_str());
#endif #endif
} } else if (attributeName.compare(L"promptName") == 0) {
else if(attributeName.compare(L"promptName") == 0)
{
m_promptId = attributeValue; m_promptId = attributeValue;
#ifndef _CONTENT_PACKAGE #ifndef _CONTENT_PACKAGE
wprintf(L"GameRuleDefinition: Adding parameter m_promptId=%ls\n",m_promptId.c_str()); wprintf(L"GameRuleDefinition: Adding parameter m_promptId=%ls\n",
m_promptId.c_str());
#endif #endif
} } else if (attributeName.compare(L"dataTag") == 0) {
else if(attributeName.compare(L"dataTag") == 0)
{
m_4JDataValue = _fromString<int>(attributeValue); m_4JDataValue = _fromString<int>(attributeValue);
app.DebugPrintf("GameRuleDefinition: Adding parameter m_4JDataValue=%d\n",m_4JDataValue); app.DebugPrintf(
} "GameRuleDefinition: Adding parameter m_4JDataValue=%d\n",
else m_4JDataValue);
{ } else {
#ifndef _CONTENT_PACKAGE #ifndef _CONTENT_PACKAGE
wprintf(L"GameRuleDefinition: Attempted to add invalid attribute: %ls\n", attributeName.c_str()); wprintf(
L"GameRuleDefinition: Attempted to add invalid attribute: %ls\n",
attributeName.c_str());
#endif #endif
} }
} }
void GameRuleDefinition::populateGameRule(GameRulesInstance::EGameRulesInstanceType type, GameRule *rule) void GameRuleDefinition::populateGameRule(
{ GameRulesInstance::EGameRulesInstanceType type, GameRule* rule) {
GameRule::ValueType value; GameRule::ValueType value;
value.b = false; value.b = false;
rule->setParameter(L"bComplete",value); rule->setParameter(L"bComplete", value);
} }
bool GameRuleDefinition::getComplete(GameRule *rule) bool GameRuleDefinition::getComplete(GameRule* rule) {
{
GameRule::ValueType value; GameRule::ValueType value;
value = rule->getParameter(L"bComplete"); value = rule->getParameter(L"bComplete");
return value.b; return value.b;
} }
void GameRuleDefinition::setComplete(GameRule *rule, bool val) void GameRuleDefinition::setComplete(GameRule* rule, bool val) {
{
GameRule::ValueType value; GameRule::ValueType value;
value = rule->getParameter(L"bComplete"); value = rule->getParameter(L"bComplete");
value.b = val; value.b = val;
rule->setParameter(L"bComplete",value); rule->setParameter(L"bComplete", value);
} }
std::vector<GameRuleDefinition *> *GameRuleDefinition::enumerate() std::vector<GameRuleDefinition*>* GameRuleDefinition::enumerate() {
{
// Get Vector. // Get Vector.
std::vector<GameRuleDefinition *> *gRules; std::vector<GameRuleDefinition*>* gRules;
gRules = new std::vector<GameRuleDefinition *>(); gRules = new std::vector<GameRuleDefinition*>();
gRules->push_back(this); gRules->push_back(this);
getChildren(gRules); getChildren(gRules);
return gRules; return gRules;
} }
std::unordered_map<GameRuleDefinition *, int> *GameRuleDefinition::enumerateMap() std::unordered_map<GameRuleDefinition*, int>*
{ GameRuleDefinition::enumerateMap() {
std::unordered_map<GameRuleDefinition *, int> *out std::unordered_map<GameRuleDefinition*, int>* out =
= new std::unordered_map<GameRuleDefinition *, int>(); new std::unordered_map<GameRuleDefinition*, int>();
int i = 0; int i = 0;
std::vector<GameRuleDefinition *> *gRules = enumerate(); std::vector<GameRuleDefinition*>* gRules = enumerate();
for (AUTO_VAR(it, gRules->begin()); it != gRules->end(); it++) for (AUTO_VAR(it, gRules->begin()); it != gRules->end(); it++)
out->insert( std::pair<GameRuleDefinition *, int>( *it, i++ ) ); out->insert(std::pair<GameRuleDefinition*, int>(*it, i++));
return out; return out;
} }
GameRulesInstance *GameRuleDefinition::generateNewGameRulesInstance(GameRulesInstance::EGameRulesInstanceType type, LevelRuleset *rules, Connection *connection) GameRulesInstance* GameRuleDefinition::generateNewGameRulesInstance(
{ GameRulesInstance::EGameRulesInstanceType type, LevelRuleset* rules,
GameRulesInstance *manager = new GameRulesInstance(rules, connection); Connection* connection) {
GameRulesInstance* manager = new GameRulesInstance(rules, connection);
rules->populateGameRule(type, manager); rules->populateGameRule(type, manager);
return manager; return manager;
} }
std::wstring GameRuleDefinition::generateDescriptionString(ConsoleGameRules::EGameRuleType defType, const std::wstring &description, void *data, int dataLength) std::wstring GameRuleDefinition::generateDescriptionString(
{ ConsoleGameRules::EGameRuleType defType, const std::wstring& description,
void* data, int dataLength) {
std::wstring formatted = description; std::wstring formatted = description;
switch(defType) switch (defType) {
{
case ConsoleGameRules::eGameRuleType_CompleteAllRule: case ConsoleGameRules::eGameRuleType_CompleteAllRule:
formatted = CompleteAllRuleDefinition::generateDescriptionString(description,data,dataLength); formatted = CompleteAllRuleDefinition::generateDescriptionString(
description, data, dataLength);
break; break;
default: default:
break; break;

View file

@ -1,5 +1,5 @@
#pragma once #pragma once
//using namespace std; // using namespace std;
#include <unordered_map> #include <unordered_map>
#include <string> #include <string>
@ -13,8 +13,7 @@ class LevelRuleset;
class Player; class Player;
class WstringLookup; class WstringLookup;
class GameRuleDefinition class GameRuleDefinition {
{
private: private:
// Owner type defines who this rule applies to // Owner type defines who this rule applies to
GameRulesInstance::EGameRulesInstanceType m_ownerType; GameRulesInstance::EGameRulesInstanceType m_ownerType;
@ -27,41 +26,56 @@ protected:
public: public:
GameRuleDefinition(); GameRuleDefinition();
virtual ~GameRuleDefinition(){} virtual ~GameRuleDefinition() {}
virtual ConsoleGameRules::EGameRuleType getActionType() = 0; virtual ConsoleGameRules::EGameRuleType getActionType() = 0;
void setOwnerType(GameRulesInstance::EGameRulesInstanceType ownerType) { m_ownerType = ownerType;} void setOwnerType(GameRulesInstance::EGameRulesInstanceType ownerType) {
m_ownerType = ownerType;
}
virtual void write(DataOutputStream *); virtual void write(DataOutputStream*);
virtual void writeAttributes(DataOutputStream *dos, unsigned int numAttributes); virtual void writeAttributes(DataOutputStream* dos,
virtual void getChildren(std::vector<GameRuleDefinition *> *); unsigned int numAttributes);
virtual void getChildren(std::vector<GameRuleDefinition*>*);
virtual GameRuleDefinition *addChild(ConsoleGameRules::EGameRuleType ruleType); virtual GameRuleDefinition* addChild(
virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue); ConsoleGameRules::EGameRuleType ruleType);
virtual void addAttribute(const std::wstring& attributeName,
const std::wstring& attributeValue);
virtual void populateGameRule(GameRulesInstance::EGameRulesInstanceType type, GameRule *rule); virtual void populateGameRule(
GameRulesInstance::EGameRulesInstanceType type, GameRule* rule);
bool getComplete(GameRule *rule); bool getComplete(GameRule* rule);
void setComplete(GameRule *rule, bool val); void setComplete(GameRule* rule, bool val);
virtual int getGoal() { return 0; } virtual int getGoal() { return 0; }
virtual int getProgress(GameRule *rule) { return 0; } virtual int getProgress(GameRule* rule) { return 0; }
virtual int getIcon() { return -1; } virtual int getIcon() { return -1; }
virtual int getAuxValue() { return 0; } virtual int getAuxValue() { return 0; }
// Here we should have functions for all the hooks, with a GameRule* as the first parameter // Here we should have functions for all the hooks, with a GameRule* as the
virtual bool onUseTile(GameRule *rule, int tileId, int x, int y, int z) { return false; } // first parameter
virtual bool onCollectItem(GameRule *rule, std::shared_ptr<ItemInstance> item) { return false; } virtual bool onUseTile(GameRule* rule, int tileId, int x, int y, int z) {
virtual void postProcessPlayer(std::shared_ptr<Player> player) { } return false;
}
virtual bool onCollectItem(GameRule* rule,
std::shared_ptr<ItemInstance> item) {
return false;
}
virtual void postProcessPlayer(std::shared_ptr<Player> player) {}
std::vector<GameRuleDefinition *> *enumerate(); std::vector<GameRuleDefinition*>* enumerate();
std::unordered_map<GameRuleDefinition *, int> *enumerateMap(); std::unordered_map<GameRuleDefinition*, int>* enumerateMap();
// Static functions // Static functions
static GameRulesInstance *generateNewGameRulesInstance(GameRulesInstance::EGameRulesInstanceType type, LevelRuleset *rules, Connection *connection); static GameRulesInstance* generateNewGameRulesInstance(
static std::wstring generateDescriptionString(ConsoleGameRules::EGameRuleType defType, const std::wstring &description, void *data = NULL, int dataLength = 0); GameRulesInstance::EGameRulesInstanceType type, LevelRuleset* rules,
Connection* connection);
static std::wstring generateDescriptionString(
ConsoleGameRules::EGameRuleType defType,
const std::wstring& description, void* data = NULL, int dataLength = 0);
}; };

View file

@ -12,8 +12,7 @@
#include "ConsoleGameRules.h" #include "ConsoleGameRules.h"
#include "GameRuleManager.h" #include "GameRuleManager.h"
const WCHAR *GameRuleManager::wchTagNameA[] = const WCHAR* GameRuleManager::wchTagNameA[] = {
{
L"", // eGameRuleType_Root L"", // eGameRuleType_Root
L"MapOptions", // eGameRuleType_LevelGenerationOptions L"MapOptions", // eGameRuleType_LevelGenerationOptions
L"ApplySchematic", // eGameRuleType_ApplySchematic L"ApplySchematic", // eGameRuleType_ApplySchematic
@ -34,8 +33,7 @@ const WCHAR *GameRuleManager::wchTagNameA[] =
L"UpdatePlayer", // eGameRuleType_UpdatePlayerRule L"UpdatePlayer", // eGameRuleType_UpdatePlayerRule
}; };
const WCHAR *GameRuleManager::wchAttrNameA[] = const WCHAR* GameRuleManager::wchAttrNameA[] = {
{
L"descriptionName", // eGameRuleAttr_descriptionName L"descriptionName", // eGameRuleAttr_descriptionName
L"promptName", // eGameRuleAttr_promptName L"promptName", // eGameRuleAttr_promptName
L"dataTag", // eGameRuleAttr_dataTag L"dataTag", // eGameRuleAttr_dataTag
@ -83,89 +81,94 @@ const WCHAR *GameRuleManager::wchAttrNameA[] =
L"feature", // eGameRuleAttr_feature L"feature", // eGameRuleAttr_feature
}; };
GameRuleManager::GameRuleManager() GameRuleManager::GameRuleManager() {
{
m_currentGameRuleDefinitions = NULL; m_currentGameRuleDefinitions = NULL;
m_currentLevelGenerationOptions = NULL; m_currentLevelGenerationOptions = NULL;
} }
void GameRuleManager::loadGameRules(DLCPack *pack) void GameRuleManager::loadGameRules(DLCPack* pack) {
{ StringTable* strings = NULL;
StringTable *strings = NULL;
if(pack->doesPackContainFile(DLCManager::e_DLCType_LocalisationData,L"languages.loc")) if (pack->doesPackContainFile(DLCManager::e_DLCType_LocalisationData,
{ L"languages.loc")) {
DLCLocalisationFile *localisationFile = (DLCLocalisationFile *)pack->getFile(DLCManager::e_DLCType_LocalisationData, L"languages.loc"); DLCLocalisationFile* localisationFile =
(DLCLocalisationFile*)pack->getFile(
DLCManager::e_DLCType_LocalisationData, L"languages.loc");
strings = localisationFile->getStringTable(); strings = localisationFile->getStringTable();
} }
int gameRulesCount = pack->getDLCItemsCount(DLCManager::e_DLCType_GameRulesHeader); int gameRulesCount =
for(int i = 0; i < gameRulesCount; ++i) pack->getDLCItemsCount(DLCManager::e_DLCType_GameRulesHeader);
{ for (int i = 0; i < gameRulesCount; ++i) {
DLCGameRulesHeader *dlcHeader = (DLCGameRulesHeader *)pack->getFile(DLCManager::e_DLCType_GameRulesHeader, i); DLCGameRulesHeader* dlcHeader = (DLCGameRulesHeader*)pack->getFile(
DLCManager::e_DLCType_GameRulesHeader, i);
std::uint32_t dSize; std::uint32_t dSize;
uint8_t *dData = dlcHeader->getData(dSize); uint8_t* dData = dlcHeader->getData(dSize);
LevelGenerationOptions *createdLevelGenerationOptions = new LevelGenerationOptions(); LevelGenerationOptions* createdLevelGenerationOptions =
new LevelGenerationOptions();
// = loadGameRules(dData, dSize); //, strings); // = loadGameRules(dData, dSize); //, strings);
createdLevelGenerationOptions->setGrSource( dlcHeader ); createdLevelGenerationOptions->setGrSource(dlcHeader);
readRuleFile(createdLevelGenerationOptions, dData, dSize, strings); readRuleFile(createdLevelGenerationOptions, dData, dSize, strings);
createdLevelGenerationOptions->setSrc( LevelGenerationOptions::eSrc_fromDLC ); createdLevelGenerationOptions->setSrc(
LevelGenerationOptions::eSrc_fromDLC);
// createdLevelGenerationOptions->setSrc(
//createdLevelGenerationOptions->setSrc( LevelGenerationOptions::eSrc_fromDLC ); // LevelGenerationOptions::eSrc_fromDLC );
dlcHeader->lgo = createdLevelGenerationOptions; dlcHeader->lgo = createdLevelGenerationOptions;
} }
gameRulesCount = pack->getDLCItemsCount(DLCManager::e_DLCType_GameRules); gameRulesCount = pack->getDLCItemsCount(DLCManager::e_DLCType_GameRules);
for (int i = 0; i < gameRulesCount; ++i) for (int i = 0; i < gameRulesCount; ++i) {
{ DLCGameRulesFile* dlcFile = (DLCGameRulesFile*)pack->getFile(
DLCGameRulesFile *dlcFile = (DLCGameRulesFile *)pack->getFile(DLCManager::e_DLCType_GameRules, i); DLCManager::e_DLCType_GameRules, i);
std::uint32_t dSize; std::uint32_t dSize;
uint8_t *dData = dlcFile->getData(dSize); uint8_t* dData = dlcFile->getData(dSize);
LevelGenerationOptions *createdLevelGenerationOptions = new LevelGenerationOptions(); LevelGenerationOptions* createdLevelGenerationOptions =
new LevelGenerationOptions();
// = loadGameRules(dData, dSize); //, strings); // = loadGameRules(dData, dSize); //, strings);
createdLevelGenerationOptions->setGrSource( new JustGrSource() ); createdLevelGenerationOptions->setGrSource(new JustGrSource());
readRuleFile(createdLevelGenerationOptions, dData, dSize, strings); readRuleFile(createdLevelGenerationOptions, dData, dSize, strings);
createdLevelGenerationOptions->setSrc( LevelGenerationOptions::eSrc_tutorial ); createdLevelGenerationOptions->setSrc(
LevelGenerationOptions::eSrc_tutorial);
//createdLevelGenerationOptions->set_DLCGameRulesFile( dlcFile ); // createdLevelGenerationOptions->set_DLCGameRulesFile( dlcFile );
createdLevelGenerationOptions->setLoadedData(); createdLevelGenerationOptions->setLoadedData();
} }
} }
LevelGenerationOptions *GameRuleManager::loadGameRules(uint8_t *dIn, unsigned int dSize) LevelGenerationOptions* GameRuleManager::loadGameRules(uint8_t* dIn,
{ unsigned int dSize) {
LevelGenerationOptions *lgo = new LevelGenerationOptions(); LevelGenerationOptions* lgo = new LevelGenerationOptions();
lgo->setGrSource( new JustGrSource() ); lgo->setGrSource(new JustGrSource());
lgo->setSrc( LevelGenerationOptions::eSrc_fromSave ); lgo->setSrc(LevelGenerationOptions::eSrc_fromSave);
loadGameRules(lgo, dIn, dSize); loadGameRules(lgo, dIn, dSize);
lgo->setLoadedData(); lgo->setLoadedData();
return lgo; return lgo;
} }
// 4J-JEV: Reverse of saveGameRules. // 4J-JEV: Reverse of saveGameRules.
void GameRuleManager::loadGameRules(LevelGenerationOptions *lgo, uint8_t *dIn, unsigned int dSize) void GameRuleManager::loadGameRules(LevelGenerationOptions* lgo, uint8_t* dIn,
{ unsigned int dSize) {
app.DebugPrintf("GameRuleManager::LoadingGameRules:\n"); app.DebugPrintf("GameRuleManager::LoadingGameRules:\n");
ByteArrayInputStream bais( byteArray(dIn,dSize) ); ByteArrayInputStream bais(byteArray(dIn, dSize));
DataInputStream dis(&bais); DataInputStream dis(&bais);
// Read file header. // Read file header.
//dis.readInt(); // File Size // dis.readInt(); // File Size
short version = dis.readShort(); short version = dis.readShort();
assert( 0x1 == version ); assert(0x1 == version);
app.DebugPrintf("\tversion=%d.\n", version); app.DebugPrintf("\tversion=%d.\n", version);
for (int i = 0; i < 8; i++) dis.readByte(); for (int i = 0; i < 8; i++) dis.readByte();
@ -178,8 +181,8 @@ void GameRuleManager::loadGameRules(LevelGenerationOptions *lgo, uint8_t *dIn, u
compr_len = dis.readInt(); compr_len = dis.readInt();
decomp_len = dis.readInt(); decomp_len = dis.readInt();
app.DebugPrintf("\tcompr_len=%d.\n\tdecomp_len=%d.\n", compr_len, decomp_len); app.DebugPrintf("\tcompr_len=%d.\n\tdecomp_len=%d.\n", compr_len,
decomp_len);
// Decompress File Body // Decompress File Body
@ -187,64 +190,63 @@ void GameRuleManager::loadGameRules(LevelGenerationOptions *lgo, uint8_t *dIn, u
compr_content(new std::uint8_t[compr_len], compr_len); compr_content(new std::uint8_t[compr_len], compr_len);
dis.read(compr_content); dis.read(compr_content);
Compression::getCompression()->SetDecompressionType( (Compression::ECompressionTypes)compression_type ); Compression::getCompression()->SetDecompressionType(
Compression::getCompression()->DecompressLZXRLE( content.data, &content.length, (Compression::ECompressionTypes)compression_type);
compr_content.data, compr_content.length); Compression::getCompression()->DecompressLZXRLE(
Compression::getCompression()->SetDecompressionType( SAVE_FILE_PLATFORM_LOCAL ); content.data, &content.length, compr_content.data,
compr_content.length);
Compression::getCompression()->SetDecompressionType(
SAVE_FILE_PLATFORM_LOCAL);
dis.close(); dis.close();
bais.close(); bais.close();
delete [] compr_content.data; delete[] compr_content.data;
ByteArrayInputStream bais2( content ); ByteArrayInputStream bais2(content);
DataInputStream dis2( &bais2 ); DataInputStream dis2(&bais2);
// Read StringTable. // Read StringTable.
byteArray bStringTable; byteArray bStringTable;
bStringTable.length = dis2.readInt(); bStringTable.length = dis2.readInt();
bStringTable.data = new std::uint8_t[ bStringTable.length ]; bStringTable.data = new std::uint8_t[bStringTable.length];
dis2.read(bStringTable); dis2.read(bStringTable);
StringTable *strings = new StringTable(bStringTable.data, bStringTable.length); StringTable* strings =
new StringTable(bStringTable.data, bStringTable.length);
// Read RuleFile. // Read RuleFile.
byteArray bRuleFile; byteArray bRuleFile;
bRuleFile.length = content.length - bStringTable.length; bRuleFile.length = content.length - bStringTable.length;
bRuleFile.data = new std::uint8_t[ bRuleFile.length ]; bRuleFile.data = new std::uint8_t[bRuleFile.length];
dis2.read(bRuleFile); dis2.read(bRuleFile);
// 4J-JEV: I don't believe that the path-name is ever used. // 4J-JEV: I don't believe that the path-name is ever used.
//DLCGameRulesFile *dlcgr = new DLCGameRulesFile(L"__PLACEHOLDER__"); // DLCGameRulesFile *dlcgr = new DLCGameRulesFile(L"__PLACEHOLDER__");
//dlcgr->addData(bRuleFile.data,bRuleFile.length); // dlcgr->addData(bRuleFile.data,bRuleFile.length);
if (readRuleFile(lgo, bRuleFile.data, bRuleFile.length, strings)) if (readRuleFile(lgo, bRuleFile.data, bRuleFile.length, strings)) {
{
// Set current gen options and ruleset. // Set current gen options and ruleset.
//createdLevelGenerationOptions->setFromSaveGame(true); // createdLevelGenerationOptions->setFromSaveGame(true);
lgo->setSrc(LevelGenerationOptions::eSrc_fromSave); lgo->setSrc(LevelGenerationOptions::eSrc_fromSave);
setLevelGenerationOptions( lgo ); setLevelGenerationOptions(lgo);
//m_currentGameRuleDefinitions = lgo->getRequiredGameRules(); // m_currentGameRuleDefinitions = lgo->getRequiredGameRules();
} } else {
else
{
delete lgo; delete lgo;
} }
//delete [] content.data; // delete [] content.data;
// Close and return. // Close and return.
dis2.close(); dis2.close();
bais2.close(); bais2.close();
return ; return;
} }
// 4J-JEV: Reverse of loadGameRules. // 4J-JEV: Reverse of loadGameRules.
void GameRuleManager::saveGameRules(uint8_t **dOut, unsigned int *dSize) void GameRuleManager::saveGameRules(uint8_t** dOut, unsigned int* dSize) {
{
if (m_currentGameRuleDefinitions == NULL && if (m_currentGameRuleDefinitions == NULL &&
m_currentLevelGenerationOptions == NULL) m_currentLevelGenerationOptions == NULL) {
{
app.DebugPrintf("GameRuleManager:: Nothing here to save."); app.DebugPrintf("GameRuleManager:: Nothing here to save.");
*dOut = NULL; *dOut = NULL;
*dSize = 0; *dSize = 0;
@ -260,12 +262,11 @@ void GameRuleManager::saveGameRules(uint8_t **dOut, unsigned int *dSize)
// Write header. // Write header.
// VERSION NUMBER // VERSION NUMBER
dos.writeShort( 0x1 ); // version_number dos.writeShort(0x1); // version_number
// Write 8 bytes of empty space in case we need them later. // Write 8 bytes of empty space in case we need them later.
// Mainly useful for the ones we save embedded in game saves. // Mainly useful for the ones we save embedded in game saves.
for (unsigned int i = 0; i < 8; i++) for (unsigned int i = 0; i < 8; i++) dos.writeByte(0x0);
dos.writeByte(0x0);
dos.writeByte(APPROPRIATE_COMPRESSION_TYPE); // m_compressionType dos.writeByte(APPROPRIATE_COMPRESSION_TYPE); // m_compressionType
@ -273,31 +274,28 @@ void GameRuleManager::saveGameRules(uint8_t **dOut, unsigned int *dSize)
ByteArrayOutputStream compr_baos; ByteArrayOutputStream compr_baos;
DataOutputStream compr_dos(&compr_baos); DataOutputStream compr_dos(&compr_baos);
if (m_currentGameRuleDefinitions == NULL) if (m_currentGameRuleDefinitions == NULL) {
{ compr_dos.writeInt(0); // numStrings for StringTable
compr_dos.writeInt( 0 ); // numStrings for StringTable compr_dos.writeInt(version_number);
compr_dos.writeInt( version_number ); compr_dos.writeByte(
compr_dos.writeByte(Compression::eCompressionType_None); // compression type Compression::eCompressionType_None); // compression type
for (int i=0; i<2; i++) compr_dos.writeByte(0x0); // Padding. for (int i = 0; i < 2; i++) compr_dos.writeByte(0x0); // Padding.
compr_dos.writeInt( 0 ); // StringLookup.length compr_dos.writeInt(0); // StringLookup.length
compr_dos.writeInt( 0 ); // SchematicFiles.length compr_dos.writeInt(0); // SchematicFiles.length
compr_dos.writeInt( 0 ); // XmlObjects.length compr_dos.writeInt(0); // XmlObjects.length
} } else {
else StringTable* st = m_currentGameRuleDefinitions->getStringTable();
{
StringTable *st = m_currentGameRuleDefinitions->getStringTable();
if (st == NULL) if (st == NULL) {
{ app.DebugPrintf(
app.DebugPrintf("GameRuleManager::saveGameRules: StringTable == NULL!"); "GameRuleManager::saveGameRules: StringTable == NULL!");
} } else {
else
{
// Write string table. // Write string table.
byteArray stba; byteArray stba;
m_currentGameRuleDefinitions->getStringTable()->getData(&stba.data, &stba.length); m_currentGameRuleDefinitions->getStringTable()->getData(
compr_dos.writeInt( stba.length ); &stba.data, &stba.length);
compr_dos.write( stba ); compr_dos.writeInt(stba.length);
compr_dos.write(stba);
// Write game rule file to second // Write game rule file to second
// buffer and generate string lookup. // buffer and generate string lookup.
@ -306,18 +304,20 @@ void GameRuleManager::saveGameRules(uint8_t **dOut, unsigned int *dSize)
} }
// Compress compr_dos and write to dos. // Compress compr_dos and write to dos.
byteArray compr_ba(new std::uint8_t[ compr_baos.buf.length ], compr_baos.buf.length); byteArray compr_ba(new std::uint8_t[compr_baos.buf.length],
Compression::getCompression()->CompressLZXRLE( compr_ba.data, &compr_ba.length, compr_baos.buf.length);
compr_baos.buf.data, compr_baos.buf.length ); Compression::getCompression()->CompressLZXRLE(
compr_ba.data, &compr_ba.length, compr_baos.buf.data,
compr_baos.buf.length);
app.DebugPrintf("\tcompr_ba.length=%d.\n\tcompr_baos.buf.length=%d.\n", app.DebugPrintf("\tcompr_ba.length=%d.\n\tcompr_baos.buf.length=%d.\n",
compr_ba.length, compr_baos.buf.length ); compr_ba.length, compr_baos.buf.length);
dos.writeInt( compr_ba.length ); // Write length dos.writeInt(compr_ba.length); // Write length
dos.writeInt( compr_baos.buf.length ); dos.writeInt(compr_baos.buf.length);
dos.write(compr_ba); dos.write(compr_ba);
delete [] compr_ba.data; delete[] compr_ba.data;
compr_dos.close(); compr_dos.close();
compr_baos.close(); compr_baos.close();
@ -329,61 +329,66 @@ void GameRuleManager::saveGameRules(uint8_t **dOut, unsigned int *dSize)
baos.buf.data = NULL; baos.buf.data = NULL;
dos.close(); baos.close(); dos.close();
baos.close();
} }
// 4J-JEV: Reverse of readRuleFile. // 4J-JEV: Reverse of readRuleFile.
void GameRuleManager::writeRuleFile(DataOutputStream *dos) void GameRuleManager::writeRuleFile(DataOutputStream* dos) {
{
// Write Header // Write Header
dos->writeShort(version_number); // Version number. dos->writeShort(version_number); // Version number.
dos->writeByte(Compression::eCompressionType_None); // compression type dos->writeByte(Compression::eCompressionType_None); // compression type
for (int i=0; i<8; i++) dos->writeBoolean(false); // Padding. for (int i = 0; i < 8; i++) dos->writeBoolean(false); // Padding.
// Write string lookup. // Write string lookup.
int numStrings = static_cast<int>(ConsoleGameRules::eGameRuleType_Count) + int numStrings = static_cast<int>(ConsoleGameRules::eGameRuleType_Count) +
static_cast<int>(ConsoleGameRules::eGameRuleAttr_Count); static_cast<int>(ConsoleGameRules::eGameRuleAttr_Count);
dos->writeInt(numStrings); dos->writeInt(numStrings);
for (int i = 0; i < ConsoleGameRules::eGameRuleType_Count; i++) dos->writeUTF( wchTagNameA[i] ); for (int i = 0; i < ConsoleGameRules::eGameRuleType_Count; i++)
for (int i = 0; i < ConsoleGameRules::eGameRuleAttr_Count; i++) dos->writeUTF( wchAttrNameA[i] ); dos->writeUTF(wchTagNameA[i]);
for (int i = 0; i < ConsoleGameRules::eGameRuleAttr_Count; i++)
dos->writeUTF(wchAttrNameA[i]);
// Write schematic files. // Write schematic files.
std::unordered_map<std::wstring, ConsoleSchematicFile *> *files; std::unordered_map<std::wstring, ConsoleSchematicFile*>* files;
files = getLevelGenerationOptions()->getUnfinishedSchematicFiles(); files = getLevelGenerationOptions()->getUnfinishedSchematicFiles();
dos->writeInt( files->size() ); dos->writeInt(files->size());
for (AUTO_VAR(it, files->begin()); it != files->end(); it++) for (AUTO_VAR(it, files->begin()); it != files->end(); it++) {
{
std::wstring filename = it->first; std::wstring filename = it->first;
ConsoleSchematicFile *file = it->second; ConsoleSchematicFile* file = it->second;
ByteArrayOutputStream fileBaos; ByteArrayOutputStream fileBaos;
DataOutputStream fileDos(&fileBaos); DataOutputStream fileDos(&fileBaos);
file->save(&fileDos); file->save(&fileDos);
dos->writeUTF(filename); dos->writeUTF(filename);
//dos->writeInt(file->m_data.length); // dos->writeInt(file->m_data.length);
dos->writeInt(fileBaos.buf.length); dos->writeInt(fileBaos.buf.length);
dos->write((byteArray)fileBaos.buf); dos->write((byteArray)fileBaos.buf);
fileDos.close(); fileBaos.close(); fileDos.close();
fileBaos.close();
} }
// Write xml objects. // Write xml objects.
dos->writeInt( 2 ); // numChildren dos->writeInt(2); // numChildren
m_currentLevelGenerationOptions->write(dos); m_currentLevelGenerationOptions->write(dos);
m_currentGameRuleDefinitions->write(dos); m_currentGameRuleDefinitions->write(dos);
} }
bool GameRuleManager::readRuleFile(LevelGenerationOptions *lgo, uint8_t *dIn, unsigned int dSize, StringTable *strings) //(DLCGameRulesFile *dlcFile, StringTable *strings) bool GameRuleManager::readRuleFile(
LevelGenerationOptions* lgo, uint8_t* dIn, unsigned int dSize,
StringTable* strings) //(DLCGameRulesFile *dlcFile, StringTable *strings)
{ {
bool levelGenAdded = false; bool levelGenAdded = false;
bool gameRulesAdded = false; bool gameRulesAdded = false;
LevelGenerationOptions *levelGenerator = lgo;//new LevelGenerationOptions(); LevelGenerationOptions* levelGenerator =
LevelRuleset *gameRules = new LevelRuleset(); lgo; // new LevelGenerationOptions();
LevelRuleset* gameRules = new LevelRuleset();
//std::uint32_t dataLength = 0; // std::uint32_t dataLength = 0;
//std::uint8_t *data = dlcFile->getData(dataLength); // std::uint8_t *data = dlcFile->getData(dataLength);
//byteArray data(pbData,dwLen); // byteArray data(pbData,dwLen);
byteArray data(dIn, dSize); byteArray data(dIn, dSize);
ByteArrayInputStream bais(data); ByteArrayInputStream bais(data);
@ -394,30 +399,24 @@ bool GameRuleManager::readRuleFile(LevelGenerationOptions *lgo, uint8_t *dIn, un
// version_number // version_number
__int64 version = dis.readShort(); __int64 version = dis.readShort();
unsigned char compressionType = 0; unsigned char compressionType = 0;
if(version == 0) if (version == 0) {
{
for (int i = 0; i < 14; i++) dis.readByte(); // Read padding. for (int i = 0; i < 14; i++) dis.readByte(); // Read padding.
} } else {
else
{
compressionType = dis.readByte(); compressionType = dis.readByte();
// Read the spare bytes we inserted for future use // Read the spare bytes we inserted for future use
for(int i = 0; i < 8; ++i) dis.readBoolean(); for (int i = 0; i < 8; ++i) dis.readBoolean();
} }
ByteArrayInputStream *contentBais = NULL; ByteArrayInputStream* contentBais = NULL;
DataInputStream *contentDis = NULL; DataInputStream* contentDis = NULL;
if(compressionType == Compression::eCompressionType_None) if (compressionType == Compression::eCompressionType_None) {
{
// No compression // No compression
// No need to read buffer size, as we can read the stream as it is; // No need to read buffer size, as we can read the stream as it is;
app.DebugPrintf("De-compressing game rules with: None\n"); app.DebugPrintf("De-compressing game rules with: None\n");
contentDis = &dis; contentDis = &dis;
} } else {
else
{
unsigned int uncompressedSize = dis.readInt(); unsigned int uncompressedSize = dis.readInt();
unsigned int compressedSize = dis.readInt(); unsigned int compressedSize = dis.readInt();
byteArray compressedBuffer(compressedSize); byteArray compressedBuffer(compressedSize);
@ -425,45 +424,54 @@ bool GameRuleManager::readRuleFile(LevelGenerationOptions *lgo, uint8_t *dIn, un
byteArray decompressedBuffer = byteArray(uncompressedSize); byteArray decompressedBuffer = byteArray(uncompressedSize);
switch(compressionType) switch (compressionType) {
{
case Compression::eCompressionType_None: case Compression::eCompressionType_None:
memcpy(decompressedBuffer.data, compressedBuffer.data, uncompressedSize); memcpy(decompressedBuffer.data, compressedBuffer.data,
uncompressedSize);
break; break;
case Compression::eCompressionType_RLE: case Compression::eCompressionType_RLE:
app.DebugPrintf("De-compressing game rules with: RLE\n"); app.DebugPrintf("De-compressing game rules with: RLE\n");
Compression::getCompression()->Decompress( decompressedBuffer.data, &decompressedBuffer.length, compressedBuffer.data, compressedSize); Compression::getCompression()->Decompress(
decompressedBuffer.data, &decompressedBuffer.length,
compressedBuffer.data, compressedSize);
break; break;
default: default:
app.DebugPrintf("De-compressing game rules."); app.DebugPrintf("De-compressing game rules.");
#ifndef _CONTENT_PACKAGE #ifndef _CONTENT_PACKAGE
assert( compressionType == APPROPRIATE_COMPRESSION_TYPE ); assert(compressionType == APPROPRIATE_COMPRESSION_TYPE);
#endif #endif
// 4J-JEV: DecompressLZXRLE uses the correct platform specific compression type. (need to assert that the data is compressed with it though). // 4J-JEV: DecompressLZXRLE uses the correct platform specific
Compression::getCompression()->DecompressLZXRLE(decompressedBuffer.data, &decompressedBuffer.length, compressedBuffer.data, compressedSize); // compression type. (need to assert that the data is compressed
// with it though).
Compression::getCompression()->DecompressLZXRLE(
decompressedBuffer.data, &decompressedBuffer.length,
compressedBuffer.data, compressedSize);
break; break;
/* 4J-JEV: /* 4J-JEV:
Each platform has only 1 method of compression, 'compression.h' file deals with it. Each platform has only 1 method of compression,
'compression.h' file deals with it.
case Compression::eCompressionType_LZXRLE: case Compression::eCompressionType_LZXRLE:
app.DebugPrintf("De-compressing game rules with: LZX+RLE\n"); app.DebugPrintf("De-compressing game
Compression::getCompression()->DecompressLZXRLE( decompressedBuffer.data, &uncompressedSize, compressedBuffer.data, compressedSize); rules with: LZX+RLE\n");
break; Compression::getCompression()->DecompressLZXRLE(
default: decompressedBuffer.data, &uncompressedSize,
app.DebugPrintf("Invalid compression type %d found\n", compressionType); compressedBuffer.data, compressedSize); break; default:
app.DebugPrintf("Invalid compression
type %d found\n", compressionType);
__debugbreak(); __debugbreak();
delete [] compressedBuffer.data; delete [] decompressedBuffer.data; delete [] compressedBuffer.data; delete
dis.close(); bais.reset(); [] decompressedBuffer.data; dis.close(); bais.reset();
if(!gameRulesAdded) delete gameRules; if(!gameRulesAdded) delete gameRules;
return false; return false;
*/ */
}; };
delete [] compressedBuffer.data; delete[] compressedBuffer.data;
contentBais = new ByteArrayInputStream(decompressedBuffer); contentBais = new ByteArrayInputStream(decompressedBuffer);
contentDis = new DataInputStream(contentBais); contentDis = new DataInputStream(contentBais);
@ -473,16 +481,16 @@ bool GameRuleManager::readRuleFile(LevelGenerationOptions *lgo, uint8_t *dIn, un
unsigned int numStrings = contentDis->readInt(); unsigned int numStrings = contentDis->readInt();
std::vector<std::wstring> tagsAndAtts; std::vector<std::wstring> tagsAndAtts;
for (unsigned int i = 0; i < numStrings; i++) for (unsigned int i = 0; i < numStrings; i++)
tagsAndAtts.push_back( contentDis->readUTF() ); tagsAndAtts.push_back(contentDis->readUTF());
std::unordered_map<int, ConsoleGameRules::EGameRuleType> tagIdMap; std::unordered_map<int, ConsoleGameRules::EGameRuleType> tagIdMap;
for(int type = (int)ConsoleGameRules::eGameRuleType_Root; type < (int)ConsoleGameRules::eGameRuleType_Count; ++type) for (int type = (int)ConsoleGameRules::eGameRuleType_Root;
{ type < (int)ConsoleGameRules::eGameRuleType_Count; ++type) {
for(unsigned int i = 0; i < numStrings; ++i) for (unsigned int i = 0; i < numStrings; ++i) {
{ if (tagsAndAtts[i].compare(wchTagNameA[type]) == 0) {
if(tagsAndAtts[i].compare(wchTagNameA[type]) == 0) tagIdMap.insert(
{ std::unordered_map<int, ConsoleGameRules::EGameRuleType>::
tagIdMap.insert( std::unordered_map<int, ConsoleGameRules::EGameRuleType>::value_type(i, (ConsoleGameRules::EGameRuleType)type) ); value_type(i, (ConsoleGameRules::EGameRuleType)type));
break; break;
} }
} }
@ -491,58 +499,55 @@ bool GameRuleManager::readRuleFile(LevelGenerationOptions *lgo, uint8_t *dIn, un
// 4J-JEV: TODO: As yet unused. // 4J-JEV: TODO: As yet unused.
/* /*
std::unordered_map<int, ConsoleGameRules::EGameRuleAttr> attrIdMap; std::unordered_map<int, ConsoleGameRules::EGameRuleAttr> attrIdMap;
for(int attr = (int)ConsoleGameRules::eGameRuleAttr_descriptionName; attr < (int)ConsoleGameRules::eGameRuleAttr_Count; ++attr) for(int attr = (int)ConsoleGameRules::eGameRuleAttr_descriptionName; attr <
(int)ConsoleGameRules::eGameRuleAttr_Count; ++attr)
{ {
for (unsigned int i = 0; i < numStrings; i++) for (unsigned int i = 0; i < numStrings; i++)
{ {
if (tagsAndAtts[i].compare(wchAttrNameA[attr]) == 0) if (tagsAndAtts[i].compare(wchAttrNameA[attr]) == 0)
{ {
tagIdMap.insert( std::unordered_map<int, ConsoleGameRules::EGameRuleAttr>::value_type(i , (ConsoleGameRules::EGameRuleAttr)attr) ); tagIdMap.insert( std::unordered_map<int,
break; ConsoleGameRules::EGameRuleAttr>::value_type(i ,
(ConsoleGameRules::EGameRuleAttr)attr) ); break;
} }
} }
}*/ }*/
// subfile // subfile
unsigned int numFiles = contentDis->readInt(); unsigned int numFiles = contentDis->readInt();
for (unsigned int i = 0; i < numFiles; i++) for (unsigned int i = 0; i < numFiles; i++) {
{
std::wstring sFilename = contentDis->readUTF(); std::wstring sFilename = contentDis->readUTF();
int length = contentDis->readInt(); int length = contentDis->readInt();
byteArray ba( length ); byteArray ba(length);
contentDis->read(ba); contentDis->read(ba);
levelGenerator->loadSchematicFile(sFilename, ba.data, ba.length); levelGenerator->loadSchematicFile(sFilename, ba.data, ba.length);
} }
LEVEL_GEN_ID lgoID = LEVEL_GEN_ID_NULL; LEVEL_GEN_ID lgoID = LEVEL_GEN_ID_NULL;
// xml objects // xml objects
unsigned int numObjects = contentDis->readInt(); unsigned int numObjects = contentDis->readInt();
for(unsigned int i = 0; i < numObjects; ++i) for (unsigned int i = 0; i < numObjects; ++i) {
{
int tagId = contentDis->readInt(); int tagId = contentDis->readInt();
ConsoleGameRules::EGameRuleType tagVal = ConsoleGameRules::eGameRuleType_Invalid; ConsoleGameRules::EGameRuleType tagVal =
AUTO_VAR(it,tagIdMap.find(tagId)); ConsoleGameRules::eGameRuleType_Invalid;
if(it != tagIdMap.end()) tagVal = it->second; AUTO_VAR(it, tagIdMap.find(tagId));
if (it != tagIdMap.end()) tagVal = it->second;
GameRuleDefinition *rule = NULL; GameRuleDefinition* rule = NULL;
if(tagVal == ConsoleGameRules::eGameRuleType_LevelGenerationOptions) if (tagVal == ConsoleGameRules::eGameRuleType_LevelGenerationOptions) {
{
rule = levelGenerator; rule = levelGenerator;
levelGenAdded = true; levelGenAdded = true;
//m_levelGenerators.addLevelGenerator(L"",levelGenerator); // m_levelGenerators.addLevelGenerator(L"",levelGenerator);
lgoID = addLevelGenerationOptions(levelGenerator); lgoID = addLevelGenerationOptions(levelGenerator);
levelGenerator->loadStringTable(strings); levelGenerator->loadStringTable(strings);
} } else if (tagVal == ConsoleGameRules::eGameRuleType_LevelRules) {
else if(tagVal == ConsoleGameRules::eGameRuleType_LevelRules)
{
rule = gameRules; rule = gameRules;
gameRulesAdded = true; gameRulesAdded = true;
m_levelRules.addLevelRule(L"",gameRules); m_levelRules.addLevelRule(L"", gameRules);
levelGenerator->setRequiredGameRules(gameRules); levelGenerator->setRequiredGameRules(gameRules);
gameRules->loadStringTable(strings); gameRules->loadStringTable(strings);
} }
@ -551,29 +556,25 @@ bool GameRuleManager::readRuleFile(LevelGenerationOptions *lgo, uint8_t *dIn, un
readChildren(contentDis, &tagsAndAtts, &tagIdMap, rule); readChildren(contentDis, &tagsAndAtts, &tagIdMap, rule);
} }
if(compressionType != 0) if (compressionType != 0) {
{
// Not default // Not default
contentDis->close(); contentDis->close();
if(contentBais != NULL) delete contentBais; if (contentBais != NULL) delete contentBais;
delete contentDis; delete contentDis;
} }
dis.close(); dis.close();
bais.reset(); bais.reset();
//if(!levelGenAdded) { delete levelGenerator; levelGenerator = NULL; } // if(!levelGenAdded) { delete levelGenerator; levelGenerator = NULL; }
if(!gameRulesAdded) delete gameRules; if (!gameRulesAdded) delete gameRules;
return true; return true;
//return levelGenerator; // return levelGenerator;
} }
LevelGenerationOptions *GameRuleManager::readHeader(DLCGameRulesHeader *grh) LevelGenerationOptions* GameRuleManager::readHeader(DLCGameRulesHeader* grh) {
{ LevelGenerationOptions* out = new LevelGenerationOptions();
LevelGenerationOptions *out =
new LevelGenerationOptions();
out->setSrc(LevelGenerationOptions::eSrc_fromDLC); out->setSrc(LevelGenerationOptions::eSrc_fromDLC);
out->setGrSource(grh); out->setGrSource(grh);
@ -582,56 +583,55 @@ LevelGenerationOptions *GameRuleManager::readHeader(DLCGameRulesHeader *grh)
return out; return out;
} }
void GameRuleManager::readAttributes(DataInputStream *dis, std::vector<std::wstring> *tagsAndAtts, GameRuleDefinition *rule) void GameRuleManager::readAttributes(DataInputStream* dis,
{ std::vector<std::wstring>* tagsAndAtts,
GameRuleDefinition* rule) {
int numAttrs = dis->readInt(); int numAttrs = dis->readInt();
for (unsigned int att = 0; att < static_cast<unsigned int>(numAttrs); ++att) for (unsigned int att = 0; att < static_cast<unsigned int>(numAttrs);
{ ++att) {
int attID = dis->readInt(); int attID = dis->readInt();
std::wstring value = dis->readUTF(); std::wstring value = dis->readUTF();
if(rule != NULL) rule->addAttribute(tagsAndAtts->at(attID),value); if (rule != NULL) rule->addAttribute(tagsAndAtts->at(attID), value);
} }
} }
void GameRuleManager::readChildren(DataInputStream *dis, std::vector<std::wstring> *tagsAndAtts, std::unordered_map<int, ConsoleGameRules::EGameRuleType> *tagIdMap, GameRuleDefinition *rule) void GameRuleManager::readChildren(
{ DataInputStream* dis, std::vector<std::wstring>* tagsAndAtts,
std::unordered_map<int, ConsoleGameRules::EGameRuleType>* tagIdMap,
GameRuleDefinition* rule) {
int numChildren = dis->readInt(); int numChildren = dis->readInt();
for(unsigned int child = 0; child < static_cast<unsigned int>(numChildren); ++child) for (unsigned int child = 0; child < static_cast<unsigned int>(numChildren);
{ ++child) {
int tagId = dis->readInt(); int tagId = dis->readInt();
ConsoleGameRules::EGameRuleType tagVal = ConsoleGameRules::eGameRuleType_Invalid; ConsoleGameRules::EGameRuleType tagVal =
AUTO_VAR(it,tagIdMap->find(tagId)); ConsoleGameRules::eGameRuleType_Invalid;
if(it != tagIdMap->end()) tagVal = it->second; AUTO_VAR(it, tagIdMap->find(tagId));
if (it != tagIdMap->end()) tagVal = it->second;
GameRuleDefinition *childRule = NULL; GameRuleDefinition* childRule = NULL;
if(rule != NULL) childRule = rule->addChild(tagVal); if (rule != NULL) childRule = rule->addChild(tagVal);
readAttributes(dis,tagsAndAtts,childRule); readAttributes(dis, tagsAndAtts, childRule);
readChildren(dis,tagsAndAtts,tagIdMap,childRule); readChildren(dis, tagsAndAtts, tagIdMap, childRule);
} }
} }
void GameRuleManager::processSchematics(LevelChunk *levelChunk) void GameRuleManager::processSchematics(LevelChunk* levelChunk) {
{ if (getLevelGenerationOptions() != NULL) {
if(getLevelGenerationOptions() != NULL) LevelGenerationOptions* levelGenOptions = getLevelGenerationOptions();
{
LevelGenerationOptions *levelGenOptions = getLevelGenerationOptions();
levelGenOptions->processSchematics(levelChunk); levelGenOptions->processSchematics(levelChunk);
} }
} }
void GameRuleManager::processSchematicsLighting(LevelChunk *levelChunk) void GameRuleManager::processSchematicsLighting(LevelChunk* levelChunk) {
{ if (getLevelGenerationOptions() != NULL) {
if(getLevelGenerationOptions() != NULL) LevelGenerationOptions* levelGenOptions = getLevelGenerationOptions();
{
LevelGenerationOptions *levelGenOptions = getLevelGenerationOptions();
levelGenOptions->processSchematicsLighting(levelChunk); levelGenOptions->processSchematicsLighting(levelChunk);
} }
} }
void GameRuleManager::loadDefaultGameRules() void GameRuleManager::loadDefaultGameRules() {
{
#ifdef _XBOX #ifdef _XBOX
#ifdef _TU_BUILD #ifdef _TU_BUILD
std::wstring fileRoot = L"UPDATE:\\res\\GameRules\\Tutorial.pck"; std::wstring fileRoot = L"UPDATE:\\res\\GameRules\\Tutorial.pck";
@ -639,63 +639,68 @@ void GameRuleManager::loadDefaultGameRules()
std::wstring fileRoot = L"GAME:\\res\\TitleUpdate\\GameRules\\Tutorial.pck"; std::wstring fileRoot = L"GAME:\\res\\TitleUpdate\\GameRules\\Tutorial.pck";
#endif #endif
File packedTutorialFile(fileRoot); File packedTutorialFile(fileRoot);
if(loadGameRulesPack(&packedTutorialFile)) if (loadGameRulesPack(&packedTutorialFile)) {
{ m_levelGenerators.getLevelGenerators()->at(0)->setWorldName(
m_levelGenerators.getLevelGenerators()->at(0)->setWorldName(app.GetString(IDS_PLAY_TUTORIAL)); app.GetString(IDS_PLAY_TUTORIAL));
//m_levelGenerators.getLevelGenerators()->at(0)->setDefaultSaveName(L"Tutorial"); // m_levelGenerators.getLevelGenerators()->at(0)->setDefaultSaveName(L"Tutorial");
m_levelGenerators.getLevelGenerators()->at(0)->setDefaultSaveName(app.GetString(IDS_TUTORIALSAVENAME)); m_levelGenerators.getLevelGenerators()->at(0)->setDefaultSaveName(
app.GetString(IDS_TUTORIALSAVENAME));
} }
#ifndef _CONTENT_PACKAGE #ifndef _CONTENT_PACKAGE
// 4J Stu - Remove these just now // 4J Stu - Remove these just now
//File testRulesPath(L"GAME:\\GameRules"); // File testRulesPath(L"GAME:\\GameRules");
//std::vector<File *> *packFiles = testRulesPath.listFiles(); // std::vector<File *> *packFiles = testRulesPath.listFiles();
//for(AUTO_VAR(it,packFiles->begin()); it != packFiles->end(); ++it) // for(AUTO_VAR(it,packFiles->begin()); it != packFiles->end(); ++it)
//{ //{
// loadGameRulesPack(*it); // loadGameRulesPack(*it);
//} // }
//delete packFiles; // delete packFiles;
#endif #endif
#else // _XBOX #else // _XBOX
std::wstring fpTutorial = L"Tutorial.pck"; std::wstring fpTutorial = L"Tutorial.pck";
if(app.getArchiveFileSize(fpTutorial) >= 0) if (app.getArchiveFileSize(fpTutorial) >= 0) {
{ DLCPack* pack = new DLCPack(L"", 0xffffffff);
DLCPack *pack = new DLCPack(L"",0xffffffff);
unsigned int dwFilesProcessed = 0; unsigned int dwFilesProcessed = 0;
if ( app.m_dlcManager.readDLCDataFile(dwFilesProcessed,fpTutorial,pack,true) ) if (app.m_dlcManager.readDLCDataFile(dwFilesProcessed, fpTutorial, pack,
{ true)) {
app.m_dlcManager.addPack(pack); app.m_dlcManager.addPack(pack);
if (!m_levelGenerators.getLevelGenerators()->empty()) if (!m_levelGenerators.getLevelGenerators()->empty()) {
{ m_levelGenerators.getLevelGenerators()->at(0)->setWorldName(
m_levelGenerators.getLevelGenerators()->at(0)->setWorldName(app.GetString(IDS_PLAY_TUTORIAL)); app.GetString(IDS_PLAY_TUTORIAL));
m_levelGenerators.getLevelGenerators()->at(0)->setDefaultSaveName(app.GetString(IDS_TUTORIALSAVENAME)); m_levelGenerators.getLevelGenerators()
->at(0)
->setDefaultSaveName(app.GetString(IDS_TUTORIALSAVENAME));
} else {
app.DebugPrintf(
"loadDefaultGameRules: Tutorial.pck parsed OK but no level "
"generators were added (missing "
"GameRules/LevelGenerationOptions tag?)\n");
} }
else } else {
{ app.DebugPrintf(
app.DebugPrintf("loadDefaultGameRules: Tutorial.pck parsed OK but no level generators were added (missing GameRules/LevelGenerationOptions tag?)\n"); "loadDefaultGameRules: readDLCDataFile failed for Tutorial.pck "
} "(version too old, IO error, or DLC_TYPE_GameRules not "
} "found)\n");
else
{
app.DebugPrintf("loadDefaultGameRules: readDLCDataFile failed for Tutorial.pck (version too old, IO error, or DLC_TYPE_GameRules not found)\n");
delete pack; delete pack;
} }
} } else {
else app.DebugPrintf(
{ "loadDefaultGameRules: Tutorial.pck not found in archive\n");
app.DebugPrintf("loadDefaultGameRules: Tutorial.pck not found in archive\n");
} }
// Linux/PC port fallback: if Tutorial.pck parsing didn't populate level generators // Linux/PC port fallback: if Tutorial.pck parsing didn't populate level
// (e.g. DLC version mismatch, missing GameRules tag), create a minimal placeholder so // generators (e.g. DLC version mismatch, missing GameRules tag), create a
// the game doesn't crash with vector::at(0) in LoadTrial(). // minimal placeholder so the game doesn't crash with vector::at(0) in
if (m_levelGenerators.getLevelGenerators()->empty()) // LoadTrial().
{ if (m_levelGenerators.getLevelGenerators()->empty()) {
app.DebugPrintf("loadDefaultGameRules: creating minimal fallback LevelGenerationOptions\n"); app.DebugPrintf(
LevelGenerationOptions *lgo = new LevelGenerationOptions(); "loadDefaultGameRules: creating minimal fallback "
"LevelGenerationOptions\n");
LevelGenerationOptions* lgo = new LevelGenerationOptions();
lgo->setGrSource(new JustGrSource()); lgo->setGrSource(new JustGrSource());
lgo->setSrc(LevelGenerationOptions::eSrc_tutorial); lgo->setSrc(LevelGenerationOptions::eSrc_tutorial);
lgo->setWorldName(app.GetString(IDS_PLAY_TUTORIAL)); lgo->setWorldName(app.GetString(IDS_PLAY_TUTORIAL));
@ -714,21 +719,17 @@ void GameRuleManager::loadDefaultGameRules()
#endif #endif
} }
bool GameRuleManager::loadGameRulesPack(File *path) bool GameRuleManager::loadGameRulesPack(File* path) {
{
bool success = false; bool success = false;
#ifdef _XBOX #ifdef _XBOX
if(path->exists()) if (path->exists()) {
{ DLCPack* pack = new DLCPack(L"", 0xffffffff);
DLCPack *pack = new DLCPack(L"",0xffffffff);
unsigned int dwFilesProcessed = 0; unsigned int dwFilesProcessed = 0;
if( app.m_dlcManager.readDLCDataFile(dwFilesProcessed, path->getPath(),pack)) if (app.m_dlcManager.readDLCDataFile(dwFilesProcessed, path->getPath(),
{ pack)) {
app.m_dlcManager.addPack(pack); app.m_dlcManager.addPack(pack);
success = true; success = true;
} } else {
else
{
delete pack; delete pack;
} }
} }
@ -736,60 +737,53 @@ bool GameRuleManager::loadGameRulesPack(File *path)
return success; return success;
} }
void GameRuleManager::setLevelGenerationOptions(LevelGenerationOptions *levelGen) void GameRuleManager::setLevelGenerationOptions(
{ LevelGenerationOptions* levelGen) {
m_currentGameRuleDefinitions = NULL; m_currentGameRuleDefinitions = NULL;
m_currentLevelGenerationOptions = levelGen; m_currentLevelGenerationOptions = levelGen;
if(m_currentLevelGenerationOptions != NULL && m_currentLevelGenerationOptions->requiresGameRules() ) if (m_currentLevelGenerationOptions != NULL &&
{ m_currentLevelGenerationOptions->requiresGameRules()) {
m_currentGameRuleDefinitions = m_currentLevelGenerationOptions->getRequiredGameRules(); m_currentGameRuleDefinitions =
m_currentLevelGenerationOptions->getRequiredGameRules();
} }
if(m_currentLevelGenerationOptions != NULL) if (m_currentLevelGenerationOptions != NULL)
m_currentLevelGenerationOptions->reset_start(); m_currentLevelGenerationOptions->reset_start();
} }
const wchar_t *GameRuleManager::GetGameRulesString(const std::wstring &key) const wchar_t* GameRuleManager::GetGameRulesString(const std::wstring& key) {
{ if (m_currentGameRuleDefinitions != NULL && !key.empty()) {
if(m_currentGameRuleDefinitions != NULL && !key.empty() )
{
return m_currentGameRuleDefinitions->getString(key); return m_currentGameRuleDefinitions->getString(key);
} } else {
else
{
return L""; return L"";
} }
} }
LEVEL_GEN_ID GameRuleManager::addLevelGenerationOptions(LevelGenerationOptions *lgo) LEVEL_GEN_ID GameRuleManager::addLevelGenerationOptions(
{ LevelGenerationOptions* lgo) {
std::vector<LevelGenerationOptions *> *lgs = m_levelGenerators.getLevelGenerators(); std::vector<LevelGenerationOptions*>* lgs =
m_levelGenerators.getLevelGenerators();
for (int i = 0; i<lgs->size(); i++) for (int i = 0; i < lgs->size(); i++)
if (lgs->at(i) == lgo) if (lgs->at(i) == lgo) return i;
return i;
lgs->push_back(lgo); lgs->push_back(lgo);
return lgs->size() - 1; return lgs->size() - 1;
} }
void GameRuleManager::unloadCurrentGameRules() void GameRuleManager::unloadCurrentGameRules() {
{ if (m_currentLevelGenerationOptions != NULL) {
if (m_currentLevelGenerationOptions != NULL) if (m_currentGameRuleDefinitions != NULL &&
{ m_currentLevelGenerationOptions->isFromSave())
if (m_currentGameRuleDefinitions != NULL m_levelRules.removeLevelRule(m_currentGameRuleDefinitions);
&& m_currentLevelGenerationOptions->isFromSave())
m_levelRules.removeLevelRule( m_currentGameRuleDefinitions );
if (m_currentLevelGenerationOptions->isFromSave()) if (m_currentLevelGenerationOptions->isFromSave()) {
{ m_levelGenerators.removeLevelGenerator(
m_levelGenerators.removeLevelGenerator( m_currentLevelGenerationOptions ); m_currentLevelGenerationOptions);
delete m_currentLevelGenerationOptions; delete m_currentLevelGenerationOptions;
} } else if (m_currentLevelGenerationOptions->isFromDLC()) {
else if (m_currentLevelGenerationOptions->isFromDLC())
{
m_currentLevelGenerationOptions->reset_finish(); m_currentLevelGenerationOptions->reset_finish();
} }
} }

View file

@ -21,58 +21,72 @@ class WstringLookup;
#define LEVEL_GEN_ID int #define LEVEL_GEN_ID int
#define LEVEL_GEN_ID_NULL 0 #define LEVEL_GEN_ID_NULL 0
class GameRuleManager class GameRuleManager {
{
public: public:
static const WCHAR *wchTagNameA[ConsoleGameRules::eGameRuleType_Count]; static const WCHAR* wchTagNameA[ConsoleGameRules::eGameRuleType_Count];
static const WCHAR *wchAttrNameA[ConsoleGameRules::eGameRuleAttr_Count]; static const WCHAR* wchAttrNameA[ConsoleGameRules::eGameRuleAttr_Count];
static const short version_number = 2; static const short version_number = 2;
private: private:
LevelGenerationOptions *m_currentLevelGenerationOptions; LevelGenerationOptions* m_currentLevelGenerationOptions;
LevelRuleset *m_currentGameRuleDefinitions; LevelRuleset* m_currentGameRuleDefinitions;
LevelGenerators m_levelGenerators; LevelGenerators m_levelGenerators;
LevelRules m_levelRules; LevelRules m_levelRules;
public: public:
GameRuleManager(); GameRuleManager();
void loadGameRules(DLCPack *); void loadGameRules(DLCPack*);
LevelGenerationOptions *loadGameRules(uint8_t *dIn, unsigned int dSize); LevelGenerationOptions* loadGameRules(uint8_t* dIn, unsigned int dSize);
void loadGameRules(LevelGenerationOptions *lgo, uint8_t *dIn, unsigned int dSize); void loadGameRules(LevelGenerationOptions* lgo, uint8_t* dIn,
unsigned int dSize);
void saveGameRules(uint8_t **dOut, unsigned int *dSize); void saveGameRules(uint8_t** dOut, unsigned int* dSize);
private: private:
LevelGenerationOptions *readHeader(DLCGameRulesHeader *grh); LevelGenerationOptions* readHeader(DLCGameRulesHeader* grh);
void writeRuleFile(DataOutputStream *dos); void writeRuleFile(DataOutputStream* dos);
public: public:
bool readRuleFile(LevelGenerationOptions *lgo, uint8_t *dIn, unsigned int dSize, StringTable *strings); //(DLCGameRulesFile *dlcFile, StringTable *strings); bool readRuleFile(LevelGenerationOptions* lgo, uint8_t* dIn,
unsigned int dSize,
StringTable* strings); //(DLCGameRulesFile *dlcFile,
//StringTable *strings);
private: private:
void readAttributes(DataInputStream *dis, std::vector<std::wstring> *tagsAndAtts, GameRuleDefinition *rule); void readAttributes(DataInputStream* dis,
void readChildren(DataInputStream *dis, std::vector<std::wstring> *tagsAndAtts, std::unordered_map<int, ConsoleGameRules::EGameRuleType> *tagIdMap, GameRuleDefinition *rule); std::vector<std::wstring>* tagsAndAtts,
GameRuleDefinition* rule);
void readChildren(
DataInputStream* dis, std::vector<std::wstring>* tagsAndAtts,
std::unordered_map<int, ConsoleGameRules::EGameRuleType>* tagIdMap,
GameRuleDefinition* rule);
public: public:
void processSchematics(LevelChunk *levelChunk); void processSchematics(LevelChunk* levelChunk);
void processSchematicsLighting(LevelChunk *levelChunk); void processSchematicsLighting(LevelChunk* levelChunk);
void loadDefaultGameRules(); void loadDefaultGameRules();
private: private:
bool loadGameRulesPack(File *path); bool loadGameRulesPack(File* path);
LEVEL_GEN_ID addLevelGenerationOptions(LevelGenerationOptions *); LEVEL_GEN_ID addLevelGenerationOptions(LevelGenerationOptions*);
public: public:
std::vector<LevelGenerationOptions *> *getLevelGenerators() { return m_levelGenerators.getLevelGenerators(); } std::vector<LevelGenerationOptions*>* getLevelGenerators() {
void setLevelGenerationOptions(LevelGenerationOptions *levelGen); return m_levelGenerators.getLevelGenerators();
LevelRuleset *getGameRuleDefinitions() { return m_currentGameRuleDefinitions; } }
LevelGenerationOptions *getLevelGenerationOptions() { return m_currentLevelGenerationOptions; } void setLevelGenerationOptions(LevelGenerationOptions* levelGen);
const wchar_t *GetGameRulesString(const std::wstring &key); LevelRuleset* getGameRuleDefinitions() {
return m_currentGameRuleDefinitions;
}
LevelGenerationOptions* getLevelGenerationOptions() {
return m_currentLevelGenerationOptions;
}
const wchar_t* GetGameRulesString(const std::wstring& key);
// 4J-JEV: // 4J-JEV:
// Properly cleans-up and unloads the current set of gameRules. // Properly cleans-up and unloads the current set of gameRules.

View file

@ -1,24 +1,24 @@
#pragma once #pragma once
//using namespace std; // using namespace std;
#include <vector> #include <vector>
#include "GameRule.h" #include "GameRule.h"
class GameRuleDefinition; class GameRuleDefinition;
// The game rule manager belongs to a player/server or other object, and maintains their current state for each of // The game rule manager belongs to a player/server or other object, and
// the rules that apply to them // maintains their current state for each of the rules that apply to them
class GameRulesInstance : public GameRule class GameRulesInstance : public GameRule {
{
public: public:
// These types are used by the GameRuleDefinition to know which rules to add to this GameRulesInstance // These types are used by the GameRuleDefinition to know which rules to add
enum EGameRulesInstanceType // to this GameRulesInstance
{ enum EGameRulesInstanceType {
eGameRulesInstanceType_ServerPlayer, eGameRulesInstanceType_ServerPlayer,
eGameRulesInstanceType_Server, eGameRulesInstanceType_Server,
eGameRulesInstanceType_Count eGameRulesInstanceType_Count
}; };
public: public:
GameRulesInstance(GameRuleDefinition *definition, Connection *connection) : GameRule(definition,connection) {} GameRulesInstance(GameRuleDefinition* definition, Connection* connection)
: GameRule(definition, connection) {}
// Functions for all the hooks should go here // Functions for all the hooks should go here
}; };

View file

@ -11,10 +11,9 @@
#include "LevelGenerationOptions.h" #include "LevelGenerationOptions.h"
#include "ConsoleGameRules.h" #include "ConsoleGameRules.h"
JustGrSource::JustGrSource() JustGrSource::JustGrSource() {
{
m_displayName = L"Default_DisplayName"; m_displayName = L"Default_DisplayName";
m_worldName= L"Default_WorldName"; m_worldName = L"Default_WorldName";
m_defaultSaveName = L"Default_DefaultSaveName"; m_defaultSaveName = L"Default_DefaultSaveName";
m_bRequiresTexturePack = false; m_bRequiresTexturePack = false;
m_requiredTexturePackId = 0; m_requiredTexturePackId = 0;
@ -22,27 +21,37 @@ JustGrSource::JustGrSource()
m_bRequiresBaseSave = false; m_bRequiresBaseSave = false;
} }
bool JustGrSource::requiresTexturePack() {return m_bRequiresTexturePack;} bool JustGrSource::requiresTexturePack() { return m_bRequiresTexturePack; }
std::uint32_t JustGrSource::getRequiredTexturePackId() {return m_requiredTexturePackId;} std::uint32_t JustGrSource::getRequiredTexturePackId() {
std::wstring JustGrSource::getDefaultSaveName() {return m_defaultSaveName;} return m_requiredTexturePackId;
const wchar_t *JustGrSource::getWorldName() {return m_worldName.c_str();} }
const wchar_t *JustGrSource::getDisplayName() {return m_displayName.c_str();} std::wstring JustGrSource::getDefaultSaveName() { return m_defaultSaveName; }
std::wstring JustGrSource::getGrfPath() {return m_grfPath;} const wchar_t* JustGrSource::getWorldName() { return m_worldName.c_str(); }
const wchar_t* JustGrSource::getDisplayName() { return m_displayName.c_str(); }
std::wstring JustGrSource::getGrfPath() { return m_grfPath; }
bool JustGrSource::requiresBaseSave() { return m_bRequiresBaseSave; }; bool JustGrSource::requiresBaseSave() { return m_bRequiresBaseSave; };
std::wstring JustGrSource::getBaseSavePath() { return m_baseSavePath; }; std::wstring JustGrSource::getBaseSavePath() { return m_baseSavePath; };
void JustGrSource::setRequiresTexturePack(bool x) {m_bRequiresTexturePack = x;} void JustGrSource::setRequiresTexturePack(bool x) {
void JustGrSource::setRequiredTexturePackId(std::uint32_t x) {m_requiredTexturePackId = x;} m_bRequiresTexturePack = x;
void JustGrSource::setDefaultSaveName(const std::wstring &x) {m_defaultSaveName = x;} }
void JustGrSource::setWorldName(const std::wstring &x) {m_worldName = x;} void JustGrSource::setRequiredTexturePackId(std::uint32_t x) {
void JustGrSource::setDisplayName(const std::wstring &x) {m_displayName = x;} m_requiredTexturePackId = x;
void JustGrSource::setGrfPath(const std::wstring &x) {m_grfPath = x;} }
void JustGrSource::setBaseSavePath(const std::wstring &x) { m_baseSavePath = x; m_bRequiresBaseSave = true; } void JustGrSource::setDefaultSaveName(const std::wstring& x) {
m_defaultSaveName = x;
}
void JustGrSource::setWorldName(const std::wstring& x) { m_worldName = x; }
void JustGrSource::setDisplayName(const std::wstring& x) { m_displayName = x; }
void JustGrSource::setGrfPath(const std::wstring& x) { m_grfPath = x; }
void JustGrSource::setBaseSavePath(const std::wstring& x) {
m_baseSavePath = x;
m_bRequiresBaseSave = true;
}
bool JustGrSource::ready() { return true; } bool JustGrSource::ready() { return true; }
LevelGenerationOptions::LevelGenerationOptions() LevelGenerationOptions::LevelGenerationOptions() {
{
m_spawnPos = NULL; m_spawnPos = NULL;
m_stringTable = NULL; m_stringTable = NULL;
@ -58,40 +67,39 @@ LevelGenerationOptions::LevelGenerationOptions()
m_baseSaveSize = 0; m_baseSaveSize = 0;
} }
LevelGenerationOptions::~LevelGenerationOptions() LevelGenerationOptions::~LevelGenerationOptions() {
{
clearSchematics(); clearSchematics();
if(m_spawnPos != NULL) delete m_spawnPos; if (m_spawnPos != NULL) delete m_spawnPos;
for(AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end(); ++it) for (AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end();
{ ++it) {
delete *it; delete *it;
} }
for(AUTO_VAR(it, m_structureRules.begin()); it != m_structureRules.end(); ++it) for (AUTO_VAR(it, m_structureRules.begin()); it != m_structureRules.end();
{ ++it) {
delete *it; delete *it;
} }
for(AUTO_VAR(it, m_biomeOverrides.begin()); it != m_biomeOverrides.end(); ++it) for (AUTO_VAR(it, m_biomeOverrides.begin()); it != m_biomeOverrides.end();
{ ++it) {
delete *it; delete *it;
} }
for(AUTO_VAR(it, m_features.begin()); it != m_features.end(); ++it) for (AUTO_VAR(it, m_features.begin()); it != m_features.end(); ++it) {
{
delete *it; delete *it;
} }
if (m_stringTable) if (m_stringTable)
if (!isTutorial()) if (!isTutorial()) delete m_stringTable;
delete m_stringTable;
if (isFromSave()) delete m_pSrc; if (isFromSave()) delete m_pSrc;
} }
ConsoleGameRules::EGameRuleType LevelGenerationOptions::getActionType() { return ConsoleGameRules::eGameRuleType_LevelGenerationOptions; } ConsoleGameRules::EGameRuleType LevelGenerationOptions::getActionType() {
return ConsoleGameRules::eGameRuleType_LevelGenerationOptions;
}
void LevelGenerationOptions::writeAttributes(DataOutputStream *dos, unsigned int numAttrs) void LevelGenerationOptions::writeAttributes(DataOutputStream* dos,
{ unsigned int numAttrs) {
GameRuleDefinition::writeAttributes(dos, numAttrs + 5); GameRuleDefinition::writeAttributes(dos, numAttrs + 5);
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_spawnX); ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_spawnX);
@ -107,140 +115,140 @@ void LevelGenerationOptions::writeAttributes(DataOutputStream *dos, unsigned int
dos->writeUTF(_toString(m_useFlatWorld)); dos->writeUTF(_toString(m_useFlatWorld));
} }
void LevelGenerationOptions::getChildren(std::vector<GameRuleDefinition *> *children) void LevelGenerationOptions::getChildren(
{ std::vector<GameRuleDefinition*>* children) {
GameRuleDefinition::getChildren(children); GameRuleDefinition::getChildren(children);
std::vector<ApplySchematicRuleDefinition *> used_schematics; std::vector<ApplySchematicRuleDefinition*> used_schematics;
for (AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end(); it++) for (AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end();
if ( !(*it)->isComplete() ) it++)
used_schematics.push_back( *it ); if (!(*it)->isComplete()) used_schematics.push_back(*it);
for(AUTO_VAR(it, m_structureRules.begin()); it!=m_structureRules.end(); it++) for (AUTO_VAR(it, m_structureRules.begin()); it != m_structureRules.end();
children->push_back( *it ); it++)
for(AUTO_VAR(it, used_schematics.begin()); it!=used_schematics.end(); it++) children->push_back(*it);
children->push_back( *it ); for (AUTO_VAR(it, used_schematics.begin()); it != used_schematics.end();
for(AUTO_VAR(it, m_biomeOverrides.begin()); it != m_biomeOverrides.end(); ++it) it++)
children->push_back( *it ); children->push_back(*it);
for(AUTO_VAR(it, m_features.begin()); it != m_features.end(); ++it) for (AUTO_VAR(it, m_biomeOverrides.begin()); it != m_biomeOverrides.end();
children->push_back( *it ); ++it)
children->push_back(*it);
for (AUTO_VAR(it, m_features.begin()); it != m_features.end(); ++it)
children->push_back(*it);
} }
GameRuleDefinition *LevelGenerationOptions::addChild(ConsoleGameRules::EGameRuleType ruleType) GameRuleDefinition* LevelGenerationOptions::addChild(
{ ConsoleGameRules::EGameRuleType ruleType) {
GameRuleDefinition *rule = NULL; GameRuleDefinition* rule = NULL;
if(ruleType == ConsoleGameRules::eGameRuleType_ApplySchematic) if (ruleType == ConsoleGameRules::eGameRuleType_ApplySchematic) {
{
rule = new ApplySchematicRuleDefinition(this); rule = new ApplySchematicRuleDefinition(this);
m_schematicRules.push_back((ApplySchematicRuleDefinition *)rule); m_schematicRules.push_back((ApplySchematicRuleDefinition*)rule);
} } else if (ruleType == ConsoleGameRules::eGameRuleType_GenerateStructure) {
else if(ruleType == ConsoleGameRules::eGameRuleType_GenerateStructure)
{
rule = new ConsoleGenerateStructure(); rule = new ConsoleGenerateStructure();
m_structureRules.push_back((ConsoleGenerateStructure *)rule); m_structureRules.push_back((ConsoleGenerateStructure*)rule);
} } else if (ruleType == ConsoleGameRules::eGameRuleType_BiomeOverride) {
else if(ruleType == ConsoleGameRules::eGameRuleType_BiomeOverride)
{
rule = new BiomeOverride(); rule = new BiomeOverride();
m_biomeOverrides.push_back((BiomeOverride *)rule); m_biomeOverrides.push_back((BiomeOverride*)rule);
} } else if (ruleType == ConsoleGameRules::eGameRuleType_StartFeature) {
else if(ruleType == ConsoleGameRules::eGameRuleType_StartFeature)
{
rule = new StartFeature(); rule = new StartFeature();
m_features.push_back((StartFeature *)rule); m_features.push_back((StartFeature*)rule);
} } else {
else
{
#ifndef _CONTENT_PACKAGE #ifndef _CONTENT_PACKAGE
wprintf(L"LevelGenerationOptions: Attempted to add invalid child rule - %d\n", ruleType ); wprintf(
L"LevelGenerationOptions: Attempted to add invalid child rule - "
L"%d\n",
ruleType);
#endif #endif
} }
return rule; return rule;
} }
void LevelGenerationOptions::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue) void LevelGenerationOptions::addAttribute(const std::wstring& attributeName,
{ const std::wstring& attributeValue) {
if(attributeName.compare(L"seed") == 0) if (attributeName.compare(L"seed") == 0) {
{
m_seed = _fromString<__int64>(attributeValue); m_seed = _fromString<__int64>(attributeValue);
app.DebugPrintf("LevelGenerationOptions: Adding parameter m_seed=%I64d\n",m_seed); app.DebugPrintf(
} "LevelGenerationOptions: Adding parameter m_seed=%I64d\n", m_seed);
else if(attributeName.compare(L"spawnX") == 0) } else if (attributeName.compare(L"spawnX") == 0) {
{ if (m_spawnPos == NULL) m_spawnPos = new Pos();
if(m_spawnPos == NULL) m_spawnPos = new Pos();
int value = _fromString<int>(attributeValue); int value = _fromString<int>(attributeValue);
m_spawnPos->x = value; m_spawnPos->x = value;
app.DebugPrintf("LevelGenerationOptions: Adding parameter spawnX=%d\n",value); app.DebugPrintf("LevelGenerationOptions: Adding parameter spawnX=%d\n",
} value);
else if(attributeName.compare(L"spawnY") == 0) } else if (attributeName.compare(L"spawnY") == 0) {
{ if (m_spawnPos == NULL) m_spawnPos = new Pos();
if(m_spawnPos == NULL) m_spawnPos = new Pos();
int value = _fromString<int>(attributeValue); int value = _fromString<int>(attributeValue);
m_spawnPos->y = value; m_spawnPos->y = value;
app.DebugPrintf("LevelGenerationOptions: Adding parameter spawnY=%d\n",value); app.DebugPrintf("LevelGenerationOptions: Adding parameter spawnY=%d\n",
} value);
else if(attributeName.compare(L"spawnZ") == 0) } else if (attributeName.compare(L"spawnZ") == 0) {
{ if (m_spawnPos == NULL) m_spawnPos = new Pos();
if(m_spawnPos == NULL) m_spawnPos = new Pos();
int value = _fromString<int>(attributeValue); int value = _fromString<int>(attributeValue);
m_spawnPos->z = value; m_spawnPos->z = value;
app.DebugPrintf("LevelGenerationOptions: Adding parameter spawnZ=%d\n",value); app.DebugPrintf("LevelGenerationOptions: Adding parameter spawnZ=%d\n",
} value);
else if(attributeName.compare(L"flatworld") == 0) } else if (attributeName.compare(L"flatworld") == 0) {
{ if (attributeValue.compare(L"true") == 0) m_useFlatWorld = true;
if(attributeValue.compare(L"true") == 0) m_useFlatWorld = true; app.DebugPrintf(
app.DebugPrintf("LevelGenerationOptions: Adding parameter flatworld=%s\n",m_useFlatWorld?"TRUE":"FALSE"); "LevelGenerationOptions: Adding parameter flatworld=%s\n",
} m_useFlatWorld ? "TRUE" : "FALSE");
else if(attributeName.compare(L"saveName") == 0) } else if (attributeName.compare(L"saveName") == 0) {
{
std::wstring string(getString(attributeValue)); std::wstring string(getString(attributeValue));
if(!string.empty()) setDefaultSaveName( string ); if (!string.empty())
else setDefaultSaveName( attributeValue ); setDefaultSaveName(string);
app.DebugPrintf("LevelGenerationOptions: Adding parameter saveName=%ls\n", getDefaultSaveName().c_str());
}
else if(attributeName.compare(L"worldName") == 0)
{
std::wstring string(getString(attributeValue));
if(!string.empty()) setWorldName( string );
else setWorldName( attributeValue );
app.DebugPrintf("LevelGenerationOptions: Adding parameter worldName=%ls\n", getWorldName());
}
else if(attributeName.compare(L"displayName") == 0)
{
std::wstring string(getString(attributeValue));
if(!string.empty()) setDisplayName( string );
else setDisplayName( attributeValue );
app.DebugPrintf("LevelGenerationOptions: Adding parameter displayName=%ls\n", getDisplayName());
}
else if(attributeName.compare(L"texturePackId") == 0)
{
setRequiredTexturePackId( _fromString<unsigned int>(attributeValue) );
setRequiresTexturePack( true );
app.DebugPrintf("LevelGenerationOptions: Adding parameter texturePackId=%0x\n", getRequiredTexturePackId());
}
else if(attributeName.compare(L"isTutorial") == 0)
{
if(attributeValue.compare(L"true") == 0) setSrc(eSrc_tutorial);
app.DebugPrintf("LevelGenerationOptions: Adding parameter isTutorial=%s\n",isTutorial()?"TRUE":"FALSE");
}
else if(attributeName.compare(L"baseSaveName") == 0)
{
setBaseSavePath( attributeValue );
app.DebugPrintf("LevelGenerationOptions: Adding parameter baseSaveName=%ls\n", getBaseSavePath().c_str());
}
else else
{ setDefaultSaveName(attributeValue);
app.DebugPrintf(
"LevelGenerationOptions: Adding parameter saveName=%ls\n",
getDefaultSaveName().c_str());
} else if (attributeName.compare(L"worldName") == 0) {
std::wstring string(getString(attributeValue));
if (!string.empty())
setWorldName(string);
else
setWorldName(attributeValue);
app.DebugPrintf(
"LevelGenerationOptions: Adding parameter worldName=%ls\n",
getWorldName());
} else if (attributeName.compare(L"displayName") == 0) {
std::wstring string(getString(attributeValue));
if (!string.empty())
setDisplayName(string);
else
setDisplayName(attributeValue);
app.DebugPrintf(
"LevelGenerationOptions: Adding parameter displayName=%ls\n",
getDisplayName());
} else if (attributeName.compare(L"texturePackId") == 0) {
setRequiredTexturePackId(_fromString<unsigned int>(attributeValue));
setRequiresTexturePack(true);
app.DebugPrintf(
"LevelGenerationOptions: Adding parameter texturePackId=%0x\n",
getRequiredTexturePackId());
} else if (attributeName.compare(L"isTutorial") == 0) {
if (attributeValue.compare(L"true") == 0) setSrc(eSrc_tutorial);
app.DebugPrintf(
"LevelGenerationOptions: Adding parameter isTutorial=%s\n",
isTutorial() ? "TRUE" : "FALSE");
} else if (attributeName.compare(L"baseSaveName") == 0) {
setBaseSavePath(attributeValue);
app.DebugPrintf(
"LevelGenerationOptions: Adding parameter baseSaveName=%ls\n",
getBaseSavePath().c_str());
} else {
GameRuleDefinition::addAttribute(attributeName, attributeValue); GameRuleDefinition::addAttribute(attributeName, attributeValue);
} }
} }
void LevelGenerationOptions::processSchematics(LevelChunk *chunk) void LevelGenerationOptions::processSchematics(LevelChunk* chunk) {
{ PIXBeginNamedEvent(0, "Processing schematics for chunk (%d,%d)", chunk->x,
PIXBeginNamedEvent(0,"Processing schematics for chunk (%d,%d)", chunk->x, chunk->z); chunk->z);
AABB *chunkBox = AABB::newTemp(chunk->x*16,0,chunk->z*16,chunk->x*16 + 16,Level::maxBuildHeight,chunk->z*16 + 16); AABB* chunkBox =
for( AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end();++it) AABB::newTemp(chunk->x * 16, 0, chunk->z * 16, chunk->x * 16 + 16,
{ Level::maxBuildHeight, chunk->z * 16 + 16);
ApplySchematicRuleDefinition *rule = *it; for (AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end();
++it) {
ApplySchematicRuleDefinition* rule = *it;
rule->processSchematic(chunkBox, chunk); rule->processSchematic(chunkBox, chunk);
} }
@ -248,13 +256,13 @@ void LevelGenerationOptions::processSchematics(LevelChunk *chunk)
int cx = ((unsigned)chunk->x << 4); int cx = ((unsigned)chunk->x << 4);
int cz = ((unsigned)chunk->z << 4); int cz = ((unsigned)chunk->z << 4);
for( AUTO_VAR(it, m_structureRules.begin()); it != m_structureRules.end(); it++ ) for (AUTO_VAR(it, m_structureRules.begin()); it != m_structureRules.end();
{ it++) {
ConsoleGenerateStructure *structureStart = *it; ConsoleGenerateStructure* structureStart = *it;
if (structureStart->getBoundingBox()->intersects(cx, cz, cx + 15, cz + 15)) if (structureStart->getBoundingBox()->intersects(cx, cz, cx + 15,
{ cz + 15)) {
BoundingBox *bb = new BoundingBox(cx, cz, cx + 15, cz + 15); BoundingBox* bb = new BoundingBox(cx, cz, cx + 15, cz + 15);
structureStart->postProcess(chunk->level, NULL, bb); structureStart->postProcess(chunk->level, NULL, bb);
delete bb; delete bb;
} }
@ -262,90 +270,93 @@ void LevelGenerationOptions::processSchematics(LevelChunk *chunk)
PIXEndNamedEvent(); PIXEndNamedEvent();
} }
void LevelGenerationOptions::processSchematicsLighting(LevelChunk *chunk) void LevelGenerationOptions::processSchematicsLighting(LevelChunk* chunk) {
{ PIXBeginNamedEvent(0, "Processing schematics (lighting) for chunk (%d,%d)",
PIXBeginNamedEvent(0,"Processing schematics (lighting) for chunk (%d,%d)", chunk->x, chunk->z); chunk->x, chunk->z);
AABB *chunkBox = AABB::newTemp(chunk->x*16,0,chunk->z*16,chunk->x*16 + 16,Level::maxBuildHeight,chunk->z*16 + 16); AABB* chunkBox =
for( AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end();++it) AABB::newTemp(chunk->x * 16, 0, chunk->z * 16, chunk->x * 16 + 16,
{ Level::maxBuildHeight, chunk->z * 16 + 16);
ApplySchematicRuleDefinition *rule = *it; for (AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end();
++it) {
ApplySchematicRuleDefinition* rule = *it;
rule->processSchematicLighting(chunkBox, chunk); rule->processSchematicLighting(chunkBox, chunk);
} }
PIXEndNamedEvent(); PIXEndNamedEvent();
} }
bool LevelGenerationOptions::checkIntersects(int x0, int y0, int z0, int x1, int y1, int z1) bool LevelGenerationOptions::checkIntersects(int x0, int y0, int z0, int x1,
{ int y1, int z1) {
PIXBeginNamedEvent(0,"Check Intersects"); PIXBeginNamedEvent(0, "Check Intersects");
// As an optimisation, we can quickly discard things below a certain y which makes most ore checks faster due to // As an optimisation, we can quickly discard things below a certain y which
// a) ores generally being below ground/sea level and b) tutorial world additions generally being above ground/sea level // makes most ore checks faster due to a) ores generally being below
if(!m_bHaveMinY) // ground/sea level and b) tutorial world additions generally being above
{ // ground/sea level
for(AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end();++it) if (!m_bHaveMinY) {
{ for (AUTO_VAR(it, m_schematicRules.begin());
ApplySchematicRuleDefinition *rule = *it; it != m_schematicRules.end(); ++it) {
ApplySchematicRuleDefinition* rule = *it;
int minY = rule->getMinY(); int minY = rule->getMinY();
if(minY < m_minY) m_minY = minY; if (minY < m_minY) m_minY = minY;
} }
for( AUTO_VAR(it, m_structureRules.begin()); it != m_structureRules.end(); it++ ) for (AUTO_VAR(it, m_structureRules.begin());
{ it != m_structureRules.end(); it++) {
ConsoleGenerateStructure *structureStart = *it; ConsoleGenerateStructure* structureStart = *it;
int minY = structureStart->getMinY(); int minY = structureStart->getMinY();
if(minY < m_minY) m_minY = minY; if (minY < m_minY) m_minY = minY;
} }
m_bHaveMinY = true; m_bHaveMinY = true;
} }
// 4J Stu - We DO NOT intersect if our upper bound is below the lower bound for all schematics // 4J Stu - We DO NOT intersect if our upper bound is below the lower bound
if( y1 < m_minY ) return false; // for all schematics
if (y1 < m_minY) return false;
bool intersects = false; bool intersects = false;
for(AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end();++it) for (AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end();
{ ++it) {
ApplySchematicRuleDefinition *rule = *it; ApplySchematicRuleDefinition* rule = *it;
intersects = rule->checkIntersects(x0,y0,z0,x1,y1,z1); intersects = rule->checkIntersects(x0, y0, z0, x1, y1, z1);
if(intersects) break; if (intersects) break;
} }
if(!intersects) if (!intersects) {
{ for (AUTO_VAR(it, m_structureRules.begin());
for( AUTO_VAR(it, m_structureRules.begin()); it != m_structureRules.end(); it++ ) it != m_structureRules.end(); it++) {
{ ConsoleGenerateStructure* structureStart = *it;
ConsoleGenerateStructure *structureStart = *it; intersects =
intersects = structureStart->checkIntersects(x0,y0,z0,x1,y1,z1); structureStart->checkIntersects(x0, y0, z0, x1, y1, z1);
if(intersects) break; if (intersects) break;
} }
} }
PIXEndNamedEvent(); PIXEndNamedEvent();
return intersects; return intersects;
} }
void LevelGenerationOptions::clearSchematics() void LevelGenerationOptions::clearSchematics() {
{ for (AUTO_VAR(it, m_schematics.begin()); it != m_schematics.end(); ++it) {
for(AUTO_VAR(it, m_schematics.begin()); it != m_schematics.end(); ++it)
{
delete it->second; delete it->second;
} }
m_schematics.clear(); m_schematics.clear();
} }
ConsoleSchematicFile *LevelGenerationOptions::loadSchematicFile(const std::wstring &filename, std::uint8_t *pbData, unsigned int dataLength) ConsoleSchematicFile* LevelGenerationOptions::loadSchematicFile(
{ const std::wstring& filename, std::uint8_t* pbData,
unsigned int dataLength) {
// If we have already loaded this, just return // If we have already loaded this, just return
AUTO_VAR(it, m_schematics.find(filename)); AUTO_VAR(it, m_schematics.find(filename));
if(it != m_schematics.end()) if (it != m_schematics.end()) {
{
#ifndef _CONTENT_PACKAGE #ifndef _CONTENT_PACKAGE
wprintf(L"We have already loaded schematic file %ls\n", filename.c_str() ); wprintf(L"We have already loaded schematic file %ls\n",
filename.c_str());
#endif #endif
it->second->incrementRefCount(); it->second->incrementRefCount();
return it->second; return it->second;
} }
ConsoleSchematicFile *schematic = NULL; ConsoleSchematicFile* schematic = NULL;
byteArray data(pbData, dataLength); byteArray data(pbData, dataLength);
ByteArrayInputStream bais(data); ByteArrayInputStream bais(data);
DataInputStream dis(&bais); DataInputStream dis(&bais);
@ -356,23 +367,23 @@ ConsoleSchematicFile *LevelGenerationOptions::loadSchematicFile(const std::wstri
return schematic; return schematic;
} }
ConsoleSchematicFile *LevelGenerationOptions::getSchematicFile(const std::wstring &filename) ConsoleSchematicFile* LevelGenerationOptions::getSchematicFile(
{ const std::wstring& filename) {
ConsoleSchematicFile *schematic = NULL; ConsoleSchematicFile* schematic = NULL;
// If we have already loaded this, just return // If we have already loaded this, just return
AUTO_VAR(it, m_schematics.find(filename)); AUTO_VAR(it, m_schematics.find(filename));
if(it != m_schematics.end()) if (it != m_schematics.end()) {
{
schematic = it->second; schematic = it->second;
} }
return schematic; return schematic;
} }
void LevelGenerationOptions::releaseSchematicFile(const std::wstring &filename) void LevelGenerationOptions::releaseSchematicFile(
{ const std::wstring& filename) {
// 4J Stu - We don't want to delete them when done, but probably want to keep a set of active schematics for the current world // 4J Stu - We don't want to delete them when done, but probably want to
//AUTO_VAR(it, m_schematics.find(filename)); // keep a set of active schematics for the current world
//if(it != m_schematics.end()) // AUTO_VAR(it, m_schematics.find(filename));
// if(it != m_schematics.end())
//{ //{
// ConsoleSchematicFile *schematic = it->second; // ConsoleSchematicFile *schematic = it->second;
// schematic->decrementRefCount(); // schematic->decrementRefCount();
@ -384,45 +395,37 @@ void LevelGenerationOptions::releaseSchematicFile(const std::wstring &filename)
//} //}
} }
void LevelGenerationOptions::loadStringTable(StringTable *table) void LevelGenerationOptions::loadStringTable(StringTable* table) {
{
m_stringTable = table; m_stringTable = table;
} }
const wchar_t *LevelGenerationOptions::getString(const std::wstring &key) const wchar_t* LevelGenerationOptions::getString(const std::wstring& key) {
{ if (m_stringTable == NULL) {
if(m_stringTable == NULL)
{
return L""; return L"";
} } else {
else
{
return m_stringTable->getString(key); return m_stringTable->getString(key);
} }
} }
void LevelGenerationOptions::getBiomeOverride(int biomeId, std::uint8_t &tile, std::uint8_t &topTile) void LevelGenerationOptions::getBiomeOverride(int biomeId, std::uint8_t& tile,
{ std::uint8_t& topTile) {
for(AUTO_VAR(it, m_biomeOverrides.begin()); it != m_biomeOverrides.end(); ++it) for (AUTO_VAR(it, m_biomeOverrides.begin()); it != m_biomeOverrides.end();
{ ++it) {
BiomeOverride *bo = *it; BiomeOverride* bo = *it;
if(bo->isBiome(biomeId)) if (bo->isBiome(biomeId)) {
{ bo->getTileValues(tile, topTile);
bo->getTileValues(tile,topTile);
break; break;
} }
} }
} }
bool LevelGenerationOptions::isFeatureChunk(int chunkX, int chunkZ, StructureFeature::EFeatureTypes feature) bool LevelGenerationOptions::isFeatureChunk(
{ int chunkX, int chunkZ, StructureFeature::EFeatureTypes feature) {
bool isFeature = false; bool isFeature = false;
for(AUTO_VAR(it, m_features.begin()); it != m_features.end(); ++it) for (AUTO_VAR(it, m_features.begin()); it != m_features.end(); ++it) {
{ StartFeature* sf = *it;
StartFeature *sf = *it; if (sf->isFeatureChunk(chunkX, chunkZ, feature)) {
if(sf->isFeatureChunk(chunkX, chunkZ, feature))
{
isFeature = true; isFeature = true;
break; break;
} }
@ -430,46 +433,43 @@ bool LevelGenerationOptions::isFeatureChunk(int chunkX, int chunkZ, StructureFea
return isFeature; return isFeature;
} }
std::unordered_map<std::wstring, ConsoleSchematicFile *> *LevelGenerationOptions::getUnfinishedSchematicFiles() std::unordered_map<std::wstring, ConsoleSchematicFile*>*
{ LevelGenerationOptions::getUnfinishedSchematicFiles() {
// Clean schematic rules. // Clean schematic rules.
std::unordered_set<std::wstring> usedFiles = std::unordered_set<std::wstring>(); std::unordered_set<std::wstring> usedFiles =
for (AUTO_VAR(it, m_schematicRules.begin()); it!=m_schematicRules.end(); it++) std::unordered_set<std::wstring>();
if ( !(*it)->isComplete() ) for (AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end();
usedFiles.insert( (*it)->getSchematicName() ); it++)
if (!(*it)->isComplete()) usedFiles.insert((*it)->getSchematicName());
// Clean schematic files. // Clean schematic files.
std::unordered_map<std::wstring, ConsoleSchematicFile *> *out std::unordered_map<std::wstring, ConsoleSchematicFile*>* out =
= new std::unordered_map<std::wstring, ConsoleSchematicFile *>(); new std::unordered_map<std::wstring, ConsoleSchematicFile*>();
for (AUTO_VAR(it, usedFiles.begin()); it!=usedFiles.end(); it++) for (AUTO_VAR(it, usedFiles.begin()); it != usedFiles.end(); it++)
out->insert( std::pair<std::wstring, ConsoleSchematicFile *>(*it, getSchematicFile(*it)) ); out->insert(std::pair<std::wstring, ConsoleSchematicFile*>(
*it, getSchematicFile(*it)));
return out; return out;
} }
void LevelGenerationOptions::reset_start() void LevelGenerationOptions::reset_start() {
{ for (AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end();
for ( AUTO_VAR( it, m_schematicRules.begin()); it++) {
it != m_schematicRules.end();
it++ )
{
(*it)->reset(); (*it)->reset();
} }
} }
void LevelGenerationOptions::reset_finish() void LevelGenerationOptions::reset_finish() {
{ // if (m_spawnPos) { delete m_spawnPos; m_spawnPos
//if (m_spawnPos) { delete m_spawnPos; m_spawnPos = NULL; } // = NULL; } if (m_stringTable) { delete m_stringTable;
//if (m_stringTable) { delete m_stringTable; m_stringTable = NULL; } // m_stringTable = NULL; }
if (isFromDLC()) if (isFromDLC()) {
{
m_hasLoadedData = false; m_hasLoadedData = false;
} }
} }
GrSource* LevelGenerationOptions::info() { return m_pSrc; }
GrSource *LevelGenerationOptions::info() { return m_pSrc; }
void LevelGenerationOptions::setSrc(eSrc src) { m_src = src; } void LevelGenerationOptions::setSrc(eSrc src) { m_src = src; }
LevelGenerationOptions::eSrc LevelGenerationOptions::getSrc() { return m_src; } LevelGenerationOptions::eSrc LevelGenerationOptions::getSrc() { return m_src; }
@ -477,39 +477,89 @@ bool LevelGenerationOptions::isTutorial() { return getSrc() == eSrc_tutorial; }
bool LevelGenerationOptions::isFromSave() { return getSrc() == eSrc_fromSave; } bool LevelGenerationOptions::isFromSave() { return getSrc() == eSrc_fromSave; }
bool LevelGenerationOptions::isFromDLC() { return getSrc() == eSrc_fromDLC; } bool LevelGenerationOptions::isFromDLC() { return getSrc() == eSrc_fromDLC; }
bool LevelGenerationOptions::requiresTexturePack() { return info()->requiresTexturePack(); } bool LevelGenerationOptions::requiresTexturePack() {
std::uint32_t LevelGenerationOptions::getRequiredTexturePackId() { return info()->getRequiredTexturePackId(); } return info()->requiresTexturePack();
std::wstring LevelGenerationOptions::getDefaultSaveName() { return info()->getDefaultSaveName(); } }
const wchar_t *LevelGenerationOptions::getWorldName() { return info()->getWorldName(); } std::uint32_t LevelGenerationOptions::getRequiredTexturePackId() {
const wchar_t *LevelGenerationOptions::getDisplayName() { return info()->getDisplayName(); } return info()->getRequiredTexturePackId();
std::wstring LevelGenerationOptions::getGrfPath() { return info()->getGrfPath(); } }
bool LevelGenerationOptions::requiresBaseSave() { return info()->requiresBaseSave(); } std::wstring LevelGenerationOptions::getDefaultSaveName() {
std::wstring LevelGenerationOptions::getBaseSavePath() { return info()->getBaseSavePath(); } return info()->getDefaultSaveName();
}
const wchar_t* LevelGenerationOptions::getWorldName() {
return info()->getWorldName();
}
const wchar_t* LevelGenerationOptions::getDisplayName() {
return info()->getDisplayName();
}
std::wstring LevelGenerationOptions::getGrfPath() {
return info()->getGrfPath();
}
bool LevelGenerationOptions::requiresBaseSave() {
return info()->requiresBaseSave();
}
std::wstring LevelGenerationOptions::getBaseSavePath() {
return info()->getBaseSavePath();
}
void LevelGenerationOptions::setGrSource(GrSource *grs) { m_pSrc = grs; } void LevelGenerationOptions::setGrSource(GrSource* grs) { m_pSrc = grs; }
void LevelGenerationOptions::setRequiresTexturePack(bool x) { info()->setRequiresTexturePack(x); } void LevelGenerationOptions::setRequiresTexturePack(bool x) {
void LevelGenerationOptions::setRequiredTexturePackId(std::uint32_t x) { info()->setRequiredTexturePackId(x); } info()->setRequiresTexturePack(x);
void LevelGenerationOptions::setDefaultSaveName(const std::wstring &x) { info()->setDefaultSaveName(x); } }
void LevelGenerationOptions::setWorldName(const std::wstring &x) { info()->setWorldName(x); } void LevelGenerationOptions::setRequiredTexturePackId(std::uint32_t x) {
void LevelGenerationOptions::setDisplayName(const std::wstring &x) { info()->setDisplayName(x); } info()->setRequiredTexturePackId(x);
void LevelGenerationOptions::setGrfPath(const std::wstring &x) { info()->setGrfPath(x); } }
void LevelGenerationOptions::setBaseSavePath(const std::wstring &x) { info()->setBaseSavePath(x); } void LevelGenerationOptions::setDefaultSaveName(const std::wstring& x) {
info()->setDefaultSaveName(x);
}
void LevelGenerationOptions::setWorldName(const std::wstring& x) {
info()->setWorldName(x);
}
void LevelGenerationOptions::setDisplayName(const std::wstring& x) {
info()->setDisplayName(x);
}
void LevelGenerationOptions::setGrfPath(const std::wstring& x) {
info()->setGrfPath(x);
}
void LevelGenerationOptions::setBaseSavePath(const std::wstring& x) {
info()->setBaseSavePath(x);
}
bool LevelGenerationOptions::ready() { return info()->ready(); } bool LevelGenerationOptions::ready() { return info()->ready(); }
void LevelGenerationOptions::setBaseSaveData(std::uint8_t *pbData, unsigned int dataSize) { m_pbBaseSaveData = pbData; m_baseSaveSize = dataSize; } void LevelGenerationOptions::setBaseSaveData(std::uint8_t* pbData,
std::uint8_t *LevelGenerationOptions::getBaseSaveData(unsigned int &size) { size = m_baseSaveSize; return m_pbBaseSaveData; } unsigned int dataSize) {
bool LevelGenerationOptions::hasBaseSaveData() { return m_baseSaveSize > 0 && m_pbBaseSaveData != NULL; } m_pbBaseSaveData = pbData;
void LevelGenerationOptions::deleteBaseSaveData() { delete[] m_pbBaseSaveData; m_pbBaseSaveData = NULL; m_baseSaveSize = 0; } m_baseSaveSize = dataSize;
}
std::uint8_t* LevelGenerationOptions::getBaseSaveData(unsigned int& size) {
size = m_baseSaveSize;
return m_pbBaseSaveData;
}
bool LevelGenerationOptions::hasBaseSaveData() {
return m_baseSaveSize > 0 && m_pbBaseSaveData != NULL;
}
void LevelGenerationOptions::deleteBaseSaveData() {
delete[] m_pbBaseSaveData;
m_pbBaseSaveData = NULL;
m_baseSaveSize = 0;
}
bool LevelGenerationOptions::hasLoadedData() { return m_hasLoadedData; } bool LevelGenerationOptions::hasLoadedData() { return m_hasLoadedData; }
void LevelGenerationOptions::setLoadedData() { m_hasLoadedData = true; } void LevelGenerationOptions::setLoadedData() { m_hasLoadedData = true; }
__int64 LevelGenerationOptions::getLevelSeed() { return m_seed; } __int64 LevelGenerationOptions::getLevelSeed() { return m_seed; }
Pos *LevelGenerationOptions::getSpawnPos() { return m_spawnPos; } Pos* LevelGenerationOptions::getSpawnPos() { return m_spawnPos; }
bool LevelGenerationOptions::getuseFlatWorld() { return m_useFlatWorld; } bool LevelGenerationOptions::getuseFlatWorld() { return m_useFlatWorld; }
bool LevelGenerationOptions::requiresGameRules() { return m_bRequiresGameRules; } bool LevelGenerationOptions::requiresGameRules() {
void LevelGenerationOptions::setRequiredGameRules(LevelRuleset *rules) { m_requiredGameRules = rules; m_bRequiresGameRules = true; } return m_bRequiresGameRules;
LevelRuleset *LevelGenerationOptions::getRequiredGameRules() { return m_requiredGameRules; } }
void LevelGenerationOptions::setRequiredGameRules(LevelRuleset* rules) {
m_requiredGameRules = rules;
m_bRequiresGameRules = true;
}
LevelRuleset* LevelGenerationOptions::getRequiredGameRules() {
return m_requiredGameRules;
}

View file

@ -1,5 +1,5 @@
#pragma once #pragma once
//using namespace std; // using namespace std;
// #pragma message("LevelGenerationOptions.h ") // #pragma message("LevelGenerationOptions.h ")
@ -16,39 +16,37 @@ class LevelRuleset;
class BiomeOverride; class BiomeOverride;
class StartFeature; class StartFeature;
class GrSource class GrSource {
{
public: public:
// 4J-JEV: // 4J-JEV:
// Moved all this here; I didn't like that all this header information // Moved all this here; I didn't like that all this header information
// was being mixed in with all the game information as they have // was being mixed in with all the game information as they have
// completely different lifespans. // completely different lifespans.
virtual ~GrSource(){} virtual ~GrSource() {}
virtual bool requiresTexturePack()=0; virtual bool requiresTexturePack() = 0;
virtual std::uint32_t getRequiredTexturePackId()=0; virtual std::uint32_t getRequiredTexturePackId() = 0;
virtual std::wstring getDefaultSaveName()=0; virtual std::wstring getDefaultSaveName() = 0;
virtual const wchar_t *getWorldName()=0; virtual const wchar_t* getWorldName() = 0;
virtual const wchar_t *getDisplayName()=0; virtual const wchar_t* getDisplayName() = 0;
virtual std::wstring getGrfPath()=0; virtual std::wstring getGrfPath() = 0;
virtual bool requiresBaseSave() = 0; virtual bool requiresBaseSave() = 0;
virtual std::wstring getBaseSavePath() = 0; virtual std::wstring getBaseSavePath() = 0;
virtual void setRequiresTexturePack(bool)=0; virtual void setRequiresTexturePack(bool) = 0;
virtual void setRequiredTexturePackId(std::uint32_t)=0; virtual void setRequiredTexturePackId(std::uint32_t) = 0;
virtual void setDefaultSaveName(const std::wstring &)=0; virtual void setDefaultSaveName(const std::wstring&) = 0;
virtual void setWorldName(const std::wstring &)=0; virtual void setWorldName(const std::wstring&) = 0;
virtual void setDisplayName(const std::wstring &)=0; virtual void setDisplayName(const std::wstring&) = 0;
virtual void setGrfPath(const std::wstring &)=0; virtual void setGrfPath(const std::wstring&) = 0;
virtual void setBaseSavePath(const std::wstring &)=0; virtual void setBaseSavePath(const std::wstring&) = 0;
virtual bool ready()=0; virtual bool ready() = 0;
//virtual void getGrfData(std::uint8_t *&pData, unsigned int &pSize)=0; // virtual void getGrfData(std::uint8_t *&pData, unsigned int &pSize)=0;
}; };
class JustGrSource : public GrSource class JustGrSource : public GrSource {
{
protected: protected:
std::wstring m_worldName; std::wstring m_worldName;
std::wstring m_displayName; std::wstring m_displayName;
@ -63,37 +61,37 @@ public:
virtual bool requiresTexturePack(); virtual bool requiresTexturePack();
virtual std::uint32_t getRequiredTexturePackId(); virtual std::uint32_t getRequiredTexturePackId();
virtual std::wstring getDefaultSaveName(); virtual std::wstring getDefaultSaveName();
virtual const wchar_t *getWorldName(); virtual const wchar_t* getWorldName();
virtual const wchar_t *getDisplayName(); virtual const wchar_t* getDisplayName();
virtual std::wstring getGrfPath(); virtual std::wstring getGrfPath();
virtual bool requiresBaseSave(); virtual bool requiresBaseSave();
virtual std::wstring getBaseSavePath(); virtual std::wstring getBaseSavePath();
virtual void setRequiresTexturePack(bool x); virtual void setRequiresTexturePack(bool x);
virtual void setRequiredTexturePackId(std::uint32_t x); virtual void setRequiredTexturePackId(std::uint32_t x);
virtual void setDefaultSaveName(const std::wstring &x); virtual void setDefaultSaveName(const std::wstring& x);
virtual void setWorldName(const std::wstring &x); virtual void setWorldName(const std::wstring& x);
virtual void setDisplayName(const std::wstring &x); virtual void setDisplayName(const std::wstring& x);
virtual void setGrfPath(const std::wstring &x); virtual void setGrfPath(const std::wstring& x);
virtual void setBaseSavePath(const std::wstring &x); virtual void setBaseSavePath(const std::wstring& x);
virtual bool ready(); virtual bool ready();
JustGrSource(); JustGrSource();
}; };
class LevelGenerationOptions : public GameRuleDefinition class LevelGenerationOptions : public GameRuleDefinition {
{
public: public:
enum eSrc enum eSrc {
{
eSrc_none, eSrc_none,
eSrc_fromSave, // Neither content or header is persistent. eSrc_fromSave, // Neither content or header is persistent.
eSrc_fromDLC, // Header is persistent, content should be deleted to conserve space. eSrc_fromDLC, // Header is persistent, content should be deleted to
// conserve space.
eSrc_tutorial, // Both header and content is persistent, content cannot be reloaded. eSrc_tutorial, // Both header and content is persistent, content cannot
// be reloaded.
eSrc_MAX eSrc_MAX
}; };
@ -101,16 +99,15 @@ public:
private: private:
eSrc m_src; eSrc m_src;
GrSource *m_pSrc; GrSource* m_pSrc;
GrSource *info(); GrSource* info();
bool m_hasLoadedData; bool m_hasLoadedData;
std::uint8_t *m_pbBaseSaveData; std::uint8_t* m_pbBaseSaveData;
unsigned int m_baseSaveSize; unsigned int m_baseSaveSize;
public: public:
void setSrc(eSrc src); void setSrc(eSrc src);
eSrc getSrc(); eSrc getSrc();
@ -121,26 +118,26 @@ public:
bool requiresTexturePack(); bool requiresTexturePack();
std::uint32_t getRequiredTexturePackId(); std::uint32_t getRequiredTexturePackId();
std::wstring getDefaultSaveName(); std::wstring getDefaultSaveName();
const wchar_t *getWorldName(); const wchar_t* getWorldName();
const wchar_t *getDisplayName(); const wchar_t* getDisplayName();
std::wstring getGrfPath(); std::wstring getGrfPath();
bool requiresBaseSave(); bool requiresBaseSave();
std::wstring getBaseSavePath(); std::wstring getBaseSavePath();
void setGrSource(GrSource *grs); void setGrSource(GrSource* grs);
void setRequiresTexturePack(bool x); void setRequiresTexturePack(bool x);
void setRequiredTexturePackId(std::uint32_t x); void setRequiredTexturePackId(std::uint32_t x);
void setDefaultSaveName(const std::wstring &x); void setDefaultSaveName(const std::wstring& x);
void setWorldName(const std::wstring &x); void setWorldName(const std::wstring& x);
void setDisplayName(const std::wstring &x); void setDisplayName(const std::wstring& x);
void setGrfPath(const std::wstring &x); void setGrfPath(const std::wstring& x);
void setBaseSavePath(const std::wstring &x); void setBaseSavePath(const std::wstring& x);
bool ready(); bool ready();
void setBaseSaveData(std::uint8_t *pbData, unsigned int dataSize); void setBaseSaveData(std::uint8_t* pbData, unsigned int dataSize);
std::uint8_t *getBaseSaveData(unsigned int &size); std::uint8_t* getBaseSaveData(unsigned int& size);
bool hasBaseSaveData(); bool hasBaseSaveData();
void deleteBaseSaveData(); void deleteBaseSaveData();
@ -151,19 +148,19 @@ private:
// This should match the "MapOptionsRule" definition in the XML schema // This should match the "MapOptionsRule" definition in the XML schema
__int64 m_seed; __int64 m_seed;
bool m_useFlatWorld; bool m_useFlatWorld;
Pos *m_spawnPos; Pos* m_spawnPos;
std::vector<ApplySchematicRuleDefinition *> m_schematicRules; std::vector<ApplySchematicRuleDefinition*> m_schematicRules;
std::vector<ConsoleGenerateStructure *> m_structureRules; std::vector<ConsoleGenerateStructure*> m_structureRules;
bool m_bHaveMinY; bool m_bHaveMinY;
int m_minY; int m_minY;
std::unordered_map<std::wstring, ConsoleSchematicFile *> m_schematics; std::unordered_map<std::wstring, ConsoleSchematicFile*> m_schematics;
std::vector<BiomeOverride *> m_biomeOverrides; std::vector<BiomeOverride*> m_biomeOverrides;
std::vector<StartFeature *> m_features; std::vector<StartFeature*> m_features;
bool m_bRequiresGameRules; bool m_bRequiresGameRules;
LevelRuleset *m_requiredGameRules; LevelRuleset* m_requiredGameRules;
StringTable *m_stringTable; StringTable* m_stringTable;
public: public:
LevelGenerationOptions(); LevelGenerationOptions();
@ -171,17 +168,20 @@ public:
virtual ConsoleGameRules::EGameRuleType getActionType(); virtual ConsoleGameRules::EGameRuleType getActionType();
virtual void writeAttributes(DataOutputStream *dos, unsigned int numAttributes); virtual void writeAttributes(DataOutputStream* dos,
virtual void getChildren(std::vector<GameRuleDefinition *> *children); unsigned int numAttributes);
virtual GameRuleDefinition *addChild(ConsoleGameRules::EGameRuleType ruleType); virtual void getChildren(std::vector<GameRuleDefinition*>* children);
virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue); virtual GameRuleDefinition* addChild(
ConsoleGameRules::EGameRuleType ruleType);
virtual void addAttribute(const std::wstring& attributeName,
const std::wstring& attributeValue);
__int64 getLevelSeed(); __int64 getLevelSeed();
Pos *getSpawnPos(); Pos* getSpawnPos();
bool getuseFlatWorld(); bool getuseFlatWorld();
void processSchematics(LevelChunk *chunk); void processSchematics(LevelChunk* chunk);
void processSchematicsLighting(LevelChunk *chunk); void processSchematicsLighting(LevelChunk* chunk);
bool checkIntersects(int x0, int y0, int z0, int x1, int y1, int z1); bool checkIntersects(int x0, int y0, int z0, int x1, int y1, int z1);
@ -189,23 +189,28 @@ private:
void clearSchematics(); void clearSchematics();
public: public:
ConsoleSchematicFile *loadSchematicFile(const std::wstring &filename, std::uint8_t *pbData, unsigned int dataLength); ConsoleSchematicFile* loadSchematicFile(const std::wstring& filename,
std::uint8_t* pbData,
unsigned int dataLength);
public: public:
ConsoleSchematicFile *getSchematicFile(const std::wstring &filename); ConsoleSchematicFile* getSchematicFile(const std::wstring& filename);
void releaseSchematicFile(const std::wstring &filename); void releaseSchematicFile(const std::wstring& filename);
bool requiresGameRules(); bool requiresGameRules();
void setRequiredGameRules(LevelRuleset *rules); void setRequiredGameRules(LevelRuleset* rules);
LevelRuleset *getRequiredGameRules(); LevelRuleset* getRequiredGameRules();
void getBiomeOverride(int biomeId, std::uint8_t &tile, std::uint8_t &topTile); void getBiomeOverride(int biomeId, std::uint8_t& tile,
bool isFeatureChunk(int chunkX, int chunkZ, StructureFeature::EFeatureTypes feature); std::uint8_t& topTile);
bool isFeatureChunk(int chunkX, int chunkZ,
StructureFeature::EFeatureTypes feature);
void loadStringTable(StringTable *table); void loadStringTable(StringTable* table);
const wchar_t *getString(const std::wstring &key); const wchar_t* getString(const std::wstring& key);
std::unordered_map<std::wstring, ConsoleSchematicFile *> *getUnfinishedSchematicFiles(); std::unordered_map<std::wstring, ConsoleSchematicFile*>*
getUnfinishedSchematicFiles();
// 4J-JEV: // 4J-JEV:
// ApplySchematicRules contain limited state // ApplySchematicRules contain limited state

View file

@ -2,25 +2,18 @@
#include "LevelGenerationOptions.h" #include "LevelGenerationOptions.h"
#include "LevelGenerators.h" #include "LevelGenerators.h"
LevelGenerators::LevelGenerators() {}
LevelGenerators::LevelGenerators() void LevelGenerators::addLevelGenerator(const std::wstring& displayName,
{ LevelGenerationOptions* generator) {
} if (!displayName.empty()) generator->setDisplayName(displayName);
void LevelGenerators::addLevelGenerator(const std::wstring &displayName, LevelGenerationOptions *generator)
{
if(!displayName.empty()) generator->setDisplayName(displayName);
m_levelGenerators.push_back(generator); m_levelGenerators.push_back(generator);
} }
void LevelGenerators::removeLevelGenerator(LevelGenerationOptions *generator) void LevelGenerators::removeLevelGenerator(LevelGenerationOptions* generator) {
{ std::vector<LevelGenerationOptions*>::iterator it;
std::vector<LevelGenerationOptions *>::iterator it; while ((it = find(m_levelGenerators.begin(), m_levelGenerators.end(),
while ( (it = find( m_levelGenerators.begin(), generator)) != m_levelGenerators.end()) {
m_levelGenerators.end(),
generator ) )
!= m_levelGenerators.end() )
{
m_levelGenerators.erase(it); m_levelGenerators.erase(it);
} }
} }

View file

@ -1,19 +1,21 @@
#pragma once #pragma once
//using namespace std; // using namespace std;
class LevelGenerationOptions; class LevelGenerationOptions;
class LevelGenerators class LevelGenerators {
{
private: private:
std::vector<LevelGenerationOptions *> m_levelGenerators; std::vector<LevelGenerationOptions*> m_levelGenerators;
public: public:
LevelGenerators(); LevelGenerators();
void addLevelGenerator(const std::wstring &displayName, LevelGenerationOptions *generator); void addLevelGenerator(const std::wstring& displayName,
void removeLevelGenerator(LevelGenerationOptions *generator); LevelGenerationOptions* generator);
void removeLevelGenerator(LevelGenerationOptions* generator);
std::vector<LevelGenerationOptions *> *getLevelGenerators() { return &m_levelGenerators; } std::vector<LevelGenerationOptions*>* getLevelGenerators() {
return &m_levelGenerators;
}
}; };

View file

@ -1,20 +1,14 @@
#include "../../Minecraft.World/Platform/stdafx.h" #include "../../Minecraft.World/Platform/stdafx.h"
#include "LevelRules.h" #include "LevelRules.h"
LevelRules::LevelRules() {}
LevelRules::LevelRules() void LevelRules::addLevelRule(const std::wstring& displayName,
{ std::uint8_t* pbData, unsigned int dataLength) {}
}
void LevelRules::addLevelRule(const std::wstring &displayName, std::uint8_t *pbData, unsigned int dataLength) void LevelRules::addLevelRule(const std::wstring& displayName,
{ LevelRuleset* rootRule) {}
}
void LevelRules::addLevelRule(const std::wstring &displayName, LevelRuleset *rootRule) void LevelRules::removeLevelRule(LevelRuleset* removing) {
{
}
void LevelRules::removeLevelRule(LevelRuleset *removing)
{
// TODO ? // TODO ?
} }

View file

@ -2,13 +2,13 @@
class LevelRuleset; class LevelRuleset;
class LevelRules class LevelRules {
{
public: public:
LevelRules(); LevelRules();
void addLevelRule(const std::wstring &displayName, std::uint8_t *pbData, unsigned int dataLength); void addLevelRule(const std::wstring& displayName, std::uint8_t* pbData,
void addLevelRule(const std::wstring &displayName, LevelRuleset *rootRule); unsigned int dataLength);
void addLevelRule(const std::wstring& displayName, LevelRuleset* rootRule);
void removeLevelRule(LevelRuleset *removing); void removeLevelRule(LevelRuleset* removing);
}; };

View file

@ -4,65 +4,48 @@
#include "ConsoleGameRules.h" #include "ConsoleGameRules.h"
#include "LevelRuleset.h" #include "LevelRuleset.h"
LevelRuleset::LevelRuleset() LevelRuleset::LevelRuleset() { m_stringTable = NULL; }
{
m_stringTable = NULL;
}
LevelRuleset::~LevelRuleset() LevelRuleset::~LevelRuleset() {
{ for (AUTO_VAR(it, m_areas.begin()); it != m_areas.end(); ++it) {
for(AUTO_VAR(it, m_areas.begin()); it != m_areas.end(); ++it)
{
delete *it; delete *it;
} }
} }
void LevelRuleset::getChildren(std::vector<GameRuleDefinition *> *children) void LevelRuleset::getChildren(std::vector<GameRuleDefinition*>* children) {
{
CompoundGameRuleDefinition::getChildren(children); CompoundGameRuleDefinition::getChildren(children);
for (AUTO_VAR(it, m_areas.begin()); it != m_areas.end(); it++) for (AUTO_VAR(it, m_areas.begin()); it != m_areas.end(); it++)
children->push_back(*it); children->push_back(*it);
} }
GameRuleDefinition *LevelRuleset::addChild(ConsoleGameRules::EGameRuleType ruleType) GameRuleDefinition* LevelRuleset::addChild(
{ ConsoleGameRules::EGameRuleType ruleType) {
GameRuleDefinition *rule = NULL; GameRuleDefinition* rule = NULL;
if(ruleType == ConsoleGameRules::eGameRuleType_NamedArea) if (ruleType == ConsoleGameRules::eGameRuleType_NamedArea) {
{
rule = new NamedAreaRuleDefinition(); rule = new NamedAreaRuleDefinition();
m_areas.push_back((NamedAreaRuleDefinition *)rule); m_areas.push_back((NamedAreaRuleDefinition*)rule);
} } else {
else
{
rule = CompoundGameRuleDefinition::addChild(ruleType); rule = CompoundGameRuleDefinition::addChild(ruleType);
} }
return rule; return rule;
} }
void LevelRuleset::loadStringTable(StringTable *table) void LevelRuleset::loadStringTable(StringTable* table) {
{
m_stringTable = table; m_stringTable = table;
} }
const wchar_t *LevelRuleset::getString(const std::wstring &key) const wchar_t* LevelRuleset::getString(const std::wstring& key) {
{ if (m_stringTable == NULL) {
if(m_stringTable == NULL)
{
return L""; return L"";
} } else {
else
{
return m_stringTable->getString(key); return m_stringTable->getString(key);
} }
} }
AABB *LevelRuleset::getNamedArea(const std::wstring &areaName) AABB* LevelRuleset::getNamedArea(const std::wstring& areaName) {
{ AABB* area = NULL;
AABB *area = NULL; for (AUTO_VAR(it, m_areas.begin()); it != m_areas.end(); ++it) {
for(AUTO_VAR(it, m_areas.begin()); it != m_areas.end(); ++it) if ((*it)->getName().compare(areaName) == 0) {
{
if( (*it)->getName().compare(areaName) == 0 )
{
area = (*it)->getArea(); area = (*it)->getArea();
break; break;
} }

View file

@ -4,24 +4,27 @@
class NamedAreaRuleDefinition; class NamedAreaRuleDefinition;
class LevelRuleset : public CompoundGameRuleDefinition class LevelRuleset : public CompoundGameRuleDefinition {
{
private: private:
std::vector<NamedAreaRuleDefinition *> m_areas; std::vector<NamedAreaRuleDefinition*> m_areas;
StringTable *m_stringTable; StringTable* m_stringTable;
public: public:
LevelRuleset(); LevelRuleset();
~LevelRuleset(); ~LevelRuleset();
virtual void getChildren(std::vector<GameRuleDefinition *> *children); virtual void getChildren(std::vector<GameRuleDefinition*>* children);
virtual GameRuleDefinition *addChild(ConsoleGameRules::EGameRuleType ruleType); virtual GameRuleDefinition* addChild(
ConsoleGameRules::EGameRuleType ruleType);
virtual ConsoleGameRules::EGameRuleType getActionType() { return ConsoleGameRules::eGameRuleType_LevelRules; } virtual ConsoleGameRules::EGameRuleType getActionType() {
return ConsoleGameRules::eGameRuleType_LevelRules;
}
void loadStringTable(StringTable *table); void loadStringTable(StringTable* table);
const wchar_t *getString(const std::wstring &key); const wchar_t* getString(const std::wstring& key);
AABB *getNamedArea(const std::wstring &areaName); AABB* getNamedArea(const std::wstring& areaName);
StringTable *getStringTable() { return m_stringTable; } StringTable* getStringTable() { return m_stringTable; }
}; };

View file

@ -3,19 +3,15 @@
#include "../../Minecraft.World/Util/StringHelpers.h" #include "../../Minecraft.World/Util/StringHelpers.h"
#include "../../Minecraft.World/Headers/net.minecraft.world.phys.h" #include "../../Minecraft.World/Headers/net.minecraft.world.phys.h"
NamedAreaRuleDefinition::NamedAreaRuleDefinition() NamedAreaRuleDefinition::NamedAreaRuleDefinition() {
{
m_name = L""; m_name = L"";
m_area = AABB::newPermanent(0,0,0,0,0,0); m_area = AABB::newPermanent(0, 0, 0, 0, 0, 0);
} }
NamedAreaRuleDefinition::~NamedAreaRuleDefinition() NamedAreaRuleDefinition::~NamedAreaRuleDefinition() { delete m_area; }
{
delete m_area;
}
void NamedAreaRuleDefinition::writeAttributes(DataOutputStream *dos, unsigned int numAttributes) void NamedAreaRuleDefinition::writeAttributes(DataOutputStream* dos,
{ unsigned int numAttributes) {
GameRuleDefinition::writeAttributes(dos, numAttributes + 7); GameRuleDefinition::writeAttributes(dos, numAttributes + 7);
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_name); ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_name);
@ -36,49 +32,41 @@ void NamedAreaRuleDefinition::writeAttributes(DataOutputStream *dos, unsigned in
dos->writeUTF(_toString(m_area->z1)); dos->writeUTF(_toString(m_area->z1));
} }
void NamedAreaRuleDefinition::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue) void NamedAreaRuleDefinition::addAttribute(const std::wstring& attributeName,
{ const std::wstring& attributeValue) {
if(attributeName.compare(L"name") == 0) if (attributeName.compare(L"name") == 0) {
{
m_name = attributeValue; m_name = attributeValue;
#ifndef _CONTENT_PACKAGE #ifndef _CONTENT_PACKAGE
wprintf(L"NamedAreaRuleDefinition: Adding parameter name=%ls\n",m_name.c_str()); wprintf(L"NamedAreaRuleDefinition: Adding parameter name=%ls\n",
m_name.c_str());
#endif #endif
} } else if (attributeName.compare(L"x0") == 0) {
else if(attributeName.compare(L"x0") == 0)
{
m_area->x0 = _fromString<int>(attributeValue); m_area->x0 = _fromString<int>(attributeValue);
app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter x0=%f\n",m_area->x0); app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter x0=%f\n",
} m_area->x0);
else if(attributeName.compare(L"y0") == 0) } else if (attributeName.compare(L"y0") == 0) {
{
m_area->y0 = _fromString<int>(attributeValue); m_area->y0 = _fromString<int>(attributeValue);
if(m_area->y0 < 0) m_area->y0 = 0; if (m_area->y0 < 0) m_area->y0 = 0;
app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter y0=%f\n",m_area->y0); app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter y0=%f\n",
} m_area->y0);
else if(attributeName.compare(L"z0") == 0) } else if (attributeName.compare(L"z0") == 0) {
{
m_area->z0 = _fromString<int>(attributeValue); m_area->z0 = _fromString<int>(attributeValue);
app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter z0=%f\n",m_area->z0); app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter z0=%f\n",
} m_area->z0);
else if(attributeName.compare(L"x1") == 0) } else if (attributeName.compare(L"x1") == 0) {
{
m_area->x1 = _fromString<int>(attributeValue); m_area->x1 = _fromString<int>(attributeValue);
app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter x1=%f\n",m_area->x1); app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter x1=%f\n",
} m_area->x1);
else if(attributeName.compare(L"y1") == 0) } else if (attributeName.compare(L"y1") == 0) {
{
m_area->y1 = _fromString<int>(attributeValue); m_area->y1 = _fromString<int>(attributeValue);
if(m_area->y1 < 0) m_area->y1 = 0; if (m_area->y1 < 0) m_area->y1 = 0;
app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter y1=%f\n",m_area->y1); app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter y1=%f\n",
} m_area->y1);
else if(attributeName.compare(L"z1") == 0) } else if (attributeName.compare(L"z1") == 0) {
{
m_area->z1 = _fromString<int>(attributeValue); m_area->z1 = _fromString<int>(attributeValue);
app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter z1=%f\n",m_area->z1); app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter z1=%f\n",
} m_area->z1);
else } else {
{
GameRuleDefinition::addAttribute(attributeName, attributeValue); GameRuleDefinition::addAttribute(attributeName, attributeValue);
} }
} }

View file

@ -2,22 +2,25 @@
#include "GameRuleDefinition.h" #include "GameRuleDefinition.h"
class NamedAreaRuleDefinition : public GameRuleDefinition class NamedAreaRuleDefinition : public GameRuleDefinition {
{
private: private:
std::wstring m_name; std::wstring m_name;
AABB *m_area; AABB* m_area;
public: public:
NamedAreaRuleDefinition(); NamedAreaRuleDefinition();
~NamedAreaRuleDefinition(); ~NamedAreaRuleDefinition();
virtual void writeAttributes(DataOutputStream *dos, unsigned int numAttributes); virtual void writeAttributes(DataOutputStream* dos,
unsigned int numAttributes);
virtual ConsoleGameRules::EGameRuleType getActionType() { return ConsoleGameRules::eGameRuleType_NamedArea; } virtual ConsoleGameRules::EGameRuleType getActionType() {
return ConsoleGameRules::eGameRuleType_NamedArea;
}
virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue); virtual void addAttribute(const std::wstring& attributeName,
const std::wstring& attributeValue);
AABB *getArea() { return m_area; } AABB* getArea() { return m_area; }
std::wstring getName() { return m_name; } std::wstring getName() { return m_name; }
}; };

View file

@ -2,15 +2,14 @@
#include "../../Minecraft.World/Util/StringHelpers.h" #include "../../Minecraft.World/Util/StringHelpers.h"
#include "StartFeature.h" #include "StartFeature.h"
StartFeature::StartFeature() StartFeature::StartFeature() {
{
m_chunkX = 0; m_chunkX = 0;
m_chunkZ = 0; m_chunkZ = 0;
m_feature = StructureFeature::eFeature_Temples; m_feature = StructureFeature::eFeature_Temples;
} }
void StartFeature::writeAttributes(DataOutputStream *dos, unsigned int numAttrs) void StartFeature::writeAttributes(DataOutputStream* dos,
{ unsigned int numAttrs) {
GameRuleDefinition::writeAttributes(dos, numAttrs + 3); GameRuleDefinition::writeAttributes(dos, numAttrs + 3);
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_chunkX); ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_chunkX);
@ -21,33 +20,27 @@ void StartFeature::writeAttributes(DataOutputStream *dos, unsigned int numAttrs)
dos->writeUTF(_toString((int)m_feature)); dos->writeUTF(_toString((int)m_feature));
} }
void StartFeature::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue) void StartFeature::addAttribute(const std::wstring& attributeName,
{ const std::wstring& attributeValue) {
if(attributeName.compare(L"chunkX") == 0) if (attributeName.compare(L"chunkX") == 0) {
{
int value = _fromString<int>(attributeValue); int value = _fromString<int>(attributeValue);
m_chunkX = value; m_chunkX = value;
app.DebugPrintf("StartFeature: Adding parameter chunkX=%d\n",m_chunkX); app.DebugPrintf("StartFeature: Adding parameter chunkX=%d\n", m_chunkX);
} } else if (attributeName.compare(L"chunkZ") == 0) {
else if(attributeName.compare(L"chunkZ") == 0)
{
int value = _fromString<int>(attributeValue); int value = _fromString<int>(attributeValue);
m_chunkZ = value; m_chunkZ = value;
app.DebugPrintf("StartFeature: Adding parameter chunkZ=%d\n",m_chunkZ); app.DebugPrintf("StartFeature: Adding parameter chunkZ=%d\n", m_chunkZ);
} } else if (attributeName.compare(L"feature") == 0) {
else if(attributeName.compare(L"feature") == 0)
{
int value = _fromString<int>(attributeValue); int value = _fromString<int>(attributeValue);
m_feature = (StructureFeature::EFeatureTypes)value; m_feature = (StructureFeature::EFeatureTypes)value;
app.DebugPrintf("StartFeature: Adding parameter feature=%d\n",m_feature); app.DebugPrintf("StartFeature: Adding parameter feature=%d\n",
} m_feature);
else } else {
{
GameRuleDefinition::addAttribute(attributeName, attributeValue); GameRuleDefinition::addAttribute(attributeName, attributeValue);
} }
} }
bool StartFeature::isFeatureChunk(int chunkX, int chunkZ, StructureFeature::EFeatureTypes feature) bool StartFeature::isFeatureChunk(int chunkX, int chunkZ,
{ StructureFeature::EFeatureTypes feature) {
return chunkX == m_chunkX && chunkZ == m_chunkZ && feature == m_feature; return chunkX == m_chunkX && chunkZ == m_chunkZ && feature == m_feature;
} }

View file

@ -1,11 +1,10 @@
#pragma once #pragma once
//using namespace std; // using namespace std;
#include "GameRuleDefinition.h" #include "GameRuleDefinition.h"
#include "../../Minecraft.World/WorldGen/Features/StructureFeature.h" #include "../../Minecraft.World/WorldGen/Features/StructureFeature.h"
class StartFeature : public GameRuleDefinition class StartFeature : public GameRuleDefinition {
{
private: private:
int m_chunkX, m_chunkZ; int m_chunkX, m_chunkZ;
StructureFeature::EFeatureTypes m_feature; StructureFeature::EFeatureTypes m_feature;
@ -13,10 +12,14 @@ private:
public: public:
StartFeature(); StartFeature();
virtual ConsoleGameRules::EGameRuleType getActionType() { return ConsoleGameRules::eGameRuleType_StartFeature; } virtual ConsoleGameRules::EGameRuleType getActionType() {
return ConsoleGameRules::eGameRuleType_StartFeature;
}
virtual void writeAttributes(DataOutputStream *dos, unsigned int numAttrs); virtual void writeAttributes(DataOutputStream* dos, unsigned int numAttrs);
virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue); virtual void addAttribute(const std::wstring& attributeName,
const std::wstring& attributeValue);
bool isFeatureChunk(int chunkX, int chunkZ, StructureFeature::EFeatureTypes feature); bool isFeatureChunk(int chunkX, int chunkZ,
StructureFeature::EFeatureTypes feature);
}; };

View file

@ -7,30 +7,28 @@
#include "../../Minecraft.World/Headers/net.minecraft.world.food.h" #include "../../Minecraft.World/Headers/net.minecraft.world.food.h"
#include "../../Minecraft.World/Headers/net.minecraft.world.item.h" #include "../../Minecraft.World/Headers/net.minecraft.world.item.h"
UpdatePlayerRuleDefinition::UpdatePlayerRuleDefinition() UpdatePlayerRuleDefinition::UpdatePlayerRuleDefinition() {
{ m_bUpdateHealth = m_bUpdateFood = m_bUpdateYRot = false;
m_bUpdateHealth = m_bUpdateFood = m_bUpdateYRot = false;; ;
m_health = 0; m_health = 0;
m_food = 0; m_food = 0;
m_spawnPos = NULL; m_spawnPos = NULL;
m_yRot = 0.0f; m_yRot = 0.0f;
} }
UpdatePlayerRuleDefinition::~UpdatePlayerRuleDefinition() UpdatePlayerRuleDefinition::~UpdatePlayerRuleDefinition() {
{ for (AUTO_VAR(it, m_items.begin()); it != m_items.end(); ++it) {
for(AUTO_VAR(it, m_items.begin()); it != m_items.end(); ++it)
{
delete *it; delete *it;
} }
} }
void UpdatePlayerRuleDefinition::writeAttributes(DataOutputStream *dos, unsigned int numAttributes) void UpdatePlayerRuleDefinition::writeAttributes(DataOutputStream* dos,
{ unsigned int numAttributes) {
int attrCount = 3; int attrCount = 3;
if(m_bUpdateHealth) ++attrCount; if (m_bUpdateHealth) ++attrCount;
if(m_bUpdateFood) ++attrCount; if (m_bUpdateFood) ++attrCount;
if(m_bUpdateYRot) ++attrCount; if (m_bUpdateYRot) ++attrCount;
GameRuleDefinition::writeAttributes(dos, numAttributes + attrCount ); GameRuleDefinition::writeAttributes(dos, numAttributes + attrCount);
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_spawnX); ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_spawnX);
dos->writeUTF(_toString(m_spawnPos->x)); dos->writeUTF(_toString(m_spawnPos->x));
@ -39,107 +37,95 @@ void UpdatePlayerRuleDefinition::writeAttributes(DataOutputStream *dos, unsigned
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_spawnZ); ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_spawnZ);
dos->writeUTF(_toString(m_spawnPos->z)); dos->writeUTF(_toString(m_spawnPos->z));
if(m_bUpdateYRot) if (m_bUpdateYRot) {
{
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_yRot); ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_yRot);
dos->writeUTF(_toString(m_yRot)); dos->writeUTF(_toString(m_yRot));
} }
if(m_bUpdateHealth) if (m_bUpdateHealth) {
{
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_food); ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_food);
dos->writeUTF(_toString(m_health)); dos->writeUTF(_toString(m_health));
} }
if(m_bUpdateFood) if (m_bUpdateFood) {
{
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_health); ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_health);
dos->writeUTF(_toString(m_food)); dos->writeUTF(_toString(m_food));
} }
} }
void UpdatePlayerRuleDefinition::getChildren(std::vector<GameRuleDefinition *> *children) void UpdatePlayerRuleDefinition::getChildren(
{ std::vector<GameRuleDefinition*>* children) {
GameRuleDefinition::getChildren(children); GameRuleDefinition::getChildren(children);
for(AUTO_VAR(it, m_items.begin()); it!=m_items.end(); it++) for (AUTO_VAR(it, m_items.begin()); it != m_items.end(); it++)
children->push_back(*it); children->push_back(*it);
} }
GameRuleDefinition *UpdatePlayerRuleDefinition::addChild(ConsoleGameRules::EGameRuleType ruleType) GameRuleDefinition* UpdatePlayerRuleDefinition::addChild(
{ ConsoleGameRules::EGameRuleType ruleType) {
GameRuleDefinition *rule = NULL; GameRuleDefinition* rule = NULL;
if(ruleType == ConsoleGameRules::eGameRuleType_AddItem) if (ruleType == ConsoleGameRules::eGameRuleType_AddItem) {
{
rule = new AddItemRuleDefinition(); rule = new AddItemRuleDefinition();
m_items.push_back((AddItemRuleDefinition *)rule); m_items.push_back((AddItemRuleDefinition*)rule);
} } else {
else
{
#ifndef _CONTENT_PACKAGE #ifndef _CONTENT_PACKAGE
wprintf(L"UpdatePlayerRuleDefinition: Attempted to add invalid child rule - %d\n", ruleType ); wprintf(
L"UpdatePlayerRuleDefinition: Attempted to add invalid child rule "
L"- %d\n",
ruleType);
#endif #endif
} }
return rule; return rule;
} }
void UpdatePlayerRuleDefinition::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue) void UpdatePlayerRuleDefinition::addAttribute(
{ const std::wstring& attributeName, const std::wstring& attributeValue) {
if(attributeName.compare(L"spawnX") == 0) if (attributeName.compare(L"spawnX") == 0) {
{ if (m_spawnPos == NULL) m_spawnPos = new Pos();
if(m_spawnPos == NULL) m_spawnPos = new Pos();
int value = _fromString<int>(attributeValue); int value = _fromString<int>(attributeValue);
m_spawnPos->x = value; m_spawnPos->x = value;
app.DebugPrintf("UpdatePlayerRuleDefinition: Adding parameter spawnX=%d\n",value); app.DebugPrintf(
} "UpdatePlayerRuleDefinition: Adding parameter spawnX=%d\n", value);
else if(attributeName.compare(L"spawnY") == 0) } else if (attributeName.compare(L"spawnY") == 0) {
{ if (m_spawnPos == NULL) m_spawnPos = new Pos();
if(m_spawnPos == NULL) m_spawnPos = new Pos();
int value = _fromString<int>(attributeValue); int value = _fromString<int>(attributeValue);
m_spawnPos->y = value; m_spawnPos->y = value;
app.DebugPrintf("UpdatePlayerRuleDefinition: Adding parameter spawnY=%d\n",value); app.DebugPrintf(
} "UpdatePlayerRuleDefinition: Adding parameter spawnY=%d\n", value);
else if(attributeName.compare(L"spawnZ") == 0) } else if (attributeName.compare(L"spawnZ") == 0) {
{ if (m_spawnPos == NULL) m_spawnPos = new Pos();
if(m_spawnPos == NULL) m_spawnPos = new Pos();
int value = _fromString<int>(attributeValue); int value = _fromString<int>(attributeValue);
m_spawnPos->z = value; m_spawnPos->z = value;
app.DebugPrintf("UpdatePlayerRuleDefinition: Adding parameter spawnZ=%d\n",value); app.DebugPrintf(
} "UpdatePlayerRuleDefinition: Adding parameter spawnZ=%d\n", value);
else if(attributeName.compare(L"health") == 0) } else if (attributeName.compare(L"health") == 0) {
{
int value = _fromString<int>(attributeValue); int value = _fromString<int>(attributeValue);
m_health = value; m_health = value;
m_bUpdateHealth = true; m_bUpdateHealth = true;
app.DebugPrintf("UpdatePlayerRuleDefinition: Adding parameter health=%d\n",value); app.DebugPrintf(
} "UpdatePlayerRuleDefinition: Adding parameter health=%d\n", value);
else if(attributeName.compare(L"food") == 0) } else if (attributeName.compare(L"food") == 0) {
{
int value = _fromString<int>(attributeValue); int value = _fromString<int>(attributeValue);
m_food = value; m_food = value;
m_bUpdateFood = true; m_bUpdateFood = true;
app.DebugPrintf("UpdatePlayerRuleDefinition: Adding parameter health=%d\n",value); app.DebugPrintf(
} "UpdatePlayerRuleDefinition: Adding parameter health=%d\n", value);
else if(attributeName.compare(L"yRot") == 0) } else if (attributeName.compare(L"yRot") == 0) {
{
float value = _fromString<float>(attributeValue); float value = _fromString<float>(attributeValue);
m_yRot = value; m_yRot = value;
m_bUpdateYRot = true; m_bUpdateYRot = true;
app.DebugPrintf("UpdatePlayerRuleDefinition: Adding parameter yRot=%f\n",value); app.DebugPrintf(
} "UpdatePlayerRuleDefinition: Adding parameter yRot=%f\n", value);
else } else {
{
GameRuleDefinition::addAttribute(attributeName, attributeValue); GameRuleDefinition::addAttribute(attributeName, attributeValue);
} }
} }
void UpdatePlayerRuleDefinition::postProcessPlayer(std::shared_ptr<Player> player) void UpdatePlayerRuleDefinition::postProcessPlayer(
{ std::shared_ptr<Player> player) {
if(m_bUpdateHealth) if (m_bUpdateHealth) {
{
player->lastHealth = m_health; player->lastHealth = m_health;
player->setHealth(m_health); player->setHealth(m_health);
} }
if(m_bUpdateFood) if (m_bUpdateFood) {
{
player->getFoodData()->setFoodLevel(m_food); player->getFoodData()->setFoodLevel(m_food);
} }
@ -148,23 +134,21 @@ void UpdatePlayerRuleDefinition::postProcessPlayer(std::shared_ptr<Player> playe
double z = player->z; double z = player->z;
float yRot = player->yRot; float yRot = player->yRot;
float xRot = player->xRot; float xRot = player->xRot;
if(m_spawnPos != NULL) if (m_spawnPos != NULL) {
{
x = m_spawnPos->x; x = m_spawnPos->x;
y = m_spawnPos->y; y = m_spawnPos->y;
z = m_spawnPos->z; z = m_spawnPos->z;
} }
if(m_bUpdateYRot) if (m_bUpdateYRot) {
{
yRot = m_yRot; yRot = m_yRot;
} }
if(m_spawnPos != NULL || m_bUpdateYRot) player->absMoveTo(x,y,z,yRot,xRot); if (m_spawnPos != NULL || m_bUpdateYRot)
player->absMoveTo(x, y, z, yRot, xRot);
for(AUTO_VAR(it, m_items.begin()); it != m_items.end(); ++it) for (AUTO_VAR(it, m_items.begin()); it != m_items.end(); ++it) {
{ AddItemRuleDefinition* addItem = *it;
AddItemRuleDefinition *addItem = *it;
addItem->addItemToContainer(player->inventory, -1); addItem->addItemToContainer(player->inventory, -1);
} }

View file

@ -1,33 +1,37 @@
#pragma once #pragma once
//using namespace std; // using namespace std;
#include "GameRuleDefinition.h" #include "GameRuleDefinition.h"
class AddItemRuleDefinition; class AddItemRuleDefinition;
class Pos; class Pos;
class UpdatePlayerRuleDefinition : public GameRuleDefinition class UpdatePlayerRuleDefinition : public GameRuleDefinition {
{
private: private:
std::vector<AddItemRuleDefinition *> m_items; std::vector<AddItemRuleDefinition*> m_items;
bool m_bUpdateHealth, m_bUpdateFood, m_bUpdateYRot, m_bUpdateInventory; bool m_bUpdateHealth, m_bUpdateFood, m_bUpdateYRot, m_bUpdateInventory;
int m_health; int m_health;
int m_food; int m_food;
Pos *m_spawnPos; Pos* m_spawnPos;
float m_yRot; float m_yRot;
public: public:
UpdatePlayerRuleDefinition(); UpdatePlayerRuleDefinition();
~UpdatePlayerRuleDefinition(); ~UpdatePlayerRuleDefinition();
virtual ConsoleGameRules::EGameRuleType getActionType() { return ConsoleGameRules::eGameRuleType_UpdatePlayerRule; } virtual ConsoleGameRules::EGameRuleType getActionType() {
return ConsoleGameRules::eGameRuleType_UpdatePlayerRule;
}
virtual void getChildren(std::vector<GameRuleDefinition *> *children); virtual void getChildren(std::vector<GameRuleDefinition*>* children);
virtual GameRuleDefinition *addChild(ConsoleGameRules::EGameRuleType ruleType); virtual GameRuleDefinition* addChild(
ConsoleGameRules::EGameRuleType ruleType);
virtual void writeAttributes(DataOutputStream *dos, unsigned int numAttributes); virtual void writeAttributes(DataOutputStream* dos,
virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue); unsigned int numAttributes);
virtual void addAttribute(const std::wstring& attributeName,
const std::wstring& attributeValue);
virtual void postProcessPlayer(std::shared_ptr<Player> player); virtual void postProcessPlayer(std::shared_ptr<Player> player);
}; };

View file

@ -2,14 +2,13 @@
#include "../../Minecraft.World/Util/StringHelpers.h" #include "../../Minecraft.World/Util/StringHelpers.h"
#include "UseTileRuleDefinition.h" #include "UseTileRuleDefinition.h"
UseTileRuleDefinition::UseTileRuleDefinition() UseTileRuleDefinition::UseTileRuleDefinition() {
{
m_tileId = -1; m_tileId = -1;
m_useCoords = false; m_useCoords = false;
} }
void UseTileRuleDefinition::writeAttributes(DataOutputStream *dos, unsigned int numAttributes) void UseTileRuleDefinition::writeAttributes(DataOutputStream* dos,
{ unsigned int numAttributes) {
GameRuleDefinition::writeAttributes(dos, numAttributes + 5); GameRuleDefinition::writeAttributes(dos, numAttributes + 5);
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_tileId); ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_tileId);
@ -28,51 +27,46 @@ void UseTileRuleDefinition::writeAttributes(DataOutputStream *dos, unsigned int
dos->writeUTF(_toString(m_coordinates.z)); dos->writeUTF(_toString(m_coordinates.z));
} }
void UseTileRuleDefinition::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue) void UseTileRuleDefinition::addAttribute(const std::wstring& attributeName,
{ const std::wstring& attributeValue) {
if(attributeName.compare(L"tileId") == 0) if (attributeName.compare(L"tileId") == 0) {
{
m_tileId = _fromString<int>(attributeValue); m_tileId = _fromString<int>(attributeValue);
app.DebugPrintf("UseTileRule: Adding parameter tileId=%d\n",m_tileId); app.DebugPrintf("UseTileRule: Adding parameter tileId=%d\n", m_tileId);
} } else if (attributeName.compare(L"useCoords") == 0) {
else if(attributeName.compare(L"useCoords") == 0)
{
m_useCoords = _fromString<bool>(attributeValue); m_useCoords = _fromString<bool>(attributeValue);
app.DebugPrintf("UseTileRule: Adding parameter useCoords=%s\n",m_useCoords?"TRUE":"FALSE"); app.DebugPrintf("UseTileRule: Adding parameter useCoords=%s\n",
} m_useCoords ? "TRUE" : "FALSE");
else if(attributeName.compare(L"x") == 0) } else if (attributeName.compare(L"x") == 0) {
{
m_coordinates.x = _fromString<int>(attributeValue); m_coordinates.x = _fromString<int>(attributeValue);
app.DebugPrintf("UseTileRule: Adding parameter x=%d\n",m_coordinates.x); app.DebugPrintf("UseTileRule: Adding parameter x=%d\n",
} m_coordinates.x);
else if(attributeName.compare(L"y") == 0) } else if (attributeName.compare(L"y") == 0) {
{
m_coordinates.y = _fromString<int>(attributeValue); m_coordinates.y = _fromString<int>(attributeValue);
app.DebugPrintf("UseTileRule: Adding parameter y=%d\n",m_coordinates.y); app.DebugPrintf("UseTileRule: Adding parameter y=%d\n",
} m_coordinates.y);
else if(attributeName.compare(L"z") == 0) } else if (attributeName.compare(L"z") == 0) {
{
m_coordinates.z = _fromString<int>(attributeValue); m_coordinates.z = _fromString<int>(attributeValue);
app.DebugPrintf("UseTileRule: Adding parameter z=%d\n",m_coordinates.z); app.DebugPrintf("UseTileRule: Adding parameter z=%d\n",
} m_coordinates.z);
else } else {
{
GameRuleDefinition::addAttribute(attributeName, attributeValue); GameRuleDefinition::addAttribute(attributeName, attributeValue);
} }
} }
bool UseTileRuleDefinition::onUseTile(GameRule *rule, int tileId, int x, int y, int z) bool UseTileRuleDefinition::onUseTile(GameRule* rule, int tileId, int x, int y,
{ int z) {
bool statusChanged = false; bool statusChanged = false;
if( m_tileId == tileId ) if (m_tileId == tileId) {
{ if (!m_useCoords || (m_coordinates.x == x && m_coordinates.y == y &&
if( !m_useCoords || (m_coordinates.x == x && m_coordinates.y == y && m_coordinates.z == z) ) m_coordinates.z == z)) {
{ if (!getComplete(rule)) {
if(!getComplete(rule))
{
statusChanged = true; statusChanged = true;
setComplete(rule,true); setComplete(rule, true);
app.DebugPrintf("Completed UseTileRule with info - t:%d, coords:%s, x:%d, y:%d, z:%d\n", m_tileId,m_useCoords?"TRUE":"FALSE",m_coordinates.x,m_coordinates.y,m_coordinates.z); app.DebugPrintf(
"Completed UseTileRule with info - t:%d, coords:%s, x:%d, "
"y:%d, z:%d\n",
m_tileId, m_useCoords ? "TRUE" : "FALSE", m_coordinates.x,
m_coordinates.y, m_coordinates.z);
// Send a packet or some other announcement here // Send a packet or some other announcement here
} }

View file

@ -1,11 +1,10 @@
#pragma once #pragma once
//using namespace std; // using namespace std;
#include "GameRuleDefinition.h" #include "GameRuleDefinition.h"
#include "../../Minecraft.World/Util/Pos.h" #include "../../Minecraft.World/Util/Pos.h"
class UseTileRuleDefinition : public GameRuleDefinition class UseTileRuleDefinition : public GameRuleDefinition {
{
private: private:
// These values should map directly to the xsd definition for this Rule // These values should map directly to the xsd definition for this Rule
int m_tileId; int m_tileId;
@ -15,10 +14,14 @@ private:
public: public:
UseTileRuleDefinition(); UseTileRuleDefinition();
ConsoleGameRules::EGameRuleType getActionType() { return ConsoleGameRules::eGameRuleType_UseTileRule; } ConsoleGameRules::EGameRuleType getActionType() {
return ConsoleGameRules::eGameRuleType_UseTileRule;
}
virtual void writeAttributes(DataOutputStream *dos, unsigned int numAttributes); virtual void writeAttributes(DataOutputStream* dos,
virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue); unsigned int numAttributes);
virtual void addAttribute(const std::wstring& attributeName,
const std::wstring& attributeValue);
virtual bool onUseTile(GameRule *rule, int tileId, int x, int y, int z); virtual bool onUseTile(GameRule* rule, int tileId, int x, int y, int z);
}; };

View file

@ -3,14 +3,13 @@
#include "../../Minecraft.World/Util/StringHelpers.h" #include "../../Minecraft.World/Util/StringHelpers.h"
#include "../../Minecraft.World/Headers/net.minecraft.world.level.levelgen.structure.h" #include "../../Minecraft.World/Headers/net.minecraft.world.level.levelgen.structure.h"
XboxStructureActionGenerateBox::XboxStructureActionGenerateBox() XboxStructureActionGenerateBox::XboxStructureActionGenerateBox() {
{
m_x0 = m_y0 = m_z0 = m_x1 = m_y1 = m_z1 = m_edgeTile = m_fillTile = 0; m_x0 = m_y0 = m_z0 = m_x1 = m_y1 = m_z1 = m_edgeTile = m_fillTile = 0;
m_skipAir = false; m_skipAir = false;
} }
void XboxStructureActionGenerateBox::writeAttributes(DataOutputStream *dos, unsigned int numAttrs) void XboxStructureActionGenerateBox::writeAttributes(DataOutputStream* dos,
{ unsigned int numAttrs) {
ConsoleGenerateStructureAction::writeAttributes(dos, numAttrs + 9); ConsoleGenerateStructureAction::writeAttributes(dos, numAttrs + 9);
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x0); ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x0);
@ -35,70 +34,64 @@ void XboxStructureActionGenerateBox::writeAttributes(DataOutputStream *dos, unsi
dos->writeUTF(_toString(m_skipAir)); dos->writeUTF(_toString(m_skipAir));
} }
void XboxStructureActionGenerateBox::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue) void XboxStructureActionGenerateBox::addAttribute(
{ const std::wstring& attributeName, const std::wstring& attributeValue) {
if(attributeName.compare(L"x0") == 0) if (attributeName.compare(L"x0") == 0) {
{
int value = _fromString<int>(attributeValue); int value = _fromString<int>(attributeValue);
m_x0 = value; m_x0 = value;
app.DebugPrintf("XboxStructureActionGenerateBox: Adding parameter x0=%d\n",m_x0); app.DebugPrintf(
} "XboxStructureActionGenerateBox: Adding parameter x0=%d\n", m_x0);
else if(attributeName.compare(L"y0") == 0) } else if (attributeName.compare(L"y0") == 0) {
{
int value = _fromString<int>(attributeValue); int value = _fromString<int>(attributeValue);
m_y0 = value; m_y0 = value;
app.DebugPrintf("XboxStructureActionGenerateBox: Adding parameter y0=%d\n",m_y0); app.DebugPrintf(
} "XboxStructureActionGenerateBox: Adding parameter y0=%d\n", m_y0);
else if(attributeName.compare(L"z0") == 0) } else if (attributeName.compare(L"z0") == 0) {
{
int value = _fromString<int>(attributeValue); int value = _fromString<int>(attributeValue);
m_z0 = value; m_z0 = value;
app.DebugPrintf("XboxStructureActionGenerateBox: Adding parameter z0=%d\n",m_z0); app.DebugPrintf(
} "XboxStructureActionGenerateBox: Adding parameter z0=%d\n", m_z0);
else if(attributeName.compare(L"x1") == 0) } else if (attributeName.compare(L"x1") == 0) {
{
int value = _fromString<int>(attributeValue); int value = _fromString<int>(attributeValue);
m_x1 = value; m_x1 = value;
app.DebugPrintf("XboxStructureActionGenerateBox: Adding parameter x1=%d\n",m_x1); app.DebugPrintf(
} "XboxStructureActionGenerateBox: Adding parameter x1=%d\n", m_x1);
else if(attributeName.compare(L"y1") == 0) } else if (attributeName.compare(L"y1") == 0) {
{
int value = _fromString<int>(attributeValue); int value = _fromString<int>(attributeValue);
m_y1 = value; m_y1 = value;
app.DebugPrintf("XboxStructureActionGenerateBox: Adding parameter y1=%d\n",m_y1); app.DebugPrintf(
} "XboxStructureActionGenerateBox: Adding parameter y1=%d\n", m_y1);
else if(attributeName.compare(L"z1") == 0) } else if (attributeName.compare(L"z1") == 0) {
{
int value = _fromString<int>(attributeValue); int value = _fromString<int>(attributeValue);
m_z1 = value; m_z1 = value;
app.DebugPrintf("XboxStructureActionGenerateBox: Adding parameter z1=%d\n",m_z1); app.DebugPrintf(
} "XboxStructureActionGenerateBox: Adding parameter z1=%d\n", m_z1);
else if(attributeName.compare(L"edgeTile") == 0) } else if (attributeName.compare(L"edgeTile") == 0) {
{
int value = _fromString<int>(attributeValue); int value = _fromString<int>(attributeValue);
m_edgeTile = value; m_edgeTile = value;
app.DebugPrintf("XboxStructureActionGenerateBox: Adding parameter edgeTile=%d\n",m_edgeTile); app.DebugPrintf(
} "XboxStructureActionGenerateBox: Adding parameter edgeTile=%d\n",
else if(attributeName.compare(L"fillTile") == 0) m_edgeTile);
{ } else if (attributeName.compare(L"fillTile") == 0) {
int value = _fromString<int>(attributeValue); int value = _fromString<int>(attributeValue);
m_fillTile = value; m_fillTile = value;
app.DebugPrintf("XboxStructureActionGenerateBox: Adding parameter fillTile=%d\n",m_fillTile); app.DebugPrintf(
} "XboxStructureActionGenerateBox: Adding parameter fillTile=%d\n",
else if(attributeName.compare(L"skipAir") == 0) m_fillTile);
{ } else if (attributeName.compare(L"skipAir") == 0) {
if(attributeValue.compare(L"true") == 0) m_skipAir = true; if (attributeValue.compare(L"true") == 0) m_skipAir = true;
app.DebugPrintf("XboxStructureActionGenerateBox: Adding parameter skipAir=%s\n",m_skipAir?"TRUE":"FALSE"); app.DebugPrintf(
} "XboxStructureActionGenerateBox: Adding parameter skipAir=%s\n",
else m_skipAir ? "TRUE" : "FALSE");
{ } else {
GameRuleDefinition::addAttribute(attributeName, attributeValue); GameRuleDefinition::addAttribute(attributeName, attributeValue);
} }
} }
bool XboxStructureActionGenerateBox::generateBoxInLevel(StructurePiece *structure, Level *level, BoundingBox *chunkBB) bool XboxStructureActionGenerateBox::generateBoxInLevel(
{ StructurePiece* structure, Level* level, BoundingBox* chunkBB) {
app.DebugPrintf("XboxStructureActionGenerateBox - generating a box\n"); app.DebugPrintf("XboxStructureActionGenerateBox - generating a box\n");
structure->generateBox(level,chunkBB,m_x0,m_y0,m_z0,m_x1,m_y1,m_z1,m_edgeTile,m_fillTile,m_skipAir); structure->generateBox(level, chunkBB, m_x0, m_y0, m_z0, m_x1, m_y1, m_z1,
m_edgeTile, m_fillTile, m_skipAir);
return true; return true;
} }

View file

@ -5,22 +5,26 @@ class StructurePiece;
class Level; class Level;
class BoundingBox; class BoundingBox;
class XboxStructureActionGenerateBox : public ConsoleGenerateStructureAction class XboxStructureActionGenerateBox : public ConsoleGenerateStructureAction {
{
private: private:
int m_x0, m_y0, m_z0, m_x1, m_y1, m_z1, m_edgeTile, m_fillTile; int m_x0, m_y0, m_z0, m_x1, m_y1, m_z1, m_edgeTile, m_fillTile;
bool m_skipAir; bool m_skipAir;
public: public:
XboxStructureActionGenerateBox(); XboxStructureActionGenerateBox();
virtual ConsoleGameRules::EGameRuleType getActionType() { return ConsoleGameRules::eGameRuleType_GenerateBox; } virtual ConsoleGameRules::EGameRuleType getActionType() {
return ConsoleGameRules::eGameRuleType_GenerateBox;
}
virtual int getEndX() { return m_x1; } virtual int getEndX() { return m_x1; }
virtual int getEndY() { return m_y1; } virtual int getEndY() { return m_y1; }
virtual int getEndZ() { return m_z1; } virtual int getEndZ() { return m_z1; }
virtual void writeAttributes(DataOutputStream *dos, unsigned int numAttrs); virtual void writeAttributes(DataOutputStream* dos, unsigned int numAttrs);
virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue); virtual void addAttribute(const std::wstring& attributeName,
const std::wstring& attributeValue);
bool generateBoxInLevel(StructurePiece *structure, Level *level, BoundingBox *chunkBB); bool generateBoxInLevel(StructurePiece* structure, Level* level,
BoundingBox* chunkBB);
}; };

View file

@ -3,13 +3,12 @@
#include "../../Minecraft.World/Util/StringHelpers.h" #include "../../Minecraft.World/Util/StringHelpers.h"
#include "../../Minecraft.World/Headers/net.minecraft.world.level.levelgen.structure.h" #include "../../Minecraft.World/Headers/net.minecraft.world.level.levelgen.structure.h"
XboxStructureActionPlaceBlock::XboxStructureActionPlaceBlock() XboxStructureActionPlaceBlock::XboxStructureActionPlaceBlock() {
{
m_x = m_y = m_z = m_tile = m_data = 0; m_x = m_y = m_z = m_tile = m_data = 0;
} }
void XboxStructureActionPlaceBlock::writeAttributes(DataOutputStream *dos, unsigned int numAttrs) void XboxStructureActionPlaceBlock::writeAttributes(DataOutputStream* dos,
{ unsigned int numAttrs) {
ConsoleGenerateStructureAction::writeAttributes(dos, numAttrs + 5); ConsoleGenerateStructureAction::writeAttributes(dos, numAttrs + 5);
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x); ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x);
@ -25,48 +24,44 @@ void XboxStructureActionPlaceBlock::writeAttributes(DataOutputStream *dos, unsig
dos->writeUTF(_toString(m_tile)); dos->writeUTF(_toString(m_tile));
} }
void XboxStructureActionPlaceBlock::addAttribute(
void XboxStructureActionPlaceBlock::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue) const std::wstring& attributeName, const std::wstring& attributeValue) {
{ if (attributeName.compare(L"x") == 0) {
if(attributeName.compare(L"x") == 0)
{
int value = _fromString<int>(attributeValue); int value = _fromString<int>(attributeValue);
m_x = value; m_x = value;
app.DebugPrintf("XboxStructureActionPlaceBlock: Adding parameter x=%d\n",m_x); app.DebugPrintf(
} "XboxStructureActionPlaceBlock: Adding parameter x=%d\n", m_x);
else if(attributeName.compare(L"y") == 0) } else if (attributeName.compare(L"y") == 0) {
{
int value = _fromString<int>(attributeValue); int value = _fromString<int>(attributeValue);
m_y = value; m_y = value;
app.DebugPrintf("XboxStructureActionPlaceBlock: Adding parameter y=%d\n",m_y); app.DebugPrintf(
} "XboxStructureActionPlaceBlock: Adding parameter y=%d\n", m_y);
else if(attributeName.compare(L"z") == 0) } else if (attributeName.compare(L"z") == 0) {
{
int value = _fromString<int>(attributeValue); int value = _fromString<int>(attributeValue);
m_z = value; m_z = value;
app.DebugPrintf("XboxStructureActionPlaceBlock: Adding parameter z=%d\n",m_z); app.DebugPrintf(
} "XboxStructureActionPlaceBlock: Adding parameter z=%d\n", m_z);
else if(attributeName.compare(L"block") == 0) } else if (attributeName.compare(L"block") == 0) {
{
int value = _fromString<int>(attributeValue); int value = _fromString<int>(attributeValue);
m_tile = value; m_tile = value;
app.DebugPrintf("XboxStructureActionPlaceBlock: Adding parameter block=%d\n",m_tile); app.DebugPrintf(
} "XboxStructureActionPlaceBlock: Adding parameter block=%d\n",
else if(attributeName.compare(L"data") == 0) m_tile);
{ } else if (attributeName.compare(L"data") == 0) {
int value = _fromString<int>(attributeValue); int value = _fromString<int>(attributeValue);
m_data = value; m_data = value;
app.DebugPrintf("XboxStructureActionPlaceBlock: Adding parameter data=%d\n",m_data); app.DebugPrintf(
} "XboxStructureActionPlaceBlock: Adding parameter data=%d\n",
else m_data);
{ } else {
GameRuleDefinition::addAttribute(attributeName, attributeValue); GameRuleDefinition::addAttribute(attributeName, attributeValue);
} }
} }
bool XboxStructureActionPlaceBlock::placeBlockInLevel(StructurePiece *structure, Level *level, BoundingBox *chunkBB) bool XboxStructureActionPlaceBlock::placeBlockInLevel(StructurePiece* structure,
{ Level* level,
BoundingBox* chunkBB) {
app.DebugPrintf("XboxStructureActionPlaceBlock - placing a block\n"); app.DebugPrintf("XboxStructureActionPlaceBlock - placing a block\n");
structure->placeBlock(level,m_tile,m_data,m_x,m_y,m_z,chunkBB); structure->placeBlock(level, m_tile, m_data, m_x, m_y, m_z, chunkBB);
return true; return true;
} }

View file

@ -5,21 +5,25 @@ class StructurePiece;
class Level; class Level;
class BoundingBox; class BoundingBox;
class XboxStructureActionPlaceBlock : public ConsoleGenerateStructureAction class XboxStructureActionPlaceBlock : public ConsoleGenerateStructureAction {
{
protected: protected:
int m_x, m_y, m_z, m_tile, m_data; int m_x, m_y, m_z, m_tile, m_data;
public: public:
XboxStructureActionPlaceBlock(); XboxStructureActionPlaceBlock();
virtual ConsoleGameRules::EGameRuleType getActionType() { return ConsoleGameRules::eGameRuleType_PlaceBlock; } virtual ConsoleGameRules::EGameRuleType getActionType() {
return ConsoleGameRules::eGameRuleType_PlaceBlock;
}
virtual int getEndX() { return m_x; } virtual int getEndX() { return m_x; }
virtual int getEndY() { return m_y; } virtual int getEndY() { return m_y; }
virtual int getEndZ() { return m_z; } virtual int getEndZ() { return m_z; }
virtual void writeAttributes(DataOutputStream *dos, unsigned int numAttrs); virtual void writeAttributes(DataOutputStream* dos, unsigned int numAttrs);
virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue); virtual void addAttribute(const std::wstring& attributeName,
const std::wstring& attributeValue);
bool placeBlockInLevel(StructurePiece *structure, Level *level, BoundingBox *chunkBB); bool placeBlockInLevel(StructurePiece* structure, Level* level,
BoundingBox* chunkBB);
}; };

View file

@ -7,90 +7,91 @@
#include "../../Minecraft.World/Headers/net.minecraft.world.level.tile.h" #include "../../Minecraft.World/Headers/net.minecraft.world.level.tile.h"
#include "../../Minecraft.World/Headers/net.minecraft.world.inventory.h" #include "../../Minecraft.World/Headers/net.minecraft.world.inventory.h"
XboxStructureActionPlaceContainer::XboxStructureActionPlaceContainer() XboxStructureActionPlaceContainer::XboxStructureActionPlaceContainer() {
{
m_tile = Tile::chest_Id; m_tile = Tile::chest_Id;
} }
XboxStructureActionPlaceContainer::~XboxStructureActionPlaceContainer() XboxStructureActionPlaceContainer::~XboxStructureActionPlaceContainer() {
{ for (AUTO_VAR(it, m_items.begin()); it != m_items.end(); ++it) {
for(AUTO_VAR(it, m_items.begin()); it != m_items.end(); ++it)
{
delete *it; delete *it;
} }
} }
// 4J-JEV: Super class handles attr-facing fine. // 4J-JEV: Super class handles attr-facing fine.
//void XboxStructureActionPlaceContainer::writeAttributes(DataOutputStream *dos, unsigned int numAttrs) // void XboxStructureActionPlaceContainer::writeAttributes(DataOutputStream
// *dos, unsigned int numAttrs)
void XboxStructureActionPlaceContainer::getChildren(
void XboxStructureActionPlaceContainer::getChildren(std::vector<GameRuleDefinition *> *children) std::vector<GameRuleDefinition*>* children) {
{
XboxStructureActionPlaceBlock::getChildren(children); XboxStructureActionPlaceBlock::getChildren(children);
for(AUTO_VAR(it, m_items.begin()); it!=m_items.end(); it++) for (AUTO_VAR(it, m_items.begin()); it != m_items.end(); it++)
children->push_back( *it ); children->push_back(*it);
} }
GameRuleDefinition *XboxStructureActionPlaceContainer::addChild(ConsoleGameRules::EGameRuleType ruleType) GameRuleDefinition* XboxStructureActionPlaceContainer::addChild(
{ ConsoleGameRules::EGameRuleType ruleType) {
GameRuleDefinition *rule = NULL; GameRuleDefinition* rule = NULL;
if(ruleType == ConsoleGameRules::eGameRuleType_AddItem) if (ruleType == ConsoleGameRules::eGameRuleType_AddItem) {
{
rule = new AddItemRuleDefinition(); rule = new AddItemRuleDefinition();
m_items.push_back((AddItemRuleDefinition *)rule); m_items.push_back((AddItemRuleDefinition*)rule);
} } else {
else
{
#ifndef _CONTENT_PACKAGE #ifndef _CONTENT_PACKAGE
wprintf(L"XboxStructureActionPlaceContainer: Attempted to add invalid child rule - %d\n", ruleType ); wprintf(
L"XboxStructureActionPlaceContainer: Attempted to add invalid "
L"child rule - %d\n",
ruleType);
#endif #endif
} }
return rule; return rule;
} }
void XboxStructureActionPlaceContainer::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue) void XboxStructureActionPlaceContainer::addAttribute(
{ const std::wstring& attributeName, const std::wstring& attributeValue) {
if(attributeName.compare(L"facing") == 0) if (attributeName.compare(L"facing") == 0) {
{
int value = _fromString<int>(attributeValue); int value = _fromString<int>(attributeValue);
m_data = value; m_data = value;
app.DebugPrintf("XboxStructureActionPlaceContainer: Adding parameter facing=%d\n",m_data); app.DebugPrintf(
} "XboxStructureActionPlaceContainer: Adding parameter facing=%d\n",
else m_data);
{ } else {
XboxStructureActionPlaceBlock::addAttribute(attributeName, attributeValue); XboxStructureActionPlaceBlock::addAttribute(attributeName,
attributeValue);
} }
} }
bool XboxStructureActionPlaceContainer::placeContainerInLevel(StructurePiece *structure, Level *level, BoundingBox *chunkBB) bool XboxStructureActionPlaceContainer::placeContainerInLevel(
{ StructurePiece* structure, Level* level, BoundingBox* chunkBB) {
int worldX = structure->getWorldX( m_x, m_z ); int worldX = structure->getWorldX(m_x, m_z);
int worldY = structure->getWorldY( m_y ); int worldY = structure->getWorldY(m_y);
int worldZ = structure->getWorldZ( m_x, m_z ); int worldZ = structure->getWorldZ(m_x, m_z);
if ( chunkBB->isInside( worldX, worldY, worldZ ) ) if (chunkBB->isInside(worldX, worldY, worldZ)) {
{ if (level->getTileEntity(worldX, worldY, worldZ) != NULL) {
if ( level->getTileEntity( worldX, worldY, worldZ ) != NULL )
{
// Remove the current tile entity // Remove the current tile entity
level->removeTileEntity( worldX, worldY, worldZ ); level->removeTileEntity(worldX, worldY, worldZ);
level->setTile( worldX, worldY, worldZ, 0 ); level->setTile(worldX, worldY, worldZ, 0);
} }
level->setTile( worldX, worldY, worldZ, m_tile ); level->setTile(worldX, worldY, worldZ, m_tile);
std::shared_ptr<Container> container = std::dynamic_pointer_cast<Container>(level->getTileEntity( worldX, worldY, worldZ )); std::shared_ptr<Container> container =
std::dynamic_pointer_cast<Container>(
level->getTileEntity(worldX, worldY, worldZ));
app.DebugPrintf("XboxStructureActionPlaceContainer - placing a container at (%d,%d,%d)\n", worldX, worldY, worldZ); app.DebugPrintf(
if ( container != NULL ) "XboxStructureActionPlaceContainer - placing a container at "
{ "(%d,%d,%d)\n",
level->setData( worldX, worldY, worldZ, m_data); worldX, worldY, worldZ);
if (container != NULL) {
level->setData(worldX, worldY, worldZ, m_data);
// Add items // Add items
int slotId = 0; int slotId = 0;
for(AUTO_VAR(it, m_items.begin()); it != m_items.end() && (slotId < container->getContainerSize()); ++it, ++slotId ) for (AUTO_VAR(it, m_items.begin());
{ it != m_items.end() &&
AddItemRuleDefinition *addItem = *it; (slotId < container->getContainerSize());
++it, ++slotId) {
AddItemRuleDefinition* addItem = *it;
addItem->addItemToContainer(container,slotId); addItem->addItemToContainer(container, slotId);
} }
} }
return true; return true;

View file

@ -7,23 +7,29 @@ class StructurePiece;
class Level; class Level;
class BoundingBox; class BoundingBox;
class XboxStructureActionPlaceContainer : public XboxStructureActionPlaceBlock class XboxStructureActionPlaceContainer : public XboxStructureActionPlaceBlock {
{
private: private:
std::vector<AddItemRuleDefinition *> m_items; std::vector<AddItemRuleDefinition*> m_items;
public: public:
XboxStructureActionPlaceContainer(); XboxStructureActionPlaceContainer();
~XboxStructureActionPlaceContainer(); ~XboxStructureActionPlaceContainer();
virtual ConsoleGameRules::EGameRuleType getActionType() { return ConsoleGameRules::eGameRuleType_PlaceContainer; } virtual ConsoleGameRules::EGameRuleType getActionType() {
return ConsoleGameRules::eGameRuleType_PlaceContainer;
}
virtual void getChildren(std::vector<GameRuleDefinition *> *children); virtual void getChildren(std::vector<GameRuleDefinition*>* children);
virtual GameRuleDefinition *addChild(ConsoleGameRules::EGameRuleType ruleType); virtual GameRuleDefinition* addChild(
ConsoleGameRules::EGameRuleType ruleType);
// 4J-JEV: Super class handles attr-facing fine. // 4J-JEV: Super class handles attr-facing fine.
//virtual void writeAttributes(DataOutputStream *dos, unsigned int numAttributes); // virtual void writeAttributes(DataOutputStream *dos, unsigned int
// numAttributes);
virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue); virtual void addAttribute(const std::wstring& attributeName,
const std::wstring& attributeValue);
bool placeContainerInLevel(StructurePiece *structure, Level *level, BoundingBox *chunkBB); bool placeContainerInLevel(StructurePiece* structure, Level* level,
BoundingBox* chunkBB);
}; };

View file

@ -5,62 +5,61 @@
#include "../../Minecraft.World/Headers/net.minecraft.world.level.h" #include "../../Minecraft.World/Headers/net.minecraft.world.level.h"
#include "../../Minecraft.World/Headers/net.minecraft.world.level.tile.entity.h" #include "../../Minecraft.World/Headers/net.minecraft.world.level.tile.entity.h"
XboxStructureActionPlaceSpawner::XboxStructureActionPlaceSpawner() XboxStructureActionPlaceSpawner::XboxStructureActionPlaceSpawner() {
{
m_tile = Tile::mobSpawner_Id; m_tile = Tile::mobSpawner_Id;
m_entityId = L"Pig"; m_entityId = L"Pig";
} }
XboxStructureActionPlaceSpawner::~XboxStructureActionPlaceSpawner() XboxStructureActionPlaceSpawner::~XboxStructureActionPlaceSpawner() {}
{
}
void XboxStructureActionPlaceSpawner::writeAttributes(DataOutputStream *dos, unsigned int numAttrs) void XboxStructureActionPlaceSpawner::writeAttributes(DataOutputStream* dos,
{ unsigned int numAttrs) {
XboxStructureActionPlaceBlock::writeAttributes(dos, numAttrs + 1); XboxStructureActionPlaceBlock::writeAttributes(dos, numAttrs + 1);
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_entity); ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_entity);
dos->writeUTF(m_entityId); dos->writeUTF(m_entityId);
} }
void XboxStructureActionPlaceSpawner::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue) void XboxStructureActionPlaceSpawner::addAttribute(
{ const std::wstring& attributeName, const std::wstring& attributeValue) {
if(attributeName.compare(L"entity") == 0) if (attributeName.compare(L"entity") == 0) {
{
m_entityId = attributeValue; m_entityId = attributeValue;
#ifndef _CONTENT_PACKAGE #ifndef _CONTENT_PACKAGE
wprintf(L"XboxStructureActionPlaceSpawner: Adding parameter entity=%ls\n",m_entityId.c_str()); wprintf(
L"XboxStructureActionPlaceSpawner: Adding parameter entity=%ls\n",
m_entityId.c_str());
#endif #endif
} } else {
else XboxStructureActionPlaceBlock::addAttribute(attributeName,
{ attributeValue);
XboxStructureActionPlaceBlock::addAttribute(attributeName, attributeValue);
} }
} }
bool XboxStructureActionPlaceSpawner::placeSpawnerInLevel(StructurePiece *structure, Level *level, BoundingBox *chunkBB) bool XboxStructureActionPlaceSpawner::placeSpawnerInLevel(
{ StructurePiece* structure, Level* level, BoundingBox* chunkBB) {
int worldX = structure->getWorldX( m_x, m_z ); int worldX = structure->getWorldX(m_x, m_z);
int worldY = structure->getWorldY( m_y ); int worldY = structure->getWorldY(m_y);
int worldZ = structure->getWorldZ( m_x, m_z ); int worldZ = structure->getWorldZ(m_x, m_z);
if ( chunkBB->isInside( worldX, worldY, worldZ ) ) if (chunkBB->isInside(worldX, worldY, worldZ)) {
{ if (level->getTileEntity(worldX, worldY, worldZ) != NULL) {
if ( level->getTileEntity( worldX, worldY, worldZ ) != NULL )
{
// Remove the current tile entity // Remove the current tile entity
level->removeTileEntity( worldX, worldY, worldZ ); level->removeTileEntity(worldX, worldY, worldZ);
level->setTile( worldX, worldY, worldZ, 0 ); level->setTile(worldX, worldY, worldZ, 0);
} }
level->setTile( worldX, worldY, worldZ, m_tile ); level->setTile(worldX, worldY, worldZ, m_tile);
std::shared_ptr<MobSpawnerTileEntity> entity = std::dynamic_pointer_cast<MobSpawnerTileEntity>(level->getTileEntity( worldX, worldY, worldZ )); std::shared_ptr<MobSpawnerTileEntity> entity =
std::dynamic_pointer_cast<MobSpawnerTileEntity>(
level->getTileEntity(worldX, worldY, worldZ));
#ifndef _CONTENT_PACKAGE #ifndef _CONTENT_PACKAGE
wprintf(L"XboxStructureActionPlaceSpawner - placing a %ls spawner at (%d,%d,%d)\n", m_entityId.c_str(), worldX, worldY, worldZ); wprintf(
L"XboxStructureActionPlaceSpawner - placing a %ls spawner at "
L"(%d,%d,%d)\n",
m_entityId.c_str(), worldX, worldY, worldZ);
#endif #endif
if( entity != NULL ) if (entity != NULL) {
{
entity->setEntityId(m_entityId); entity->setEntityId(m_entityId);
} }
return true; return true;

View file

@ -7,18 +7,22 @@ class Level;
class BoundingBox; class BoundingBox;
class GRFObject; class GRFObject;
class XboxStructureActionPlaceSpawner : public XboxStructureActionPlaceBlock class XboxStructureActionPlaceSpawner : public XboxStructureActionPlaceBlock {
{
private: private:
std::wstring m_entityId; std::wstring m_entityId;
public: public:
XboxStructureActionPlaceSpawner(); XboxStructureActionPlaceSpawner();
~XboxStructureActionPlaceSpawner(); ~XboxStructureActionPlaceSpawner();
virtual ConsoleGameRules::EGameRuleType getActionType() { return ConsoleGameRules::eGameRuleType_PlaceSpawner; } virtual ConsoleGameRules::EGameRuleType getActionType() {
return ConsoleGameRules::eGameRuleType_PlaceSpawner;
}
virtual void writeAttributes(DataOutputStream *dos, unsigned int numAttrs); virtual void writeAttributes(DataOutputStream* dos, unsigned int numAttrs);
virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue); virtual void addAttribute(const std::wstring& attributeName,
const std::wstring& attributeValue);
bool placeSpawnerInLevel(StructurePiece *structure, Level *level, BoundingBox *chunkBB); bool placeSpawnerInLevel(StructurePiece* structure, Level* level,
BoundingBox* chunkBB);
}; };