aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/common.h19
-rw-r--r--include/world.h58
-rw-r--r--src/common.cpp18
-rw-r--r--src/world.cpp36
4 files changed, 67 insertions, 64 deletions
diff --git a/include/common.h b/include/common.h
index ff8d361..71335f2 100644
--- a/include/common.h
+++ b/include/common.h
@@ -186,23 +186,6 @@ extern unsigned int loops;
extern GLuint shaderProgram;
/**
- * This class contains a string for identification and a value. It can be used to
- * save certain events for and decisions so that they can be recalled later.
- */
-
-class Condition {
-private:
- char *id;
- void *value;
-public:
- Condition(const char *_id,void *val);
- ~Condition();
-
- bool sameID(const char *s);
- void *getValue(void);
-};
-
-/**
* Prints a formatted debug message to the console, along with the callee's file and line
* number.
*/
@@ -244,6 +227,4 @@ int strCreateFunc(const char *equ);
template<typename N, size_t s>
size_t arrAmt(N (&)[s]){return s;}
-extern void *NULLPTR;
-
#endif // COMMON_H
diff --git a/include/world.h b/include/world.h
index f9e952e..56f1577 100644
--- a/include/world.h
+++ b/include/world.h
@@ -81,24 +81,54 @@ typedef struct line_t {
unsigned char color; /**< Lightness of dirt (brown) */
} line_t;
-/*
- * Handle all logic that has to do with villages
+class World;
+
+/**
+ * The village class, used to group structures into villages.
*/
+class Village {
+public:
+
+ /**
+ * The name of the village.
+ */
-struct Village{
std::string name;
+
+ /**
+ * The coordinate of where the village starts.
+ *
+ * This is used to check if the player has entered the village's area.
+ */
+
vec2 start;
+
+ /**
+ * The coordinate of where the village ends.
+ *
+ * This is used to check if the player has entered the village's area.
+ */
+
vec2 end;
+
+ /**
+ * TODO
+ */
+
bool in;
+ /**
+ * A vector of all structures that are associated with this village.
+ */
+
std::vector<Structures *> build;
- Village(const char *meme){
- name = meme;
- end.x = -0xffffffff;
- start.x = 0xffffffff;
- in = false;
- }
+
+ /**
+ * Creates a village of name `meme` in the world `w`.
+ */
+
+ Village(const char *meme, World *w);
};
/**
@@ -132,8 +162,6 @@ protected:
*/
void singleDetect(Entity *e);
-
- static void villageLogic(World *world);
/**
* Empties all entity vectors.
@@ -253,6 +281,11 @@ public:
std::vector<Particles *> particles;
+
+
+
+ std::vector<Village * > village;
+
/**
* A vector of all light elements in this world.
*/
@@ -264,9 +297,6 @@ public:
*/
std::vector<std::string > sTexLoc;
-
- std::vector<Village>village;
-
/**
* NULLifies pointers and allocates necessary memory. This should be
diff --git a/src/common.cpp b/src/common.cpp
index faa7012..01c8779 100644
--- a/src/common.cpp
+++ b/src/common.cpp
@@ -10,8 +10,6 @@
#include <vector>
#endif // __WIN32__
-void *NULLPTR = NULL;
-
#ifndef __WIN32__
unsigned int millis(void){
@@ -21,22 +19,6 @@ unsigned int millis(void){
#endif // __WIN32__
-Condition::Condition(const char *_id,void *val){
- id = new char[strlen(_id)+1];
- strcpy(id,_id);
- value = val;
-}
-Condition::~Condition(){
- delete[] id;
-}
-
-bool Condition::sameID(const char *s){
- return !strcmp(id,s);
-}
-void *Condition::getValue(void){
- return value;
-}
-
void DEBUG_prints(const char* file, int line, const char *s,...){
va_list args;
printf("%s:%d: ",file,line);
diff --git a/src/world.cpp b/src/world.cpp
index 2df0712..303d53b 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -999,13 +999,13 @@ void World::detect(Player *p){
}
for(auto &v : village){
- if(p->loc.x > v.start.x && p->loc.x < v.end.x){
- if(!v.in){
- ui::passiveImportantText(5000,"Welcome to %s",v.name.c_str());
- v.in = true;
+ if(p->loc.x > v->start.x && p->loc.x < v->end.x){
+ if(!v->in){
+ ui::passiveImportantText(5000,"Welcome to %s",v->name.c_str());
+ v->in = true;
}
}else{
- v.in = false;
+ v->in = false;
}
}
@@ -1614,8 +1614,11 @@ World *loadWorldFromXMLNoSave(const char *path){
wxml = wxml->NextSiblingElement();
}
+ Village *vptr;
+
if(vil){
- tmp->village.push_back(vil->Attribute("name"));
+ tmp->village.push_back(new Village(vil->Attribute("name"), tmp));
+ vptr = tmp->village.back();
vil = vil->FirstChildElement();
}
@@ -1627,22 +1630,22 @@ World *loadWorldFromXMLNoSave(const char *path){
/**
* READS DATA ABOUT STRUCTURE CONTAINED IN VILLAGE
*/
+
if(!strcmp(name,"structure")){
ptr = vil->Attribute("inside");
tmp->addStructure((BUILD_SUB)vil->UnsignedAttribute("type"),
- vil->QueryFloatAttribute("x", &spawnx) != XML_NO_ERROR ?
- randx : spawnx,
+ vil->QueryFloatAttribute("x", &spawnx) != XML_NO_ERROR ? randx : spawnx,
100,
(char*)vil->Attribute("texture"),
ptr);
- tmp->village.back().build.push_back(tmp->build.back());
+ vptr->build.push_back(tmp->build.back());
}
- if(tmp->village.back().build.back()->loc.x < tmp->village.back().start.x){
- tmp->village.back().start.x = tmp->village.back().build.back()->loc.x;
+ if(vptr->build.back()->loc.x < vptr->start.x){
+ vptr->start.x = vptr->build.back()->loc.x;
}
- if(tmp->village.back().build.back()->loc.x + tmp->village.back().build.back()->width > tmp->village.back().end.x){
- tmp->village.back().end.x = tmp->village.back().build.back()->loc.x + tmp->village.back().build.back()->width;
+ if(vptr->build.back()->loc.x + vptr->build.back()->width > vptr->end.x){
+ vptr->end.x = vptr->build.back()->loc.x + vptr->build.back()->width;
}
//go to the next element in the village block
@@ -1657,3 +1660,10 @@ World *loadWorldFromXMLNoSave(const char *path){
return tmp;
}
+
+Village::Village(const char *meme, World *w){
+ name = meme;
+ start.x = w->getTheWidth() / 2.0f;
+ end.x = -start.x;
+ in = false;
+}