]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
village cleanup?
authorClyne Sullivan <tullivan99@gmail.com>
Fri, 26 Feb 2016 12:49:33 +0000 (07:49 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Fri, 26 Feb 2016 12:49:33 +0000 (07:49 -0500)
include/common.h
include/world.h
src/common.cpp
src/world.cpp

index ff8d361b5ab4abc077cab0be7fa125c3d09d1725..71335f2648e8e0c6987923050ec31f508ea449af 100644 (file)
@@ -185,23 +185,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
index f9e952e7d5fe3fe35b282b420b44f1416febcdac..56f1577200f4684ecd391ad82df19fc4b40f722f 100644 (file)
@@ -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
index faa7012bbf0832b3ade9ae90adb16a096bae09eb..01c87794532b8cda73071a696c1f9993f6df9895 100644 (file)
@@ -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);
index 2df0712df9ed00ad02c30b5639d041964dd04dd9..303d53b020c9121a13ae12d1367f971f29f770de 100644 (file)
@@ -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;
+}