Partial perl parser rewrite, want to make it cleaner and have it match the interface

This commit is contained in:
KimLS
2013-05-08 20:18:39 -07:00
parent ac1d931b5e
commit bcf9546b2d
14 changed files with 5712 additions and 5598 deletions
+207 -126
View File
@@ -1,122 +1,42 @@
//extends the parser to include perl
//Eglin
#ifndef EMBPARSER_H
#define EMBPARSER_H
#ifndef EQEMU_EMBPARSER_H
#define EQMEU_EMBPARSER_H
#ifdef EMBPERL
#include "client.h"
#include "parser.h"
#include "embperl.h"
#include "../common/features.h"
#include "QuestParserCollection.h"
#include "QuestInterface.h"
#include <string>
#include <map>
#include <queue>
using namespace std;
#include "embperl.h"
class Seperator;
typedef enum {
questDefault = 1,
questDefaultByZone,
questByName,
questTemplate,
questTemplateByID,
questByID
} questMode;
typedef enum {
itemQuestUnloaded = 1,
itemQuestScale,
itemQuestLore,
itemQuestID,
itemScriptFileID
} itemQuestMode;
typedef enum {
pQuestLoaded = 1,
pQuestUnloaded,
pQuestEventCast, // player.pl loaded, has an EVENT_CAST sub
pQuestReadyToLoad
} playerQuestMode;
typedef enum {
nQuestLoaded = 1,
nQuestUnloaded,
nQuestReadyToLoad
} GlobalNPCQuestMode;
typedef enum {
spellQuestUnloaded = 1,
spellQuestFullyLoaded,
spellQuestFailed
} spellQuestMode;
struct EventRecord {
QuestEventID event;
uint32 objid;
string data;
NPC* npcmob;
ItemInst* iteminst;
Mob* mob;
uint32 extradata;
bool global;
};
class PerlembParser : public Parser
typedef enum
{
protected:
//could prolly get rid of this map now, since I check for the
//actual subroutine in the quest package as opposed to just seeing
//if they do not have a quest or the default.
map<uint32, questMode> hasQuests; //npcid -> questMode
map<std::string, playerQuestMode> playerQuestLoaded; //zone shortname -> playerQuestMode
playerQuestMode globalPlayerQuestLoaded;
GlobalNPCQuestMode globalNPCQuestLoaded;
map<std::string, itemQuestMode> itemQuestLoaded; // package name - > itemQuestMode
map<uint32, spellQuestMode> spellQuestLoaded;
questUnloaded,
questLoaded,
questFailedToLoad
} PerlQuestStatus;
queue<EventRecord> eventQueue; //for events that happen when perl is in use.
bool eventQueueProcessing;
void HandleQueue();
void EventCommon(QuestEventID event, uint32 objid, const char * data, NPC* npcmob, ItemInst* iteminst, Mob* mob, uint32 extradata, bool global = false);
Embperl * perl;
//export a symbol table of sorts
virtual void map_funs();
class PerlembParser : public QuestInterface {
public:
PerlembParser(void);
PerlembParser();
~PerlembParser();
Embperl * getperl(void) { return perl; };
//todo, consider making the following two methods static (need to check for perl!=null, first, then)
bool isloaded(const char *packagename) const;
//interface stuff
virtual void EventNPC(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data);
virtual void EventNPC(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data);
virtual void EventGlobalNPC(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data);
virtual void EventPlayer(QuestEventID evt, Client *client, std::string data, uint32 extra_data);
virtual void EventGlobalPlayer(QuestEventID evt, Client *client, std::string data, uint32 extra_data);
virtual void EventItem(QuestEventID evt, Client *client, ItemInst *item, uint32 objid, uint32 extra_data);
virtual void EventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, uint32 extra_data);
virtual bool HasQuestSub(uint32 npcid, const char *subname);
virtual bool HasQuestSub(uint32 npcid, const char *subname);
virtual bool HasGlobalQuestSub(const char *subname);
virtual bool PlayerHasQuestSub(const char *subname);
virtual bool GlobalPlayerHasQuestSub(const char *subname);
virtual bool SpellHasQuestSub(uint32 spell_id, const char *subname);
virtual bool ItemHasQuestSub(ItemInst *itm, const char *subname);
virtual void ReloadQuests(bool with_timers = false);
virtual void AddVar(std::string name, std::string val) { Parser::AddVar(name, val); };
virtual uint32 GetIdentifier() { return 0xf8b05c11; }
virtual bool ItemHasQuestSub(ItemInst *itm, const char *subname);
virtual void LoadNPCScript(std::string filename, int npc_id);
virtual void LoadGlobalNPCScript(std::string filename);
@@ -125,39 +45,200 @@ public:
virtual void LoadItemScript(std::string filename, std::string item_script);
virtual void LoadSpellScript(std::string filename, uint32 spell_id);
//int LoadScript(int npcid, const char * zone, Mob* activater=0);
//int LoadGlobalNPCScript();
//int LoadPlayerScript(const char *zone);
//int LoadGlobalPlayerScript();
//int LoadItemScript(ItemInst* iteminst, string packagename, itemQuestMode Qtype);
//int LoadSpellScript(uint32 id);
virtual void AddVar(std::string name, std::string val);
virtual std::string GetVar(std::string name);
virtual void ReloadQuests();
virtual uint32 GetIdentifier() { return 0xf8b05c11; }
private:
Embperl *perl;
//expose a var to the script (probably parallels addvar))
//i.e. exportvar("qst1234", "name", "somemob");
//would expose the variable $name='somemob' to the script that handles npc1234
void ExportHash(const char *pkgprefix, const char *hashname, std::map<string,string> &vals);
void ExportVar(const char * pkgprefix, const char * varname, const char * value) const;
void ExportVar(const char * pkgprefix, const char * varname, int value) const;
void ExportVar(const char * pkgprefix, const char * varname, unsigned int value) const;
void ExportVar(const char * pkgprefix, const char * varname, float value) const;
//I don't escape the strings, so use caution!!
//Same as export var, except value is not quoted, and is evaluated as perl
void ExportVarComplex(const char * pkgprefix, const char * varname, const char * value) const;
//get an appropriate namespage/packagename from an npcid
std::string GetPkgPrefix(uint32 npcid, bool defaultOK = true);
//call the appropriate perl handler. afterwards, parse and dispatch the command queue
//SendCommands("qst1234", "EVENT_SAY") would trigger sub EVENT_SAY() from the qst1234.pl file
virtual void SendCommands(const char * pkgprefix, const char *event, uint32 npcid, Mob* other, Mob* mob, ItemInst* iteminst);
int HasQuestFile(uint32 npcid);
void ExportHash(const char *pkgprefix, const char *hashname, std::map<std::string, std::string> &vals);
void ExportVar(const char *pkgprefix, const char *varname, const char *value) const;
void ExportVar(const char *pkgprefix, const char *varname, int32 value) const;
void ExportVar(const char *pkgprefix, const char *varname, uint32 value) const;
void ExportVar(const char *pkgprefix, const char *varname, float value) const;
void ExportVarComplex(const char *pkgprefix, const char *varname, const char *value) const;
#ifdef EMBPERL_COMMANDS
void ExecCommand(Client *c, Seperator *sep);
#endif
void EventCommon(QuestEventID event, uint32 objid, const char * data, NPC* npcmob, ItemInst* iteminst, Mob* mob,
uint32 extradata, bool global);
void SendCommands(const char *pkgprefix, const char *event, uint32 npcid, Mob* other, Mob* mob, ItemInst* iteminst);
void MapFunctions();
std::map<uint32, PerlQuestStatus> npc_quest_status_;
PerlQuestStatus global_npc_quest_status_;
PerlQuestStatus player_quest_status_;
PerlQuestStatus global_player_quest_status_;
std::map<std::string, PerlQuestStatus> item_quest_status_;
std::map<uint32, PerlQuestStatus> spell_quest_status_;
};
#endif //EMBPERL
#endif
#endif
#endif //EMBPARSER_H
////extends the parser to include perl
////Eglin
//
//#ifndef EMBPARSER_H
//#define EMBPARSER_H
//
//#ifdef EMBPERL
//
//#include "client.h"
//#include "parser.h"
//#include "embperl.h"
//#include "../common/features.h"
//#include "QuestParserCollection.h"
//#include "QuestInterface.h"
//
//#include <string>
//#include <map>
//#include <queue>
//using namespace std;
//
//class Seperator;
//
//typedef enum {
// questDefault = 1,
// questDefaultByZone,
// questByName,
// questTemplate,
// questTemplateByID,
// questByID
//} questMode;
//
//typedef enum {
// itemQuestUnloaded = 1,
// itemQuestScale,
// itemQuestLore,
// itemQuestID,
// itemScriptFileID
//} itemQuestMode;
//
//typedef enum {
// pQuestLoaded = 1,
// pQuestUnloaded,
// pQuestEventCast, // player.pl loaded, has an EVENT_CAST sub
// pQuestReadyToLoad
//} playerQuestMode;
//
//typedef enum {
// nQuestLoaded = 1,
// nQuestUnloaded,
// nQuestReadyToLoad
//} GlobalNPCQuestMode;
//
//typedef enum {
// spellQuestUnloaded = 1,
// spellQuestFullyLoaded,
// spellQuestFailed
//} spellQuestMode;
//
//
//struct EventRecord {
// QuestEventID event;
// uint32 objid;
// string data;
// NPC* npcmob;
// ItemInst* iteminst;
// Mob* mob;
// uint32 extradata;
// bool global;
//};
//
//class PerlembParser : public Parser
//{
//protected:
//
// //could prolly get rid of this map now, since I check for the
// //actual subroutine in the quest package as opposed to just seeing
// //if they do not have a quest or the default.
// map<uint32, questMode> hasQuests; //npcid -> questMode
// map<std::string, playerQuestMode> playerQuestLoaded; //zone shortname -> playerQuestMode
// playerQuestMode globalPlayerQuestLoaded;
// GlobalNPCQuestMode globalNPCQuestLoaded;
// map<std::string, itemQuestMode> itemQuestLoaded; // package name - > itemQuestMode
// map<uint32, spellQuestMode> spellQuestLoaded;
//
// queue<EventRecord> eventQueue; //for events that happen when perl is in use.
// bool eventQueueProcessing;
//
// void HandleQueue();
//
// void EventCommon(QuestEventID event, uint32 objid, const char * data, NPC* npcmob, ItemInst* iteminst, Mob* mob, uint32 extradata, bool global = false);
//
// Embperl * perl;
// //export a symbol table of sorts
// virtual void map_funs();
//public:
// PerlembParser(void);
// ~PerlembParser();
// Embperl * getperl(void) { return perl; };
// //todo, consider making the following two methods static (need to check for perl!=null, first, then)
// bool isloaded(const char *packagename) const;
//
// //interface stuff
// virtual void EventNPC(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data);
// virtual void EventGlobalNPC(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data);
// virtual void EventPlayer(QuestEventID evt, Client *client, std::string data, uint32 extra_data);
// virtual void EventGlobalPlayer(QuestEventID evt, Client *client, std::string data, uint32 extra_data);
// virtual void EventItem(QuestEventID evt, Client *client, ItemInst *item, uint32 objid, uint32 extra_data);
// virtual void EventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, uint32 extra_data);
//
// virtual bool HasQuestSub(uint32 npcid, const char *subname);
// virtual bool HasGlobalQuestSub(const char *subname);
// virtual bool PlayerHasQuestSub(const char *subname);
// virtual bool GlobalPlayerHasQuestSub(const char *subname);
// virtual bool SpellHasQuestSub(uint32 spell_id, const char *subname);
// virtual bool ItemHasQuestSub(ItemInst *itm, const char *subname);
//
// virtual void ReloadQuests(bool with_timers = false);
// virtual void AddVar(std::string name, std::string val) { Parser::AddVar(name, val); };
// virtual uint32 GetIdentifier() { return 0xf8b05c11; }
//
// virtual void LoadNPCScript(std::string filename, int npc_id);
// virtual void LoadGlobalNPCScript(std::string filename);
// virtual void LoadPlayerScript(std::string filename);
// virtual void LoadGlobalPlayerScript(std::string filename);
// virtual void LoadItemScript(std::string filename, std::string item_script);
// virtual void LoadSpellScript(std::string filename, uint32 spell_id);
//
// //int LoadScript(int npcid, const char * zone, Mob* activater=0);
// //int LoadGlobalNPCScript();
// //int LoadPlayerScript(const char *zone);
// //int LoadGlobalPlayerScript();
// //int LoadItemScript(ItemInst* iteminst, string packagename, itemQuestMode Qtype);
// //int LoadSpellScript(uint32 id);
//
// //expose a var to the script (probably parallels addvar))
// //i.e. exportvar("qst1234", "name", "somemob");
// //would expose the variable $name='somemob' to the script that handles npc1234
// void ExportHash(const char *pkgprefix, const char *hashname, std::map<string,string> &vals);
// void ExportVar(const char * pkgprefix, const char * varname, const char * value) const;
// void ExportVar(const char * pkgprefix, const char * varname, int value) const;
// void ExportVar(const char * pkgprefix, const char * varname, unsigned int value) const;
// void ExportVar(const char * pkgprefix, const char * varname, float value) const;
// //I don't escape the strings, so use caution!!
// //Same as export var, except value is not quoted, and is evaluated as perl
// void ExportVarComplex(const char * pkgprefix, const char * varname, const char * value) const;
//
// //get an appropriate namespage/packagename from an npcid
// std::string GetPkgPrefix(uint32 npcid, bool defaultOK = true);
// //call the appropriate perl handler. afterwards, parse and dispatch the command queue
// //SendCommands("qst1234", "EVENT_SAY") would trigger sub EVENT_SAY() from the qst1234.pl file
// virtual void SendCommands(const char * pkgprefix, const char *event, uint32 npcid, Mob* other, Mob* mob, ItemInst* iteminst);
//
// int HasQuestFile(uint32 npcid);
//
//#ifdef EMBPERL_COMMANDS
// void ExecCommand(Client *c, Seperator *sep);
//#endif
//
//};
//
//#endif //EMBPERL
//
//#endif //EMBPARSER_H