Menu

[r2]: / scriptmanager.cpp  Maximize  Restore  History

Download this file

150 lines (126 with data), 4.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
//////////////////////////////////////////////////////////////////////
// OpenTibia - an opensource roleplaying game
//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
// 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; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; 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 "otpch.h"
#include "scriptmanager.h"
#include "luascript.h"
#include "configmanager.h"
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
#include "actions.h"
#include "talkaction.h"
#include "spells.h"
#include "movement.h"
#include "weapons.h"
#include "globalevent.h"
#include "creatureevent.h"
Actions* g_actions = NULL;
TalkActions* g_talkactions = NULL;
Spells* g_spells = NULL;
MoveEvents* g_moveEvents = NULL;
Weapons* g_weapons = NULL;
CreatureEvents* g_creatureEvents = NULL;
GlobalEvents* g_globalEvents = NULL;
extern ConfigManager g_config;
extern void ErrorMessage(const char* message) ;
ScriptingManager* ScriptingManager::_instance = NULL;
ScriptingManager::ScriptingManager()
{
//
}
ScriptingManager::~ScriptingManager()
{
//
}
ScriptingManager* ScriptingManager::getInstance()
{
if(_instance == NULL){
_instance = new ScriptingManager();
}
return _instance;
}
bool ScriptingManager::loadScriptSystems()
{
std::cout << ":: Loading Script Systems" << std::endl;
std::string datadir = g_config.getString(ConfigManager::DATA_DIRECTORY);
//load weapons data
std::cout << ":: Loading Weapons ...";
g_weapons = new Weapons();
if(!g_weapons->loadFromXml(datadir)){
ErrorMessage("Unable to load Weapons!");
return false;
}
g_weapons->loadDefaults();
std::cout << "[done]" << std::endl;
//load spells data
std::cout << ":: Loading Spells ...";
g_spells = new Spells();
if(!g_spells->loadFromXml(datadir)){
ErrorMessage("Unable to load Spells!");
return false;
}
std::cout << "[done]" << std::endl;
/*
std::cout << ":: Loading Fields ...";
Items::loadFieldsFromXml(datadir);
std::cout << "[done]" << std::endl;
*/
//load actions data
std::cout << ":: Loading Actions ...";
g_actions = new Actions();
if(!g_actions->loadFromXml(datadir)){
ErrorMessage("Unable to load Actions!");
return false;
}
std::cout << "[done]" << std::endl;
//load talkactions data
std::cout << ":: Loading Talkactions ...";
g_talkactions = new TalkActions();
if(!g_talkactions->loadFromXml(datadir)){
ErrorMessage("Unable to load Talkactions!");
return false;
}
std::cout << "[done]" << std::endl;
//load moveEvents
std::cout << ":: Loading MoveEvents ...";
g_moveEvents = new MoveEvents();
if(!g_moveEvents->loadFromXml(datadir)){
ErrorMessage("Unable to load MoveEvents!");
return false;
}
std::cout << "[done]" << std::endl;
//load creature events
std::cout << ":: Loading CreatureEvents ...";
g_creatureEvents = new CreatureEvents();
if(!g_creatureEvents->loadFromXml(datadir)){
ErrorMessage("Unable to load CreatureEvents!");
return false;
}
std::cout << "[done]" << std::endl;
// global
std::cout << ":: Loading GlobalEvents ...";
g_globalEvents = new GlobalEvents();
if(!g_globalEvents->loadFromXml(datadir))
{
std::cout << "> ERROR: Unable to load GlobalEvents!" << std::endl;
return false;
}
std::cout << "[done]" << std::endl;
return true;
}