Planeshift

questmanager.h

Go to the documentation of this file.
00001 /*
00002  * questmanager.h
00003  *
00004  * Copyright (C) 2003 Atomic Blue ([email protected], http://www.atomicblue.org)
00005  *
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation (version 2 of the License)
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017  *
00018  */
00019 #ifndef __QUESTMANAGER_H__
00020 #define __QUESTMANAGER_H__
00021 
00022 //=============================================================================
00023 // Crystal Space Includes
00024 //=============================================================================
00025 
00026 //=============================================================================
00027 // Project Includes
00028 //=============================================================================
00029 #include "bulkobjects/psquest.h"
00030 
00031 //=============================================================================
00032 // Local Includes
00033 //=============================================================================
00034 #include "msgmanager.h"   // Subscriber class
00035 
00036 
00037 class Client;
00038 class psItemStats;
00039 
00040 struct QuestRewardOffer;
00041 struct QuestRewardItem;
00042 class gemNPC;
00043 class NpcDialogMenu;
00044 class NpcResponse;
00045 class WordArray;
00046 class psString;
00047 
00052 class QuestManager : public MessageManager<QuestManager>
00053 {
00054 protected:
00055     csPDelArray<QuestRewardOffer>  offers;
00056 
00057     csString lastError;     
00058 
00059     CacheManager* cacheManager;
00060 
00064     bool LoadQuestScripts();
00072     int  PreParseQuestScript(psQuest* mainQuest,const char* script);
00073     void CutOutParenthesis(csString &response, csString &within,char start_char,char end_char) const;
00074 
00075     bool GetResponseText(csString &block,csString &response,csString &file_path,
00076                          csString &him, csString &her, csString &it, csString &them) const;
00077     bool BuildTriggerList(csString &block,csStringArray &list) const;
00078 
00089     bool ParseQuestScriptMenu(const csString &block,const csStringArray &triggers, psQuest* quest, NpcDialogMenu* menu) const;
00090 
00091     int GetNPCFromBlock(WordArray words,csString &current_npc);
00092     bool ParseItemList(const csString &input, csString &parsedItemList);
00093     bool ParseItem(const char* text, psStringArray &xmlItems, psMoney &money);
00094 
00108     NpcResponse* AddResponse(const csString &current_npc,const char* response_text,
00109                              int &last_response_id, psQuest* quest,
00110                              csString &him, csString &her, csString &it, csString &them, csString &file_path);
00121     bool         AddTrigger(const csString &current_npc,const char* trigger,
00122                             int prior_response_id,NpcResponse* trig_response, psQuest* quest, const psString &postfix);
00123     void         MergeTriggerMenus(NpcDialogMenu* pending_menu, const csString &current_npc);
00124 
00125     void GetNextScriptLine(psString &scr, csString &block, size_t &start, int &line_number);
00126     bool PrependPrerequisites(csString &substep_requireop,
00127                               csString &response_requireop,
00128                               bool quest_assigned_already,
00129                               NpcResponse* last_response,
00130                               psQuest* mainQuest);
00131 
00132     bool HandlePlayerAction(csString &block,
00133                             size_t &which_trigger,
00134                             csString &current_npc,
00135                             csStringArray &pending_triggers);
00136 
00137     bool HandleScriptCommand(csString &block,
00138                              csString &response_requireop,
00139                              csString &substep_requireop,
00140                              NpcResponse* last_response,
00141                              psQuest* mainQuest,
00142                              bool &quest_assigned_already,
00143                              psQuest* quest);
00144 
00153     csString ParseRequireCommand(csString &block, bool &result, psQuest* mainQuest);
00154 
00162     bool HandleRequireCommand(csString &block, csString &response_requireop, psQuest* mainQuest);
00163 
00170     void AutocompleteQuestName(csString &questname, psQuest* mainQuest);
00171 
00172     void HandleQuestInfo(MsgEntry* pMsg,Client* client);
00173     void HandleQuestReward(MsgEntry* pMsg,Client* client);
00174 
00175 private:
00180     class TaskEntry
00181     {
00182     public:
00183         csString text;        
00184         int completionOrder;  
00185         int questOrder;       
00186 
00198         bool operator<(const TaskEntry &other) const
00199         {
00200             //first check if the completion order is different
00201             //in that case use that as order
00202             if(completionOrder != other.completionOrder)
00203             {
00204                 return completionOrder > other.completionOrder;
00205             }
00206             //if they are the same check for the case the completion
00207             //order is invalid and check if quest order is different
00208             return questOrder > other.questOrder;
00209         }
00210     };
00211 
00212 public:
00213 
00214     QuestManager(CacheManager* cachemanager);
00215     virtual ~QuestManager();
00216 
00217     bool Initialize();
00218 
00221     int  ParseQuestScript(int id,const char* script);
00222 
00228     int  ParseCustomScript(int id, const csString& current_npc, const char* script);
00229 
00232     void Assign(psQuest* quest, Client* who, gemNPC* assigner,csTicks timeDelay=0);
00233 
00236     bool Complete(psQuest* quest, Client* who, csTicks timeDelay = 0);
00237 
00246     bool Uncomplete(psQuest* quest, Client* who, csTicks timeDelay = 0);
00247 
00248 
00249     void OfferRewardsToPlayer(Client* who, csArray<QuestRewardItem>& offer, csTicks& timeDelay);
00250     bool GiveRewardToPlayer(Client* who, QuestRewardItem& reward);
00251     bool LoadQuestScript(int id);
00252     const char* LastError()
00253     {
00254         return lastError.GetData();
00255     }
00256 };
00257 
00258 
00259 #endif
00260