From 43d0350870cc33bd86edd6172cd0368d21d10fee Mon Sep 17 00:00:00 2001 From: KimLS Date: Thu, 9 May 2013 21:25:50 -0700 Subject: [PATCH] Cleanup perl parsers --- zone/CMakeLists.txt | 2 +- zone/QuestInterface.h | 38 +- zone/QuestParserCollection.cpp | 967 +++++------ zone/QuestParserCollection.h | 81 +- zone/embparser.cpp | 53 +- zone/embparser.h | 210 +-- zone/{perlparser.cpp => embparser_api.cpp} | 337 ++-- zone/net.cpp | 14 +- zone/parser.cpp | 1694 -------------------- zone/parser.h | 124 -- zone/perlparser.h | 1 - 11 files changed, 806 insertions(+), 2715 deletions(-) rename zone/{perlparser.cpp => embparser_api.cpp} (92%) delete mode 100644 zone/parser.cpp delete mode 100644 zone/parser.h delete mode 100644 zone/perlparser.h diff --git a/zone/CMakeLists.txt b/zone/CMakeLists.txt index 334619697..4fdab00ee 100644 --- a/zone/CMakeLists.txt +++ b/zone/CMakeLists.txt @@ -17,6 +17,7 @@ SET(zone_sources doors.cpp effects.cpp embparser.cpp + embparser_api.cpp embperl.cpp embxs.cpp entity.cpp @@ -53,7 +54,6 @@ SET(zone_sources perl_questitem.cpp perl_raids.cpp perlpacket.cpp - perlparser.cpp petitions.cpp pets.cpp PlayerCorpse.cpp diff --git a/zone/QuestInterface.h b/zone/QuestInterface.h index 3ecd99f0f..8bb647b76 100644 --- a/zone/QuestInterface.h +++ b/zone/QuestInterface.h @@ -1,3 +1,21 @@ +/* EQEMu: Everquest Server Emulator + Copyright (C) 2001-2006 EQEMu Development Team (http://eqemulator.net) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY except by those people which sell it, which + are required to give you total support for your newly bought product; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + #ifndef _EQE_QUESTINTERFACE_H #define _EQE_QUESTINTERFACE_H @@ -10,19 +28,19 @@ class NPC; class QuestInterface { public: - virtual double EventNPC(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data) { return 100.0; } + virtual double EventNPC(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data) { return 100.0; } virtual double EventGlobalNPC(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data) { return 100.0; } - virtual double EventPlayer(QuestEventID evt, Client *client, std::string data, uint32 extra_data) { return 100.0; } - virtual double EventGlobalPlayer(QuestEventID evt, Client *client, std::string data, uint32 extra_data) { return 100.0; } - virtual double EventItem(QuestEventID evt, Client *client, ItemInst *item, uint32 objid, uint32 extra_data) { return 100.0; } - virtual double EventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, uint32 extra_data) { return 100.0; } + virtual double EventPlayer(QuestEventID evt, Client *client, std::string data, uint32 extra_data) { return 100.0; } + virtual double EventGlobalPlayer(QuestEventID evt, Client *client, std::string data, uint32 extra_data) { return 100.0; } + virtual double EventItem(QuestEventID evt, Client *client, ItemInst *item, uint32 objid, uint32 extra_data) { return 100.0; } + virtual double EventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, uint32 extra_data) { return 100.0; } virtual bool HasQuestSub(uint32 npcid, const char *subname) { return false; } virtual bool HasGlobalQuestSub(const char *subname) { return false; } virtual bool PlayerHasQuestSub(const char *subname) { return false; } - virtual bool GlobalPlayerHasQuestSub(const char *subname) { return false; } + virtual bool GlobalPlayerHasQuestSub(const char *subname) { return false; } virtual bool SpellHasQuestSub(uint32 spell_id, const char *subname) { return false; } - virtual bool ItemHasQuestSub(ItemInst *itm, const char *subname) { return false; } + virtual bool ItemHasQuestSub(ItemInst *itm, const char *subname) { return false; } virtual void LoadNPCScript(std::string filename, int npc_id) { } virtual void LoadGlobalNPCScript(std::string filename) { } @@ -31,10 +49,10 @@ public: virtual void LoadItemScript(std::string filename, std::string item_script) { } virtual void LoadSpellScript(std::string filename, uint32 spell_id) { } - virtual void AddVar(std::string name, std::string val) { } + virtual void AddVar(std::string name, std::string val) { } virtual std::string GetVar(std::string name) { return std::string(); } - virtual void ReloadQuests() { } - virtual uint32 GetIdentifier() = 0; + virtual void ReloadQuests() { } + virtual uint32 GetIdentifier() = 0; }; #endif diff --git a/zone/QuestParserCollection.cpp b/zone/QuestParserCollection.cpp index 052ea99f7..ba8d863cf 100644 --- a/zone/QuestParserCollection.cpp +++ b/zone/QuestParserCollection.cpp @@ -1,10 +1,27 @@ +/* EQEMu: Everquest Server Emulator + Copyright (C) 2001-2006 EQEMu Development Team (http://eqemulator.net) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY except by those people which sell it, which + are required to give you total support for your newly bought product; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + #include "../common/debug.h" #include "../common/MiscFunctions.h" #include "../common/features.h" #include "QuestParserCollection.h" #include "QuestInterface.h" #include "zone.h" -#include "zonedb.h" #include "questmgr.h" #include @@ -14,26 +31,26 @@ extern Zone* zone; QuestParserCollection::QuestParserCollection() { - _player_quest_status = QuestUnloaded; - _global_player_quest_status = QuestUnloaded; - _global_npc_quest_status = QuestUnloaded; + _player_quest_status = QuestUnloaded; + _global_player_quest_status = QuestUnloaded; + _global_npc_quest_status = QuestUnloaded; } QuestParserCollection::~QuestParserCollection() { } void QuestParserCollection::RegisterQuestInterface(QuestInterface *qi, std::string ext) { - _interfaces[qi->GetIdentifier()] = qi; - _extensions[qi->GetIdentifier()] = ext; - _load_precedence.push_back(qi); + _interfaces[qi->GetIdentifier()] = qi; + _extensions[qi->GetIdentifier()] = ext; + _load_precedence.push_back(qi); } void QuestParserCollection::AddVar(std::string name, std::string val) { - std::list::iterator iter = _load_precedence.begin(); - while(iter != _load_precedence.end()) { - (*iter)->AddVar(name, val); - iter++; - } + std::list::iterator iter = _load_precedence.begin(); + while(iter != _load_precedence.end()) { + (*iter)->AddVar(name, val); + iter++; + } } void QuestParserCollection::ReloadQuests(bool reset_timers) { @@ -41,17 +58,17 @@ void QuestParserCollection::ReloadQuests(bool reset_timers) { quest_manager.ClearAllTimers(); } - _npc_quest_status.clear(); - _player_quest_status = QuestUnloaded; - _global_player_quest_status = QuestUnloaded; + _npc_quest_status.clear(); + _player_quest_status = QuestUnloaded; + _global_player_quest_status = QuestUnloaded; _global_npc_quest_status = QuestUnloaded; - _spell_quest_status.clear(); - _item_quest_status.clear(); - std::list::iterator iter = _load_precedence.begin(); - while(iter != _load_precedence.end()) { - (*iter)->ReloadQuests(); - iter++; - } + _spell_quest_status.clear(); + _item_quest_status.clear(); + std::list::iterator iter = _load_precedence.begin(); + while(iter != _load_precedence.end()) { + (*iter)->ReloadQuests(); + iter++; + } } bool QuestParserCollection::HasQuestSub(uint32 npcid, const char *subname) { @@ -59,143 +76,143 @@ bool QuestParserCollection::HasQuestSub(uint32 npcid, const char *subname) { } bool QuestParserCollection::HasQuestSubLocal(uint32 npcid, const char *subname) { - std::map::iterator iter = _npc_quest_status.find(npcid); + std::map::iterator iter = _npc_quest_status.find(npcid); - if(iter != _npc_quest_status.end()) { - //loaded or failed to load - if(iter->second != QuestFailedToLoad) { - std::map::iterator qiter = _interfaces.find(iter->second); - if(qiter->second->HasQuestSub(npcid, subname)) { - return true; - } - } - } else { + if(iter != _npc_quest_status.end()) { + //loaded or failed to load + if(iter->second != QuestFailedToLoad) { + std::map::iterator qiter = _interfaces.find(iter->second); + if(qiter->second->HasQuestSub(npcid, subname)) { + return true; + } + } + } else { std::string filename; - QuestInterface *qi = GetQIByNPCQuest(npcid, filename); - if(qi) { - _npc_quest_status[npcid] = qi->GetIdentifier(); + QuestInterface *qi = GetQIByNPCQuest(npcid, filename); + if(qi) { + _npc_quest_status[npcid] = qi->GetIdentifier(); qi->LoadNPCScript(filename, npcid); - if(qi->HasQuestSub(npcid, subname)) { - return true; - } - } else { - _npc_quest_status[npcid] = QuestFailedToLoad; - } - } - return false; + if(qi->HasQuestSub(npcid, subname)) { + return true; + } + } else { + _npc_quest_status[npcid] = QuestFailedToLoad; + } + } + return false; } bool QuestParserCollection::HasQuestSubGlobal(const char *subname) { - if(_global_npc_quest_status == QuestUnloaded) { + if(_global_npc_quest_status == QuestUnloaded) { std::string filename; QuestInterface *qi = GetQIByGlobalNPCQuest(filename); - if(qi) { + if(qi) { qi->LoadGlobalNPCScript(filename); - _global_npc_quest_status = qi->GetIdentifier(); + _global_npc_quest_status = qi->GetIdentifier(); if(qi->HasGlobalQuestSub(subname)) { - return true; - } - } + return true; + } + } } else { - if(_global_npc_quest_status != QuestFailedToLoad) { - std::map::iterator qiter = _interfaces.find(_global_npc_quest_status); - if(qiter->second->HasGlobalQuestSub(subname)) { - return true; - } - } - } - return false; + if(_global_npc_quest_status != QuestFailedToLoad) { + std::map::iterator qiter = _interfaces.find(_global_npc_quest_status); + if(qiter->second->HasGlobalQuestSub(subname)) { + return true; + } + } + } + return false; } bool QuestParserCollection::PlayerHasQuestSub(const char *subname) { - return PlayerHasQuestSubLocal(subname) || PlayerHasQuestSubGlobal(subname); + return PlayerHasQuestSubLocal(subname) || PlayerHasQuestSubGlobal(subname); } bool QuestParserCollection::PlayerHasQuestSubLocal(const char *subname) { - if(_player_quest_status == QuestUnloaded) { - std::string filename; - QuestInterface *qi = GetQIByPlayerQuest(filename); - if(qi) { - _player_quest_status = qi->GetIdentifier(); + if(_player_quest_status == QuestUnloaded) { + std::string filename; + QuestInterface *qi = GetQIByPlayerQuest(filename); + if(qi) { + _player_quest_status = qi->GetIdentifier(); qi->LoadPlayerScript(filename); - return qi->PlayerHasQuestSub(subname); - } - } else if(_player_quest_status != QuestFailedToLoad) { - std::map::iterator iter = _interfaces.find(_player_quest_status); - return iter->second->PlayerHasQuestSub(subname); - } - return false; + return qi->PlayerHasQuestSub(subname); + } + } else if(_player_quest_status != QuestFailedToLoad) { + std::map::iterator iter = _interfaces.find(_player_quest_status); + return iter->second->PlayerHasQuestSub(subname); + } + return false; } bool QuestParserCollection::PlayerHasQuestSubGlobal(const char *subname) { - if(_global_player_quest_status == QuestUnloaded) { - std::string filename; - QuestInterface *qi = GetQIByPlayerQuest(filename); - if(qi) { - _global_player_quest_status = qi->GetIdentifier(); + if(_global_player_quest_status == QuestUnloaded) { + std::string filename; + QuestInterface *qi = GetQIByPlayerQuest(filename); + if(qi) { + _global_player_quest_status = qi->GetIdentifier(); qi->LoadPlayerScript(filename); - return qi->GlobalPlayerHasQuestSub(subname); - } - } else if(_global_player_quest_status != QuestFailedToLoad) { - std::map::iterator iter = _interfaces.find(_global_player_quest_status); - return iter->second->GlobalPlayerHasQuestSub(subname); - } - return false; + return qi->GlobalPlayerHasQuestSub(subname); + } + } else if(_global_player_quest_status != QuestFailedToLoad) { + std::map::iterator iter = _interfaces.find(_global_player_quest_status); + return iter->second->GlobalPlayerHasQuestSub(subname); + } + return false; } bool QuestParserCollection::SpellHasQuestSub(uint32 spell_id, const char *subname) { - std::map::iterator iter = _spell_quest_status.find(spell_id); - if(iter != _spell_quest_status.end()) { - //loaded or failed to load - if(iter->second != QuestFailedToLoad) { - std::map::iterator qiter = _interfaces.find(iter->second); - return qiter->second->SpellHasQuestSub(spell_id, subname); - } - } else { + std::map::iterator iter = _spell_quest_status.find(spell_id); + if(iter != _spell_quest_status.end()) { + //loaded or failed to load + if(iter->second != QuestFailedToLoad) { + std::map::iterator qiter = _interfaces.find(iter->second); + return qiter->second->SpellHasQuestSub(spell_id, subname); + } + } else { std::string filename; - QuestInterface *qi = GetQIBySpellQuest(spell_id, filename); - if(qi) { - _spell_quest_status[spell_id] = qi->GetIdentifier(); + QuestInterface *qi = GetQIBySpellQuest(spell_id, filename); + if(qi) { + _spell_quest_status[spell_id] = qi->GetIdentifier(); qi->LoadSpellScript(filename, spell_id); - return qi->SpellHasQuestSub(spell_id, subname); - } else { - _spell_quest_status[spell_id] = QuestFailedToLoad; - } - } - return false; + return qi->SpellHasQuestSub(spell_id, subname); + } else { + _spell_quest_status[spell_id] = QuestFailedToLoad; + } + } + return false; } bool QuestParserCollection::ItemHasQuestSub(ItemInst *itm, const char *subname) { - std::string item_script; - if(strcmp("EVENT_SCALE_CALC", subname) == 0 || strcmp("EVENT_ITEM_ENTERZONE", subname) == 0) { - item_script = itm->GetItem()->CharmFile; - } else if(strcmp("EVENT_ITEM_CLICK", subname) == 0 || strcmp("EVENT_ITEM_CLICK_CAST", subname) == 0) { - item_script = "script_"; - item_script += itoa(itm->GetItem()->ScriptFileID); - } else { - item_script = itoa(itm->GetItem()->ID); - } + std::string item_script; + if(strcmp("EVENT_SCALE_CALC", subname) == 0 || strcmp("EVENT_ITEM_ENTERZONE", subname) == 0) { + item_script = itm->GetItem()->CharmFile; + } else if(strcmp("EVENT_ITEM_CLICK", subname) == 0 || strcmp("EVENT_ITEM_CLICK_CAST", subname) == 0) { + item_script = "script_"; + item_script += itoa(itm->GetItem()->ScriptFileID); + } else { + item_script = itoa(itm->GetItem()->ID); + } - std::map::iterator iter = _item_quest_status.find(item_script); - if(iter != _item_quest_status.end()) { - //loaded or failed to load - if(iter->second != QuestFailedToLoad) { - std::map::iterator qiter = _interfaces.find(iter->second); - return qiter->second->ItemHasQuestSub(itm, subname); - } - } else { + std::map::iterator iter = _item_quest_status.find(item_script); + if(iter != _item_quest_status.end()) { + //loaded or failed to load + if(iter->second != QuestFailedToLoad) { + std::map::iterator qiter = _interfaces.find(iter->second); + return qiter->second->ItemHasQuestSub(itm, subname); + } + } else { std::string filename; - QuestInterface *qi = GetQIByItemQuest(item_script, filename); - if(qi) { - _item_quest_status[item_script] = qi->GetIdentifier(); + QuestInterface *qi = GetQIByItemQuest(item_script, filename); + if(qi) { + _item_quest_status[item_script] = qi->GetIdentifier(); qi->LoadItemScript(filename, item_script); - return qi->ItemHasQuestSub(itm, subname); - } else { - _item_quest_status[item_script] = QuestFailedToLoad; - } - } - return false; + return qi->ItemHasQuestSub(itm, subname); + } else { + _item_quest_status[item_script] = QuestFailedToLoad; + } + } + return false; } void QuestParserCollection::EventNPC(QuestEventID evt, NPC *npc, Mob *init, std::string data, uint32 extra_data) { @@ -206,39 +223,39 @@ void QuestParserCollection::EventNPC(QuestEventID evt, NPC *npc, Mob *init, std: void QuestParserCollection::EventNPCLocal(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data) { std::map::iterator iter = _npc_quest_status.find(npc->GetNPCTypeID()); if(iter != _npc_quest_status.end()) { - //loaded or failed to load - if(iter->second != QuestFailedToLoad) { - std::map::iterator qiter = _interfaces.find(iter->second); - qiter->second->EventNPC(evt, npc, init, data, extra_data); - } - } else { + //loaded or failed to load + if(iter->second != QuestFailedToLoad) { + std::map::iterator qiter = _interfaces.find(iter->second); + qiter->second->EventNPC(evt, npc, init, data, extra_data); + } + } else { std::string filename; - QuestInterface *qi = GetQIByNPCQuest(npc->GetNPCTypeID(), filename); - if(qi) { - _npc_quest_status[npc->GetNPCTypeID()] = qi->GetIdentifier(); + QuestInterface *qi = GetQIByNPCQuest(npc->GetNPCTypeID(), filename); + if(qi) { + _npc_quest_status[npc->GetNPCTypeID()] = qi->GetIdentifier(); qi->LoadNPCScript(filename, npc->GetNPCTypeID()); - qi->EventNPC(evt, npc, init, data, extra_data); - } else { - _npc_quest_status[npc->GetNPCTypeID()] = QuestFailedToLoad; - } - } + qi->EventNPC(evt, npc, init, data, extra_data); + } else { + _npc_quest_status[npc->GetNPCTypeID()] = QuestFailedToLoad; + } + } } void QuestParserCollection::EventNPCGlobal(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data) { - if(_global_npc_quest_status != QuestUnloaded && _global_npc_quest_status != QuestFailedToLoad) { - std::map::iterator qiter = _interfaces.find(_global_npc_quest_status); - qiter->second->EventGlobalNPC(evt, npc, init, data, extra_data); - } else { + if(_global_npc_quest_status != QuestUnloaded && _global_npc_quest_status != QuestFailedToLoad) { + std::map::iterator qiter = _interfaces.find(_global_npc_quest_status); + qiter->second->EventGlobalNPC(evt, npc, init, data, extra_data); + } else { std::string filename; - QuestInterface *qi = GetQIByGlobalNPCQuest(filename); - if(qi) { - _global_npc_quest_status = qi->GetIdentifier(); + QuestInterface *qi = GetQIByGlobalNPCQuest(filename); + if(qi) { + _global_npc_quest_status = qi->GetIdentifier(); qi->LoadGlobalNPCScript(filename); - qi->EventGlobalNPC(evt, npc, init, data, extra_data); - } else { - _global_npc_quest_status = QuestFailedToLoad; - } - } + qi->EventGlobalNPC(evt, npc, init, data, extra_data); + } else { + _global_npc_quest_status = QuestFailedToLoad; + } + } } void QuestParserCollection::EventPlayer(QuestEventID evt, Client *client, std::string data, uint32 extra_data) { @@ -247,235 +264,235 @@ void QuestParserCollection::EventPlayer(QuestEventID evt, Client *client, std::s } void QuestParserCollection::EventPlayerLocal(QuestEventID evt, Client *client, std::string data, uint32 extra_data) { - if(_player_quest_status == QuestUnloaded) { + if(_player_quest_status == QuestUnloaded) { std::string filename; - QuestInterface *qi = GetQIByPlayerQuest(filename); - if(qi) { - _player_quest_status = qi->GetIdentifier(); + QuestInterface *qi = GetQIByPlayerQuest(filename); + if(qi) { + _player_quest_status = qi->GetIdentifier(); qi->LoadPlayerScript(filename); - qi->EventPlayer(evt, client, data, extra_data); - } - } else { - if(_player_quest_status != QuestFailedToLoad) { - std::map::iterator iter = _interfaces.find(_player_quest_status); - iter->second->EventPlayer(evt, client, data, extra_data); - } - } + qi->EventPlayer(evt, client, data, extra_data); + } + } else { + if(_player_quest_status != QuestFailedToLoad) { + std::map::iterator iter = _interfaces.find(_player_quest_status); + iter->second->EventPlayer(evt, client, data, extra_data); + } + } } void QuestParserCollection::EventPlayerGlobal(QuestEventID evt, Client *client, std::string data, uint32 extra_data) { - if(_global_player_quest_status == QuestUnloaded) { + if(_global_player_quest_status == QuestUnloaded) { std::string filename; - QuestInterface *qi = GetQIByGlobalPlayerQuest(filename); - if(qi) { - _global_player_quest_status = qi->GetIdentifier(); + QuestInterface *qi = GetQIByGlobalPlayerQuest(filename); + if(qi) { + _global_player_quest_status = qi->GetIdentifier(); qi->LoadGlobalPlayerScript(filename); - qi->EventGlobalPlayer(evt, client, data, extra_data); - } - } else { - if(_global_player_quest_status != QuestFailedToLoad) { - std::map::iterator iter = _interfaces.find(_global_player_quest_status); - iter->second->EventGlobalPlayer(evt, client, data, extra_data); - } - } + qi->EventGlobalPlayer(evt, client, data, extra_data); + } + } else { + if(_global_player_quest_status != QuestFailedToLoad) { + std::map::iterator iter = _interfaces.find(_global_player_quest_status); + iter->second->EventGlobalPlayer(evt, client, data, extra_data); + } + } } void QuestParserCollection::EventItem(QuestEventID evt, Client *client, ItemInst *item, uint32 objid, uint32 extra_data) { - std::string item_script; - if(evt == EVENT_SCALE_CALC || evt == EVENT_ITEM_ENTERZONE) { - item_script = item->GetItem()->CharmFile; - } else if(evt == EVENT_ITEM_CLICK || evt == EVENT_ITEM_CLICK_CAST) { - item_script = "script_"; - item_script += itoa(item->GetItem()->ScriptFileID); - } else { - item_script = itoa(item->GetItem()->ID); - } + std::string item_script; + if(evt == EVENT_SCALE_CALC || evt == EVENT_ITEM_ENTERZONE) { + item_script = item->GetItem()->CharmFile; + } else if(evt == EVENT_ITEM_CLICK || evt == EVENT_ITEM_CLICK_CAST) { + item_script = "script_"; + item_script += itoa(item->GetItem()->ScriptFileID); + } else { + item_script = itoa(item->GetItem()->ID); + } - std::map::iterator iter = _item_quest_status.find(item_script); - if(iter != _item_quest_status.end()) { - //loaded or failed to load - if(iter->second != QuestFailedToLoad) { - std::map::iterator qiter = _interfaces.find(iter->second); - qiter->second->EventItem(evt, client, item, objid, extra_data); - } - } else { + std::map::iterator iter = _item_quest_status.find(item_script); + if(iter != _item_quest_status.end()) { + //loaded or failed to load + if(iter->second != QuestFailedToLoad) { + std::map::iterator qiter = _interfaces.find(iter->second); + qiter->second->EventItem(evt, client, item, objid, extra_data); + } + } else { std::string filename; - QuestInterface *qi = GetQIByItemQuest(item_script, filename); - if(qi) { - _item_quest_status[item_script] = qi->GetIdentifier(); + QuestInterface *qi = GetQIByItemQuest(item_script, filename); + if(qi) { + _item_quest_status[item_script] = qi->GetIdentifier(); qi->LoadItemScript(filename, item_script); - qi->EventItem(evt, client, item, objid, extra_data); - } else { - _item_quest_status[item_script] = QuestFailedToLoad; - } - } + qi->EventItem(evt, client, item, objid, extra_data); + } else { + _item_quest_status[item_script] = QuestFailedToLoad; + } + } } void QuestParserCollection::EventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, uint32 extra_data) { - std::map::iterator iter = _spell_quest_status.find(spell_id); - if(iter != _spell_quest_status.end()) { - //loaded or failed to load - if(iter->second != QuestFailedToLoad) { - std::map::iterator qiter = _interfaces.find(iter->second); - qiter->second->EventSpell(evt, npc, client, spell_id, extra_data); - } - } else { + std::map::iterator iter = _spell_quest_status.find(spell_id); + if(iter != _spell_quest_status.end()) { + //loaded or failed to load + if(iter->second != QuestFailedToLoad) { + std::map::iterator qiter = _interfaces.find(iter->second); + qiter->second->EventSpell(evt, npc, client, spell_id, extra_data); + } + } else { std::string filename; - QuestInterface *qi = GetQIBySpellQuest(spell_id, filename); - if(qi) { - _spell_quest_status[spell_id] = qi->GetIdentifier(); + QuestInterface *qi = GetQIBySpellQuest(spell_id, filename); + if(qi) { + _spell_quest_status[spell_id] = qi->GetIdentifier(); qi->LoadSpellScript(filename, spell_id); - qi->EventSpell(evt, npc, client, spell_id, extra_data); - } else { - _spell_quest_status[spell_id] = QuestFailedToLoad; - } - } + qi->EventSpell(evt, npc, client, spell_id, extra_data); + } else { + _spell_quest_status[spell_id] = QuestFailedToLoad; + } + } } QuestInterface *QuestParserCollection::GetQIByNPCQuest(uint32 npcid, std::string &filename) { - //first look for /quests/zone/npcid.ext (precedence) - filename = "quests/"; - filename += zone->GetShortName(); - filename += "/"; - filename += itoa(npcid); - std::string tmp; - FILE *f = nullptr; + //first look for /quests/zone/npcid.ext (precedence) + filename = "quests/"; + filename += zone->GetShortName(); + filename += "/"; + filename += itoa(npcid); + std::string tmp; + FILE *f = nullptr; - std::list::iterator iter = _load_precedence.begin(); - while(iter != _load_precedence.end()) { - tmp = filename; - std::map::iterator ext = _extensions.find((*iter)->GetIdentifier()); - tmp += "."; - tmp += ext->second; - f = fopen(tmp.c_str(), "r"); - if(f) { - fclose(f); + std::list::iterator iter = _load_precedence.begin(); + while(iter != _load_precedence.end()) { + tmp = filename; + std::map::iterator ext = _extensions.find((*iter)->GetIdentifier()); + tmp += "."; + tmp += ext->second; + f = fopen(tmp.c_str(), "r"); + if(f) { + fclose(f); filename = tmp; - return (*iter); - } + return (*iter); + } - iter++; - } + iter++; + } - //second look for /quests/zone/npcname.ext (precedence) - const NPCType *npc_type = database.GetNPCType(npcid); - if(!npc_type) { - return nullptr; - } - std::string npc_name = npc_type->name; - int sz = static_cast(npc_name.length()); - for(int i = 0; i < sz; ++i) { - if(npc_name[i] == '`') { - npc_name[i] = '-'; - } - } + //second look for /quests/zone/npcname.ext (precedence) + const NPCType *npc_type = database.GetNPCType(npcid); + if(!npc_type) { + return nullptr; + } + std::string npc_name = npc_type->name; + int sz = static_cast(npc_name.length()); + for(int i = 0; i < sz; ++i) { + if(npc_name[i] == '`') { + npc_name[i] = '-'; + } + } - filename = "quests/"; - filename += zone->GetShortName(); - filename += "/"; - filename += npc_name; + filename = "quests/"; + filename += zone->GetShortName(); + filename += "/"; + filename += npc_name; - iter = _load_precedence.begin(); - while(iter != _load_precedence.end()) { - tmp = filename; - std::map::iterator ext = _extensions.find((*iter)->GetIdentifier()); - tmp += "."; - tmp += ext->second; - f = fopen(tmp.c_str(), "r"); - if(f) { - fclose(f); + iter = _load_precedence.begin(); + while(iter != _load_precedence.end()) { + tmp = filename; + std::map::iterator ext = _extensions.find((*iter)->GetIdentifier()); + tmp += "."; + tmp += ext->second; + f = fopen(tmp.c_str(), "r"); + if(f) { + fclose(f); filename = tmp; - return (*iter); - } + return (*iter); + } - iter++; - } + iter++; + } - //third look for /quests/templates/npcid.ext (precedence) - filename = "quests/"; - filename += QUEST_TEMPLATES_DIRECTORY; - filename += "/"; - filename += itoa(npcid); - iter = _load_precedence.begin(); - while(iter != _load_precedence.end()) { - tmp = filename; - std::map::iterator ext = _extensions.find((*iter)->GetIdentifier()); - tmp += "."; - tmp += ext->second; - f = fopen(tmp.c_str(), "r"); - if(f) { - fclose(f); + //third look for /quests/templates/npcid.ext (precedence) + filename = "quests/"; + filename += QUEST_TEMPLATES_DIRECTORY; + filename += "/"; + filename += itoa(npcid); + iter = _load_precedence.begin(); + while(iter != _load_precedence.end()) { + tmp = filename; + std::map::iterator ext = _extensions.find((*iter)->GetIdentifier()); + tmp += "."; + tmp += ext->second; + f = fopen(tmp.c_str(), "r"); + if(f) { + fclose(f); filename = tmp; - return (*iter); - } + return (*iter); + } - iter++; - } + iter++; + } - //fourth look for /quests/templates/npcname.ext (precedence) - filename = "quests/"; - filename += QUEST_TEMPLATES_DIRECTORY; - filename += "/"; - filename += npc_name; - iter = _load_precedence.begin(); - while(iter != _load_precedence.end()) { - tmp = filename; - std::map::iterator ext = _extensions.find((*iter)->GetIdentifier()); - tmp += "."; - tmp += ext->second; - f = fopen(tmp.c_str(), "r"); - if(f) { - fclose(f); + //fourth look for /quests/templates/npcname.ext (precedence) + filename = "quests/"; + filename += QUEST_TEMPLATES_DIRECTORY; + filename += "/"; + filename += npc_name; + iter = _load_precedence.begin(); + while(iter != _load_precedence.end()) { + tmp = filename; + std::map::iterator ext = _extensions.find((*iter)->GetIdentifier()); + tmp += "."; + tmp += ext->second; + f = fopen(tmp.c_str(), "r"); + if(f) { + fclose(f); filename = tmp; - return (*iter); - } + return (*iter); + } - iter++; - } + iter++; + } //fifth look for /quests/zone/default.ext (precedence) - filename = "quests/"; - filename += zone->GetShortName(); - filename += "/"; - filename += "default"; - iter = _load_precedence.begin(); - while(iter != _load_precedence.end()) { - tmp = filename; - std::map::iterator ext = _extensions.find((*iter)->GetIdentifier()); - tmp += "."; - tmp += ext->second; - f = fopen(tmp.c_str(), "r"); - if(f) { - fclose(f); + filename = "quests/"; + filename += zone->GetShortName(); + filename += "/"; + filename += "default"; + iter = _load_precedence.begin(); + while(iter != _load_precedence.end()) { + tmp = filename; + std::map::iterator ext = _extensions.find((*iter)->GetIdentifier()); + tmp += "."; + tmp += ext->second; + f = fopen(tmp.c_str(), "r"); + if(f) { + fclose(f); filename = tmp; - return (*iter); - } + return (*iter); + } - iter++; - } + iter++; + } - //last look for /quests/templates/default.ext (precedence) - filename = "quests/"; - filename += QUEST_TEMPLATES_DIRECTORY; - filename += "/"; - filename += "default"; - iter = _load_precedence.begin(); - while(iter != _load_precedence.end()) { - tmp = filename; - std::map::iterator ext = _extensions.find((*iter)->GetIdentifier()); - tmp += "."; - tmp += ext->second; - f = fopen(tmp.c_str(), "r"); - if(f) { - fclose(f); + //last look for /quests/templates/default.ext (precedence) + filename = "quests/"; + filename += QUEST_TEMPLATES_DIRECTORY; + filename += "/"; + filename += "default"; + iter = _load_precedence.begin(); + while(iter != _load_precedence.end()) { + tmp = filename; + std::map::iterator ext = _extensions.find((*iter)->GetIdentifier()); + tmp += "."; + tmp += ext->second; + f = fopen(tmp.c_str(), "r"); + if(f) { + fclose(f); filename = tmp; - return (*iter); - } + return (*iter); + } - iter++; - } + iter++; + } - return nullptr; + return nullptr; } QuestInterface *QuestParserCollection::GetQIByPlayerQuest(std::string &filename) { @@ -483,181 +500,181 @@ QuestInterface *QuestParserCollection::GetQIByPlayerQuest(std::string &filename) if(!zone) return nullptr; - //first look for /quests/zone/player_v[instance_version].ext (precedence) - filename = "quests/"; - filename += zone->GetShortName(); - filename += "/"; - filename += "player_v"; - filename += itoa(zone->GetInstanceVersion()); - std::string tmp; - FILE *f = nullptr; + //first look for /quests/zone/player_v[instance_version].ext (precedence) + filename = "quests/"; + filename += zone->GetShortName(); + filename += "/"; + filename += "player_v"; + filename += itoa(zone->GetInstanceVersion()); + std::string tmp; + FILE *f = nullptr; - std::list::iterator iter = _load_precedence.begin(); - while(iter != _load_precedence.end()) { - tmp = filename; - std::map::iterator ext = _extensions.find((*iter)->GetIdentifier()); - tmp += "."; - tmp += ext->second; - f = fopen(tmp.c_str(), "r"); - if(f) { - fclose(f); + std::list::iterator iter = _load_precedence.begin(); + while(iter != _load_precedence.end()) { + tmp = filename; + std::map::iterator ext = _extensions.find((*iter)->GetIdentifier()); + tmp += "."; + tmp += ext->second; + f = fopen(tmp.c_str(), "r"); + if(f) { + fclose(f); filename = tmp; - return (*iter); - } + return (*iter); + } - iter++; - } + iter++; + } - //second look for /quests/zone/player.ext (precedence) - filename = "quests/"; - filename += zone->GetShortName(); - filename += "/"; - filename += "player"; + //second look for /quests/zone/player.ext (precedence) + filename = "quests/"; + filename += zone->GetShortName(); + filename += "/"; + filename += "player"; - iter = _load_precedence.begin(); - while(iter != _load_precedence.end()) { - tmp = filename; - std::map::iterator ext = _extensions.find((*iter)->GetIdentifier()); - tmp += "."; - tmp += ext->second; - f = fopen(tmp.c_str(), "r"); - if(f) { - fclose(f); + iter = _load_precedence.begin(); + while(iter != _load_precedence.end()) { + tmp = filename; + std::map::iterator ext = _extensions.find((*iter)->GetIdentifier()); + tmp += "."; + tmp += ext->second; + f = fopen(tmp.c_str(), "r"); + if(f) { + fclose(f); filename = tmp; - return (*iter); - } + return (*iter); + } - iter++; - } + iter++; + } - //third look for /quests/templates/player.ext (precedence) - filename = "quests/"; - filename += QUEST_TEMPLATES_DIRECTORY; - filename += "/"; - filename += "player"; - iter = _load_precedence.begin(); - while(iter != _load_precedence.end()) { - tmp = filename; - std::map::iterator ext = _extensions.find((*iter)->GetIdentifier()); - tmp += "."; - tmp += ext->second; - f = fopen(tmp.c_str(), "r"); - if(f) { - fclose(f); + //third look for /quests/templates/player.ext (precedence) + filename = "quests/"; + filename += QUEST_TEMPLATES_DIRECTORY; + filename += "/"; + filename += "player"; + iter = _load_precedence.begin(); + while(iter != _load_precedence.end()) { + tmp = filename; + std::map::iterator ext = _extensions.find((*iter)->GetIdentifier()); + tmp += "."; + tmp += ext->second; + f = fopen(tmp.c_str(), "r"); + if(f) { + fclose(f); filename = tmp; - return (*iter); - } + return (*iter); + } - iter++; - } + iter++; + } - return nullptr; + return nullptr; } QuestInterface *QuestParserCollection::GetQIByGlobalNPCQuest(std::string &filename) { - // simply look for templates/global_npc.pl - filename = "quests/"; - filename += QUEST_TEMPLATES_DIRECTORY; - filename += "/"; - filename += "global_npc"; - std::string tmp; - FILE *f = nullptr; + // simply look for templates/global_npc.pl + filename = "quests/"; + filename += QUEST_TEMPLATES_DIRECTORY; + filename += "/"; + filename += "global_npc"; + std::string tmp; + FILE *f = nullptr; - std::list::iterator iter = _load_precedence.begin(); - while(iter != _load_precedence.end()) { - tmp = filename; - std::map::iterator ext = _extensions.find((*iter)->GetIdentifier()); - tmp += "."; - tmp += ext->second; - f = fopen(tmp.c_str(), "r"); - if(f) { - fclose(f); + std::list::iterator iter = _load_precedence.begin(); + while(iter != _load_precedence.end()) { + tmp = filename; + std::map::iterator ext = _extensions.find((*iter)->GetIdentifier()); + tmp += "."; + tmp += ext->second; + f = fopen(tmp.c_str(), "r"); + if(f) { + fclose(f); filename = tmp; - return (*iter); - } + return (*iter); + } - iter++; - } + iter++; + } - return nullptr; + return nullptr; } QuestInterface *QuestParserCollection::GetQIByGlobalPlayerQuest(std::string &filename) { - //first look for /quests/templates/player.ext (precedence) - filename = "quests/"; - filename += QUEST_TEMPLATES_DIRECTORY; - filename += "/"; - filename += "global_player"; - std::string tmp; - FILE *f = nullptr; + //first look for /quests/templates/player.ext (precedence) + filename = "quests/"; + filename += QUEST_TEMPLATES_DIRECTORY; + filename += "/"; + filename += "global_player"; + std::string tmp; + FILE *f = nullptr; - std::list::iterator iter = _load_precedence.begin(); - while(iter != _load_precedence.end()) { - tmp = filename; - std::map::iterator ext = _extensions.find((*iter)->GetIdentifier()); - tmp += "."; - tmp += ext->second; - f = fopen(tmp.c_str(), "r"); - if(f) { - fclose(f); + std::list::iterator iter = _load_precedence.begin(); + while(iter != _load_precedence.end()) { + tmp = filename; + std::map::iterator ext = _extensions.find((*iter)->GetIdentifier()); + tmp += "."; + tmp += ext->second; + f = fopen(tmp.c_str(), "r"); + if(f) { + fclose(f); filename = tmp; - return (*iter); - } + return (*iter); + } - iter++; - } + iter++; + } - return nullptr; + return nullptr; } QuestInterface *QuestParserCollection::GetQIBySpellQuest(uint32 spell_id, std::string &filename) { - //first look for /quests/spells/spell_id.ext (precedence) - filename = "quests/spells/"; - filename += itoa(spell_id); - std::string tmp; - FILE *f = nullptr; + //first look for /quests/spells/spell_id.ext (precedence) + filename = "quests/spells/"; + filename += itoa(spell_id); + std::string tmp; + FILE *f = nullptr; - std::list::iterator iter = _load_precedence.begin(); - while(iter != _load_precedence.end()) { - tmp = filename; - std::map::iterator ext = _extensions.find((*iter)->GetIdentifier()); - tmp += "."; - tmp += ext->second; - f = fopen(tmp.c_str(), "r"); - if(f) { - fclose(f); + std::list::iterator iter = _load_precedence.begin(); + while(iter != _load_precedence.end()) { + tmp = filename; + std::map::iterator ext = _extensions.find((*iter)->GetIdentifier()); + tmp += "."; + tmp += ext->second; + f = fopen(tmp.c_str(), "r"); + if(f) { + fclose(f); filename = tmp; - return (*iter); - } + return (*iter); + } - iter++; - } + iter++; + } - return nullptr; + return nullptr; } QuestInterface *QuestParserCollection::GetQIByItemQuest(std::string item_script, std::string &filename) { - //first look for /quests/items/item_script.ext (precedence) - filename = "quests/items/"; - filename += item_script; - std::string tmp; - FILE *f = nullptr; + //first look for /quests/items/item_script.ext (precedence) + filename = "quests/items/"; + filename += item_script; + std::string tmp; + FILE *f = nullptr; - std::list::iterator iter = _load_precedence.begin(); - while(iter != _load_precedence.end()) { - tmp = filename; - std::map::iterator ext = _extensions.find((*iter)->GetIdentifier()); - tmp += "."; - tmp += ext->second; - f = fopen(tmp.c_str(), "r"); - if(f) { - fclose(f); + std::list::iterator iter = _load_precedence.begin(); + while(iter != _load_precedence.end()) { + tmp = filename; + std::map::iterator ext = _extensions.find((*iter)->GetIdentifier()); + tmp += "."; + tmp += ext->second; + f = fopen(tmp.c_str(), "r"); + if(f) { + fclose(f); filename = tmp; - return (*iter); - } + return (*iter); + } - iter++; - } + iter++; + } - return nullptr; + return nullptr; } diff --git a/zone/QuestParserCollection.h b/zone/QuestParserCollection.h index d2d518821..8831c8c6b 100644 --- a/zone/QuestParserCollection.h +++ b/zone/QuestParserCollection.h @@ -1,38 +1,57 @@ +/* EQEMu: Everquest Server Emulator + Copyright (C) 2001-2006 EQEMu Development Team (http://eqemulator.net) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY except by those people which sell it, which + are required to give you total support for your newly bought product; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + #ifndef _EQE_QUESTPARSERCOLLECTION_H #define _EQE_QUESTPARSERCOLLECTION_H #include "../common/types.h" +#include "../common/Item.h" + +#include "masterentity.h" +#include "QuestInterface.h" + #include #include #include #include -#include "masterentity.h" -#include "../common/Item.h" -#include "QuestInterface.h" - #define QuestFailedToLoad 0xFFFFFFFF #define QuestUnloaded 0x00 class QuestParserCollection { public: - QuestParserCollection(); - ~QuestParserCollection(); + QuestParserCollection(); + ~QuestParserCollection(); - void RegisterQuestInterface(QuestInterface *qi, std::string ext); + void RegisterQuestInterface(QuestInterface *qi, std::string ext); - void AddVar(std::string name, std::string val); - void ReloadQuests(bool reset_timers = true); + void AddVar(std::string name, std::string val); + void ReloadQuests(bool reset_timers = true); - bool HasQuestSub(uint32 npcid, const char *subname); + bool HasQuestSub(uint32 npcid, const char *subname); bool PlayerHasQuestSub(const char *subname); bool SpellHasQuestSub(uint32 spell_id, const char *subname); - bool ItemHasQuestSub(ItemInst *itm, const char *subname); + bool ItemHasQuestSub(ItemInst *itm, const char *subname); - void EventNPC(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data); - void EventPlayer(QuestEventID evt, Client *client, std::string data, uint32 extra_data); - void EventItem(QuestEventID evt, Client *client, ItemInst *item, uint32 objid, uint32 extra_data); - void EventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, uint32 extra_data); + void EventNPC(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data); + void EventPlayer(QuestEventID evt, Client *client, std::string data, uint32 extra_data); + void EventItem(QuestEventID evt, Client *client, ItemInst *item, uint32 objid, uint32 extra_data); + void EventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, uint32 extra_data); private: bool HasQuestSubLocal(uint32 npcid, const char *subname); @@ -45,25 +64,25 @@ private: void EventPlayerLocal(QuestEventID evt, Client *client, std::string data, uint32 extra_data); void EventPlayerGlobal(QuestEventID evt, Client *client, std::string data, uint32 extra_data); - QuestInterface *GetQIByNPCQuest(uint32 npcid, std::string &filename); - QuestInterface *GetQIByGlobalNPCQuest(std::string &filename); - QuestInterface *GetQIByPlayerQuest(std::string &filename); - QuestInterface *GetQIByGlobalPlayerQuest(std::string &filename); - QuestInterface *GetQIBySpellQuest(uint32 spell_id, std::string &filename); - QuestInterface *GetQIByItemQuest(std::string item_script, std::string &filename); + QuestInterface *GetQIByNPCQuest(uint32 npcid, std::string &filename); + QuestInterface *GetQIByGlobalNPCQuest(std::string &filename); + QuestInterface *GetQIByPlayerQuest(std::string &filename); + QuestInterface *GetQIByGlobalPlayerQuest(std::string &filename); + QuestInterface *GetQIBySpellQuest(uint32 spell_id, std::string &filename); + QuestInterface *GetQIByItemQuest(std::string item_script, std::string &filename); - std::map _interfaces; - std::map _extensions; - std::list _load_precedence; + std::map _interfaces; + std::map _extensions; + std::list _load_precedence; - //0x00 = Unloaded - //0xFFFFFFFF = Failed to Load - std::map _npc_quest_status; + //0x00 = Unloaded + //0xFFFFFFFF = Failed to Load + std::map _npc_quest_status; uint32 _global_npc_quest_status; - uint32 _player_quest_status; - uint32 _global_player_quest_status; - std::map _spell_quest_status; - std::map _item_quest_status; + uint32 _player_quest_status; + uint32 _global_player_quest_status; + std::map _spell_quest_status; + std::map _item_quest_status; }; extern QuestParserCollection *parse; diff --git a/zone/embparser.cpp b/zone/embparser.cpp index 854016574..45b7ac1d6 100644 --- a/zone/embparser.cpp +++ b/zone/embparser.cpp @@ -1,31 +1,30 @@ /* EQEMu: Everquest Server Emulator - Copyright (C) 2001-2013 EQEMu Development Team (http://eqemulator.net) + Copyright (C) 2001-2006 EQEMu Development Team (http://eqemulator.net) - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; version 2 of the License. + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY except by those people which sell it, which + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY except by those people which sell it, which are required to give you total support for your newly bought product; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - #ifdef EMBPERL #include "../common/debug.h" +#include "../common/seperator.h" +#include "../common/MiscFunctions.h" +#include "../common/features.h" #include "masterentity.h" #include "embparser.h" #include "questmgr.h" -#include "command.h" -#include "../common/seperator.h" -#include "../common/MiscFunctions.h" #include "QGlobals.h" #include "zone.h" #include @@ -184,11 +183,11 @@ void PerlembParser::EventCommon(QuestEventID event, uint32 objid, const char * d } else if(isSpellQuest) { - if(mob) { - SendCommands(package_name.c_str(), sub_name, 0, mob, mob, nullptr); - } else { - SendCommands(package_name.c_str(), sub_name, 0, npcmob, mob, nullptr); - } + if(mob) { + SendCommands(package_name.c_str(), sub_name, 0, mob, mob, nullptr); + } else { + SendCommands(package_name.c_str(), sub_name, 0, npcmob, mob, nullptr); + } } else { SendCommands(package_name.c_str(), sub_name, objid, npcmob, mob, nullptr); @@ -645,7 +644,7 @@ void PerlembParser::SendCommands(const char *pkgprefix, const char *event, uint3 perl->dosub(std::string(pkgprefix).append("::").append(event).c_str()); #ifdef EMBPERL_XS_CLASSES - std::string eval_str = (std::string)"$" + (std::string)pkgprefix + (std::string)"::client = undef;"; + std::string eval_str = (std::string)"$" + (std::string)pkgprefix + (std::string)"::client = undef;"; eval_str += (std::string)"$" + (std::string)pkgprefix + (std::string)"::npc = undef;"; eval_str += (std::string)"$" + (std::string)pkgprefix + (std::string)"::questitem = undef;"; eval_str += (std::string)"$" + (std::string)pkgprefix + (std::string)"::entity_list = undef;"; @@ -765,12 +764,12 @@ void PerlembParser::GetQuestTypes(bool &isPlayerQuest, bool &isGlobalPlayerQuest { if(!npcmob && mob) { if(!iteminst) { - if(global) { - isGlobalPlayerQuest = true; - } else { - isPlayerQuest = true; - } - } + if(global) { + isGlobalPlayerQuest = true; + } else { + isPlayerQuest = true; + } + } else isItemQuest = true; } @@ -811,7 +810,7 @@ void PerlembParser::GetQuestPackageName(bool &isPlayerQuest, bool &isGlobalPlaye } else if(isGlobalPlayerQuest) { package_name = "qst_global_player"; - } + } else { package_name = "qst_spell_"; @@ -1221,7 +1220,7 @@ void PerlembParser::ExportEventVariables(std::string &package_name, QuestEventID } case EVENT_SCALE_CALC: - case EVENT_ITEM_ENTERZONE: { + case EVENT_ITEM_ENTERZONE: { ExportVar(package_name.c_str(), "itemid", objid); ExportVar(package_name.c_str(), "itemname", iteminst->GetItem()->Name); break; diff --git a/zone/embparser.h b/zone/embparser.h index 0680ae6f9..acdcae269 100644 --- a/zone/embparser.h +++ b/zone/embparser.h @@ -1,17 +1,37 @@ +/* EQEMu: Everquest Server Emulator + Copyright (C) 2001-2006 EQEMu Development Team (http://eqemulator.net) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY except by those people which sell it, which + are required to give you total support for your newly bought product; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + #ifndef EQEMU_EMBPARSER_H #define EQMEU_EMBPARSER_H #ifdef EMBPERL - -#include "client.h" -#include "../common/features.h" #include "QuestParserCollection.h" #include "QuestInterface.h" #include -#include #include +#include #include "embperl.h" +class ItemInst; +class Mob; +class Client; +class NPC; + typedef enum { questUnloaded, @@ -37,17 +57,17 @@ public: virtual double EventNPC(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data); virtual double EventGlobalNPC(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data); - virtual double EventPlayer(QuestEventID evt, Client *client, std::string data, uint32 extra_data); - virtual double EventGlobalPlayer(QuestEventID evt, Client *client, std::string data, uint32 extra_data); - virtual double EventItem(QuestEventID evt, Client *client, ItemInst *item, uint32 objid, uint32 extra_data); - virtual double EventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, uint32 extra_data); + virtual double EventPlayer(QuestEventID evt, Client *client, std::string data, uint32 extra_data); + virtual double EventGlobalPlayer(QuestEventID evt, Client *client, std::string data, uint32 extra_data); + virtual double EventItem(QuestEventID evt, Client *client, ItemInst *item, uint32 objid, uint32 extra_data); + virtual double 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 GlobalPlayerHasQuestSub(const char *subname); virtual bool SpellHasQuestSub(uint32 spell_id, const char *subname); - virtual bool ItemHasQuestSub(ItemInst *itm, const char *subname); + virtual bool ItemHasQuestSub(ItemInst *itm, const char *subname); virtual void LoadNPCScript(std::string filename, int npc_id); virtual void LoadGlobalNPCScript(std::string filename); @@ -56,10 +76,10 @@ public: virtual void LoadItemScript(std::string filename, std::string item_script); virtual void LoadSpellScript(std::string filename, uint32 spell_id); - virtual void AddVar(std::string name, std::string val); + virtual void AddVar(std::string name, std::string val); virtual std::string GetVar(std::string name); - virtual void ReloadQuests(); - virtual uint32 GetIdentifier() { return 0xf8b05c11; } + virtual void ReloadQuests(); + virtual uint32 GetIdentifier() { return 0xf8b05c11; } private: Embperl *perl; @@ -111,167 +131,3 @@ private: #endif #endif - - - - -////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 -//#include -//#include -//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 hasQuests; //npcid -> questMode -// map playerQuestLoaded; //zone shortname -> playerQuestMode -// playerQuestMode globalPlayerQuestLoaded; -// GlobalNPCQuestMode globalNPCQuestLoaded; -// map itemQuestLoaded; // package name - > itemQuestMode -// map spellQuestLoaded; -// -// queue 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 &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); -// -// -//}; -// -//#endif //EMBPERL -// -//#endif //EMBPARSER_H diff --git a/zone/perlparser.cpp b/zone/embparser_api.cpp similarity index 92% rename from zone/perlparser.cpp rename to zone/embparser_api.cpp index dcd23341e..eb91675f6 100644 --- a/zone/perlparser.cpp +++ b/zone/embparser_api.cpp @@ -1,19 +1,19 @@ /* EQEMu: Everquest Server Emulator - Copyright (C) 2001-2006 EQEMu Development Team (http://eqemulator.net) + Copyright (C) 2001-2006 EQEMu Development Team (http://eqemulator.net) - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; version 2 of the License. + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY except by those people which sell it, which + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY except by those people which sell it, which are required to give you total support for your newly bought product; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "../common/features.h" @@ -22,12 +22,13 @@ #ifdef EMBPERL_XS #include "../common/debug.h" +#include "../common/MiscFunctions.h" #include "embparser.h" #include "questmgr.h" #include "embxs.h" #include "entity.h" -#include "../common/MiscFunctions.h" #include "zone.h" + extern Zone* zone; /* @@ -141,7 +142,7 @@ XS(XS__echo) { dXSARGS; if (items != 2) - Perl_croak(aTHX_ "Usage: echo(id#, str)"); + Perl_croak(aTHX_ "Usage: echo(id#, str)"); quest_manager.echo(SvUV(ST(0)), SvPV_nolen(ST(1))); @@ -1741,79 +1742,79 @@ XS(XS__clear_zone_flag) XS(XS__summonburriedplayercorpse); XS(XS__summonburriedplayercorpse) { - dXSARGS; - if (items != 5) - Perl_croak(aTHX_ "Usage: summonburriedplayercorpse(char_id,dest_x,dest_y,dest_z,dest_heading)"); + dXSARGS; + if (items != 5) + Perl_croak(aTHX_ "Usage: summonburriedplayercorpse(char_id,dest_x,dest_y,dest_z,dest_heading)"); - bool RETVAL; - uint32 char_id = (int)SvIV(ST(0)); - float dest_x = (float)SvIV(ST(1)); - float dest_y = (float)SvIV(ST(2)); - float dest_z = (float)SvIV(ST(3)); - float dest_heading = (float)SvIV(ST(4)); + bool RETVAL; + uint32 char_id = (int)SvIV(ST(0)); + float dest_x = (float)SvIV(ST(1)); + float dest_y = (float)SvIV(ST(2)); + float dest_z = (float)SvIV(ST(3)); + float dest_heading = (float)SvIV(ST(4)); - RETVAL = quest_manager.summonburriedplayercorpse(char_id, dest_x, dest_y, dest_z, dest_heading); + RETVAL = quest_manager.summonburriedplayercorpse(char_id, dest_x, dest_y, dest_z, dest_heading); - ST(0) = boolSV(RETVAL); - sv_2mortal(ST(0)); - XSRETURN(1); + ST(0) = boolSV(RETVAL); + sv_2mortal(ST(0)); + XSRETURN(1); } XS(XS__summonallplayercorpses); XS(XS__summonallplayercorpses) { - dXSARGS; - if (items != 5) - Perl_croak(aTHX_ "Usage: summonallplayercorpses(char_id,dest_x,dest_y,dest_z,dest_heading)"); + dXSARGS; + if (items != 5) + Perl_croak(aTHX_ "Usage: summonallplayercorpses(char_id,dest_x,dest_y,dest_z,dest_heading)"); - bool RETVAL; - uint32 char_id = (int)SvIV(ST(0)); - float dest_x = (float)SvIV(ST(1)); - float dest_y = (float)SvIV(ST(2)); - float dest_z = (float)SvIV(ST(3)); - float dest_heading = (float)SvIV(ST(4)); + bool RETVAL; + uint32 char_id = (int)SvIV(ST(0)); + float dest_x = (float)SvIV(ST(1)); + float dest_y = (float)SvIV(ST(2)); + float dest_z = (float)SvIV(ST(3)); + float dest_heading = (float)SvIV(ST(4)); - RETVAL = quest_manager.summonallplayercorpses(char_id, dest_x, dest_y, dest_z, dest_heading); + RETVAL = quest_manager.summonallplayercorpses(char_id, dest_x, dest_y, dest_z, dest_heading); - ST(0) = boolSV(RETVAL); - sv_2mortal(ST(0)); - XSRETURN(1); + ST(0) = boolSV(RETVAL); + sv_2mortal(ST(0)); + XSRETURN(1); } XS(XS__getplayerburriedcorpsecount); XS(XS__getplayerburriedcorpsecount) { - dXSARGS; - if (items != 1) - Perl_croak(aTHX_ "Usage: getplayerburriedcorpsecount(char_id)"); + dXSARGS; + if (items != 1) + Perl_croak(aTHX_ "Usage: getplayerburriedcorpsecount(char_id)"); - uint32 RETVAL; - dXSTARG; + uint32 RETVAL; + dXSTARG; - uint32 char_id = (int)SvIV(ST(0)); + uint32 char_id = (int)SvIV(ST(0)); - RETVAL = quest_manager.getplayerburriedcorpsecount(char_id); - XSprePUSH; PUSHu((IV)RETVAL); + RETVAL = quest_manager.getplayerburriedcorpsecount(char_id); + XSprePUSH; PUSHu((IV)RETVAL); - XSRETURN(1); + XSRETURN(1); } XS(XS__buryplayercorpse); XS(XS__buryplayercorpse) { - dXSARGS; - if (items != 1) - Perl_croak(aTHX_ "Usage: buryplayercorpse(char_id)"); + dXSARGS; + if (items != 1) + Perl_croak(aTHX_ "Usage: buryplayercorpse(char_id)"); - uint32 RETVAL; - dXSTARG; + uint32 RETVAL; + dXSTARG; - uint32 char_id = (int)SvIV(ST(0)); + uint32 char_id = (int)SvIV(ST(0)); - RETVAL = quest_manager.buryplayercorpse(char_id); - XSprePUSH; PUSHu((IV)RETVAL); + RETVAL = quest_manager.buryplayercorpse(char_id); + XSprePUSH; PUSHu((IV)RETVAL); - XSRETURN(1); + XSRETURN(1); } XS(XS__forcedooropen); @@ -1885,14 +1886,14 @@ XS(XS__toggledoorstate) XS(XS__isdooropen); XS(XS__isdooropen) { - dXSARGS; - if (items != 1) - Perl_croak(aTHX_ "Usage: isdooropen(doorid)"); + dXSARGS; + if (items != 1) + Perl_croak(aTHX_ "Usage: isdooropen(doorid)"); - bool RETVAL; - dXSTARG; + bool RETVAL; + dXSTARG; - uint32 doorid = (int)SvIV(ST(0)); + uint32 doorid = (int)SvIV(ST(0)); RETVAL = quest_manager.isdooropen(doorid); XSprePUSH; PUSHu((IV)RETVAL); @@ -2073,9 +2074,9 @@ XS(XS__npcfeature) XS(XS__createbotcount); XS(XS__createbotcount) { - dXSARGS; - int RETVAL; - dXSTARG; + dXSARGS; + int RETVAL; + dXSTARG; RETVAL = quest_manager.createbotcount(); XSprePUSH; PUSHi((IV)RETVAL); @@ -2086,9 +2087,9 @@ XS(XS__createbotcount) XS(XS__spawnbotcount); XS(XS__spawnbotcount) { - dXSARGS; - int RETVAL; - dXSTARG; + dXSARGS; + int RETVAL; + dXSTARG; RETVAL = quest_manager.spawnbotcount(); XSprePUSH; PUSHi((IV)RETVAL); @@ -2099,9 +2100,9 @@ XS(XS__spawnbotcount) XS(XS__botquest); XS(XS__botquest) { - dXSARGS; - bool RETVAL; - dXSTARG; + dXSARGS; + bool RETVAL; + dXSTARG; RETVAL = quest_manager.botquest(); XSprePUSH; PUSHu((IV)RETVAL); @@ -2201,7 +2202,7 @@ XS(XS__istaskenabled); XS(XS__istaskenabled) { dXSARGS; - bool RETVAL; + bool RETVAL; dXSTARG; if(items == 1) { @@ -2219,7 +2220,7 @@ XS(XS__istaskactive); XS(XS__istaskactive) { dXSARGS; - bool RETVAL; + bool RETVAL; dXSTARG; if(items == 1) { @@ -2237,7 +2238,7 @@ XS(XS__istaskactivityactive); XS(XS__istaskactivityactive) { dXSARGS; - bool RETVAL; + bool RETVAL; dXSTARG; if(items == 2) { @@ -2256,7 +2257,7 @@ XS(XS__gettaskactivitydonecount); XS(XS__gettaskactivitydonecount) { dXSARGS; - uint32 RETVAL; + uint32 RETVAL; dXSTARG; if(items == 2) { @@ -2358,7 +2359,7 @@ XS(XS__tasktimeleft); XS(XS__tasktimeleft) { dXSARGS; - int RETVAL; + int RETVAL; dXSTARG; if(items == 1) { @@ -2377,7 +2378,7 @@ XS(XS__istaskcompleted); XS(XS__istaskcompleted) { dXSARGS; - int RETVAL; + int RETVAL; dXSTARG; if(items == 1) { @@ -2396,7 +2397,7 @@ XS(XS__enabledtaskcount); XS(XS__enabledtaskcount) { dXSARGS; - int RETVAL; + int RETVAL; dXSTARG; if(items == 1) { @@ -2415,7 +2416,7 @@ XS(XS__firsttaskinset); XS(XS__firsttaskinset) { dXSARGS; - int RETVAL; + int RETVAL; dXSTARG; if(items == 1) { @@ -2434,7 +2435,7 @@ XS(XS__lasttaskinset); XS(XS__lasttaskinset) { dXSARGS; - int RETVAL; + int RETVAL; dXSTARG; if(items == 1) { @@ -2453,7 +2454,7 @@ XS(XS__nexttaskinset); XS(XS__nexttaskinset) { dXSARGS; - int RETVAL; + int RETVAL; dXSTARG; if(items == 2) { @@ -2472,7 +2473,7 @@ XS(XS__activespeaktask); XS(XS__activespeaktask) { dXSARGS; - int RETVAL; + int RETVAL; dXSTARG; if(items == 0) { @@ -2490,7 +2491,7 @@ XS(XS__activespeakactivity); XS(XS__activespeakactivity) { dXSARGS; - int RETVAL; + int RETVAL; dXSTARG; if(items == 1) { @@ -2509,7 +2510,7 @@ XS(XS__activetasksinset); XS(XS__activetasksinset) { dXSARGS; - int RETVAL; + int RETVAL; dXSTARG; if(items == 1) { @@ -2528,7 +2529,7 @@ XS(XS__completedtasksinset); XS(XS__completedtasksinset) { dXSARGS; - int RETVAL; + int RETVAL; dXSTARG; if(items == 1) { @@ -2548,7 +2549,7 @@ XS(XS__istaskappropriate); XS(XS__istaskappropriate) { dXSARGS; - bool RETVAL; + bool RETVAL; dXSTARG; if(items == 1) { @@ -2565,13 +2566,13 @@ XS(XS__istaskappropriate) XS(XS__popup); // prototype to pass -Wmissing-prototypes XS(XS__popup) { - dXSARGS; + dXSARGS; int popupid = 0; int buttons = 0; int duration = 0; if((items < 2) || (items > 5)) - Perl_croak(aTHX_ "Usage: popup(windowtitle, text, popupid, buttons, duration)"); + Perl_croak(aTHX_ "Usage: popup(windowtitle, text, popupid, buttons, duration)"); if(items >= 3) popupid = (int)SvIV(ST(2)); @@ -2582,9 +2583,9 @@ XS(XS__istaskappropriate) if(items == 5) duration = (int)SvIV(ST(4)); - quest_manager.popup(SvPV_nolen(ST(0)), SvPV_nolen(ST(1)), popupid, buttons, duration); + quest_manager.popup(SvPV_nolen(ST(0)), SvPV_nolen(ST(1)), popupid, buttons, duration); - XSRETURN_EMPTY; + XSRETURN_EMPTY; } XS(XS__clearspawntimers); XS(XS__clearspawntimers) @@ -2952,11 +2953,11 @@ XS(XS__saylink) { Const_char * RETVAL; char text[250]; char text2[250]; - bool silent = false; + bool silent = false; strcpy(text,(char *)SvPV_nolen(ST(0))); - if(items >= 2) { - silent = ((int)SvIV(ST(1))) == 0 ? false : true; - } + if(items >= 2) { + silent = ((int)SvIV(ST(1))) == 0 ? false : true; + } if (items == 3) strcpy(text2,(char *)SvPV_nolen(ST(2))); else @@ -3000,12 +3001,12 @@ XS(XS__SetRunning) XS(XS__IsRunning); XS(XS__IsRunning) { - dXSARGS; - if (items >= 1) - Perl_croak(aTHX_ "Usage: IsRunning()"); + dXSARGS; + if (items >= 1) + Perl_croak(aTHX_ "Usage: IsRunning()"); - bool RETVAL; - dXSTARG; + bool RETVAL; + dXSTARG; RETVAL = quest_manager.IsRunning(); @@ -3017,14 +3018,14 @@ XS(XS__IsRunning) XS(XS__IsEffectInSpell); XS(XS__IsEffectInSpell) { - dXSARGS; - if (items != 2) - Perl_croak(aTHX_ "Usage: IsEffectInSpell(spell_id, effect_id)"); + dXSARGS; + if (items != 2) + Perl_croak(aTHX_ "Usage: IsEffectInSpell(spell_id, effect_id)"); uint32 spell_id = (uint32)SvUV(ST(0)); uint32 effect_id = (uint32)SvUV(ST(1)); - bool RETVAL; - dXSTARG; + bool RETVAL; + dXSTARG; RETVAL = IsEffectInSpell(spell_id, effect_id); @@ -3036,13 +3037,13 @@ XS(XS__IsEffectInSpell) XS(XS__IsBeneficialSpell); XS(XS__IsBeneficialSpell) { - dXSARGS; - if (items != 1) - Perl_croak(aTHX_ "Usage: IsBeneficialSpell(spell_id)"); + dXSARGS; + if (items != 1) + Perl_croak(aTHX_ "Usage: IsBeneficialSpell(spell_id)"); uint32 spell_id = (uint32)SvUV(ST(0)); - bool RETVAL; - dXSTARG; + bool RETVAL; + dXSTARG; RETVAL = BeneficialSpell(spell_id); @@ -3054,13 +3055,13 @@ XS(XS__IsBeneficialSpell) XS(XS__GetSpellResistType); XS(XS__GetSpellResistType) { - dXSARGS; - if (items != 1) - Perl_croak(aTHX_ "Usage: GetSpellResistType(spell_id)"); + dXSARGS; + if (items != 1) + Perl_croak(aTHX_ "Usage: GetSpellResistType(spell_id)"); uint32 spell_id = (uint32)SvUV(ST(0)); int32 spell_val = 0; - dXSTARG; + dXSTARG; spell_val = GetSpellResistType(spell_id); XSRETURN_UV(spell_val); @@ -3069,13 +3070,13 @@ XS(XS__GetSpellResistType) XS(XS__GetSpellTargetType); XS(XS__GetSpellTargetType) { - dXSARGS; - if (items != 1) - Perl_croak(aTHX_ "Usage: GetSpellTargetType(spell_id)"); + dXSARGS; + if (items != 1) + Perl_croak(aTHX_ "Usage: GetSpellTargetType(spell_id)"); uint32 spell_id = (uint32)SvUV(ST(0)); int32 spell_val = 0; - dXSTARG; + dXSTARG; spell_val = GetSpellTargetType(spell_id); XSRETURN_UV(spell_val); @@ -3108,7 +3109,7 @@ XS(XS__enabletitle) { dXSARGS; if (items != 1) - Perl_croak(aTHX_ "Usage: enabletitle(titleset)"); + Perl_croak(aTHX_ "Usage: enabletitle(titleset)"); int titleset = (int)SvIV(ST(0)); @@ -3122,16 +3123,16 @@ XS(XS__checktitle) { dXSARGS; if (items != 1) - Perl_croak(aTHX_ "Usage: checktitle(titleset)"); + Perl_croak(aTHX_ "Usage: checktitle(titleset)"); bool RETVAL; int titleset = (int)SvIV(ST(0)); RETVAL = quest_manager.checktitle(titleset); - ST(0) = boolSV(RETVAL); - sv_2mortal(ST(0)); - XSRETURN(1); + ST(0) = boolSV(RETVAL); + sv_2mortal(ST(0)); + XSRETURN(1); } XS(XS__removetitle); @@ -3139,7 +3140,7 @@ XS(XS__removetitle) { dXSARGS; if (items != 1) - Perl_croak(aTHX_ "Usage: removetitle(titleset)"); + Perl_croak(aTHX_ "Usage: removetitle(titleset)"); int titleset = (int)SvIV(ST(0)); @@ -3151,9 +3152,9 @@ XS(XS__removetitle) XS(XS__wearchange); XS(XS__wearchange) { - dXSARGS; - if (items != 2) - Perl_croak(aTHX_ "Usage: wearchange(slot, texture)"); + dXSARGS; + if (items != 2) + Perl_croak(aTHX_ "Usage: wearchange(slot, texture)"); uint8 slot = (int)SvUV(ST(0)); uint16 texture = (int)SvUV(ST(1)); @@ -3183,72 +3184,72 @@ XS(XS__voicetell) XS(XS__LearnRecipe); XS(XS__LearnRecipe) { - dXSARGS; - if (items != 1) - Perl_croak(aTHX_ "Usage: LearnRecipe(recipe_id)"); + dXSARGS; + if (items != 1) + Perl_croak(aTHX_ "Usage: LearnRecipe(recipe_id)"); - uint32 recipe_id = (uint32)SvIV(ST(0)); + uint32 recipe_id = (uint32)SvIV(ST(0)); - quest_manager.LearnRecipe(recipe_id); + quest_manager.LearnRecipe(recipe_id); - XSRETURN_EMPTY; + XSRETURN_EMPTY; } XS(XS__SendMail); XS(XS__SendMail) { - dXSARGS; - if (items != 4) - Perl_croak(aTHX_ "Usage: SendMail(to, from, subject, message)"); + dXSARGS; + if (items != 4) + Perl_croak(aTHX_ "Usage: SendMail(to, from, subject, message)"); - char *to = (char *)SvPV_nolen(ST(0)); - char *from = (char *)SvPV_nolen(ST(1)); - char *subject = (char *)SvPV_nolen(ST(2)); - char *message = (char *)SvPV_nolen(ST(3)); + char *to = (char *)SvPV_nolen(ST(0)); + char *from = (char *)SvPV_nolen(ST(1)); + char *subject = (char *)SvPV_nolen(ST(2)); + char *message = (char *)SvPV_nolen(ST(3)); - quest_manager.SendMail(to, from, subject, message); + quest_manager.SendMail(to, from, subject, message); - XSRETURN_EMPTY; + XSRETURN_EMPTY; } XS(XS__GetZoneID); XS(XS__GetZoneID) { - dXSARGS; - if (items != 1) - Perl_croak(aTHX_ "Usage: GetZoneID(zone)"); + dXSARGS; + if (items != 1) + Perl_croak(aTHX_ "Usage: GetZoneID(zone)"); - char *zone = (char *)SvPV_nolen(ST(0)); - int32 id = quest_manager.GetZoneID(zone); - - XSRETURN_IV(id); + char *zone = (char *)SvPV_nolen(ST(0)); + int32 id = quest_manager.GetZoneID(zone); + + XSRETURN_IV(id); } XS(XS__GetZoneLongName); XS(XS__GetZoneLongName) { - dXSARGS; - if (items != 1) - Perl_croak(aTHX_ "Usage: GetZoneLongName(zone)"); - dXSTARG; - char *zone = (char *)SvPV_nolen(ST(0)); - Const_char* RETVAL = quest_manager.GetZoneLongName(zone); - - sv_setpv(TARG, RETVAL); XSprePUSH; PUSHTARG; + dXSARGS; + if (items != 1) + Perl_croak(aTHX_ "Usage: GetZoneLongName(zone)"); + dXSTARG; + char *zone = (char *)SvPV_nolen(ST(0)); + Const_char* RETVAL = quest_manager.GetZoneLongName(zone); + + sv_setpv(TARG, RETVAL); XSprePUSH; PUSHTARG; XSRETURN(1); } XS(XS__GetTimeSeconds); XS(XS__GetTimeSeconds) { - dXSARGS; - if (items != 0) - Perl_croak(aTHX_ "Usage: GetTimeSeconds()"); + dXSARGS; + if (items != 0) + Perl_croak(aTHX_ "Usage: GetTimeSeconds()"); uint32 seconds = 0; - dXSTARG; + dXSTARG; - seconds = Timer::GetTimeSeconds(); + seconds = Timer::GetTimeSeconds(); XSRETURN_UV(seconds); } @@ -3401,7 +3402,7 @@ EXTERN_C XS(boot_quest) newXS(strcpy(buf, "addloot"), XS__addloot, file); newXS(strcpy(buf, "zone"), XS__zone, file); newXS(strcpy(buf, "settimer"), XS__settimer, file); - newXS(strcpy(buf, "settimerMS"), XS__settimerMS, file); + newXS(strcpy(buf, "settimerMS"), XS__settimerMS, file); newXS(strcpy(buf, "stoptimer"), XS__stoptimer, file); newXS(strcpy(buf, "stopalltimers"), XS__stopalltimers, file); newXS(strcpy(buf, "emote"), XS__emote, file); @@ -3573,14 +3574,14 @@ EXTERN_C XS(boot_quest) newXS(strcpy(buf, "removetitle"), XS__removetitle, file); newXS(strcpy(buf, "wearchange"), XS__wearchange, file); newXS(strcpy(buf, "voicetell"), XS__voicetell, file); - newXS(strcpy(buf, "LearnRecipe"), XS__LearnRecipe, file); - newXS(strcpy(buf, "SendMail"), XS__SendMail, file); - newXS(strcpy(buf, "GetZoneID"), XS__GetZoneID, file); - newXS(strcpy(buf, "GetZoneLongName"), XS__GetZoneLongName, file); - newXS(strcpy(buf, "GetTimeSeconds"), XS__GetTimeSeconds, file); + newXS(strcpy(buf, "LearnRecipe"), XS__LearnRecipe, file); + newXS(strcpy(buf, "SendMail"), XS__SendMail, file); + newXS(strcpy(buf, "GetZoneID"), XS__GetZoneID, file); + newXS(strcpy(buf, "GetZoneLongName"), XS__GetZoneLongName, file); + newXS(strcpy(buf, "GetTimeSeconds"), XS__GetTimeSeconds, file); newXS(strcpy(buf, "handleturnin"), XS__handleturnin, file); - newXS(strcpy(buf, "completehandin"), XS__completehandin, file); - newXS(strcpy(buf, "resethandin"), XS__resethandin, file); + newXS(strcpy(buf, "completehandin"), XS__completehandin, file); + newXS(strcpy(buf, "resethandin"), XS__resethandin, file); newXS(strcpy(buf, "clearhandin"), XS__clearhandin, file); newXS(strcpy(buf, "crosszonesignalclientbycharid"), XS__crosszonesignalclientbycharid, file); newXS(strcpy(buf, "crosszonesignalclientbyname"), XS__crosszonesignalclientbyname, file); diff --git a/zone/net.cpp b/zone/net.cpp index 4e762a957..85b9e94cc 100644 --- a/zone/net.cpp +++ b/zone/net.cpp @@ -54,7 +54,6 @@ extern volatile bool ZoneLoaded; #include "../common/Mutex.h" #include "../common/version.h" #include "../common/EQEMuError.h" -#include "ZoneConfig.h" #include "../common/packet_dump_file.h" #include "../common/opcodemgr.h" #include "../common/guilds.h" @@ -67,22 +66,23 @@ extern volatile bool ZoneLoaded; #include "../common/ipc_mutex.h" #include "../common/memory_mapped_file.h" #include "../common/eqemu_exception.h" +#include "../common/spdat.h" #include "masterentity.h" #include "worldserver.h" #include "net.h" -#include "../common/spdat.h" #include "zone.h" #include "command.h" -#include "embparser.h" -#include "perlparser.h" -#include "lua_parser.h" -#include "client_logs.h" -#include "questmgr.h" +#include "ZoneConfig.h" #include "titles.h" #include "guild_mgr.h" #include "tasks.h" + #include "QuestParserCollection.h" +#include "embparser.h" +#include "lua_parser.h" +#include "client_logs.h" +#include "questmgr.h" TimeoutManager timeout_manager; NetConnection net; diff --git a/zone/parser.cpp b/zone/parser.cpp deleted file mode 100644 index 4ff3a0f56..000000000 --- a/zone/parser.cpp +++ /dev/null @@ -1,1694 +0,0 @@ -// Quest Parser written by Wes, Leave this here =P -//Variables causing crash with linked lists (Bad pointers being added to the lists) - Npcs causing crashes with linked lists - - -#include -#include -using namespace std; -#include -using namespace std; -#include -#include -#include - -using namespace std; -#include "../common/debug.h" -#include "entity.h" -#include "masterentity.h" - -#include "worldserver.h" -#include "net.h" -#include "../common/skills.h" -#include "../common/classes.h" -#include "../common/races.h" -#include "zonedb.h" -#include "../common/spdat.h" -#include "../common/packet_functions.h" -#include "spawn2.h" -#include "zone.h" -#include "event_codes.h" -#include -#include "parser.h" -#include "basic_functions.h" -#include "questmgr.h" - - -extern Zone* zone; -extern WorldServer worldserver; -extern EntityList entity_list; - - -#define Parser_DEBUG 1 - -int mindex1 = 0; - -const char * charIn3 = "`~1234567890-=!@#$%^&*_+qwertyuiop[]asdfghjkl'zxcvbnm,./QWERTYUIOP|ASDFGHJKL:ZXCVBNM<>?\"\\"; - -// MYRA - restore missing commands for qst type files & add itemlink -string cmds("if 0|break 1|spawn 6|spawn2 7|settimer 2|stoptimer 1|rebind 4|echo 1|summonitem 1|selfcast 1|zone 1|castspell 2|say 1|emote 1|shout 1|shout2 1|depop 1|exp 1|level 1|safemove 1|rain 1|snow 1|givecash 4|pvp 1|doanim 1|addskill 2|flagcheck 1|me 1|write 2|settarget 2|follow 1|sfollow 1|save 1|setallskill 1|faction 2|settime 2|setguild 2|setsky 1|setstat 2|movepc 5|gmmove 3|movegrp 4|signal 1|attack 1|itemlink 1|setglobal 4|delglobal 1|targlobal 6|setskill 2|setlanguage 2|stop 0|resume 0|start 1|moveto 3|pause 1|addldonpoints 2|"); - - -//end Myra - - -int GetArgs(string command) -{ - string::iterator iterator = cmds.begin(); - string buffer; - string cmd; - string argnum; - while (*iterator) { - if (*iterator == ' ') - { - if (buffer.compare(command)==0) { - cmd = buffer; - buffer=""; - } - } - else { - if (*iterator != '|') - buffer += *iterator; - } - if (*iterator == '|') - { - if (!cmd.empty()) { - int argnums = atoi(buffer.c_str()); - return argnums; - } - else { - buffer=""; - } - } - iterator++; - } - return -1; -} - -int calc(string calc) -{ - string::iterator iterator = calc.begin(); - string buffer; - string integer1; - char op = 0; - int returnvalue = 0; - - while (*iterator) { - char ch = *iterator; - - if(ch >= '0' && ch <= '9') { //If this character is numeric add it to the buffer - buffer += ch; - } - else if(ch == '+' || ch == '-' || ch == '/' || ch == '*') { //otherwise, are we an operator? - int val = atoi(buffer.c_str()); - if (!op) { //if this is the first time through, set returnvalue to what we have so far - returnvalue = val; - } - else { //otherwise we've got returnvalue initialized, perform operation on previous numbers - if (buffer.length() == 0) { //Do we have a value? - printf("Parser::calc() Error in syntax: '%s'.\n", calc.c_str()); - return 0; - } - - //what was the previous op - switch(op) - { - case '+': { - returnvalue += val; - break; - } - case '-': { - returnvalue -= val; - break; - } - case '/': { - if(val == 0)//can't divide by zero - { - printf("Parser::calc() Error, Divide by zero '%s'.\n", calc.c_str()); - return 0; - } - returnvalue /= val; - break; - } - case '*': { - returnvalue *= val; - break; - } - }; - - op = ch; //save current operator and continue parsing - } - buffer=""; //clear buffer now that we're starting on a new number - op = ch; - } - else { - printf("Parser::calc() Error processing '%c'.\n", ch); - return 0; - } - } - return returnvalue; -} - -int Parser::numtok(const char *text, char character) { - int returnvalue=0; - for(; *text != '\0'; text++) { - if(*text == character) returnvalue++; - } - return returnvalue; -} - -string strlwr(string tmp) { - string res; - transform(tmp.begin(), tmp.end(), res.begin(), (int(*)(int))tolower); - return(res); -} - -int strcmp(const string &com, const string &com2) { - return strcmp(com.c_str(),com2.c_str()); -} - -string gettok(const char *text, char character, int index) -{ - string buffer; - int find=0; - for(; *text != '\0'; *text++) - { - if (*text != character) - buffer += *text; - else { - if (find == index) - break; - buffer = ""; - find++; - } - } - return buffer; -} - -void Parser::MakeVars(string text, uint32 npcid) { - string buffer; - string temp; - int pos = numtok(text.c_str(),' ')+1; - for(int i=0;i10 - printf("Buffer: %s, temp: %s\n",buffer.c_str(),temp.c_str()); -#endif -AddVar(temp,buffer); - temp=""; - temp=(string)itoa(i+1) + "-." + (string)itoa(npcid); - AddVar(temp,strstr(text.c_str(),buffer.c_str())); - buffer=""; - } - -} - - -int Parser::CheckAliases(const char * alias, uint32 npcid, Mob* npcmob, Mob* mob) -{ -/* MyListItem * Ptr = AliasList.First; - - while (Ptr) { - if ( (uint32)Ptr->Data->npcid == npcid) { - for (int i=0; i <= Ptr->Data->index; i++) { - if (!strcmp(strlwr(Ptr->Data->name[i]),alias)) { - CommandEx(Ptr->Data->command[i], npcid, npcmob, mob); - return 1; - } - } - } - Ptr = Ptr->Next; - } - return 0;*/ - return 0; -} - - -int Parser::pcalc(const char * string) { - char temp[100]; - memset(temp, 0, sizeof(temp)); - char temp2[100]; - memset(temp2, 0, sizeof(temp2)); - int p =0; - char temp3[100]; - memset(temp3, 0, sizeof(temp3)); - char temp4[100]; - memset(temp4, 0, sizeof(temp4)); - while (strrchr(string,'(')) { - strn0cpy(temp,strrchr(string,'('), sizeof(temp)); - for ( unsigned int i=0;i < strlen(temp); i++ ) { - if (temp[i] != '(' && temp[i] != ')') { - temp2[p] = temp[i]; - p++; - } - else if (temp[i] == ')') { - snprintf(temp3, sizeof(temp3), "(%s)", temp2); -// Replace(string,temp3,itoa(calc(temp2),temp4,10),0); - memset(temp, 0, sizeof(temp)); - memset(temp2, 0, sizeof(temp2)); - memset(temp3, 0, sizeof(temp3)); - memset(temp4, 0, sizeof(temp4)); - p=0; - } - } - } - return calc(string); -} - -void Parser::MakeParms(const char * str, uint32 npcid) { - char temp[100]; - memset(temp, 0, sizeof(temp)); - char temp2[100]; - memset(temp2, 0, sizeof(temp2)); - char temp3[100]; - memset(temp3, 0, sizeof(temp3)); - - int tmpfor = numtok(str, ',')+1; - for ( int i=0; i < tmpfor; i++) { - memset(temp2, 0, sizeof(temp2)); - strn0cpy(temp2, gettok(str, ',', i).c_str(), sizeof(temp2)); - snprintf(temp, sizeof(temp), "param%s.%d", itoa(i+1 ,temp3, 10),npcid); - AddVar(temp, temp2); - } -} - -int Parser::GetItemCount(string itemid, uint32 npcid) -{ - string temp; - int a=0; - for (int i=1;i<5;i++) - { - temp = (string)"item" + (string)itoa(i); - if (!GetVar(temp,npcid).compare(itemid)) - a++; - temp=""; - } - return a; -} - -int Parser::HasQuestFile(uint32 npcid) -{ - int32 qstID = GetNPCqstID(npcid); - int success=1; - if (qstID==-1) - success = LoadScript(npcid, zone->GetShortName()); - if (!success) - return false; - -return true; -} - -void Parser::Event(QuestEventID event, uint32 npcid, const char * data, NPC* npcmob, Mob* mob, uint32 extradata) { - if (npcid == 0) - return; - if(event >= _LargestEventID) - return; - int32 qstID = GetNPCqstID(npcid); - int success=1; - if (qstID==-1) - success = LoadScript(npcid, zone->GetShortName(),mob); - if (!success) - return; - else - qstID = GetNPCqstID(npcid); - -// SCORPIOUS2K - load global variables - - if (npcmob->GetQglobal()) - { - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - MYSQL_RES *result; - MYSQL_ROW row; - char tmpname[65]; - int charid=0; - - if (mob && mob->IsClient()) // some events like waypoint and spawn don't have a player involved - { - charid=mob->CastToClient()->CharacterID(); - } - - else - { - charid=0-npcmob->GetNPCTypeID(); // make char id negative npc id as a fudge - } - - AddVar("charid.g",itoa(charid)); - - database.RunQuery(query, MakeAnyLenString(&query, - "SELECT name,value FROM quest_globals WHERE (npcid=%i || npcid=0) && (charid=%i || charid=0) && (zoneid=%i || zoneid=0) && expdate >= unix_timestamp(now())", - npcmob->GetNPCTypeID(),charid,zone->GetZoneID()), errbuf, &result); - printf("%s\n",query); - printf("%s\n",errbuf); - if (result) - { - printf("Loading global variables for %s\n",npcmob->GetName()); - while ((row = mysql_fetch_row(result))) - { - sprintf(tmpname,"%s.g",row[0]); - AddVar(tmpname, row[1]); - } - mysql_free_result(result); - } - if (query) - { - safe_delete_array(query); - query=0; - } - } - - if (event == EVENT_TIMER) - { - AddVar("timername.g",data); - } - if (event == EVENT_SIGNAL) - { - AddVar("signal.g",data); - } - uint8 fac = 0; - if (mob && mob->IsClient()) { - AddVar("uguild_id.g", itoa(mob->CastToClient()->GuildID())); - AddVar("uguildrank.g", itoa(mob->CastToClient()->GuildRank())); - } - - if (mob && npcmob && mob->IsClient() && npcmob->IsNPC()) { - Client* client = mob->CastToClient(); - NPC* npc = npcmob->CastToNPC(); - - // Need to figure out why one of these casts would fail.. - if (client && npc) { - fac = client->GetFactionLevel(client->GetID(), npcmob->GetID(), client->GetRace(), client->GetClass(), DEITY_AGNOSTIC, npc->GetPrimaryFaction(), npcmob); - } - else if (!client) { - cerr << "WARNING: cast failure on mob->CastToClient()" << endl; - } - else if (!npc) { - cerr << "WARNING: cast failure on npcmob->CastToNPC()" << endl; - } - } - if (mob) { - AddVar("name.g", mob->GetName()); - AddVar("race.g", GetRaceName(mob->GetRace())); - AddVar("class.g", GetEQClassName(mob->GetClass())); - AddVar("ulevel.g", itoa(mob->GetLevel())); - AddVar("userid.g", itoa(mob->GetID())); - } - if (npcmob) - { - AddVar("mname.g",npcmob->GetName()); - } - - if (fac) { - AddVar("faction.g", itoa(fac)); - } - - if (zone) { -// SCORPIOUS2K- added variable zoneid - AddVar("zoneid.g",itoa(zone->GetZoneID())); - AddVar("zoneln.g",zone->GetLongName()); - AddVar("zonesn.g",zone->GetShortName()); - } - - string temp; -#if Parser_DEBUG>10 - printf("Data: %s,Id: %i\n",data,npcid); -#endif - switch (event) { - case EVENT_SAY: { - MakeVars(data, npcid); - npcmob->FaceTarget(mob); - SendCommands("event_say", qstID, npcmob, mob); - break; - } - case EVENT_TIMER: { - SendCommands("event_timer", qstID, npcmob, mob); - break; - } - case EVENT_DEATH: { - SendCommands("event_death", qstID, npcmob, mob); - break; - } - case EVENT_ITEM: { - npcmob->FaceTarget(mob); - SendCommands("event_item", qstID, npcmob, mob); - break; - } - case EVENT_SPAWN: { - SendCommands("event_spawn", qstID, npcmob, mob); - break; - } - case EVENT_ATTACK: { - SendCommands("event_attack", qstID, npcmob, mob); - break; - } - case EVENT_COMBAT: { - SendCommands("event_combat", qstID, npcmob, mob); - break; - } - case EVENT_SLAY: { - SendCommands("event_slay", qstID, npcmob, mob); - break; - } - case EVENT_NPC_SLAY: { - SendCommands("event_npc_slay", qstID, npcmob, mob); - break; - } - case EVENT_WAYPOINT_ARRIVE: { - temp = "wp." + (string)itoa(npcid); - AddVar(temp,data); - SendCommands("event_waypoint_arrive", qstID, npcmob, mob); - break; - } - case EVENT_WAYPOINT_DEPART: { - temp = "wp." + (string)itoa(npcid); - AddVar(temp,data); - SendCommands("event_waypoint_depart", qstID, npcmob, mob); - break; - } - case EVENT_SIGNAL: { - SendCommands("event_signal", qstID, npcmob, mob); - break; - } - case EVENT_AGGRO: { - SendCommands("event_aggro", qstID, npcmob, mob); - break; - } - case EVENT_ENTER: { - SendCommands("event_enter", qstID, npcmob, mob); - break; - } - case EVENT_EXIT: { - SendCommands("event_exit", qstID, npcmob, mob); - break; - } - case EVENT_AGGRO_SAY: { - MakeVars(data, npcid); - SendCommands("event_aggro_say", qstID, npcmob, mob); - break; - } - default: { - // should we do anything here? - break; - } - } - DelChatAndItemVars(npcid); - -} - -Parser::Parser() : DEFAULT_QUEST_PREFIX("default") { - MainList.clear(); - pNPCqstID = new int32[1]; - npcarrayindex=1; -} - -Parser::~Parser() { - MainList.clear(); - varlist.clear(); - AliasList.clear(); - safe_delete_array(pNPCqstID); -} - -bool Parser::LoadAttempted(uint32 iNPCID) { - if (iNPCID > pMaxNPCID) - return false; - - return (bool) (FindNPCQuestID(iNPCID) != 0); -} -uint32 Parser::FindNPCQuestID(int32 npcid){ - for(uint32 i=0;i pMaxNPCID) - return false; - uint32 idx = FindNPCQuestID(iNPCID); - if(idx) - pNPCqstID[idx] = iValue; - else{ - idx=AddNPCQuestID(iNPCID); - pNPCqstID[idx] = iValue; - } - return true; -} - -int32 Parser::GetNPCqstID(uint32 iNPCID) { - if (iNPCID > pMaxNPCID || iNPCID == 0) - return -1; - if(uint32 idx=FindNPCQuestID(iNPCID)) - return pNPCqstID[idx]; - else - return -1; -} - -void Parser::ClearCache() { -#if Parser_DEBUG >= 2 - cout << "Parser::ClearCache" << endl; -#endif - //for (uint32 i=0; iEvent.begin(); - if ( p->npcid == npcid ) { - if(mob && mob->IsClient()) - quest_manager.StartQuest(npcmob, mob->CastToClient()); - else - quest_manager.StartQuest(npcmob, nullptr); - while (listIt2 != p->Event.end()) - { - pp = *listIt2; - if (pp && !strcmp(strlwr(pp->event.c_str()),strlwr(event))) { -#if Parser_DEBUG>10 - printf("PP command: %s\n",pp->command.c_str()); -#endif - ParseCommands(pp->command,0,0,npcid,npcmob,mob); - } - listIt2++; - } - quest_manager.EndQuest(); - return; - } - listIt++; - } -} - -void Parser::scanformat(char *string, const char *format, char arg[10][1024]) -{ - int increment_arglist = 0; - int argnum = 0; - int i = 0; - char lookfor = 0; - - // someone forgot to set string or format - if(!format) - return; - if(!string) - return; - - for(;;) - { - // increment while they're the same (and not nullptr) - while(*format && *string && *format == *string) { - format++; - string++; - } - - // format string is gone - if(!format) - break; - // string is gone while the format string is still there (ERRor) - if(!string) - return; - - // the format string HAS to be equal to ÿ or else things are messed up - if(*format != 'ÿ') - return; - - format++; - lookfor = *format; // copy until we find char after 'y' - format++; - - if(!lookfor) - break; - - // start on a new arg - if(increment_arglist) { - arg[argnum][i] = 0; - argnum++; - } - - increment_arglist = 1; // we found the first crazy y - i = 0; // reset index - - while(*string && *string != lookfor) - arg[argnum][i++] = *string++; - string++; - } - - // final part of the string - if(increment_arglist) { - arg[argnum][i] = 0; - argnum++; - i = 0; - } - - while(*string) - arg[argnum][i++] = *string++; - - arg[argnum][i] = 0; -} - -void Parser::ClearEventsByNPCID(uint32 iNPCID) { - list::iterator iterator = MainList.begin(); - Events* p; - while (iterator != MainList.end()) - { - p = *iterator; - if (p->npcid == iNPCID) { - p->Event.clear(); - return; - } - iterator++; - } -} - -void Parser::ClearAliasesByNPCID(uint32 iNPCID) { -/* MyListItem* Ptr = AliasList.First; - MyListItem* next = 0; - while (Ptr) { - next = Ptr->Next; - if ( (uint32)Ptr->Data->npcid == iNPCID) { - AliasList.DeleteItemAndData(Ptr); - } - Ptr = next; - }*/ -} - -void Parser::ExCommands(string o_command, string parms, int argnums, uint32 npcid, Mob* other, Mob* mob ) -{ - char arglist[10][1024]; - //Work out the argument list, if there needs to be one -#if Parser_DEBUG>10 - printf("Parms: %s\n", parms.c_str()); -#endif - if (argnums > 1) { - string buffer; - string::iterator iterator = parms.begin(); - int quote=0,alist=0,ignore=0; - while (1) { - if (*iterator == '"') { - if (quote) quote--; - else { quote++; if (buffer.empty()) ignore=1; } - } - if (((*iterator != '"' && *iterator != ',' && *iterator != ' ' && *iterator != ')') || quote) && !ignore) { - buffer+=*iterator; - } - if (ignore && *iterator == '"')ignore--; - if ((*iterator == ',' && !quote)) { - strcpy(arglist[alist],buffer.c_str()); - alist++; - buffer=""; - } - if (iterator == parms.end()) - { - strcpy(arglist[alist],buffer.c_str()); - alist++; - break; - } - iterator++; - } - } - else { - string::iterator iterator = parms.begin(); - if (*iterator == '"') - { - int quote=0,ignore=0; //once=0 - string tmp; - while (iterator != parms.end()) - { - if (*iterator == '"') - { - if (quote)quote--; - else quote++; - ignore++; - } - - if (!ignore && (quote || (*iterator != '"'))) - tmp+=*iterator; - - else if (*iterator == '"' && ignore) - ignore--; - iterator++; - } - strcpy(arglist[0],tmp.c_str()); - } - else - strcpy(arglist[0],parms.c_str()); - } -#if Parser_DEBUG>10 - printf("After: %s\n", arglist[0]); -#endif - - char command[256]; - strncpy(command, o_command.c_str(), 255); - command[255] = 0; - char *cptr = command; - while(*cptr != '\0') { - if(*cptr >= 'A' && *cptr <= 'Z') - *cptr = *cptr + ('a' - 'A'); - *cptr++; - } - - - if (!strcmp(command,"write")) { - quest_manager.write(arglist[0], arglist[1]); - } - else if (!strcmp(command,"me")) { -// MYRA - fixed comma bug for me command - quest_manager.me(parms.c_str()); -//end Myra - } - else if (!strcmp(command,"spawn") || !strcmp(command,"spawn2")) - { - - float hdng; - if (!strcmp(command,"spawn")) - { - hdng=mob->CastToClient()->GetHeading(); - } - else - { - hdng=atof(arglist[6]); - } - quest_manager.spawn2(atoi(arglist[0]), atoi(arglist[1]), 0, - atof(arglist[3]), atof(arglist[4]), atof(arglist[5]), hdng); - } - else if (!strcmp(command,"unique_spawn")) - { - - float hdng; - hdng=mob->CastToClient()->GetHeading(); - quest_manager.unique_spawn(atoi(arglist[0]), atoi(arglist[1]), 0, - atof(arglist[3]), atof(arglist[4]), atof(arglist[5]), hdng); - } - else if (!strcmp(command,"echo")) { - quest_manager.echo(atoi(arglist[0]), parms.c_str()); - } - else if (!strcmp(command,"summonitem")) { - quest_manager.summonitem(atoi(arglist[0])); - } - else if (!strcmp(command,"setstat")) { - quest_manager.setstat(atoi(arglist[0]), atoi(arglist[1])); - } - else if (!strcmp(command,"setanim")) { - quest_manager.setanim(atoi(arglist[0]), atoi(arglist[1])); - } - else if (!strcmp(command,"castspell")) { - quest_manager.castspell(atoi(arglist[1]), atoi(arglist[0])); - } - else if (!strcmp(command,"selfcast")) { - quest_manager.selfcast(atoi(arglist[0])); - } - else if (!strcmp(command,"addloot")) {//Cofruben: add an item to the mob. - quest_manager.addloot(atoi(arglist[0]),atoi(arglist[1])); - } - else if (!strcmp(command,"zone")) { - quest_manager.Zone(arglist[0]); - } - else if (!strcmp(command,"settimer")) { - quest_manager.settimer(arglist[0], atoi(arglist[1])); - } - else if (!strcmp(command,"say")) { - quest_manager.say(parms.c_str()); - } - else if (!strcmp(command,"stoptimer")) { - quest_manager.stoptimer(arglist[0]); - } - else if (!strcmp(command,"emote")) { - quest_manager.emote(parms.c_str()); - } - else if (!strcmp(command,"shout2")) { - quest_manager.shout2(parms.c_str()); - } - else if (!strcmp(command,"shout")) { - quest_manager.shout(parms.c_str()); - } - else if (!strcmp(command,"gmsay")) { - quest_manager.shout2(parms.c_str()); - } - else if (!strcmp(command,"depop")) { - quest_manager.depop(atoi(arglist[0])); - } - else if (!strcmp(command,"settarget")) { - quest_manager.settarget(arglist[0], atoi(arglist[1])); - } - else if (!strcmp(command,"follow")) { - quest_manager.follow(atoi(arglist[0]), atoi(arglist[1])); - } - else if (!strcmp(command,"sfollow")) { - quest_manager.sfollow(); - } - else if (!strcmp(command,"changedeity")) { - quest_manager.changedeity(atoi(arglist[0])); - } - else if (!strcmp(command,"exp")) { - quest_manager.exp(atoi(arglist[0])); - } - else if (!strcmp(command,"level")) { - quest_manager.level(atoi(arglist[0])); - } - else if (!strcmp(command,"traindisc")) { - quest_manager.traindisc(atoi(arglist[0])); - } - else if (!strcmp(command,"safemove")) { - quest_manager.safemove(); - } - else if (!strcmp(command,"rain")) { - quest_manager.rain(atoi(arglist[0])); - } - else if (!strcmp(command,"snow")) { - quest_manager.snow(atoi(arglist[0])); - } - else if (!strcmp(command,"surname")) { - quest_manager.surname(arglist[0]); - } - else if (!strcmp(command,"permaclass")) { - quest_manager.permaclass(atoi(arglist[0])); - } - else if (!strcmp(command,"permarace")) { - quest_manager.permarace(atoi(arglist[0])); - } - else if (!strcmp(command,"permagender")) { - quest_manager.permagender(atoi(arglist[0])); - } - else if (!strcmp(command,"scribespells")) { - quest_manager.scribespells(atoi(arglist[0])); - } - else if (!strcmp(command,"traindiscs")) { - quest_manager.traindiscs(atoi(arglist[0])); - } - else if (!strcmp(command,"givecash")) { - quest_manager.givecash(atoi(arglist[0]), atoi(arglist[1]), atoi(arglist[2]), atoi(arglist[3])); - } - else if (!strcmp(command,"pvp")) { - quest_manager.pvp(arglist[0]); - } - else if (!strcmp(command,"movepc")) { - quest_manager.movepc((atoi(arglist[0])),(atof(arglist[1])),(atof(arglist[2])),(atof(arglist[3])),(atof(arglist[4]))); - } - else if (!strcmp(command,"gmmove")) { - quest_manager.gmmove(atof(arglist[0]), atof(arglist[1]), atof(arglist[2])); - } - else if (!strcmp(command,"movegrp")) { - quest_manager.movegrp((atoi(arglist[0])),(atof(arglist[1])),(atof(arglist[2])),(atof(arglist[3]))); - } - else if (!strcmp(command,"doanim")) { - quest_manager.doanim(atoi(arglist[0])); - } - else if (!strcmp(command,"addskill")) { - quest_manager.addskill(atoi(arglist[0]), atoi(arglist[1])); - } - else if (!strcmp(command,"setlanguage")) { - quest_manager.setlanguage(atoi(arglist[0]), atoi(arglist[1])); - } - else if (!strcmp(command,"setskill")) { - quest_manager.setskill(atoi(arglist[0]), atoi(arglist[1])); - } - else if (!strcmp(command,"setallskill")) { - quest_manager.setallskill(atoi(arglist[0])); - } - else if (!strcmp(command,"attack")) { - quest_manager.attack(arglist[0]); - } - else if (!strcmp(command,"save")) { - quest_manager.save(); - } - /*else if (!strcmp(command,"flagcheck")) { - quest_manager.flagcheck(atoi(arglist[0]), atoi(arglist[1])); - }*/ - else if (!strcmp(command,"faction")) { - quest_manager.faction(atoi(arglist[0]), atoi(arglist[1]), atoi(arglist[2])); - } - else if (!strcmp(command,"setsky")) { - quest_manager.setsky(atoi(arglist[0])); - } - else if (!strcmp(command,"setguild")) { - quest_manager.setguild(atoi(arglist[0]), atoi(arglist[1])); - } - else if (!strcmp(command,"settime")) { - quest_manager.settime(atoi(arglist[0]), atoi(arglist[1])); - } - else if (!strcmp(command,"itemlink")) { - quest_manager.itemlink(atoi(arglist[0])); - } - else if (!strcmp(command,"signal")) { - quest_manager.signal(atoi(arglist[0])); - } - else if (!strcmp(command,"setglobal")) { - quest_manager.setglobal(arglist[0], arglist[1], atoi(arglist[2]), arglist[3]); - } - else if (!strcmp(command,"targlobal")) { - quest_manager.targlobal(arglist[0], arglist[1], arglist[2], atoi(arglist[3]), atoi(arglist[4]), atoi(arglist[5])); - } - else if (!strcmp(command,"ding")) { - quest_manager.ding(); - } - else if (!strcmp(command,"delglobal")) { - quest_manager.delglobal(arglist[0]); - } - else if (!strcmp(command,"rebind")) { - quest_manager.rebind((atoi(arglist[0])),(atof(arglist[1])),(atof(arglist[2])),(atof(arglist[3]))); - } - else if (!strcmp(command,"stop")) { - quest_manager.stop(); - } - else if (!strcmp(command,"pause")) { - quest_manager.pause(atoi(arglist[0])); - } - else if (!strcmp(command,"moveto")) { - quest_manager.moveto(atof(arglist[0]), atof(arglist[1]), atof(arglist[2]), atof(arglist[3]), atoi(arglist[4])); - } - else if (!strcmp(command,"pathto")) { - quest_manager.pathto(atof(arglist[0]), atof(arglist[1]), atof(arglist[2])); - } - else if (!strcmp(command,"showpath")) { - quest_manager.showpath(atof(arglist[0]), atof(arglist[1]), atof(arglist[2])); - } - else if (!strcmp(command,"showgrid")) { - quest_manager.showgrid(atoi(arglist[0])); - } - else if (!strcmp(command,"toggle_spawn_event")) { - quest_manager.toggle_spawn_event(atoi(arglist[0]),(atoi(arglist[1])!=0),(atoi(arglist[2])!=0)); - } - else if (!strcmp(command,"spawn_condition")) { - quest_manager.spawn_condition(arglist[0], 0, atoi(arglist[1]), atoi(arglist[2])); - } - else if (!strcmp(command,"resume")) { - quest_manager.resume(); - } - else if (!strcmp(command,"start")) { - quest_manager.start(atoi(arglist[0])); - } - else if (!strcmp(command,"addldonpoints")) { - quest_manager.addldonpoints(atoi(arglist[0]), atoi(arglist[1])); - } - else if (!strcmp(command,"setnexthpevent")) { - quest_manager.setnexthpevent(atoi(arglist[0])); - } - else if (!strcmp(command,"setnextinchpevent")) { - quest_manager.setnextinchpevent(atoi(arglist[0])); - } - else if (!strcmp(command,"clear_zone_flag")) { - quest_manager.clear_zone_flag(atoi(arglist[0])); - } - else if (!strcmp(command,"set_zone_flag")) { - quest_manager.set_zone_flag(atoi(arglist[0])); - } - else if (!strcmp(command,"set_proximity")) { - float v1 = atof(arglist[4]); - float v2 = atof(arglist[5]); - if(v1 == v2) //omitted, or wrong, either way, skip them - quest_manager.set_proximity(atof(arglist[0]), atof(arglist[1]), atof(arglist[2]), atof(arglist[3])); - else - quest_manager.set_proximity(atof(arglist[0]), atof(arglist[1]), atof(arglist[2]), atof(arglist[3]), v1, v2); - } - else if (!strcmp(command,"clear_proximity")) { - quest_manager.clear_proximity(); - } - else if (!strcmp(command,"respawn")) - { - quest_manager.respawn(atoi(arglist[0]), atoi(arglist[1])); - } - else - printf("\nUnknown perl function used:%s",command); - - -} - -int Parser::LoadScript(int npcid, const char * zone, Mob* activater) -{ - SetNPCqstID(npcid, npcid); - ClearEventsByNPCID(npcid); - ClearAliasesByNPCID(npcid); - - //string strnpcid = ("default"); - string strnpcid = (DEFAULT_QUEST_PREFIX); - - if (npcid) - strnpcid = itoa(npcid); - string filename; - filename = "./quests/" + (string)zone + "/" + (string)strnpcid + ".qst"; - string line,buffer,temp; - ifstream file( filename.c_str() ); - if (!file) - { - if (npcid) { - SetNPCqstID(npcid, 0); - LoadScript(0, zone); - } - else - SetNPCqstID(0, -1); - } - - int quote=0,ignore=0,bracket=0,line_num=0,paren=0; - EventList* event1 = new EventList; - Events * NewEventList = new Events; - while (file && !file.eof()) - { - getline(file,line); - string::iterator iterator = line.begin(); - while (*iterator) - { - if (iterator[0] == '/' && iterator[1] == '/') break; - if (!ignore && *iterator == '/' && iterator[1] == '*') { ignore++; iterator++; iterator++; } - if (*iterator == '*' && iterator[1] == '/') { ignore--; iterator++; iterator++; } - if (!ignore && (strchr(charIn,*iterator) || quote || paren)) - buffer+=*iterator; - if (!ignore) - { - if (*iterator == '{') - { - bracket++; - if (bracket == 1) - { - event1 = new EventList; - NewEventList->npcid = npcid; - buffer.replace(buffer.length()-1,buffer.length(),""); - event1->event = buffer; - buffer=""; - } - } - if (*iterator == '}') - { - bracket--; - if (bracket == 0) - { - buffer.replace(buffer.length()-1,buffer.length(),""); - int heh = ParseCommands(buffer,line_num,0,0,0,0,filename); - if (!heh){ - safe_delete(NewEventList); - return 0; - } - event1->command = buffer; - buffer=""; - NewEventList->Event.push_back(event1); - } - if (bracket==-1) - { - if(activater && activater->IsClient()) - activater->CastToClient()->Message(10,"Line: %d,File: %s | error C0006: syntax error : too many ')'s",line_num,filename.c_str()); - return 0; - } - } - if (*iterator == '"')if(quote)quote--;else quote++; - if (*iterator == '(')paren++; - if (*iterator == ')')paren--; - } - iterator++; - } - line_num++; - - } - MainList.push_back(NewEventList); - return 1; -} - - -void Parser::Replace(string& string1, string repstr, string rep, int all) { - while (string1.find(repstr.c_str()) != string::npos) { - string1.replace(string1.find(repstr.c_str()),repstr.length(),rep.c_str()); - if (!all) - break; - } -} - -string Parser::GetVar(string varname, uint32 npcid) -{ - list::iterator iterator = varlist.begin(); - vars * p; - string checkfirst; - string checksecond; - checkfirst = varname + (string)"." + (string)itoa(npcid); - checksecond = varname + (string)".g"; - - while(iterator != varlist.end()) - { - p = *iterator; - if (!strcasecmp(p->name.c_str(), checkfirst.c_str()) || !strcasecmp(p->name.c_str(),checksecond.c_str())) - { -printf("GetVar(%s) = '%s'\n", varname.c_str(), p->value.c_str()); - return p->value; - } - iterator++; - } - checkfirst=""; - checkfirst = "nullptr"; - return checkfirst; -} - -void Parser::DeleteVar(string name) -{ - list::iterator iterator = varlist.begin(); - vars* p; - while(iterator != varlist.end()) - { - p = *iterator; - if (!p->name.compare(name)) - { - varlist.erase(iterator); - return; - } - iterator++; - } -} - -void Parser::DelChatAndItemVars(uint32 npcid) -{ -// MyListItem * Ptr; - string temp; - int i=0; - for (i=0;i<10;i++) - { - temp = (string)itoa(i) + "." + (string)itoa(npcid); - DeleteVar(temp); - temp = (string)itoa(i) + "-." + (string)itoa(npcid); - DeleteVar(temp); - } - for (i=1;i<5;i++) - { - temp = "item"+(string)itoa(i) + "." + (string)itoa(npcid); - DeleteVar(temp); - temp = "item"+(string)itoa(i) + ".stack." + (string)itoa(npcid); - DeleteVar(temp); - } -} - -void Parser::AddVar(string varname, string varval) -{ - list::iterator iterator = varlist.begin(); - vars* p; - while(iterator != varlist.end()) - { - p = *iterator; - if (!p->name.compare(varname)) - { - p->value=""; - p->value = varval; - return; - } - iterator++; - } - vars * newvar = new vars; - newvar->name = varname; - newvar->value = varval; - varlist.push_back(newvar); -} - -void Parser::HandleVars(string varname, string varparms, string& origstring, string format, uint32 npcid, Mob* mob) -{ - string tempvar; - tempvar = GetVar(varname,npcid); - char arglist[10][1024]; - string::iterator iterator = varparms.begin(); - string buffer; - int quote=0; - int alist=0; - while (*iterator) - { - if (*iterator != '"' && *iterator != ',' && *iterator != ' ' || (quote && *iterator != '"')) - buffer+=*iterator; - if (*iterator == '"') - { - if (quote)quote--; - else quote++; - } - if (*iterator == ',' && !quote) - { - strcpy(arglist[alist],buffer.c_str()); - alist++; - buffer=""; - } - iterator++; - } - strcpy(arglist[alist],buffer.c_str()); - if (!strcmp(strlwr((const char*)varname.c_str()),"mid")) { - int pos=0; - int one = atoi(arglist[1]); - int two = atoi(arglist[2]); - string buffer2; - string find = arglist[0]; - string::iterator iterator = find.begin(); - while (*iterator) - { - pos++; - if (pos>=one) - buffer2+=*iterator; - if (pos==two) - break; - iterator++; - } - Replace(origstring,format,buffer2.c_str()); - } - else if (!strcmp(strlwr((const char*)varname.c_str()),"+")) { - string temp; - temp = (string)" "+format+(string)" "; - Replace(origstring, temp, " REPLACETHISSHIT ",1); - } - else if (!strcmp(strlwr((const char*)varname.c_str()),"replace")) { - string temp; - temp = (string)arglist[0]; - Replace(temp, arglist[1], arglist[2],1); - Replace(origstring, format, temp); - } - else if (!strcmp(strlwr(varname.c_str()),"itemcount")) { - string temp; - int o=0; - o = GetItemCount(varparms,npcid); - temp = (string)itoa(o); - Replace(origstring,format,temp,1); - } - else if (!strcmp(strlwr(varname.c_str()),"calc")) { - Replace(origstring,format,itoa(pcalc(varparms.c_str()))); - } - else if (!strcmp(strlwr(varname.c_str()),"status") && mob && mob->IsClient()) { - Replace(origstring,format,itoa(mob->CastToClient()->Admin())); - } - else if (!strcmp(strlwr(varname.c_str()),"hasitem") && mob && mob->IsClient()) { - int has=0; - for (int i=0; i<=30;i++) { - if (mob->CastToClient()->GetItemIDAt(i) == (uint32) atoi(varparms.c_str())) { - Replace(origstring,format,"true"); - has = 1; - break; - } - } - if (!has) - Replace(origstring,format,"false"); - } - else if (!strcmp(strlwr((const char*)varname.c_str()),"read")) { - ifstream file(arglist[0]); - if (file) - { - string line; - int index=0,stop=atoi(arglist[1]); - while (!file.eof()) - { - getline(file,line); - if (index == stop)break; - index++; - } - Replace(origstring,format,line); - } - } - else if (!strcmp(strlwr((const char*)varname.c_str()),"npc_status")) { - Mob * tmp; - if (!atoi(varparms.c_str())) { - tmp = entity_list.GetMob(varparms.c_str()); - } - else { - tmp = entity_list.GetMobByNpcTypeID(atoi(varparms.c_str())); - } - if (tmp && tmp->GetHP() > 0) Replace(origstring,format,"up"); - else Replace(origstring,format,"down"); - } - else if (!strcmp(strlwr((const char*)varname.c_str()),"strlen")) { - Replace(origstring,format,itoa(varparms.length()-1)); - } - else if (!strcmp(strlwr((const char*)varname.c_str()),"chr")) { - char temp[4]; - memset(temp, 0x0, 4); - temp[0] = atoi(varparms.c_str()); - Replace(origstring,format,temp); - } - //used_pawn - random implementation. - else if (!strcmp(strlwr((const char*)varname.c_str()),"random")) { - Replace(origstring,format,itoa(MakeRandomInt(0, varparms[0]-1))); - } - else if (!strcmp(strlwr((const char*)varname.c_str()),"asc")) { - Replace(origstring,format,itoa(varparms[0])); - } - else if (!strcmp(strlwr((const char*)varname.c_str()),"gettok")) { - Replace(origstring,format,gettok(arglist[0],arglist[1][0],atoi(arglist[2]))); - } - else { - Replace(origstring,format,tempvar); - } - gClient = 0; -} - -void Parser::ParseVars(string& text, uint32 npcid, Mob* mob) -{ - if (text.find("$") == string::npos && text.find("%") == string::npos) - return; - string buffer2; - string fname; - string parms; - while (text.find("%") != string::npos) - { - string temp; - temp = (string)text.substr(text.find("%")).c_str(); - string::iterator iterator = temp.begin(); - string buffer; - while (*iterator) - { - if (!strrchr(notin,*iterator)) - buffer+=*iterator; - else - { - HandleVars(buffer,0,text,buffer,npcid,mob); - Replace(text,buffer,"testing",0); - break; - } - iterator++; - } - } - while (text.find("$") != string::npos) - { - string temp; - temp = (string)text.substr(text.rfind("$")).c_str(); - string::iterator iterator = temp.begin(); - int paren=0; - int fin=0; - string buffer; - while (iterator != temp.end()) - { - if (!strrchr(notin,*iterator) || paren) - { - if (*iterator != '(' && *iterator != ')') - buffer+=*iterator; - } - else - { - buffer.replace(0,1,"",0); - HandleVars(buffer,"",text,buffer2,npcid,mob); - buffer=""; - buffer2=""; - break; - } - buffer2+=*iterator; - if (*iterator == '(') - { - paren++; - if (paren == 1) - { - fname = buffer; - buffer=""; - } - } - if (*iterator == ')') - { - paren--; - if (paren == 0) - { - parms = buffer; - fname.replace(0,1,"",0); - HandleVars(fname,parms,text,buffer2,npcid,mob); - buffer=""; - buffer2=""; - parms=""; - fname=""; - fin=1; - break; - } - } - iterator++; - } - } -} - -/* -char * fixstring(char * string) -{ - char tmp[255]; - memset(tmp,0x0,255); - - static char tmp2[255]; - memset(tmp2,0x0,255); - int quote=0; - int o=0; - strcpy(tmp,string); - uint32 len = strlen(tmp); - for (uint32 i=0;i10 - printf("compare1: %s,sign: %s, compare2: %s\n",compare1.c_str(),sign.c_str(),compare2.c_str()); -#endif - if (!strcmp(sign.c_str(),"==")) { - if (strcmp(strlwr((const char*)compare1.c_str()),strlwr((const char*)compare2.c_str()))) - return 0; - } - else if (!strcmp(sign.c_str(),"!=")) { - if (!strcmp(strlwr((const char*)compare1.c_str()),strlwr((const char*)compare2.c_str()))) - return 0; - } - else if (!strcmp(sign.c_str(),"=~")) { - if (!strstr(strlwr(compare1.c_str()).c_str(),strlwr(compare2.c_str()).c_str())) - return 0; - } - else if (!strcmp(sign.c_str(),"!~")) { - if (strstr(strlwr(compare1.c_str()).c_str(),strlwr(compare2.c_str()).c_str())) - return 0; - } - else if (!strcmp(sign.c_str(),"<")) { - if (atoi(compare1.c_str()) > atoi(compare2.c_str()) || atoi(compare1.c_str()) == atoi(compare2.c_str())) - return 0; - } - else if (!strcmp(sign.c_str(),">")) { - if (atoi(compare1.c_str()) < atoi(compare2.c_str()) || atoi(compare1.c_str()) == atoi(compare2.c_str())) - return 0; - } - else if (!strcmp(sign.c_str(),"<=")) { - if (atoi(compare1.c_str()) > atoi(compare2.c_str()) || atoi(compare1.c_str()) != atoi(compare2.c_str())) - return 0; - } - else if (!strcmp(sign.c_str(),">=")) { - if (atoi(compare1.c_str()) < atoi(compare2.c_str()) || atoi(compare1.c_str()) != atoi(compare2.c_str())) - return 0; - } - return 1; -} - -int Parser::ParseIf(string text) -{ - string::iterator iterator = text.begin(); - string com1,com2,sign,next,buffer; - while (*iterator) - { - if (!strchr(notin,*iterator)) - buffer+=*iterator; - if (*iterator == '=' || *iterator == '!' || *iterator == '~') - { - sign+=*iterator; - if (sign.length() == 1) - { - com1 = buffer; - buffer=""; - next=""; - } - } - if ((*iterator == '<' || *iterator == '>') && iterator[1] != '=') - { - sign+=*iterator; - if (sign.length() == 1) - { - com1 = buffer; - buffer=""; - next=""; - } - iterator++; - } - if (*iterator == '&' || *iterator == '|') - { - next+=*iterator; - if (next.length() == 1) - { - com2 = buffer; - buffer=""; - } - if (next.length() == 2) - { - if (!DoCompare(com1,sign,com2) && strcmp(next.c_str(),"||")) - return 0; - com1=""; - sign=""; - com2=""; - } - } - iterator++; - if (iterator == text.end()) { - com2 = buffer; - //com2.replace(0,1,""); - buffer=""; - if (!DoCompare(com1,sign,com2)) - return 0; - } - } - return 1; -} - -int Parser::ParseCommands(string text, int line, int justcheck, uint32 npcid, Mob* other, Mob* mob, std::string filename) -{ - string buffer,command,parms,temp,temp2; - temp2 = text; - ParseVars(temp2,npcid,mob); - int bracket=0,paren=0,lastif=0,last_finished=0,quote=0,escape=0,ignore=0,argnums=0,argit=1; - string::iterator iterator = temp2.begin(); - while (iterator != temp2.end()) - { - if (*iterator == '\\' && !escape) { - escape++; - } - //"`~1234567890-=!@#$%^&*_+qwertyuiop[]asdfghjkl'zxcvbnm,./QWERTYUIOP|ASDFGHJKL:ZXCVBNM<>?\"\\" - if (!ignore && *iterator != ')' && (strchr(charIn3,*iterator) || quote || escape || paren)) - { - buffer+=*iterator; - } - if (*iterator == '"' && !escape && !ignore) - if (quote)quote--; - else quote++; - - if (*iterator == ',' && !ignore && !quote && !escape && paren) - argit++; - - if (*iterator == '(' && !ignore && !quote && !escape) - { - paren++; - if (paren == 1) - { - if (last_finished) - { - if(mob && mob->IsClient()) - mob->CastToClient()->Message(10,"Line: %d,File: %s | error C0008: syntax error : missing ';' before function '%s'", line, filename.c_str(), command.c_str()); - return 0; - } - command = buffer; - if(!strcmp(strlwr(command.c_str()),"break") && other) - return 1; - buffer=""; - argnums = GetArgs(command); -#if Parser_DEBUG>10 - if(mob && mob->IsClient()) - mob->CastToClient()->Message(10,"Command: %s, Num Args: %i\n",command.c_str(),argnums); -#endif - if (argnums == -1) - { - if(mob && mob->IsClient()) - mob->CastToClient()->Message(10,"Line: %d,File: %s | error C0007: '%s' : Unknown function", line, filename.c_str(), command.c_str()); - return 0; - } - } - } - else if (*iterator == ')' && !ignore && !quote && !escape) - { - paren--; - if (paren == 0) - { - lastif=0,quote=0,escape=0,ignore=0; - parms = buffer; - buffer=""; - if (!strcmp(strlwr((const char*)command.c_str()),"if")) { last_finished=0; } - else { - last_finished=1; - } - } - if (paren<0) - { - if(mob && mob->IsClient()) - mob->CastToClient()->Message(10,"Line: %d,File: %s | error C0006: syntax error : too many ')'s",line,filename.c_str() ); - return 0; - } - } - else if (*iterator == '{' && !escape) - { - bracket++; - if (!ignore) { - if (!strcmp(strlwr((const char*)command.c_str()),"if")) { - lastif = ParseIf(parms); -#if Parser_DEBUG>10 - if(mob && mob->IsClient()) - mob->CastToClient()->Message(10,"Parms: %s\n",parms.c_str()); -#endif - if (!lastif) ignore=1; - else ignore=0; - } - } - } - else if (*iterator == '}' && !escape) - { - bracket--; - if (last_finished) - { - if(mob && mob->IsClient()) - mob->CastToClient()->Message(10,"Line: %d,File: %s | error C0008: syntax error : missing ';' before '}'", line,filename.c_str() ); - return 0; - } - if (bracket<0) - { - if(mob && mob->IsClient()) - mob->CastToClient()->Message(10,"Line: %d,File: %s | error C0006: syntax error : too many '}'s",line, filename.c_str() ); - return 0; - } - if (bracket == 0) - { - if (!ignore) lastif=1; - else lastif=0; - lastif=0,last_finished=0,quote=0,escape=0,ignore=0,argnums=0,argit=1; - } - } - else if (*iterator == ';' && !escape && !ignore && !quote) - { - if (last_finished) - { - last_finished=0; - if (argnums != 1 && argnums!=argit) - { - if(mob && mob->IsClient()) - mob->CastToClient()->Message(10,"Line: %d, File: %s | error C0001: '%s' : function does not take %d parameter(s)", line, filename.c_str(), command.c_str(), argit); - return 0; - } - if (!justcheck) - ExCommands((const char*)command.c_str(),(const char*)parms.c_str(),argnums, npcid, other, mob); - argit=1; - } - else { - if(mob && mob->IsClient()) - mob->CastToClient()->Message(10,"Line: %d,File: %s | error C0002: '%s' :syntax error : '(' %d '('s still not closed.", line, filename.c_str(), command.c_str(), paren); - } - } - if (escape) escape--; - iterator++; - } - if (last_finished) - { - if(mob && mob->IsClient()) - mob->CastToClient()->Message(10,"Line: %d,File: %s | error C0008: syntax error : missing ';' before '}'", line, filename.c_str() ); - return 0; - } - return 1; -} - -void Parser::ReloadQuests(bool with_timers) { - ClearCache(); -} - diff --git a/zone/parser.h b/zone/parser.h deleted file mode 100644 index 3e2cb539f..000000000 --- a/zone/parser.h +++ /dev/null @@ -1,124 +0,0 @@ -#ifndef PARSER_H -#define PARSER_H - -#define Parser_MaxVars 1024 -#include "../common/timer.h" -#include -#include -#include "event_codes.h" -#include "QuestInterface.h" - - -struct EventList { - std::string event; - std::string command; -}; - -struct Events { -uint32 npcid; -std::list Event; -}; - -struct Alias { - int index; - uint32 npcid; - char name[100][100]; - char command[100][1024]; -}; - -struct vars { - std::string name; - std::string value; -}; - -struct command_list { - char command_name[100]; - int param_amount[17]; -}; - - -class Parser : public QuestInterface -{ -public: - Parser(); - virtual ~Parser(); - int mindex; - const std::string DEFAULT_QUEST_PREFIX; - - typedef list::iterator iter_events; - typedef list::iterator iter_eventlist; - std::list MainList; - std::list varlist; - std::list AliasList; - uint32 npcarrayindex; - - uint32 AddNPCQuestID(uint32 npcid); - uint32 FindNPCQuestID(int32 npcid); - int CheckAliases(const char * alias, uint32 npcid, Mob* npcmob, Mob* mob); - void ClearAliasesByNPCID(uint32 iNPCID); - void ClearCache(); - void ClearEventsByNPCID(uint32 iNPCID); - - void DelChatAndItemVars(uint32 npcid); - void DeleteVar(std::string name); - - void ExCommands(std::string command, std::string parms, int argnums, uint32 npcid, Mob* other, Mob* mob ); - - void GetCommandName(char * command1, char * arg); - int GetFreeID(); - int GetItemCount(std::string itemid, uint32 npcid); - int32 GetNPCqstID(uint32 iNPCID); - std::string GetVar(std::string varname, uint32 npcid); - - void HandleVars(std::string varname, std::string varparms, std::string& origstring, std::string format, uint32 npcid, Mob* mob); - - bool LoadAttempted(uint32 iNPCID); - void LoadCommands(const char * filename); - virtual int LoadScript(int npcid, const char * zone, Mob* activater=0); - - void MakeParms(const char * string, uint32 npcid); - void MakeVars(std::string text, uint32 npcid); - - int numtok(const char *text, char character); - - int ParseCommands(std::string text, int line, int justcheck, uint32 npcid, Mob* other, Mob* mob, std::string filename=string("none")); - int ParseIf(std::string text); - int pcalc(const char * string); - void ParseVars(std::string& text, uint32 npcid, Mob* mob); - - void Replace(std::string& string1, std::string repstr, std::string rep, int all=0); - - void scanformat(char *string, const char *format, char arg[10][1024]); - bool SetNPCqstID(uint32 iNPCID, int32 iValue); - char * strrstr(char* string, const char * sub); - virtual void SendCommands(const char * event, uint32 npcid, NPC* npcmob, Mob* mob); - - int HasQuestFile(uint32 npcid); - - //interface stuff - virtual void EventNPC(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) { return HasQuestFile(npcid) != 0; } - virtual bool PlayerHasQuestSub(const char *subname) { return true; } - virtual bool GlobalPlayerHasQuestSub(const char *subname) { return true; } - virtual bool SpellHasQuestSub(uint32 spell_id, const char *subname) { return true; } - virtual bool ItemHasQuestSub(ItemInst *itm, const char *subname) { return true; } - virtual void AddVar(std::string varname, std::string varval); - virtual void ReloadQuests(bool with_timers = false); - virtual uint32 GetIdentifier() { return 0x04629fff; } - -private: - //void Event(int event, uint32 npcid, const char * data, Mob* npcmob, Mob* mob); - //changed - Eglin. more reasonable (IMHO) than changing every single referance to the global pointer. - //that's what you get for using globals! :) - virtual void Event(QuestEventID event, uint32 npcid, const char * data, NPC* npcmob, Mob* mob, uint32 extradata = 0); - - uint32 pMaxNPCID; - int32* pNPCqstID; -}; - -#endif - diff --git a/zone/perlparser.h b/zone/perlparser.h deleted file mode 100644 index 8b1378917..000000000 --- a/zone/perlparser.h +++ /dev/null @@ -1 +0,0 @@ -