diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2009-04-09 16:03:28 -0400 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2009-04-09 16:03:28 -0400 |
| commit | cb839e58e268c125fd3e6dd704370b4d0bde3cf8 (patch) | |
| tree | 83bf15737450bf2c5a00ae392092d77c347321db /plugins | |
| parent | ce9e1a24c5ae67abbee16d02a43e42903ad644af (diff) | |
| download | sigen-cb839e58e268c125fd3e6dd704370b4d0bde3cf8.tar.gz sigen-cb839e58e268c125fd3e6dd704370b4d0bde3cf8.tar.xz sigen-cb839e58e268c125fd3e6dd704370b4d0bde3cf8.zip | |
Move the plugins out of sigencore
Diffstat (limited to 'plugins')
19 files changed, 1173 insertions, 0 deletions
diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt new file mode 100644 index 00000000..7c2279d0 --- /dev/null +++ b/plugins/CMakeLists.txt @@ -0,0 +1,7 @@ +project(plugins) + +# Arena plugins +add_subdirectory(sigen_arena_standard) + +# Canvas plugins +add_subdirectory(sigen_canvas_standard) diff --git a/plugins/sigen_arena_standard/CMakeLists.txt b/plugins/sigen_arena_standard/CMakeLists.txt new file mode 100644 index 00000000..de972424 --- /dev/null +++ b/plugins/sigen_arena_standard/CMakeLists.txt @@ -0,0 +1,40 @@ +project(sigenarenas) + +set(sigenarenas_SRCS + SigenArenas.cpp + atb/ActionMap.cpp + atb/ATBArena.cpp + atb/ATBTimer.cpp + standard/TurnArena.cpp +) +set(sigenarenas_SERVICES + sigen_arenas.desktop +) + +kde4_add_plugin(arena_sigen + ${sigenarenas_SRCS} +) +target_link_libraries(arena_sigen + ${QT_QTCORE_LIBRARY} + ${KDE4_KDEUI_LIBRARY} + ${KDE4_KROSSCORE_LIBRARY} + sigencoreplugins +) + +install( + TARGETS + arena_sigen + DESTINATION + ${PLUGIN_INSTALL_DIR} + COMPONENT + plugins +) + +install( + FILES + ${sigenarenas_SERVICES} + DESTINATION + ${SERVICES_INSTALL_DIR} + COMPONENT + plugins +) diff --git a/plugins/sigen_arena_standard/SigenArenas.cpp b/plugins/sigen_arena_standard/SigenArenas.cpp new file mode 100644 index 00000000..faf3f848 --- /dev/null +++ b/plugins/sigen_arena_standard/SigenArenas.cpp @@ -0,0 +1,92 @@ +/* + * Copyright 2009 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/>. + */ + +// Header include +#include "SigenArenas.h" + +// Arena includes +#include "standard/TurnArena.h" +#include "atb/ATBArena.h" + +// Sigencore includes +#include <sigencore/Arena.h> + +// KDE includes +#include <KIcon> + +SIGEN_ARENA_PLUGIN_VERSION(SigenArenas, "sigen_arenas", 000101) + +using namespace Sigscript; +using namespace Sigencore; +using namespace Sigencore::Plugins; + +SigenArenas::SigenArenas(QObject* parent, const QVariantList& args) : + ArenaPlugin(parent, args) +{ +} + +SigenArenas::~SigenArenas() +{ +} + +QStringList SigenArenas::classList() const +{ + return QStringList() << TurnArena::name() << ATBArena::name(); +} + +QString SigenArenas::description(const QString& name) const +{ + if (name == TurnArena::name()) + return TurnArena::description(); + if (name == ATBArena::name()) + return ATBArena::description(); + return "(Unknown arena)"; +} + +QIcon SigenArenas::icon(const QString& name) +{ + if (name == TurnArena::name()) + return TurnArena::icon(); + if (name == ATBArena::name()) + return ATBArena::icon(); + return KIcon(); +} + +Arena* SigenArenas::createArena(const QString& name, GameWrapper* game, Config* parent) +{ + if (name == TurnArena::name()) + return new TurnArena(game, parent); + if (name == ATBArena::name()) + return new ATBArena(game, parent); + return NULL; +} + +void SigenArenas::cleanupArena(Arena* arena) +{ + TurnArena* turnArena = qobject_cast<TurnArena*>(arena); + if (turnArena) + { + delete turnArena; + return; + } + ATBArena* atbArena = qobject_cast<ATBArena*>(arena); + if (atbArena) + { + delete atbArena; + return; + } +} diff --git a/plugins/sigen_arena_standard/SigenArenas.h b/plugins/sigen_arena_standard/SigenArenas.h new file mode 100644 index 00000000..14ce15c8 --- /dev/null +++ b/plugins/sigen_arena_standard/SigenArenas.h @@ -0,0 +1,41 @@ +/* + * Copyright 2009 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 SIGENARENAS_SIGENARENAS +#define SIGENARENAS_SIGENARENAS + +// Sigencore plugin includes +#include <sigencore/plugins/ArenaPlugin.h> + +class SigenArenas : public Sigencore::Plugins::ArenaPlugin +{ + Q_OBJECT + + public: + SigenArenas(QObject* parent, const QVariantList& args); + ~SigenArenas(); + + QStringList classList() const; + QString description(const QString& name) const; + QIcon icon(const QString& name); + protected: + Sigencore::Arena* createArena(const QString& name, Sigscript::GameWrapper* game, Sigscript::Config* parent); + protected slots: + void cleanupArena(Sigencore::Arena* arena); +}; + +#endif diff --git a/plugins/sigen_arena_standard/atb/ATBArena.cpp b/plugins/sigen_arena_standard/atb/ATBArena.cpp new file mode 100644 index 00000000..21fd1914 --- /dev/null +++ b/plugins/sigen_arena_standard/atb/ATBArena.cpp @@ -0,0 +1,90 @@ +/* + * Copyright 2008-2009 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/>. + */ + +// Header includes +#include "ATBArena.h" + +// Sigbattle includes +#include "ATBTimer.h" + +// KDE includes +#include <KIcon> + +// Qt includes +#include <QtCore/QTimer> +#include <QtGui/QIcon> + +using namespace Sigscript; +using namespace Sigencore; + +ATBArena::ATBArena(GameWrapper* sigmod, Config* parent) : + Arena(sigmod, parent), + m_atbTimer(new ATBTimer(this, m_decisions)) +{ + connect(m_atbTimer, SIGNAL(actionReady(Sigencore::TeamMember*)), this, SLOT(processAction(Sigencore::TeamMember*))); + setupBattle(); +} + +ATBArena::~ATBArena() +{ +} + +QString ATBArena::name() +{ + return "Sigen ATB Arena"; +} + +QString ATBArena::description() +{ + return "An arena where creatures have an action bar which when filled, can act"; +} + +QIcon ATBArena::icon() +{ + // TODO + return KIcon(); +} + +void ATBArena::handleAction(TeamMember* teamMember, TeamMember::Action action) +{ + if ((action.first == TeamMember::Invalid) || (action.first == TeamMember::Timeout)) + return; + Arena::handleAction(teamMember, action); +} + +bool ATBArena::isTeamAllowed(Sigencore::Team* team) +{ + Q_UNUSED(team) + // TODO: Use rules format here? + return true; +} + +void ATBArena::setupBattle() +{ + Arena::setupBattle(); +} + +void ATBArena::processAction(TeamMember* teamMember) +{ + handleAction(teamMember, m_decisions[teamMember].second); + m_decisions.remove(teamMember); +} + +void ATBArena::cleanUp() +{ + Arena::cleanUp(); +} diff --git a/plugins/sigen_arena_standard/atb/ATBArena.h b/plugins/sigen_arena_standard/atb/ATBArena.h new file mode 100644 index 00000000..7e6e5b08 --- /dev/null +++ b/plugins/sigen_arena_standard/atb/ATBArena.h @@ -0,0 +1,59 @@ +/* + * Copyright 2008-2009 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 SIGENARENAS_ATBARENA +#define SIGENARENAS_ATBARENA + +// ATB includes +#include "ActionMap.h" + +// Sigencore includes +#include <sigencore/Arena.h> + +// Forward declaraions +class QTimer; +class ATBTimer; + +class ATBArena : public Sigencore::Arena +{ + Q_OBJECT + + public: + ATBArena(Sigscript::GameWrapper* game, Sigscript::Config* parent); + ~ATBArena(); + + static QString name(); + static QString description(); + static QIcon icon(); + protected: + virtual void handleAction(Sigencore::TeamMember* teamMember, Sigencore::TeamMember::Action action); + + virtual bool isTeamAllowed(Sigencore::Team* team); + + virtual void setupBattle(); + + Kross::ActionCollection* m_priorityScripts; + protected slots: + void processAction(Sigencore::TeamMember* teamMember); + + virtual void cleanUp(); + private: + ActionMap m_decisions; + ATBTimer* m_atbTimer; +}; + +#endif diff --git a/plugins/sigen_arena_standard/atb/ATBTimer.cpp b/plugins/sigen_arena_standard/atb/ATBTimer.cpp new file mode 100644 index 00000000..adb2a853 --- /dev/null +++ b/plugins/sigen_arena_standard/atb/ATBTimer.cpp @@ -0,0 +1,103 @@ +/* + * Copyright 2008-2009 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/>. + */ + +// Header include +#include "ATBTimer.h" + +// ATB includes +#include "ActionMap.h" +#include "ATBArena.h" + +// Sigscript includes +#include <sigscript/GameWrapper.h> +#include <sigscript/RulesWrapper.h> + +// Qt includes +#include <QtCore/QtConcurrentFilter> +#include <QtCore/QFuture> +#include <QtCore/QSignalMapper> +#include <QtCore/QTimerEvent> + +using namespace Sigencore; + +struct ATBTimer::TimerIncrementFunctor +{ + TimerIncrementFunctor(ATBTimer* timer) : + m_timer(timer) + { + } + + typedef bool result_type; + + bool operator()(TeamMember* teamMember) + { + double factor = .1; + m_timer->m_arena->valueOfType("meter-factor", &factor); + if (!m_timer->m_actions.contains(teamMember)) + { + m_timer->m_timers[teamMember] += teamMember->statValue(Sigmod::ST_Speed) * factor; + int threshold = 1000; + m_timer->m_arena->valueOfType("meter-threshold", &threshold); + if (threshold <= m_timer->m_timers[teamMember]) + { + QFutureWatcher<TeamMember::Action>* watcher = new QFutureWatcher<TeamMember::Action>(m_timer); + TeamMember::RequestedAction action = requestDecision(teamMember); + watcher->setFuture(action.second); + m_timer->connect(watcher, SIGNAL(finished()), m_timer->m_actionMapper, SLOT(map())); + m_timer->connect(watcher, SIGNAL(finished()), SLOT(deleteLater())); + m_timer->m_actionMapper->setMapping(watcher, teamMember); + m_timer->m_actions.set(teamMember, action); + } + } + return false; + } + + ATBTimer* m_timer; +}; + +ATBTimer::ATBTimer(ATBArena* arena, ActionMap& actions) : + QThread(arena), + m_arena(arena), + m_actionMapper(new QSignalMapper(this)), + m_actions(actions) +{ + connect(m_actionMapper, SIGNAL(mapped(QObject*)), this, SLOT(actionReceived(QObject*))); +} + +ATBTimer::~ATBTimer() +{ +} + +void ATBTimer::run() +{ + startTimer(50); + exec(); +} + +void ATBTimer::timerEvent(QTimerEvent* event) +{ + Q_UNUSED(event) + const QList<TeamMember*> active = m_arena->active(Arena::Fighters); + QtConcurrent::blockingFiltered(active, TimerIncrementFunctor(this)); +} + +void ATBTimer::actionReceived(QObject* object) +{ + TeamMember* teamMember = qobject_cast<TeamMember*>(object); + if (teamMember) + emit(actionReady(teamMember)); +} diff --git a/plugins/sigen_arena_standard/atb/ATBTimer.h b/plugins/sigen_arena_standard/atb/ATBTimer.h new file mode 100644 index 00000000..113d7669 --- /dev/null +++ b/plugins/sigen_arena_standard/atb/ATBTimer.h @@ -0,0 +1,58 @@ +/* + * Copyright 2008-2009 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 SIGENARENAS_ATBTIMER +#define SIGENARENAS_ATBTIMER + +// Sigencore includes +#include <sigencore/TeamMember.h> + +// Qt includes +#include <QtCore/QFutureWatcher> +#include <QtCore/QMap> +#include <QtCore/QThread> + +// Forward declarations +class QSignalMapper; +class ActionMap; +class ATBArena; + +class ATBTimer : public QThread +{ + Q_OBJECT + + public: + ATBTimer(ATBArena* arena, ActionMap& actions); + ~ATBTimer(); + signals: + void actionReady(Sigencore::TeamMember* teamMember); + protected: + void run(); + + void timerEvent(QTimerEvent* event); + protected slots: + void actionReceived(QObject* object); + private: + struct TimerIncrementFunctor; + + ATBArena* m_arena; + QSignalMapper* m_actionMapper; + QMap<Sigencore::TeamMember*, int> m_timers; + ActionMap& m_actions; +}; + +#endif diff --git a/plugins/sigen_arena_standard/atb/ActionMap.cpp b/plugins/sigen_arena_standard/atb/ActionMap.cpp new file mode 100644 index 00000000..c5ad49a2 --- /dev/null +++ b/plugins/sigen_arena_standard/atb/ActionMap.cpp @@ -0,0 +1,55 @@ +/* + * Copyright 2008-2009 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/>. + */ + +// Header include +#include "ActionMap.h" + +// Qt includes +#include <QtCore/QReadLocker> +#include <QtCore/QWriteLocker> + +using namespace Sigencore; + +bool ActionMap::contains(TeamMember* teamMember) const +{ + QReadLocker locker(&m_mutex); + return m_map.contains(teamMember); +} + +int ActionMap::remove(TeamMember* teamMember) +{ + QWriteLocker locker(&m_mutex); + return m_map.remove(teamMember); +} + +bool ActionMap::isEmpty() const +{ + QReadLocker locker(&m_mutex); + return m_map.isEmpty(); +} + +void ActionMap::set(TeamMember* teamMember, const TeamMember::RequestedAction& action) +{ + QWriteLocker locker(&m_mutex); + m_map[teamMember] = action; +} + +const TeamMember::RequestedAction ActionMap::operator[](TeamMember* teamMember) const +{ + QReadLocker locker(&m_mutex); + return m_map[teamMember]; +} diff --git a/plugins/sigen_arena_standard/atb/ActionMap.h b/plugins/sigen_arena_standard/atb/ActionMap.h new file mode 100644 index 00000000..7c65a97e --- /dev/null +++ b/plugins/sigen_arena_standard/atb/ActionMap.h @@ -0,0 +1,44 @@ +/* + * Copyright 2008-2009 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 SIGENARENAS_ACTIONMAP +#define SIGENARENAS_ACTIONMAP + +// Sigencore includes +#include <sigencore/TeamMember.h> + +// Qt includes +#include <QtCore/QMap> +#include <QtCore/QReadWriteLock> + +class ActionMap +{ + public: + bool contains(Sigencore::TeamMember* teamMember) const; + int remove(Sigencore::TeamMember* teamMember); + + bool isEmpty() const; + + void set(Sigencore::TeamMember* teamMember, const Sigencore::TeamMember::RequestedAction& action); + + const Sigencore::TeamMember::RequestedAction operator[](Sigencore::TeamMember* teamMember) const; + private: + QMap<Sigencore::TeamMember*, Sigencore::TeamMember::RequestedAction> m_map; + mutable QReadWriteLock m_mutex; +}; + +#endif diff --git a/plugins/sigen_arena_standard/sigen_arenas.desktop b/plugins/sigen_arena_standard/sigen_arenas.desktop new file mode 100644 index 00000000..e4f659c7 --- /dev/null +++ b/plugins/sigen_arena_standard/sigen_arenas.desktop @@ -0,0 +1,16 @@ +[Desktop Entry] +Type=Service +X-KDE-ServiceTypes=Sigen/Arena +Icon=sigen-arenaplugin +Name=Sigen Arenas +X-Sigen-MinVersion=000101 +X-KDE-Library=arena_sigen +X-KDE-PluginInfo-Author=Ben Boeckel +X-KDE-PluginInfo-Email=MathStuf@gmail.com +X-KDE-PluginInfo-Name=sigen_arenas +X-KDE-PluginInfo-Version=0.1.1 +X-KDE-PluginInfo-Website= +X-KDE-PluginInfo-Category=arena +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPLv3 +X-KDE-PluginInfo-EnabledByDefault=true diff --git a/plugins/sigen_arena_standard/standard/TurnArena.cpp b/plugins/sigen_arena_standard/standard/TurnArena.cpp new file mode 100644 index 00000000..233e512f --- /dev/null +++ b/plugins/sigen_arena_standard/standard/TurnArena.cpp @@ -0,0 +1,160 @@ +/* + * Copyright 2008-2009 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/>. + */ + +// Header include +#include "TurnArena.h" + +// Sigencore includes +#include <sigencore/Player.h> +#include <sigencore/RunScript.h> +#include <sigencore/Team.h> + +// Sigscript includes +#include <sigscript/GameWrapper.h> +#include <sigscript/MoveWrapper.h> + +// KDE includes +#include <KIcon> +#include <kross/core/actioncollection.h> + +// Qt includes +#include <QtAlgorithms> +#include <QtCore/QtConcurrentMap> +#include <QtCore/QFuture> +#include <QtGui/QIcon> + +using namespace Sigcore; +using namespace Sigscript; +using namespace Sigencore; + +bool sortActions(const TeamMember::RequestedAction& reqAction1, const TeamMember::RequestedAction& reqAction2) +{ + TeamMember::Action action1 = reqAction1.second.isCanceled() ? TeamMember::Action(TeamMember::Timeout, TeamMember::ActionData()) : reqAction1.second; + TeamMember::Action action2 = reqAction2.second.isCanceled() ? TeamMember::Action(TeamMember::Timeout, TeamMember::ActionData()) : reqAction2.second; + const int priority1 = actionPriority(reqAction1.first, action1); + const int priority2 = actionPriority(reqAction1.first, action2); + if (priority1 < priority2) + return true; + else if (priority1 == priority2) + { + const int speed1 = reqAction1.first->statValue(Sigmod::ST_Speed); + const int speed2 = reqAction2.first->statValue(Sigmod::ST_Speed); + if (speed1 < speed2) + return true; + else if (speed1 == speed2) + return Sigcore::Fraction::poll(1, 2); + } + return false; +} + +TurnArena::TurnArena(GameWrapper* sigmod, Config* parent) : + Arena(sigmod, parent), + m_priorityScripts(new Kross::ActionCollection("priority-scripts", m_actions)) +{ + setupBattle(); +} + +QString TurnArena::name() +{ + return "Sigen turn arena"; +} + +QString TurnArena::description() +{ + return "An arena where creatures act in order of their speed (unless move priority takes precedence)"; +} + +QIcon TurnArena::icon() +{ + // TODO + return KIcon(); +} + +bool TurnArena::isTeamAllowed(Sigencore::Team* team) +{ + Q_UNUSED(team) + // TODO: Use rules format here? + return true; +} + +void TurnArena::handleAction(TeamMember* teamMember, TeamMember::Action action) +{ + Arena::handleAction(teamMember, action); +} + +void TurnArena::setupBattle() +{ + connect(this, SIGNAL(battleStarted()), SLOT(processRound())); + Arena::setupBattle(); +} + +void TurnArena::distributeWinnings() +{ + Arena::distributeWinnings(); +} + +void TurnArena::checkForLosers() +{ + Arena::checkForLosers(); +} + +void TurnArena::registerScript(const Script& script) +{ + Arena::registerScript(script); +} + +void TurnArena::cleanUp() +{ + Arena::cleanUp(); +} + +void TurnArena::processRound() +{ + emit(roundAboutToStart()); + emit(roundStarted()); + QFuture<TeamMember::RequestedAction> reqActions = QtConcurrent::mapped(active(Fighters), &requestDecision); + reqActions.waitForFinished(); + QList<TeamMember::RequestedAction> actions = reqActions.results(); + qStableSort(actions.begin(), actions.end(), sortActions); + foreach (const TeamMember::RequestedAction& reqAction, actions) + { + TeamMember::Action action = reqAction.second; + if (action.first == TeamMember::Attack) + { + MoveWrapper* move = m_game->move(action.second.first.toInt()); + const Script script = move->priorityScript(); + ObjectMap objects; + objects["arena"] = this; + objects["move"] = move; + objects["owner"] = reqAction.first; + objects["player"] = reqAction.first->team()->player(); + objects["sigmod"] = m_game; + // TODO: Add other players + runScript(QString("priority-%1").arg(QUuid::createUuid().toString()), script, objects, m_priorityScripts)->trigger(); + } + } + qStableSort(actions.begin(), actions.end(), sortActions); + foreach (const TeamMember::RequestedAction& action, actions) + { + if (action.first->currentHp()) + handleAction(action.first, action.second); + } + emit(roundAboutToEnd()); + emit(roundEnded()); + // TODO: Check if there is anyone left to fight + processRound(); +} diff --git a/plugins/sigen_arena_standard/standard/TurnArena.h b/plugins/sigen_arena_standard/standard/TurnArena.h new file mode 100644 index 00000000..9dce6ea3 --- /dev/null +++ b/plugins/sigen_arena_standard/standard/TurnArena.h @@ -0,0 +1,60 @@ +/* + * Copyright 2008-2009 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 SIGENARENAS_TURNARENA +#define SIGENARENAS_TURNARENA + +// Sigencore includes +#include <sigencore/Arena.h> + +class TurnArena : public Sigencore::Arena +{ + Q_OBJECT + + public: + TurnArena(Sigscript::GameWrapper* game, Sigscript::Config* parent); + + static QString name(); + static QString description(); + static QIcon icon(); + signals: + void roundAboutToStart(); + void roundStarted(); + void roundEnded(); + void roundAboutToEnd(); + protected: + virtual void handleAction(Sigencore::TeamMember* teamMember, Sigencore::TeamMember::Action action); + + virtual bool isTeamAllowed(Sigencore::Team* team); + + virtual void setupBattle(); + + virtual void distributeWinnings(); + virtual void checkForLosers(); + + Kross::ActionCollection* m_priorityScripts; + protected slots: + void processRound(); + + virtual void registerScript(const Sigcore::Script& script); + + virtual void cleanUp(); +}; + +bool sortActions(const Sigencore::TeamMember::RequestedAction& reqAction1, const Sigencore::TeamMember::RequestedAction& reqAction2); + +#endif diff --git a/plugins/sigen_canvas_standard/CMakeLists.txt b/plugins/sigen_canvas_standard/CMakeLists.txt new file mode 100644 index 00000000..931659d4 --- /dev/null +++ b/plugins/sigen_canvas_standard/CMakeLists.txt @@ -0,0 +1,38 @@ +project(sigencanvases) + +set(sigencanvases_SRCS + SigenCanvases.cpp + qgraphicsscene/QGSCanvas.cpp +) +set(sigencanvases_SERVICES + sigen_canvases.desktop +) + +kde4_add_plugin(canvas_sigen + ${sigencanvases_SRCS} +) +target_link_libraries(canvas_sigen + ${QT_QTCORE_LIBRARY} + ${QT_QTGUI_LIBRARY} + ${KDE4_KDEUI_LIBRARY} + ${KDE4_KROSSCORE_LIBRARY} + sigencoreplugins +) + +install( + TARGETS + canvas_sigen + DESTINATION + ${PLUGIN_INSTALL_DIR} + COMPONENT + plugins +) + +install( + FILES + ${sigencanvases_SERVICES} + DESTINATION + ${SERVICES_INSTALL_DIR} + COMPONENT + plugins +) diff --git a/plugins/sigen_canvas_standard/SigenCanvases.cpp b/plugins/sigen_canvas_standard/SigenCanvases.cpp new file mode 100644 index 00000000..3969a56e --- /dev/null +++ b/plugins/sigen_canvas_standard/SigenCanvases.cpp @@ -0,0 +1,79 @@ +/* + * Copyright 2009 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/>. + */ + +// Header include +#include "SigenCanvases.h" + +// Canvas includes +#include "qgraphicsscene/QGSCanvas.h" + +// Sigencore includes +#include <sigencore/Canvas.h> + +// KDE includes +#include <KIcon> + +SIGEN_CANVAS_PLUGIN_VERSION(SigenCanvases, "sigen_canvases", 000101) + +using namespace Sigscript; +using namespace Sigencore; +using namespace Sigencore::Plugins; + +SigenCanvases::SigenCanvases(QObject* parent, const QVariantList& args) : + CanvasPlugin(parent, args) +{ +} + +SigenCanvases::~SigenCanvases() +{ +} + +QStringList SigenCanvases::classList() const +{ + return QStringList() << QGSCanvas::name(); +} + +QString SigenCanvases::description(const QString& name) const +{ + if (name == QGSCanvas::name()) + return QGSCanvas::description(); + return "(Unknown canvas)"; +} + +QIcon SigenCanvases::icon(const QString& name) +{ + if (name == QGSCanvas::name()) + return QGSCanvas::icon(); + return KIcon(); +} + +Canvas* SigenCanvases::createCanvas(const QString& name, GameWrapper* game, Config* parent) +{ + if (name == QGSCanvas::name()) + return new QGSCanvas(game, parent); + return NULL; +} + +void SigenCanvases::cleanupCanvas(Canvas* canvas) +{ + QGSCanvas* qgsCanvas = qobject_cast<QGSCanvas*>(canvas); + if (qgsCanvas) + { + delete qgsCanvas; + return; + } +} diff --git a/plugins/sigen_canvas_standard/SigenCanvases.h b/plugins/sigen_canvas_standard/SigenCanvases.h new file mode 100644 index 00000000..6e0eaf22 --- /dev/null +++ b/plugins/sigen_canvas_standard/SigenCanvases.h @@ -0,0 +1,41 @@ +/* + * Copyright 2009 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 SIGENCANVASES_SIGENCANVASES +#define SIGENCANVASES_SIGENCANVASES + +// Sigencore plugin includes +#include <sigencore/plugins/CanvasPlugin.h> + +class SigenCanvases : public Sigencore::Plugins::CanvasPlugin +{ + Q_OBJECT + + public: + SigenCanvases(QObject* parent, const QVariantList& args); + ~SigenCanvases(); + + QStringList classList() const; + QString description(const QString& name) const; + QIcon icon(const QString& name); + protected: + Sigencore::Canvas* createCanvas(const QString& name, Sigscript::GameWrapper* game, Sigscript::Config* parent); + protected slots: + void cleanupCanvas(Sigencore::Canvas* canvas); +}; + +#endif diff --git a/plugins/sigen_canvas_standard/qgraphicsscene/QGSCanvas.cpp b/plugins/sigen_canvas_standard/qgraphicsscene/QGSCanvas.cpp new file mode 100644 index 00000000..09f823b1 --- /dev/null +++ b/plugins/sigen_canvas_standard/qgraphicsscene/QGSCanvas.cpp @@ -0,0 +1,112 @@ +/* + * Copyright 2009 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/>. + */ + +// Header include +#include "QGSCanvas.h" + +// Sigencore includes +#include <sigencore/RunScript.h> + +// Sigscript includes +#include <sigscript/GameWrapper.h> +#include <sigscript/SpriteWrapper.h> + +// KDE includes +#include <KIcon> +#include <kross/core/action.h> +#include <kross/core/actioncollection.h> +#include <kross/core/manager.h> + +// Qt includes +#include <QtCore/QUuid> +#include <QtGui/QGraphicsItem> +#include <QtGui/QGraphicsScene> +#include <QtGui/QGraphicsView> + +using namespace Sigscript; +using namespace Sigencore; + +QGSCanvas::QGSCanvas(GameWrapper* game, Config* parent) : + Canvas(parent), + m_game(game), + m_scene(new QGraphicsScene), + m_collection(new Kross::ActionCollection(QString("canvas-%1").arg(QUuid::createUuid().toString()), Kross::Manager::self().actionCollection())) +{ +} + +QGSCanvas::~QGSCanvas() +{ + delete m_scene; + delete m_collection; +} + +QString QGSCanvas::name() +{ + return "QGraphicsScene canvas"; +} + +QString QGSCanvas::description() +{ + return "A canvas using QGraphicsScene"; +} + +QIcon QGSCanvas::icon() +{ + return KIcon(); +} + +void QGSCanvas::addSprite(const QString& name, const QString& sprite, const int x, const int y, const int zOrder) +{ + // TODO: NOOP or refresh? + if (m_items.contains(name)) + return; + SpriteWrapper* spr = m_game->sprite(sprite); + if (spr) + { + QGraphicsPixmapItem* item = new QGraphicsPixmapItem(spr->sprite()); + item->setPos(x, y); + item->setZValue(zOrder); + m_scene->addItem(item); + m_items[name] = item; + } +} + +void QGSCanvas::removeSprite(const QString& name) +{ + if (m_items.contains(name)) + { + delete m_items[name]; + m_items.remove(name); + } +} + +void QGSCanvas::transform(const QString& transform, const QString& object, const QVariantList& parameters) +{ +} + +int QGSCanvas::type() const +{ + return QGraphicsSceneCanvas; +} + +QWidget* QGSCanvas::viewport() +{ + // TODO: Only one view allowed? or as many as wanted? + QGraphicsView* view = new QGraphicsView; + view->setScene(m_scene); + return view; +} diff --git a/plugins/sigen_canvas_standard/qgraphicsscene/QGSCanvas.h b/plugins/sigen_canvas_standard/qgraphicsscene/QGSCanvas.h new file mode 100644 index 00000000..d779a3b3 --- /dev/null +++ b/plugins/sigen_canvas_standard/qgraphicsscene/QGSCanvas.h @@ -0,0 +1,62 @@ +/* + * Copyright 2009 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 SIGENCANVASES_QGSCANVAS +#define SIGENCANVASES_QGSCANVAS + +// Sigencore includes +#include <sigencore/Canvas.h> + +// Forward declarations +namespace Kross +{ +class ActionCollection; +} +class QGraphicsItem; +class QGraphicsScene; +namespace Sigscript +{ +class GameWrapper; +} + +class QGSCanvas : public Sigencore::Canvas +{ + Q_OBJECT + + public: + QGSCanvas(Sigscript::GameWrapper* game, Sigscript::Config* parent); + ~QGSCanvas(); + + static QString name(); + static QString description(); + static QIcon icon(); + + Q_SCRIPTABLE void addSprite(const QString& name, const QString& sprite, const int x, const int y, const int zOrder); + Q_SCRIPTABLE void removeSprite(const QString& name); + Q_SCRIPTABLE void transform(const QString& transform, const QString& object, const QVariantList& parameters); + + int type() const; + + QWidget* viewport(); + private: + Sigscript::GameWrapper* m_game; + QGraphicsScene* m_scene; + QMap<QString, QGraphicsItem*> m_items; + Kross::ActionCollection* m_collection; +}; + +#endif diff --git a/plugins/sigen_canvas_standard/sigen_canvases.desktop b/plugins/sigen_canvas_standard/sigen_canvases.desktop new file mode 100644 index 00000000..7731030c --- /dev/null +++ b/plugins/sigen_canvas_standard/sigen_canvases.desktop @@ -0,0 +1,16 @@ +[Desktop Entry] +Type=Service +X-KDE-ServiceTypes=Sigen/Canvas +Icon=sigen-canvasplugin +Name=Sigen Canvases +X-Sigen-MinVersion=0.1.1 +X-KDE-Library=canvas_sigen +X-KDE-PluginInfo-Author=Ben Boeckel +X-KDE-PluginInfo-Email=MathStuf@gmail.com +X-KDE-PluginInfo-Name=sigen_canvas +X-KDE-PluginInfo-Version=0.1.1 +X-KDE-PluginInfo-Website= +X-KDE-PluginInfo-Category=canvas +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPLv3 +X-KDE-PluginInfo-EnabledByDefault=true |
