diff options
| author | Kris Parker | 2009-11-13 22:26:17 +0000 |
|---|---|---|
| committer | Kris Parker | 2009-11-13 22:26:17 +0000 |
| commit | 1cb48474b399549ca64dca40ab2ad20a80d3db30 (patch) | |
| tree | 74f3a8754eba20def409d7687997eab510d1709c /BlockCondition.cpp | |
| parent | a71d4adc7da44c0d5fa70eaba700afea6bb4f89d (diff) | |
| download | stonesense-1cb48474b399549ca64dca40ab2ad20a80d3db30.tar.gz stonesense-1cb48474b399549ca64dca40ab2ad20a80d3db30.tar.bz2 stonesense-1cb48474b399549ca64dca40ab2ad20a80d3db30.tar.xz | |
First pass at merging new building config
Diffstat (limited to 'BlockCondition.cpp')
| -rw-r--r-- | BlockCondition.cpp | 332 |
1 files changed, 282 insertions, 50 deletions
diff --git a/BlockCondition.cpp b/BlockCondition.cpp index aaf5c47..0723dd3 100644 --- a/BlockCondition.cpp +++ b/BlockCondition.cpp @@ -1,36 +1,59 @@ #include "BlockCondition.h"
#include "GameBuildings.h"
#include "WorldSegment.h"
+#include <iostream>
-BlockCondition::BlockCondition(BlockConditionTypes type)
+int getDirectionFromString(const char* strDir)
{
- this->type = type;
- this->value = INVALID_INDEX;
+ if (strDir == NULL)
+ return INVALID_INDEX;
+ if( strcmp(strDir, "None") == 0)
+ return eSimpleSingle;
+ if( strcmp(strDir, "North") == 0)
+ return eSimpleN;
+ if( strcmp(strDir, "South") == 0)
+ return eSimpleS;
+ if( strcmp(strDir, "West") == 0)
+ return eSimpleW;
+ if( strcmp(strDir, "East") == 0)
+ return eSimpleE;
+ //these will change when rotation is available
+ if( strcmp(strDir, "TopRight") == 0)
+ return eSimpleN;
+ if( strcmp(strDir, "BottomLeft") == 0)
+ return eSimpleS;
+ if( strcmp(strDir, "TopLeft") == 0)
+ return eSimpleW;
+ if( strcmp(strDir, "BottomRight") == 0)
+ return eSimpleE;
+ return INVALID_INDEX;
}
+int getBuildingFromString(const char* strType)
+{
+ for (uint32_t i=0; i<v_buildingtypes.size(); i++){
+ if (v_buildingtypes[i].compare(strType) == 0)
+ {
+ return i;
+ }
+ }
+ return INVALID_INDEX;
+}
+NeighbourWallCondition::NeighbourWallCondition(const char* strDir)
+ : BlockCondition()
+{
+ this->value = getDirectionFromString(strDir);
+}
-bool BlockCondition::Matches(Block* b){
- if(type == Cond_PositionIndex){
- int x = b->x - b->building.info.x1;
- int y = b->y - b->building.info.y1;
- int w = b->building.info.x2 - b->building.info.x1 + 1 ;
- int pos = y * w + x;
-
- return pos == this->value;
- }
- if(type == Cond_MaterialType){
- return b->building.info.material.type == this->value;
- }
-
- if(type == Cond_NeighbourWall){
- //dirTypes closebyWalls = findWallCloseTo(b->ownerSegment,b);
+bool NeighbourWallCondition::Matches(Block* b)
+{
bool n = hasWall( b->ownerSegment->getBlockRelativeTo( b->x, b->y, b->z, eUp ) );
bool s = hasWall( b->ownerSegment->getBlockRelativeTo( b->x, b->y, b->z, eDown ) );
bool w = hasWall( b->ownerSegment->getBlockRelativeTo( b->x, b->y, b->z, eLeft ) );
bool e = hasWall( b->ownerSegment->getBlockRelativeTo( b->x, b->y, b->z, eRight ) );
-
+
if( value == eSimpleN && n) return true;
if( value == eSimpleS && s) return true;
if( value == eSimpleW && w) return true;
@@ -39,16 +62,102 @@ bool BlockCondition::Matches(Block* b){ if( value == eSimpleSingle && !n && !s && !w && !e) return true;
return false;
- }
+}
- if(type == Cond_NeighbourSameBuilding){
- int blocksBuildingID = b->building.info.type;
- bool n = hasBuildingOfID( b->ownerSegment->getBlockRelativeTo( b->x, b->y, b->z, eUp ), blocksBuildingID );
- bool s = hasBuildingOfID( b->ownerSegment->getBlockRelativeTo( b->x, b->y, b->z, eDown ), blocksBuildingID );
- bool w = hasBuildingOfID( b->ownerSegment->getBlockRelativeTo( b->x, b->y, b->z, eLeft ), blocksBuildingID);
- bool e = hasBuildingOfID( b->ownerSegment->getBlockRelativeTo( b->x, b->y, b->z, eRight ), blocksBuildingID );
-
+PositionIndexCondition::PositionIndexCondition(const char* strValue)
+ : BlockCondition()
+{
+ this->value = atoi( strValue );
+}
+
+bool PositionIndexCondition::Matches(Block* b)
+{
+ int x = b->x - b->building.info.x1;
+ int y = b->y - b->building.info.y1;
+ int w = b->building.info.x2 - b->building.info.x1 + 1 ;
+ int pos = y * w + x;
+
+ return pos == this->value;
+}
+
+
+
+
+MaterialTypeCondition::MaterialTypeCondition(const char* strValue)
+ : BlockCondition()
+{
+ // is there a better way to handle this?
+ // seems non-extensible
+ value = -1;
+ if( strcmp(strValue, "Wood") == 0)
+ value = Mat_Wood;
+ else if( strcmp(strValue, "Stone") == 0)
+ value = Mat_Stone;
+ else if( strcmp(strValue, "Metal") == 0)
+ value = Mat_Metal;
+ else if( strcmp(strValue, "Leather") == 0)
+ value = Mat_Leather;
+ else if( strcmp(strValue, "Silk") == 0)
+ value = Mat_SilkCloth;
+ else if( strcmp(strValue, "PlantCloth") == 0)
+ value = Mat_PlantCloth;
+ else if( strcmp(strValue, "GreenGlass") == 0)
+ value = Mat_GreenGlass;
+ else if( strcmp(strValue, "ClearGlass") == 0)
+ value = Mat_ClearGlass;
+ else if( strcmp(strValue, "CrystalGlass") == 0)
+ value = Mat_CrystalGlass;
+}
+
+bool MaterialTypeCondition::Matches(Block* b)
+{
+ return b->building.info.material.type == this->value;
+}
+
+
+AnimationFrameCondition::AnimationFrameCondition(const char* strValue)
+ : BlockCondition()
+{
+ this->value = atoi( strValue );
+}
+
+bool AnimationFrameCondition::Matches(Block* b)
+{
+ //not doing animation yet: always frame 0
+ return this->value==0;
+ //return this->value == currentAnimationFrame;
+}
+
+
+BuildingOccupancyCondition::BuildingOccupancyCondition(const char* strValue)
+ : BlockCondition()
+{
+ this->value = atoi( strValue );
+}
+
+bool BuildingOccupancyCondition::Matches(Block* b)
+{
+ return b->occ.bits.building == this->value;
+}
+
+
+
+NeighbourSameBuildingCondition::NeighbourSameBuildingCondition(const char* strDir)
+ : BlockCondition()
+{
+ this->value = getDirectionFromString(strDir);
+}
+
+bool NeighbourSameBuildingCondition::Matches(Block* b)
+{
+ int blocksBuildingIndex = b->building.index;
+
+ bool n = hasBuildingOfIndex( b->ownerSegment->getBlockRelativeTo( b->x, b->y, b->z, eUp ), blocksBuildingIndex );
+ bool s = hasBuildingOfIndex( b->ownerSegment->getBlockRelativeTo( b->x, b->y, b->z, eDown ), blocksBuildingIndex );
+ bool w = hasBuildingOfIndex( b->ownerSegment->getBlockRelativeTo( b->x, b->y, b->z, eLeft ), blocksBuildingIndex );
+ bool e = hasBuildingOfIndex( b->ownerSegment->getBlockRelativeTo( b->x, b->y, b->z, eRight ), blocksBuildingIndex );
+
if( value == eSimpleN && n) return true;
if( value == eSimpleS && s) return true;
if( value == eSimpleW && w) return true;
@@ -57,10 +166,18 @@ bool BlockCondition::Matches(Block* b){ if( value == eSimpleSingle && !n && !s && !w && !e) return true;
return false;
- }
-
- if(type == Cond_NeighbourIdentical){
-
+}
+
+
+
+NeighbourIdenticalCondition::NeighbourIdenticalCondition(const char* strDir)
+ : BlockCondition()
+{
+ this->value = getDirectionFromString(strDir);
+}
+
+bool NeighbourIdenticalCondition::Matches(Block* b)
+{
int blocksBuildingIndex = b->building.index;
int blocksBuildingOcc = b->occ.bits.building;
@@ -77,30 +194,145 @@ bool BlockCondition::Matches(Block* b){ if( value == eSimpleSingle && !n && !s && !w && !e) return true;
return false;
- }
+}
- if(type == Cond_NeighbourSameIndex){
-
- int blocksBuildingIndex = b->building.index;
- bool n = hasBuildingOfIndex( b->ownerSegment->getBlockRelativeTo( b->x, b->y, b->z, eUp ), blocksBuildingIndex );
- bool s = hasBuildingOfIndex( b->ownerSegment->getBlockRelativeTo( b->x, b->y, b->z, eDown ), blocksBuildingIndex );
- bool w = hasBuildingOfIndex( b->ownerSegment->getBlockRelativeTo( b->x, b->y, b->z, eLeft ), blocksBuildingIndex );
- bool e = hasBuildingOfIndex( b->ownerSegment->getBlockRelativeTo( b->x, b->y, b->z, eRight ), blocksBuildingIndex );
+NeighbourOfTypeCondition::NeighbourOfTypeCondition(const char* strDir, const char* strType)
+ : BlockCondition()
+{
+ this->direction = getDirectionFromString(strDir);
+ this->value = getBuildingFromString(strType);
+}
- if( value == eSimpleN && n) return true;
- if( value == eSimpleS && s) return true;
- if( value == eSimpleW && w) return true;
- if( value == eSimpleE && e) return true;
+bool NeighbourOfTypeCondition::Matches(Block* b)
+{
+ bool n = hasBuildingOfID( b->ownerSegment->getBlockRelativeTo( b->x, b->y, b->z, eUp ), value );
+ bool s = hasBuildingOfID( b->ownerSegment->getBlockRelativeTo( b->x, b->y, b->z, eDown ), value );
+ bool w = hasBuildingOfID( b->ownerSegment->getBlockRelativeTo( b->x, b->y, b->z, eLeft ), value);
+ bool e = hasBuildingOfID( b->ownerSegment->getBlockRelativeTo( b->x, b->y, b->z, eRight ), value );
+
+ if( direction == eSimpleN && n) return true;
+ if( direction == eSimpleS && s) return true;
+ if( direction == eSimpleW && w) return true;
+ if( direction == eSimpleE && e) return true;
- if( value == eSimpleSingle && !n && !s && !w && !e) return true;
+ if( direction == eSimpleSingle && !n && !s && !w && !e) return true;
return false;
- }
-
- if(type == Cond_BuildingOcc){
- return b->occ.bits.building == this->value;
- }
+}
+
+NeighbourSameTypeCondition::NeighbourSameTypeCondition(const char* strDir)
+ : BlockCondition()
+{
+ this->direction = getDirectionFromString(strDir);
+}
+
+bool NeighbourSameTypeCondition::Matches(Block* b)
+{
+ int value = b->building.info.type;
+
+ bool n = hasBuildingOfID( b->ownerSegment->getBlockRelativeTo( b->x, b->y, b->z, eUp ), value );
+ bool s = hasBuildingOfID( b->ownerSegment->getBlockRelativeTo( b->x, b->y, b->z, eDown ), value );
+ bool w = hasBuildingOfID( b->ownerSegment->getBlockRelativeTo( b->x, b->y, b->z, eLeft ), value);
+ bool e = hasBuildingOfID( b->ownerSegment->getBlockRelativeTo( b->x, b->y, b->z, eRight ), value );
+
+ if( direction == eSimpleN && n) return true;
+ if( direction == eSimpleS && s) return true;
+ if( direction == eSimpleW && w) return true;
+ if( direction == eSimpleE && e) return true;
- return false;
+ if( direction == eSimpleSingle && !n && !s && !w && !e) return true;
+
+ return false;
+}
+
+AndConditionalNode::~AndConditionalNode(void)
+{
+ int max = children.size();
+ for(uint32_t i=0; i<max; i++)
+ {
+ delete(children[i]);
+ }
+}
+
+bool AndConditionalNode::Matches(Block* b)
+{
+ int max = children.size();
+ for(uint32_t i=0; i<max; i++)
+ {
+ if (!children[i]->Matches( b ))
+ return false;
+ }
+ return true;
+}
+bool AndConditionalNode::addCondition(BlockCondition* cond)
+{
+ children.push_back(cond);
+ return true;
+}
+
+OrConditionalNode::~OrConditionalNode(void)
+{
+ int max = children.size();
+ for(uint32_t i=0; i<max; i++)
+ {
+ delete(children[i]);
+ }
+}
+
+bool OrConditionalNode::Matches(Block* b)
+{
+ int max = children.size();
+ for(uint32_t i=0; i<max; i++)
+ {
+ if (children[i]->Matches( b ))
+ return true;
+ }
+ return false;
+}
+bool OrConditionalNode::addCondition(BlockCondition* cond)
+{
+ children.push_back(cond);
+ return true;
+}
+
+bool AlwaysCondition::Matches(Block* b)
+{
+ return true;
+}
+bool NeverCondition::Matches(Block* b)
+{
+ return false;
+}
+
+NotConditionalNode::NotConditionalNode(void)
+{
+ childcond = NULL;
+}
+
+NotConditionalNode::~NotConditionalNode(void)
+{
+ delete(childcond);
+}
+
+bool NotConditionalNode::Matches(Block* b)
+{
+ if (childcond == NULL)
+ return true;
+ return !childcond->Matches( b );
+}
+bool NotConditionalNode::addCondition(BlockCondition* cond)
+{
+ if (childcond != NULL)
+ {
+ WriteErr("Too many condition elements for NotConditionalNode\n");
+ return false;
+ }
+ childcond = cond;
+ return true;
+}
+
+bool HaveFloorCondition::Matches(Block* b)
+{
+ return (b->floorType > 0);
}
|
