mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-04-28 03:53:37 +00:00
format .Client/Common/GameRules
This commit is contained in:
parent
6c92bc0be8
commit
87b4af678b
|
|
@ -4,67 +4,64 @@
|
|||
#include "../../Minecraft.World/Headers/net.minecraft.world.item.enchantment.h"
|
||||
#include "AddEnchantmentRuleDefinition.h"
|
||||
|
||||
AddEnchantmentRuleDefinition::AddEnchantmentRuleDefinition()
|
||||
{
|
||||
m_enchantmentId = m_enchantmentLevel = 0;
|
||||
AddEnchantmentRuleDefinition::AddEnchantmentRuleDefinition() {
|
||||
m_enchantmentId = m_enchantmentLevel = 0;
|
||||
}
|
||||
|
||||
void AddEnchantmentRuleDefinition::writeAttributes(DataOutputStream *dos, unsigned int numAttributes)
|
||||
{
|
||||
GameRuleDefinition::writeAttributes(dos, numAttributes + 2);
|
||||
void AddEnchantmentRuleDefinition::writeAttributes(DataOutputStream* dos,
|
||||
unsigned int numAttributes) {
|
||||
GameRuleDefinition::writeAttributes(dos, numAttributes + 2);
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_enchantmentId);
|
||||
dos->writeUTF( _toString( m_enchantmentId ) );
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_enchantmentId);
|
||||
dos->writeUTF(_toString(m_enchantmentId));
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_enchantmentLevel);
|
||||
dos->writeUTF( _toString( m_enchantmentLevel ) );
|
||||
ConsoleGameRules::write(dos,
|
||||
ConsoleGameRules::eGameRuleAttr_enchantmentLevel);
|
||||
dos->writeUTF(_toString(m_enchantmentLevel));
|
||||
}
|
||||
|
||||
void AddEnchantmentRuleDefinition::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue)
|
||||
{
|
||||
if(attributeName.compare(L"enchantmentId") == 0)
|
||||
{
|
||||
int value = _fromString<int>(attributeValue);
|
||||
if(value < 0) value = 0;
|
||||
if(value >= 256) value = 255;
|
||||
m_enchantmentId = value;
|
||||
app.DebugPrintf("AddEnchantmentRuleDefinition: Adding parameter enchantmentId=%d\n",m_enchantmentId);
|
||||
}
|
||||
else if(attributeName.compare(L"enchantmentLevel") == 0)
|
||||
{
|
||||
int value = _fromString<int>(attributeValue);
|
||||
if(value < 0) value = 0;
|
||||
m_enchantmentLevel = value;
|
||||
app.DebugPrintf("AddEnchantmentRuleDefinition: Adding parameter enchantmentLevel=%d\n",m_enchantmentLevel);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameRuleDefinition::addAttribute(attributeName, attributeValue);
|
||||
}
|
||||
void AddEnchantmentRuleDefinition::addAttribute(
|
||||
const std::wstring& attributeName, const std::wstring& attributeValue) {
|
||||
if (attributeName.compare(L"enchantmentId") == 0) {
|
||||
int value = _fromString<int>(attributeValue);
|
||||
if (value < 0) value = 0;
|
||||
if (value >= 256) value = 255;
|
||||
m_enchantmentId = value;
|
||||
app.DebugPrintf(
|
||||
"AddEnchantmentRuleDefinition: Adding parameter enchantmentId=%d\n",
|
||||
m_enchantmentId);
|
||||
} else if (attributeName.compare(L"enchantmentLevel") == 0) {
|
||||
int value = _fromString<int>(attributeValue);
|
||||
if (value < 0) value = 0;
|
||||
m_enchantmentLevel = value;
|
||||
app.DebugPrintf(
|
||||
"AddEnchantmentRuleDefinition: Adding parameter "
|
||||
"enchantmentLevel=%d\n",
|
||||
m_enchantmentLevel);
|
||||
} else {
|
||||
GameRuleDefinition::addAttribute(attributeName, attributeValue);
|
||||
}
|
||||
}
|
||||
|
||||
bool AddEnchantmentRuleDefinition::enchantItem(std::shared_ptr<ItemInstance> item)
|
||||
{
|
||||
bool enchanted = false;
|
||||
if (item != NULL)
|
||||
{
|
||||
// 4J-JEV: Ripped code from enchantmenthelpers
|
||||
// Maybe we want to add an addEnchantment method to EnchantmentHelpers
|
||||
if (item->id == Item::enchantedBook_Id)
|
||||
{
|
||||
Item::enchantedBook->addEnchantment( item, new EnchantmentInstance(m_enchantmentId, m_enchantmentLevel) );
|
||||
}
|
||||
else if (item->isEnchantable())
|
||||
{
|
||||
Enchantment *e = Enchantment::enchantments[m_enchantmentId];
|
||||
bool AddEnchantmentRuleDefinition::enchantItem(
|
||||
std::shared_ptr<ItemInstance> item) {
|
||||
bool enchanted = false;
|
||||
if (item != NULL) {
|
||||
// 4J-JEV: Ripped code from enchantmenthelpers
|
||||
// Maybe we want to add an addEnchantment method to EnchantmentHelpers
|
||||
if (item->id == Item::enchantedBook_Id) {
|
||||
Item::enchantedBook->addEnchantment(
|
||||
item,
|
||||
new EnchantmentInstance(m_enchantmentId, m_enchantmentLevel));
|
||||
} else if (item->isEnchantable()) {
|
||||
Enchantment* e = Enchantment::enchantments[m_enchantmentId];
|
||||
|
||||
if(e != NULL && e->category->canEnchant(item->getItem()))
|
||||
{
|
||||
int level = std::min(e->getMaxLevel(), m_enchantmentLevel);
|
||||
item->enchant(e, m_enchantmentLevel);
|
||||
enchanted = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return enchanted;
|
||||
if (e != NULL && e->category->canEnchant(item->getItem())) {
|
||||
int level = std::min(e->getMaxLevel(), m_enchantmentLevel);
|
||||
item->enchant(e, m_enchantmentLevel);
|
||||
enchanted = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return enchanted;
|
||||
}
|
||||
|
|
@ -4,20 +4,22 @@
|
|||
|
||||
class ItemInstance;
|
||||
|
||||
class AddEnchantmentRuleDefinition : public GameRuleDefinition
|
||||
{
|
||||
class AddEnchantmentRuleDefinition : public GameRuleDefinition {
|
||||
private:
|
||||
int m_enchantmentId;
|
||||
int m_enchantmentLevel;
|
||||
int m_enchantmentId;
|
||||
int m_enchantmentLevel;
|
||||
|
||||
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,122 +6,110 @@
|
|||
#include "AddItemRuleDefinition.h"
|
||||
#include "AddEnchantmentRuleDefinition.h"
|
||||
|
||||
AddItemRuleDefinition::AddItemRuleDefinition()
|
||||
{
|
||||
m_itemId = m_quantity = m_auxValue = m_dataTag = 0;
|
||||
m_slot = -1;
|
||||
AddItemRuleDefinition::AddItemRuleDefinition() {
|
||||
m_itemId = m_quantity = m_auxValue = m_dataTag = 0;
|
||||
m_slot = -1;
|
||||
}
|
||||
|
||||
void AddItemRuleDefinition::writeAttributes(DataOutputStream *dos, unsigned int numAttrs)
|
||||
{
|
||||
GameRuleDefinition::writeAttributes(dos, numAttrs + 5);
|
||||
void AddItemRuleDefinition::writeAttributes(DataOutputStream* dos,
|
||||
unsigned int numAttrs) {
|
||||
GameRuleDefinition::writeAttributes(dos, numAttrs + 5);
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_itemId);
|
||||
dos->writeUTF( _toString( m_itemId ) );
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_itemId);
|
||||
dos->writeUTF(_toString(m_itemId));
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_quantity);
|
||||
dos->writeUTF( _toString( m_quantity ) );
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_quantity);
|
||||
dos->writeUTF(_toString(m_quantity));
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_auxValue);
|
||||
dos->writeUTF( _toString( m_auxValue ) );
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_auxValue);
|
||||
dos->writeUTF(_toString(m_auxValue));
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_dataTag);
|
||||
dos->writeUTF( _toString( m_dataTag ) );
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_dataTag);
|
||||
dos->writeUTF(_toString(m_dataTag));
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_slot);
|
||||
dos->writeUTF( _toString( m_slot ) );
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_slot);
|
||||
dos->writeUTF(_toString(m_slot));
|
||||
}
|
||||
|
||||
void AddItemRuleDefinition::getChildren(std::vector<GameRuleDefinition *> *children)
|
||||
{
|
||||
GameRuleDefinition::getChildren( children );
|
||||
for (AUTO_VAR(it, m_enchantments.begin()); it != m_enchantments.end(); it++)
|
||||
children->push_back( *it );
|
||||
void AddItemRuleDefinition::getChildren(
|
||||
std::vector<GameRuleDefinition*>* children) {
|
||||
GameRuleDefinition::getChildren(children);
|
||||
for (AUTO_VAR(it, m_enchantments.begin()); it != m_enchantments.end(); it++)
|
||||
children->push_back(*it);
|
||||
}
|
||||
|
||||
GameRuleDefinition *AddItemRuleDefinition::addChild(ConsoleGameRules::EGameRuleType ruleType)
|
||||
{
|
||||
GameRuleDefinition *rule = NULL;
|
||||
if(ruleType == ConsoleGameRules::eGameRuleType_AddEnchantment)
|
||||
{
|
||||
rule = new AddEnchantmentRuleDefinition();
|
||||
m_enchantments.push_back((AddEnchantmentRuleDefinition *)rule);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameRuleDefinition* AddItemRuleDefinition::addChild(
|
||||
ConsoleGameRules::EGameRuleType ruleType) {
|
||||
GameRuleDefinition* rule = NULL;
|
||||
if (ruleType == ConsoleGameRules::eGameRuleType_AddEnchantment) {
|
||||
rule = new AddEnchantmentRuleDefinition();
|
||||
m_enchantments.push_back((AddEnchantmentRuleDefinition*)rule);
|
||||
} else {
|
||||
#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
|
||||
}
|
||||
return rule;
|
||||
}
|
||||
return rule;
|
||||
}
|
||||
|
||||
void AddItemRuleDefinition::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue)
|
||||
{
|
||||
if(attributeName.compare(L"itemId") == 0)
|
||||
{
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_itemId = value;
|
||||
//app.DebugPrintf(2,"AddItemRuleDefinition: Adding parameter itemId=%d\n",m_itemId);
|
||||
}
|
||||
else if(attributeName.compare(L"quantity") == 0)
|
||||
{
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_quantity = value;
|
||||
//app.DebugPrintf(2,"AddItemRuleDefinition: Adding parameter quantity=%d\n",m_quantity);
|
||||
}
|
||||
else if(attributeName.compare(L"auxValue") == 0)
|
||||
{
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_auxValue = value;
|
||||
//app.DebugPrintf(2,"AddItemRuleDefinition: Adding parameter auxValue=%d\n",m_auxValue);
|
||||
}
|
||||
else if(attributeName.compare(L"dataTag") == 0)
|
||||
{
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_dataTag = value;
|
||||
//app.DebugPrintf(2,"AddItemRuleDefinition: Adding parameter dataTag=%d\n",m_dataTag);
|
||||
}
|
||||
else if(attributeName.compare(L"slot") == 0)
|
||||
{
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_slot = value;
|
||||
//app.DebugPrintf(2,"AddItemRuleDefinition: Adding parameter slot=%d\n",m_slot);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameRuleDefinition::addAttribute(attributeName, attributeValue);
|
||||
}
|
||||
void AddItemRuleDefinition::addAttribute(const std::wstring& attributeName,
|
||||
const std::wstring& attributeValue) {
|
||||
if (attributeName.compare(L"itemId") == 0) {
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_itemId = value;
|
||||
// app.DebugPrintf(2,"AddItemRuleDefinition: Adding parameter
|
||||
// itemId=%d\n",m_itemId);
|
||||
} else if (attributeName.compare(L"quantity") == 0) {
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_quantity = value;
|
||||
// app.DebugPrintf(2,"AddItemRuleDefinition: Adding parameter
|
||||
// quantity=%d\n",m_quantity);
|
||||
} else if (attributeName.compare(L"auxValue") == 0) {
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_auxValue = value;
|
||||
// app.DebugPrintf(2,"AddItemRuleDefinition: Adding parameter
|
||||
// auxValue=%d\n",m_auxValue);
|
||||
} else if (attributeName.compare(L"dataTag") == 0) {
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_dataTag = value;
|
||||
// app.DebugPrintf(2,"AddItemRuleDefinition: Adding parameter
|
||||
// dataTag=%d\n",m_dataTag);
|
||||
} else if (attributeName.compare(L"slot") == 0) {
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_slot = value;
|
||||
// app.DebugPrintf(2,"AddItemRuleDefinition: Adding parameter
|
||||
// slot=%d\n",m_slot);
|
||||
} else {
|
||||
GameRuleDefinition::addAttribute(attributeName, attributeValue);
|
||||
}
|
||||
}
|
||||
|
||||
bool AddItemRuleDefinition::addItemToContainer(std::shared_ptr<Container> container, int slotId)
|
||||
{
|
||||
bool added = false;
|
||||
if(Item::items[m_itemId] != NULL)
|
||||
{
|
||||
int quantity = 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) );
|
||||
newItem->set4JData(m_dataTag);
|
||||
bool AddItemRuleDefinition::addItemToContainer(
|
||||
std::shared_ptr<Container> container, int slotId) {
|
||||
bool added = false;
|
||||
if (Item::items[m_itemId] != NULL) {
|
||||
int quantity =
|
||||
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));
|
||||
newItem->set4JData(m_dataTag);
|
||||
|
||||
for(AUTO_VAR(it, m_enchantments.begin()); it != m_enchantments.end(); ++it)
|
||||
{
|
||||
(*it)->enchantItem(newItem);
|
||||
}
|
||||
for (AUTO_VAR(it, m_enchantments.begin()); it != m_enchantments.end();
|
||||
++it) {
|
||||
(*it)->enchantItem(newItem);
|
||||
}
|
||||
|
||||
if(m_slot >= 0 && m_slot < container->getContainerSize() )
|
||||
{
|
||||
container->setItem( m_slot, newItem );
|
||||
added = true;
|
||||
}
|
||||
else if(slotId >= 0 && slotId < container->getContainerSize() )
|
||||
{
|
||||
container->setItem( slotId, newItem );
|
||||
added = true;
|
||||
}
|
||||
else if(std::dynamic_pointer_cast<Inventory>(container) != NULL)
|
||||
{
|
||||
added = std::dynamic_pointer_cast<Inventory>(container)->add(newItem);
|
||||
}
|
||||
}
|
||||
return added;
|
||||
if (m_slot >= 0 && m_slot < container->getContainerSize()) {
|
||||
container->setItem(m_slot, newItem);
|
||||
added = true;
|
||||
} else if (slotId >= 0 && slotId < container->getContainerSize()) {
|
||||
container->setItem(slotId, newItem);
|
||||
added = true;
|
||||
} else if (std::dynamic_pointer_cast<Inventory>(container) != NULL) {
|
||||
added =
|
||||
std::dynamic_pointer_cast<Inventory>(container)->add(newItem);
|
||||
}
|
||||
}
|
||||
return added;
|
||||
}
|
||||
|
|
@ -5,26 +5,29 @@
|
|||
class Container;
|
||||
class AddEnchantmentRuleDefinition;
|
||||
|
||||
class AddItemRuleDefinition : public GameRuleDefinition
|
||||
{
|
||||
class AddItemRuleDefinition : public GameRuleDefinition {
|
||||
private:
|
||||
int m_itemId;
|
||||
int m_quantity;
|
||||
int m_auxValue;
|
||||
int m_dataTag;
|
||||
int m_slot;
|
||||
std::vector<AddEnchantmentRuleDefinition *> m_enchantments;
|
||||
int m_itemId;
|
||||
int m_quantity;
|
||||
int m_auxValue;
|
||||
int m_dataTag;
|
||||
int m_slot;
|
||||
std::vector<AddEnchantmentRuleDefinition*> m_enchantments;
|
||||
|
||||
public:
|
||||
AddItemRuleDefinition();
|
||||
AddItemRuleDefinition();
|
||||
|
||||
virtual void writeAttributes(DataOutputStream *, unsigned int numAttributes);
|
||||
virtual void getChildren(std::vector<GameRuleDefinition *> *children);
|
||||
virtual void writeAttributes(DataOutputStream*, unsigned int numAttributes);
|
||||
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 void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue);
|
||||
virtual GameRuleDefinition* addChild(
|
||||
ConsoleGameRules::EGameRuleType ruleType);
|
||||
virtual void addAttribute(const std::wstring& attributeName,
|
||||
const std::wstring& attributeValue);
|
||||
|
||||
bool addItemToContainer(std::shared_ptr<Container> container, int slotId);
|
||||
bool addItemToContainer(std::shared_ptr<Container> container, int slotId);
|
||||
};
|
||||
|
|
@ -9,241 +9,246 @@
|
|||
#include "LevelGenerationOptions.h"
|
||||
#include "ConsoleSchematicFile.h"
|
||||
|
||||
ApplySchematicRuleDefinition::ApplySchematicRuleDefinition(LevelGenerationOptions *levelGenOptions)
|
||||
{
|
||||
m_levelGenOptions = levelGenOptions;
|
||||
m_location = Vec3::newPermanent(0,0,0);
|
||||
m_locationBox = NULL;
|
||||
m_totalBlocksChanged = 0;
|
||||
m_totalBlocksChangedLighting = 0;
|
||||
m_rotation = ConsoleSchematicFile::eSchematicRot_0;
|
||||
m_completed = false;
|
||||
m_dimension = 0;
|
||||
m_schematic = NULL;
|
||||
ApplySchematicRuleDefinition::ApplySchematicRuleDefinition(
|
||||
LevelGenerationOptions* levelGenOptions) {
|
||||
m_levelGenOptions = levelGenOptions;
|
||||
m_location = Vec3::newPermanent(0, 0, 0);
|
||||
m_locationBox = NULL;
|
||||
m_totalBlocksChanged = 0;
|
||||
m_totalBlocksChangedLighting = 0;
|
||||
m_rotation = ConsoleSchematicFile::eSchematicRot_0;
|
||||
m_completed = false;
|
||||
m_dimension = 0;
|
||||
m_schematic = NULL;
|
||||
}
|
||||
|
||||
ApplySchematicRuleDefinition::~ApplySchematicRuleDefinition()
|
||||
{
|
||||
app.DebugPrintf("Deleting ApplySchematicRuleDefinition.\n");
|
||||
if(!m_completed) m_levelGenOptions->releaseSchematicFile(m_schematicName);
|
||||
m_schematic = NULL;
|
||||
delete m_location;
|
||||
ApplySchematicRuleDefinition::~ApplySchematicRuleDefinition() {
|
||||
app.DebugPrintf("Deleting ApplySchematicRuleDefinition.\n");
|
||||
if (!m_completed) m_levelGenOptions->releaseSchematicFile(m_schematicName);
|
||||
m_schematic = NULL;
|
||||
delete m_location;
|
||||
}
|
||||
|
||||
void ApplySchematicRuleDefinition::writeAttributes(DataOutputStream *dos, unsigned int numAttrs)
|
||||
{
|
||||
GameRuleDefinition::writeAttributes(dos, numAttrs + 5);
|
||||
void ApplySchematicRuleDefinition::writeAttributes(DataOutputStream* dos,
|
||||
unsigned int numAttrs) {
|
||||
GameRuleDefinition::writeAttributes(dos, numAttrs + 5);
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_filename);
|
||||
dos->writeUTF(m_schematicName);
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x);
|
||||
dos->writeUTF(_toString(m_location->x));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y);
|
||||
dos->writeUTF(_toString(m_location->y));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z);
|
||||
dos->writeUTF(_toString(m_location->z));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_rot);
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_filename);
|
||||
dos->writeUTF(m_schematicName);
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x);
|
||||
dos->writeUTF(_toString(m_location->x));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y);
|
||||
dos->writeUTF(_toString(m_location->y));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z);
|
||||
dos->writeUTF(_toString(m_location->z));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_rot);
|
||||
|
||||
switch (m_rotation)
|
||||
{
|
||||
case ConsoleSchematicFile::eSchematicRot_0: dos->writeUTF(_toString( 0 )); break;
|
||||
case ConsoleSchematicFile::eSchematicRot_90: dos->writeUTF(_toString( 90 )); break;
|
||||
case ConsoleSchematicFile::eSchematicRot_180: dos->writeUTF(_toString( 180 )); break;
|
||||
case ConsoleSchematicFile::eSchematicRot_270: dos->writeUTF(_toString( 270 )); break;
|
||||
}
|
||||
switch (m_rotation) {
|
||||
case ConsoleSchematicFile::eSchematicRot_0:
|
||||
dos->writeUTF(_toString(0));
|
||||
break;
|
||||
case ConsoleSchematicFile::eSchematicRot_90:
|
||||
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)
|
||||
{
|
||||
if(attributeName.compare(L"filename") == 0)
|
||||
{
|
||||
m_schematicName = attributeValue;
|
||||
//app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter filename=%s\n",m_schematicName.c_str());
|
||||
void ApplySchematicRuleDefinition::addAttribute(
|
||||
const std::wstring& attributeName, const std::wstring& attributeValue) {
|
||||
if (attributeName.compare(L"filename") == 0) {
|
||||
m_schematicName = attributeValue;
|
||||
// app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter
|
||||
// filename=%s\n",m_schematicName.c_str());
|
||||
|
||||
if(!m_schematicName.empty())
|
||||
{
|
||||
if(m_schematicName.substr( m_schematicName.length() - 4, m_schematicName.length()).compare(L".sch") != 0)
|
||||
{
|
||||
m_schematicName.append(L".sch");
|
||||
}
|
||||
m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName);
|
||||
}
|
||||
}
|
||||
else if(attributeName.compare(L"x") == 0)
|
||||
{
|
||||
m_location->x = _fromString<int>(attributeValue);
|
||||
if( ((int)abs(m_location->x))%2 != 0) m_location->x -=1;
|
||||
//app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter x=%f\n",m_location->x);
|
||||
}
|
||||
else if(attributeName.compare(L"y") == 0)
|
||||
{
|
||||
m_location->y = _fromString<int>(attributeValue);
|
||||
if( ((int)abs(m_location->y))%2 != 0) m_location->y -= 1;
|
||||
if(m_location->y < 0) m_location->y = 0;
|
||||
//app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter y=%f\n",m_location->y);
|
||||
}
|
||||
else if(attributeName.compare(L"z") == 0)
|
||||
{
|
||||
m_location->z = _fromString<int>(attributeValue);
|
||||
if(((int)abs(m_location->z))%2 != 0) m_location->z -= 1;
|
||||
//app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter z=%f\n",m_location->z);
|
||||
}
|
||||
else if(attributeName.compare(L"rot") == 0)
|
||||
{
|
||||
int degrees = _fromString<int>(attributeValue);
|
||||
if (!m_schematicName.empty()) {
|
||||
if (m_schematicName
|
||||
.substr(m_schematicName.length() - 4,
|
||||
m_schematicName.length())
|
||||
.compare(L".sch") != 0) {
|
||||
m_schematicName.append(L".sch");
|
||||
}
|
||||
m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName);
|
||||
}
|
||||
} else if (attributeName.compare(L"x") == 0) {
|
||||
m_location->x = _fromString<int>(attributeValue);
|
||||
if (((int)abs(m_location->x)) % 2 != 0) m_location->x -= 1;
|
||||
// app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter
|
||||
// x=%f\n",m_location->x);
|
||||
} else if (attributeName.compare(L"y") == 0) {
|
||||
m_location->y = _fromString<int>(attributeValue);
|
||||
if (((int)abs(m_location->y)) % 2 != 0) m_location->y -= 1;
|
||||
if (m_location->y < 0) m_location->y = 0;
|
||||
// app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter
|
||||
// y=%f\n",m_location->y);
|
||||
} else if (attributeName.compare(L"z") == 0) {
|
||||
m_location->z = _fromString<int>(attributeValue);
|
||||
if (((int)abs(m_location->z)) % 2 != 0) m_location->z -= 1;
|
||||
// app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter
|
||||
// z=%f\n",m_location->z);
|
||||
} else if (attributeName.compare(L"rot") == 0) {
|
||||
int degrees = _fromString<int>(attributeValue);
|
||||
|
||||
while(degrees < 0) degrees += 360;
|
||||
while(degrees >= 360) degrees -= 360;
|
||||
float quad = degrees/90;
|
||||
degrees = (int)(quad + 0.5f);
|
||||
switch(degrees)
|
||||
{
|
||||
case 1:
|
||||
m_rotation = ConsoleSchematicFile::eSchematicRot_90;
|
||||
break;
|
||||
case 2:
|
||||
m_rotation = ConsoleSchematicFile::eSchematicRot_180;
|
||||
break;
|
||||
case 3:
|
||||
case 4:
|
||||
m_rotation = ConsoleSchematicFile::eSchematicRot_270;
|
||||
break;
|
||||
case 0:
|
||||
default:
|
||||
m_rotation = ConsoleSchematicFile::eSchematicRot_0;
|
||||
break;
|
||||
};
|
||||
|
||||
//app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter rot=%d\n",m_rotation);
|
||||
}
|
||||
else if(attributeName.compare(L"dim") == 0)
|
||||
{
|
||||
m_dimension = _fromString<int>(attributeValue);
|
||||
if(m_dimension > 1 || m_dimension < -1) m_dimension = 0;
|
||||
//app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter dimension=%d\n",m_dimension);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameRuleDefinition::addAttribute(attributeName, attributeValue);
|
||||
}
|
||||
while (degrees < 0) degrees += 360;
|
||||
while (degrees >= 360) degrees -= 360;
|
||||
float quad = degrees / 90;
|
||||
degrees = (int)(quad + 0.5f);
|
||||
switch (degrees) {
|
||||
case 1:
|
||||
m_rotation = ConsoleSchematicFile::eSchematicRot_90;
|
||||
break;
|
||||
case 2:
|
||||
m_rotation = ConsoleSchematicFile::eSchematicRot_180;
|
||||
break;
|
||||
case 3:
|
||||
case 4:
|
||||
m_rotation = ConsoleSchematicFile::eSchematicRot_270;
|
||||
break;
|
||||
case 0:
|
||||
default:
|
||||
m_rotation = ConsoleSchematicFile::eSchematicRot_0;
|
||||
break;
|
||||
};
|
||||
|
||||
// app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter
|
||||
// rot=%d\n",m_rotation);
|
||||
} else if (attributeName.compare(L"dim") == 0) {
|
||||
m_dimension = _fromString<int>(attributeValue);
|
||||
if (m_dimension > 1 || m_dimension < -1) m_dimension = 0;
|
||||
// app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter
|
||||
// dimension=%d\n",m_dimension);
|
||||
} else {
|
||||
GameRuleDefinition::addAttribute(attributeName, attributeValue);
|
||||
}
|
||||
}
|
||||
|
||||
void ApplySchematicRuleDefinition::updateLocationBox()
|
||||
{
|
||||
if(m_schematic == NULL) m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName);
|
||||
void ApplySchematicRuleDefinition::updateLocationBox() {
|
||||
if (m_schematic == NULL)
|
||||
m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName);
|
||||
|
||||
m_locationBox = AABB::newPermanent(0,0,0,0,0,0);
|
||||
m_locationBox = AABB::newPermanent(0, 0, 0, 0, 0, 0);
|
||||
|
||||
m_locationBox->x0 = m_location->x;
|
||||
m_locationBox->y0 = m_location->y;
|
||||
m_locationBox->z0 = m_location->z;
|
||||
m_locationBox->x0 = m_location->x;
|
||||
m_locationBox->y0 = m_location->y;
|
||||
m_locationBox->z0 = m_location->z;
|
||||
|
||||
m_locationBox->y1 = m_location->y + m_schematic->getYSize();
|
||||
m_locationBox->y1 = m_location->y + m_schematic->getYSize();
|
||||
|
||||
switch(m_rotation)
|
||||
{
|
||||
case ConsoleSchematicFile::eSchematicRot_90:
|
||||
case ConsoleSchematicFile::eSchematicRot_270:
|
||||
m_locationBox->x1 = m_location->x + m_schematic->getZSize();
|
||||
m_locationBox->z1 = m_location->z + m_schematic->getXSize();
|
||||
break;
|
||||
case ConsoleSchematicFile::eSchematicRot_0:
|
||||
case ConsoleSchematicFile::eSchematicRot_180:
|
||||
default:
|
||||
m_locationBox->x1 = m_location->x + m_schematic->getXSize();
|
||||
m_locationBox->z1 = m_location->z + m_schematic->getZSize();
|
||||
break;
|
||||
};
|
||||
switch (m_rotation) {
|
||||
case ConsoleSchematicFile::eSchematicRot_90:
|
||||
case ConsoleSchematicFile::eSchematicRot_270:
|
||||
m_locationBox->x1 = m_location->x + m_schematic->getZSize();
|
||||
m_locationBox->z1 = m_location->z + m_schematic->getXSize();
|
||||
break;
|
||||
case ConsoleSchematicFile::eSchematicRot_0:
|
||||
case ConsoleSchematicFile::eSchematicRot_180:
|
||||
default:
|
||||
m_locationBox->x1 = m_location->x + m_schematic->getXSize();
|
||||
m_locationBox->z1 = m_location->z + m_schematic->getZSize();
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
void ApplySchematicRuleDefinition::processSchematic(AABB *chunkBox, LevelChunk *chunk)
|
||||
{
|
||||
if( m_completed ) return;
|
||||
if(chunk->level->dimension->id != m_dimension) return;
|
||||
|
||||
PIXBeginNamedEvent(0, "Processing ApplySchematicRuleDefinition");
|
||||
if(m_schematic == NULL) m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName);
|
||||
void ApplySchematicRuleDefinition::processSchematic(AABB* chunkBox,
|
||||
LevelChunk* chunk) {
|
||||
if (m_completed) return;
|
||||
if (chunk->level->dimension->id != m_dimension) return;
|
||||
|
||||
if(m_locationBox == NULL) updateLocationBox();
|
||||
if(chunkBox->intersects( m_locationBox ))
|
||||
{
|
||||
m_locationBox->y1 = std::min((double)Level::maxBuildHeight, m_locationBox->y1 );
|
||||
PIXBeginNamedEvent(0, "Processing ApplySchematicRuleDefinition");
|
||||
if (m_schematic == NULL)
|
||||
m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName);
|
||||
|
||||
if (m_locationBox == NULL) updateLocationBox();
|
||||
if (chunkBox->intersects(m_locationBox)) {
|
||||
m_locationBox->y1 =
|
||||
std::min((double)Level::maxBuildHeight, m_locationBox->y1);
|
||||
|
||||
#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
|
||||
PIXBeginNamedEvent(0,"Applying blocks and data");
|
||||
m_totalBlocksChanged += m_schematic->applyBlocksAndData(chunk, chunkBox, m_locationBox, m_rotation);
|
||||
PIXEndNamedEvent();
|
||||
PIXBeginNamedEvent(0, "Applying blocks and data");
|
||||
m_totalBlocksChanged += m_schematic->applyBlocksAndData(
|
||||
chunk, chunkBox, m_locationBox, m_rotation);
|
||||
PIXEndNamedEvent();
|
||||
|
||||
// Add the tileEntities
|
||||
PIXBeginNamedEvent(0,"Applying tile entities");
|
||||
m_schematic->applyTileEntities(chunk, chunkBox, m_locationBox, m_rotation);
|
||||
PIXEndNamedEvent();
|
||||
// Add the tileEntities
|
||||
PIXBeginNamedEvent(0, "Applying tile entities");
|
||||
m_schematic->applyTileEntities(chunk, chunkBox, m_locationBox,
|
||||
m_rotation);
|
||||
PIXEndNamedEvent();
|
||||
|
||||
// TODO This does not take into account things that go outside the bounds of the world
|
||||
int targetBlocks = (m_locationBox->x1 - m_locationBox->x0)
|
||||
* (m_locationBox->y1 - m_locationBox->y0)
|
||||
* (m_locationBox->z1 - m_locationBox->z0);
|
||||
if( (m_totalBlocksChanged == targetBlocks) && (m_totalBlocksChangedLighting == targetBlocks) )
|
||||
{
|
||||
m_completed = true;
|
||||
//m_levelGenOptions->releaseSchematicFile(m_schematicName);
|
||||
//m_schematic = NULL;
|
||||
}
|
||||
}
|
||||
PIXEndNamedEvent();
|
||||
// TODO This does not take into account things that go outside the
|
||||
// bounds of the world
|
||||
int targetBlocks = (m_locationBox->x1 - m_locationBox->x0) *
|
||||
(m_locationBox->y1 - m_locationBox->y0) *
|
||||
(m_locationBox->z1 - m_locationBox->z0);
|
||||
if ((m_totalBlocksChanged == targetBlocks) &&
|
||||
(m_totalBlocksChangedLighting == targetBlocks)) {
|
||||
m_completed = true;
|
||||
// m_levelGenOptions->releaseSchematicFile(m_schematicName);
|
||||
// m_schematic = NULL;
|
||||
}
|
||||
}
|
||||
PIXEndNamedEvent();
|
||||
}
|
||||
|
||||
void ApplySchematicRuleDefinition::processSchematicLighting(AABB *chunkBox, LevelChunk *chunk)
|
||||
{
|
||||
if( m_completed ) return;
|
||||
if(chunk->level->dimension->id != m_dimension) return;
|
||||
|
||||
PIXBeginNamedEvent(0, "Processing ApplySchematicRuleDefinition (lighting)");
|
||||
if(m_schematic == NULL) m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName);
|
||||
void ApplySchematicRuleDefinition::processSchematicLighting(AABB* chunkBox,
|
||||
LevelChunk* chunk) {
|
||||
if (m_completed) return;
|
||||
if (chunk->level->dimension->id != m_dimension) return;
|
||||
|
||||
if(m_locationBox == NULL) updateLocationBox();
|
||||
if(chunkBox->intersects( m_locationBox ))
|
||||
{
|
||||
m_locationBox->y1 = std::min((double)Level::maxBuildHeight, m_locationBox->y1 );
|
||||
PIXBeginNamedEvent(0, "Processing ApplySchematicRuleDefinition (lighting)");
|
||||
if (m_schematic == NULL)
|
||||
m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName);
|
||||
|
||||
if (m_locationBox == NULL) updateLocationBox();
|
||||
if (chunkBox->intersects(m_locationBox)) {
|
||||
m_locationBox->y1 =
|
||||
std::min((double)Level::maxBuildHeight, m_locationBox->y1);
|
||||
|
||||
#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
|
||||
PIXBeginNamedEvent(0,"Patching lighting");
|
||||
m_totalBlocksChangedLighting += m_schematic->applyLighting(chunk, chunkBox, m_locationBox, m_rotation);
|
||||
PIXEndNamedEvent();
|
||||
PIXBeginNamedEvent(0, "Patching lighting");
|
||||
m_totalBlocksChangedLighting += m_schematic->applyLighting(
|
||||
chunk, chunkBox, m_locationBox, m_rotation);
|
||||
PIXEndNamedEvent();
|
||||
|
||||
// TODO This does not take into account things that go outside the bounds of the world
|
||||
int targetBlocks = (m_locationBox->x1 - m_locationBox->x0)
|
||||
* (m_locationBox->y1 - m_locationBox->y0)
|
||||
* (m_locationBox->z1 - m_locationBox->z0);
|
||||
if( (m_totalBlocksChanged == targetBlocks) && (m_totalBlocksChangedLighting == targetBlocks) )
|
||||
{
|
||||
m_completed = true;
|
||||
//m_levelGenOptions->releaseSchematicFile(m_schematicName);
|
||||
//m_schematic = NULL;
|
||||
}
|
||||
}
|
||||
PIXEndNamedEvent();
|
||||
// TODO This does not take into account things that go outside the
|
||||
// bounds of the world
|
||||
int targetBlocks = (m_locationBox->x1 - m_locationBox->x0) *
|
||||
(m_locationBox->y1 - m_locationBox->y0) *
|
||||
(m_locationBox->z1 - m_locationBox->z0);
|
||||
if ((m_totalBlocksChanged == targetBlocks) &&
|
||||
(m_totalBlocksChangedLighting == targetBlocks)) {
|
||||
m_completed = true;
|
||||
// m_levelGenOptions->releaseSchematicFile(m_schematicName);
|
||||
// m_schematic = NULL;
|
||||
}
|
||||
}
|
||||
PIXEndNamedEvent();
|
||||
}
|
||||
|
||||
bool ApplySchematicRuleDefinition::checkIntersects(int x0, int y0, int z0, int x1, int y1, int z1)
|
||||
{
|
||||
if( m_locationBox == NULL ) updateLocationBox();
|
||||
return m_locationBox->intersects(x0,y0,z0,x1,y1,z1);
|
||||
bool ApplySchematicRuleDefinition::checkIntersects(int x0, int y0, int z0,
|
||||
int x1, int y1, int z1) {
|
||||
if (m_locationBox == NULL) updateLocationBox();
|
||||
return m_locationBox->intersects(x0, y0, z0, x1, y1, z1);
|
||||
}
|
||||
|
||||
int ApplySchematicRuleDefinition::getMinY()
|
||||
{
|
||||
if( m_locationBox == NULL ) updateLocationBox();
|
||||
return m_locationBox->y0;
|
||||
int ApplySchematicRuleDefinition::getMinY() {
|
||||
if (m_locationBox == NULL) updateLocationBox();
|
||||
return m_locationBox->y0;
|
||||
}
|
||||
|
||||
void ApplySchematicRuleDefinition::reset()
|
||||
{
|
||||
m_totalBlocksChanged = 0;
|
||||
m_totalBlocksChangedLighting = 0;
|
||||
m_completed = false;
|
||||
void ApplySchematicRuleDefinition::reset() {
|
||||
m_totalBlocksChanged = 0;
|
||||
m_totalBlocksChangedLighting = 0;
|
||||
m_completed = false;
|
||||
}
|
||||
|
|
@ -8,44 +8,47 @@ class LevelChunk;
|
|||
class LevelGenerationOptions;
|
||||
class GRFObject;
|
||||
|
||||
class ApplySchematicRuleDefinition : public GameRuleDefinition
|
||||
{
|
||||
class ApplySchematicRuleDefinition : public GameRuleDefinition {
|
||||
private:
|
||||
LevelGenerationOptions *m_levelGenOptions;
|
||||
std::wstring m_schematicName;
|
||||
ConsoleSchematicFile *m_schematic;
|
||||
Vec3 *m_location;
|
||||
AABB *m_locationBox;
|
||||
ConsoleSchematicFile::ESchematicRotation m_rotation;
|
||||
int m_dimension;
|
||||
LevelGenerationOptions* m_levelGenOptions;
|
||||
std::wstring m_schematicName;
|
||||
ConsoleSchematicFile* m_schematic;
|
||||
Vec3* m_location;
|
||||
AABB* m_locationBox;
|
||||
ConsoleSchematicFile::ESchematicRotation m_rotation;
|
||||
int m_dimension;
|
||||
|
||||
__int64 m_totalBlocksChanged;
|
||||
__int64 m_totalBlocksChangedLighting;
|
||||
bool m_completed;
|
||||
__int64 m_totalBlocksChanged;
|
||||
__int64 m_totalBlocksChangedLighting;
|
||||
bool m_completed;
|
||||
|
||||
void updateLocationBox();
|
||||
public:
|
||||
ApplySchematicRuleDefinition(LevelGenerationOptions *levelGenOptions);
|
||||
~ApplySchematicRuleDefinition();
|
||||
void updateLocationBox();
|
||||
|
||||
virtual ConsoleGameRules::EGameRuleType getActionType() { return ConsoleGameRules::eGameRuleType_ApplySchematic; }
|
||||
|
||||
virtual void writeAttributes(DataOutputStream *dos, unsigned int numAttrs);
|
||||
virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue);
|
||||
public:
|
||||
ApplySchematicRuleDefinition(LevelGenerationOptions* levelGenOptions);
|
||||
~ApplySchematicRuleDefinition();
|
||||
|
||||
void processSchematic(AABB *chunkBox, LevelChunk *chunk);
|
||||
void processSchematicLighting(AABB *chunkBox, LevelChunk *chunk);
|
||||
virtual ConsoleGameRules::EGameRuleType getActionType() {
|
||||
return ConsoleGameRules::eGameRuleType_ApplySchematic;
|
||||
}
|
||||
|
||||
bool checkIntersects(int x0, int y0, int z0, int x1, int y1, int z1);
|
||||
int getMinY();
|
||||
virtual void writeAttributes(DataOutputStream* dos, unsigned int numAttrs);
|
||||
virtual void addAttribute(const std::wstring& attributeName,
|
||||
const std::wstring& attributeValue);
|
||||
|
||||
bool isComplete() { return m_completed; }
|
||||
void processSchematic(AABB* chunkBox, LevelChunk* chunk);
|
||||
void processSchematicLighting(AABB* chunkBox, LevelChunk* chunk);
|
||||
|
||||
std::wstring getSchematicName() { return m_schematicName; }
|
||||
bool checkIntersects(int x0, int y0, int z0, int x1, int y1, int z1);
|
||||
int getMinY();
|
||||
|
||||
/** 4J-JEV:
|
||||
* This GameRuleDefinition contains limited game state.
|
||||
* Reset any state to how it should be before a new game.
|
||||
*/
|
||||
void reset();
|
||||
bool isComplete() { return m_completed; }
|
||||
|
||||
std::wstring getSchematicName() { return m_schematicName; }
|
||||
|
||||
/** 4J-JEV:
|
||||
* This GameRuleDefinition contains limited game state.
|
||||
* Reset any state to how it should be before a new game.
|
||||
*/
|
||||
void reset();
|
||||
};
|
||||
|
|
@ -2,58 +2,48 @@
|
|||
#include "../../Minecraft.World/Util/StringHelpers.h"
|
||||
#include "BiomeOverride.h"
|
||||
|
||||
BiomeOverride::BiomeOverride()
|
||||
{
|
||||
m_tile = 0;
|
||||
m_topTile = 0;
|
||||
m_biomeId = 0;
|
||||
BiomeOverride::BiomeOverride() {
|
||||
m_tile = 0;
|
||||
m_topTile = 0;
|
||||
m_biomeId = 0;
|
||||
}
|
||||
|
||||
void BiomeOverride::writeAttributes(DataOutputStream *dos, unsigned int numAttrs)
|
||||
{
|
||||
GameRuleDefinition::writeAttributes(dos, numAttrs + 3);
|
||||
void BiomeOverride::writeAttributes(DataOutputStream* dos,
|
||||
unsigned int numAttrs) {
|
||||
GameRuleDefinition::writeAttributes(dos, numAttrs + 3);
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_biomeId);
|
||||
dos->writeUTF(_toString(m_biomeId));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_tileId);
|
||||
dos->writeUTF(_toString(m_tile));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_topTileId);
|
||||
dos->writeUTF(_toString(m_topTile));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_biomeId);
|
||||
dos->writeUTF(_toString(m_biomeId));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_tileId);
|
||||
dos->writeUTF(_toString(m_tile));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_topTileId);
|
||||
dos->writeUTF(_toString(m_topTile));
|
||||
}
|
||||
|
||||
void BiomeOverride::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue)
|
||||
{
|
||||
if(attributeName.compare(L"tileId") == 0)
|
||||
{
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_tile = value;
|
||||
app.DebugPrintf("BiomeOverride: Adding parameter tileId=%d\n",m_tile);
|
||||
}
|
||||
else if(attributeName.compare(L"topTileId") == 0)
|
||||
{
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_topTile = value;
|
||||
app.DebugPrintf("BiomeOverride: Adding parameter topTileId=%d\n",m_topTile);
|
||||
}
|
||||
else if(attributeName.compare(L"biomeId") == 0)
|
||||
{
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_biomeId = value;
|
||||
app.DebugPrintf("BiomeOverride: Adding parameter biomeId=%d\n",m_biomeId);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameRuleDefinition::addAttribute(attributeName, attributeValue);
|
||||
}
|
||||
void BiomeOverride::addAttribute(const std::wstring& attributeName,
|
||||
const std::wstring& attributeValue) {
|
||||
if (attributeName.compare(L"tileId") == 0) {
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_tile = value;
|
||||
app.DebugPrintf("BiomeOverride: Adding parameter tileId=%d\n", m_tile);
|
||||
} else if (attributeName.compare(L"topTileId") == 0) {
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_topTile = value;
|
||||
app.DebugPrintf("BiomeOverride: Adding parameter topTileId=%d\n",
|
||||
m_topTile);
|
||||
} else if (attributeName.compare(L"biomeId") == 0) {
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_biomeId = value;
|
||||
app.DebugPrintf("BiomeOverride: Adding parameter biomeId=%d\n",
|
||||
m_biomeId);
|
||||
} else {
|
||||
GameRuleDefinition::addAttribute(attributeName, attributeValue);
|
||||
}
|
||||
}
|
||||
|
||||
bool BiomeOverride::isBiome(int id)
|
||||
{
|
||||
return m_biomeId == id;
|
||||
}
|
||||
bool BiomeOverride::isBiome(int id) { return m_biomeId == id; }
|
||||
|
||||
void BiomeOverride::getTileValues(std::uint8_t &tile, std::uint8_t &topTile)
|
||||
{
|
||||
if(m_tile != 0) tile = m_tile;
|
||||
if(m_topTile != 0) topTile = m_topTile;
|
||||
void BiomeOverride::getTileValues(std::uint8_t& tile, std::uint8_t& topTile) {
|
||||
if (m_tile != 0) tile = m_tile;
|
||||
if (m_topTile != 0) topTile = m_topTile;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,25 @@
|
|||
#pragma once
|
||||
//using namespace std;
|
||||
// using namespace std;
|
||||
|
||||
#include "GameRuleDefinition.h"
|
||||
|
||||
class BiomeOverride : public GameRuleDefinition
|
||||
{
|
||||
class BiomeOverride : public GameRuleDefinition {
|
||||
private:
|
||||
std::uint8_t m_topTile;
|
||||
std::uint8_t m_tile;
|
||||
int m_biomeId;
|
||||
std::uint8_t m_topTile;
|
||||
std::uint8_t m_tile;
|
||||
int m_biomeId;
|
||||
|
||||
public:
|
||||
BiomeOverride();
|
||||
BiomeOverride();
|
||||
|
||||
virtual ConsoleGameRules::EGameRuleType getActionType() { return ConsoleGameRules::eGameRuleType_BiomeOverride; }
|
||||
|
||||
virtual void writeAttributes(DataOutputStream *dos, unsigned int numAttrs);
|
||||
virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue);
|
||||
virtual ConsoleGameRules::EGameRuleType getActionType() {
|
||||
return ConsoleGameRules::eGameRuleType_BiomeOverride;
|
||||
}
|
||||
|
||||
bool isBiome(int id);
|
||||
void getTileValues(std::uint8_t &tile, std::uint8_t &topTile);
|
||||
virtual void writeAttributes(DataOutputStream* dos, unsigned int numAttrs);
|
||||
virtual void addAttribute(const std::wstring& attributeName,
|
||||
const std::wstring& attributeValue);
|
||||
|
||||
bool isBiome(int id);
|
||||
void getTileValues(std::uint8_t& tile, std::uint8_t& topTile);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -6,112 +6,111 @@
|
|||
#include "../../Minecraft.World/Network/Connection.h"
|
||||
#include "../../Minecraft.World/Headers/net.minecraft.network.packet.h"
|
||||
|
||||
CollectItemRuleDefinition::CollectItemRuleDefinition()
|
||||
{
|
||||
m_itemId = 0;
|
||||
m_auxValue = 0;
|
||||
m_quantity = 0;
|
||||
CollectItemRuleDefinition::CollectItemRuleDefinition() {
|
||||
m_itemId = 0;
|
||||
m_auxValue = 0;
|
||||
m_quantity = 0;
|
||||
}
|
||||
|
||||
CollectItemRuleDefinition::~CollectItemRuleDefinition()
|
||||
{
|
||||
CollectItemRuleDefinition::~CollectItemRuleDefinition() {}
|
||||
|
||||
void CollectItemRuleDefinition::writeAttributes(DataOutputStream* dos,
|
||||
unsigned int numAttributes) {
|
||||
GameRuleDefinition::writeAttributes(dos, numAttributes + 3);
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_itemId);
|
||||
dos->writeUTF(_toString(m_itemId));
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_auxValue);
|
||||
dos->writeUTF(_toString(m_auxValue));
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_quantity);
|
||||
dos->writeUTF(_toString(m_quantity));
|
||||
}
|
||||
|
||||
void CollectItemRuleDefinition::writeAttributes(DataOutputStream *dos, unsigned int numAttributes)
|
||||
{
|
||||
GameRuleDefinition::writeAttributes(dos, numAttributes + 3);
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_itemId);
|
||||
dos->writeUTF( _toString( m_itemId ) );
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_auxValue);
|
||||
dos->writeUTF( _toString( m_auxValue ) );
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_quantity);
|
||||
dos->writeUTF( _toString( m_quantity ) );
|
||||
void CollectItemRuleDefinition::addAttribute(
|
||||
const std::wstring& attributeName, const std::wstring& attributeValue) {
|
||||
if (attributeName.compare(L"itemId") == 0) {
|
||||
m_itemId = _fromString<int>(attributeValue);
|
||||
app.DebugPrintf("CollectItemRule: Adding parameter itemId=%d\n",
|
||||
m_itemId);
|
||||
} else if (attributeName.compare(L"auxValue") == 0) {
|
||||
m_auxValue = _fromString<int>(attributeValue);
|
||||
app.DebugPrintf("CollectItemRule: Adding parameter m_auxValue=%d\n",
|
||||
m_auxValue);
|
||||
} else if (attributeName.compare(L"quantity") == 0) {
|
||||
m_quantity = _fromString<int>(attributeValue);
|
||||
app.DebugPrintf("CollectItemRule: Adding parameter m_quantity=%d\n",
|
||||
m_quantity);
|
||||
} else {
|
||||
GameRuleDefinition::addAttribute(attributeName, attributeValue);
|
||||
}
|
||||
}
|
||||
|
||||
void CollectItemRuleDefinition::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue)
|
||||
{
|
||||
if(attributeName.compare(L"itemId") == 0)
|
||||
{
|
||||
m_itemId = _fromString<int>(attributeValue);
|
||||
app.DebugPrintf("CollectItemRule: Adding parameter itemId=%d\n",m_itemId);
|
||||
}
|
||||
else if(attributeName.compare(L"auxValue") == 0)
|
||||
{
|
||||
m_auxValue = _fromString<int>(attributeValue);
|
||||
app.DebugPrintf("CollectItemRule: Adding parameter m_auxValue=%d\n",m_auxValue);
|
||||
}
|
||||
else if(attributeName.compare(L"quantity") == 0)
|
||||
{
|
||||
m_quantity = _fromString<int>(attributeValue);
|
||||
app.DebugPrintf("CollectItemRule: Adding parameter m_quantity=%d\n",m_quantity);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameRuleDefinition::addAttribute(attributeName, attributeValue);
|
||||
}
|
||||
int CollectItemRuleDefinition::getGoal() { return m_quantity; }
|
||||
|
||||
int CollectItemRuleDefinition::getProgress(GameRule* rule) {
|
||||
GameRule::ValueType value = rule->getParameter(L"iQuantity");
|
||||
return value.i;
|
||||
}
|
||||
|
||||
int CollectItemRuleDefinition::getGoal()
|
||||
{
|
||||
return m_quantity;
|
||||
void CollectItemRuleDefinition::populateGameRule(
|
||||
GameRulesInstance::EGameRulesInstanceType type, GameRule* rule) {
|
||||
GameRule::ValueType value;
|
||||
value.i = 0;
|
||||
rule->setParameter(L"iQuantity", value);
|
||||
|
||||
GameRuleDefinition::populateGameRule(type, rule);
|
||||
}
|
||||
|
||||
int CollectItemRuleDefinition::getProgress(GameRule *rule)
|
||||
{
|
||||
GameRule::ValueType value = rule->getParameter(L"iQuantity");
|
||||
return value.i;
|
||||
bool CollectItemRuleDefinition::onCollectItem(
|
||||
GameRule* rule, std::shared_ptr<ItemInstance> item) {
|
||||
bool statusChanged = false;
|
||||
if (item != NULL && item->id == m_itemId &&
|
||||
item->getAuxValue() == m_auxValue &&
|
||||
item->get4JData() == m_4JDataValue) {
|
||||
if (!getComplete(rule)) {
|
||||
GameRule::ValueType value = rule->getParameter(L"iQuantity");
|
||||
int quantityCollected = (value.i += item->count);
|
||||
rule->setParameter(L"iQuantity", value);
|
||||
|
||||
statusChanged = true;
|
||||
|
||||
if (quantityCollected >= m_quantity) {
|
||||
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);
|
||||
|
||||
if (rule->getConnection() != NULL) {
|
||||
rule->getConnection()->send(
|
||||
std::shared_ptr<UpdateGameRuleProgressPacket>(
|
||||
new UpdateGameRuleProgressPacket(
|
||||
getActionType(), this->m_descriptionId,
|
||||
m_itemId, m_auxValue, this->m_4JDataValue, NULL,
|
||||
0)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return statusChanged;
|
||||
}
|
||||
|
||||
void CollectItemRuleDefinition::populateGameRule(GameRulesInstance::EGameRulesInstanceType type, GameRule *rule)
|
||||
{
|
||||
GameRule::ValueType value;
|
||||
value.i = 0;
|
||||
rule->setParameter(L"iQuantity",value);
|
||||
|
||||
GameRuleDefinition::populateGameRule(type, rule);
|
||||
}
|
||||
|
||||
bool CollectItemRuleDefinition::onCollectItem(GameRule *rule, std::shared_ptr<ItemInstance> item)
|
||||
{
|
||||
bool statusChanged = false;
|
||||
if(item != NULL && item->id == m_itemId && item->getAuxValue() == m_auxValue && item->get4JData() == m_4JDataValue)
|
||||
{
|
||||
if(!getComplete(rule))
|
||||
{
|
||||
GameRule::ValueType value = rule->getParameter(L"iQuantity");
|
||||
int quantityCollected = (value.i += item->count);
|
||||
rule->setParameter(L"iQuantity",value);
|
||||
|
||||
statusChanged = true;
|
||||
|
||||
if(quantityCollected >= m_quantity)
|
||||
{
|
||||
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);
|
||||
|
||||
if(rule->getConnection() != NULL)
|
||||
{
|
||||
rule->getConnection()->send( std::shared_ptr<UpdateGameRuleProgressPacket>( new UpdateGameRuleProgressPacket(getActionType(), this->m_descriptionId, m_itemId, m_auxValue, this->m_4JDataValue,NULL,0)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return statusChanged;
|
||||
}
|
||||
|
||||
std::wstring CollectItemRuleDefinition::generateXml(std::shared_ptr<ItemInstance> item)
|
||||
{
|
||||
// 4J Stu - This should be kept in sync with the GameRulesDefinition.xsd
|
||||
std::wstring xml = L"";
|
||||
if(item != NULL)
|
||||
{
|
||||
xml = L"<CollectItemRule itemId=\"" + _toString<int>(item->id) + L"\" quantity=\"SET\" descriptionName=\"OPTIONAL\" promptName=\"OPTIONAL\"";
|
||||
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";
|
||||
}
|
||||
return xml;
|
||||
std::wstring CollectItemRuleDefinition::generateXml(
|
||||
std::shared_ptr<ItemInstance> item) {
|
||||
// 4J Stu - This should be kept in sync with the GameRulesDefinition.xsd
|
||||
std::wstring xml = L"";
|
||||
if (item != NULL) {
|
||||
xml = L"<CollectItemRule itemId=\"" + _toString<int>(item->id) +
|
||||
L"\" quantity=\"SET\" descriptionName=\"OPTIONAL\" "
|
||||
L"promptName=\"OPTIONAL\"";
|
||||
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";
|
||||
}
|
||||
return xml;
|
||||
}
|
||||
|
|
@ -6,35 +6,38 @@ class Pos;
|
|||
class UseTileRuleDefinition;
|
||||
class ItemInstance;
|
||||
|
||||
class CollectItemRuleDefinition : public GameRuleDefinition
|
||||
{
|
||||
class CollectItemRuleDefinition : public GameRuleDefinition {
|
||||
private:
|
||||
// These values should map directly to the xsd definition for this Rule
|
||||
int m_itemId;
|
||||
unsigned char m_auxValue;
|
||||
int m_quantity;
|
||||
// These values should map directly to the xsd definition for this Rule
|
||||
int m_itemId;
|
||||
unsigned char m_auxValue;
|
||||
int m_quantity;
|
||||
|
||||
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 addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue);
|
||||
virtual void writeAttributes(DataOutputStream*, unsigned int numAttributes);
|
||||
virtual void addAttribute(const std::wstring& attributeName,
|
||||
const std::wstring& attributeValue);
|
||||
|
||||
virtual int getGoal();
|
||||
virtual int getProgress(GameRule *rule);
|
||||
|
||||
virtual int getIcon() { return m_itemId; }
|
||||
virtual int getAuxValue() { return m_auxValue; }
|
||||
virtual int getGoal();
|
||||
virtual int getProgress(GameRule* rule);
|
||||
|
||||
void populateGameRule(GameRulesInstance::EGameRulesInstanceType type, GameRule *rule);
|
||||
virtual int getIcon() { return m_itemId; }
|
||||
virtual int getAuxValue() { return m_auxValue; }
|
||||
|
||||
bool onCollectItem(GameRule *rule, std::shared_ptr<ItemInstance> item);
|
||||
void populateGameRule(GameRulesInstance::EGameRulesInstanceType type,
|
||||
GameRule* rule);
|
||||
|
||||
static std::wstring generateXml(std::shared_ptr<ItemInstance> item);
|
||||
bool onCollectItem(GameRule* rule, std::shared_ptr<ItemInstance> item);
|
||||
|
||||
private:
|
||||
//static std::wstring generateXml(CollectItemRuleDefinition *ruleDef);
|
||||
static std::wstring generateXml(std::shared_ptr<ItemInstance> item);
|
||||
|
||||
private:
|
||||
// static std::wstring generateXml(CollectItemRuleDefinition *ruleDef);
|
||||
};
|
||||
|
|
@ -5,62 +5,66 @@
|
|||
#include "../../Minecraft.World/Network/Connection.h"
|
||||
#include "../../Minecraft.World/Headers/net.minecraft.network.packet.h"
|
||||
|
||||
void CompleteAllRuleDefinition::getChildren(std::vector<GameRuleDefinition *> *children)
|
||||
{
|
||||
CompoundGameRuleDefinition::getChildren(children);
|
||||
void CompleteAllRuleDefinition::getChildren(
|
||||
std::vector<GameRuleDefinition*>* children) {
|
||||
CompoundGameRuleDefinition::getChildren(children);
|
||||
}
|
||||
|
||||
bool CompleteAllRuleDefinition::onUseTile(GameRule *rule, int tileId, int x, int y, int z)
|
||||
{
|
||||
bool statusChanged = CompoundGameRuleDefinition::onUseTile(rule,tileId,x,y,z);
|
||||
if(statusChanged) updateStatus(rule);
|
||||
return statusChanged;
|
||||
bool CompleteAllRuleDefinition::onUseTile(GameRule* rule, int tileId, int x,
|
||||
int y, int z) {
|
||||
bool statusChanged =
|
||||
CompoundGameRuleDefinition::onUseTile(rule, tileId, x, y, z);
|
||||
if (statusChanged) updateStatus(rule);
|
||||
return statusChanged;
|
||||
}
|
||||
|
||||
bool CompleteAllRuleDefinition::onCollectItem(GameRule *rule, std::shared_ptr<ItemInstance> item)
|
||||
{
|
||||
bool statusChanged = CompoundGameRuleDefinition::onCollectItem(rule,item);
|
||||
if(statusChanged) updateStatus(rule);
|
||||
return statusChanged;
|
||||
bool CompleteAllRuleDefinition::onCollectItem(
|
||||
GameRule* rule, std::shared_ptr<ItemInstance> item) {
|
||||
bool statusChanged = CompoundGameRuleDefinition::onCollectItem(rule, item);
|
||||
if (statusChanged) updateStatus(rule);
|
||||
return statusChanged;
|
||||
}
|
||||
|
||||
void CompleteAllRuleDefinition::updateStatus(GameRule *rule)
|
||||
{
|
||||
int goal = 0;
|
||||
int progress = 0;
|
||||
for(AUTO_VAR(it, rule->m_parameters.begin()); it != rule->m_parameters.end(); ++it)
|
||||
{
|
||||
if(it->second.isPointer)
|
||||
{
|
||||
goal += it->second.gr->getGameRuleDefinition()->getGoal();
|
||||
progress += it->second.gr->getGameRuleDefinition()->getProgress(it->second.gr);
|
||||
}
|
||||
}
|
||||
if(rule->getConnection() != NULL)
|
||||
{
|
||||
PacketData data;
|
||||
data.goal = goal;
|
||||
data.progress = progress;
|
||||
void CompleteAllRuleDefinition::updateStatus(GameRule* rule) {
|
||||
int goal = 0;
|
||||
int progress = 0;
|
||||
for (AUTO_VAR(it, rule->m_parameters.begin());
|
||||
it != rule->m_parameters.end(); ++it) {
|
||||
if (it->second.isPointer) {
|
||||
goal += it->second.gr->getGameRuleDefinition()->getGoal();
|
||||
progress += it->second.gr->getGameRuleDefinition()->getProgress(
|
||||
it->second.gr);
|
||||
}
|
||||
}
|
||||
if (rule->getConnection() != NULL) {
|
||||
PacketData data;
|
||||
data.goal = goal;
|
||||
data.progress = progress;
|
||||
|
||||
int icon = -1;
|
||||
int auxValue = 0;
|
||||
|
||||
if(m_lastRuleStatusChanged != NULL)
|
||||
{
|
||||
icon = m_lastRuleStatusChanged->getIcon();
|
||||
auxValue = m_lastRuleStatusChanged->getAuxValue();
|
||||
m_lastRuleStatusChanged = NULL;
|
||||
}
|
||||
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);
|
||||
int icon = -1;
|
||||
int auxValue = 0;
|
||||
|
||||
if (m_lastRuleStatusChanged != NULL) {
|
||||
icon = m_lastRuleStatusChanged->getIcon();
|
||||
auxValue = m_lastRuleStatusChanged->getAuxValue();
|
||||
m_lastRuleStatusChanged = NULL;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
std::wstring CompleteAllRuleDefinition::generateDescriptionString(const std::wstring &description, void *data, int dataLength)
|
||||
{
|
||||
PacketData *values = (PacketData *)data;
|
||||
std::wstring newDesc = description;
|
||||
newDesc = replaceAll(newDesc,L"{*progress*}",_toString<int>(values->progress));
|
||||
newDesc = replaceAll(newDesc,L"{*goal*}",_toString<int>(values->goal));
|
||||
return newDesc;
|
||||
std::wstring CompleteAllRuleDefinition::generateDescriptionString(
|
||||
const std::wstring& description, void* data, int dataLength) {
|
||||
PacketData* values = (PacketData*)data;
|
||||
std::wstring newDesc = description;
|
||||
newDesc =
|
||||
replaceAll(newDesc, L"{*progress*}", _toString<int>(values->progress));
|
||||
newDesc = replaceAll(newDesc, L"{*goal*}", _toString<int>(values->goal));
|
||||
return newDesc;
|
||||
}
|
||||
|
|
@ -2,25 +2,27 @@
|
|||
|
||||
#include "CompoundGameRuleDefinition.h"
|
||||
|
||||
class CompleteAllRuleDefinition : public CompoundGameRuleDefinition
|
||||
{
|
||||
class CompleteAllRuleDefinition : public CompoundGameRuleDefinition {
|
||||
private:
|
||||
typedef struct _packetData
|
||||
{
|
||||
int goal;
|
||||
int progress;
|
||||
} PacketData;
|
||||
typedef struct _packetData {
|
||||
int goal;
|
||||
int progress;
|
||||
} PacketData;
|
||||
|
||||
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 onCollectItem(GameRule *rule, std::shared_ptr<ItemInstance> item);
|
||||
virtual bool onUseTile(GameRule* rule, int tileId, int x, int y, int z);
|
||||
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:
|
||||
void updateStatus(GameRule *rule);
|
||||
void updateStatus(GameRule* rule);
|
||||
};
|
||||
|
|
@ -4,115 +4,105 @@
|
|||
#include "CompoundGameRuleDefinition.h"
|
||||
#include "ConsoleGameRules.h"
|
||||
|
||||
CompoundGameRuleDefinition::CompoundGameRuleDefinition()
|
||||
{
|
||||
m_lastRuleStatusChanged = NULL;
|
||||
CompoundGameRuleDefinition::CompoundGameRuleDefinition() {
|
||||
m_lastRuleStatusChanged = NULL;
|
||||
}
|
||||
|
||||
CompoundGameRuleDefinition::~CompoundGameRuleDefinition()
|
||||
{
|
||||
for(AUTO_VAR(it, m_children.begin()); it != m_children.end(); ++it)
|
||||
{
|
||||
delete (*it);
|
||||
}
|
||||
CompoundGameRuleDefinition::~CompoundGameRuleDefinition() {
|
||||
for (AUTO_VAR(it, m_children.begin()); it != m_children.end(); ++it) {
|
||||
delete (*it);
|
||||
}
|
||||
}
|
||||
|
||||
void CompoundGameRuleDefinition::getChildren(std::vector<GameRuleDefinition *> *children)
|
||||
{
|
||||
GameRuleDefinition::getChildren(children);
|
||||
for (AUTO_VAR(it, m_children.begin()); it != m_children.end(); it++)
|
||||
children->push_back(*it);
|
||||
void CompoundGameRuleDefinition::getChildren(
|
||||
std::vector<GameRuleDefinition*>* children) {
|
||||
GameRuleDefinition::getChildren(children);
|
||||
for (AUTO_VAR(it, m_children.begin()); it != m_children.end(); it++)
|
||||
children->push_back(*it);
|
||||
}
|
||||
|
||||
GameRuleDefinition *CompoundGameRuleDefinition::addChild(ConsoleGameRules::EGameRuleType ruleType)
|
||||
{
|
||||
GameRuleDefinition *rule = NULL;
|
||||
if(ruleType == ConsoleGameRules::eGameRuleType_CompleteAllRule)
|
||||
{
|
||||
rule = new CompleteAllRuleDefinition();
|
||||
}
|
||||
else if(ruleType == ConsoleGameRules::eGameRuleType_CollectItemRule)
|
||||
{
|
||||
rule = new CollectItemRuleDefinition();
|
||||
}
|
||||
else if(ruleType == ConsoleGameRules::eGameRuleType_UseTileRule)
|
||||
{
|
||||
rule = new UseTileRuleDefinition();
|
||||
}
|
||||
else if(ruleType == ConsoleGameRules::eGameRuleType_UpdatePlayerRule)
|
||||
{
|
||||
rule = new UpdatePlayerRuleDefinition();
|
||||
}
|
||||
else
|
||||
{
|
||||
GameRuleDefinition* CompoundGameRuleDefinition::addChild(
|
||||
ConsoleGameRules::EGameRuleType ruleType) {
|
||||
GameRuleDefinition* rule = NULL;
|
||||
if (ruleType == ConsoleGameRules::eGameRuleType_CompleteAllRule) {
|
||||
rule = new CompleteAllRuleDefinition();
|
||||
} else if (ruleType == ConsoleGameRules::eGameRuleType_CollectItemRule) {
|
||||
rule = new CollectItemRuleDefinition();
|
||||
} else if (ruleType == ConsoleGameRules::eGameRuleType_UseTileRule) {
|
||||
rule = new UseTileRuleDefinition();
|
||||
} else if (ruleType == ConsoleGameRules::eGameRuleType_UpdatePlayerRule) {
|
||||
rule = new UpdatePlayerRuleDefinition();
|
||||
} else {
|
||||
#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
|
||||
}
|
||||
if(rule != NULL) m_children.push_back(rule);
|
||||
return rule;
|
||||
}
|
||||
if (rule != NULL) m_children.push_back(rule);
|
||||
return rule;
|
||||
}
|
||||
|
||||
void CompoundGameRuleDefinition::populateGameRule(GameRulesInstance::EGameRulesInstanceType type, GameRule *rule)
|
||||
{
|
||||
GameRule *newRule = NULL;
|
||||
int i = 0;
|
||||
for(AUTO_VAR(it, m_children.begin()); it != m_children.end(); ++it)
|
||||
{
|
||||
newRule = new GameRule(*it, rule->getConnection() );
|
||||
(*it)->populateGameRule(type,newRule);
|
||||
void CompoundGameRuleDefinition::populateGameRule(
|
||||
GameRulesInstance::EGameRulesInstanceType type, GameRule* rule) {
|
||||
GameRule* newRule = NULL;
|
||||
int i = 0;
|
||||
for (AUTO_VAR(it, m_children.begin()); it != m_children.end(); ++it) {
|
||||
newRule = new GameRule(*it, rule->getConnection());
|
||||
(*it)->populateGameRule(type, newRule);
|
||||
|
||||
GameRule::ValueType value;
|
||||
value.gr = newRule;
|
||||
value.isPointer = true;
|
||||
GameRule::ValueType value;
|
||||
value.gr = newRule;
|
||||
value.isPointer = true;
|
||||
|
||||
// Somehow add the newRule to the current rule
|
||||
rule->setParameter(L"rule" + _toString<int>(i),value);
|
||||
++i;
|
||||
}
|
||||
GameRuleDefinition::populateGameRule(type, rule);
|
||||
// Somehow add the newRule to the current rule
|
||||
rule->setParameter(L"rule" + _toString<int>(i), value);
|
||||
++i;
|
||||
}
|
||||
GameRuleDefinition::populateGameRule(type, rule);
|
||||
}
|
||||
|
||||
bool CompoundGameRuleDefinition::onUseTile(GameRule *rule, int tileId, int x, int y, int z)
|
||||
{
|
||||
bool statusChanged = false;
|
||||
for(AUTO_VAR(it, rule->m_parameters.begin()); it != rule->m_parameters.end(); ++it)
|
||||
{
|
||||
if(it->second.isPointer)
|
||||
{
|
||||
bool changed = it->second.gr->getGameRuleDefinition()->onUseTile(it->second.gr,tileId,x,y,z);
|
||||
if(!statusChanged && changed)
|
||||
{
|
||||
m_lastRuleStatusChanged = it->second.gr->getGameRuleDefinition();
|
||||
statusChanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return statusChanged;
|
||||
bool CompoundGameRuleDefinition::onUseTile(GameRule* rule, int tileId, int x,
|
||||
int y, int z) {
|
||||
bool statusChanged = false;
|
||||
for (AUTO_VAR(it, rule->m_parameters.begin());
|
||||
it != rule->m_parameters.end(); ++it) {
|
||||
if (it->second.isPointer) {
|
||||
bool changed = it->second.gr->getGameRuleDefinition()->onUseTile(
|
||||
it->second.gr, tileId, x, y, z);
|
||||
if (!statusChanged && changed) {
|
||||
m_lastRuleStatusChanged =
|
||||
it->second.gr->getGameRuleDefinition();
|
||||
statusChanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return statusChanged;
|
||||
}
|
||||
|
||||
bool CompoundGameRuleDefinition::onCollectItem(GameRule *rule, std::shared_ptr<ItemInstance> item)
|
||||
{
|
||||
bool statusChanged = false;
|
||||
for(AUTO_VAR(it, rule->m_parameters.begin()); it != rule->m_parameters.end(); ++it)
|
||||
{
|
||||
if(it->second.isPointer)
|
||||
{
|
||||
bool changed = it->second.gr->getGameRuleDefinition()->onCollectItem(it->second.gr,item);
|
||||
if(!statusChanged && changed)
|
||||
{
|
||||
m_lastRuleStatusChanged = it->second.gr->getGameRuleDefinition();
|
||||
statusChanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return statusChanged;
|
||||
bool CompoundGameRuleDefinition::onCollectItem(
|
||||
GameRule* rule, std::shared_ptr<ItemInstance> item) {
|
||||
bool statusChanged = false;
|
||||
for (AUTO_VAR(it, rule->m_parameters.begin());
|
||||
it != rule->m_parameters.end(); ++it) {
|
||||
if (it->second.isPointer) {
|
||||
bool changed =
|
||||
it->second.gr->getGameRuleDefinition()->onCollectItem(
|
||||
it->second.gr, item);
|
||||
if (!statusChanged && changed) {
|
||||
m_lastRuleStatusChanged =
|
||||
it->second.gr->getGameRuleDefinition();
|
||||
statusChanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return statusChanged;
|
||||
}
|
||||
|
||||
void CompoundGameRuleDefinition::postProcessPlayer(std::shared_ptr<Player> player)
|
||||
{
|
||||
for(AUTO_VAR(it, m_children.begin()); it != m_children.end(); ++it)
|
||||
{
|
||||
(*it)->postProcessPlayer(player);
|
||||
}
|
||||
void CompoundGameRuleDefinition::postProcessPlayer(
|
||||
std::shared_ptr<Player> player) {
|
||||
for (AUTO_VAR(it, m_children.begin()); it != m_children.end(); ++it) {
|
||||
(*it)->postProcessPlayer(player);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,22 +2,26 @@
|
|||
|
||||
#include "GameRuleDefinition.h"
|
||||
|
||||
class CompoundGameRuleDefinition : public GameRuleDefinition
|
||||
{
|
||||
class CompoundGameRuleDefinition : public GameRuleDefinition {
|
||||
protected:
|
||||
std::vector<GameRuleDefinition *> m_children;
|
||||
std::vector<GameRuleDefinition*> m_children;
|
||||
|
||||
protected:
|
||||
GameRuleDefinition *m_lastRuleStatusChanged;
|
||||
GameRuleDefinition* m_lastRuleStatusChanged;
|
||||
|
||||
public:
|
||||
CompoundGameRuleDefinition();
|
||||
virtual ~CompoundGameRuleDefinition();
|
||||
CompoundGameRuleDefinition();
|
||||
virtual ~CompoundGameRuleDefinition();
|
||||
|
||||
virtual void getChildren(std::vector<GameRuleDefinition *> *children);
|
||||
virtual GameRuleDefinition *addChild(ConsoleGameRules::EGameRuleType ruleType);
|
||||
virtual void getChildren(std::vector<GameRuleDefinition*>* children);
|
||||
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 onCollectItem(GameRule *rule, std::shared_ptr<ItemInstance> item);
|
||||
virtual void postProcessPlayer(std::shared_ptr<Player> player);
|
||||
virtual bool onUseTile(GameRule* rule, int tileId, int x, int y, int z);
|
||||
virtual bool onCollectItem(GameRule* rule,
|
||||
std::shared_ptr<ItemInstance> item);
|
||||
virtual void postProcessPlayer(std::shared_ptr<Player> player);
|
||||
};
|
||||
|
|
@ -1,120 +1,118 @@
|
|||
#pragma once
|
||||
|
||||
//#include "
|
||||
// #include "
|
||||
|
||||
class ConsoleGameRules
|
||||
{
|
||||
class ConsoleGameRules {
|
||||
public:
|
||||
enum EGameRuleType
|
||||
{
|
||||
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
|
||||
enum EGameRuleType {
|
||||
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_LevelGenerationOptions,
|
||||
eGameRuleType_ApplySchematic,
|
||||
eGameRuleType_GenerateStructure,
|
||||
eGameRuleType_GenerateBox,
|
||||
eGameRuleType_PlaceBlock,
|
||||
eGameRuleType_PlaceContainer,
|
||||
eGameRuleType_PlaceSpawner,
|
||||
eGameRuleType_BiomeOverride,
|
||||
eGameRuleType_StartFeature,
|
||||
eGameRuleType_LevelGenerationOptions,
|
||||
eGameRuleType_ApplySchematic,
|
||||
eGameRuleType_GenerateStructure,
|
||||
eGameRuleType_GenerateBox,
|
||||
eGameRuleType_PlaceBlock,
|
||||
eGameRuleType_PlaceContainer,
|
||||
eGameRuleType_PlaceSpawner,
|
||||
eGameRuleType_BiomeOverride,
|
||||
eGameRuleType_StartFeature,
|
||||
|
||||
eGameRuleType_AddItem,
|
||||
eGameRuleType_AddEnchantment,
|
||||
eGameRuleType_AddItem,
|
||||
eGameRuleType_AddEnchantment,
|
||||
|
||||
eGameRuleType_LevelRules,
|
||||
eGameRuleType_NamedArea,
|
||||
eGameRuleType_LevelRules,
|
||||
eGameRuleType_NamedArea,
|
||||
|
||||
eGameRuleType_UseTileRule,
|
||||
eGameRuleType_CollectItemRule,
|
||||
eGameRuleType_CompleteAllRule,
|
||||
eGameRuleType_UpdatePlayerRule,
|
||||
eGameRuleType_UseTileRule,
|
||||
eGameRuleType_CollectItemRule,
|
||||
eGameRuleType_CompleteAllRule,
|
||||
eGameRuleType_UpdatePlayerRule,
|
||||
|
||||
eGameRuleType_Count
|
||||
};
|
||||
eGameRuleType_Count
|
||||
};
|
||||
|
||||
enum EGameRuleAttr
|
||||
{
|
||||
eGameRuleAttr_Invalid = -1,
|
||||
enum EGameRuleAttr {
|
||||
eGameRuleAttr_Invalid = -1,
|
||||
|
||||
eGameRuleAttr_descriptionName = 0,
|
||||
eGameRuleAttr_promptName,
|
||||
eGameRuleAttr_dataTag,
|
||||
eGameRuleAttr_descriptionName = 0,
|
||||
eGameRuleAttr_promptName,
|
||||
eGameRuleAttr_dataTag,
|
||||
|
||||
eGameRuleAttr_enchantmentId,
|
||||
eGameRuleAttr_enchantmentLevel,
|
||||
eGameRuleAttr_enchantmentId,
|
||||
eGameRuleAttr_enchantmentLevel,
|
||||
|
||||
eGameRuleAttr_itemId,
|
||||
eGameRuleAttr_quantity,
|
||||
eGameRuleAttr_auxValue,
|
||||
eGameRuleAttr_slot,
|
||||
eGameRuleAttr_itemId,
|
||||
eGameRuleAttr_quantity,
|
||||
eGameRuleAttr_auxValue,
|
||||
eGameRuleAttr_slot,
|
||||
|
||||
eGameRuleAttr_name,
|
||||
eGameRuleAttr_name,
|
||||
|
||||
eGameRuleAttr_food,
|
||||
eGameRuleAttr_health,
|
||||
eGameRuleAttr_food,
|
||||
eGameRuleAttr_health,
|
||||
|
||||
eGameRuleAttr_tileId,
|
||||
eGameRuleAttr_useCoords,
|
||||
eGameRuleAttr_tileId,
|
||||
eGameRuleAttr_useCoords,
|
||||
|
||||
eGameRuleAttr_seed,
|
||||
eGameRuleAttr_flatworld,
|
||||
eGameRuleAttr_seed,
|
||||
eGameRuleAttr_flatworld,
|
||||
|
||||
eGameRuleAttr_filename,
|
||||
eGameRuleAttr_rot,
|
||||
eGameRuleAttr_filename,
|
||||
eGameRuleAttr_rot,
|
||||
|
||||
eGameRuleAttr_data,
|
||||
eGameRuleAttr_block,
|
||||
eGameRuleAttr_entity,
|
||||
eGameRuleAttr_data,
|
||||
eGameRuleAttr_block,
|
||||
eGameRuleAttr_entity,
|
||||
|
||||
eGameRuleAttr_facing,
|
||||
eGameRuleAttr_facing,
|
||||
|
||||
eGameRuleAttr_edgeTile,
|
||||
eGameRuleAttr_fillTile,
|
||||
eGameRuleAttr_skipAir,
|
||||
eGameRuleAttr_edgeTile,
|
||||
eGameRuleAttr_fillTile,
|
||||
eGameRuleAttr_skipAir,
|
||||
|
||||
eGameRuleAttr_x,
|
||||
eGameRuleAttr_x0,
|
||||
eGameRuleAttr_x1,
|
||||
|
||||
eGameRuleAttr_y,
|
||||
eGameRuleAttr_y0,
|
||||
eGameRuleAttr_y1,
|
||||
eGameRuleAttr_x,
|
||||
eGameRuleAttr_x0,
|
||||
eGameRuleAttr_x1,
|
||||
|
||||
eGameRuleAttr_z,
|
||||
eGameRuleAttr_z0,
|
||||
eGameRuleAttr_z1,
|
||||
eGameRuleAttr_y,
|
||||
eGameRuleAttr_y0,
|
||||
eGameRuleAttr_y1,
|
||||
|
||||
eGameRuleAttr_chunkX,
|
||||
eGameRuleAttr_chunkZ,
|
||||
eGameRuleAttr_z,
|
||||
eGameRuleAttr_z0,
|
||||
eGameRuleAttr_z1,
|
||||
|
||||
eGameRuleAttr_yRot,
|
||||
eGameRuleAttr_chunkX,
|
||||
eGameRuleAttr_chunkZ,
|
||||
|
||||
eGameRuleAttr_spawnX,
|
||||
eGameRuleAttr_spawnY,
|
||||
eGameRuleAttr_spawnZ,
|
||||
eGameRuleAttr_yRot,
|
||||
|
||||
eGameRuleAttr_orientation,
|
||||
eGameRuleAttr_dimension,
|
||||
eGameRuleAttr_spawnX,
|
||||
eGameRuleAttr_spawnY,
|
||||
eGameRuleAttr_spawnZ,
|
||||
|
||||
eGameRuleAttr_topTileId,
|
||||
eGameRuleAttr_biomeId,
|
||||
eGameRuleAttr_orientation,
|
||||
eGameRuleAttr_dimension,
|
||||
|
||||
eGameRuleAttr_feature,
|
||||
eGameRuleAttr_topTileId,
|
||||
eGameRuleAttr_biomeId,
|
||||
|
||||
eGameRuleAttr_Count
|
||||
};
|
||||
eGameRuleAttr_feature,
|
||||
|
||||
static void write(DataOutputStream *dos, ConsoleGameRules::EGameRuleType eType)
|
||||
{
|
||||
dos->writeInt(eType);
|
||||
}
|
||||
eGameRuleAttr_Count
|
||||
};
|
||||
|
||||
static void write(DataOutputStream *dos, ConsoleGameRules::EGameRuleAttr eAttr)
|
||||
{
|
||||
dos->writeInt(static_cast<int>(eGameRuleType_Count) +
|
||||
static_cast<int>(eAttr));
|
||||
}
|
||||
static void write(DataOutputStream* dos,
|
||||
ConsoleGameRules::EGameRuleType eType) {
|
||||
dos->writeInt(eType);
|
||||
}
|
||||
|
||||
static void write(DataOutputStream* dos,
|
||||
ConsoleGameRules::EGameRuleAttr eAttr) {
|
||||
dos->writeInt(static_cast<int>(eGameRuleType_Count) +
|
||||
static_cast<int>(eAttr));
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -7,177 +7,155 @@
|
|||
#include "../../Minecraft.World/Util/StringHelpers.h"
|
||||
#include "../../Minecraft.World/Headers/net.minecraft.h"
|
||||
|
||||
ConsoleGenerateStructure::ConsoleGenerateStructure() : StructurePiece(0)
|
||||
{
|
||||
m_x = m_y = m_z = 0;
|
||||
boundingBox = NULL;
|
||||
orientation = Direction::NORTH;
|
||||
m_dimension = 0;
|
||||
ConsoleGenerateStructure::ConsoleGenerateStructure() : StructurePiece(0) {
|
||||
m_x = m_y = m_z = 0;
|
||||
boundingBox = NULL;
|
||||
orientation = Direction::NORTH;
|
||||
m_dimension = 0;
|
||||
}
|
||||
|
||||
void ConsoleGenerateStructure::getChildren(std::vector<GameRuleDefinition *> *children)
|
||||
{
|
||||
GameRuleDefinition::getChildren(children);
|
||||
|
||||
for(AUTO_VAR(it, m_actions.begin()); it != m_actions.end(); it++)
|
||||
children->push_back( *it );
|
||||
void ConsoleGenerateStructure::getChildren(
|
||||
std::vector<GameRuleDefinition*>* children) {
|
||||
GameRuleDefinition::getChildren(children);
|
||||
|
||||
for (AUTO_VAR(it, m_actions.begin()); it != m_actions.end(); it++)
|
||||
children->push_back(*it);
|
||||
}
|
||||
|
||||
GameRuleDefinition *ConsoleGenerateStructure::addChild(ConsoleGameRules::EGameRuleType ruleType)
|
||||
{
|
||||
GameRuleDefinition *rule = NULL;
|
||||
if(ruleType == ConsoleGameRules::eGameRuleType_GenerateBox)
|
||||
{
|
||||
rule = new XboxStructureActionGenerateBox();
|
||||
m_actions.push_back((XboxStructureActionGenerateBox *)rule);
|
||||
}
|
||||
else if(ruleType == ConsoleGameRules::eGameRuleType_PlaceBlock)
|
||||
{
|
||||
rule = new XboxStructureActionPlaceBlock();
|
||||
m_actions.push_back((XboxStructureActionPlaceBlock *)rule);
|
||||
}
|
||||
else if(ruleType == ConsoleGameRules::eGameRuleType_PlaceContainer)
|
||||
{
|
||||
rule = new XboxStructureActionPlaceContainer();
|
||||
m_actions.push_back((XboxStructureActionPlaceContainer *)rule);
|
||||
}
|
||||
else if(ruleType == ConsoleGameRules::eGameRuleType_PlaceSpawner)
|
||||
{
|
||||
rule = new XboxStructureActionPlaceSpawner();
|
||||
m_actions.push_back((XboxStructureActionPlaceSpawner *)rule);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameRuleDefinition* ConsoleGenerateStructure::addChild(
|
||||
ConsoleGameRules::EGameRuleType ruleType) {
|
||||
GameRuleDefinition* rule = NULL;
|
||||
if (ruleType == ConsoleGameRules::eGameRuleType_GenerateBox) {
|
||||
rule = new XboxStructureActionGenerateBox();
|
||||
m_actions.push_back((XboxStructureActionGenerateBox*)rule);
|
||||
} else if (ruleType == ConsoleGameRules::eGameRuleType_PlaceBlock) {
|
||||
rule = new XboxStructureActionPlaceBlock();
|
||||
m_actions.push_back((XboxStructureActionPlaceBlock*)rule);
|
||||
} else if (ruleType == ConsoleGameRules::eGameRuleType_PlaceContainer) {
|
||||
rule = new XboxStructureActionPlaceContainer();
|
||||
m_actions.push_back((XboxStructureActionPlaceContainer*)rule);
|
||||
} else if (ruleType == ConsoleGameRules::eGameRuleType_PlaceSpawner) {
|
||||
rule = new XboxStructureActionPlaceSpawner();
|
||||
m_actions.push_back((XboxStructureActionPlaceSpawner*)rule);
|
||||
} else {
|
||||
#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
|
||||
}
|
||||
return rule;
|
||||
}
|
||||
return rule;
|
||||
}
|
||||
|
||||
void ConsoleGenerateStructure::writeAttributes(DataOutputStream *dos, unsigned int numAttrs)
|
||||
{
|
||||
GameRuleDefinition::writeAttributes(dos, numAttrs + 5);
|
||||
void ConsoleGenerateStructure::writeAttributes(DataOutputStream* dos,
|
||||
unsigned int numAttrs) {
|
||||
GameRuleDefinition::writeAttributes(dos, numAttrs + 5);
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x);
|
||||
dos->writeUTF(_toString(m_x));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y);
|
||||
dos->writeUTF(_toString(m_y));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z);
|
||||
dos->writeUTF(_toString(m_z));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x);
|
||||
dos->writeUTF(_toString(m_x));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y);
|
||||
dos->writeUTF(_toString(m_y));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z);
|
||||
dos->writeUTF(_toString(m_z));
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_orientation);
|
||||
dos->writeUTF(_toString(orientation));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_dimension);
|
||||
dos->writeUTF(_toString(m_dimension));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_orientation);
|
||||
dos->writeUTF(_toString(orientation));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_dimension);
|
||||
dos->writeUTF(_toString(m_dimension));
|
||||
}
|
||||
|
||||
void ConsoleGenerateStructure::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue)
|
||||
{
|
||||
if(attributeName.compare(L"x") == 0)
|
||||
{
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_x = value;
|
||||
app.DebugPrintf("ConsoleGenerateStructure: Adding parameter x=%d\n",m_x);
|
||||
}
|
||||
else if(attributeName.compare(L"y") == 0)
|
||||
{
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_y = value;
|
||||
app.DebugPrintf("ConsoleGenerateStructure: Adding parameter y=%d\n",m_y);
|
||||
}
|
||||
else if(attributeName.compare(L"z") == 0)
|
||||
{
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_z = value;
|
||||
app.DebugPrintf("ConsoleGenerateStructure: Adding parameter z=%d\n",m_z);
|
||||
}
|
||||
else if(attributeName.compare(L"orientation") == 0)
|
||||
{
|
||||
int value = _fromString<int>(attributeValue);
|
||||
orientation = value;
|
||||
app.DebugPrintf("ConsoleGenerateStructure: Adding parameter orientation=%d\n",orientation);
|
||||
}
|
||||
else if(attributeName.compare(L"dim") == 0)
|
||||
{
|
||||
m_dimension = _fromString<int>(attributeValue);
|
||||
if(m_dimension > 1 || m_dimension < -1) m_dimension = 0;
|
||||
app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter dimension=%d\n",m_dimension);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameRuleDefinition::addAttribute(attributeName, attributeValue);
|
||||
}
|
||||
void ConsoleGenerateStructure::addAttribute(
|
||||
const std::wstring& attributeName, const std::wstring& attributeValue) {
|
||||
if (attributeName.compare(L"x") == 0) {
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_x = value;
|
||||
app.DebugPrintf("ConsoleGenerateStructure: Adding parameter x=%d\n",
|
||||
m_x);
|
||||
} else if (attributeName.compare(L"y") == 0) {
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_y = value;
|
||||
app.DebugPrintf("ConsoleGenerateStructure: Adding parameter y=%d\n",
|
||||
m_y);
|
||||
} else if (attributeName.compare(L"z") == 0) {
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_z = value;
|
||||
app.DebugPrintf("ConsoleGenerateStructure: Adding parameter z=%d\n",
|
||||
m_z);
|
||||
} else if (attributeName.compare(L"orientation") == 0) {
|
||||
int value = _fromString<int>(attributeValue);
|
||||
orientation = value;
|
||||
app.DebugPrintf(
|
||||
"ConsoleGenerateStructure: Adding parameter orientation=%d\n",
|
||||
orientation);
|
||||
} else if (attributeName.compare(L"dim") == 0) {
|
||||
m_dimension = _fromString<int>(attributeValue);
|
||||
if (m_dimension > 1 || m_dimension < -1) m_dimension = 0;
|
||||
app.DebugPrintf(
|
||||
"ApplySchematicRuleDefinition: Adding parameter dimension=%d\n",
|
||||
m_dimension);
|
||||
} else {
|
||||
GameRuleDefinition::addAttribute(attributeName, attributeValue);
|
||||
}
|
||||
}
|
||||
|
||||
BoundingBox* ConsoleGenerateStructure::getBoundingBox()
|
||||
{
|
||||
if(boundingBox == NULL)
|
||||
{
|
||||
// Find the max bounds
|
||||
int maxX, maxY, maxZ;
|
||||
maxX = maxY = maxZ = 1;
|
||||
for(AUTO_VAR(it, m_actions.begin()); it != m_actions.end(); ++it)
|
||||
{
|
||||
ConsoleGenerateStructureAction *action = *it;
|
||||
maxX = std::max(maxX,action->getEndX());
|
||||
maxY = std::max(maxY,action->getEndY());
|
||||
maxZ = std::max(maxZ,action->getEndZ());
|
||||
}
|
||||
|
||||
boundingBox = new BoundingBox(m_x, m_y, m_z, m_x + maxX, m_y + maxY, m_z + maxZ);
|
||||
}
|
||||
return boundingBox;
|
||||
BoundingBox* ConsoleGenerateStructure::getBoundingBox() {
|
||||
if (boundingBox == NULL) {
|
||||
// Find the max bounds
|
||||
int maxX, maxY, maxZ;
|
||||
maxX = maxY = maxZ = 1;
|
||||
for (AUTO_VAR(it, m_actions.begin()); it != m_actions.end(); ++it) {
|
||||
ConsoleGenerateStructureAction* action = *it;
|
||||
maxX = std::max(maxX, action->getEndX());
|
||||
maxY = std::max(maxY, action->getEndY());
|
||||
maxZ = std::max(maxZ, action->getEndZ());
|
||||
}
|
||||
|
||||
boundingBox =
|
||||
new BoundingBox(m_x, m_y, m_z, m_x + maxX, m_y + maxY, m_z + maxZ);
|
||||
}
|
||||
return boundingBox;
|
||||
}
|
||||
|
||||
bool ConsoleGenerateStructure::postProcess(Level *level, Random *random, BoundingBox *chunkBB)
|
||||
{
|
||||
if(level->dimension->id != m_dimension) return false;
|
||||
bool ConsoleGenerateStructure::postProcess(Level* level, Random* random,
|
||||
BoundingBox* chunkBB) {
|
||||
if (level->dimension->id != m_dimension) return false;
|
||||
|
||||
for(AUTO_VAR(it, m_actions.begin()); it != m_actions.end(); ++it)
|
||||
{
|
||||
ConsoleGenerateStructureAction *action = *it;
|
||||
|
||||
switch(action->getActionType())
|
||||
{
|
||||
case ConsoleGameRules::eGameRuleType_GenerateBox:
|
||||
{
|
||||
XboxStructureActionGenerateBox *genBox = (XboxStructureActionGenerateBox *)action;
|
||||
genBox->generateBoxInLevel(this,level,chunkBB);
|
||||
}
|
||||
break;
|
||||
case ConsoleGameRules::eGameRuleType_PlaceBlock:
|
||||
{
|
||||
XboxStructureActionPlaceBlock *pPlaceBlock = (XboxStructureActionPlaceBlock *)action;
|
||||
pPlaceBlock->placeBlockInLevel(this,level,chunkBB);
|
||||
}
|
||||
break;
|
||||
case ConsoleGameRules::eGameRuleType_PlaceContainer:
|
||||
{
|
||||
XboxStructureActionPlaceContainer *pPlaceContainer = (XboxStructureActionPlaceContainer *)action;
|
||||
pPlaceContainer->placeContainerInLevel(this,level,chunkBB);
|
||||
}
|
||||
break;
|
||||
case ConsoleGameRules::eGameRuleType_PlaceSpawner:
|
||||
{
|
||||
XboxStructureActionPlaceSpawner *pPlaceSpawner = (XboxStructureActionPlaceSpawner *)action;
|
||||
pPlaceSpawner->placeSpawnerInLevel(this,level,chunkBB);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
};
|
||||
}
|
||||
for (AUTO_VAR(it, m_actions.begin()); it != m_actions.end(); ++it) {
|
||||
ConsoleGenerateStructureAction* action = *it;
|
||||
|
||||
return false;
|
||||
switch (action->getActionType()) {
|
||||
case ConsoleGameRules::eGameRuleType_GenerateBox: {
|
||||
XboxStructureActionGenerateBox* genBox =
|
||||
(XboxStructureActionGenerateBox*)action;
|
||||
genBox->generateBoxInLevel(this, level, chunkBB);
|
||||
} break;
|
||||
case ConsoleGameRules::eGameRuleType_PlaceBlock: {
|
||||
XboxStructureActionPlaceBlock* pPlaceBlock =
|
||||
(XboxStructureActionPlaceBlock*)action;
|
||||
pPlaceBlock->placeBlockInLevel(this, level, chunkBB);
|
||||
} break;
|
||||
case ConsoleGameRules::eGameRuleType_PlaceContainer: {
|
||||
XboxStructureActionPlaceContainer* pPlaceContainer =
|
||||
(XboxStructureActionPlaceContainer*)action;
|
||||
pPlaceContainer->placeContainerInLevel(this, level, chunkBB);
|
||||
} break;
|
||||
case ConsoleGameRules::eGameRuleType_PlaceSpawner: {
|
||||
XboxStructureActionPlaceSpawner* pPlaceSpawner =
|
||||
(XboxStructureActionPlaceSpawner*)action;
|
||||
pPlaceSpawner->placeSpawnerInLevel(this, level, chunkBB);
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ConsoleGenerateStructure::checkIntersects(int x0, int y0, int z0, int x1, int y1, int z1)
|
||||
{
|
||||
return getBoundingBox()->intersects(x0,y0,z0,x1,y1,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);
|
||||
}
|
||||
|
||||
int ConsoleGenerateStructure::getMinY()
|
||||
{
|
||||
return getBoundingBox()->y0;
|
||||
}
|
||||
int ConsoleGenerateStructure::getMinY() { return getBoundingBox()->y0; }
|
||||
|
|
|
|||
|
|
@ -9,30 +9,37 @@ class ConsoleGenerateStructureAction;
|
|||
class XboxStructureActionPlaceContainer;
|
||||
class GRFObject;
|
||||
|
||||
class ConsoleGenerateStructure : public GameRuleDefinition, public StructurePiece
|
||||
{
|
||||
class ConsoleGenerateStructure : public GameRuleDefinition,
|
||||
public StructurePiece {
|
||||
private:
|
||||
int m_x, m_y, m_z;
|
||||
std::vector<ConsoleGenerateStructureAction *> m_actions;
|
||||
int m_dimension;
|
||||
public:
|
||||
ConsoleGenerateStructure();
|
||||
int m_x, m_y, m_z;
|
||||
std::vector<ConsoleGenerateStructureAction*> m_actions;
|
||||
int m_dimension;
|
||||
|
||||
virtual ConsoleGameRules::EGameRuleType getActionType() { return ConsoleGameRules::eGameRuleType_GenerateStructure; }
|
||||
public:
|
||||
ConsoleGenerateStructure();
|
||||
|
||||
virtual void getChildren(std::vector<GameRuleDefinition *> *children);
|
||||
virtual GameRuleDefinition *addChild(ConsoleGameRules::EGameRuleType ruleType);
|
||||
|
||||
virtual void writeAttributes(DataOutputStream *dos, unsigned int numAttrs);
|
||||
virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue);
|
||||
virtual ConsoleGameRules::EGameRuleType getActionType() {
|
||||
return ConsoleGameRules::eGameRuleType_GenerateStructure;
|
||||
}
|
||||
|
||||
// StructurePiece
|
||||
virtual BoundingBox *getBoundingBox();
|
||||
virtual bool postProcess(Level *level, Random *random, BoundingBox *chunkBB);
|
||||
virtual void getChildren(std::vector<GameRuleDefinition*>* children);
|
||||
virtual GameRuleDefinition* addChild(
|
||||
ConsoleGameRules::EGameRuleType ruleType);
|
||||
|
||||
void createContainer(XboxStructureActionPlaceContainer *action, Level *level, BoundingBox *chunkBB);
|
||||
virtual void writeAttributes(DataOutputStream* dos, unsigned int numAttrs);
|
||||
virtual void addAttribute(const std::wstring& attributeName,
|
||||
const std::wstring& attributeValue);
|
||||
|
||||
bool checkIntersects(int x0, int y0, int z0, int x1, int y1, int z1);
|
||||
// StructurePiece
|
||||
virtual BoundingBox* getBoundingBox();
|
||||
virtual bool postProcess(Level* level, Random* random,
|
||||
BoundingBox* chunkBB);
|
||||
|
||||
virtual int getMinY();
|
||||
void createContainer(XboxStructureActionPlaceContainer* action,
|
||||
Level* level, BoundingBox* chunkBB);
|
||||
|
||||
bool checkIntersects(int x0, int y0, int z0, int x1, int y1, int z1);
|
||||
|
||||
virtual int getMinY();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,10 +2,9 @@
|
|||
|
||||
#include "GameRuleDefinition.h"
|
||||
|
||||
class ConsoleGenerateStructureAction : public GameRuleDefinition
|
||||
{
|
||||
class ConsoleGenerateStructureAction : public GameRuleDefinition {
|
||||
public:
|
||||
virtual int getEndX() = 0;
|
||||
virtual int getEndY() = 0;
|
||||
virtual int getEndZ() = 0;
|
||||
virtual int getEndX() = 0;
|
||||
virtual int getEndY() = 0;
|
||||
virtual int getEndZ() = 0;
|
||||
};
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,5 +1,5 @@
|
|||
#pragma once
|
||||
//using namespace std;
|
||||
// using namespace std;
|
||||
|
||||
#define XBOX_SCHEMATIC_ORIGINAL_VERSION 1
|
||||
#define XBOX_SCHEMATIC_CURRENT_VERSION 2
|
||||
|
|
@ -14,77 +14,95 @@ class LevelChunk;
|
|||
class AABB;
|
||||
class Vec3;
|
||||
|
||||
class ConsoleSchematicFile
|
||||
{
|
||||
class ConsoleSchematicFile {
|
||||
public:
|
||||
enum ESchematicRotation
|
||||
{
|
||||
eSchematicRot_0,
|
||||
eSchematicRot_90,
|
||||
eSchematicRot_180,
|
||||
eSchematicRot_270
|
||||
};
|
||||
enum ESchematicRotation {
|
||||
eSchematicRot_0,
|
||||
eSchematicRot_90,
|
||||
eSchematicRot_180,
|
||||
eSchematicRot_270
|
||||
};
|
||||
|
||||
private:
|
||||
int m_refCount;
|
||||
int m_refCount;
|
||||
|
||||
public:
|
||||
void incrementRefCount() { ++m_refCount; }
|
||||
void decrementRefCount() { --m_refCount; }
|
||||
bool shouldDelete() { return m_refCount <= 0; }
|
||||
void incrementRefCount() { ++m_refCount; }
|
||||
void decrementRefCount() { --m_refCount; }
|
||||
bool shouldDelete() { return m_refCount <= 0; }
|
||||
|
||||
typedef struct _XboxSchematicInitParam
|
||||
{
|
||||
wchar_t name[64];
|
||||
int startX;
|
||||
int startY;
|
||||
int startZ;
|
||||
int endX;
|
||||
int endY;
|
||||
int endZ;
|
||||
bool bSaveMobs;
|
||||
typedef struct _XboxSchematicInitParam {
|
||||
wchar_t name[64];
|
||||
int startX;
|
||||
int startY;
|
||||
int startZ;
|
||||
int endX;
|
||||
int endY;
|
||||
int endZ;
|
||||
bool bSaveMobs;
|
||||
|
||||
Compression::ECompressionTypes compressionType;
|
||||
Compression::ECompressionTypes compressionType;
|
||||
|
||||
_XboxSchematicInitParam() {
|
||||
ZeroMemory(name, 64 * (sizeof(wchar_t)));
|
||||
startX = startY = startZ = endX = endY = endZ = 0;
|
||||
bSaveMobs = false;
|
||||
compressionType = Compression::eCompressionType_None;
|
||||
}
|
||||
} XboxSchematicInitParam;
|
||||
|
||||
_XboxSchematicInitParam()
|
||||
{
|
||||
ZeroMemory(name,64*(sizeof(wchar_t)));
|
||||
startX = startY = startZ = endX = endY = endZ = 0;
|
||||
bSaveMobs = false;
|
||||
compressionType = Compression::eCompressionType_None;
|
||||
}
|
||||
} XboxSchematicInitParam;
|
||||
private:
|
||||
int m_xSize, m_ySize, m_zSize;
|
||||
std::vector<std::shared_ptr<TileEntity> > m_tileEntities;
|
||||
std::vector< std::pair<Vec3 *, CompoundTag *> > m_entities;
|
||||
|
||||
public:
|
||||
byteArray m_data;
|
||||
int m_xSize, m_ySize, m_zSize;
|
||||
std::vector<std::shared_ptr<TileEntity> > m_tileEntities;
|
||||
std::vector<std::pair<Vec3*, CompoundTag*> > m_entities;
|
||||
|
||||
public:
|
||||
ConsoleSchematicFile();
|
||||
~ConsoleSchematicFile();
|
||||
byteArray m_data;
|
||||
|
||||
int getXSize() { return m_xSize; }
|
||||
int getYSize() { return m_ySize; }
|
||||
int getZSize() { return m_zSize; }
|
||||
public:
|
||||
ConsoleSchematicFile();
|
||||
~ConsoleSchematicFile();
|
||||
|
||||
void save(DataOutputStream *dos);
|
||||
void load(DataInputStream *dis);
|
||||
int getXSize() { return m_xSize; }
|
||||
int getYSize() { return m_ySize; }
|
||||
int getZSize() { return m_zSize; }
|
||||
|
||||
__int64 applyBlocksAndData(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);
|
||||
void save(DataOutputStream* dos);
|
||||
void load(DataInputStream* dis);
|
||||
|
||||
__int64 applyBlocksAndData(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:
|
||||
void save_tags(DataOutputStream *dos);
|
||||
void load_tags(DataInputStream *dis);
|
||||
void save_tags(DataOutputStream* dos);
|
||||
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 std::vector<std::shared_ptr<TileEntity> > *getTileEntitiesInRegion(LevelChunk *chunk, int x0, int y0, int z0, int x1, int y1, int z1);
|
||||
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 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 schematicCoordToChunkCoord(AABB *destinationBox, double schematicX, double schematicZ, ESchematicRotation rot, double &chunkX, double &chunkZ);
|
||||
void chunkCoordToSchematicCoord(AABB* destinationBox, int chunkX,
|
||||
int chunkZ, ESchematicRotation rot,
|
||||
int& schematicX, int& schematicZ);
|
||||
void schematicCoordToChunkCoord(AABB* destinationBox, double schematicX,
|
||||
double schematicZ, ESchematicRotation rot,
|
||||
double& chunkX, double& chunkZ);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,97 +1,83 @@
|
|||
#include "../../Minecraft.World/Platform/stdafx.h"
|
||||
#include "ConsoleGameRules.h"
|
||||
|
||||
GameRule::GameRule(GameRuleDefinition *definition, Connection *connection)
|
||||
{
|
||||
m_definition = definition;
|
||||
m_connection = connection;
|
||||
GameRule::GameRule(GameRuleDefinition* definition, Connection* connection) {
|
||||
m_definition = definition;
|
||||
m_connection = connection;
|
||||
}
|
||||
|
||||
GameRule::~GameRule()
|
||||
{
|
||||
for(AUTO_VAR(it, m_parameters.begin()); it != m_parameters.end(); ++it)
|
||||
{
|
||||
if(it->second.isPointer)
|
||||
{
|
||||
delete it->second.gr;
|
||||
}
|
||||
}
|
||||
GameRule::~GameRule() {
|
||||
for (AUTO_VAR(it, m_parameters.begin()); it != m_parameters.end(); ++it) {
|
||||
if (it->second.isPointer) {
|
||||
delete it->second.gr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GameRule::ValueType GameRule::getParameter(const std::wstring ¶meterName)
|
||||
{
|
||||
if(m_parameters.find(parameterName) == m_parameters.end())
|
||||
{
|
||||
GameRule::ValueType GameRule::getParameter(const std::wstring& parameterName) {
|
||||
if (m_parameters.find(parameterName) == m_parameters.end()) {
|
||||
#ifndef _CONTENT_PACKAGE
|
||||
wprintf(L"WARNING: Parameter %ls was not set before being fetched\n", parameterName.c_str());
|
||||
__debugbreak();
|
||||
wprintf(L"WARNING: Parameter %ls was not set before being fetched\n",
|
||||
parameterName.c_str());
|
||||
__debugbreak();
|
||||
#endif
|
||||
}
|
||||
return m_parameters[parameterName];
|
||||
}
|
||||
return m_parameters[parameterName];
|
||||
}
|
||||
|
||||
void GameRule::setParameter(const std::wstring ¶meterName,ValueType value)
|
||||
{
|
||||
if(m_parameters.find(parameterName) == m_parameters.end())
|
||||
{
|
||||
void GameRule::setParameter(const std::wstring& parameterName,
|
||||
ValueType value) {
|
||||
if (m_parameters.find(parameterName) == m_parameters.end()) {
|
||||
#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
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
#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
|
||||
}
|
||||
m_parameters[parameterName] = value;
|
||||
}
|
||||
m_parameters[parameterName] = value;
|
||||
}
|
||||
|
||||
GameRuleDefinition *GameRule::getGameRuleDefinition()
|
||||
{
|
||||
return m_definition;
|
||||
GameRuleDefinition* GameRule::getGameRuleDefinition() { 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::onCollectItem(std::shared_ptr<ItemInstance> item) { m_definition->onCollectItem(this,item); }
|
||||
void GameRule::write(DataOutputStream* dos) {
|
||||
// Find required parameters.
|
||||
dos->writeInt(m_parameters.size());
|
||||
for (AUTO_VAR(it, m_parameters.begin()); it != m_parameters.end(); it++) {
|
||||
std::wstring pName = (*it).first;
|
||||
ValueType vType = (*it).second;
|
||||
|
||||
void GameRule::write(DataOutputStream *dos)
|
||||
{
|
||||
// Find required parameters.
|
||||
dos->writeInt(m_parameters.size());
|
||||
for (AUTO_VAR(it, m_parameters.begin()); it != m_parameters.end(); it++)
|
||||
{
|
||||
std::wstring pName = (*it).first;
|
||||
ValueType vType = (*it).second;
|
||||
|
||||
dos->writeUTF( (*it).first );
|
||||
dos->writeBoolean( vType.isPointer );
|
||||
dos->writeUTF((*it).first);
|
||||
dos->writeBoolean(vType.isPointer);
|
||||
|
||||
if (vType.isPointer)
|
||||
vType.gr->write(dos);
|
||||
else
|
||||
dos->writeLong( vType.i64 );
|
||||
}
|
||||
if (vType.isPointer)
|
||||
vType.gr->write(dos);
|
||||
else
|
||||
dos->writeLong(vType.i64);
|
||||
}
|
||||
}
|
||||
|
||||
void GameRule::read(DataInputStream *dis)
|
||||
{
|
||||
int savedParams = dis->readInt();
|
||||
for (int i = 0; i < savedParams; i++)
|
||||
{
|
||||
std::wstring pNames = dis->readUTF();
|
||||
|
||||
ValueType vType = getParameter(pNames);
|
||||
void GameRule::read(DataInputStream* dis) {
|
||||
int savedParams = dis->readInt();
|
||||
for (int i = 0; i < savedParams; i++) {
|
||||
std::wstring pNames = dis->readUTF();
|
||||
|
||||
if (dis->readBoolean())
|
||||
{
|
||||
vType.gr->read(dis);
|
||||
}
|
||||
else
|
||||
{
|
||||
vType.isPointer = false;
|
||||
vType.i64 = dis->readLong();
|
||||
setParameter(pNames, vType);
|
||||
}
|
||||
}
|
||||
ValueType vType = getParameter(pNames);
|
||||
|
||||
if (dis->readBoolean()) {
|
||||
vType.gr->read(dis);
|
||||
} else {
|
||||
vType.isPointer = false;
|
||||
vType.i64 = dis->readLong();
|
||||
setParameter(pNames, vType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#pragma once
|
||||
//using namespace std;
|
||||
// using namespace std;
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
|
|
@ -8,55 +8,54 @@ class GameRuleDefinition;
|
|||
class Connection;
|
||||
|
||||
// A game rule maintains the state for one particular definition
|
||||
class GameRule
|
||||
{
|
||||
class GameRule {
|
||||
public:
|
||||
typedef struct _ValueType
|
||||
{
|
||||
union{
|
||||
__int64 i64;
|
||||
int i;
|
||||
char c;
|
||||
bool b;
|
||||
float f;
|
||||
double d;
|
||||
GameRule *gr;
|
||||
};
|
||||
bool isPointer;
|
||||
typedef struct _ValueType {
|
||||
union {
|
||||
__int64 i64;
|
||||
int i;
|
||||
char c;
|
||||
bool b;
|
||||
float f;
|
||||
double d;
|
||||
GameRule* gr;
|
||||
};
|
||||
bool isPointer;
|
||||
|
||||
_ValueType()
|
||||
{
|
||||
i64 = 0;
|
||||
isPointer = false;
|
||||
}
|
||||
} ValueType;
|
||||
_ValueType() {
|
||||
i64 = 0;
|
||||
isPointer = false;
|
||||
}
|
||||
} ValueType;
|
||||
|
||||
private:
|
||||
GameRuleDefinition *m_definition;
|
||||
Connection *m_connection;
|
||||
GameRuleDefinition* m_definition;
|
||||
Connection* m_connection;
|
||||
|
||||
public:
|
||||
typedef std::unordered_map<std::wstring,ValueType> stringValueMapType;
|
||||
stringValueMapType m_parameters; // These are the members of this rule that maintain it's state
|
||||
typedef std::unordered_map<std::wstring, ValueType> stringValueMapType;
|
||||
stringValueMapType m_parameters; // These are the members of this rule that
|
||||
// maintain it's state
|
||||
|
||||
public:
|
||||
GameRule(GameRuleDefinition *definition, Connection *connection = NULL);
|
||||
virtual ~GameRule();
|
||||
GameRule(GameRuleDefinition* definition, Connection* connection = NULL);
|
||||
virtual ~GameRule();
|
||||
|
||||
Connection *getConnection() { return m_connection; }
|
||||
|
||||
ValueType getParameter(const std::wstring ¶meterName);
|
||||
void setParameter(const std::wstring ¶meterName,ValueType value);
|
||||
GameRuleDefinition *getGameRuleDefinition();
|
||||
Connection* getConnection() { return m_connection; }
|
||||
|
||||
// All the hooks go here
|
||||
void onUseTile(int tileId, int x, int y, int z);
|
||||
void onCollectItem(std::shared_ptr<ItemInstance> item);
|
||||
ValueType getParameter(const std::wstring& parameterName);
|
||||
void setParameter(const std::wstring& parameterName, ValueType value);
|
||||
GameRuleDefinition* getGameRuleDefinition();
|
||||
|
||||
// 4J-JEV: For saving.
|
||||
//CompoundTag *toTags(std::unordered_map<GameRuleDefinition *, int> *map);
|
||||
//static GameRule *fromTags(Connection *c, CompoundTag *cTag, std::vector<GameRuleDefinition *> *grds);
|
||||
// All the hooks go here
|
||||
void onUseTile(int tileId, int x, int y, int z);
|
||||
void onCollectItem(std::shared_ptr<ItemInstance> item);
|
||||
|
||||
void write(DataOutputStream *dos);
|
||||
void read(DataInputStream *dos);
|
||||
// 4J-JEV: For saving.
|
||||
// CompoundTag *toTags(std::unordered_map<GameRuleDefinition *, int> *map);
|
||||
// static GameRule *fromTags(Connection *c, CompoundTag *cTag,
|
||||
// std::vector<GameRuleDefinition *> *grds);
|
||||
|
||||
void write(DataOutputStream* dos);
|
||||
void read(DataInputStream* dos);
|
||||
};
|
||||
|
|
@ -3,149 +3,149 @@
|
|||
#include "../../Minecraft.World/Util/StringHelpers.h"
|
||||
#include "ConsoleGameRules.h"
|
||||
|
||||
GameRuleDefinition::GameRuleDefinition()
|
||||
{
|
||||
m_descriptionId = L"";
|
||||
m_promptId = L"";
|
||||
m_4JDataValue = 0;
|
||||
GameRuleDefinition::GameRuleDefinition() {
|
||||
m_descriptionId = L"";
|
||||
m_promptId = L"";
|
||||
m_4JDataValue = 0;
|
||||
}
|
||||
|
||||
void GameRuleDefinition::write(DataOutputStream *dos)
|
||||
{
|
||||
// Write EGameRuleType.
|
||||
ConsoleGameRules::EGameRuleType eType = getActionType();
|
||||
assert( eType != ConsoleGameRules::eGameRuleType_Invalid );
|
||||
ConsoleGameRules::write(dos, eType); // stringID
|
||||
void GameRuleDefinition::write(DataOutputStream* dos) {
|
||||
// Write EGameRuleType.
|
||||
ConsoleGameRules::EGameRuleType eType = getActionType();
|
||||
assert(eType != ConsoleGameRules::eGameRuleType_Invalid);
|
||||
ConsoleGameRules::write(dos, eType); // stringID
|
||||
|
||||
writeAttributes(dos, 0);
|
||||
|
||||
// 4J-JEV: Get children.
|
||||
std::vector<GameRuleDefinition *> *children = new std::vector<GameRuleDefinition *>();
|
||||
getChildren( children );
|
||||
writeAttributes(dos, 0);
|
||||
|
||||
// Write children.
|
||||
dos->writeInt( children->size() );
|
||||
for (AUTO_VAR(it, children->begin()); it != children->end(); it++)
|
||||
(*it)->write(dos);
|
||||
// 4J-JEV: Get children.
|
||||
std::vector<GameRuleDefinition*>* children =
|
||||
new std::vector<GameRuleDefinition*>();
|
||||
getChildren(children);
|
||||
|
||||
// Write children.
|
||||
dos->writeInt(children->size());
|
||||
for (AUTO_VAR(it, children->begin()); it != children->end(); it++)
|
||||
(*it)->write(dos);
|
||||
}
|
||||
|
||||
void GameRuleDefinition::writeAttributes(DataOutputStream *dos, unsigned int numAttributes)
|
||||
{
|
||||
dos->writeInt(numAttributes + 3);
|
||||
void GameRuleDefinition::writeAttributes(DataOutputStream* dos,
|
||||
unsigned int numAttributes) {
|
||||
dos->writeInt(numAttributes + 3);
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_descriptionName);
|
||||
dos->writeUTF(m_descriptionId);
|
||||
ConsoleGameRules::write(dos,
|
||||
ConsoleGameRules::eGameRuleAttr_descriptionName);
|
||||
dos->writeUTF(m_descriptionId);
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_promptName);
|
||||
dos->writeUTF(m_promptId);
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_promptName);
|
||||
dos->writeUTF(m_promptId);
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_dataTag);
|
||||
dos->writeUTF(_toString(m_4JDataValue));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_dataTag);
|
||||
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
|
||||
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
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void GameRuleDefinition::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue)
|
||||
{
|
||||
if(attributeName.compare(L"descriptionName") == 0)
|
||||
{
|
||||
m_descriptionId = attributeValue;
|
||||
void GameRuleDefinition::addAttribute(const std::wstring& attributeName,
|
||||
const std::wstring& attributeValue) {
|
||||
if (attributeName.compare(L"descriptionName") == 0) {
|
||||
m_descriptionId = attributeValue;
|
||||
#ifndef _CONTENT_PACKAGE
|
||||
wprintf(L"GameRuleDefinition: Adding parameter descriptionId=%ls\n",m_descriptionId.c_str());
|
||||
wprintf(L"GameRuleDefinition: Adding parameter descriptionId=%ls\n",
|
||||
m_descriptionId.c_str());
|
||||
#endif
|
||||
}
|
||||
else if(attributeName.compare(L"promptName") == 0)
|
||||
{
|
||||
m_promptId = attributeValue;
|
||||
} else if (attributeName.compare(L"promptName") == 0) {
|
||||
m_promptId = attributeValue;
|
||||
#ifndef _CONTENT_PACKAGE
|
||||
wprintf(L"GameRuleDefinition: Adding parameter m_promptId=%ls\n",m_promptId.c_str());
|
||||
wprintf(L"GameRuleDefinition: Adding parameter m_promptId=%ls\n",
|
||||
m_promptId.c_str());
|
||||
#endif
|
||||
}
|
||||
else if(attributeName.compare(L"dataTag") == 0)
|
||||
{
|
||||
m_4JDataValue = _fromString<int>(attributeValue);
|
||||
app.DebugPrintf("GameRuleDefinition: Adding parameter m_4JDataValue=%d\n",m_4JDataValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else if (attributeName.compare(L"dataTag") == 0) {
|
||||
m_4JDataValue = _fromString<int>(attributeValue);
|
||||
app.DebugPrintf(
|
||||
"GameRuleDefinition: Adding parameter m_4JDataValue=%d\n",
|
||||
m_4JDataValue);
|
||||
} else {
|
||||
#ifndef _CONTENT_PACKAGE
|
||||
wprintf(L"GameRuleDefinition: Attempted to add invalid attribute: %ls\n", attributeName.c_str());
|
||||
wprintf(
|
||||
L"GameRuleDefinition: Attempted to add invalid attribute: %ls\n",
|
||||
attributeName.c_str());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GameRuleDefinition::populateGameRule(GameRulesInstance::EGameRulesInstanceType type, GameRule *rule)
|
||||
{
|
||||
GameRule::ValueType value;
|
||||
value.b = false;
|
||||
rule->setParameter(L"bComplete",value);
|
||||
void GameRuleDefinition::populateGameRule(
|
||||
GameRulesInstance::EGameRulesInstanceType type, GameRule* rule) {
|
||||
GameRule::ValueType value;
|
||||
value.b = false;
|
||||
rule->setParameter(L"bComplete", value);
|
||||
}
|
||||
|
||||
bool GameRuleDefinition::getComplete(GameRule *rule)
|
||||
{
|
||||
GameRule::ValueType value;
|
||||
value = rule->getParameter(L"bComplete");
|
||||
return value.b;
|
||||
bool GameRuleDefinition::getComplete(GameRule* rule) {
|
||||
GameRule::ValueType value;
|
||||
value = rule->getParameter(L"bComplete");
|
||||
return value.b;
|
||||
}
|
||||
|
||||
void GameRuleDefinition::setComplete(GameRule *rule, bool val)
|
||||
{
|
||||
GameRule::ValueType value;
|
||||
value = rule->getParameter(L"bComplete");
|
||||
value.b = val;
|
||||
rule->setParameter(L"bComplete",value);
|
||||
void GameRuleDefinition::setComplete(GameRule* rule, bool val) {
|
||||
GameRule::ValueType value;
|
||||
value = rule->getParameter(L"bComplete");
|
||||
value.b = val;
|
||||
rule->setParameter(L"bComplete", value);
|
||||
}
|
||||
|
||||
std::vector<GameRuleDefinition *> *GameRuleDefinition::enumerate()
|
||||
{
|
||||
// Get Vector.
|
||||
std::vector<GameRuleDefinition *> *gRules;
|
||||
gRules = new std::vector<GameRuleDefinition *>();
|
||||
gRules->push_back(this);
|
||||
getChildren(gRules);
|
||||
return gRules;
|
||||
std::vector<GameRuleDefinition*>* GameRuleDefinition::enumerate() {
|
||||
// Get Vector.
|
||||
std::vector<GameRuleDefinition*>* gRules;
|
||||
gRules = new std::vector<GameRuleDefinition*>();
|
||||
gRules->push_back(this);
|
||||
getChildren(gRules);
|
||||
return gRules;
|
||||
}
|
||||
|
||||
std::unordered_map<GameRuleDefinition *, int> *GameRuleDefinition::enumerateMap()
|
||||
{
|
||||
std::unordered_map<GameRuleDefinition *, int> *out
|
||||
= new std::unordered_map<GameRuleDefinition *, int>();
|
||||
std::unordered_map<GameRuleDefinition*, int>*
|
||||
GameRuleDefinition::enumerateMap() {
|
||||
std::unordered_map<GameRuleDefinition*, int>* out =
|
||||
new std::unordered_map<GameRuleDefinition*, int>();
|
||||
|
||||
int i = 0;
|
||||
std::vector<GameRuleDefinition *> *gRules = enumerate();
|
||||
for (AUTO_VAR(it, gRules->begin()); it != gRules->end(); it++)
|
||||
out->insert( std::pair<GameRuleDefinition *, int>( *it, i++ ) );
|
||||
int i = 0;
|
||||
std::vector<GameRuleDefinition*>* gRules = enumerate();
|
||||
for (AUTO_VAR(it, gRules->begin()); it != gRules->end(); it++)
|
||||
out->insert(std::pair<GameRuleDefinition*, int>(*it, i++));
|
||||
|
||||
return out;
|
||||
return out;
|
||||
}
|
||||
|
||||
GameRulesInstance *GameRuleDefinition::generateNewGameRulesInstance(GameRulesInstance::EGameRulesInstanceType type, LevelRuleset *rules, Connection *connection)
|
||||
{
|
||||
GameRulesInstance *manager = new GameRulesInstance(rules, connection);
|
||||
GameRulesInstance* GameRuleDefinition::generateNewGameRulesInstance(
|
||||
GameRulesInstance::EGameRulesInstanceType type, LevelRuleset* rules,
|
||||
Connection* connection) {
|
||||
GameRulesInstance* manager = new GameRulesInstance(rules, connection);
|
||||
|
||||
rules->populateGameRule(type, manager);
|
||||
rules->populateGameRule(type, manager);
|
||||
|
||||
return manager;
|
||||
return manager;
|
||||
}
|
||||
|
||||
std::wstring GameRuleDefinition::generateDescriptionString(ConsoleGameRules::EGameRuleType defType, const std::wstring &description, void *data, int dataLength)
|
||||
{
|
||||
std::wstring formatted = description;
|
||||
switch(defType)
|
||||
{
|
||||
case ConsoleGameRules::eGameRuleType_CompleteAllRule:
|
||||
formatted = CompleteAllRuleDefinition::generateDescriptionString(description,data,dataLength);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
};
|
||||
return formatted;
|
||||
std::wstring GameRuleDefinition::generateDescriptionString(
|
||||
ConsoleGameRules::EGameRuleType defType, const std::wstring& description,
|
||||
void* data, int dataLength) {
|
||||
std::wstring formatted = description;
|
||||
switch (defType) {
|
||||
case ConsoleGameRules::eGameRuleType_CompleteAllRule:
|
||||
formatted = CompleteAllRuleDefinition::generateDescriptionString(
|
||||
description, data, dataLength);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
};
|
||||
return formatted;
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
#pragma once
|
||||
//using namespace std;
|
||||
// using namespace std;
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
|
||||
|
|
@ -13,55 +13,69 @@ class LevelRuleset;
|
|||
class Player;
|
||||
class WstringLookup;
|
||||
|
||||
class GameRuleDefinition
|
||||
{
|
||||
class GameRuleDefinition {
|
||||
private:
|
||||
// Owner type defines who this rule applies to
|
||||
GameRulesInstance::EGameRulesInstanceType m_ownerType;
|
||||
// Owner type defines who this rule applies to
|
||||
GameRulesInstance::EGameRulesInstanceType m_ownerType;
|
||||
|
||||
protected:
|
||||
// These attributes should map to those in the XSD GameRuleType
|
||||
std::wstring m_descriptionId;
|
||||
std::wstring m_promptId;
|
||||
int m_4JDataValue;
|
||||
// These attributes should map to those in the XSD GameRuleType
|
||||
std::wstring m_descriptionId;
|
||||
std::wstring m_promptId;
|
||||
int m_4JDataValue;
|
||||
|
||||
public:
|
||||
GameRuleDefinition();
|
||||
virtual ~GameRuleDefinition(){}
|
||||
GameRuleDefinition();
|
||||
virtual ~GameRuleDefinition() {}
|
||||
|
||||
virtual ConsoleGameRules::EGameRuleType getActionType() = 0;
|
||||
virtual ConsoleGameRules::EGameRuleType getActionType() = 0;
|
||||
|
||||
void setOwnerType(GameRulesInstance::EGameRulesInstanceType ownerType) { m_ownerType = ownerType;}
|
||||
void setOwnerType(GameRulesInstance::EGameRulesInstanceType ownerType) {
|
||||
m_ownerType = ownerType;
|
||||
}
|
||||
|
||||
virtual void write(DataOutputStream *);
|
||||
virtual void write(DataOutputStream*);
|
||||
|
||||
virtual void writeAttributes(DataOutputStream *dos, unsigned int numAttributes);
|
||||
virtual void getChildren(std::vector<GameRuleDefinition *> *);
|
||||
virtual void writeAttributes(DataOutputStream* dos,
|
||||
unsigned int numAttributes);
|
||||
virtual void getChildren(std::vector<GameRuleDefinition*>*);
|
||||
|
||||
virtual GameRuleDefinition *addChild(ConsoleGameRules::EGameRuleType ruleType);
|
||||
virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue);
|
||||
|
||||
virtual void populateGameRule(GameRulesInstance::EGameRulesInstanceType type, GameRule *rule);
|
||||
virtual GameRuleDefinition* addChild(
|
||||
ConsoleGameRules::EGameRuleType ruleType);
|
||||
virtual void addAttribute(const std::wstring& attributeName,
|
||||
const std::wstring& attributeValue);
|
||||
|
||||
bool getComplete(GameRule *rule);
|
||||
void setComplete(GameRule *rule, bool val);
|
||||
virtual void populateGameRule(
|
||||
GameRulesInstance::EGameRulesInstanceType type, GameRule* rule);
|
||||
|
||||
virtual int getGoal() { return 0; }
|
||||
virtual int getProgress(GameRule *rule) { return 0; }
|
||||
bool getComplete(GameRule* rule);
|
||||
void setComplete(GameRule* rule, bool val);
|
||||
|
||||
virtual int getIcon() { return -1; }
|
||||
virtual int getAuxValue() { return 0; }
|
||||
virtual int getGoal() { return 0; }
|
||||
virtual int getProgress(GameRule* rule) { return 0; }
|
||||
|
||||
// Here we should have functions for all the hooks, with a GameRule* as the first parameter
|
||||
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 int getIcon() { return -1; }
|
||||
virtual int getAuxValue() { return 0; }
|
||||
|
||||
std::vector<GameRuleDefinition *> *enumerate();
|
||||
std::unordered_map<GameRuleDefinition *, int> *enumerateMap();
|
||||
// Here we should have functions for all the hooks, with a GameRule* as the
|
||||
// first parameter
|
||||
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) {}
|
||||
|
||||
// Static functions
|
||||
static GameRulesInstance *generateNewGameRulesInstance(GameRulesInstance::EGameRulesInstanceType type, LevelRuleset *rules, Connection *connection);
|
||||
static std::wstring generateDescriptionString(ConsoleGameRules::EGameRuleType defType, const std::wstring &description, void *data = NULL, int dataLength = 0);
|
||||
std::vector<GameRuleDefinition*>* enumerate();
|
||||
std::unordered_map<GameRuleDefinition*, int>* enumerateMap();
|
||||
|
||||
// Static functions
|
||||
static GameRulesInstance* generateNewGameRulesInstance(
|
||||
GameRulesInstance::EGameRulesInstanceType type, LevelRuleset* rules,
|
||||
Connection* connection);
|
||||
static std::wstring generateDescriptionString(
|
||||
ConsoleGameRules::EGameRuleType defType,
|
||||
const std::wstring& description, void* data = NULL, int dataLength = 0);
|
||||
};
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -17,64 +17,78 @@ class WstringLookup;
|
|||
|
||||
#define GAME_RULE_SAVENAME L"requiredGameRules.grf"
|
||||
|
||||
// 4J-JEV:
|
||||
// 4J-JEV:
|
||||
#define LEVEL_GEN_ID int
|
||||
#define LEVEL_GEN_ID_NULL 0
|
||||
|
||||
class GameRuleManager
|
||||
{
|
||||
class GameRuleManager {
|
||||
public:
|
||||
static const WCHAR *wchTagNameA[ConsoleGameRules::eGameRuleType_Count];
|
||||
static const WCHAR *wchAttrNameA[ConsoleGameRules::eGameRuleAttr_Count];
|
||||
static const WCHAR* wchTagNameA[ConsoleGameRules::eGameRuleType_Count];
|
||||
static const WCHAR* wchAttrNameA[ConsoleGameRules::eGameRuleAttr_Count];
|
||||
|
||||
static const short version_number = 2;
|
||||
static const short version_number = 2;
|
||||
|
||||
private:
|
||||
LevelGenerationOptions *m_currentLevelGenerationOptions;
|
||||
LevelRuleset *m_currentGameRuleDefinitions;
|
||||
LevelGenerators m_levelGenerators;
|
||||
LevelRules m_levelRules;
|
||||
LevelGenerationOptions* m_currentLevelGenerationOptions;
|
||||
LevelRuleset* m_currentGameRuleDefinitions;
|
||||
LevelGenerators m_levelGenerators;
|
||||
LevelRules m_levelRules;
|
||||
|
||||
public:
|
||||
GameRuleManager();
|
||||
GameRuleManager();
|
||||
|
||||
void loadGameRules(DLCPack *);
|
||||
void loadGameRules(DLCPack*);
|
||||
|
||||
LevelGenerationOptions *loadGameRules(uint8_t *dIn, unsigned int dSize);
|
||||
void loadGameRules(LevelGenerationOptions *lgo, 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 saveGameRules(uint8_t **dOut, unsigned int *dSize);
|
||||
void saveGameRules(uint8_t** dOut, unsigned int* dSize);
|
||||
|
||||
private:
|
||||
LevelGenerationOptions *readHeader(DLCGameRulesHeader *grh);
|
||||
LevelGenerationOptions* readHeader(DLCGameRulesHeader* grh);
|
||||
|
||||
void writeRuleFile(DataOutputStream *dos);
|
||||
void writeRuleFile(DataOutputStream* dos);
|
||||
|
||||
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:
|
||||
void readAttributes(DataInputStream *dis, 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);
|
||||
void readAttributes(DataInputStream* dis,
|
||||
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:
|
||||
void processSchematics(LevelChunk *levelChunk);
|
||||
void processSchematicsLighting(LevelChunk *levelChunk);
|
||||
void loadDefaultGameRules();
|
||||
void processSchematics(LevelChunk* levelChunk);
|
||||
void processSchematicsLighting(LevelChunk* levelChunk);
|
||||
void loadDefaultGameRules();
|
||||
|
||||
private:
|
||||
bool loadGameRulesPack(File *path);
|
||||
bool loadGameRulesPack(File* path);
|
||||
|
||||
LEVEL_GEN_ID addLevelGenerationOptions(LevelGenerationOptions *);
|
||||
LEVEL_GEN_ID addLevelGenerationOptions(LevelGenerationOptions*);
|
||||
|
||||
public:
|
||||
std::vector<LevelGenerationOptions *> *getLevelGenerators() { return m_levelGenerators.getLevelGenerators(); }
|
||||
void setLevelGenerationOptions(LevelGenerationOptions *levelGen);
|
||||
LevelRuleset *getGameRuleDefinitions() { return m_currentGameRuleDefinitions; }
|
||||
LevelGenerationOptions *getLevelGenerationOptions() { return m_currentLevelGenerationOptions; }
|
||||
const wchar_t *GetGameRulesString(const std::wstring &key);
|
||||
std::vector<LevelGenerationOptions*>* getLevelGenerators() {
|
||||
return m_levelGenerators.getLevelGenerators();
|
||||
}
|
||||
void setLevelGenerationOptions(LevelGenerationOptions* levelGen);
|
||||
LevelRuleset* getGameRuleDefinitions() {
|
||||
return m_currentGameRuleDefinitions;
|
||||
}
|
||||
LevelGenerationOptions* getLevelGenerationOptions() {
|
||||
return m_currentLevelGenerationOptions;
|
||||
}
|
||||
const wchar_t* GetGameRulesString(const std::wstring& key);
|
||||
|
||||
// 4J-JEV:
|
||||
// Properly cleans-up and unloads the current set of gameRules.
|
||||
void unloadCurrentGameRules();
|
||||
// 4J-JEV:
|
||||
// Properly cleans-up and unloads the current set of gameRules.
|
||||
void unloadCurrentGameRules();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,24 +1,24 @@
|
|||
#pragma once
|
||||
//using namespace std;
|
||||
// using namespace std;
|
||||
#include <vector>
|
||||
#include "GameRule.h"
|
||||
|
||||
class GameRuleDefinition;
|
||||
|
||||
// The game rule manager belongs to a player/server or other object, and maintains their current state for each of
|
||||
// the rules that apply to them
|
||||
class GameRulesInstance : public GameRule
|
||||
{
|
||||
// The game rule manager belongs to a player/server or other object, and
|
||||
// maintains their current state for each of the rules that apply to them
|
||||
class GameRulesInstance : public GameRule {
|
||||
public:
|
||||
// These types are used by the GameRuleDefinition to know which rules to add to this GameRulesInstance
|
||||
enum EGameRulesInstanceType
|
||||
{
|
||||
eGameRulesInstanceType_ServerPlayer,
|
||||
eGameRulesInstanceType_Server,
|
||||
eGameRulesInstanceType_Count
|
||||
};
|
||||
// These types are used by the GameRuleDefinition to know which rules to add
|
||||
// to this GameRulesInstance
|
||||
enum EGameRulesInstanceType {
|
||||
eGameRulesInstanceType_ServerPlayer,
|
||||
eGameRulesInstanceType_Server,
|
||||
eGameRulesInstanceType_Count
|
||||
};
|
||||
|
||||
public:
|
||||
GameRulesInstance(GameRuleDefinition *definition, Connection *connection) : GameRule(definition,connection) {}
|
||||
// Functions for all the hooks should go here
|
||||
GameRulesInstance(GameRuleDefinition* definition, Connection* connection)
|
||||
: GameRule(definition, connection) {}
|
||||
// Functions for all the hooks should go here
|
||||
};
|
||||
|
|
@ -11,465 +11,465 @@
|
|||
#include "LevelGenerationOptions.h"
|
||||
#include "ConsoleGameRules.h"
|
||||
|
||||
JustGrSource::JustGrSource()
|
||||
{
|
||||
m_displayName = L"Default_DisplayName";
|
||||
m_worldName= L"Default_WorldName";
|
||||
m_defaultSaveName = L"Default_DefaultSaveName";
|
||||
m_bRequiresTexturePack = false;
|
||||
m_requiredTexturePackId = 0;
|
||||
m_grfPath = L"__NO_GRF_PATH__";
|
||||
m_bRequiresBaseSave = false;
|
||||
JustGrSource::JustGrSource() {
|
||||
m_displayName = L"Default_DisplayName";
|
||||
m_worldName = L"Default_WorldName";
|
||||
m_defaultSaveName = L"Default_DefaultSaveName";
|
||||
m_bRequiresTexturePack = false;
|
||||
m_requiredTexturePackId = 0;
|
||||
m_grfPath = L"__NO_GRF_PATH__";
|
||||
m_bRequiresBaseSave = false;
|
||||
}
|
||||
|
||||
bool JustGrSource::requiresTexturePack() {return m_bRequiresTexturePack;}
|
||||
std::uint32_t JustGrSource::getRequiredTexturePackId() {return m_requiredTexturePackId;}
|
||||
std::wstring JustGrSource::getDefaultSaveName() {return m_defaultSaveName;}
|
||||
const wchar_t *JustGrSource::getWorldName() {return m_worldName.c_str();}
|
||||
const wchar_t *JustGrSource::getDisplayName() {return m_displayName.c_str();}
|
||||
std::wstring JustGrSource::getGrfPath() {return m_grfPath;}
|
||||
bool JustGrSource::requiresTexturePack() { return m_bRequiresTexturePack; }
|
||||
std::uint32_t JustGrSource::getRequiredTexturePackId() {
|
||||
return m_requiredTexturePackId;
|
||||
}
|
||||
std::wstring JustGrSource::getDefaultSaveName() { return m_defaultSaveName; }
|
||||
const wchar_t* JustGrSource::getWorldName() { return m_worldName.c_str(); }
|
||||
const wchar_t* JustGrSource::getDisplayName() { return m_displayName.c_str(); }
|
||||
std::wstring JustGrSource::getGrfPath() { return m_grfPath; }
|
||||
bool JustGrSource::requiresBaseSave() { return m_bRequiresBaseSave; };
|
||||
std::wstring JustGrSource::getBaseSavePath() { return m_baseSavePath; };
|
||||
|
||||
void JustGrSource::setRequiresTexturePack(bool x) {m_bRequiresTexturePack = 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::setDisplayName(const std::wstring &x) {m_displayName = x;}
|
||||
void JustGrSource::setGrfPath(const std::wstring &x) {m_grfPath = x;}
|
||||
void JustGrSource::setBaseSavePath(const std::wstring &x) { m_baseSavePath = x; m_bRequiresBaseSave = true; }
|
||||
void JustGrSource::setRequiresTexturePack(bool x) {
|
||||
m_bRequiresTexturePack = 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::setDisplayName(const std::wstring& x) { m_displayName = x; }
|
||||
void JustGrSource::setGrfPath(const std::wstring& x) { m_grfPath = x; }
|
||||
void JustGrSource::setBaseSavePath(const std::wstring& x) {
|
||||
m_baseSavePath = x;
|
||||
m_bRequiresBaseSave = true;
|
||||
}
|
||||
|
||||
bool JustGrSource::ready() { return true; }
|
||||
|
||||
LevelGenerationOptions::LevelGenerationOptions()
|
||||
{
|
||||
m_spawnPos = NULL;
|
||||
m_stringTable = NULL;
|
||||
LevelGenerationOptions::LevelGenerationOptions() {
|
||||
m_spawnPos = NULL;
|
||||
m_stringTable = NULL;
|
||||
|
||||
m_hasLoadedData = false;
|
||||
m_hasLoadedData = false;
|
||||
|
||||
m_seed = 0;
|
||||
m_useFlatWorld = false;
|
||||
m_bHaveMinY = false;
|
||||
m_minY = INT_MAX;
|
||||
m_bRequiresGameRules = false;
|
||||
m_seed = 0;
|
||||
m_useFlatWorld = false;
|
||||
m_bHaveMinY = false;
|
||||
m_minY = INT_MAX;
|
||||
m_bRequiresGameRules = false;
|
||||
|
||||
m_pbBaseSaveData = NULL;
|
||||
m_baseSaveSize = 0;
|
||||
m_pbBaseSaveData = NULL;
|
||||
m_baseSaveSize = 0;
|
||||
}
|
||||
|
||||
LevelGenerationOptions::~LevelGenerationOptions()
|
||||
{
|
||||
clearSchematics();
|
||||
if(m_spawnPos != NULL) delete m_spawnPos;
|
||||
for(AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end(); ++it)
|
||||
{
|
||||
delete *it;
|
||||
}
|
||||
for(AUTO_VAR(it, m_structureRules.begin()); it != m_structureRules.end(); ++it)
|
||||
{
|
||||
delete *it;
|
||||
}
|
||||
|
||||
for(AUTO_VAR(it, m_biomeOverrides.begin()); it != m_biomeOverrides.end(); ++it)
|
||||
{
|
||||
delete *it;
|
||||
}
|
||||
|
||||
for(AUTO_VAR(it, m_features.begin()); it != m_features.end(); ++it)
|
||||
{
|
||||
delete *it;
|
||||
}
|
||||
|
||||
if (m_stringTable)
|
||||
if (!isTutorial())
|
||||
delete m_stringTable;
|
||||
LevelGenerationOptions::~LevelGenerationOptions() {
|
||||
clearSchematics();
|
||||
if (m_spawnPos != NULL) delete m_spawnPos;
|
||||
for (AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end();
|
||||
++it) {
|
||||
delete *it;
|
||||
}
|
||||
for (AUTO_VAR(it, m_structureRules.begin()); it != m_structureRules.end();
|
||||
++it) {
|
||||
delete *it;
|
||||
}
|
||||
|
||||
if (isFromSave()) delete m_pSrc;
|
||||
for (AUTO_VAR(it, m_biomeOverrides.begin()); it != m_biomeOverrides.end();
|
||||
++it) {
|
||||
delete *it;
|
||||
}
|
||||
|
||||
for (AUTO_VAR(it, m_features.begin()); it != m_features.end(); ++it) {
|
||||
delete *it;
|
||||
}
|
||||
|
||||
if (m_stringTable)
|
||||
if (!isTutorial()) delete m_stringTable;
|
||||
|
||||
if (isFromSave()) delete m_pSrc;
|
||||
}
|
||||
|
||||
ConsoleGameRules::EGameRuleType LevelGenerationOptions::getActionType() { return ConsoleGameRules::eGameRuleType_LevelGenerationOptions; }
|
||||
|
||||
void LevelGenerationOptions::writeAttributes(DataOutputStream *dos, unsigned int numAttrs)
|
||||
{
|
||||
GameRuleDefinition::writeAttributes(dos, numAttrs + 5);
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_spawnX);
|
||||
dos->writeUTF(_toString(m_spawnPos->x));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_spawnY);
|
||||
dos->writeUTF(_toString(m_spawnPos->y));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_spawnZ);
|
||||
dos->writeUTF(_toString(m_spawnPos->z));
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_seed);
|
||||
dos->writeUTF(_toString(m_seed));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_flatworld);
|
||||
dos->writeUTF(_toString(m_useFlatWorld));
|
||||
ConsoleGameRules::EGameRuleType LevelGenerationOptions::getActionType() {
|
||||
return ConsoleGameRules::eGameRuleType_LevelGenerationOptions;
|
||||
}
|
||||
|
||||
void LevelGenerationOptions::getChildren(std::vector<GameRuleDefinition *> *children)
|
||||
{
|
||||
GameRuleDefinition::getChildren(children);
|
||||
|
||||
std::vector<ApplySchematicRuleDefinition *> used_schematics;
|
||||
for (AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end(); it++)
|
||||
if ( !(*it)->isComplete() )
|
||||
used_schematics.push_back( *it );
|
||||
|
||||
for(AUTO_VAR(it, m_structureRules.begin()); it!=m_structureRules.end(); it++)
|
||||
children->push_back( *it );
|
||||
for(AUTO_VAR(it, used_schematics.begin()); it!=used_schematics.end(); it++)
|
||||
children->push_back( *it );
|
||||
for(AUTO_VAR(it, m_biomeOverrides.begin()); it != m_biomeOverrides.end(); ++it)
|
||||
children->push_back( *it );
|
||||
for(AUTO_VAR(it, m_features.begin()); it != m_features.end(); ++it)
|
||||
children->push_back( *it );
|
||||
void LevelGenerationOptions::writeAttributes(DataOutputStream* dos,
|
||||
unsigned int numAttrs) {
|
||||
GameRuleDefinition::writeAttributes(dos, numAttrs + 5);
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_spawnX);
|
||||
dos->writeUTF(_toString(m_spawnPos->x));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_spawnY);
|
||||
dos->writeUTF(_toString(m_spawnPos->y));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_spawnZ);
|
||||
dos->writeUTF(_toString(m_spawnPos->z));
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_seed);
|
||||
dos->writeUTF(_toString(m_seed));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_flatworld);
|
||||
dos->writeUTF(_toString(m_useFlatWorld));
|
||||
}
|
||||
|
||||
GameRuleDefinition *LevelGenerationOptions::addChild(ConsoleGameRules::EGameRuleType ruleType)
|
||||
{
|
||||
GameRuleDefinition *rule = NULL;
|
||||
if(ruleType == ConsoleGameRules::eGameRuleType_ApplySchematic)
|
||||
{
|
||||
rule = new ApplySchematicRuleDefinition(this);
|
||||
m_schematicRules.push_back((ApplySchematicRuleDefinition *)rule);
|
||||
}
|
||||
else if(ruleType == ConsoleGameRules::eGameRuleType_GenerateStructure)
|
||||
{
|
||||
rule = new ConsoleGenerateStructure();
|
||||
m_structureRules.push_back((ConsoleGenerateStructure *)rule);
|
||||
}
|
||||
else if(ruleType == ConsoleGameRules::eGameRuleType_BiomeOverride)
|
||||
{
|
||||
rule = new BiomeOverride();
|
||||
m_biomeOverrides.push_back((BiomeOverride *)rule);
|
||||
}
|
||||
else if(ruleType == ConsoleGameRules::eGameRuleType_StartFeature)
|
||||
{
|
||||
rule = new StartFeature();
|
||||
m_features.push_back((StartFeature *)rule);
|
||||
}
|
||||
else
|
||||
{
|
||||
void LevelGenerationOptions::getChildren(
|
||||
std::vector<GameRuleDefinition*>* children) {
|
||||
GameRuleDefinition::getChildren(children);
|
||||
|
||||
std::vector<ApplySchematicRuleDefinition*> used_schematics;
|
||||
for (AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end();
|
||||
it++)
|
||||
if (!(*it)->isComplete()) used_schematics.push_back(*it);
|
||||
|
||||
for (AUTO_VAR(it, m_structureRules.begin()); it != m_structureRules.end();
|
||||
it++)
|
||||
children->push_back(*it);
|
||||
for (AUTO_VAR(it, used_schematics.begin()); it != used_schematics.end();
|
||||
it++)
|
||||
children->push_back(*it);
|
||||
for (AUTO_VAR(it, m_biomeOverrides.begin()); it != m_biomeOverrides.end();
|
||||
++it)
|
||||
children->push_back(*it);
|
||||
for (AUTO_VAR(it, m_features.begin()); it != m_features.end(); ++it)
|
||||
children->push_back(*it);
|
||||
}
|
||||
|
||||
GameRuleDefinition* LevelGenerationOptions::addChild(
|
||||
ConsoleGameRules::EGameRuleType ruleType) {
|
||||
GameRuleDefinition* rule = NULL;
|
||||
if (ruleType == ConsoleGameRules::eGameRuleType_ApplySchematic) {
|
||||
rule = new ApplySchematicRuleDefinition(this);
|
||||
m_schematicRules.push_back((ApplySchematicRuleDefinition*)rule);
|
||||
} else if (ruleType == ConsoleGameRules::eGameRuleType_GenerateStructure) {
|
||||
rule = new ConsoleGenerateStructure();
|
||||
m_structureRules.push_back((ConsoleGenerateStructure*)rule);
|
||||
} else if (ruleType == ConsoleGameRules::eGameRuleType_BiomeOverride) {
|
||||
rule = new BiomeOverride();
|
||||
m_biomeOverrides.push_back((BiomeOverride*)rule);
|
||||
} else if (ruleType == ConsoleGameRules::eGameRuleType_StartFeature) {
|
||||
rule = new StartFeature();
|
||||
m_features.push_back((StartFeature*)rule);
|
||||
} else {
|
||||
#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
|
||||
}
|
||||
return rule;
|
||||
}
|
||||
return rule;
|
||||
}
|
||||
|
||||
void LevelGenerationOptions::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue)
|
||||
{
|
||||
if(attributeName.compare(L"seed") == 0)
|
||||
{
|
||||
m_seed = _fromString<__int64>(attributeValue);
|
||||
app.DebugPrintf("LevelGenerationOptions: Adding parameter m_seed=%I64d\n",m_seed);
|
||||
}
|
||||
else if(attributeName.compare(L"spawnX") == 0)
|
||||
{
|
||||
if(m_spawnPos == NULL) m_spawnPos = new Pos();
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_spawnPos->x = value;
|
||||
app.DebugPrintf("LevelGenerationOptions: Adding parameter spawnX=%d\n",value);
|
||||
}
|
||||
else if(attributeName.compare(L"spawnY") == 0)
|
||||
{
|
||||
if(m_spawnPos == NULL) m_spawnPos = new Pos();
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_spawnPos->y = value;
|
||||
app.DebugPrintf("LevelGenerationOptions: Adding parameter spawnY=%d\n",value);
|
||||
}
|
||||
else if(attributeName.compare(L"spawnZ") == 0)
|
||||
{
|
||||
if(m_spawnPos == NULL) m_spawnPos = new Pos();
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_spawnPos->z = value;
|
||||
app.DebugPrintf("LevelGenerationOptions: Adding parameter spawnZ=%d\n",value);
|
||||
}
|
||||
else if(attributeName.compare(L"flatworld") == 0)
|
||||
{
|
||||
if(attributeValue.compare(L"true") == 0) m_useFlatWorld = true;
|
||||
app.DebugPrintf("LevelGenerationOptions: Adding parameter flatworld=%s\n",m_useFlatWorld?"TRUE":"FALSE");
|
||||
}
|
||||
else if(attributeName.compare(L"saveName") == 0)
|
||||
{
|
||||
std::wstring string(getString(attributeValue));
|
||||
if(!string.empty()) setDefaultSaveName( string );
|
||||
else setDefaultSaveName( attributeValue );
|
||||
app.DebugPrintf("LevelGenerationOptions: Adding parameter saveName=%ls\n", getDefaultSaveName().c_str());
|
||||
}
|
||||
else if(attributeName.compare(L"worldName") == 0)
|
||||
{
|
||||
std::wstring string(getString(attributeValue));
|
||||
if(!string.empty()) setWorldName( string );
|
||||
else setWorldName( attributeValue );
|
||||
app.DebugPrintf("LevelGenerationOptions: Adding parameter worldName=%ls\n", getWorldName());
|
||||
}
|
||||
else if(attributeName.compare(L"displayName") == 0)
|
||||
{
|
||||
std::wstring string(getString(attributeValue));
|
||||
if(!string.empty()) setDisplayName( string );
|
||||
else setDisplayName( attributeValue );
|
||||
app.DebugPrintf("LevelGenerationOptions: Adding parameter displayName=%ls\n", getDisplayName());
|
||||
}
|
||||
else if(attributeName.compare(L"texturePackId") == 0)
|
||||
{
|
||||
setRequiredTexturePackId( _fromString<unsigned int>(attributeValue) );
|
||||
setRequiresTexturePack( true );
|
||||
app.DebugPrintf("LevelGenerationOptions: Adding parameter texturePackId=%0x\n", getRequiredTexturePackId());
|
||||
}
|
||||
else if(attributeName.compare(L"isTutorial") == 0)
|
||||
{
|
||||
if(attributeValue.compare(L"true") == 0) setSrc(eSrc_tutorial);
|
||||
app.DebugPrintf("LevelGenerationOptions: Adding parameter isTutorial=%s\n",isTutorial()?"TRUE":"FALSE");
|
||||
}
|
||||
else if(attributeName.compare(L"baseSaveName") == 0)
|
||||
{
|
||||
setBaseSavePath( attributeValue );
|
||||
app.DebugPrintf("LevelGenerationOptions: Adding parameter baseSaveName=%ls\n", getBaseSavePath().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
GameRuleDefinition::addAttribute(attributeName, attributeValue);
|
||||
}
|
||||
void LevelGenerationOptions::addAttribute(const std::wstring& attributeName,
|
||||
const std::wstring& attributeValue) {
|
||||
if (attributeName.compare(L"seed") == 0) {
|
||||
m_seed = _fromString<__int64>(attributeValue);
|
||||
app.DebugPrintf(
|
||||
"LevelGenerationOptions: Adding parameter m_seed=%I64d\n", m_seed);
|
||||
} else if (attributeName.compare(L"spawnX") == 0) {
|
||||
if (m_spawnPos == NULL) m_spawnPos = new Pos();
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_spawnPos->x = value;
|
||||
app.DebugPrintf("LevelGenerationOptions: Adding parameter spawnX=%d\n",
|
||||
value);
|
||||
} else if (attributeName.compare(L"spawnY") == 0) {
|
||||
if (m_spawnPos == NULL) m_spawnPos = new Pos();
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_spawnPos->y = value;
|
||||
app.DebugPrintf("LevelGenerationOptions: Adding parameter spawnY=%d\n",
|
||||
value);
|
||||
} else if (attributeName.compare(L"spawnZ") == 0) {
|
||||
if (m_spawnPos == NULL) m_spawnPos = new Pos();
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_spawnPos->z = value;
|
||||
app.DebugPrintf("LevelGenerationOptions: Adding parameter spawnZ=%d\n",
|
||||
value);
|
||||
} else if (attributeName.compare(L"flatworld") == 0) {
|
||||
if (attributeValue.compare(L"true") == 0) m_useFlatWorld = true;
|
||||
app.DebugPrintf(
|
||||
"LevelGenerationOptions: Adding parameter flatworld=%s\n",
|
||||
m_useFlatWorld ? "TRUE" : "FALSE");
|
||||
} else if (attributeName.compare(L"saveName") == 0) {
|
||||
std::wstring string(getString(attributeValue));
|
||||
if (!string.empty())
|
||||
setDefaultSaveName(string);
|
||||
else
|
||||
setDefaultSaveName(attributeValue);
|
||||
app.DebugPrintf(
|
||||
"LevelGenerationOptions: Adding parameter saveName=%ls\n",
|
||||
getDefaultSaveName().c_str());
|
||||
} else if (attributeName.compare(L"worldName") == 0) {
|
||||
std::wstring string(getString(attributeValue));
|
||||
if (!string.empty())
|
||||
setWorldName(string);
|
||||
else
|
||||
setWorldName(attributeValue);
|
||||
app.DebugPrintf(
|
||||
"LevelGenerationOptions: Adding parameter worldName=%ls\n",
|
||||
getWorldName());
|
||||
} else if (attributeName.compare(L"displayName") == 0) {
|
||||
std::wstring string(getString(attributeValue));
|
||||
if (!string.empty())
|
||||
setDisplayName(string);
|
||||
else
|
||||
setDisplayName(attributeValue);
|
||||
app.DebugPrintf(
|
||||
"LevelGenerationOptions: Adding parameter displayName=%ls\n",
|
||||
getDisplayName());
|
||||
} else if (attributeName.compare(L"texturePackId") == 0) {
|
||||
setRequiredTexturePackId(_fromString<unsigned int>(attributeValue));
|
||||
setRequiresTexturePack(true);
|
||||
app.DebugPrintf(
|
||||
"LevelGenerationOptions: Adding parameter texturePackId=%0x\n",
|
||||
getRequiredTexturePackId());
|
||||
} else if (attributeName.compare(L"isTutorial") == 0) {
|
||||
if (attributeValue.compare(L"true") == 0) setSrc(eSrc_tutorial);
|
||||
app.DebugPrintf(
|
||||
"LevelGenerationOptions: Adding parameter isTutorial=%s\n",
|
||||
isTutorial() ? "TRUE" : "FALSE");
|
||||
} else if (attributeName.compare(L"baseSaveName") == 0) {
|
||||
setBaseSavePath(attributeValue);
|
||||
app.DebugPrintf(
|
||||
"LevelGenerationOptions: Adding parameter baseSaveName=%ls\n",
|
||||
getBaseSavePath().c_str());
|
||||
} else {
|
||||
GameRuleDefinition::addAttribute(attributeName, attributeValue);
|
||||
}
|
||||
}
|
||||
|
||||
void LevelGenerationOptions::processSchematics(LevelChunk *chunk)
|
||||
{
|
||||
PIXBeginNamedEvent(0,"Processing schematics for chunk (%d,%d)", 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);
|
||||
for( AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end();++it)
|
||||
{
|
||||
ApplySchematicRuleDefinition *rule = *it;
|
||||
rule->processSchematic(chunkBox, chunk);
|
||||
}
|
||||
void LevelGenerationOptions::processSchematics(LevelChunk* chunk) {
|
||||
PIXBeginNamedEvent(0, "Processing schematics for chunk (%d,%d)", 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);
|
||||
for (AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end();
|
||||
++it) {
|
||||
ApplySchematicRuleDefinition* rule = *it;
|
||||
rule->processSchematic(chunkBox, chunk);
|
||||
}
|
||||
|
||||
// 4jcraft added cast to unsigned
|
||||
int cx = ((unsigned)chunk->x << 4);
|
||||
int cz = ((unsigned)chunk->z << 4);
|
||||
// 4jcraft added cast to unsigned
|
||||
int cx = ((unsigned)chunk->x << 4);
|
||||
int cz = ((unsigned)chunk->z << 4);
|
||||
|
||||
for( AUTO_VAR(it, m_structureRules.begin()); it != m_structureRules.end(); it++ )
|
||||
{
|
||||
ConsoleGenerateStructure *structureStart = *it;
|
||||
for (AUTO_VAR(it, m_structureRules.begin()); it != m_structureRules.end();
|
||||
it++) {
|
||||
ConsoleGenerateStructure* structureStart = *it;
|
||||
|
||||
if (structureStart->getBoundingBox()->intersects(cx, cz, cx + 15, cz + 15))
|
||||
{
|
||||
BoundingBox *bb = new BoundingBox(cx, cz, cx + 15, cz + 15);
|
||||
structureStart->postProcess(chunk->level, NULL, bb);
|
||||
delete bb;
|
||||
}
|
||||
}
|
||||
PIXEndNamedEvent();
|
||||
if (structureStart->getBoundingBox()->intersects(cx, cz, cx + 15,
|
||||
cz + 15)) {
|
||||
BoundingBox* bb = new BoundingBox(cx, cz, cx + 15, cz + 15);
|
||||
structureStart->postProcess(chunk->level, NULL, bb);
|
||||
delete bb;
|
||||
}
|
||||
}
|
||||
PIXEndNamedEvent();
|
||||
}
|
||||
|
||||
void LevelGenerationOptions::processSchematicsLighting(LevelChunk *chunk)
|
||||
{
|
||||
PIXBeginNamedEvent(0,"Processing schematics (lighting) for chunk (%d,%d)", 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);
|
||||
for( AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end();++it)
|
||||
{
|
||||
ApplySchematicRuleDefinition *rule = *it;
|
||||
rule->processSchematicLighting(chunkBox, chunk);
|
||||
}
|
||||
PIXEndNamedEvent();
|
||||
void LevelGenerationOptions::processSchematicsLighting(LevelChunk* chunk) {
|
||||
PIXBeginNamedEvent(0, "Processing schematics (lighting) for chunk (%d,%d)",
|
||||
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);
|
||||
for (AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end();
|
||||
++it) {
|
||||
ApplySchematicRuleDefinition* rule = *it;
|
||||
rule->processSchematicLighting(chunkBox, chunk);
|
||||
}
|
||||
PIXEndNamedEvent();
|
||||
}
|
||||
|
||||
bool LevelGenerationOptions::checkIntersects(int x0, int y0, int z0, int x1, int y1, int z1)
|
||||
{
|
||||
PIXBeginNamedEvent(0,"Check Intersects");
|
||||
bool LevelGenerationOptions::checkIntersects(int x0, int y0, int z0, int x1,
|
||||
int y1, int z1) {
|
||||
PIXBeginNamedEvent(0, "Check Intersects");
|
||||
|
||||
// As an optimisation, we can quickly discard things below a certain y which makes most ore checks faster due to
|
||||
// a) ores generally being below ground/sea level and b) tutorial world additions generally being above ground/sea level
|
||||
if(!m_bHaveMinY)
|
||||
{
|
||||
for(AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end();++it)
|
||||
{
|
||||
ApplySchematicRuleDefinition *rule = *it;
|
||||
int minY = rule->getMinY();
|
||||
if(minY < m_minY) m_minY = minY;
|
||||
}
|
||||
// As an optimisation, we can quickly discard things below a certain y which
|
||||
// makes most ore checks faster due to a) ores generally being below
|
||||
// ground/sea level and b) tutorial world additions generally being above
|
||||
// ground/sea level
|
||||
if (!m_bHaveMinY) {
|
||||
for (AUTO_VAR(it, m_schematicRules.begin());
|
||||
it != m_schematicRules.end(); ++it) {
|
||||
ApplySchematicRuleDefinition* rule = *it;
|
||||
int minY = rule->getMinY();
|
||||
if (minY < m_minY) m_minY = minY;
|
||||
}
|
||||
|
||||
for( AUTO_VAR(it, m_structureRules.begin()); it != m_structureRules.end(); it++ )
|
||||
{
|
||||
ConsoleGenerateStructure *structureStart = *it;
|
||||
int minY = structureStart->getMinY();
|
||||
if(minY < m_minY) m_minY = minY;
|
||||
}
|
||||
for (AUTO_VAR(it, m_structureRules.begin());
|
||||
it != m_structureRules.end(); it++) {
|
||||
ConsoleGenerateStructure* structureStart = *it;
|
||||
int minY = structureStart->getMinY();
|
||||
if (minY < m_minY) m_minY = minY;
|
||||
}
|
||||
|
||||
m_bHaveMinY = true;
|
||||
}
|
||||
|
||||
// 4J Stu - We DO NOT intersect if our upper bound is below the lower bound for all schematics
|
||||
if( y1 < m_minY ) return false;
|
||||
m_bHaveMinY = true;
|
||||
}
|
||||
|
||||
bool intersects = false;
|
||||
for(AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end();++it)
|
||||
{
|
||||
ApplySchematicRuleDefinition *rule = *it;
|
||||
intersects = rule->checkIntersects(x0,y0,z0,x1,y1,z1);
|
||||
if(intersects) break;
|
||||
}
|
||||
// 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(!intersects)
|
||||
{
|
||||
for( AUTO_VAR(it, m_structureRules.begin()); it != m_structureRules.end(); it++ )
|
||||
{
|
||||
ConsoleGenerateStructure *structureStart = *it;
|
||||
intersects = structureStart->checkIntersects(x0,y0,z0,x1,y1,z1);
|
||||
if(intersects) break;
|
||||
}
|
||||
}
|
||||
PIXEndNamedEvent();
|
||||
return intersects;
|
||||
bool intersects = false;
|
||||
for (AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end();
|
||||
++it) {
|
||||
ApplySchematicRuleDefinition* rule = *it;
|
||||
intersects = rule->checkIntersects(x0, y0, z0, x1, y1, z1);
|
||||
if (intersects) break;
|
||||
}
|
||||
|
||||
if (!intersects) {
|
||||
for (AUTO_VAR(it, m_structureRules.begin());
|
||||
it != m_structureRules.end(); it++) {
|
||||
ConsoleGenerateStructure* structureStart = *it;
|
||||
intersects =
|
||||
structureStart->checkIntersects(x0, y0, z0, x1, y1, z1);
|
||||
if (intersects) break;
|
||||
}
|
||||
}
|
||||
PIXEndNamedEvent();
|
||||
return intersects;
|
||||
}
|
||||
|
||||
void LevelGenerationOptions::clearSchematics()
|
||||
{
|
||||
for(AUTO_VAR(it, m_schematics.begin()); it != m_schematics.end(); ++it)
|
||||
{
|
||||
delete it->second;
|
||||
}
|
||||
m_schematics.clear();
|
||||
void LevelGenerationOptions::clearSchematics() {
|
||||
for (AUTO_VAR(it, m_schematics.begin()); it != m_schematics.end(); ++it) {
|
||||
delete it->second;
|
||||
}
|
||||
m_schematics.clear();
|
||||
}
|
||||
|
||||
ConsoleSchematicFile *LevelGenerationOptions::loadSchematicFile(const std::wstring &filename, std::uint8_t *pbData, unsigned int dataLength)
|
||||
{
|
||||
// If we have already loaded this, just return
|
||||
AUTO_VAR(it, m_schematics.find(filename));
|
||||
if(it != m_schematics.end())
|
||||
{
|
||||
ConsoleSchematicFile* LevelGenerationOptions::loadSchematicFile(
|
||||
const std::wstring& filename, std::uint8_t* pbData,
|
||||
unsigned int dataLength) {
|
||||
// If we have already loaded this, just return
|
||||
AUTO_VAR(it, m_schematics.find(filename));
|
||||
if (it != m_schematics.end()) {
|
||||
#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
|
||||
it->second->incrementRefCount();
|
||||
return it->second;
|
||||
}
|
||||
it->second->incrementRefCount();
|
||||
return it->second;
|
||||
}
|
||||
|
||||
ConsoleSchematicFile *schematic = NULL;
|
||||
byteArray data(pbData, dataLength);
|
||||
ByteArrayInputStream bais(data);
|
||||
DataInputStream dis(&bais);
|
||||
schematic = new ConsoleSchematicFile();
|
||||
schematic->load(&dis);
|
||||
m_schematics[filename] = schematic;
|
||||
bais.reset();
|
||||
return schematic;
|
||||
ConsoleSchematicFile* schematic = NULL;
|
||||
byteArray data(pbData, dataLength);
|
||||
ByteArrayInputStream bais(data);
|
||||
DataInputStream dis(&bais);
|
||||
schematic = new ConsoleSchematicFile();
|
||||
schematic->load(&dis);
|
||||
m_schematics[filename] = schematic;
|
||||
bais.reset();
|
||||
return schematic;
|
||||
}
|
||||
|
||||
ConsoleSchematicFile *LevelGenerationOptions::getSchematicFile(const std::wstring &filename)
|
||||
{
|
||||
ConsoleSchematicFile *schematic = NULL;
|
||||
// If we have already loaded this, just return
|
||||
AUTO_VAR(it, m_schematics.find(filename));
|
||||
if(it != m_schematics.end())
|
||||
{
|
||||
schematic = it->second;
|
||||
}
|
||||
return schematic;
|
||||
ConsoleSchematicFile* LevelGenerationOptions::getSchematicFile(
|
||||
const std::wstring& filename) {
|
||||
ConsoleSchematicFile* schematic = NULL;
|
||||
// If we have already loaded this, just return
|
||||
AUTO_VAR(it, m_schematics.find(filename));
|
||||
if (it != m_schematics.end()) {
|
||||
schematic = it->second;
|
||||
}
|
||||
return schematic;
|
||||
}
|
||||
|
||||
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
|
||||
//AUTO_VAR(it, m_schematics.find(filename));
|
||||
//if(it != m_schematics.end())
|
||||
//{
|
||||
// ConsoleSchematicFile *schematic = it->second;
|
||||
// schematic->decrementRefCount();
|
||||
// if(schematic->shouldDelete())
|
||||
// {
|
||||
// delete schematic;
|
||||
// m_schematics.erase(it);
|
||||
// }
|
||||
//}
|
||||
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
|
||||
// AUTO_VAR(it, m_schematics.find(filename));
|
||||
// if(it != m_schematics.end())
|
||||
//{
|
||||
// ConsoleSchematicFile *schematic = it->second;
|
||||
// schematic->decrementRefCount();
|
||||
// if(schematic->shouldDelete())
|
||||
// {
|
||||
// delete schematic;
|
||||
// m_schematics.erase(it);
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
void LevelGenerationOptions::loadStringTable(StringTable *table)
|
||||
{
|
||||
m_stringTable = table;
|
||||
void LevelGenerationOptions::loadStringTable(StringTable* table) {
|
||||
m_stringTable = table;
|
||||
}
|
||||
|
||||
const wchar_t *LevelGenerationOptions::getString(const std::wstring &key)
|
||||
{
|
||||
if(m_stringTable == NULL)
|
||||
{
|
||||
return L"";
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_stringTable->getString(key);
|
||||
}
|
||||
const wchar_t* LevelGenerationOptions::getString(const std::wstring& key) {
|
||||
if (m_stringTable == NULL) {
|
||||
return L"";
|
||||
} else {
|
||||
return m_stringTable->getString(key);
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
BiomeOverride *bo = *it;
|
||||
if(bo->isBiome(biomeId))
|
||||
{
|
||||
bo->getTileValues(tile,topTile);
|
||||
break;
|
||||
}
|
||||
}
|
||||
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) {
|
||||
BiomeOverride* bo = *it;
|
||||
if (bo->isBiome(biomeId)) {
|
||||
bo->getTileValues(tile, topTile);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool LevelGenerationOptions::isFeatureChunk(int chunkX, int chunkZ, StructureFeature::EFeatureTypes feature)
|
||||
{
|
||||
bool isFeature = false;
|
||||
bool LevelGenerationOptions::isFeatureChunk(
|
||||
int chunkX, int chunkZ, StructureFeature::EFeatureTypes feature) {
|
||||
bool isFeature = false;
|
||||
|
||||
for(AUTO_VAR(it, m_features.begin()); it != m_features.end(); ++it)
|
||||
{
|
||||
StartFeature *sf = *it;
|
||||
if(sf->isFeatureChunk(chunkX, chunkZ, feature))
|
||||
{
|
||||
isFeature = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return isFeature;
|
||||
for (AUTO_VAR(it, m_features.begin()); it != m_features.end(); ++it) {
|
||||
StartFeature* sf = *it;
|
||||
if (sf->isFeatureChunk(chunkX, chunkZ, feature)) {
|
||||
isFeature = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return isFeature;
|
||||
}
|
||||
|
||||
std::unordered_map<std::wstring, ConsoleSchematicFile *> *LevelGenerationOptions::getUnfinishedSchematicFiles()
|
||||
{
|
||||
// Clean schematic rules.
|
||||
std::unordered_set<std::wstring> usedFiles = std::unordered_set<std::wstring>();
|
||||
for (AUTO_VAR(it, m_schematicRules.begin()); it!=m_schematicRules.end(); it++)
|
||||
if ( !(*it)->isComplete() )
|
||||
usedFiles.insert( (*it)->getSchematicName() );
|
||||
std::unordered_map<std::wstring, ConsoleSchematicFile*>*
|
||||
LevelGenerationOptions::getUnfinishedSchematicFiles() {
|
||||
// Clean schematic rules.
|
||||
std::unordered_set<std::wstring> usedFiles =
|
||||
std::unordered_set<std::wstring>();
|
||||
for (AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end();
|
||||
it++)
|
||||
if (!(*it)->isComplete()) usedFiles.insert((*it)->getSchematicName());
|
||||
|
||||
// Clean schematic files.
|
||||
std::unordered_map<std::wstring, ConsoleSchematicFile *> *out
|
||||
= new std::unordered_map<std::wstring, ConsoleSchematicFile *>();
|
||||
for (AUTO_VAR(it, usedFiles.begin()); it!=usedFiles.end(); it++)
|
||||
out->insert( std::pair<std::wstring, ConsoleSchematicFile *>(*it, getSchematicFile(*it)) );
|
||||
|
||||
return out;
|
||||
// Clean schematic files.
|
||||
std::unordered_map<std::wstring, ConsoleSchematicFile*>* out =
|
||||
new std::unordered_map<std::wstring, ConsoleSchematicFile*>();
|
||||
for (AUTO_VAR(it, usedFiles.begin()); it != usedFiles.end(); it++)
|
||||
out->insert(std::pair<std::wstring, ConsoleSchematicFile*>(
|
||||
*it, getSchematicFile(*it)));
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
void LevelGenerationOptions::reset_start()
|
||||
{
|
||||
for ( AUTO_VAR( it, m_schematicRules.begin());
|
||||
it != m_schematicRules.end();
|
||||
it++ )
|
||||
{
|
||||
(*it)->reset();
|
||||
}
|
||||
void LevelGenerationOptions::reset_start() {
|
||||
for (AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end();
|
||||
it++) {
|
||||
(*it)->reset();
|
||||
}
|
||||
}
|
||||
|
||||
void LevelGenerationOptions::reset_finish()
|
||||
{
|
||||
//if (m_spawnPos) { delete m_spawnPos; m_spawnPos = NULL; }
|
||||
//if (m_stringTable) { delete m_stringTable; m_stringTable = NULL; }
|
||||
void LevelGenerationOptions::reset_finish() {
|
||||
// if (m_spawnPos) { delete m_spawnPos; m_spawnPos
|
||||
// = NULL; } if (m_stringTable) { delete m_stringTable;
|
||||
// m_stringTable = NULL; }
|
||||
|
||||
if (isFromDLC())
|
||||
{
|
||||
m_hasLoadedData = false;
|
||||
}
|
||||
if (isFromDLC()) {
|
||||
m_hasLoadedData = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
GrSource *LevelGenerationOptions::info() { return m_pSrc; }
|
||||
GrSource* LevelGenerationOptions::info() { return m_pSrc; }
|
||||
void LevelGenerationOptions::setSrc(eSrc src) { m_src = src; }
|
||||
LevelGenerationOptions::eSrc LevelGenerationOptions::getSrc() { return m_src; }
|
||||
|
||||
|
|
@ -477,39 +477,89 @@ bool LevelGenerationOptions::isTutorial() { return getSrc() == eSrc_tutorial; }
|
|||
bool LevelGenerationOptions::isFromSave() { return getSrc() == eSrc_fromSave; }
|
||||
bool LevelGenerationOptions::isFromDLC() { return getSrc() == eSrc_fromDLC; }
|
||||
|
||||
bool LevelGenerationOptions::requiresTexturePack() { return info()->requiresTexturePack(); }
|
||||
std::uint32_t LevelGenerationOptions::getRequiredTexturePackId() { return info()->getRequiredTexturePackId(); }
|
||||
std::wstring LevelGenerationOptions::getDefaultSaveName() { 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(); }
|
||||
bool LevelGenerationOptions::requiresTexturePack() {
|
||||
return info()->requiresTexturePack();
|
||||
}
|
||||
std::uint32_t LevelGenerationOptions::getRequiredTexturePackId() {
|
||||
return info()->getRequiredTexturePackId();
|
||||
}
|
||||
std::wstring LevelGenerationOptions::getDefaultSaveName() {
|
||||
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::setRequiredTexturePackId(std::uint32_t x) { info()->setRequiredTexturePackId(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); }
|
||||
void LevelGenerationOptions::setRequiresTexturePack(bool x) {
|
||||
info()->setRequiresTexturePack(x);
|
||||
}
|
||||
void LevelGenerationOptions::setRequiredTexturePackId(std::uint32_t x) {
|
||||
info()->setRequiredTexturePackId(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(); }
|
||||
|
||||
void LevelGenerationOptions::setBaseSaveData(std::uint8_t *pbData, unsigned int dataSize) { m_pbBaseSaveData = pbData; 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; }
|
||||
void LevelGenerationOptions::setBaseSaveData(std::uint8_t* pbData,
|
||||
unsigned int dataSize) {
|
||||
m_pbBaseSaveData = pbData;
|
||||
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; }
|
||||
void LevelGenerationOptions::setLoadedData() { m_hasLoadedData = true; }
|
||||
|
||||
__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::requiresGameRules() { return m_bRequiresGameRules; }
|
||||
void LevelGenerationOptions::setRequiredGameRules(LevelRuleset *rules) { m_requiredGameRules = rules; m_bRequiresGameRules = true; }
|
||||
LevelRuleset *LevelGenerationOptions::getRequiredGameRules() { return m_requiredGameRules; }
|
||||
bool LevelGenerationOptions::requiresGameRules() {
|
||||
return m_bRequiresGameRules;
|
||||
}
|
||||
void LevelGenerationOptions::setRequiredGameRules(LevelRuleset* rules) {
|
||||
m_requiredGameRules = rules;
|
||||
m_bRequiresGameRules = true;
|
||||
}
|
||||
LevelRuleset* LevelGenerationOptions::getRequiredGameRules() {
|
||||
return m_requiredGameRules;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#pragma once
|
||||
//using namespace std;
|
||||
// using namespace std;
|
||||
|
||||
// #pragma message("LevelGenerationOptions.h ")
|
||||
|
||||
|
|
@ -16,204 +16,209 @@ class LevelRuleset;
|
|||
class BiomeOverride;
|
||||
class StartFeature;
|
||||
|
||||
class GrSource
|
||||
{
|
||||
class GrSource {
|
||||
public:
|
||||
// 4J-JEV:
|
||||
// Moved all this here; I didn't like that all this header information
|
||||
// was being mixed in with all the game information as they have
|
||||
// completely different lifespans.
|
||||
// 4J-JEV:
|
||||
// Moved all this here; I didn't like that all this header information
|
||||
// was being mixed in with all the game information as they have
|
||||
// completely different lifespans.
|
||||
|
||||
virtual ~GrSource(){}
|
||||
virtual bool requiresTexturePack()=0;
|
||||
virtual std::uint32_t getRequiredTexturePackId()=0;
|
||||
virtual std::wstring getDefaultSaveName()=0;
|
||||
virtual const wchar_t *getWorldName()=0;
|
||||
virtual const wchar_t *getDisplayName()=0;
|
||||
virtual std::wstring getGrfPath()=0;
|
||||
virtual bool requiresBaseSave() = 0;
|
||||
virtual std::wstring getBaseSavePath() = 0;
|
||||
virtual ~GrSource() {}
|
||||
virtual bool requiresTexturePack() = 0;
|
||||
virtual std::uint32_t getRequiredTexturePackId() = 0;
|
||||
virtual std::wstring getDefaultSaveName() = 0;
|
||||
virtual const wchar_t* getWorldName() = 0;
|
||||
virtual const wchar_t* getDisplayName() = 0;
|
||||
virtual std::wstring getGrfPath() = 0;
|
||||
virtual bool requiresBaseSave() = 0;
|
||||
virtual std::wstring getBaseSavePath() = 0;
|
||||
|
||||
virtual void setRequiresTexturePack(bool)=0;
|
||||
virtual void setRequiredTexturePackId(std::uint32_t)=0;
|
||||
virtual void setDefaultSaveName(const std::wstring &)=0;
|
||||
virtual void setWorldName(const std::wstring &)=0;
|
||||
virtual void setDisplayName(const std::wstring &)=0;
|
||||
virtual void setGrfPath(const std::wstring &)=0;
|
||||
virtual void setBaseSavePath(const std::wstring &)=0;
|
||||
virtual void setRequiresTexturePack(bool) = 0;
|
||||
virtual void setRequiredTexturePackId(std::uint32_t) = 0;
|
||||
virtual void setDefaultSaveName(const std::wstring&) = 0;
|
||||
virtual void setWorldName(const std::wstring&) = 0;
|
||||
virtual void setDisplayName(const std::wstring&) = 0;
|
||||
virtual void setGrfPath(const std::wstring&) = 0;
|
||||
virtual void setBaseSavePath(const std::wstring&) = 0;
|
||||
|
||||
virtual bool ready()=0;
|
||||
virtual bool ready() = 0;
|
||||
|
||||
//virtual void getGrfData(std::uint8_t *&pData, unsigned int &pSize)=0;
|
||||
// virtual void getGrfData(std::uint8_t *&pData, unsigned int &pSize)=0;
|
||||
};
|
||||
|
||||
class JustGrSource : public GrSource
|
||||
{
|
||||
class JustGrSource : public GrSource {
|
||||
protected:
|
||||
std::wstring m_worldName;
|
||||
std::wstring m_displayName;
|
||||
std::wstring m_defaultSaveName;
|
||||
bool m_bRequiresTexturePack;
|
||||
std::uint32_t m_requiredTexturePackId;
|
||||
std::wstring m_grfPath;
|
||||
std::wstring m_baseSavePath;
|
||||
bool m_bRequiresBaseSave;
|
||||
std::wstring m_worldName;
|
||||
std::wstring m_displayName;
|
||||
std::wstring m_defaultSaveName;
|
||||
bool m_bRequiresTexturePack;
|
||||
std::uint32_t m_requiredTexturePackId;
|
||||
std::wstring m_grfPath;
|
||||
std::wstring m_baseSavePath;
|
||||
bool m_bRequiresBaseSave;
|
||||
|
||||
public:
|
||||
virtual bool requiresTexturePack();
|
||||
virtual std::uint32_t getRequiredTexturePackId();
|
||||
virtual std::wstring getDefaultSaveName();
|
||||
virtual const wchar_t *getWorldName();
|
||||
virtual const wchar_t *getDisplayName();
|
||||
virtual std::wstring getGrfPath();
|
||||
virtual bool requiresBaseSave();
|
||||
virtual std::wstring getBaseSavePath();
|
||||
virtual bool requiresTexturePack();
|
||||
virtual std::uint32_t getRequiredTexturePackId();
|
||||
virtual std::wstring getDefaultSaveName();
|
||||
virtual const wchar_t* getWorldName();
|
||||
virtual const wchar_t* getDisplayName();
|
||||
virtual std::wstring getGrfPath();
|
||||
virtual bool requiresBaseSave();
|
||||
virtual std::wstring getBaseSavePath();
|
||||
|
||||
virtual void setRequiresTexturePack(bool x);
|
||||
virtual void setRequiredTexturePackId(std::uint32_t x);
|
||||
virtual void setDefaultSaveName(const std::wstring &x);
|
||||
virtual void setWorldName(const std::wstring &x);
|
||||
virtual void setDisplayName(const std::wstring &x);
|
||||
virtual void setGrfPath(const std::wstring &x);
|
||||
virtual void setBaseSavePath(const std::wstring &x);
|
||||
virtual void setRequiresTexturePack(bool x);
|
||||
virtual void setRequiredTexturePackId(std::uint32_t x);
|
||||
virtual void setDefaultSaveName(const std::wstring& x);
|
||||
virtual void setWorldName(const std::wstring& x);
|
||||
virtual void setDisplayName(const std::wstring& x);
|
||||
virtual void setGrfPath(const std::wstring& x);
|
||||
virtual void setBaseSavePath(const std::wstring& x);
|
||||
|
||||
virtual bool ready();
|
||||
virtual bool ready();
|
||||
|
||||
JustGrSource();
|
||||
JustGrSource();
|
||||
};
|
||||
|
||||
class LevelGenerationOptions : public GameRuleDefinition
|
||||
{
|
||||
class LevelGenerationOptions : public GameRuleDefinition {
|
||||
public:
|
||||
enum eSrc
|
||||
{
|
||||
eSrc_none,
|
||||
enum eSrc {
|
||||
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
|
||||
};
|
||||
|
||||
private:
|
||||
eSrc m_src;
|
||||
eSrc m_src;
|
||||
|
||||
GrSource *m_pSrc;
|
||||
GrSource *info();
|
||||
GrSource* m_pSrc;
|
||||
GrSource* info();
|
||||
|
||||
bool m_hasLoadedData;
|
||||
bool m_hasLoadedData;
|
||||
|
||||
std::uint8_t *m_pbBaseSaveData;
|
||||
unsigned int m_baseSaveSize;
|
||||
std::uint8_t* m_pbBaseSaveData;
|
||||
unsigned int m_baseSaveSize;
|
||||
|
||||
public:
|
||||
void setSrc(eSrc src);
|
||||
eSrc getSrc();
|
||||
|
||||
void setSrc(eSrc src);
|
||||
eSrc getSrc();
|
||||
bool isTutorial();
|
||||
bool isFromSave();
|
||||
bool isFromDLC();
|
||||
|
||||
bool isTutorial();
|
||||
bool isFromSave();
|
||||
bool isFromDLC();
|
||||
bool requiresTexturePack();
|
||||
std::uint32_t getRequiredTexturePackId();
|
||||
std::wstring getDefaultSaveName();
|
||||
const wchar_t* getWorldName();
|
||||
const wchar_t* getDisplayName();
|
||||
std::wstring getGrfPath();
|
||||
bool requiresBaseSave();
|
||||
std::wstring getBaseSavePath();
|
||||
|
||||
bool requiresTexturePack();
|
||||
std::uint32_t getRequiredTexturePackId();
|
||||
std::wstring getDefaultSaveName();
|
||||
const wchar_t *getWorldName();
|
||||
const wchar_t *getDisplayName();
|
||||
std::wstring getGrfPath();
|
||||
bool requiresBaseSave();
|
||||
std::wstring getBaseSavePath();
|
||||
void setGrSource(GrSource* grs);
|
||||
|
||||
void setGrSource(GrSource *grs);
|
||||
void setRequiresTexturePack(bool x);
|
||||
void setRequiredTexturePackId(std::uint32_t x);
|
||||
void setDefaultSaveName(const std::wstring& x);
|
||||
void setWorldName(const std::wstring& x);
|
||||
void setDisplayName(const std::wstring& x);
|
||||
void setGrfPath(const std::wstring& x);
|
||||
void setBaseSavePath(const std::wstring& x);
|
||||
|
||||
void setRequiresTexturePack(bool x);
|
||||
void setRequiredTexturePackId(std::uint32_t x);
|
||||
void setDefaultSaveName(const std::wstring &x);
|
||||
void setWorldName(const std::wstring &x);
|
||||
void setDisplayName(const std::wstring &x);
|
||||
void setGrfPath(const std::wstring &x);
|
||||
void setBaseSavePath(const std::wstring &x);
|
||||
bool ready();
|
||||
|
||||
bool ready();
|
||||
void setBaseSaveData(std::uint8_t* pbData, unsigned int dataSize);
|
||||
std::uint8_t* getBaseSaveData(unsigned int& size);
|
||||
bool hasBaseSaveData();
|
||||
void deleteBaseSaveData();
|
||||
|
||||
void setBaseSaveData(std::uint8_t *pbData, unsigned int dataSize);
|
||||
std::uint8_t *getBaseSaveData(unsigned int &size);
|
||||
bool hasBaseSaveData();
|
||||
void deleteBaseSaveData();
|
||||
|
||||
bool hasLoadedData();
|
||||
void setLoadedData();
|
||||
bool hasLoadedData();
|
||||
void setLoadedData();
|
||||
|
||||
private:
|
||||
// This should match the "MapOptionsRule" definition in the XML schema
|
||||
__int64 m_seed;
|
||||
bool m_useFlatWorld;
|
||||
Pos *m_spawnPos;
|
||||
std::vector<ApplySchematicRuleDefinition *> m_schematicRules;
|
||||
std::vector<ConsoleGenerateStructure *> m_structureRules;
|
||||
bool m_bHaveMinY;
|
||||
int m_minY;
|
||||
std::unordered_map<std::wstring, ConsoleSchematicFile *> m_schematics;
|
||||
std::vector<BiomeOverride *> m_biomeOverrides;
|
||||
std::vector<StartFeature *> m_features;
|
||||
// This should match the "MapOptionsRule" definition in the XML schema
|
||||
__int64 m_seed;
|
||||
bool m_useFlatWorld;
|
||||
Pos* m_spawnPos;
|
||||
std::vector<ApplySchematicRuleDefinition*> m_schematicRules;
|
||||
std::vector<ConsoleGenerateStructure*> m_structureRules;
|
||||
bool m_bHaveMinY;
|
||||
int m_minY;
|
||||
std::unordered_map<std::wstring, ConsoleSchematicFile*> m_schematics;
|
||||
std::vector<BiomeOverride*> m_biomeOverrides;
|
||||
std::vector<StartFeature*> m_features;
|
||||
|
||||
bool m_bRequiresGameRules;
|
||||
LevelRuleset *m_requiredGameRules;
|
||||
bool m_bRequiresGameRules;
|
||||
LevelRuleset* m_requiredGameRules;
|
||||
|
||||
StringTable *m_stringTable;
|
||||
StringTable* m_stringTable;
|
||||
|
||||
public:
|
||||
LevelGenerationOptions();
|
||||
~LevelGenerationOptions();
|
||||
LevelGenerationOptions();
|
||||
~LevelGenerationOptions();
|
||||
|
||||
virtual ConsoleGameRules::EGameRuleType getActionType();
|
||||
|
||||
virtual void writeAttributes(DataOutputStream *dos, unsigned int numAttributes);
|
||||
virtual void getChildren(std::vector<GameRuleDefinition *> *children);
|
||||
virtual GameRuleDefinition *addChild(ConsoleGameRules::EGameRuleType ruleType);
|
||||
virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue);
|
||||
virtual ConsoleGameRules::EGameRuleType getActionType();
|
||||
|
||||
__int64 getLevelSeed();
|
||||
Pos *getSpawnPos();
|
||||
bool getuseFlatWorld();
|
||||
virtual void writeAttributes(DataOutputStream* dos,
|
||||
unsigned int numAttributes);
|
||||
virtual void getChildren(std::vector<GameRuleDefinition*>* children);
|
||||
virtual GameRuleDefinition* addChild(
|
||||
ConsoleGameRules::EGameRuleType ruleType);
|
||||
virtual void addAttribute(const std::wstring& attributeName,
|
||||
const std::wstring& attributeValue);
|
||||
|
||||
void processSchematics(LevelChunk *chunk);
|
||||
void processSchematicsLighting(LevelChunk *chunk);
|
||||
__int64 getLevelSeed();
|
||||
Pos* getSpawnPos();
|
||||
bool getuseFlatWorld();
|
||||
|
||||
bool checkIntersects(int x0, int y0, int z0, int x1, int y1, int z1);
|
||||
void processSchematics(LevelChunk* chunk);
|
||||
void processSchematicsLighting(LevelChunk* chunk);
|
||||
|
||||
bool checkIntersects(int x0, int y0, int z0, int x1, int y1, int z1);
|
||||
|
||||
private:
|
||||
void clearSchematics();
|
||||
|
||||
public:
|
||||
ConsoleSchematicFile *loadSchematicFile(const std::wstring &filename, std::uint8_t *pbData, unsigned int dataLength);
|
||||
void clearSchematics();
|
||||
|
||||
public:
|
||||
ConsoleSchematicFile *getSchematicFile(const std::wstring &filename);
|
||||
void releaseSchematicFile(const std::wstring &filename);
|
||||
ConsoleSchematicFile* loadSchematicFile(const std::wstring& filename,
|
||||
std::uint8_t* pbData,
|
||||
unsigned int dataLength);
|
||||
|
||||
bool requiresGameRules();
|
||||
void setRequiredGameRules(LevelRuleset *rules);
|
||||
LevelRuleset *getRequiredGameRules();
|
||||
public:
|
||||
ConsoleSchematicFile* getSchematicFile(const std::wstring& filename);
|
||||
void releaseSchematicFile(const std::wstring& filename);
|
||||
|
||||
void getBiomeOverride(int biomeId, std::uint8_t &tile, std::uint8_t &topTile);
|
||||
bool isFeatureChunk(int chunkX, int chunkZ, StructureFeature::EFeatureTypes feature);
|
||||
bool requiresGameRules();
|
||||
void setRequiredGameRules(LevelRuleset* rules);
|
||||
LevelRuleset* getRequiredGameRules();
|
||||
|
||||
void loadStringTable(StringTable *table);
|
||||
const wchar_t *getString(const std::wstring &key);
|
||||
void getBiomeOverride(int biomeId, std::uint8_t& tile,
|
||||
std::uint8_t& topTile);
|
||||
bool isFeatureChunk(int chunkX, int chunkZ,
|
||||
StructureFeature::EFeatureTypes feature);
|
||||
|
||||
std::unordered_map<std::wstring, ConsoleSchematicFile *> *getUnfinishedSchematicFiles();
|
||||
|
||||
// 4J-JEV:
|
||||
// ApplySchematicRules contain limited state
|
||||
// which needs to be reset BEFORE a new game starts.
|
||||
void reset_start();
|
||||
void loadStringTable(StringTable* table);
|
||||
const wchar_t* getString(const std::wstring& key);
|
||||
|
||||
// 4J-JEV:
|
||||
// This file contains state that needs to be deleted
|
||||
// or reset once a game has finished.
|
||||
void reset_finish();
|
||||
std::unordered_map<std::wstring, ConsoleSchematicFile*>*
|
||||
getUnfinishedSchematicFiles();
|
||||
|
||||
// 4J-JEV:
|
||||
// ApplySchematicRules contain limited state
|
||||
// which needs to be reset BEFORE a new game starts.
|
||||
void reset_start();
|
||||
|
||||
// 4J-JEV:
|
||||
// This file contains state that needs to be deleted
|
||||
// or reset once a game has finished.
|
||||
void reset_finish();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,25 +2,18 @@
|
|||
#include "LevelGenerationOptions.h"
|
||||
#include "LevelGenerators.h"
|
||||
|
||||
LevelGenerators::LevelGenerators() {}
|
||||
|
||||
LevelGenerators::LevelGenerators()
|
||||
{
|
||||
void LevelGenerators::addLevelGenerator(const std::wstring& displayName,
|
||||
LevelGenerationOptions* generator) {
|
||||
if (!displayName.empty()) generator->setDisplayName(displayName);
|
||||
m_levelGenerators.push_back(generator);
|
||||
}
|
||||
|
||||
void LevelGenerators::addLevelGenerator(const std::wstring &displayName, LevelGenerationOptions *generator)
|
||||
{
|
||||
if(!displayName.empty()) generator->setDisplayName(displayName);
|
||||
m_levelGenerators.push_back(generator);
|
||||
}
|
||||
|
||||
void LevelGenerators::removeLevelGenerator(LevelGenerationOptions *generator)
|
||||
{
|
||||
std::vector<LevelGenerationOptions *>::iterator it;
|
||||
while ( (it = find( m_levelGenerators.begin(),
|
||||
m_levelGenerators.end(),
|
||||
generator ) )
|
||||
!= m_levelGenerators.end() )
|
||||
{
|
||||
m_levelGenerators.erase(it);
|
||||
}
|
||||
void LevelGenerators::removeLevelGenerator(LevelGenerationOptions* generator) {
|
||||
std::vector<LevelGenerationOptions*>::iterator it;
|
||||
while ((it = find(m_levelGenerators.begin(), m_levelGenerators.end(),
|
||||
generator)) != m_levelGenerators.end()) {
|
||||
m_levelGenerators.erase(it);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +1,21 @@
|
|||
#pragma once
|
||||
|
||||
//using namespace std;
|
||||
// using namespace std;
|
||||
|
||||
class LevelGenerationOptions;
|
||||
|
||||
class LevelGenerators
|
||||
{
|
||||
class LevelGenerators {
|
||||
private:
|
||||
std::vector<LevelGenerationOptions *> m_levelGenerators;
|
||||
std::vector<LevelGenerationOptions*> m_levelGenerators;
|
||||
|
||||
public:
|
||||
LevelGenerators();
|
||||
LevelGenerators();
|
||||
|
||||
void addLevelGenerator(const std::wstring &displayName, LevelGenerationOptions *generator);
|
||||
void removeLevelGenerator(LevelGenerationOptions *generator);
|
||||
void addLevelGenerator(const std::wstring& displayName,
|
||||
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 "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)
|
||||
{
|
||||
// TODO ?
|
||||
void LevelRules::removeLevelRule(LevelRuleset* removing) {
|
||||
// TODO ?
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@
|
|||
|
||||
class LevelRuleset;
|
||||
|
||||
class LevelRules
|
||||
{
|
||||
class LevelRules {
|
||||
public:
|
||||
LevelRules();
|
||||
LevelRules();
|
||||
|
||||
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, std::uint8_t* pbData,
|
||||
unsigned int dataLength);
|
||||
void addLevelRule(const std::wstring& displayName, LevelRuleset* rootRule);
|
||||
|
||||
void removeLevelRule(LevelRuleset *removing);
|
||||
void removeLevelRule(LevelRuleset* removing);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -4,68 +4,51 @@
|
|||
#include "ConsoleGameRules.h"
|
||||
#include "LevelRuleset.h"
|
||||
|
||||
LevelRuleset::LevelRuleset()
|
||||
{
|
||||
m_stringTable = NULL;
|
||||
LevelRuleset::LevelRuleset() { m_stringTable = NULL; }
|
||||
|
||||
LevelRuleset::~LevelRuleset() {
|
||||
for (AUTO_VAR(it, m_areas.begin()); it != m_areas.end(); ++it) {
|
||||
delete *it;
|
||||
}
|
||||
}
|
||||
|
||||
LevelRuleset::~LevelRuleset()
|
||||
{
|
||||
for(AUTO_VAR(it, m_areas.begin()); it != m_areas.end(); ++it)
|
||||
{
|
||||
delete *it;
|
||||
}
|
||||
void LevelRuleset::getChildren(std::vector<GameRuleDefinition*>* children) {
|
||||
CompoundGameRuleDefinition::getChildren(children);
|
||||
for (AUTO_VAR(it, m_areas.begin()); it != m_areas.end(); it++)
|
||||
children->push_back(*it);
|
||||
}
|
||||
|
||||
void LevelRuleset::getChildren(std::vector<GameRuleDefinition *> *children)
|
||||
{
|
||||
CompoundGameRuleDefinition::getChildren(children);
|
||||
for (AUTO_VAR(it, m_areas.begin()); it != m_areas.end(); it++)
|
||||
children->push_back(*it);
|
||||
GameRuleDefinition* LevelRuleset::addChild(
|
||||
ConsoleGameRules::EGameRuleType ruleType) {
|
||||
GameRuleDefinition* rule = NULL;
|
||||
if (ruleType == ConsoleGameRules::eGameRuleType_NamedArea) {
|
||||
rule = new NamedAreaRuleDefinition();
|
||||
m_areas.push_back((NamedAreaRuleDefinition*)rule);
|
||||
} else {
|
||||
rule = CompoundGameRuleDefinition::addChild(ruleType);
|
||||
}
|
||||
return rule;
|
||||
}
|
||||
|
||||
GameRuleDefinition *LevelRuleset::addChild(ConsoleGameRules::EGameRuleType ruleType)
|
||||
{
|
||||
GameRuleDefinition *rule = NULL;
|
||||
if(ruleType == ConsoleGameRules::eGameRuleType_NamedArea)
|
||||
{
|
||||
rule = new NamedAreaRuleDefinition();
|
||||
m_areas.push_back((NamedAreaRuleDefinition *)rule);
|
||||
}
|
||||
else
|
||||
{
|
||||
rule = CompoundGameRuleDefinition::addChild(ruleType);
|
||||
}
|
||||
return rule;
|
||||
void LevelRuleset::loadStringTable(StringTable* table) {
|
||||
m_stringTable = table;
|
||||
}
|
||||
|
||||
void LevelRuleset::loadStringTable(StringTable *table)
|
||||
{
|
||||
m_stringTable = table;
|
||||
const wchar_t* LevelRuleset::getString(const std::wstring& key) {
|
||||
if (m_stringTable == NULL) {
|
||||
return L"";
|
||||
} else {
|
||||
return m_stringTable->getString(key);
|
||||
}
|
||||
}
|
||||
|
||||
const wchar_t *LevelRuleset::getString(const std::wstring &key)
|
||||
{
|
||||
if(m_stringTable == NULL)
|
||||
{
|
||||
return L"";
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_stringTable->getString(key);
|
||||
}
|
||||
}
|
||||
|
||||
AABB *LevelRuleset::getNamedArea(const std::wstring &areaName)
|
||||
{
|
||||
AABB *area = NULL;
|
||||
for(AUTO_VAR(it, m_areas.begin()); it != m_areas.end(); ++it)
|
||||
{
|
||||
if( (*it)->getName().compare(areaName) == 0 )
|
||||
{
|
||||
area = (*it)->getArea();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return area;
|
||||
AABB* LevelRuleset::getNamedArea(const std::wstring& areaName) {
|
||||
AABB* area = NULL;
|
||||
for (AUTO_VAR(it, m_areas.begin()); it != m_areas.end(); ++it) {
|
||||
if ((*it)->getName().compare(areaName) == 0) {
|
||||
area = (*it)->getArea();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return area;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,24 +4,27 @@
|
|||
|
||||
class NamedAreaRuleDefinition;
|
||||
|
||||
class LevelRuleset : public CompoundGameRuleDefinition
|
||||
{
|
||||
class LevelRuleset : public CompoundGameRuleDefinition {
|
||||
private:
|
||||
std::vector<NamedAreaRuleDefinition *> m_areas;
|
||||
StringTable *m_stringTable;
|
||||
std::vector<NamedAreaRuleDefinition*> m_areas;
|
||||
StringTable* m_stringTable;
|
||||
|
||||
public:
|
||||
LevelRuleset();
|
||||
~LevelRuleset();
|
||||
LevelRuleset();
|
||||
~LevelRuleset();
|
||||
|
||||
virtual void getChildren(std::vector<GameRuleDefinition *> *children);
|
||||
virtual GameRuleDefinition *addChild(ConsoleGameRules::EGameRuleType ruleType);
|
||||
virtual void getChildren(std::vector<GameRuleDefinition*>* children);
|
||||
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);
|
||||
const wchar_t *getString(const std::wstring &key);
|
||||
void loadStringTable(StringTable* table);
|
||||
const wchar_t* getString(const std::wstring& key);
|
||||
|
||||
AABB *getNamedArea(const std::wstring &areaName);
|
||||
AABB* getNamedArea(const std::wstring& areaName);
|
||||
|
||||
StringTable *getStringTable() { return m_stringTable; }
|
||||
StringTable* getStringTable() { return m_stringTable; }
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,82 +3,70 @@
|
|||
#include "../../Minecraft.World/Util/StringHelpers.h"
|
||||
#include "../../Minecraft.World/Headers/net.minecraft.world.phys.h"
|
||||
|
||||
NamedAreaRuleDefinition::NamedAreaRuleDefinition()
|
||||
{
|
||||
m_name = L"";
|
||||
m_area = AABB::newPermanent(0,0,0,0,0,0);
|
||||
NamedAreaRuleDefinition::NamedAreaRuleDefinition() {
|
||||
m_name = L"";
|
||||
m_area = AABB::newPermanent(0, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
NamedAreaRuleDefinition::~NamedAreaRuleDefinition()
|
||||
{
|
||||
delete m_area;
|
||||
NamedAreaRuleDefinition::~NamedAreaRuleDefinition() { delete m_area; }
|
||||
|
||||
void NamedAreaRuleDefinition::writeAttributes(DataOutputStream* dos,
|
||||
unsigned int numAttributes) {
|
||||
GameRuleDefinition::writeAttributes(dos, numAttributes + 7);
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_name);
|
||||
dos->writeUTF(m_name);
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x0);
|
||||
dos->writeUTF(_toString(m_area->x0));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y0);
|
||||
dos->writeUTF(_toString(m_area->y0));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z0);
|
||||
dos->writeUTF(_toString(m_area->z0));
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x1);
|
||||
dos->writeUTF(_toString(m_area->x1));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y1);
|
||||
dos->writeUTF(_toString(m_area->y1));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z1);
|
||||
dos->writeUTF(_toString(m_area->z1));
|
||||
}
|
||||
|
||||
void NamedAreaRuleDefinition::writeAttributes(DataOutputStream *dos, unsigned int numAttributes)
|
||||
{
|
||||
GameRuleDefinition::writeAttributes(dos, numAttributes + 7);
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_name);
|
||||
dos->writeUTF(m_name);
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x0);
|
||||
dos->writeUTF(_toString(m_area->x0));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y0);
|
||||
dos->writeUTF(_toString(m_area->y0));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z0);
|
||||
dos->writeUTF(_toString(m_area->z0));
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x1);
|
||||
dos->writeUTF(_toString(m_area->x1));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y1);
|
||||
dos->writeUTF(_toString(m_area->y1));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z1);
|
||||
dos->writeUTF(_toString(m_area->z1));
|
||||
}
|
||||
|
||||
void NamedAreaRuleDefinition::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue)
|
||||
{
|
||||
if(attributeName.compare(L"name") == 0)
|
||||
{
|
||||
m_name = attributeValue;
|
||||
void NamedAreaRuleDefinition::addAttribute(const std::wstring& attributeName,
|
||||
const std::wstring& attributeValue) {
|
||||
if (attributeName.compare(L"name") == 0) {
|
||||
m_name = attributeValue;
|
||||
#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
|
||||
}
|
||||
else if(attributeName.compare(L"x0") == 0)
|
||||
{
|
||||
m_area->x0 = _fromString<int>(attributeValue);
|
||||
app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter x0=%f\n",m_area->x0);
|
||||
}
|
||||
else if(attributeName.compare(L"y0") == 0)
|
||||
{
|
||||
m_area->y0 = _fromString<int>(attributeValue);
|
||||
if(m_area->y0 < 0) m_area->y0 = 0;
|
||||
app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter y0=%f\n",m_area->y0);
|
||||
}
|
||||
else if(attributeName.compare(L"z0") == 0)
|
||||
{
|
||||
m_area->z0 = _fromString<int>(attributeValue);
|
||||
app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter z0=%f\n",m_area->z0);
|
||||
}
|
||||
else if(attributeName.compare(L"x1") == 0)
|
||||
{
|
||||
m_area->x1 = _fromString<int>(attributeValue);
|
||||
app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter x1=%f\n",m_area->x1);
|
||||
}
|
||||
else if(attributeName.compare(L"y1") == 0)
|
||||
{
|
||||
m_area->y1 = _fromString<int>(attributeValue);
|
||||
if(m_area->y1 < 0) m_area->y1 = 0;
|
||||
app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter y1=%f\n",m_area->y1);
|
||||
}
|
||||
else if(attributeName.compare(L"z1") == 0)
|
||||
{
|
||||
m_area->z1 = _fromString<int>(attributeValue);
|
||||
app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter z1=%f\n",m_area->z1);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameRuleDefinition::addAttribute(attributeName, attributeValue);
|
||||
}
|
||||
} else if (attributeName.compare(L"x0") == 0) {
|
||||
m_area->x0 = _fromString<int>(attributeValue);
|
||||
app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter x0=%f\n",
|
||||
m_area->x0);
|
||||
} else if (attributeName.compare(L"y0") == 0) {
|
||||
m_area->y0 = _fromString<int>(attributeValue);
|
||||
if (m_area->y0 < 0) m_area->y0 = 0;
|
||||
app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter y0=%f\n",
|
||||
m_area->y0);
|
||||
} else if (attributeName.compare(L"z0") == 0) {
|
||||
m_area->z0 = _fromString<int>(attributeValue);
|
||||
app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter z0=%f\n",
|
||||
m_area->z0);
|
||||
} else if (attributeName.compare(L"x1") == 0) {
|
||||
m_area->x1 = _fromString<int>(attributeValue);
|
||||
app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter x1=%f\n",
|
||||
m_area->x1);
|
||||
} else if (attributeName.compare(L"y1") == 0) {
|
||||
m_area->y1 = _fromString<int>(attributeValue);
|
||||
if (m_area->y1 < 0) m_area->y1 = 0;
|
||||
app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter y1=%f\n",
|
||||
m_area->y1);
|
||||
} else if (attributeName.compare(L"z1") == 0) {
|
||||
m_area->z1 = _fromString<int>(attributeValue);
|
||||
app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter z1=%f\n",
|
||||
m_area->z1);
|
||||
} else {
|
||||
GameRuleDefinition::addAttribute(attributeName, attributeValue);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,22 +2,25 @@
|
|||
|
||||
#include "GameRuleDefinition.h"
|
||||
|
||||
class NamedAreaRuleDefinition : public GameRuleDefinition
|
||||
{
|
||||
class NamedAreaRuleDefinition : public GameRuleDefinition {
|
||||
private:
|
||||
std::wstring m_name;
|
||||
AABB *m_area;
|
||||
std::wstring m_name;
|
||||
AABB* m_area;
|
||||
|
||||
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 void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue);
|
||||
virtual ConsoleGameRules::EGameRuleType getActionType() {
|
||||
return ConsoleGameRules::eGameRuleType_NamedArea;
|
||||
}
|
||||
|
||||
AABB *getArea() { return m_area; }
|
||||
std::wstring getName() { return m_name; }
|
||||
virtual void addAttribute(const std::wstring& attributeName,
|
||||
const std::wstring& attributeValue);
|
||||
|
||||
AABB* getArea() { return m_area; }
|
||||
std::wstring getName() { return m_name; }
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,52 +2,45 @@
|
|||
#include "../../Minecraft.World/Util/StringHelpers.h"
|
||||
#include "StartFeature.h"
|
||||
|
||||
StartFeature::StartFeature()
|
||||
{
|
||||
m_chunkX = 0;
|
||||
m_chunkZ = 0;
|
||||
m_feature = StructureFeature::eFeature_Temples;
|
||||
StartFeature::StartFeature() {
|
||||
m_chunkX = 0;
|
||||
m_chunkZ = 0;
|
||||
m_feature = StructureFeature::eFeature_Temples;
|
||||
}
|
||||
|
||||
void StartFeature::writeAttributes(DataOutputStream *dos, unsigned int numAttrs)
|
||||
{
|
||||
GameRuleDefinition::writeAttributes(dos, numAttrs + 3);
|
||||
void StartFeature::writeAttributes(DataOutputStream* dos,
|
||||
unsigned int numAttrs) {
|
||||
GameRuleDefinition::writeAttributes(dos, numAttrs + 3);
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_chunkX);
|
||||
dos->writeUTF(_toString(m_chunkX));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_chunkZ);
|
||||
dos->writeUTF(_toString(m_chunkZ));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_feature);
|
||||
dos->writeUTF(_toString((int)m_feature));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_chunkX);
|
||||
dos->writeUTF(_toString(m_chunkX));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_chunkZ);
|
||||
dos->writeUTF(_toString(m_chunkZ));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_feature);
|
||||
dos->writeUTF(_toString((int)m_feature));
|
||||
}
|
||||
|
||||
void StartFeature::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue)
|
||||
{
|
||||
if(attributeName.compare(L"chunkX") == 0)
|
||||
{
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_chunkX = value;
|
||||
app.DebugPrintf("StartFeature: Adding parameter chunkX=%d\n",m_chunkX);
|
||||
}
|
||||
else if(attributeName.compare(L"chunkZ") == 0)
|
||||
{
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_chunkZ = value;
|
||||
app.DebugPrintf("StartFeature: Adding parameter chunkZ=%d\n",m_chunkZ);
|
||||
}
|
||||
else if(attributeName.compare(L"feature") == 0)
|
||||
{
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_feature = (StructureFeature::EFeatureTypes)value;
|
||||
app.DebugPrintf("StartFeature: Adding parameter feature=%d\n",m_feature);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameRuleDefinition::addAttribute(attributeName, attributeValue);
|
||||
}
|
||||
void StartFeature::addAttribute(const std::wstring& attributeName,
|
||||
const std::wstring& attributeValue) {
|
||||
if (attributeName.compare(L"chunkX") == 0) {
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_chunkX = value;
|
||||
app.DebugPrintf("StartFeature: Adding parameter chunkX=%d\n", m_chunkX);
|
||||
} else if (attributeName.compare(L"chunkZ") == 0) {
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_chunkZ = value;
|
||||
app.DebugPrintf("StartFeature: Adding parameter chunkZ=%d\n", m_chunkZ);
|
||||
} else if (attributeName.compare(L"feature") == 0) {
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_feature = (StructureFeature::EFeatureTypes)value;
|
||||
app.DebugPrintf("StartFeature: Adding parameter feature=%d\n",
|
||||
m_feature);
|
||||
} else {
|
||||
GameRuleDefinition::addAttribute(attributeName, attributeValue);
|
||||
}
|
||||
}
|
||||
|
||||
bool StartFeature::isFeatureChunk(int chunkX, int chunkZ, StructureFeature::EFeatureTypes feature)
|
||||
{
|
||||
return chunkX == m_chunkX && chunkZ == m_chunkZ && feature == m_feature;
|
||||
bool StartFeature::isFeatureChunk(int chunkX, int chunkZ,
|
||||
StructureFeature::EFeatureTypes feature) {
|
||||
return chunkX == m_chunkX && chunkZ == m_chunkZ && feature == m_feature;
|
||||
}
|
||||
|
|
@ -1,22 +1,25 @@
|
|||
#pragma once
|
||||
//using namespace std;
|
||||
// using namespace std;
|
||||
|
||||
#include "GameRuleDefinition.h"
|
||||
#include "../../Minecraft.World/WorldGen/Features/StructureFeature.h"
|
||||
|
||||
class StartFeature : public GameRuleDefinition
|
||||
{
|
||||
class StartFeature : public GameRuleDefinition {
|
||||
private:
|
||||
int m_chunkX, m_chunkZ;
|
||||
StructureFeature::EFeatureTypes m_feature;
|
||||
int m_chunkX, m_chunkZ;
|
||||
StructureFeature::EFeatureTypes m_feature;
|
||||
|
||||
public:
|
||||
StartFeature();
|
||||
StartFeature();
|
||||
|
||||
virtual ConsoleGameRules::EGameRuleType getActionType() { return ConsoleGameRules::eGameRuleType_StartFeature; }
|
||||
|
||||
virtual void writeAttributes(DataOutputStream *dos, unsigned int numAttrs);
|
||||
virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue);
|
||||
virtual ConsoleGameRules::EGameRuleType getActionType() {
|
||||
return ConsoleGameRules::eGameRuleType_StartFeature;
|
||||
}
|
||||
|
||||
bool isFeatureChunk(int chunkX, int chunkZ, StructureFeature::EFeatureTypes feature);
|
||||
virtual void writeAttributes(DataOutputStream* dos, unsigned int numAttrs);
|
||||
virtual void addAttribute(const std::wstring& attributeName,
|
||||
const std::wstring& attributeValue);
|
||||
|
||||
bool isFeatureChunk(int chunkX, int chunkZ,
|
||||
StructureFeature::EFeatureTypes feature);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -7,165 +7,149 @@
|
|||
#include "../../Minecraft.World/Headers/net.minecraft.world.food.h"
|
||||
#include "../../Minecraft.World/Headers/net.minecraft.world.item.h"
|
||||
|
||||
UpdatePlayerRuleDefinition::UpdatePlayerRuleDefinition()
|
||||
{
|
||||
m_bUpdateHealth = m_bUpdateFood = m_bUpdateYRot = false;;
|
||||
m_health = 0;
|
||||
m_food = 0;
|
||||
m_spawnPos = NULL;
|
||||
m_yRot = 0.0f;
|
||||
UpdatePlayerRuleDefinition::UpdatePlayerRuleDefinition() {
|
||||
m_bUpdateHealth = m_bUpdateFood = m_bUpdateYRot = false;
|
||||
;
|
||||
m_health = 0;
|
||||
m_food = 0;
|
||||
m_spawnPos = NULL;
|
||||
m_yRot = 0.0f;
|
||||
}
|
||||
|
||||
UpdatePlayerRuleDefinition::~UpdatePlayerRuleDefinition()
|
||||
{
|
||||
for(AUTO_VAR(it, m_items.begin()); it != m_items.end(); ++it)
|
||||
{
|
||||
delete *it;
|
||||
}
|
||||
UpdatePlayerRuleDefinition::~UpdatePlayerRuleDefinition() {
|
||||
for (AUTO_VAR(it, m_items.begin()); it != m_items.end(); ++it) {
|
||||
delete *it;
|
||||
}
|
||||
}
|
||||
|
||||
void UpdatePlayerRuleDefinition::writeAttributes(DataOutputStream *dos, unsigned int numAttributes)
|
||||
{
|
||||
int attrCount = 3;
|
||||
if(m_bUpdateHealth) ++attrCount;
|
||||
if(m_bUpdateFood) ++attrCount;
|
||||
if(m_bUpdateYRot) ++attrCount;
|
||||
GameRuleDefinition::writeAttributes(dos, numAttributes + attrCount );
|
||||
void UpdatePlayerRuleDefinition::writeAttributes(DataOutputStream* dos,
|
||||
unsigned int numAttributes) {
|
||||
int attrCount = 3;
|
||||
if (m_bUpdateHealth) ++attrCount;
|
||||
if (m_bUpdateFood) ++attrCount;
|
||||
if (m_bUpdateYRot) ++attrCount;
|
||||
GameRuleDefinition::writeAttributes(dos, numAttributes + attrCount);
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_spawnX);
|
||||
dos->writeUTF(_toString(m_spawnPos->x));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_spawnY);
|
||||
dos->writeUTF(_toString(m_spawnPos->y));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_spawnZ);
|
||||
dos->writeUTF(_toString(m_spawnPos->z));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_spawnX);
|
||||
dos->writeUTF(_toString(m_spawnPos->x));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_spawnY);
|
||||
dos->writeUTF(_toString(m_spawnPos->y));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_spawnZ);
|
||||
dos->writeUTF(_toString(m_spawnPos->z));
|
||||
|
||||
if(m_bUpdateYRot)
|
||||
{
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_yRot);
|
||||
dos->writeUTF(_toString(m_yRot));
|
||||
}
|
||||
if(m_bUpdateHealth)
|
||||
{
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_food);
|
||||
dos->writeUTF(_toString(m_health));
|
||||
}
|
||||
if(m_bUpdateFood)
|
||||
{
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_health);
|
||||
dos->writeUTF(_toString(m_food));
|
||||
}
|
||||
if (m_bUpdateYRot) {
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_yRot);
|
||||
dos->writeUTF(_toString(m_yRot));
|
||||
}
|
||||
if (m_bUpdateHealth) {
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_food);
|
||||
dos->writeUTF(_toString(m_health));
|
||||
}
|
||||
if (m_bUpdateFood) {
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_health);
|
||||
dos->writeUTF(_toString(m_food));
|
||||
}
|
||||
}
|
||||
|
||||
void UpdatePlayerRuleDefinition::getChildren(std::vector<GameRuleDefinition *> *children)
|
||||
{
|
||||
GameRuleDefinition::getChildren(children);
|
||||
for(AUTO_VAR(it, m_items.begin()); it!=m_items.end(); it++)
|
||||
children->push_back(*it);
|
||||
void UpdatePlayerRuleDefinition::getChildren(
|
||||
std::vector<GameRuleDefinition*>* children) {
|
||||
GameRuleDefinition::getChildren(children);
|
||||
for (AUTO_VAR(it, m_items.begin()); it != m_items.end(); it++)
|
||||
children->push_back(*it);
|
||||
}
|
||||
|
||||
GameRuleDefinition *UpdatePlayerRuleDefinition::addChild(ConsoleGameRules::EGameRuleType ruleType)
|
||||
{
|
||||
GameRuleDefinition *rule = NULL;
|
||||
if(ruleType == ConsoleGameRules::eGameRuleType_AddItem)
|
||||
{
|
||||
rule = new AddItemRuleDefinition();
|
||||
m_items.push_back((AddItemRuleDefinition *)rule);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameRuleDefinition* UpdatePlayerRuleDefinition::addChild(
|
||||
ConsoleGameRules::EGameRuleType ruleType) {
|
||||
GameRuleDefinition* rule = NULL;
|
||||
if (ruleType == ConsoleGameRules::eGameRuleType_AddItem) {
|
||||
rule = new AddItemRuleDefinition();
|
||||
m_items.push_back((AddItemRuleDefinition*)rule);
|
||||
} else {
|
||||
#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
|
||||
}
|
||||
return rule;
|
||||
}
|
||||
return rule;
|
||||
}
|
||||
|
||||
void UpdatePlayerRuleDefinition::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue)
|
||||
{
|
||||
if(attributeName.compare(L"spawnX") == 0)
|
||||
{
|
||||
if(m_spawnPos == NULL) m_spawnPos = new Pos();
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_spawnPos->x = value;
|
||||
app.DebugPrintf("UpdatePlayerRuleDefinition: Adding parameter spawnX=%d\n",value);
|
||||
}
|
||||
else if(attributeName.compare(L"spawnY") == 0)
|
||||
{
|
||||
if(m_spawnPos == NULL) m_spawnPos = new Pos();
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_spawnPos->y = value;
|
||||
app.DebugPrintf("UpdatePlayerRuleDefinition: Adding parameter spawnY=%d\n",value);
|
||||
}
|
||||
else if(attributeName.compare(L"spawnZ") == 0)
|
||||
{
|
||||
if(m_spawnPos == NULL) m_spawnPos = new Pos();
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_spawnPos->z = value;
|
||||
app.DebugPrintf("UpdatePlayerRuleDefinition: Adding parameter spawnZ=%d\n",value);
|
||||
}
|
||||
else if(attributeName.compare(L"health") == 0)
|
||||
{
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_health = value;
|
||||
m_bUpdateHealth = true;
|
||||
app.DebugPrintf("UpdatePlayerRuleDefinition: Adding parameter health=%d\n",value);
|
||||
}
|
||||
else if(attributeName.compare(L"food") == 0)
|
||||
{
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_food = value;
|
||||
m_bUpdateFood = true;
|
||||
app.DebugPrintf("UpdatePlayerRuleDefinition: Adding parameter health=%d\n",value);
|
||||
}
|
||||
else if(attributeName.compare(L"yRot") == 0)
|
||||
{
|
||||
float value = _fromString<float>(attributeValue);
|
||||
m_yRot = value;
|
||||
m_bUpdateYRot = true;
|
||||
app.DebugPrintf("UpdatePlayerRuleDefinition: Adding parameter yRot=%f\n",value);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameRuleDefinition::addAttribute(attributeName, attributeValue);
|
||||
}
|
||||
void UpdatePlayerRuleDefinition::addAttribute(
|
||||
const std::wstring& attributeName, const std::wstring& attributeValue) {
|
||||
if (attributeName.compare(L"spawnX") == 0) {
|
||||
if (m_spawnPos == NULL) m_spawnPos = new Pos();
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_spawnPos->x = value;
|
||||
app.DebugPrintf(
|
||||
"UpdatePlayerRuleDefinition: Adding parameter spawnX=%d\n", value);
|
||||
} else if (attributeName.compare(L"spawnY") == 0) {
|
||||
if (m_spawnPos == NULL) m_spawnPos = new Pos();
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_spawnPos->y = value;
|
||||
app.DebugPrintf(
|
||||
"UpdatePlayerRuleDefinition: Adding parameter spawnY=%d\n", value);
|
||||
} else if (attributeName.compare(L"spawnZ") == 0) {
|
||||
if (m_spawnPos == NULL) m_spawnPos = new Pos();
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_spawnPos->z = value;
|
||||
app.DebugPrintf(
|
||||
"UpdatePlayerRuleDefinition: Adding parameter spawnZ=%d\n", value);
|
||||
} else if (attributeName.compare(L"health") == 0) {
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_health = value;
|
||||
m_bUpdateHealth = true;
|
||||
app.DebugPrintf(
|
||||
"UpdatePlayerRuleDefinition: Adding parameter health=%d\n", value);
|
||||
} else if (attributeName.compare(L"food") == 0) {
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_food = value;
|
||||
m_bUpdateFood = true;
|
||||
app.DebugPrintf(
|
||||
"UpdatePlayerRuleDefinition: Adding parameter health=%d\n", value);
|
||||
} else if (attributeName.compare(L"yRot") == 0) {
|
||||
float value = _fromString<float>(attributeValue);
|
||||
m_yRot = value;
|
||||
m_bUpdateYRot = true;
|
||||
app.DebugPrintf(
|
||||
"UpdatePlayerRuleDefinition: Adding parameter yRot=%f\n", value);
|
||||
} else {
|
||||
GameRuleDefinition::addAttribute(attributeName, attributeValue);
|
||||
}
|
||||
}
|
||||
|
||||
void UpdatePlayerRuleDefinition::postProcessPlayer(std::shared_ptr<Player> player)
|
||||
{
|
||||
if(m_bUpdateHealth)
|
||||
{
|
||||
player->lastHealth = m_health;
|
||||
player->setHealth(m_health);
|
||||
}
|
||||
void UpdatePlayerRuleDefinition::postProcessPlayer(
|
||||
std::shared_ptr<Player> player) {
|
||||
if (m_bUpdateHealth) {
|
||||
player->lastHealth = m_health;
|
||||
player->setHealth(m_health);
|
||||
}
|
||||
|
||||
if(m_bUpdateFood)
|
||||
{
|
||||
player->getFoodData()->setFoodLevel(m_food);
|
||||
}
|
||||
if (m_bUpdateFood) {
|
||||
player->getFoodData()->setFoodLevel(m_food);
|
||||
}
|
||||
|
||||
double x = player->x;
|
||||
double y = player->y;
|
||||
double z = player->z;
|
||||
float yRot = player->yRot;
|
||||
float xRot = player->xRot;
|
||||
if(m_spawnPos != NULL)
|
||||
{
|
||||
x = m_spawnPos->x;
|
||||
y = m_spawnPos->y;
|
||||
z = m_spawnPos->z;
|
||||
}
|
||||
double x = player->x;
|
||||
double y = player->y;
|
||||
double z = player->z;
|
||||
float yRot = player->yRot;
|
||||
float xRot = player->xRot;
|
||||
if (m_spawnPos != NULL) {
|
||||
x = m_spawnPos->x;
|
||||
y = m_spawnPos->y;
|
||||
z = m_spawnPos->z;
|
||||
}
|
||||
|
||||
if(m_bUpdateYRot)
|
||||
{
|
||||
yRot = m_yRot;
|
||||
}
|
||||
if (m_bUpdateYRot) {
|
||||
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)
|
||||
{
|
||||
AddItemRuleDefinition *addItem = *it;
|
||||
for (AUTO_VAR(it, m_items.begin()); it != m_items.end(); ++it) {
|
||||
AddItemRuleDefinition* addItem = *it;
|
||||
|
||||
addItem->addItemToContainer(player->inventory, -1);
|
||||
}
|
||||
addItem->addItemToContainer(player->inventory, -1);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,33 +1,37 @@
|
|||
#pragma once
|
||||
//using namespace std;
|
||||
// using namespace std;
|
||||
|
||||
#include "GameRuleDefinition.h"
|
||||
|
||||
class AddItemRuleDefinition;
|
||||
class Pos;
|
||||
|
||||
class UpdatePlayerRuleDefinition : public GameRuleDefinition
|
||||
{
|
||||
class UpdatePlayerRuleDefinition : public GameRuleDefinition {
|
||||
private:
|
||||
std::vector<AddItemRuleDefinition *> m_items;
|
||||
std::vector<AddItemRuleDefinition*> m_items;
|
||||
|
||||
bool m_bUpdateHealth, m_bUpdateFood, m_bUpdateYRot, m_bUpdateInventory;
|
||||
int m_health;
|
||||
int m_food;
|
||||
Pos *m_spawnPos;
|
||||
float m_yRot;
|
||||
bool m_bUpdateHealth, m_bUpdateFood, m_bUpdateYRot, m_bUpdateInventory;
|
||||
int m_health;
|
||||
int m_food;
|
||||
Pos* m_spawnPos;
|
||||
float m_yRot;
|
||||
|
||||
public:
|
||||
UpdatePlayerRuleDefinition();
|
||||
~UpdatePlayerRuleDefinition();
|
||||
UpdatePlayerRuleDefinition();
|
||||
~UpdatePlayerRuleDefinition();
|
||||
|
||||
virtual ConsoleGameRules::EGameRuleType getActionType() { return ConsoleGameRules::eGameRuleType_UpdatePlayerRule; }
|
||||
|
||||
virtual void getChildren(std::vector<GameRuleDefinition *> *children);
|
||||
virtual GameRuleDefinition *addChild(ConsoleGameRules::EGameRuleType ruleType);
|
||||
virtual ConsoleGameRules::EGameRuleType getActionType() {
|
||||
return ConsoleGameRules::eGameRuleType_UpdatePlayerRule;
|
||||
}
|
||||
|
||||
virtual void writeAttributes(DataOutputStream *dos, unsigned int numAttributes);
|
||||
virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue);
|
||||
virtual void getChildren(std::vector<GameRuleDefinition*>* children);
|
||||
virtual GameRuleDefinition* addChild(
|
||||
ConsoleGameRules::EGameRuleType ruleType);
|
||||
|
||||
virtual void postProcessPlayer(std::shared_ptr<Player> player);
|
||||
virtual void writeAttributes(DataOutputStream* dos,
|
||||
unsigned int numAttributes);
|
||||
virtual void addAttribute(const std::wstring& attributeName,
|
||||
const std::wstring& attributeValue);
|
||||
|
||||
virtual void postProcessPlayer(std::shared_ptr<Player> player);
|
||||
};
|
||||
|
|
@ -2,81 +2,75 @@
|
|||
#include "../../Minecraft.World/Util/StringHelpers.h"
|
||||
#include "UseTileRuleDefinition.h"
|
||||
|
||||
UseTileRuleDefinition::UseTileRuleDefinition()
|
||||
{
|
||||
m_tileId = -1;
|
||||
m_useCoords = false;
|
||||
UseTileRuleDefinition::UseTileRuleDefinition() {
|
||||
m_tileId = -1;
|
||||
m_useCoords = false;
|
||||
}
|
||||
|
||||
void UseTileRuleDefinition::writeAttributes(DataOutputStream *dos, unsigned int numAttributes)
|
||||
{
|
||||
GameRuleDefinition::writeAttributes(dos, numAttributes + 5);
|
||||
void UseTileRuleDefinition::writeAttributes(DataOutputStream* dos,
|
||||
unsigned int numAttributes) {
|
||||
GameRuleDefinition::writeAttributes(dos, numAttributes + 5);
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_tileId);
|
||||
dos->writeUTF(_toString(m_tileId));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_tileId);
|
||||
dos->writeUTF(_toString(m_tileId));
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_useCoords);
|
||||
dos->writeUTF(_toString(m_useCoords));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_useCoords);
|
||||
dos->writeUTF(_toString(m_useCoords));
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x);
|
||||
dos->writeUTF(_toString(m_coordinates.x));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x);
|
||||
dos->writeUTF(_toString(m_coordinates.x));
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y);
|
||||
dos->writeUTF(_toString(m_coordinates.y));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y);
|
||||
dos->writeUTF(_toString(m_coordinates.y));
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z);
|
||||
dos->writeUTF(_toString(m_coordinates.z));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z);
|
||||
dos->writeUTF(_toString(m_coordinates.z));
|
||||
}
|
||||
|
||||
void UseTileRuleDefinition::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue)
|
||||
{
|
||||
if(attributeName.compare(L"tileId") == 0)
|
||||
{
|
||||
m_tileId = _fromString<int>(attributeValue);
|
||||
app.DebugPrintf("UseTileRule: Adding parameter tileId=%d\n",m_tileId);
|
||||
}
|
||||
else if(attributeName.compare(L"useCoords") == 0)
|
||||
{
|
||||
m_useCoords = _fromString<bool>(attributeValue);
|
||||
app.DebugPrintf("UseTileRule: Adding parameter useCoords=%s\n",m_useCoords?"TRUE":"FALSE");
|
||||
}
|
||||
else if(attributeName.compare(L"x") == 0)
|
||||
{
|
||||
m_coordinates.x = _fromString<int>(attributeValue);
|
||||
app.DebugPrintf("UseTileRule: Adding parameter x=%d\n",m_coordinates.x);
|
||||
}
|
||||
else if(attributeName.compare(L"y") == 0)
|
||||
{
|
||||
m_coordinates.y = _fromString<int>(attributeValue);
|
||||
app.DebugPrintf("UseTileRule: Adding parameter y=%d\n",m_coordinates.y);
|
||||
}
|
||||
else if(attributeName.compare(L"z") == 0)
|
||||
{
|
||||
m_coordinates.z = _fromString<int>(attributeValue);
|
||||
app.DebugPrintf("UseTileRule: Adding parameter z=%d\n",m_coordinates.z);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameRuleDefinition::addAttribute(attributeName, attributeValue);
|
||||
}
|
||||
void UseTileRuleDefinition::addAttribute(const std::wstring& attributeName,
|
||||
const std::wstring& attributeValue) {
|
||||
if (attributeName.compare(L"tileId") == 0) {
|
||||
m_tileId = _fromString<int>(attributeValue);
|
||||
app.DebugPrintf("UseTileRule: Adding parameter tileId=%d\n", m_tileId);
|
||||
} else if (attributeName.compare(L"useCoords") == 0) {
|
||||
m_useCoords = _fromString<bool>(attributeValue);
|
||||
app.DebugPrintf("UseTileRule: Adding parameter useCoords=%s\n",
|
||||
m_useCoords ? "TRUE" : "FALSE");
|
||||
} else if (attributeName.compare(L"x") == 0) {
|
||||
m_coordinates.x = _fromString<int>(attributeValue);
|
||||
app.DebugPrintf("UseTileRule: Adding parameter x=%d\n",
|
||||
m_coordinates.x);
|
||||
} else if (attributeName.compare(L"y") == 0) {
|
||||
m_coordinates.y = _fromString<int>(attributeValue);
|
||||
app.DebugPrintf("UseTileRule: Adding parameter y=%d\n",
|
||||
m_coordinates.y);
|
||||
} else if (attributeName.compare(L"z") == 0) {
|
||||
m_coordinates.z = _fromString<int>(attributeValue);
|
||||
app.DebugPrintf("UseTileRule: Adding parameter z=%d\n",
|
||||
m_coordinates.z);
|
||||
} else {
|
||||
GameRuleDefinition::addAttribute(attributeName, attributeValue);
|
||||
}
|
||||
}
|
||||
|
||||
bool UseTileRuleDefinition::onUseTile(GameRule *rule, int tileId, int x, int y, int z)
|
||||
{
|
||||
bool statusChanged = false;
|
||||
if( m_tileId == tileId )
|
||||
{
|
||||
if( !m_useCoords || (m_coordinates.x == x && m_coordinates.y == y && m_coordinates.z == z) )
|
||||
{
|
||||
if(!getComplete(rule))
|
||||
{
|
||||
statusChanged = 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);
|
||||
bool UseTileRuleDefinition::onUseTile(GameRule* rule, int tileId, int x, int y,
|
||||
int z) {
|
||||
bool statusChanged = false;
|
||||
if (m_tileId == tileId) {
|
||||
if (!m_useCoords || (m_coordinates.x == x && m_coordinates.y == y &&
|
||||
m_coordinates.z == z)) {
|
||||
if (!getComplete(rule)) {
|
||||
statusChanged = 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);
|
||||
|
||||
// Send a packet or some other announcement here
|
||||
}
|
||||
}
|
||||
}
|
||||
return statusChanged;
|
||||
// Send a packet or some other announcement here
|
||||
}
|
||||
}
|
||||
}
|
||||
return statusChanged;
|
||||
}
|
||||
|
|
@ -1,24 +1,27 @@
|
|||
#pragma once
|
||||
//using namespace std;
|
||||
// using namespace std;
|
||||
|
||||
#include "GameRuleDefinition.h"
|
||||
#include "../../Minecraft.World/Util/Pos.h"
|
||||
|
||||
class UseTileRuleDefinition : public GameRuleDefinition
|
||||
{
|
||||
class UseTileRuleDefinition : public GameRuleDefinition {
|
||||
private:
|
||||
// These values should map directly to the xsd definition for this Rule
|
||||
int m_tileId;
|
||||
bool m_useCoords;
|
||||
Pos m_coordinates;
|
||||
// These values should map directly to the xsd definition for this Rule
|
||||
int m_tileId;
|
||||
bool m_useCoords;
|
||||
Pos m_coordinates;
|
||||
|
||||
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 addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue);
|
||||
|
||||
virtual bool onUseTile(GameRule *rule, int tileId, int x, int y, int z);
|
||||
virtual void writeAttributes(DataOutputStream* dos,
|
||||
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);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,102 +3,95 @@
|
|||
#include "../../Minecraft.World/Util/StringHelpers.h"
|
||||
#include "../../Minecraft.World/Headers/net.minecraft.world.level.levelgen.structure.h"
|
||||
|
||||
XboxStructureActionGenerateBox::XboxStructureActionGenerateBox()
|
||||
{
|
||||
m_x0 = m_y0 = m_z0 = m_x1 = m_y1 = m_z1 = m_edgeTile = m_fillTile = 0;
|
||||
m_skipAir = false;
|
||||
XboxStructureActionGenerateBox::XboxStructureActionGenerateBox() {
|
||||
m_x0 = m_y0 = m_z0 = m_x1 = m_y1 = m_z1 = m_edgeTile = m_fillTile = 0;
|
||||
m_skipAir = false;
|
||||
}
|
||||
|
||||
void XboxStructureActionGenerateBox::writeAttributes(DataOutputStream *dos, unsigned int numAttrs)
|
||||
{
|
||||
ConsoleGenerateStructureAction::writeAttributes(dos, numAttrs + 9);
|
||||
void XboxStructureActionGenerateBox::writeAttributes(DataOutputStream* dos,
|
||||
unsigned int numAttrs) {
|
||||
ConsoleGenerateStructureAction::writeAttributes(dos, numAttrs + 9);
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x0);
|
||||
dos->writeUTF(_toString(m_x0));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y0);
|
||||
dos->writeUTF(_toString(m_y0));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z0);
|
||||
dos->writeUTF(_toString(m_z0));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x0);
|
||||
dos->writeUTF(_toString(m_x0));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y0);
|
||||
dos->writeUTF(_toString(m_y0));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z0);
|
||||
dos->writeUTF(_toString(m_z0));
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x1);
|
||||
dos->writeUTF(_toString(m_x1));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y1);
|
||||
dos->writeUTF(_toString(m_y1));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z1);
|
||||
dos->writeUTF(_toString(m_z1));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x1);
|
||||
dos->writeUTF(_toString(m_x1));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y1);
|
||||
dos->writeUTF(_toString(m_y1));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z1);
|
||||
dos->writeUTF(_toString(m_z1));
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_edgeTile);
|
||||
dos->writeUTF(_toString(m_edgeTile));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_fillTile);
|
||||
dos->writeUTF(_toString(m_fillTile));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_skipAir);
|
||||
dos->writeUTF(_toString(m_skipAir));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_edgeTile);
|
||||
dos->writeUTF(_toString(m_edgeTile));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_fillTile);
|
||||
dos->writeUTF(_toString(m_fillTile));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_skipAir);
|
||||
dos->writeUTF(_toString(m_skipAir));
|
||||
}
|
||||
|
||||
void XboxStructureActionGenerateBox::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue)
|
||||
{
|
||||
if(attributeName.compare(L"x0") == 0)
|
||||
{
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_x0 = value;
|
||||
app.DebugPrintf("XboxStructureActionGenerateBox: Adding parameter x0=%d\n",m_x0);
|
||||
}
|
||||
else if(attributeName.compare(L"y0") == 0)
|
||||
{
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_y0 = value;
|
||||
app.DebugPrintf("XboxStructureActionGenerateBox: Adding parameter y0=%d\n",m_y0);
|
||||
}
|
||||
else if(attributeName.compare(L"z0") == 0)
|
||||
{
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_z0 = value;
|
||||
app.DebugPrintf("XboxStructureActionGenerateBox: Adding parameter z0=%d\n",m_z0);
|
||||
}
|
||||
else if(attributeName.compare(L"x1") == 0)
|
||||
{
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_x1 = value;
|
||||
app.DebugPrintf("XboxStructureActionGenerateBox: Adding parameter x1=%d\n",m_x1);
|
||||
}
|
||||
else if(attributeName.compare(L"y1") == 0)
|
||||
{
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_y1 = value;
|
||||
app.DebugPrintf("XboxStructureActionGenerateBox: Adding parameter y1=%d\n",m_y1);
|
||||
}
|
||||
else if(attributeName.compare(L"z1") == 0)
|
||||
{
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_z1 = value;
|
||||
app.DebugPrintf("XboxStructureActionGenerateBox: Adding parameter z1=%d\n",m_z1);
|
||||
}
|
||||
else if(attributeName.compare(L"edgeTile") == 0)
|
||||
{
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_edgeTile = value;
|
||||
app.DebugPrintf("XboxStructureActionGenerateBox: Adding parameter edgeTile=%d\n",m_edgeTile);
|
||||
}
|
||||
else if(attributeName.compare(L"fillTile") == 0)
|
||||
{
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_fillTile = value;
|
||||
app.DebugPrintf("XboxStructureActionGenerateBox: Adding parameter fillTile=%d\n",m_fillTile);
|
||||
}
|
||||
else if(attributeName.compare(L"skipAir") == 0)
|
||||
{
|
||||
if(attributeValue.compare(L"true") == 0) m_skipAir = true;
|
||||
app.DebugPrintf("XboxStructureActionGenerateBox: Adding parameter skipAir=%s\n",m_skipAir?"TRUE":"FALSE");
|
||||
}
|
||||
else
|
||||
{
|
||||
GameRuleDefinition::addAttribute(attributeName, attributeValue);
|
||||
}
|
||||
void XboxStructureActionGenerateBox::addAttribute(
|
||||
const std::wstring& attributeName, const std::wstring& attributeValue) {
|
||||
if (attributeName.compare(L"x0") == 0) {
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_x0 = value;
|
||||
app.DebugPrintf(
|
||||
"XboxStructureActionGenerateBox: Adding parameter x0=%d\n", m_x0);
|
||||
} else if (attributeName.compare(L"y0") == 0) {
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_y0 = value;
|
||||
app.DebugPrintf(
|
||||
"XboxStructureActionGenerateBox: Adding parameter y0=%d\n", m_y0);
|
||||
} else if (attributeName.compare(L"z0") == 0) {
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_z0 = value;
|
||||
app.DebugPrintf(
|
||||
"XboxStructureActionGenerateBox: Adding parameter z0=%d\n", m_z0);
|
||||
} else if (attributeName.compare(L"x1") == 0) {
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_x1 = value;
|
||||
app.DebugPrintf(
|
||||
"XboxStructureActionGenerateBox: Adding parameter x1=%d\n", m_x1);
|
||||
} else if (attributeName.compare(L"y1") == 0) {
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_y1 = value;
|
||||
app.DebugPrintf(
|
||||
"XboxStructureActionGenerateBox: Adding parameter y1=%d\n", m_y1);
|
||||
} else if (attributeName.compare(L"z1") == 0) {
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_z1 = value;
|
||||
app.DebugPrintf(
|
||||
"XboxStructureActionGenerateBox: Adding parameter z1=%d\n", m_z1);
|
||||
} else if (attributeName.compare(L"edgeTile") == 0) {
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_edgeTile = value;
|
||||
app.DebugPrintf(
|
||||
"XboxStructureActionGenerateBox: Adding parameter edgeTile=%d\n",
|
||||
m_edgeTile);
|
||||
} else if (attributeName.compare(L"fillTile") == 0) {
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_fillTile = value;
|
||||
app.DebugPrintf(
|
||||
"XboxStructureActionGenerateBox: Adding parameter fillTile=%d\n",
|
||||
m_fillTile);
|
||||
} else if (attributeName.compare(L"skipAir") == 0) {
|
||||
if (attributeValue.compare(L"true") == 0) m_skipAir = true;
|
||||
app.DebugPrintf(
|
||||
"XboxStructureActionGenerateBox: Adding parameter skipAir=%s\n",
|
||||
m_skipAir ? "TRUE" : "FALSE");
|
||||
} else {
|
||||
GameRuleDefinition::addAttribute(attributeName, attributeValue);
|
||||
}
|
||||
}
|
||||
|
||||
bool XboxStructureActionGenerateBox::generateBoxInLevel(StructurePiece *structure, Level *level, BoundingBox *chunkBB)
|
||||
{
|
||||
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);
|
||||
return true;
|
||||
bool XboxStructureActionGenerateBox::generateBoxInLevel(
|
||||
StructurePiece* structure, Level* level, BoundingBox* chunkBB) {
|
||||
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);
|
||||
return true;
|
||||
}
|
||||
|
|
@ -5,22 +5,26 @@ class StructurePiece;
|
|||
class Level;
|
||||
class BoundingBox;
|
||||
|
||||
class XboxStructureActionGenerateBox : public ConsoleGenerateStructureAction
|
||||
{
|
||||
class XboxStructureActionGenerateBox : public ConsoleGenerateStructureAction {
|
||||
private:
|
||||
int m_x0, m_y0, m_z0, m_x1, m_y1, m_z1, m_edgeTile, m_fillTile;
|
||||
bool m_skipAir;
|
||||
int m_x0, m_y0, m_z0, m_x1, m_y1, m_z1, m_edgeTile, m_fillTile;
|
||||
bool m_skipAir;
|
||||
|
||||
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 getEndY() { return m_y1; }
|
||||
virtual int getEndZ() { return m_z1; }
|
||||
virtual int getEndX() { return m_x1; }
|
||||
virtual int getEndY() { return m_y1; }
|
||||
virtual int getEndZ() { return m_z1; }
|
||||
|
||||
virtual void writeAttributes(DataOutputStream *dos, unsigned int numAttrs);
|
||||
virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue);
|
||||
virtual void writeAttributes(DataOutputStream* dos, unsigned int numAttrs);
|
||||
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,70 +3,65 @@
|
|||
#include "../../Minecraft.World/Util/StringHelpers.h"
|
||||
#include "../../Minecraft.World/Headers/net.minecraft.world.level.levelgen.structure.h"
|
||||
|
||||
XboxStructureActionPlaceBlock::XboxStructureActionPlaceBlock()
|
||||
{
|
||||
m_x = m_y = m_z = m_tile = m_data = 0;
|
||||
XboxStructureActionPlaceBlock::XboxStructureActionPlaceBlock() {
|
||||
m_x = m_y = m_z = m_tile = m_data = 0;
|
||||
}
|
||||
|
||||
void XboxStructureActionPlaceBlock::writeAttributes(DataOutputStream *dos, unsigned int numAttrs)
|
||||
{
|
||||
ConsoleGenerateStructureAction::writeAttributes(dos, numAttrs + 5);
|
||||
void XboxStructureActionPlaceBlock::writeAttributes(DataOutputStream* dos,
|
||||
unsigned int numAttrs) {
|
||||
ConsoleGenerateStructureAction::writeAttributes(dos, numAttrs + 5);
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x);
|
||||
dos->writeUTF(_toString(m_x));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y);
|
||||
dos->writeUTF(_toString(m_y));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z);
|
||||
dos->writeUTF(_toString(m_z));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x);
|
||||
dos->writeUTF(_toString(m_x));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y);
|
||||
dos->writeUTF(_toString(m_y));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z);
|
||||
dos->writeUTF(_toString(m_z));
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_data);
|
||||
dos->writeUTF(_toString(m_data));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_block);
|
||||
dos->writeUTF(_toString(m_tile));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_data);
|
||||
dos->writeUTF(_toString(m_data));
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_block);
|
||||
dos->writeUTF(_toString(m_tile));
|
||||
}
|
||||
|
||||
|
||||
void XboxStructureActionPlaceBlock::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue)
|
||||
{
|
||||
if(attributeName.compare(L"x") == 0)
|
||||
{
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_x = value;
|
||||
app.DebugPrintf("XboxStructureActionPlaceBlock: Adding parameter x=%d\n",m_x);
|
||||
}
|
||||
else if(attributeName.compare(L"y") == 0)
|
||||
{
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_y = value;
|
||||
app.DebugPrintf("XboxStructureActionPlaceBlock: Adding parameter y=%d\n",m_y);
|
||||
}
|
||||
else if(attributeName.compare(L"z") == 0)
|
||||
{
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_z = value;
|
||||
app.DebugPrintf("XboxStructureActionPlaceBlock: Adding parameter z=%d\n",m_z);
|
||||
}
|
||||
else if(attributeName.compare(L"block") == 0)
|
||||
{
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_tile = value;
|
||||
app.DebugPrintf("XboxStructureActionPlaceBlock: Adding parameter block=%d\n",m_tile);
|
||||
}
|
||||
else if(attributeName.compare(L"data") == 0)
|
||||
{
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_data = value;
|
||||
app.DebugPrintf("XboxStructureActionPlaceBlock: Adding parameter data=%d\n",m_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameRuleDefinition::addAttribute(attributeName, attributeValue);
|
||||
}
|
||||
void XboxStructureActionPlaceBlock::addAttribute(
|
||||
const std::wstring& attributeName, const std::wstring& attributeValue) {
|
||||
if (attributeName.compare(L"x") == 0) {
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_x = value;
|
||||
app.DebugPrintf(
|
||||
"XboxStructureActionPlaceBlock: Adding parameter x=%d\n", m_x);
|
||||
} else if (attributeName.compare(L"y") == 0) {
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_y = value;
|
||||
app.DebugPrintf(
|
||||
"XboxStructureActionPlaceBlock: Adding parameter y=%d\n", m_y);
|
||||
} else if (attributeName.compare(L"z") == 0) {
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_z = value;
|
||||
app.DebugPrintf(
|
||||
"XboxStructureActionPlaceBlock: Adding parameter z=%d\n", m_z);
|
||||
} else if (attributeName.compare(L"block") == 0) {
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_tile = value;
|
||||
app.DebugPrintf(
|
||||
"XboxStructureActionPlaceBlock: Adding parameter block=%d\n",
|
||||
m_tile);
|
||||
} else if (attributeName.compare(L"data") == 0) {
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_data = value;
|
||||
app.DebugPrintf(
|
||||
"XboxStructureActionPlaceBlock: Adding parameter data=%d\n",
|
||||
m_data);
|
||||
} else {
|
||||
GameRuleDefinition::addAttribute(attributeName, attributeValue);
|
||||
}
|
||||
}
|
||||
|
||||
bool XboxStructureActionPlaceBlock::placeBlockInLevel(StructurePiece *structure, Level *level, BoundingBox *chunkBB)
|
||||
{
|
||||
app.DebugPrintf("XboxStructureActionPlaceBlock - placing a block\n");
|
||||
structure->placeBlock(level,m_tile,m_data,m_x,m_y,m_z,chunkBB);
|
||||
return true;
|
||||
bool XboxStructureActionPlaceBlock::placeBlockInLevel(StructurePiece* structure,
|
||||
Level* level,
|
||||
BoundingBox* chunkBB) {
|
||||
app.DebugPrintf("XboxStructureActionPlaceBlock - placing a block\n");
|
||||
structure->placeBlock(level, m_tile, m_data, m_x, m_y, m_z, chunkBB);
|
||||
return true;
|
||||
}
|
||||
|
|
@ -5,21 +5,25 @@ class StructurePiece;
|
|||
class Level;
|
||||
class BoundingBox;
|
||||
|
||||
class XboxStructureActionPlaceBlock : public ConsoleGenerateStructureAction
|
||||
{
|
||||
class XboxStructureActionPlaceBlock : public ConsoleGenerateStructureAction {
|
||||
protected:
|
||||
int m_x, m_y, m_z, m_tile, m_data;
|
||||
int m_x, m_y, m_z, m_tile, m_data;
|
||||
|
||||
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 getEndY() { return m_y; }
|
||||
virtual int getEndZ() { return m_z; }
|
||||
virtual int getEndX() { return m_x; }
|
||||
virtual int getEndY() { return m_y; }
|
||||
virtual int getEndZ() { return m_z; }
|
||||
|
||||
virtual void writeAttributes(DataOutputStream *dos, unsigned int numAttrs);
|
||||
virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue);
|
||||
virtual void writeAttributes(DataOutputStream* dos, unsigned int numAttrs);
|
||||
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,93 +7,94 @@
|
|||
#include "../../Minecraft.World/Headers/net.minecraft.world.level.tile.h"
|
||||
#include "../../Minecraft.World/Headers/net.minecraft.world.inventory.h"
|
||||
|
||||
XboxStructureActionPlaceContainer::XboxStructureActionPlaceContainer()
|
||||
{
|
||||
m_tile = Tile::chest_Id;
|
||||
XboxStructureActionPlaceContainer::XboxStructureActionPlaceContainer() {
|
||||
m_tile = Tile::chest_Id;
|
||||
}
|
||||
|
||||
XboxStructureActionPlaceContainer::~XboxStructureActionPlaceContainer()
|
||||
{
|
||||
for(AUTO_VAR(it, m_items.begin()); it != m_items.end(); ++it)
|
||||
{
|
||||
delete *it;
|
||||
}
|
||||
XboxStructureActionPlaceContainer::~XboxStructureActionPlaceContainer() {
|
||||
for (AUTO_VAR(it, m_items.begin()); it != m_items.end(); ++it) {
|
||||
delete *it;
|
||||
}
|
||||
}
|
||||
|
||||
// 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(std::vector<GameRuleDefinition *> *children)
|
||||
{
|
||||
XboxStructureActionPlaceBlock::getChildren(children);
|
||||
for(AUTO_VAR(it, m_items.begin()); it!=m_items.end(); it++)
|
||||
children->push_back( *it );
|
||||
void XboxStructureActionPlaceContainer::getChildren(
|
||||
std::vector<GameRuleDefinition*>* children) {
|
||||
XboxStructureActionPlaceBlock::getChildren(children);
|
||||
for (AUTO_VAR(it, m_items.begin()); it != m_items.end(); it++)
|
||||
children->push_back(*it);
|
||||
}
|
||||
|
||||
GameRuleDefinition *XboxStructureActionPlaceContainer::addChild(ConsoleGameRules::EGameRuleType ruleType)
|
||||
{
|
||||
GameRuleDefinition *rule = NULL;
|
||||
if(ruleType == ConsoleGameRules::eGameRuleType_AddItem)
|
||||
{
|
||||
rule = new AddItemRuleDefinition();
|
||||
m_items.push_back((AddItemRuleDefinition *)rule);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameRuleDefinition* XboxStructureActionPlaceContainer::addChild(
|
||||
ConsoleGameRules::EGameRuleType ruleType) {
|
||||
GameRuleDefinition* rule = NULL;
|
||||
if (ruleType == ConsoleGameRules::eGameRuleType_AddItem) {
|
||||
rule = new AddItemRuleDefinition();
|
||||
m_items.push_back((AddItemRuleDefinition*)rule);
|
||||
} else {
|
||||
#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
|
||||
}
|
||||
return rule;
|
||||
}
|
||||
return rule;
|
||||
}
|
||||
|
||||
void XboxStructureActionPlaceContainer::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue)
|
||||
{
|
||||
if(attributeName.compare(L"facing") == 0)
|
||||
{
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_data = value;
|
||||
app.DebugPrintf("XboxStructureActionPlaceContainer: Adding parameter facing=%d\n",m_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
XboxStructureActionPlaceBlock::addAttribute(attributeName, attributeValue);
|
||||
}
|
||||
void XboxStructureActionPlaceContainer::addAttribute(
|
||||
const std::wstring& attributeName, const std::wstring& attributeValue) {
|
||||
if (attributeName.compare(L"facing") == 0) {
|
||||
int value = _fromString<int>(attributeValue);
|
||||
m_data = value;
|
||||
app.DebugPrintf(
|
||||
"XboxStructureActionPlaceContainer: Adding parameter facing=%d\n",
|
||||
m_data);
|
||||
} else {
|
||||
XboxStructureActionPlaceBlock::addAttribute(attributeName,
|
||||
attributeValue);
|
||||
}
|
||||
}
|
||||
|
||||
bool XboxStructureActionPlaceContainer::placeContainerInLevel(StructurePiece *structure, Level *level, BoundingBox *chunkBB)
|
||||
{
|
||||
int worldX = structure->getWorldX( m_x, m_z );
|
||||
int worldY = structure->getWorldY( m_y );
|
||||
int worldZ = structure->getWorldZ( m_x, m_z );
|
||||
bool XboxStructureActionPlaceContainer::placeContainerInLevel(
|
||||
StructurePiece* structure, Level* level, BoundingBox* chunkBB) {
|
||||
int worldX = structure->getWorldX(m_x, m_z);
|
||||
int worldY = structure->getWorldY(m_y);
|
||||
int worldZ = structure->getWorldZ(m_x, m_z);
|
||||
|
||||
if ( chunkBB->isInside( worldX, worldY, worldZ ) )
|
||||
{
|
||||
if ( level->getTileEntity( worldX, worldY, worldZ ) != NULL )
|
||||
{
|
||||
// Remove the current tile entity
|
||||
level->removeTileEntity( worldX, worldY, worldZ );
|
||||
level->setTile( worldX, worldY, worldZ, 0 );
|
||||
}
|
||||
if (chunkBB->isInside(worldX, worldY, worldZ)) {
|
||||
if (level->getTileEntity(worldX, worldY, worldZ) != NULL) {
|
||||
// Remove the current tile entity
|
||||
level->removeTileEntity(worldX, worldY, worldZ);
|
||||
level->setTile(worldX, worldY, worldZ, 0);
|
||||
}
|
||||
|
||||
level->setTile( worldX, worldY, worldZ, m_tile );
|
||||
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);
|
||||
if ( container != NULL )
|
||||
{
|
||||
level->setData( worldX, worldY, worldZ, m_data);
|
||||
// Add items
|
||||
int slotId = 0;
|
||||
for(AUTO_VAR(it, m_items.begin()); it != m_items.end() && (slotId < container->getContainerSize()); ++it, ++slotId )
|
||||
{
|
||||
AddItemRuleDefinition *addItem = *it;
|
||||
level->setTile(worldX, worldY, worldZ, m_tile);
|
||||
std::shared_ptr<Container> container =
|
||||
std::dynamic_pointer_cast<Container>(
|
||||
level->getTileEntity(worldX, worldY, worldZ));
|
||||
|
||||
addItem->addItemToContainer(container,slotId);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
app.DebugPrintf(
|
||||
"XboxStructureActionPlaceContainer - placing a container at "
|
||||
"(%d,%d,%d)\n",
|
||||
worldX, worldY, worldZ);
|
||||
if (container != NULL) {
|
||||
level->setData(worldX, worldY, worldZ, m_data);
|
||||
// Add items
|
||||
int slotId = 0;
|
||||
for (AUTO_VAR(it, m_items.begin());
|
||||
it != m_items.end() &&
|
||||
(slotId < container->getContainerSize());
|
||||
++it, ++slotId) {
|
||||
AddItemRuleDefinition* addItem = *it;
|
||||
|
||||
addItem->addItemToContainer(container, slotId);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
@ -7,23 +7,29 @@ class StructurePiece;
|
|||
class Level;
|
||||
class BoundingBox;
|
||||
|
||||
class XboxStructureActionPlaceContainer : public XboxStructureActionPlaceBlock
|
||||
{
|
||||
class XboxStructureActionPlaceContainer : public XboxStructureActionPlaceBlock {
|
||||
private:
|
||||
std::vector<AddItemRuleDefinition *> m_items;
|
||||
std::vector<AddItemRuleDefinition*> m_items;
|
||||
|
||||
public:
|
||||
XboxStructureActionPlaceContainer();
|
||||
~XboxStructureActionPlaceContainer();
|
||||
XboxStructureActionPlaceContainer();
|
||||
~XboxStructureActionPlaceContainer();
|
||||
|
||||
virtual ConsoleGameRules::EGameRuleType getActionType() { return ConsoleGameRules::eGameRuleType_PlaceContainer; }
|
||||
|
||||
virtual void getChildren(std::vector<GameRuleDefinition *> *children);
|
||||
virtual GameRuleDefinition *addChild(ConsoleGameRules::EGameRuleType ruleType);
|
||||
|
||||
// 4J-JEV: Super class handles attr-facing fine.
|
||||
//virtual void writeAttributes(DataOutputStream *dos, unsigned int numAttributes);
|
||||
|
||||
virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue);
|
||||
virtual ConsoleGameRules::EGameRuleType getActionType() {
|
||||
return ConsoleGameRules::eGameRuleType_PlaceContainer;
|
||||
}
|
||||
|
||||
bool placeContainerInLevel(StructurePiece *structure, Level *level, BoundingBox *chunkBB);
|
||||
virtual void getChildren(std::vector<GameRuleDefinition*>* children);
|
||||
virtual GameRuleDefinition* addChild(
|
||||
ConsoleGameRules::EGameRuleType ruleType);
|
||||
|
||||
// 4J-JEV: Super class handles attr-facing fine.
|
||||
// virtual void writeAttributes(DataOutputStream *dos, unsigned int
|
||||
// numAttributes);
|
||||
|
||||
virtual void addAttribute(const std::wstring& attributeName,
|
||||
const std::wstring& attributeValue);
|
||||
|
||||
bool placeContainerInLevel(StructurePiece* structure, Level* level,
|
||||
BoundingBox* chunkBB);
|
||||
};
|
||||
|
|
@ -5,65 +5,64 @@
|
|||
#include "../../Minecraft.World/Headers/net.minecraft.world.level.h"
|
||||
#include "../../Minecraft.World/Headers/net.minecraft.world.level.tile.entity.h"
|
||||
|
||||
XboxStructureActionPlaceSpawner::XboxStructureActionPlaceSpawner()
|
||||
{
|
||||
m_tile = Tile::mobSpawner_Id;
|
||||
m_entityId = L"Pig";
|
||||
XboxStructureActionPlaceSpawner::XboxStructureActionPlaceSpawner() {
|
||||
m_tile = Tile::mobSpawner_Id;
|
||||
m_entityId = L"Pig";
|
||||
}
|
||||
|
||||
XboxStructureActionPlaceSpawner::~XboxStructureActionPlaceSpawner()
|
||||
{
|
||||
XboxStructureActionPlaceSpawner::~XboxStructureActionPlaceSpawner() {}
|
||||
|
||||
void XboxStructureActionPlaceSpawner::writeAttributes(DataOutputStream* dos,
|
||||
unsigned int numAttrs) {
|
||||
XboxStructureActionPlaceBlock::writeAttributes(dos, numAttrs + 1);
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_entity);
|
||||
dos->writeUTF(m_entityId);
|
||||
}
|
||||
|
||||
void XboxStructureActionPlaceSpawner::writeAttributes(DataOutputStream *dos, unsigned int numAttrs)
|
||||
{
|
||||
XboxStructureActionPlaceBlock::writeAttributes(dos, numAttrs + 1);
|
||||
|
||||
ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_entity);
|
||||
dos->writeUTF(m_entityId);
|
||||
}
|
||||
|
||||
void XboxStructureActionPlaceSpawner::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue)
|
||||
{
|
||||
if(attributeName.compare(L"entity") == 0)
|
||||
{
|
||||
m_entityId = attributeValue;
|
||||
void XboxStructureActionPlaceSpawner::addAttribute(
|
||||
const std::wstring& attributeName, const std::wstring& attributeValue) {
|
||||
if (attributeName.compare(L"entity") == 0) {
|
||||
m_entityId = attributeValue;
|
||||
#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
|
||||
}
|
||||
else
|
||||
{
|
||||
XboxStructureActionPlaceBlock::addAttribute(attributeName, attributeValue);
|
||||
}
|
||||
} else {
|
||||
XboxStructureActionPlaceBlock::addAttribute(attributeName,
|
||||
attributeValue);
|
||||
}
|
||||
}
|
||||
|
||||
bool XboxStructureActionPlaceSpawner::placeSpawnerInLevel(StructurePiece *structure, Level *level, BoundingBox *chunkBB)
|
||||
{
|
||||
int worldX = structure->getWorldX( m_x, m_z );
|
||||
int worldY = structure->getWorldY( m_y );
|
||||
int worldZ = structure->getWorldZ( m_x, m_z );
|
||||
bool XboxStructureActionPlaceSpawner::placeSpawnerInLevel(
|
||||
StructurePiece* structure, Level* level, BoundingBox* chunkBB) {
|
||||
int worldX = structure->getWorldX(m_x, m_z);
|
||||
int worldY = structure->getWorldY(m_y);
|
||||
int worldZ = structure->getWorldZ(m_x, m_z);
|
||||
|
||||
if ( chunkBB->isInside( worldX, worldY, worldZ ) )
|
||||
{
|
||||
if ( level->getTileEntity( worldX, worldY, worldZ ) != NULL )
|
||||
{
|
||||
// Remove the current tile entity
|
||||
level->removeTileEntity( worldX, worldY, worldZ );
|
||||
level->setTile( worldX, worldY, worldZ, 0 );
|
||||
}
|
||||
if (chunkBB->isInside(worldX, worldY, worldZ)) {
|
||||
if (level->getTileEntity(worldX, worldY, worldZ) != NULL) {
|
||||
// Remove the current tile entity
|
||||
level->removeTileEntity(worldX, worldY, worldZ);
|
||||
level->setTile(worldX, worldY, worldZ, 0);
|
||||
}
|
||||
|
||||
level->setTile( worldX, worldY, worldZ, m_tile );
|
||||
std::shared_ptr<MobSpawnerTileEntity> entity = std::dynamic_pointer_cast<MobSpawnerTileEntity>(level->getTileEntity( worldX, worldY, worldZ ));
|
||||
level->setTile(worldX, worldY, worldZ, m_tile);
|
||||
std::shared_ptr<MobSpawnerTileEntity> entity =
|
||||
std::dynamic_pointer_cast<MobSpawnerTileEntity>(
|
||||
level->getTileEntity(worldX, worldY, worldZ));
|
||||
|
||||
#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
|
||||
if( entity != NULL )
|
||||
{
|
||||
entity->setEntityId(m_entityId);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
if (entity != NULL) {
|
||||
entity->setEntityId(m_entityId);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
@ -7,18 +7,22 @@ class Level;
|
|||
class BoundingBox;
|
||||
class GRFObject;
|
||||
|
||||
class XboxStructureActionPlaceSpawner : public XboxStructureActionPlaceBlock
|
||||
{
|
||||
class XboxStructureActionPlaceSpawner : public XboxStructureActionPlaceBlock {
|
||||
private:
|
||||
std::wstring m_entityId;
|
||||
std::wstring m_entityId;
|
||||
|
||||
public:
|
||||
XboxStructureActionPlaceSpawner();
|
||||
~XboxStructureActionPlaceSpawner();
|
||||
XboxStructureActionPlaceSpawner();
|
||||
~XboxStructureActionPlaceSpawner();
|
||||
|
||||
virtual ConsoleGameRules::EGameRuleType getActionType() { return ConsoleGameRules::eGameRuleType_PlaceSpawner; }
|
||||
|
||||
virtual void writeAttributes(DataOutputStream *dos, unsigned int numAttrs);
|
||||
virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue);
|
||||
virtual ConsoleGameRules::EGameRuleType getActionType() {
|
||||
return ConsoleGameRules::eGameRuleType_PlaceSpawner;
|
||||
}
|
||||
|
||||
bool placeSpawnerInLevel(StructurePiece *structure, Level *level, BoundingBox *chunkBB);
|
||||
virtual void writeAttributes(DataOutputStream* dos, unsigned int numAttrs);
|
||||
virtual void addAttribute(const std::wstring& attributeName,
|
||||
const std::wstring& attributeValue);
|
||||
|
||||
bool placeSpawnerInLevel(StructurePiece* structure, Level* level,
|
||||
BoundingBox* chunkBB);
|
||||
};
|
||||
Loading…
Reference in a new issue