00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef BOARD_H
00019 #define BOARD_H
00020
00021 #include "constants.h"
00022 #include <map>
00023 #include <vector>
00024 #include <string>
00025
00026 using namespace std;
00027
00028 class RpgItem;
00029 class Monster;
00030 class Creature;
00031 class Item;
00032 class Session;
00033 class Board;
00034
00039 #define BOARD_GUI_WIDTH 400
00040 #define BOARD_GUI_HEIGHT 400
00041
00042 class NpcConversation {
00043 public:
00044
00045 NpcConversation() {
00046 }
00047
00048 ~NpcConversation() {
00049 }
00050
00051 vector<string> npc_intros;
00052 vector<string> npc_unknownPhrases;
00053 map<string, string> npc_conversations;
00054 };
00055
00056 class Mission {
00057 private:
00058 Board *board;
00059 int level;
00060 int depth;
00061 char name[80];
00062 char description[2000];
00063 char success[2000];
00064 char failure[2000];
00065 map<RpgItem*, bool> items;
00066 vector<RpgItem*> itemList;
00067 map<Monster*, bool> creatures;
00068 vector<Monster*> creatureList;
00069 map<Item*,RpgItem*> itemInstanceMap;
00070 map<Creature*,Monster*> monsterInstanceMap;
00071 bool completed;
00072 bool storyLine;
00073 public:
00074
00075 #define INTRO_PHRASE "_INTRO_"
00076 #define UNKNOWN_PHRASE "_UNKNOWN_"
00077
00078 static vector<string> intros;
00079 static vector<string> unknownPhrases;
00080 static map<string, string> conversations;
00081 static map<Monster*,NpcConversation*> npcConversations;
00082
00083 static char *getIntro();
00084 static char *getAnswer( char *keyphrase );
00085 static char *getIntro( Monster *npc );
00086 static char *getAnswer( Monster *npc, char *keyphrase );
00087
00088
00089 Mission( Board *board, int level, int depth,
00090 char *name, char *description,
00091 char *success, char *failure );
00092 ~Mission();
00093
00094 inline void setStoryLine( bool b ) { storyLine = b; }
00095 inline bool isStoryLine() { return storyLine; }
00096
00097 inline void addCreature( Monster *monster ) {
00098 creatures[monster] = false;
00099 creatureList.push_back( monster );
00100 }
00101
00102 inline void addItem( RpgItem *item ) {
00103 items[item] = false;
00104 itemList.push_back( item );
00105 }
00106
00107 inline void addItemInstance( Item *item, RpgItem *rpgItem ) {
00108 itemInstanceMap[ item ] = rpgItem;
00109 }
00110
00111 inline void addCreatureInstanceMap( Creature *creature, Monster *monster ) {
00112 monsterInstanceMap[ creature ] = monster;
00113 }
00114
00115 inline bool isMissionItem( Item *item ) {
00116 return ( itemInstanceMap.find( item ) != itemInstanceMap.end() );
00117 }
00118
00119 inline bool isMissionCreature( Creature *creature ) {
00120 return ( monsterInstanceMap.find( creature ) != monsterInstanceMap.end() );
00121 }
00122
00123 void deleteItemMonsterInstances();
00124
00125 inline bool isCompleted() { return completed; }
00126 inline void setCompleted( bool b ) { completed = b; }
00127 inline char *getName() { return name; }
00128 inline char *getDescription() { return description; }
00129 inline char *getSuccess() { return success; }
00130 inline char *getFailure() { return failure; }
00131 inline int getLevel() { return level; }
00132 inline int getDepth() { return depth; }
00133 void reset();
00134
00135
00136 bool itemFound(Item *item);
00137 bool creatureSlain(Creature *creature);
00138
00139 int getItemCount() { return (int)itemList.size(); }
00140 RpgItem *getItem( int index ) { return itemList[ index ]; }
00141 bool getItemHandled( int index ) { return items[ itemList[ index ] ]; }
00142 int getCreatureCount() { return (int)creatureList.size(); }
00143 Monster *getCreature( int index ) { return creatureList[ index ]; }
00144 bool getCreatureHandled( int index ) { return creatures[ creatureList[ index ] ]; }
00145 private:
00146 void checkMissionCompleted();
00147 };
00148
00149
00150 class MissionTemplate {
00151 private:
00152 Board *board;
00153 char name[80];
00154 char description[2000];
00155 char success[2000];
00156 char failure[2000];
00157 public:
00158 MissionTemplate( Board *board, char *name, char *description, char *success, char *failure );
00159 ~MissionTemplate();
00160 Mission *createMission( Session *session, int level, int depth );
00161 private:
00162 void parseText( Session *session, int level, int depth,
00163 char *text, char *parsedText,
00164 map<string, RpgItem*> *items,
00165 map<string, Monster*> *creatures );
00166 };
00167
00168
00169
00170
00171 class Board {
00172 private:
00173 Session *session;
00174 vector<MissionTemplate *> templates;
00175 vector<Mission*> storylineMissions;
00176 int storylineIndex;
00177
00178 vector<Mission*> availableMissions;
00179
00180 char **missionText;
00181 Color *missionColor;
00182
00183 public:
00184
00185 static const int EVENT_HANDLED = 0;
00186 static const int EVENT_PLAY_MISSION = 1;
00187
00188 Board(Session *session);
00189 virtual ~Board();
00190
00191 inline Session *getSession() { return session; }
00192
00193 void initMissions();
00194 void reset();
00195
00196 inline int getStorylineIndex() { return storylineIndex; }
00197 void setStorylineIndex( int n );
00198 void storylineMissionCompleted( Mission *mission );
00199
00200 inline int getMissionCount() { return availableMissions.size(); }
00201 inline Mission *getMission(int index) { return availableMissions[index]; }
00202
00203 private:
00204 void freeListText();
00205 int readConversationLine( FILE *fp, char *line,
00206 char *keyphrase, char *answer,
00207 int n );
00208 };
00209
00210 #endif
00211