diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-08-28 14:52:45 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-08-28 14:52:45 +0000 |
| commit | b99ffef4aa68dd5f0af64de9aec0f610e267d8cc (patch) | |
| tree | d5f9e905c21c47f6a98688d400a99ce8f479e52b /pokebattle/TurnArena.cpp | |
| parent | e4630543dc17d2a42c27d192518fe3f54e7888bc (diff) | |
| download | sigen-b99ffef4aa68dd5f0af64de9aec0f610e267d8cc.tar.gz sigen-b99ffef4aa68dd5f0af64de9aec0f610e267d8cc.tar.xz sigen-b99ffef4aa68dd5f0af64de9aec0f610e267d8cc.zip | |
[FIX] Changed the providers URL to a better structure
[FIX] Arenas can now count how many players are still active
[FIX] long long is now used for experience
[FIX] Scripts initialized now
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@248 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokebattle/TurnArena.cpp')
| -rw-r--r-- | pokebattle/TurnArena.cpp | 67 |
1 files changed, 58 insertions, 9 deletions
diff --git a/pokebattle/TurnArena.cpp b/pokebattle/TurnArena.cpp index 6c279153..bf0bece8 100644 --- a/pokebattle/TurnArena.cpp +++ b/pokebattle/TurnArena.cpp @@ -18,30 +18,79 @@ // Header include #include "TurnArena.h" +// Pokemod includes +#include "../pokemod/Fraction.h" + // Qt includes +#include <QtAlgorithms> #include <QtCore/QtConcurrentMap> +#include <QtCore/QFuture> +#include <QtCore/QTimer> + +bool Pokebattle::sortActions(const TeamMember::RequestedAction& reqAction1, const TeamMember::RequestedAction& reqAction2) +{ + TeamMember::Action action1 = reqAction1.second.isFinished() ? reqAction1.second : TeamMember::Action(TeamMember::Timeout, TeamMember::ActionData()); + TeamMember::Action action2 = reqAction2.second.isFinished() ? reqAction2.second : TeamMember::Action(TeamMember::Timeout, TeamMember::ActionData()); + 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(Pokemod::ST_Speed); + const int speed2 = reqAction2.first->statValue(Pokemod::ST_Speed); + if (speed1 < speed2) + return true; + else if (speed1 == speed2) + return Pokemod::Fraction(1, 2).poll(); + } + return false; +} Pokebattle::TurnArena::TurnArena(QList<Player*> players, QObject* parent) : - Arena(players, parent) + Arena(players, parent), + m_watcher(new QFutureWatcher<TeamMember::RequestedAction>(this)), + m_timer(new QTimer(this)) { setupBattle(); + m_timer->setSingleShot(true); + connect(m_timer, SIGNAL(timeout()), m_watcher, SLOT(cancel())); } void Pokebattle::TurnArena::processRound() { emit(roundAboutToStart()); emit(roundStart()); - QFuture<TeamMember::RequestedAction> actions = QtConcurrent::mapped(active(), &Pokebattle::requestDecision); - // TODO: timeout here? - // TODO: wait for all actions (unless timeout) - // TODO: notify all attacks of what is going on (they can change priorities as needed) - // TODO: determine the order of attacks - // TODO: act out actions (ignoring those that affect fainting along the way) + QFuture<TeamMember::RequestedAction> reqActions = QtConcurrent::mapped(active(), &Pokebattle::requestDecision); + m_watcher->setFuture(reqActions); + m_timer->start(120000); + reqActions.waitForFinished(); + m_timer->stop(); + QList<TeamMember::RequestedAction> actions = reqActions.results(); + qStableSort(actions.begin(), actions.end(), sortActions); + for (int i = 0; i < actions.size(); ++i) + { + for (int j = 0; j < i; ++j) + { + + // TODO: Notify scripts of the moves before it and of its targets + } + } + // TODO: notify all attacks of what is going on in order (they can change priorities as needed) + qStableSort(actions.begin(), actions.end(), sortActions); + foreach (TeamMember::RequestedAction action, actions) + { + // TODO: Handle when the target switches or is knocked out + if (action.first->currentHp()) + handleAction(action.first, action.second); + } emit(roundAboutToEnd()); emit(roundEnd()); - // if (teamCount <= 1) + if (numActiveTeams() <= 1) + { // TODO: End Round - // else + } + else processRound(); } |
