From 823876081da2f553adde73a925be2db42772a1fe Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 9 Apr 2009 16:10:17 -0400 Subject: Move TurnArena to turn directory --- plugins/arena/standard/standard/TurnArena.cpp | 160 -------------------------- plugins/arena/standard/standard/TurnArena.h | 60 ---------- plugins/arena/standard/turn/TurnArena.cpp | 160 ++++++++++++++++++++++++++ plugins/arena/standard/turn/TurnArena.h | 60 ++++++++++ 4 files changed, 220 insertions(+), 220 deletions(-) delete mode 100644 plugins/arena/standard/standard/TurnArena.cpp delete mode 100644 plugins/arena/standard/standard/TurnArena.h create mode 100644 plugins/arena/standard/turn/TurnArena.cpp create mode 100644 plugins/arena/standard/turn/TurnArena.h diff --git a/plugins/arena/standard/standard/TurnArena.cpp b/plugins/arena/standard/standard/TurnArena.cpp deleted file mode 100644 index 233e512f..00000000 --- a/plugins/arena/standard/standard/TurnArena.cpp +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright 2008-2009 Ben Boeckel - * - * 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 . - */ - -// Header include -#include "TurnArena.h" - -// Sigencore includes -#include -#include -#include - -// Sigscript includes -#include -#include - -// KDE includes -#include -#include - -// Qt includes -#include -#include -#include -#include - -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 reqActions = QtConcurrent::mapped(active(Fighters), &requestDecision); - reqActions.waitForFinished(); - QList 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/arena/standard/standard/TurnArena.h b/plugins/arena/standard/standard/TurnArena.h deleted file mode 100644 index 9dce6ea3..00000000 --- a/plugins/arena/standard/standard/TurnArena.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2008-2009 Ben Boeckel - * - * 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 . - */ - -#ifndef SIGENARENAS_TURNARENA -#define SIGENARENAS_TURNARENA - -// Sigencore includes -#include - -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/arena/standard/turn/TurnArena.cpp b/plugins/arena/standard/turn/TurnArena.cpp new file mode 100644 index 00000000..233e512f --- /dev/null +++ b/plugins/arena/standard/turn/TurnArena.cpp @@ -0,0 +1,160 @@ +/* + * Copyright 2008-2009 Ben Boeckel + * + * 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 . + */ + +// Header include +#include "TurnArena.h" + +// Sigencore includes +#include +#include +#include + +// Sigscript includes +#include +#include + +// KDE includes +#include +#include + +// Qt includes +#include +#include +#include +#include + +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 reqActions = QtConcurrent::mapped(active(Fighters), &requestDecision); + reqActions.waitForFinished(); + QList 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/arena/standard/turn/TurnArena.h b/plugins/arena/standard/turn/TurnArena.h new file mode 100644 index 00000000..9dce6ea3 --- /dev/null +++ b/plugins/arena/standard/turn/TurnArena.h @@ -0,0 +1,60 @@ +/* + * Copyright 2008-2009 Ben Boeckel + * + * 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 . + */ + +#ifndef SIGENARENAS_TURNARENA +#define SIGENARENAS_TURNARENA + +// Sigencore includes +#include + +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 -- cgit