mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-08-20 09:57:10 +00:00
format .Client/Common/GameRules
This commit is contained in:
parent
6c92bc0be8
commit
87b4af678b
|
|
@ -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,
|
||||||
|
ConsoleGameRules::eGameRuleAttr_enchantmentLevel);
|
||||||
dos->writeUTF(_toString(m_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;
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
};
|
};
|
||||||
|
|
@ -6,14 +6,13 @@
|
||||||
#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);
|
||||||
|
|
@ -32,95 +31,84 @@ void AddItemRuleDefinition::writeAttributes(DataOutputStream *dos, unsigned int
|
||||||
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;
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,7 @@
|
||||||
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;
|
||||||
|
|
@ -21,10 +20,14 @@ public:
|
||||||
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);
|
||||||
};
|
};
|
||||||
|
|
@ -9,8 +9,8 @@
|
||||||
#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;
|
||||||
|
|
@ -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,23 +115,21 @@ 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);
|
||||||
|
|
||||||
|
|
@ -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,37 +154,42 @@ 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;
|
||||||
|
|
@ -195,32 +198,36 @@ void ApplySchematicRuleDefinition::processSchematic(AABB *chunkBox, LevelChunk *
|
||||||
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;
|
||||||
|
|
@ -229,20 +236,18 @@ void ApplySchematicRuleDefinition::processSchematicLighting(AABB *chunkBox, Leve
|
||||||
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;
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,7 @@ 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;
|
||||||
|
|
@ -24,14 +23,18 @@ 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);
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,7 @@
|
||||||
|
|
||||||
#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,10 +12,13 @@ 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);
|
||||||
|
|
|
||||||
|
|
@ -6,19 +6,16 @@
|
||||||
#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);
|
||||||
|
|
@ -31,42 +28,34 @@ void CollectItemRuleDefinition::writeAttributes(DataOutputStream *dos, unsigned
|
||||||
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);
|
||||||
|
|
@ -74,27 +63,33 @@ void CollectItemRuleDefinition::populateGameRule(GameRulesInstance::EGameRulesIn
|
||||||
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;
|
||||||
|
|
|
||||||
|
|
@ -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,10 +17,13 @@ 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);
|
||||||
|
|
@ -29,7 +31,8 @@ public:
|
||||||
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);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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 =
|
||||||
|
CompoundGameRuleDefinition::onUseTile(rule, tileId, x, y, z);
|
||||||
if (statusChanged) updateStatus(rule);
|
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 =
|
||||||
|
replaceAll(newDesc, L"{*progress*}", _toString<int>(values->progress));
|
||||||
newDesc = replaceAll(newDesc, L"{*goal*}", _toString<int>(values->goal));
|
newDesc = replaceAll(newDesc, L"{*goal*}", _toString<int>(values->goal));
|
||||||
return newDesc;
|
return newDesc;
|
||||||
}
|
}
|
||||||
|
|
@ -2,24 +2,26 @@
|
||||||
|
|
||||||
#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);
|
||||||
|
|
|
||||||
|
|
@ -4,61 +4,51 @@
|
||||||
#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);
|
||||||
|
|
||||||
|
|
@ -73,17 +63,17 @@ void CompoundGameRuleDefinition::populateGameRule(GameRulesInstance::EGameRulesI
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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);
|
||||||
};
|
};
|
||||||
|
|
@ -2,13 +2,13 @@
|
||||||
|
|
||||||
// #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));
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
break;
|
case ConsoleGameRules::eGameRuleType_PlaceBlock: {
|
||||||
case ConsoleGameRules::eGameRuleType_PlaceBlock:
|
XboxStructureActionPlaceBlock* pPlaceBlock =
|
||||||
{
|
(XboxStructureActionPlaceBlock*)action;
|
||||||
XboxStructureActionPlaceBlock *pPlaceBlock = (XboxStructureActionPlaceBlock *)action;
|
|
||||||
pPlaceBlock->placeBlockInLevel(this, level, chunkBB);
|
pPlaceBlock->placeBlockInLevel(this, level, chunkBB);
|
||||||
}
|
} break;
|
||||||
break;
|
case ConsoleGameRules::eGameRuleType_PlaceContainer: {
|
||||||
case ConsoleGameRules::eGameRuleType_PlaceContainer:
|
XboxStructureActionPlaceContainer* pPlaceContainer =
|
||||||
{
|
(XboxStructureActionPlaceContainer*)action;
|
||||||
XboxStructureActionPlaceContainer *pPlaceContainer = (XboxStructureActionPlaceContainer *)action;
|
|
||||||
pPlaceContainer->placeContainerInLevel(this, level, chunkBB);
|
pPlaceContainer->placeContainerInLevel(this, level, chunkBB);
|
||||||
}
|
} break;
|
||||||
break;
|
case ConsoleGameRules::eGameRuleType_PlaceSpawner: {
|
||||||
case ConsoleGameRules::eGameRuleType_PlaceSpawner:
|
XboxStructureActionPlaceSpawner* pPlaceSpawner =
|
||||||
{
|
(XboxStructureActionPlaceSpawner*)action;
|
||||||
XboxStructureActionPlaceSpawner *pPlaceSpawner = (XboxStructureActionPlaceSpawner *)action;
|
|
||||||
pPlaceSpawner->placeSpawnerInLevel(this, level, chunkBB);
|
pPlaceSpawner->placeSpawnerInLevel(this, level, chunkBB);
|
||||||
}
|
} break;
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -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,14 +43,14 @@ 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;
|
||||||
|
|
@ -72,19 +70,39 @@ public:
|
||||||
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);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -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 ¶meterName)
|
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 ¶meterName,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,20 +39,19 @@ void GameRule::setParameter(const std::wstring ¶meterName,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;
|
||||||
|
|
||||||
|
|
@ -74,21 +65,16 @@ void GameRule::write(DataOutputStream *dos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,9 @@ 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;
|
||||||
|
|
@ -24,8 +22,7 @@ public:
|
||||||
};
|
};
|
||||||
bool isPointer;
|
bool isPointer;
|
||||||
|
|
||||||
_ValueType()
|
_ValueType() {
|
||||||
{
|
|
||||||
i64 = 0;
|
i64 = 0;
|
||||||
isPointer = false;
|
isPointer = false;
|
||||||
}
|
}
|
||||||
|
|
@ -37,7 +34,8 @@ private:
|
||||||
|
|
||||||
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);
|
||||||
|
|
@ -55,7 +53,8 @@ public:
|
||||||
|
|
||||||
// 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);
|
||||||
|
|
|
||||||
|
|
@ -3,15 +3,13 @@
|
||||||
#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);
|
||||||
|
|
@ -20,7 +18,8 @@ void GameRuleDefinition::write(DataOutputStream *dos)
|
||||||
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 =
|
||||||
|
new std::vector<GameRuleDefinition*>();
|
||||||
getChildren(children);
|
getChildren(children);
|
||||||
|
|
||||||
// Write children.
|
// Write children.
|
||||||
|
|
@ -29,11 +28,12 @@ void GameRuleDefinition::write(DataOutputStream *dos)
|
||||||
(*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,69 +43,67 @@ 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*>();
|
||||||
|
|
@ -114,10 +112,10 @@ std::vector<GameRuleDefinition *> *GameRuleDefinition::enumerate()
|
||||||
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();
|
||||||
|
|
@ -127,8 +125,9 @@ std::unordered_map<GameRuleDefinition *, int> *GameRuleDefinition::enumerateMap(
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
GameRulesInstance *GameRuleDefinition::generateNewGameRulesInstance(GameRulesInstance::EGameRulesInstanceType type, LevelRuleset *rules, Connection *connection)
|
GameRulesInstance* GameRuleDefinition::generateNewGameRulesInstance(
|
||||||
{
|
GameRulesInstance::EGameRulesInstanceType type, LevelRuleset* rules,
|
||||||
|
Connection* connection) {
|
||||||
GameRulesInstance* manager = new GameRulesInstance(rules, connection);
|
GameRulesInstance* manager = new GameRulesInstance(rules, connection);
|
||||||
|
|
||||||
rules->populateGameRule(type, manager);
|
rules->populateGameRule(type, manager);
|
||||||
|
|
@ -136,13 +135,14 @@ GameRulesInstance *GameRuleDefinition::generateNewGameRulesInstance(GameRulesIns
|
||||||
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;
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
@ -31,17 +30,23 @@ public:
|
||||||
|
|
||||||
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,
|
||||||
|
unsigned int numAttributes);
|
||||||
virtual void getChildren(std::vector<GameRuleDefinition*>*);
|
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);
|
||||||
|
|
@ -52,16 +57,25 @@ public:
|
||||||
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) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
virtual bool onCollectItem(GameRule* rule,
|
||||||
|
std::shared_ptr<ItemInstance> item) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
virtual void postProcessPlayer(std::shared_ptr<Player> player) {}
|
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);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -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,58 +81,63 @@ 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 );
|
||||||
|
|
||||||
|
|
@ -142,8 +145,8 @@ void GameRuleManager::loadGameRules(DLCPack *pack)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
|
@ -153,8 +156,8 @@ LevelGenerationOptions *GameRuleManager::loadGameRules(uint8_t *dIn, unsigned in
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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));
|
||||||
|
|
@ -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,10 +190,13 @@ 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();
|
||||||
|
|
@ -205,7 +211,8 @@ void GameRuleManager::loadGameRules(LevelGenerationOptions *lgo, uint8_t *dIn, u
|
||||||
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;
|
||||||
|
|
@ -217,16 +224,13 @@ void GameRuleManager::loadGameRules(LevelGenerationOptions *lgo, uint8_t *dIn, u
|
||||||
// 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -240,11 +244,9 @@ void GameRuleManager::loadGameRules(LevelGenerationOptions *lgo, uint8_t *dIn, u
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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;
|
||||||
|
|
@ -264,8 +266,7 @@ void GameRuleManager::saveGameRules(uint8_t **dOut, unsigned int *dSize)
|
||||||
|
|
||||||
// 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,29 +274,26 @@ 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(Compression::eCompressionType_None); // compression type
|
compr_dos.writeByte(
|
||||||
|
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(
|
||||||
|
&stba.data, &stba.length);
|
||||||
compr_dos.writeInt(stba.length);
|
compr_dos.writeInt(stba.length);
|
||||||
compr_dos.write(stba);
|
compr_dos.write(stba);
|
||||||
|
|
||||||
|
|
@ -306,9 +304,11 @@ 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);
|
||||||
|
|
@ -329,12 +329,12 @@ 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
|
||||||
|
|
@ -344,15 +344,16 @@ void GameRuleManager::writeRuleFile(DataOutputStream *dos)
|
||||||
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;
|
||||||
|
|
||||||
|
|
@ -365,7 +366,8 @@ void GameRuleManager::writeRuleFile(DataOutputStream *dos)
|
||||||
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.
|
||||||
|
|
@ -374,11 +376,14 @@ void GameRuleManager::writeRuleFile(DataOutputStream *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 =
|
||||||
|
lgo; // new LevelGenerationOptions();
|
||||||
LevelRuleset* gameRules = new LevelRuleset();
|
LevelRuleset* gameRules = new LevelRuleset();
|
||||||
|
|
||||||
// std::uint32_t dataLength = 0;
|
// std::uint32_t dataLength = 0;
|
||||||
|
|
@ -394,12 +399,9 @@ 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
|
||||||
|
|
@ -409,15 +411,12 @@ bool GameRuleManager::readRuleFile(LevelGenerationOptions *lgo, uint8_t *dIn, un
|
||||||
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,15 +424,17 @@ 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:
|
||||||
|
|
@ -441,22 +442,29 @@ bool GameRuleManager::readRuleFile(LevelGenerationOptions *lgo, uint8_t *dIn, un
|
||||||
#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;
|
||||||
|
|
@ -476,13 +484,13 @@ bool GameRuleManager::readRuleFile(LevelGenerationOptions *lgo, uint8_t *dIn, un
|
||||||
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,22 +499,23 @@ 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);
|
||||||
|
|
@ -514,32 +523,28 @@ bool GameRuleManager::readRuleFile(LevelGenerationOptions *lgo, uint8_t *dIn, un
|
||||||
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 =
|
||||||
|
ConsoleGameRules::eGameRuleType_Invalid;
|
||||||
AUTO_VAR(it, tagIdMap.find(tagId));
|
AUTO_VAR(it, tagIdMap.find(tagId));
|
||||||
if (it != tagIdMap.end()) tagVal = it->second;
|
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);
|
||||||
|
|
@ -551,8 +556,7 @@ 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;
|
||||||
|
|
@ -569,11 +573,8 @@ bool GameRuleManager::readRuleFile(LevelGenerationOptions *lgo, uint8_t *dIn, un
|
||||||
// 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,11 +583,12 @@ 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();
|
||||||
|
|
||||||
|
|
@ -594,13 +596,16 @@ void GameRuleManager::readAttributes(DataInputStream *dis, std::vector<std::wstr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 =
|
||||||
|
ConsoleGameRules::eGameRuleType_Invalid;
|
||||||
AUTO_VAR(it, tagIdMap->find(tagId));
|
AUTO_VAR(it, tagIdMap->find(tagId));
|
||||||
if (it != tagIdMap->end()) tagVal = it->second;
|
if (it != tagIdMap->end()) tagVal = it->second;
|
||||||
|
|
||||||
|
|
@ -612,26 +617,21 @@ void GameRuleManager::readChildren(DataInputStream *dis, std::vector<std::wstrin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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,11 +639,12 @@ 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
|
||||||
|
|
@ -661,40 +662,44 @@ void GameRuleManager::loadDefaultGameRules()
|
||||||
#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(
|
||||||
|
"loadDefaultGameRules: creating minimal fallback "
|
||||||
|
"LevelGenerationOptions\n");
|
||||||
LevelGenerationOptions* lgo = new LevelGenerationOptions();
|
LevelGenerationOptions* lgo = new LevelGenerationOptions();
|
||||||
lgo->setGrSource(new JustGrSource());
|
lgo->setGrSource(new JustGrSource());
|
||||||
lgo->setSrc(LevelGenerationOptions::eSrc_tutorial);
|
lgo->setSrc(LevelGenerationOptions::eSrc_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_currentLevelGenerationOptions->isFromSave())
|
|
||||||
m_levelRules.removeLevelRule(m_currentGameRuleDefinitions);
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,7 @@ 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];
|
||||||
|
|
@ -41,7 +40,8 @@ public:
|
||||||
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);
|
||||||
|
|
||||||
|
|
@ -51,11 +51,19 @@ private:
|
||||||
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);
|
||||||
|
|
@ -68,10 +76,16 @@ private:
|
||||||
LEVEL_GEN_ID addLevelGenerationOptions(LevelGenerationOptions*);
|
LEVEL_GEN_ID addLevelGenerationOptions(LevelGenerationOptions*);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::vector<LevelGenerationOptions *> *getLevelGenerators() { return m_levelGenerators.getLevelGenerators(); }
|
std::vector<LevelGenerationOptions*>* getLevelGenerators() {
|
||||||
|
return m_levelGenerators.getLevelGenerators();
|
||||||
|
}
|
||||||
void setLevelGenerationOptions(LevelGenerationOptions* levelGen);
|
void setLevelGenerationOptions(LevelGenerationOptions* levelGen);
|
||||||
LevelRuleset *getGameRuleDefinitions() { return m_currentGameRuleDefinitions; }
|
LevelRuleset* getGameRuleDefinitions() {
|
||||||
LevelGenerationOptions *getLevelGenerationOptions() { return m_currentLevelGenerationOptions; }
|
return m_currentGameRuleDefinitions;
|
||||||
|
}
|
||||||
|
LevelGenerationOptions* getLevelGenerationOptions() {
|
||||||
|
return m_currentLevelGenerationOptions;
|
||||||
|
}
|
||||||
const wchar_t* GetGameRulesString(const std::wstring& key);
|
const wchar_t* GetGameRulesString(const std::wstring& key);
|
||||||
|
|
||||||
// 4J-JEV:
|
// 4J-JEV:
|
||||||
|
|
|
||||||
|
|
@ -5,20 +5,20 @@
|
||||||
|
|
||||||
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
|
||||||
};
|
};
|
||||||
|
|
@ -11,8 +11,7 @@
|
||||||
#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";
|
||||||
|
|
@ -23,7 +22,9 @@ JustGrSource::JustGrSource()
|
||||||
}
|
}
|
||||||
|
|
||||||
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() {
|
||||||
|
return m_requiredTexturePackId;
|
||||||
|
}
|
||||||
std::wstring JustGrSource::getDefaultSaveName() { return m_defaultSaveName; }
|
std::wstring JustGrSource::getDefaultSaveName() { return m_defaultSaveName; }
|
||||||
const wchar_t* JustGrSource::getWorldName() { return m_worldName.c_str(); }
|
const wchar_t* JustGrSource::getWorldName() { return m_worldName.c_str(); }
|
||||||
const wchar_t* JustGrSource::getDisplayName() { return m_displayName.c_str(); }
|
const wchar_t* JustGrSource::getDisplayName() { return m_displayName.c_str(); }
|
||||||
|
|
@ -31,18 +32,26 @@ 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::setRequiredTexturePackId(std::uint32_t x) {
|
||||||
|
m_requiredTexturePackId = x;
|
||||||
|
}
|
||||||
|
void JustGrSource::setDefaultSaveName(const std::wstring& x) {
|
||||||
|
m_defaultSaveName = x;
|
||||||
|
}
|
||||||
void JustGrSource::setWorldName(const std::wstring& x) { m_worldName = x; }
|
void JustGrSource::setWorldName(const std::wstring& x) { m_worldName = x; }
|
||||||
void JustGrSource::setDisplayName(const std::wstring& x) { m_displayName = x; }
|
void JustGrSource::setDisplayName(const std::wstring& x) { m_displayName = x; }
|
||||||
void JustGrSource::setGrfPath(const std::wstring& x) { m_grfPath = 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::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,139 +115,139 @@ 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();
|
||||||
|
it++)
|
||||||
children->push_back(*it);
|
children->push_back(*it);
|
||||||
for(AUTO_VAR(it, used_schematics.begin()); it!=used_schematics.end(); 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, m_biomeOverrides.begin()); it != m_biomeOverrides.end(); ++it)
|
for (AUTO_VAR(it, m_biomeOverrides.begin()); it != m_biomeOverrides.end();
|
||||||
|
++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_features.begin()); it != m_features.end(); ++it)
|
||||||
children->push_back(*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("LevelGenerationOptions: Adding parameter flatworld=%s\n",m_useFlatWorld?"TRUE":"FALSE");
|
app.DebugPrintf(
|
||||||
}
|
"LevelGenerationOptions: Adding parameter flatworld=%s\n",
|
||||||
else if(attributeName.compare(L"saveName") == 0)
|
m_useFlatWorld ? "TRUE" : "FALSE");
|
||||||
{
|
} 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
|
||||||
}
|
setDefaultSaveName(attributeValue);
|
||||||
else if(attributeName.compare(L"worldName") == 0)
|
app.DebugPrintf(
|
||||||
{
|
"LevelGenerationOptions: Adding parameter saveName=%ls\n",
|
||||||
|
getDefaultSaveName().c_str());
|
||||||
|
} else if (attributeName.compare(L"worldName") == 0) {
|
||||||
std::wstring string(getString(attributeValue));
|
std::wstring string(getString(attributeValue));
|
||||||
if(!string.empty()) setWorldName( string );
|
if (!string.empty())
|
||||||
else setWorldName( attributeValue );
|
setWorldName(string);
|
||||||
app.DebugPrintf("LevelGenerationOptions: Adding parameter worldName=%ls\n", getWorldName());
|
else
|
||||||
}
|
setWorldName(attributeValue);
|
||||||
else if(attributeName.compare(L"displayName") == 0)
|
app.DebugPrintf(
|
||||||
{
|
"LevelGenerationOptions: Adding parameter worldName=%ls\n",
|
||||||
|
getWorldName());
|
||||||
|
} else if (attributeName.compare(L"displayName") == 0) {
|
||||||
std::wstring string(getString(attributeValue));
|
std::wstring string(getString(attributeValue));
|
||||||
if(!string.empty()) setDisplayName( string );
|
if (!string.empty())
|
||||||
else setDisplayName( attributeValue );
|
setDisplayName(string);
|
||||||
app.DebugPrintf("LevelGenerationOptions: Adding parameter displayName=%ls\n", getDisplayName());
|
else
|
||||||
}
|
setDisplayName(attributeValue);
|
||||||
else if(attributeName.compare(L"texturePackId") == 0)
|
app.DebugPrintf(
|
||||||
{
|
"LevelGenerationOptions: Adding parameter displayName=%ls\n",
|
||||||
|
getDisplayName());
|
||||||
|
} else if (attributeName.compare(L"texturePackId") == 0) {
|
||||||
setRequiredTexturePackId(_fromString<unsigned int>(attributeValue));
|
setRequiredTexturePackId(_fromString<unsigned int>(attributeValue));
|
||||||
setRequiresTexturePack(true);
|
setRequiresTexturePack(true);
|
||||||
app.DebugPrintf("LevelGenerationOptions: Adding parameter texturePackId=%0x\n", getRequiredTexturePackId());
|
app.DebugPrintf(
|
||||||
}
|
"LevelGenerationOptions: Adding parameter texturePackId=%0x\n",
|
||||||
else if(attributeName.compare(L"isTutorial") == 0)
|
getRequiredTexturePackId());
|
||||||
{
|
} else if (attributeName.compare(L"isTutorial") == 0) {
|
||||||
if (attributeValue.compare(L"true") == 0) setSrc(eSrc_tutorial);
|
if (attributeValue.compare(L"true") == 0) setSrc(eSrc_tutorial);
|
||||||
app.DebugPrintf("LevelGenerationOptions: Adding parameter isTutorial=%s\n",isTutorial()?"TRUE":"FALSE");
|
app.DebugPrintf(
|
||||||
}
|
"LevelGenerationOptions: Adding parameter isTutorial=%s\n",
|
||||||
else if(attributeName.compare(L"baseSaveName") == 0)
|
isTutorial() ? "TRUE" : "FALSE");
|
||||||
{
|
} else if (attributeName.compare(L"baseSaveName") == 0) {
|
||||||
setBaseSavePath(attributeValue);
|
setBaseSavePath(attributeValue);
|
||||||
app.DebugPrintf("LevelGenerationOptions: Adding parameter baseSaveName=%ls\n", getBaseSavePath().c_str());
|
app.DebugPrintf(
|
||||||
}
|
"LevelGenerationOptions: Adding parameter baseSaveName=%ls\n",
|
||||||
else
|
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);
|
||||||
|
for (AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end();
|
||||||
|
++it) {
|
||||||
ApplySchematicRuleDefinition* rule = *it;
|
ApplySchematicRuleDefinition* rule = *it;
|
||||||
rule->processSchematic(chunkBox, chunk);
|
rule->processSchematic(chunkBox, chunk);
|
||||||
}
|
}
|
||||||
|
|
@ -248,12 +256,12 @@ 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,35 +270,38 @@ 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);
|
||||||
|
for (AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end();
|
||||||
|
++it) {
|
||||||
ApplySchematicRuleDefinition* rule = *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());
|
||||||
|
it != m_schematicRules.end(); ++it) {
|
||||||
ApplySchematicRuleDefinition* rule = *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;
|
||||||
|
|
@ -299,23 +310,24 @@ bool LevelGenerationOptions::checkIntersects(int x0, int y0, int z0, int x1, int
|
||||||
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
|
||||||
|
// for all schematics
|
||||||
if (y1 < m_minY) return false;
|
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 = structureStart->checkIntersects(x0,y0,z0,x1,y1,z1);
|
intersects =
|
||||||
|
structureStart->checkIntersects(x0, y0, z0, x1, y1, z1);
|
||||||
if (intersects) break;
|
if (intersects) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -323,23 +335,22 @@ bool LevelGenerationOptions::checkIntersects(int x0, int y0, int z0, int x1, int
|
||||||
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;
|
||||||
|
|
@ -356,21 +367,21 @@ 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
|
||||||
|
// keep a set of active schematics for the current world
|
||||||
// AUTO_VAR(it, m_schematics.find(filename));
|
// AUTO_VAR(it, m_schematics.find(filename));
|
||||||
// if(it != m_schematics.end())
|
// if(it != m_schematics.end())
|
||||||
//{
|
//{
|
||||||
|
|
@ -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,45 +433,42 @@ 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,31 +477,74 @@ 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; }
|
||||||
|
|
@ -510,6 +553,13 @@ __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;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,7 @@ 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
|
||||||
|
|
@ -47,8 +46,7 @@ public:
|
||||||
// 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;
|
||||||
|
|
@ -82,18 +80,18 @@ public:
|
||||||
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
|
||||||
};
|
};
|
||||||
|
|
@ -110,7 +108,6 @@ private:
|
||||||
unsigned int m_baseSaveSize;
|
unsigned int m_baseSaveSize;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
void setSrc(eSrc src);
|
void setSrc(eSrc src);
|
||||||
eSrc getSrc();
|
eSrc getSrc();
|
||||||
|
|
||||||
|
|
@ -171,10 +168,13 @@ public:
|
||||||
|
|
||||||
virtual ConsoleGameRules::EGameRuleType getActionType();
|
virtual ConsoleGameRules::EGameRuleType getActionType();
|
||||||
|
|
||||||
virtual void writeAttributes(DataOutputStream *dos, unsigned int numAttributes);
|
virtual void writeAttributes(DataOutputStream* dos,
|
||||||
|
unsigned int numAttributes);
|
||||||
virtual void getChildren(std::vector<GameRuleDefinition*>* children);
|
virtual void getChildren(std::vector<GameRuleDefinition*>* children);
|
||||||
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);
|
||||||
|
|
||||||
__int64 getLevelSeed();
|
__int64 getLevelSeed();
|
||||||
Pos* getSpawnPos();
|
Pos* getSpawnPos();
|
||||||
|
|
@ -189,7 +189,9 @@ 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);
|
||||||
|
|
@ -199,13 +201,16 @@ public:
|
||||||
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
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
||||||
}
|
|
||||||
|
|
||||||
void LevelGenerators::addLevelGenerator(const std::wstring &displayName, LevelGenerationOptions *generator)
|
|
||||||
{
|
|
||||||
if (!displayName.empty()) generator->setDisplayName(displayName);
|
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(),
|
while ((it = find(m_levelGenerators.begin(), m_levelGenerators.end(),
|
||||||
m_levelGenerators.end(),
|
generator)) != m_levelGenerators.end()) {
|
||||||
generator ) )
|
|
||||||
!= m_levelGenerators.end() )
|
|
||||||
{
|
|
||||||
m_levelGenerators.erase(it);
|
m_levelGenerators.erase(it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -4,16 +4,18 @@
|
||||||
|
|
||||||
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,
|
||||||
|
LevelGenerationOptions* generator);
|
||||||
void removeLevelGenerator(LevelGenerationOptions* generator);
|
void removeLevelGenerator(LevelGenerationOptions* generator);
|
||||||
|
|
||||||
std::vector<LevelGenerationOptions *> *getLevelGenerators() { return &m_levelGenerators; }
|
std::vector<LevelGenerationOptions*>* getLevelGenerators() {
|
||||||
|
return &m_levelGenerators;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -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 ?
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,12 @@
|
||||||
|
|
||||||
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,
|
||||||
|
unsigned int dataLength);
|
||||||
void addLevelRule(const std::wstring& displayName, LevelRuleset* rootRule);
|
void addLevelRule(const std::wstring& displayName, LevelRuleset* rootRule);
|
||||||
|
|
||||||
void removeLevelRule(LevelRuleset* removing);
|
void removeLevelRule(LevelRuleset* removing);
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,19 +4,22 @@
|
||||||
|
|
||||||
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);
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,7 @@
|
||||||
|
|
||||||
#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;
|
||||||
|
|
@ -12,11 +11,15 @@ 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; }
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
@ -4,8 +4,7 @@
|
||||||
#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);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -7,25 +7,23 @@
|
||||||
#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;
|
||||||
|
|
@ -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,22 +134,20 @@ 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);
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,7 @@
|
||||||
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;
|
||||||
|
|
||||||
|
|
@ -21,13 +20,18 @@ 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);
|
||||||
};
|
};
|
||||||
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,7 @@
|
||||||
#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);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
@ -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);
|
||||||
};
|
};
|
||||||
|
|
@ -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,47 +24,43 @@ 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;
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
};
|
};
|
||||||
|
|
@ -7,87 +7,88 @@
|
||||||
#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",
|
||||||
|
worldX, worldY, worldZ);
|
||||||
|
if (container != NULL) {
|
||||||
level->setData(worldX, worldY, worldZ, m_data);
|
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() &&
|
||||||
|
(slotId < container->getContainerSize());
|
||||||
|
++it, ++slotId) {
|
||||||
AddItemRuleDefinition* addItem = *it;
|
AddItemRuleDefinition* addItem = *it;
|
||||||
|
|
||||||
addItem->addItemToContainer(container, slotId);
|
addItem->addItemToContainer(container, slotId);
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
};
|
};
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
};
|
};
|
||||||
Loading…
Reference in a new issue