summaryrefslogtreecommitdiff
path: root/ConditionalSprite.cpp
diff options
context:
space:
mode:
authorJapa2010-04-09 14:24:27 +0000
committerJapa2010-04-09 14:24:27 +0000
commit114df922d3073bd296b38cf522997f520fb17850 (patch)
treec4cf372825118c3663cd77e18c69a6c3b59d070f /ConditionalSprite.cpp
parent81aefc8e03ff3f647494012e18bcdc8f33f4de42 (diff)
downloadstonesense-114df922d3073bd296b38cf522997f520fb17850.tar.gz
stonesense-114df922d3073bd296b38cf522997f520fb17850.tar.bz2
stonesense-114df922d3073bd296b38cf522997f520fb17850.tar.xz
updated trunk to the new graphics engine, and the latest DFhack
Diffstat (limited to 'ConditionalSprite.cpp')
-rw-r--r--ConditionalSprite.cpp175
1 files changed, 175 insertions, 0 deletions
diff --git a/ConditionalSprite.cpp b/ConditionalSprite.cpp
new file mode 100644
index 0000000..4e2c8fc
--- /dev/null
+++ b/ConditionalSprite.cpp
@@ -0,0 +1,175 @@
+#include "common.h"
+#include "ConditionalSprite.h"
+#include "Block.h"
+#include "GameBuildings.h"
+#include "GUI.h"
+
+/* RootBlock */
+
+RootBlock::RootBlock()
+ : SpriteNode()
+{
+ //cout << "RootBlock +" << endl;
+}
+
+RootBlock::~RootBlock(void)
+{
+ //cout << "RootBlock -" << endl;
+ uint32_t max = (uint32_t)children.size();
+ for(uint32_t i=0; i<max; i++)
+ {
+ delete(children[i]);
+ }
+}
+
+bool RootBlock::BlockMatches(Block* b)
+{
+ bool haveMatch = false;
+ uint32_t max = (uint32_t)children.size();
+
+ for(uint32_t i=0; i<max; i++)
+ {
+ if (children[i]->BlockMatches(b))
+ {
+ haveMatch = true;
+ }
+ }
+ return haveMatch;
+}
+
+void RootBlock::addChild(SpriteNode* child){
+ children.push_back(child);
+}
+
+/* SpriteBlock */
+
+SpriteBlock::SpriteBlock()
+ : ConditionalNode(), SpriteNode()
+{
+ //cout << "SpriteBlock +" << endl;
+ conditions = NULL;
+ elsenode = NULL;
+}
+
+SpriteBlock::~SpriteBlock(void)
+{
+ //cout << "SpriteBlock -" << endl;
+ delete(elsenode);
+ delete(conditions);
+ uint32_t max = (uint32_t)children.size();
+ for(uint32_t i=0; i<max; i++)
+ {
+ delete(children[i]);
+ }
+};
+
+bool SpriteBlock::BlockMatches(Block* b)
+{
+ bool condMatch = false;
+ if (conditions == NULL)
+ {
+ condMatch = true;
+ }
+ else
+ {
+ condMatch = conditions->Matches( b );
+ }
+
+ bool haveMatch=false;
+ if (condMatch)
+ {
+ uint32_t max = (uint32_t)children.size();
+ for(uint32_t i=0; i<max; i++)
+ {
+ if (children[i]->BlockMatches(b))
+ {
+ haveMatch = true;
+ }
+ }
+ }
+ else if (elsenode != NULL)
+ {
+ haveMatch = elsenode->BlockMatches(b);
+ }
+ return haveMatch;
+}
+
+bool SpriteBlock::addCondition(BlockCondition* cond){
+ if (conditions != NULL)
+ {
+ WriteErr("Too many condition elements for SpriteBlock\n");
+ return false;
+ }
+ conditions = cond;
+ return true;
+}
+
+void SpriteBlock::addChild(SpriteNode* child){
+ children.push_back(child);
+}
+
+void SpriteBlock::addElse(SpriteNode* child){
+ elsenode = child;
+}
+
+
+/* RotationBlock */
+
+RotationBlock::RotationBlock()
+ : ConditionalNode(), SpriteNode()
+{
+ //cout << "SpriteBlock +" << endl;
+}
+
+RotationBlock::~RotationBlock(void)
+{
+ //cout << "SpriteBlock -" << endl;
+ uint32_t max = (uint32_t)children.size();
+ for(uint32_t i=0; i<max; i++)
+ {
+ delete(children[i]);
+ }
+};
+
+bool RotationBlock::BlockMatches(Block* b)
+{
+ int index = DisplayedRotation;
+ int max = (int)children.size();
+ if (max == 0)
+ return false;
+ while (index >= max)
+ {
+ index = index - max;
+ }
+ return children[index]->BlockMatches(b);
+}
+
+bool RotationBlock::addCondition(BlockCondition* cond){
+ WriteErr("Condition elements not permitted for RotationBlock\n");
+ return false;
+}
+
+void RotationBlock::addChild(SpriteNode* child){
+ children.push_back(child);
+}
+
+/* SpriteElement */
+
+SpriteElement::SpriteElement()
+ : SpriteNode()
+{
+ //cout << "SpriteElement +" << endl;
+ sprite.sheetIndex = -1;
+ sprite.x = 0;
+ sprite.y = 0;
+ sprite.animFrames = 0;
+}
+
+bool SpriteElement::BlockMatches(Block* b)
+{
+ if (sprite.sheetIndex > -1)
+ {
+ b->building.sprites.push_back(sprite);
+ }
+ return true;
+}