#include #define TITLE Quest( #define DESC , #define REWARD ,(struct item_t){ #define x , #define END }), const Quest QuestList[TOTAL_QUESTS]={ // Quest("Test","A test quest",(struct item_t){1,TEST_ITEM}), // Get quest list #include "../config/quest_list.txt" }; Quest::Quest(const char *t,const char *d,struct item_t r){ strcpy((title=(char *)malloc(strlen(t))),t); strcpy((desc =(char *)malloc(strlen(d))),d); memcpy(&reward,&r,sizeof(struct item_t)); } Quest::~Quest(){ free(title); free(desc); memset(&reward,0,sizeof(struct item_t)); } int QuestHandler::assign(const char *t){ unsigned char i; for(i=0;ititle,t)){ #ifdef DEBUG DEBUG_printf("The QuestHandler already has this quest: %s\n",t); #endif // DEBUG return -2; } } for(i=0;ititle,t)){ current.erase(current.begin()+i); return current.size(); } } return -1; } int QuestHandler::finish(const char *t,void *completer){ unsigned char i; unsigned int r; for(i=0;ititle,t)){ #ifdef DEBUG DEBUG_printf("Completing quest %s.\n",t); #endif // DEBUG ((Entity *)completer)->inv->addItem(current[i]->reward.id,current[i]->reward.count); current.erase(current.begin()+i); #ifdef DEBUG DEBUG_printf("QuestHandler now has %u active quests.\n",current.size()); #endif // DEBUG return 0; } } #ifdef DEBUG DEBUG_printf("QuestHandler never had quest %s.\n",t); #endif // DEBUG return -1; } bool QuestHandler::hasQuest(const char *t){ unsigned int i; for(i=0;ititle,t)){ return true; } } return false; }