diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-06-10 03:15:20 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-06-10 03:15:20 +0000 |
| commit | 60ec161d7df28c3147e86f7344a9a548b7682aee (patch) | |
| tree | 361e36b4275f35967d8fc7208005018796ff7af7 | |
| parent | bfd8c384cec5f75c381cbf07b7982afc8be03fb5 (diff) | |
| download | sigen-60ec161d7df28c3147e86f7344a9a548b7682aee.tar.gz sigen-60ec161d7df28c3147e86f7344a9a548b7682aee.tar.xz sigen-60ec161d7df28c3147e86f7344a9a548b7682aee.zip | |
[FIX] Added some stuff to Pokebattle
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@205 6ecfd1a5-f3ed-3746-8530-beee90d26b22
| -rw-r--r-- | pokebattle/Arena.cpp | 51 | ||||
| -rw-r--r-- | pokebattle/Arena.h | 28 | ||||
| -rw-r--r-- | pokebattle/Bot.h | 15 | ||||
| -rw-r--r-- | pokebattle/Ghost.h | 2 | ||||
| -rw-r--r-- | pokebattle/GhostBot.h | 6 | ||||
| -rw-r--r-- | pokebattle/Player.h | 42 | ||||
| -rw-r--r-- | pokebattle/Team.h | 13 | ||||
| -rw-r--r-- | pokebattle/pokebattle.pro | 2 |
8 files changed, 143 insertions, 16 deletions
diff --git a/pokebattle/Arena.cpp b/pokebattle/Arena.cpp index eda64717..7c7cf776 100644 --- a/pokebattle/Arena.cpp +++ b/pokebattle/Arena.cpp @@ -18,8 +18,57 @@ // Header include #include "Arena.h" +// Pokemod includes +#include "../pokemod/Script.h" + +// KDE includes +#include <kross/core/action.h> +#include <kross/core/childreninterface.h> + +Pokebattle::Arena::Arena* Pokebattle::Arena::m_arena = 0; +Kross::ActionCollection* Pokebattle::Arena::m_actions = 0; + +Pokebattle::Arena::~Arena() +{ +} + +void Pokebattle::Arena::setTeams(QList<Team*> teams) +{ + m_teams = teams; +} + void Pokebattle::Arena::cleanUp() { delete m_arena; - m_arena = 0; + m_arena = NULL; + m_teams.clear(); +} + +void Pokebattle::Arena::registerScript(const QString& name, const Pokemod::Script& script) +{ + if (!m_actions) + remakeCollection(); + 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::unregisterScript(const QString& name) +{ + m_actions->removeAction(name); +} + +void Pokebattle::Arena::remakeCollection() +{ + if (!m_actions) + m_actions = new Kross::ActionCollection("arena", Kross::Manager::self().actionCollection()); +} + +void Pokebattle::Arena::unregisterAllScripts() +{ + delete m_actions; + m_actions = 0; } diff --git a/pokebattle/Arena.h b/pokebattle/Arena.h index 40f9e738..0842cd3f 100644 --- a/pokebattle/Arena.h +++ b/pokebattle/Arena.h @@ -18,16 +18,25 @@ #ifndef __POKEBATTLE_ARENA__ #define __POKEBATTLE_ARENA__ -// Battle includes +// Pokebattle includes #include "Team.h" // Qt includes #include <QList> #include <QObject> +// KDE includes +#include <kross/core/actioncollection.h> +#include <kross/core/manager.h> + +// Forward declarations +namespace Pokemod +{ +class Script; +} + namespace Pokebattle { -// Forward declarations class TeamMember; class Arena : public QObject @@ -40,6 +49,7 @@ class Arena : public QObject if (!m_arena) m_arena = new Arena; m_arena->connect(m_arena, SIGNAL(battleEnd()), SLOT(cleanUp())); + m_arena->connect(m_arena, SIGNAL(battleEnd()), SLOT(unregisterAllScripts())); return m_arena; } @@ -53,10 +63,8 @@ class Arena : public QObject void sentOut(TeamMember* teamMember); void actionChosen(TeamMember* teamMember); - void itemExecuted(TeamMember* teamMember); - void attackExecuted(TeamMember* teamMember); - void itemUsed(TeamMember* teamMember); - void attackUsed(TeamMember* teamMember); + void actionExecuted(TeamMember* teamMember); + void actionUsed(TeamMember* teamMember); void attackMissed(TeamMember* teamMember); void attackHit(TeamMember* teamMember); void faint(TeamMember* teamMember); @@ -67,7 +75,12 @@ class Arena : public QObject void battleEnd(); public slots: + void registerScript(const QString& name, const Pokemod::Script& script); + void unregisterScript(const QString& name); protected slots: + void remakeCollection(); + void unregisterAllScripts(); + void cleanUp(); protected: Arena(); @@ -75,7 +88,8 @@ class Arena : public QObject ~Arena(); private: static Arena* m_arena; - QList<Team*> m_teams; + static QList<Team*> m_teams; + static Kross::ActionCollection* m_actions; }; } diff --git a/pokebattle/Bot.h b/pokebattle/Bot.h index 8fb77eef..e9510af4 100644 --- a/pokebattle/Bot.h +++ b/pokebattle/Bot.h @@ -18,19 +18,26 @@ #ifndef __POKEBATTLE_BOT__ #define __POKEBATTLE_BOT__ -// Battle includes -#include "Arena.h" -#include "Team.h" +// Pokebattle includes +#include "Player.h" // Standard library includes #include <climits> namespace Pokebattle { -class Bot : public Team +// Forward declarations +class Arena; + +class Bot : public Player { Q_OBJECT + public: + signals: + public slots: + protected slots: + protected: private: long alphaBeta(const Arena& arena, const int trainerClass, const long alpha = LONG_MIN, const long beta = LONG_MAX); }; diff --git a/pokebattle/Ghost.h b/pokebattle/Ghost.h index bcf138b2..67018680 100644 --- a/pokebattle/Ghost.h +++ b/pokebattle/Ghost.h @@ -18,7 +18,7 @@ #ifndef __POKEBATTLE_GHOST__ #define __POKEBATTLE_GHOST__ -// Battle includes +// Pokebattle includes #include "TeamMember.h" namespace Pokebattle diff --git a/pokebattle/GhostBot.h b/pokebattle/GhostBot.h index 808824ca..3e4ef5f1 100644 --- a/pokebattle/GhostBot.h +++ b/pokebattle/GhostBot.h @@ -18,12 +18,12 @@ #ifndef __POKEBATTLE_GHOSTBOT__ #define __POKEBATTLE_GHOSTBOT__ -// Battle includes -#include "Team.h" +// Pokebattle includes +#include "Player.h" namespace Pokebattle { -class GhostBot : public Team +class GhostBot : public Player { Q_OBJECT }; diff --git a/pokebattle/Player.h b/pokebattle/Player.h new file mode 100644 index 00000000..e53732b6 --- /dev/null +++ b/pokebattle/Player.h @@ -0,0 +1,42 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 3 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, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEBATTLE_PLAYER__ +#define __POKEBATTLE_PLAYER__ + +// Qt includes +#include <QObject> + +namespace Pokebattle +{ +// Forward declarations +class Team; + +class Player : public QObject +{ + Q_OBJECT + + public: + signals: + public slots: + protected slots: + protected: + private: +}; +} + +#endif diff --git a/pokebattle/Team.h b/pokebattle/Team.h index b30f55d0..8986a9ca 100644 --- a/pokebattle/Team.h +++ b/pokebattle/Team.h @@ -23,9 +23,22 @@ namespace Pokebattle { +// Forward declarations +class TeamMember; + class Team : public QObject { Q_OBJECT + + public: + signals: + void teamKnockedOut(); + public slots: + protected slots: + void memberFainted(TeamMember* member); + protected: + private: + QList<TeamMember*> m_members; }; } diff --git a/pokebattle/pokebattle.pro b/pokebattle/pokebattle.pro index 6ec59e23..55771a2f 100644 --- a/pokebattle/pokebattle.pro +++ b/pokebattle/pokebattle.pro @@ -13,6 +13,7 @@ CONFIG += qt \ dll include(../install.pri) +include(../kde4.pri) SOURCES += Arena.cpp \ Ghost.cpp \ @@ -22,6 +23,7 @@ HEADERS += Arena.h \ Bot.h \ GhostBot.h \ Ghost.h \ + Player.h \ Team.h \ TeamMember.h |
