- added DEBUG flags to common.cpp and Quest.cpp
- added player health
- made textures for rabbit
+
+10/15/2015:
+===========
+
+ - fixed quest assignment/completion
+ - entities can't move when interacting now
--- /dev/null
+TITLE "Test" DESC "A test quest" REWARD 1 x TEST_ITEM END
#include <common.h>
#include <inventory.h>
+#define DEBUG
+
#define NPCp(n) ((NPC *)n)
#define PLAYER_INV_SIZE 30 // The size of the player's inventory
Inventory *inv;
void *inWorld;
-
+
float width; //width and height of the player
float height;
float speed; //speed of the play
int health;
int maxHealth;
-
+
int subtype;
_TYPE type;
//example:
// |(subtype)
// |-> 0 Base NPC
// |-> 1 Merchant
-
+
vec2 loc; //location and velocity of the entity
vec2 vel;
-
+
bool near;
bool right,left, canMove; //movement variables
bool alive; //the flag for whether or not the entity is alive
GENDER gender;
GLuint texture[3]; //TODO: ADD TEXTURES
-
+
void spawn(float, float);
void draw(void);
virtual void wander(int, vec2*){}
public:
std::vector<int (*)(NPC *)>aiFunc;
NPC();
- void addAIFunc(int (*func)(NPC *));
+ void addAIFunc(int (*func)(NPC *),bool preload);
+ void flushAIFunc(void);
void interact();
void wander(int, vec2*);
};
|->1 Merchant
|
2 MOBS
-<<<<<<< HEAD
-|->1 Rabbit
-**/
-=======
|->1 Skirl
**/
->>>>>>> 58716d5e4f20eb5a30025c88fe5119a0e40c4187
switch(entity[i]->type){
case NPCT: // Handle NPCs
- entity[i]->wander((rand()%120 + 30), &entity[i]->vel); // Make the NPC wander
+ if(entity[i]->canMove)entity[i]->wander((rand()%120 + 30), &entity[i]->vel); // Make the NPC wander
// Check if the NPC is near the player and handle potential interaction
if(pow((entity[i]->loc.x - player->loc.x),2) + pow((entity[i]->loc.y - player->loc.y),2) <= pow(40*HLINE,2)){
#include <common.h>\r
-//#include <Quest.h>\r
-//#include <entities.h>\r
+\r
+#define TITLE Quest(\r
+#define DESC ,\r
+#define REWARD ,(struct item_t){\r
+#define x ,\r
+#define END }),\r
\r
const Quest QuestList[TOTAL_QUESTS]={\r
- Quest("Test","A test quest",(struct item_t){1,TEST_ITEM})\r
+// Quest("Test","A test quest",(struct item_t){1,TEST_ITEM}),\r
+\r
+// Get quest list\r
+#include "../config/quest_list.txt"\r
+\r
};\r
\r
Quest::Quest(const char *t,const char *d,struct item_t r){\r
- size_t len;\r
- title=(char *)malloc((len=strlen(t)));\r
- strncpy(title,t,len);\r
- desc=(char *)malloc((len=strlen(d)));\r
- strncpy(desc,d,len);\r
+ strcpy((title=(char *)malloc(strlen(t))),t);\r
+ strcpy((desc =(char *)malloc(strlen(d))),d);\r
memcpy(&reward,&r,sizeof(struct item_t));\r
}\r
\r
#endif // DEBUG\r
return current.size();\r
}\r
+#ifdef DEBUG\r
+ DEBUG_printf("Finding quest: %s != %s\n",t,QuestList[i].title);\r
+#endif // DEBUG\r
}\r
#ifdef DEBUG\r
DEBUG_printf("Quest %s does not exist.\n",t);\r
vprintf(s,args);
va_end(args);
}
+
left = false;
near = false;
ticksToUse = 0;
- canMove = false;
+ canMove = true;
ground = false;
name = (char*)malloc(16);
getName();
texState-=1;
if(texState==0)up=true;
}
- }if(ground == 0){
+ }
+ if(ground == 0){
glBindTexture(GL_TEXTURE_2D, texture[1]);
}
else if(vel.x != 0){
glBindTexture(GL_TEXTURE_2D,texture[2]);
break;
}
- }else{
+ }
+ else{
glBindTexture(GL_TEXTURE_2D,texture[0]);
}
}else if(type == MOBT){
ticksToUse--; //removes one off of the entities timer
}
+static int (*AIpreload)(NPC *);
+
+void NPC::addAIFunc(int (*func)(NPC *),bool preload){
+ if(preload)
+#ifdef DEBUG
+ {
+ DEBUG_printf("Preloading an AI %x.\n",func);
+#endif // DEBUG
+ AIpreload=func;
+#ifdef DEBUG
+ }
+#endif // DEBUG
+ else aiFunc.push_back(func);
+}
-void NPC::addAIFunc(int (*func)(NPC *)){
- aiFunc.push_back(func);
+void NPC::flushAIFunc(void){
+ if(AIpreload){
+#ifdef DEBUG
+ DEBUG_printf("Unloading preloaded AI function %x.\n",AIpreload);
+#endif // DEBUG
+ aiFunc.push_back(AIpreload);
+ AIpreload=NULL;
+ }
}
void NPC::interact(){ //have the npc's interact back to the player
loc.y += 5;
if(aiFunc.size()){
func=aiFunc.front();
+ canMove=false;
if(!func(this)){
aiFunc.erase(aiFunc.begin());
}
+ canMove=true;
}
}
}
ticksToUse--; //removes one off of the entities timer
}
-}
\ No newline at end of file
+}
int giveTestQuest(NPC *speaker){
ui::dialogBox(speaker->name,"Here, have a quest!");
player->qh.assign("Test");
- NPCp(entity[2])->addAIFunc(compTestQuest);
- return 0;
-}
-
-int giveStuff(NPC *speaker){
- ui::dialogBox(speaker->name,"Have a sword :D");
- player->inv->addItem(SWORD_ITEM,1);
+ NPCp(entity[2])->addAIFunc(compTestQuest,true);
return 0;
}
entity.pop_back();
- NPCp(entity[1])->addAIFunc(giveStuff);
- NPCp(entity[1])->addAIFunc(giveTestQuest);
+ NPCp(entity[1])->addAIFunc(giveTestQuest,false);
for(i=0;i<entity.size()+1;i++){
entity[i]->inWorld=test;
}
if(item[i].id==id){
item[i].count+=count;
#ifdef DEBUG
- DEBUG_printf("Gave player %u more %s(s).\n",count,itemName[i]);
+ DEBUG_printf("Gave player %u more %s(s).\n",count,itemName[item[i].id]);
#endif // DEBUG
return 0;
}else if(!item[i].count){
item[i].id=id;
item[i].count=count;
#ifdef DEBUG
- DEBUG_printf("Gave player %u %s(s).\n",count,itemName[i]);
+ DEBUG_printf("Gave player %u %s(s).\n",count,itemName[item[i].id]);
#endif // DEBUG
return 0;
}
extern Player *player; // 'player' should be (must be) defined in main.cpp
extern World *currentWorld; // should/must also be defined in main.cpp
+extern std::vector<NPC>npc;
+
static FT_Library ftl; // Variables for the FreeType library and stuff
static FT_Face ftf;
static GLuint ftex;
h=ftf->glyph->bitmap.rows;
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,ftex);
- switch(c){
+ switch(c){ // Some characters are not properly spaced, make them so here
case '^':
case '*':
case '`':
break;
}
}
+ static bool once=false;
+ unsigned int i;
+ if(!dialogBoxExists&&!once){
+ for(i=0;i<npc.size();i++){
+ npc[i].flushAIFunc();
+ }
+ once=true;
+ }else once=false;
}
}