diff options
Diffstat (limited to 'pokebattle/Arena.cpp')
| -rw-r--r-- | pokebattle/Arena.cpp | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/pokebattle/Arena.cpp b/pokebattle/Arena.cpp index a2ece8fa..68d3d6ed 100644 --- a/pokebattle/Arena.cpp +++ b/pokebattle/Arena.cpp @@ -26,36 +26,59 @@ // KDE includes #include <kross/core/action.h> -#include <kross/core/childreninterface.h> +#include <kross/core/manager.h> -int Pokebattle::Arena::m_totalCount = 0; +QSet<int> Pokebattle::Arena::m_arenaIds; Pokebattle::Arena::Arena(QList<Player*> players) : - m_count(m_totalCount), + m_id(0), m_players(players), - m_actions(new Kross::ActionCollection(QString("arena-%1").arg(m_count), Kross::Manager::self().actionCollection())) + m_actions(NULL) { connect(this, SIGNAL(battleEnd()), SLOT(cleanUp())); connect(this, SIGNAL(battleEnd()), SLOT(unregisterAllScripts())); - ++m_totalCount; + for (; (m_id < m_arenaIds.size()) && m_arenaIds.contains(m_id); ++m_id) + ; + m_arenaIds.insert(m_id); + unregisterAllScripts(); +// foreach (Player* player, m_players) +// { +// QList<TeamMember*> leadMembers(player->active()); +// foreach (TeamMember* teamMember, leadMembers) +// { +// // TODO: load abilities +// // TODO: connect signals for retreating and fainting to removing abilities +// } +// } } Pokebattle::Arena::~Arena() { - --m_totalCount; + m_arenaIds.remove(m_id); delete m_actions; } +Kross::Action* Pokebattle::Arena::script(const QString& name) +{ + return m_actions->action(name); +} + void Pokebattle::Arena::registerScript(const QString& name, const Pokemod::Script& script) { Kross::Action* action = new Kross::Action(m_actions, name); action->setInterpreter(script.interpreter()); action->setCode(script.script().toUtf8()); action->addObject(this, "arena", Kross::ChildrenInterface::AutoConnectSignals); - action->trigger(); m_actions->addAction(action); } +void Pokebattle::Arena::triggerScript(const QString& name) +{ + Kross::Action* action = m_actions->action(name); + if (action) + action->trigger(); +} + void Pokebattle::Arena::unregisterScript(const QString& name) { m_actions->removeAction(name); @@ -64,7 +87,7 @@ void Pokebattle::Arena::unregisterScript(const QString& name) void Pokebattle::Arena::unregisterAllScripts() { delete m_actions; - m_actions = new Kross::ActionCollection(QString("arena-%1").arg(m_count), Kross::Manager::self().actionCollection()); + m_actions = new Kross::ActionCollection(QString("arena-%1").arg(m_id), Kross::Manager::self().actionCollection()); } void Pokebattle::Arena::cleanUp() |
