aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Changelog8
-rw-r--r--config/settings.xml.example26
-rw-r--r--include/Quest.h11
-rw-r--r--include/inventory.h1
-rw-r--r--src/Quest.cpp54
-rw-r--r--src/gameplay.cpp17
-rw-r--r--src/inventory.cpp29
-rw-r--r--xml/playerSpawnHill1.xml5
-rw-r--r--xml/playerSpawnHill1_Building1.xml23
9 files changed, 143 insertions, 31 deletions
diff --git a/Changelog b/Changelog
index e8a0605..582259c 100644
--- a/Changelog
+++ b/Changelog
@@ -639,3 +639,11 @@
- quests can require one item for completion
- better-er text drawing
- can set world themes through XML
+
+2/10/2016:
+==========
+
+ - proper quest handling: multiple req's, re-classified, overall good
+ - began considering unique_ptr's because they're good
+ - fixed inventory everything
+ - themes work
diff --git a/config/settings.xml.example b/config/settings.xml.example
new file mode 100644
index 0000000..d9b8077
--- /dev/null
+++ b/config/settings.xml.example
@@ -0,0 +1,26 @@
+<?xml version="1.0"?>
+<screen width="1280" height="800" fullscreen="true"/>
+
+<!--
+
+Available fonts:
+
+ 8-BIT WONDER.TTF
+ FreePixel.ttf
+ Perfect DOS VGA 437.ttf
+ Perfect DOS VGA 437 Win.ttf
+ PIXEAB__.TTF
+ PIXEARG_.TTF
+ VCR_OSD_MONO_1.001.ttf
+
+-->
+
+<font path="ttf/FreePixel.ttf"/>
+
+<hline size="3"/>
+
+<volume>
+ <master volume="100"/>
+ <music volume="50"/>
+ <sfx volume="50"/>
+</volume>
diff --git a/include/Quest.h b/include/Quest.h
index 388b14d..8b1e142 100644
--- a/include/Quest.h
+++ b/include/Quest.h
@@ -20,11 +20,16 @@
#define DEBUG
+struct need_t {
+ std::string name;
+ int n;
+};
+
typedef struct {
std::string title;
std::string desc;
struct item_t reward;
- std::vector<std::string> need;
+ std::vector<struct need_t> need;
} Quest;
/**
@@ -42,13 +47,13 @@ public:
* Adds a quest to the current quest vector by its title.
*/
- int assign(const char *t);
+ int assign(std::string title,std::string desc,std::string req);
/**
* Drops a quest through its title.
*/
- int drop(const char *t);
+ int drop(std::string title);
/**
* Finishes a quest through it's title, also giving a pointer to the Entity
diff --git a/include/inventory.h b/include/inventory.h
index e5209de..af859a5 100644
--- a/include/inventory.h
+++ b/include/inventory.h
@@ -48,6 +48,7 @@ public:
int addItem(std::string name,uint count);
int takeItem(std::string name,uint count);
+ int hasItem(std::string name);
int useItem(void);
bool detectCollision(vec2,vec2);
diff --git a/src/Quest.cpp b/src/Quest.cpp
index ac18021..535afc5 100644
--- a/src/Quest.cpp
+++ b/src/Quest.cpp
@@ -4,21 +4,59 @@
extern Player *player;
-int QuestHandler::assign(const char *t){
- return strcmp(t,"h");
+int QuestHandler::assign(std::string title,std::string desc,std::string req){
+ Quest tmp;
+ char *tok;
+
+ tmp.title = title;
+ tmp.desc = desc;
+
+ std::unique_ptr<char[]> buf (new char[req.size()]);
+
+ strcpy(buf.get(),req.c_str());
+ tok = strtok(buf.get(),"\n\r\t,");
+ tmp.need.push_back({"\0",0});
+
+ while(tok){
+ if(tmp.need.back().name != "\0"){
+ tmp.need.back().n = atoi(tok);
+ tmp.need.push_back({"\0",0});
+ }else
+ tmp.need.back().name = tok;
+
+ tok = strtok(NULL,"\n\r\t,");
+ }
+
+ tmp.need.pop_back();
+ current.push_back(tmp);
+
+ return 0;
}
-int QuestHandler::drop(const char *t){
- return strcmp(t,"h");
+int QuestHandler::drop(std::string title){
+ for(unsigned int i=0;i<current.size();i++){
+ if(current[i].title == title){
+ current.erase(current.begin()+i);
+ return 0;
+ }
+ }
+ return -1;
}
int QuestHandler::finish(std::string t){
for(unsigned int i=0;i<current.size();i++){
if(current[i].title == t){
- if(!player->inv->takeItem(current[i].need.back(),1)){
- current.erase(current.begin()+i);
- return 1;
- }else return 0;
+ for(auto &n : current[i].need){
+ if(player->inv->hasItem(n.name) < n.n)
+ return 0;
+ }
+
+ for(auto &n : current[i].need){
+ player->inv->takeItem(n.name,n.n);
+ }
+
+ current.erase(current.begin()+i);
+ return 1;
}
}
return 0;
diff --git a/src/gameplay.cpp b/src/gameplay.cpp
index bceb811..e252c26 100644
--- a/src/gameplay.cpp
+++ b/src/gameplay.cpp
@@ -69,21 +69,12 @@ int commonAIFunc(NPC *speaker){
if((oxml = exml->FirstChildElement("quest"))){
const char *qname;
- Quest tmp;
+
while(oxml){
- if((qname = oxml->Attribute("assign"))){
- tmp.title = qname;
- tmp.desc = "None";
- tmp.reward = (struct item_t){0,0};
-
- if(oxml->GetText()){
- tmp.need.push_back(oxml->GetText());
- }
-
- player->qh.current.push_back(tmp);
- }else if((qname = oxml->Attribute("check"))){
+ if((qname = oxml->Attribute("assign")))
+ player->qh.assign(qname,"None",(std::string)oxml->GetText());
+ else if((qname = oxml->Attribute("check"))){
if(player->qh.hasQuest(qname) && player->qh.finish(qname)){
- player->qh.finish(qname);
goto CONT;
}else{
oldidx = speaker->dialogIndex;
diff --git a/src/inventory.cpp b/src/inventory.cpp
index d52dbe8..b32b56f 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -13,7 +13,7 @@ static bool swing = false;
static vec2 itemLoc;
Mix_Chunk* swordSwing;
-std::vector<Item *> itemMap;
+static std::vector<Item *> itemMap;
void items(void){
XMLDocument xml;
@@ -32,7 +32,7 @@ void items(void){
itemMap.back()->texloc = exml->Attribute("sprite");
exml = exml->NextSiblingElement();
- }
+ }
}
int Inventory::addItem(std::string name,uint count){
@@ -44,7 +44,7 @@ int Inventory::addItem(std::string name,uint count){
return 0;
}
}
- items.push_back((item_t){i,count});
+ items.push_back((item_t){count,i});
return 0;
}
}
@@ -87,6 +87,27 @@ int Inventory::takeItem(std::string name,uint count){
return -2;
}
+int Inventory::hasItem(std::string name){
+ unsigned int id = 999999;
+
+ for(unsigned int i=0;i<itemMap.size();i++){
+ if(itemMap[i]->name == name){
+ id = i;
+ break;
+ }
+ }
+
+ if(id == 999999)
+ return 0;
+
+ for(auto &i : items){
+ if(i.id == id)
+ return i.count;
+ }
+
+ return 0;
+}
+
static GLuint *itemtex;
void itemDraw(Player *p,uint id);
@@ -227,7 +248,7 @@ void Inventory::draw(void){
}
glEnd();
glDisable(GL_TEXTURE_2D);
- ui::putText(r.end.x-(itemWide/2),r.end.y-(itemWide*.9),"%s",itemMap[items[a].id]->name);
+ ui::putText(r.end.x-(itemWide/2),r.end.y-(itemWide*.9),"%s",itemMap[items[a].id]->name.c_str());
ui::putText(r.end.x-(itemWide/2)+(itemWide*.85),r.end.y-(itemWide/2),"%d",items[a].count);
}
diff --git a/xml/playerSpawnHill1.xml b/xml/playerSpawnHill1.xml
index 387e1a9..3bd0095 100644
--- a/xml/playerSpawnHill1.xml
+++ b/xml/playerSpawnHill1.xml
@@ -43,7 +43,10 @@ And it wasn't stormy.
<Dialog name="Johnny">
<text id="0" nextid="1" pause="true" >
Sup bro! Have a quest. To complete it, just go talk to Ralph again.
- <quest assign="Your First Quest" >Dank MayMay</quest>
+ <quest assign="Your First Quest" >
+ Dank MayMay,2
+ Wood Sword,1
+ </quest>
</text>
<text id="1" nextid="1" pause="true" >
diff --git a/xml/playerSpawnHill1_Building1.xml b/xml/playerSpawnHill1_Building1.xml
index 5c2b723..67695c7 100644
--- a/xml/playerSpawnHill1_Building1.xml
+++ b/xml/playerSpawnHill1_Building1.xml
@@ -8,8 +8,27 @@
</IndoorWorld>
<Dialog name="Bob">
- <text id="0">
- Hey. Have a Dank Maymay :)
+ <text id="0" nextid="1" pause="true">
+ Hey. Have a Dank MayMay :)
<give id="Dank MayMay" count="1" />
</text>
+
+ <text id="1" nextid="2">
+ What? You want another Dank MayMay?
+ </text>
+
+ <text id="2" nextid="3" pause="true">
+ K.
+ <give id="Dank MayMay" count="1" />
+ </text>
+
+ <text id="3" nextid="4">
+ Well... I'm out of Dank MayMays.
+ </text>
+
+ <text id="4">
+ Have a sword though.
+ <give id="Wood Sword" count="1" />
+ </text>
+
</Dialog>