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