1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
#include <Quest.h>
const Quest QuestList[TOTAL_QUESTS]={
Quest("Test","A test quest",0)
};
Quest::Quest(const char *t,const char *d,unsigned int r){
size_t len;
title=(char *)malloc((len=strlen(t)));
strncpy(title,t,len);
desc=(char *)malloc((len=strlen(d)));
strncpy(desc,d,len);
reward=r;
}
Quest::~Quest(){
free(title);
free(desc);
reward=0;
}
int QuestHandler::assign(const char *t){
unsigned char i;
for(i=0;i<current.size();i++){
if(!strcmp(current[i]->title,t)){
return -2;
}
}
for(i=0;i<TOTAL_QUESTS;i++){
if(!strcmp(QuestList[i].title,t)){
current.push_back(&QuestList[i]);
return current.size();
}
}
return -1;
}
int QuestHandler::drop(const char *t){
unsigned char i;
for(i=0;i<current.size();i++){
if(!strcmp(current[i]->title,t)){
current.erase(current.begin()+i);
return current.size();
}
}
return -1;
}
int QuestHandler::finish(const char *t){
unsigned char i;
unsigned int r;
for(i=0;i<current.size();i++){
if(!strcmp(current[i]->title,t)){
r=current[i]->reward;
current.erase(current.begin()+i);
return r;
}
}
return -1;
}
bool QuestHandler::hasQuest(const char *t){
unsigned int i;
for(i=0;i<current.size();i++){
if(!strcmp(current[i]->title,t)){
return true;
}
}
return false;
}
|