summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Changelog14
-rw-r--r--pokebattle/ATBArena.cpp55
-rw-r--r--pokebattle/ATBArena.h14
-rw-r--r--pokebattle/ATBTimer.cpp51
-rw-r--r--pokebattle/ATBTimer.h56
-rw-r--r--pokebattle/ActionQueue.h87
-rw-r--r--pokebattle/Arena.cpp14
-rw-r--r--pokebattle/Arena.h22
-rw-r--r--pokebattle/CMakeLists.txt5
-rw-r--r--pokebattle/Containment.cpp29
-rw-r--r--pokebattle/Containment.h10
-rw-r--r--pokebattle/Player.h4
-rw-r--r--pokebattle/Team.cpp16
-rw-r--r--pokebattle/Team.h5
-rw-r--r--pokebattle/TeamMember.cpp62
-rw-r--r--pokebattle/TeamMember.h24
-rw-r--r--pokebattle/TurnArena.cpp24
-rw-r--r--pokebattle/TurnArena.h9
-rw-r--r--pokemod/Fraction.cpp2
-rw-r--r--pokemod/Fraction.h79
-rw-r--r--pokemod/Hat.h44
-rw-r--r--pokemod/SpeciesMove.cpp2
-rw-r--r--pokemodr/Pokemodr.cpp16
-rw-r--r--pokemodr/gui/speciesmove.ui2
-rw-r--r--pokescripting/Config.h8
25 files changed, 537 insertions, 117 deletions
diff --git a/Changelog b/Changelog
index d9933ae1..b3dd9fa0 100644
--- a/Changelog
+++ b/Changelog
@@ -1,4 +1,16 @@
-----------------
+Rev: 228
+Date: 20 July 2008
+User: MathStuf
+-----------------
+[FIX] Slimmed up main() for pokemodr
+[FIX] Cleaned up initializing TeamMember
+[FIX] Hat fixed up
+[ADD] Added ActionQueue (thread-safe QQueue)
+[FIX] Arena classes fleshed out a bit
+[ADD] ATBTimer class added to mediate the ATB counters
+
+-----------------
Rev: 227
Date: 20 July 2008
User: MathStuf
@@ -10,7 +22,7 @@ User: MathStuf
[FIX] Height no longer broken between feet and inches
[FIX] Fixed a bug in the TeamMember stat generation
[FIX] No more global skins; should be scripted
-[FIX] Missed somt COPY() macros
+[FIX] Missed some COPY() macros
-----------------
Rev: 226
diff --git a/pokebattle/ATBArena.cpp b/pokebattle/ATBArena.cpp
new file mode 100644
index 00000000..df7a7945
--- /dev/null
+++ b/pokebattle/ATBArena.cpp
@@ -0,0 +1,55 @@
+/*
+ * Copyright 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/>.
+ */
+
+// Header includes
+#include "ATBArena.h"
+
+// Pokebattle includes
+#include "ATBTimer.h"
+
+// Qt includes
+#include <QtCore/QtConcurrentRun>
+#include <QtCore/QTimer>
+
+Pokebattle::ATBArena::ATBArena(QList<Player*> players) :
+ Arena(players)
+{
+ setupBattle();
+}
+
+void Pokebattle::ATBArena::processActions()
+{
+ if (!m_decisions.isEmpty())
+ {
+ while (m_decisions.head().second.isFinished())
+ {
+ TeamMember::RequestedAction action = m_decisions.head();
+ // TODO: process action
+ m_decisions.dequeue();
+ }
+ }
+}
+
+void Pokebattle::ATBArena::setupBattle()
+{
+ m_atbTimer = new ATBTimer(this, m_decisions);
+ connect(this, SIGNAL(battleEnd()), m_atbTimer, SLOT(done()));
+ QTimer* moveTimer = new QTimer(this);
+ connect(moveTimer, SIGNAL(timeout()), this, SLOT(processActions()));
+ moveTimer->start(100);
+ Arena::setupBattle();
+}
diff --git a/pokebattle/ATBArena.h b/pokebattle/ATBArena.h
index 4ec4a6fc..b312dcdf 100644
--- a/pokebattle/ATBArena.h
+++ b/pokebattle/ATBArena.h
@@ -19,23 +19,29 @@
#define __POKEBATTLE_ATBARENA__
// Pokebattle includes
+#include "ActionQueue.h"
#include "Arena.h"
-// Qt includes
-#include <QtCore/QQueue>
-
namespace Pokebattle
{
+// Forward declaraions
+class ATBTimer;
+
class POKEBATTLE_EXPORT ATBArena : public Arena
{
Q_OBJECT
public:
+ ATBArena(QList<Player*> players);
signals:
public slots:
protected slots:
+ void processActions();
+ protected:
+ void setupBattle();
private:
- QQueue<Decision> m_decisions;
+ ActionQueue m_decisions;
+ ATBTimer* m_atbTimer;
};
}
diff --git a/pokebattle/ATBTimer.cpp b/pokebattle/ATBTimer.cpp
new file mode 100644
index 00000000..a72b9819
--- /dev/null
+++ b/pokebattle/ATBTimer.cpp
@@ -0,0 +1,51 @@
+/*
+ * Copyright 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/>.
+ */
+
+// Header include
+#include "ATBTimer.h"
+
+// Pokebattle includes
+#include "ATBArena.h"
+
+// Qt includes
+#include <QtCore/QtConcurrentMap>
+#include <QtCore/QtConcurrentFilter>
+#include <QtCore/QFuture>
+#include <QtCore/QTimer>
+
+Pokebattle::ATBTimer::ATBTimer(ATBArena* arena, ActionQueue& actions) :
+ QThread(arena),
+ m_arena(arena),
+ m_actions(actions),
+ m_timer(new QTimer(this))
+{
+ connect(m_timer, SIGNAL(timeout()), this, SLOT(update()));
+}
+
+void Pokebattle::ATBTimer::update()
+{
+ // TODO: update times with mapping
+ // TODO: adjust max time if needed
+ // TODO: filter out those not above the threshold and push into the queue if needed and reset its timer
+}
+
+void Pokebattle::ATBTimer::run()
+{
+ m_timer->start(50);
+ // TODO: Anything else to do here?
+ exec();
+}
diff --git a/pokebattle/ATBTimer.h b/pokebattle/ATBTimer.h
new file mode 100644
index 00000000..d0c6ee35
--- /dev/null
+++ b/pokebattle/ATBTimer.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright 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_ATBTIMER__
+#define __POKEBATTLE_ATBTIMER__
+
+// Pokebattle includes
+#include "Global.h"
+
+// Qt includes
+#include <QtCore/QMap>
+#include <QtCore/QThread>
+
+// Forward declarations
+class QTimer;
+
+namespace Pokebattle
+{
+class ActionQueue;
+class ATBArena;
+class Player;
+class TeamMember;
+
+class POKEBATTLE_EXPORT ATBTimer : public QThread
+{
+ Q_OBJECT
+
+ public:
+ ATBTimer(ATBArena* arena, ActionQueue& actions);
+ protected slots:
+ void update();
+ protected:
+ void run();
+ private:
+ ATBArena* m_arena;
+ ActionQueue& m_actions;
+ QMap<TeamMember*, double> m_timeStates;
+ QTimer* m_timer;
+};
+}
+
+#endif
diff --git a/pokebattle/ActionQueue.h b/pokebattle/ActionQueue.h
new file mode 100644
index 00000000..e6663990
--- /dev/null
+++ b/pokebattle/ActionQueue.h
@@ -0,0 +1,87 @@
+/*
+ * Copyright 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_ACTIONQUEUE__
+#define __POKEBATTLE_ACTIONQUEUE__
+
+// Pokebattle includes
+#include "Global.h"
+#include "TeamMember.h"
+
+// Qt includes
+#include <QtCore/QMutex>
+#include <QtCore/QQueue>
+
+namespace Pokebattle
+{
+class POKEBATTLE_EXPORT ActionQueue : public QQueue<TeamMember::RequestedAction>
+{
+ public:
+ ActionQueue();
+
+ TeamMember::RequestedAction dequeue();
+ void enqueue(const TeamMember::RequestedAction& action);
+
+ TeamMember::RequestedAction& head();
+
+ void lock();
+ void unlock();
+ private:
+ QMutex m_mutex;
+};
+
+inline ActionQueue::ActionQueue() :
+ QQueue<TeamMember::RequestedAction>()
+{
+}
+
+inline TeamMember::RequestedAction ActionQueue::dequeue()
+{
+ m_mutex.lock();
+ TeamMember::RequestedAction action = QQueue<TeamMember::RequestedAction>::dequeue();
+ m_mutex.unlock();
+ return action;
+}
+
+inline void ActionQueue::enqueue(const TeamMember::RequestedAction& action)
+{
+ m_mutex.lock();
+ QQueue<TeamMember::RequestedAction>::enqueue(action);
+ m_mutex.unlock();
+}
+
+inline TeamMember::RequestedAction& ActionQueue::head()
+{
+ m_mutex.lock();
+ TeamMember::RequestedAction& action = QQueue<TeamMember::RequestedAction>::head();
+ m_mutex.unlock();
+ return action;
+}
+
+inline void ActionQueue::lock()
+{
+ m_mutex.lock();
+}
+
+inline void ActionQueue::unlock()
+{
+ m_mutex.unlock();
+}
+
+}
+
+#endif
diff --git a/pokebattle/Arena.cpp b/pokebattle/Arena.cpp
index 4d5f3885..dbb2e857 100644
--- a/pokebattle/Arena.cpp
+++ b/pokebattle/Arena.cpp
@@ -29,12 +29,17 @@
#include <kross/core/actioncollection.h>
#include <kross/core/manager.h>
+Pokebattle::TeamMember::Action Pokebattle::requestDecision(const TeamMember*& teamMember)
+{
+ return teamMember->requestAction();
+}
+
QSet<int> Pokebattle::Arena::m_arenaIds;
Pokebattle::Arena::Arena(QList<Player*> players) :
- m_id(0),
m_players(players),
- m_actions(NULL)
+ m_actions(NULL),
+ m_id(0)
{
connect(this, SIGNAL(battleEnd()), SLOT(cleanUp()));
connect(this, SIGNAL(battleEnd()), SLOT(unregisterAllScripts()));
@@ -95,3 +100,8 @@ void Pokebattle::Arena::cleanUp()
{
// TODO: clean up everything
}
+
+void Pokebattle::Arena::setupBattle()
+{
+ // TODO: setup all the battle stuff
+}
diff --git a/pokebattle/Arena.h b/pokebattle/Arena.h
index fb99eca2..08142b1a 100644
--- a/pokebattle/Arena.h
+++ b/pokebattle/Arena.h
@@ -21,6 +21,7 @@
// Pokebattle includes
#include "Global.h"
#include "Team.h"
+#include "TeamMember.h"
// Qt includes
#include <QtCore/QList>
@@ -48,16 +49,6 @@ class POKEBATTLE_EXPORT Arena : public QObject
Q_OBJECT
public:
- enum ActionType
- {
- Attack = 0,
- Item = 1,
- Run = 2,
- Timeout = 3,
- Undecided = 4,
- End = 5
- };
-
Arena(QList<Player*> players);
~Arena();
@@ -74,14 +65,17 @@ class POKEBATTLE_EXPORT Arena : public QObject
void cleanUp();
protected:
- typedef QPair<ActionType, int> Action;
- typedef QPair<TeamMember*, Action> Decision;
- private:
- int m_id;
+ virtual void setupBattle();
+
QList<Player*> m_players;
Kross::ActionCollection* m_actions;
+ private:
+ int m_id;
static QSet<int> m_arenaIds;
};
+
+TeamMember::Action requestDecision(const TeamMember*& teamMember);
+
}
#endif
diff --git a/pokebattle/CMakeLists.txt b/pokebattle/CMakeLists.txt
index 45589d42..5fd685f5 100644
--- a/pokebattle/CMakeLists.txt
+++ b/pokebattle/CMakeLists.txt
@@ -9,6 +9,7 @@ ADD_DEFINITIONS(-DMAKE_POKEBATTLE_LIB)
SET(pokebattle_MOC_HEADERS
Arena.h
ATBArena.h
+ ATBTimer.h
Bot.h
Containment.h
GhostBot.h
@@ -21,12 +22,16 @@ SET(pokebattle_MOC_HEADERS
QT4_WRAP_CPP(pokebattle_MOC_SRCS ${pokebattle_MOC_HEADERS})
SET(pokebattle_HEADERS
${pokebattle_MOC_HEADERS}
+ ActionQueue.h
)
SET(pokebattle_DEVEL
${pokebattle_HEADERS}
)
SET(pokebattle_SRCS
Arena.cpp
+ ATBArena.cpp
+ ATBTimer.cpp
+ Containment.cpp
Ghost.cpp
Team.cpp
TeamMember.cpp
diff --git a/pokebattle/Containment.cpp b/pokebattle/Containment.cpp
new file mode 100644
index 00000000..0a8e7e3d
--- /dev/null
+++ b/pokebattle/Containment.cpp
@@ -0,0 +1,29 @@
+/*
+ * Copyright 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/>.
+ */
+
+// Header include
+#include "Containment.h"
+
+const Pokebattle::Player* Pokebattle::Containment::player()
+{
+ return m_player;
+}
+
+QList<Pokebattle::TeamMember*> Pokebattle::Containment::members() const
+{
+ return m_members;
+}
diff --git a/pokebattle/Containment.h b/pokebattle/Containment.h
index ffa3c525..72ea5925 100644
--- a/pokebattle/Containment.h
+++ b/pokebattle/Containment.h
@@ -38,20 +38,22 @@ class TeamMember;
class POKEBATTLE_EXPORT Containment : public QObject
{
Q_OBJECT
-
+
public:
-// const Player* player();
+ const Player* player();
+
+ QList<TeamMember*> members() const;
virtual bool isMutable() const = 0;
const Pokemod::Pokemod* pokemod() const;
signals:
- void teamKnockedOut();
public slots:
protected slots:
protected:
+ QList<TeamMember*> m_members;
private:
-// const Player* m_player;
+ const Player* m_player;
};
}
diff --git a/pokebattle/Player.h b/pokebattle/Player.h
index 928c1770..9f377e55 100644
--- a/pokebattle/Player.h
+++ b/pokebattle/Player.h
@@ -20,6 +20,7 @@
// Pokebattle includes
#include "Global.h"
+#include "TeamMember.h"
// Qt includes
#include <QtCore/QObject>
@@ -37,13 +38,14 @@ class Team;
class POKEBATTLE_EXPORT Player : public QObject
{
Q_OBJECT
-
+
public:
Player(Team* team);
const Pokemod::Pokemod* pokemod() const;
signals:
public slots:
+ virtual TeamMember::Action requestAction(const TeamMember* teamMember) const = 0;
protected slots:
protected:
Team* m_team;
diff --git a/pokebattle/Team.cpp b/pokebattle/Team.cpp
index bb519248..6a4adbb9 100644
--- a/pokebattle/Team.cpp
+++ b/pokebattle/Team.cpp
@@ -60,14 +60,8 @@
// if ((a < pokemon.size()) && pokemon[a]->CanFight())
// active = a;
// }
-//
-// unsigned Team::CanFight() const
-// {
-// unsigned alive = 0;
-// for (unsigned i = 0; (i < pokemon.size()) && !alive; ++i)
-// {
-// if (pokemon[i]->CanFight())
-// ++alive;
-// }
-// return alive;
-// }
+
+bool Pokebattle::Team::isMutable() const
+{
+ return true;
+}
diff --git a/pokebattle/Team.h b/pokebattle/Team.h
index b66471e1..b0b6605d 100644
--- a/pokebattle/Team.h
+++ b/pokebattle/Team.h
@@ -28,14 +28,13 @@ class POKEBATTLE_EXPORT Team : public Containment
Q_OBJECT
public:
-// const Player* player();
+ bool isMutable() const;
signals:
void teamKnockedOut();
public slots:
protected slots:
protected:
- private:
-// const Player* m_player;
+ QList<TeamMember*> m_members;
};
}
diff --git a/pokebattle/TeamMember.cpp b/pokebattle/TeamMember.cpp
index 98542d0e..3bdee896 100644
--- a/pokebattle/TeamMember.cpp
+++ b/pokebattle/TeamMember.cpp
@@ -20,6 +20,7 @@
// Pokebattle includes
#include "Containment.h"
+#include "Player.h"
// Pokemod includes
#include "../pokemod/Hat.h"
@@ -56,6 +57,7 @@ Pokebattle::TeamMember::TeamMember(const int speciesId, const QString& name, con
initItems();
initAbilities();
initMoves();
+ initNatures();
initStats();
if (species->genderFactor() <= 1)
m_gender = species->genderFactor().poll();
@@ -74,7 +76,7 @@ Pokebattle::TeamMember::TeamMember(const int speciesId, const QString& name, con
}
}
-Pokebattle::TeamMember::TeamMember(const Pokemod::MapTrainerTeamMember& teamMember, Containment* containment) :
+Pokebattle::TeamMember::TeamMember(const Pokemod::MapTrainerTeamMember* teamMember, Containment* containment) :
m_containment(containment)
{
// TODO: grab information from the class
@@ -117,15 +119,16 @@ int Pokebattle::TeamMember::statValue(const int stat, const int exp) const
}
else
statValue += m_dv[stat];
- statValue *= m_level;
- statValue /= 100;
+ statValue *= double(m_level) / pokemod()->rules()->maxLevel();
if (stat == Pokemod::ST_HP)
statValue += 10 + m_level;
else
{
statValue += 5;
- foreach (int natureId, m_natures)
- statValue *= pokemod()->natureById(natureId)->stat(stat);
+ Pokemod::Fraction multiplier;
+ foreach (int nature, m_natures)
+ multiplier *= pokemod()->natureById(nature)->stat(stat);
+ statValue *= multiplier;
}
return statValue;
}
@@ -136,7 +139,6 @@ int Pokebattle::TeamMember::calcExp(int level) const
level = m_level;
const int square = level * level;
const int cube = square * level;
- const double p[] = {0.000, 0.008, 0.014};
switch (pokemod()->speciesById(m_species)->growth())
{
case Pokemod::Species::Fluctuating:
@@ -160,6 +162,8 @@ int Pokebattle::TeamMember::calcExp(int level) const
case Pokemod::Species::Fast:
return 4 * cube / 5;
case Pokemod::Species::Erratic:
+ {
+ const double p[] = {0.000, 0.008, 0.014};
if (level <= 50)
return cube * ((100 - level) / 50.0);
else if (level <= 68)
@@ -171,6 +175,7 @@ int Pokebattle::TeamMember::calcExp(int level) const
// TODO: better way for further growth?
else
return 3 * cube / 5;
+ }
default:
break;
}
@@ -321,6 +326,11 @@ void Pokebattle::TeamMember::teachMove(const int move)
}
}
+Pokebattle::TeamMember::Action Pokebattle::TeamMember::requestAction() const
+{
+ return m_containment->player()->requestAction(this);
+}
+
const Pokemod::Pokemod* Pokebattle::TeamMember::pokemod() const
{
// TODO: get pokemod
@@ -372,8 +382,16 @@ void Pokebattle::TeamMember::initItems()
void Pokebattle::TeamMember::initAbilities()
{
m_abilities.clear();
- while (m_abilities.size())
- m_abilities.append(newAbility());
+ const Pokemod::Species* species = pokemod()->speciesById(m_species);
+ Pokemod::Hat<int> abilityHat;
+ for (int i = 0; i < species->abilityCount(); ++i)
+ {
+ const Pokemod::SpeciesAbility* ability = species->ability(i);
+ if (!m_abilities.contains(ability->ability()))
+ abilityHat.add(ability->ability(), ability->weight());
+ }
+ while (m_abilities.size() < pokemod()->rules()->maxAbilities())
+ m_abilities.append(abilityHat.takeAndClear());
}
void Pokebattle::TeamMember::initMoves()
@@ -382,12 +400,25 @@ void Pokebattle::TeamMember::initMoves()
m_moves.clear();
for (int i = 0; (i < species->moveCount()) && (m_moves.size() < pokemod()->rules()->maxMoves()); ++i)
{
- if ((species->move(i)->level() < m_level) && (0 <= species->move(i)->level()))
+ if (((species->move(i)->level() < m_level) && species->move(i)->level()) || (!m_containment->isMutable() && (species->move(i)->wild() < m_level)))
m_moves.append(species->move(i)->move());
}
Q_ASSERT(m_moves.size());
}
+void Pokebattle::TeamMember::initNatures()
+{
+ m_natures.clear();
+ Pokemod::Hat<int> natureHat;
+ for (int i = 0; i < pokemod()->natureCount(); ++i)
+ {
+ const Pokemod::Nature* nature = pokemod()->nature(i);
+ natureHat.add(nature->id(), nature->weight());
+ }
+ while (m_natures.size() < pokemod()->rules()->maxNatures())
+ m_natures.append(natureHat.takeAndClear());
+}
+
void Pokebattle::TeamMember::initStats()
{
if (pokemod()->rules()->specialDVSplit())
@@ -402,16 +433,3 @@ void Pokebattle::TeamMember::initStats()
m_dv[Pokemod::ST_HP] = ((m_dv[Pokemod::ST_Attack] & 1) << 3) + ((m_dv[Pokemod::ST_Defense] & 1) << 2) + ((m_dv[Pokemod::ST_Speed] & 1) << 1) + (m_dv[Pokemod::ST_Special] & 1);
}
}
-
-int Pokebattle::TeamMember::newAbility()
-{
- const Pokemod::Species* species = pokemod()->speciesById(m_species);
- Pokemod::Hat<int> abilityHat;
- for (int i = 0; i < species->abilityCount(); ++i)
- {
- const Pokemod::SpeciesAbility* ability = species->ability(i);
- if (!m_abilities.contains(ability->ability()))
- abilityHat.add(ability->ability(), ability->weight());
- }
- return abilityHat.pick();
-}
diff --git a/pokebattle/TeamMember.h b/pokebattle/TeamMember.h
index 85d10f26..609de823 100644
--- a/pokebattle/TeamMember.h
+++ b/pokebattle/TeamMember.h
@@ -25,8 +25,10 @@
#include "../pokemod/Global.h"
// Qt includes
+#include <QtCore/QFuture>
#include <QtCore/QList>
#include <QtCore/QObject>
+#include <QtCore/QPair>
#include <QtCore/QString>
// Forward declarations
@@ -45,8 +47,23 @@ class POKEBATTLE_EXPORT TeamMember : public QObject
Q_OBJECT
public:
+ enum ActionType
+ {
+ Attack = 0,
+ Item = 1,
+ Switch = 2,
+ Run = 3,
+ Undecided = 4,
+ Timeout = 5,
+ NoContact = 6,
+ End = 7
+ };
+
+ typedef QPair<ActionType, int> Action;
+ typedef QPair<TeamMember*, QFuture<TeamMember::Action> > RequestedAction;
+
TeamMember(const int speciesId, const QString& name, const int level, Containment* containment, const bool suppressItems = false);
- TeamMember(const Pokemod::MapTrainerTeamMember& teamMember, Containment* containment);
+ TeamMember(const Pokemod::MapTrainerTeamMember* teamMember, Containment* containment);
QString name() const;
int species() const;
@@ -86,6 +103,8 @@ class POKEBATTLE_EXPORT TeamMember : public QObject
void giveItem(const int item);
void forgetMove(const int moveIndex);
void teachMove(const int move);
+
+ Action requestAction() const;
protected slots:
void setSpecies(const int species);
void setLevel(const int level);
@@ -112,9 +131,8 @@ class POKEBATTLE_EXPORT TeamMember : public QObject
void initItems();
void initAbilities();
void initMoves();
+ void initNatures();
void initStats();
-
- int newAbility();
};
}
diff --git a/pokebattle/TurnArena.cpp b/pokebattle/TurnArena.cpp
index 2ec6eb55..a0ea2735 100644
--- a/pokebattle/TurnArena.cpp
+++ b/pokebattle/TurnArena.cpp
@@ -18,9 +18,31 @@
// Header include
#include "TurnArena.h"
+// Qt includes
+#include <QtCore/QtConcurrentMap>
+
Pokebattle::TurnArena::TurnArena(QList<Player*> players) :
Arena(players)
{
- emit(battleStart());
+ connect(this, SIGNAL(roundStart()), SLOT(processRound()));
+ setupBattle();
+}
+
+void Pokebattle::TurnArena::processRound()
+{
+// QFuture<TeamMember::Action> actions = QtConcurrent::mapped(m_players, requestDecision);
+ // TODO: timeout here?
+ // TODO: determine the (preliminary) order of attacks
+ // TODO: wait for all actions (unless timeout)
+ // TODO: get order again
+ // TODO: act out actions (ignoring those that faint along the way)
+ emit(roundEnd());
+ // TODO: If only one player left, battle is over
+ // TODO: restart round again
}
+void Pokebattle::TurnArena::setupBattle()
+{
+ // TODO: setup everything for the arena to do with the turns
+ Arena::setupBattle();
+}
diff --git a/pokebattle/TurnArena.h b/pokebattle/TurnArena.h
index 45fae44f..215bd3c1 100644
--- a/pokebattle/TurnArena.h
+++ b/pokebattle/TurnArena.h
@@ -20,6 +20,7 @@
// Pokebattle includes
#include "Arena.h"
+#include "TeamMember.h"
namespace Pokebattle
{
@@ -34,11 +35,9 @@ class POKEBATTLE_EXPORT TurnArena : public Arena
void roundEnd();
public slots:
protected slots:
- private:
- typedef QPair<ActionType, int> Action;
- typedef QPair<TeamMember*, Action> Decision;
-
- QList<Decision> m_decisions;
+ void processRound();
+ protected:
+ void setupBattle();
};
}
diff --git a/pokemod/Fraction.cpp b/pokemod/Fraction.cpp
index 26e114f9..0d69a889 100644
--- a/pokemod/Fraction.cpp
+++ b/pokemod/Fraction.cpp
@@ -22,6 +22,8 @@ void Pokemod::Fraction::reduce()
{
int i = m_numerator;
int j = m_denominator;
+ if (i < 0)
+ i = -i;
while (i - j)
(i > j) ? (i -= j) : (j -= i);
m_numerator /= i;
diff --git a/pokemod/Fraction.h b/pokemod/Fraction.h
index fce2aa34..c074ecbc 100644
--- a/pokemod/Fraction.h
+++ b/pokemod/Fraction.h
@@ -29,8 +29,7 @@ namespace Pokemod
class POKEMOD_EXPORT Fraction
{
public:
- Fraction();
- Fraction(const int numerator, const int denominator);
+ Fraction(const int numerator = 1, const int denominator = 1);
void set(const int numerator, const int denominator);
void setNumerator(const int numerator);
@@ -42,21 +41,27 @@ class POKEMOD_EXPORT Fraction
void reduce();
bool poll() const;
+ Fraction& operator=(const Fraction& rhs);
operator double() const;
+ Fraction operator+(const Fraction& rhs) const;
+ Fraction operator-(const Fraction& rhs) const;
Fraction operator*(const Fraction& rhs) const;
- Fraction& operator=(const Fraction& rhs);
+ Fraction operator/(const Fraction& rhs) const;
+ Fraction operator%(const Fraction& rhs) const;
+ Fraction& operator+=(const Fraction& rhs);
+ Fraction& operator-=(const Fraction& rhs);
+ Fraction& operator*=(const Fraction& rhs);
+ Fraction& operator/=(const Fraction& rhs);
+ Fraction& operator%=(const Fraction& rhs);
bool operator==(const Fraction& rhs) const;
bool operator!=(const Fraction& rhs) const;
+ protected:
+ void normalize();
private:
int m_numerator;
int m_denominator;
};
-inline Fraction::Fraction()
-{
- set(1, 1);
-}
-
inline Fraction::Fraction(const int numerator, const int denominator)
{
set(numerator, denominator);
@@ -66,6 +71,7 @@ inline void Fraction::set(const int numerator, const int denominator)
{
m_numerator = numerator;
m_denominator = denominator;
+ normalize();
}
inline void Fraction::setNumerator(const int numerator)
@@ -93,23 +99,58 @@ inline bool Fraction::poll() const
return (qrand() % m_denominator) < m_numerator;
}
+inline Fraction& Fraction::operator=(const Fraction& rhs)
+{
+ if (this == &rhs)
+ return *this;
+ m_numerator = rhs.m_numerator;
+ m_denominator = rhs.m_denominator;
+ return *this;
+}
+
inline Fraction::operator double() const
{
return (double(m_numerator) / m_denominator);
}
+inline Fraction Fraction::operator+(const Fraction& rhs) const
+{
+ return Fraction((m_numerator * rhs.m_denominator) + (m_denominator * rhs.m_numerator), m_denominator * rhs.m_denominator);
+}
+
+inline Fraction Fraction::operator-(const Fraction& rhs) const
+{
+ return Fraction((m_numerator * rhs.m_denominator) - (m_denominator * rhs.m_numerator), m_denominator * rhs.m_denominator);
+}
+
inline Fraction Fraction::operator*(const Fraction& rhs) const
{
return Fraction(m_numerator * rhs.m_numerator, m_denominator * rhs.m_denominator);
}
-inline Fraction& Fraction::operator=(const Fraction& rhs)
+inline Fraction Fraction::operator/(const Fraction& rhs) const
{
- if (this == &rhs)
- return *this;
- m_numerator = rhs.m_numerator;
- m_denominator = rhs.m_denominator;
- return *this;
+ return Fraction(m_numerator * rhs.m_denominator, m_denominator * rhs.m_numerator);
+}
+
+inline Fraction& Fraction::operator+=(const Fraction& rhs)
+{
+ return *this = *this + rhs;
+}
+
+inline Fraction& Fraction::operator-=(const Fraction& rhs)
+{
+ return *this = *this - rhs;
+}
+
+inline Fraction& Fraction::operator*=(const Fraction& rhs)
+{
+ return *this = *this * rhs;
+}
+
+inline Fraction& Fraction::operator/=(const Fraction& rhs)
+{
+ return *this = *this / rhs;
}
inline bool Fraction::operator==(const Fraction& rhs) const
@@ -122,6 +163,16 @@ inline bool Fraction::operator!=(const Fraction& rhs) const
return !(*this == rhs);
}
+inline void Fraction::normalize()
+{
+ if (m_denominator < 0)
+ {
+ m_denominator = -m_denominator;
+ m_numerator = -m_numerator;
+ }
+ reduce();
+}
+
}
Q_DECLARE_METATYPE(Pokemod::Fraction)
diff --git a/pokemod/Hat.h b/pokemod/Hat.h
index 03511028..9fa1a71b 100644
--- a/pokemod/Hat.h
+++ b/pokemod/Hat.h
@@ -34,24 +34,26 @@ template<class T> class Hat
T pick() const;
T take();
+ T takeAndClear();
void setCount(const T& key, const int weight);
void add(const T& key, const int weight);
- unsigned count() const;
- unsigned count(const T& key) const;
+ int distinctCount() const;
+ int count() const;
+ int count(const T& key) const;
double chance(const T& key) const;
- unsigned operator[](const T& key) const;
+ int operator[](const T& key) const;
private:
- QMap<T, unsigned> m_objects;
+ QMap<T, int> m_objects;
int m_count;
};
-template<class T> Hat<T>::Hat() :
+template<class T> inline Hat<T>::Hat() :
m_count(0)
{
}
-template<class T> T Hat<T>::pick() const
+template<class T> inline T Hat<T>::pick() const
{
int choice = qrand() % m_count;
foreach (T key, m_objects.keys())
@@ -63,16 +65,24 @@ template<class T> T Hat<T>::pick() const
return T();
}
-template<class T> T Hat<T>::take()
+template<class T> inline T Hat<T>::take()
{
T chosen = pick();
if (!(--m_objects[chosen]))
- m_objects.erase(chosen);
+ m_objects.remove(chosen);
--m_count;
return chosen;
}
-template<class T> void Hat<T>::setCount(const T& key, const int weight)
+template<class T> inline T Hat<T>::takeAndClear()
+{
+ T chosen = pick();
+ m_count -= m_objects[chosen];
+ m_objects.remove(chosen);
+ return chosen;
+}
+
+template<class T> inline void Hat<T>::setCount(const T& key, const int weight)
{
if (m_objects.contains(key))
m_count -= m_objects[key];
@@ -85,30 +95,36 @@ template<class T> void Hat<T>::setCount(const T& key, const int weight)
m_objects.remove(key);
}
-template<class T> void Hat<T>::add(const T& key, const int weight)
+template<class T> inline void Hat<T>::add(const T& key, const int weight)
{
+ Q_ASSERT(0 < weight);
m_objects[key] += weight;
m_count += weight;
}
-template<class T> unsigned Hat<T>::count() const
+template<class T> inline int Hat<T>::distinctCount() const
+{
+ return m_objects.size();
+}
+
+template<class T> inline int Hat<T>::count() const
{
return m_count;
}
-template<class T> unsigned Hat<T>::count(const T& key) const
+template<class T> inline int Hat<T>::count(const T& key) const
{
if (m_objects.contains(key))
return m_objects[key];
return 0;
}
-template<class T> double Hat<T>::chance(const T& key) const
+template<class T> inline double Hat<T>::chance(const T& key) const
{
return (double(count(key)) / m_count);
}
-template<class T> unsigned Hat<T>::operator[](const T& key) const
+template<class T> inline int Hat<T>::operator[](const T& key) const
{
return count(key);
}
diff --git a/pokemod/SpeciesMove.cpp b/pokemod/SpeciesMove.cpp
index 9c98f63b..0ae8401b 100644
--- a/pokemod/SpeciesMove.cpp
+++ b/pokemod/SpeciesMove.cpp
@@ -99,7 +99,7 @@ void Pokemod::SpeciesMove::setLevel(const int level)
void Pokemod::SpeciesMove::setWild(const int wild)
{
- if (qobject_cast<const Pokemod*>(pokemod())->rules()->maxLevel() <= wild)
+ if (!wild || (qobject_cast<const Pokemod*>(pokemod())->rules()->maxLevel() <= wild))
{
emit(error(bounds("wild")));
return;
diff --git a/pokemodr/Pokemodr.cpp b/pokemodr/Pokemodr.cpp
index 02794a85..bfee9d63 100644
--- a/pokemodr/Pokemodr.cpp
+++ b/pokemodr/Pokemodr.cpp
@@ -19,19 +19,12 @@
#include "Pokemodr.h"
// Pokemodr includes
-#include "FileDialog.h"
#include "PokemodrUI.h"
-// Qt includes
-#include <QtCore/QTextCodec>
-
// KDE includes
#include <KAboutData>
#include <KApplication>
#include <KCmdLineArgs>
-#include <KConfig>
-#include <KConfigGroup>
-#include <KStandardDirs>
static void messageHandler(QtMsgType type, const char* message)
{
@@ -56,21 +49,20 @@ int main(int argc, char* argv[])
{
qInstallMsgHandler(messageHandler);
- QTextCodec::setCodecForCStrings(QTextCodec::codecForLocale());
- KAboutData about("pokemodr", "pokemodr", ki18n("Pokémodr"), VERSION_STRING, ki18n(""), KAboutData::License_Custom, ki18n("©2007-2008 Ben Boeckel and Nerdy Productions"), ki18n("This program offers an easy interface so that PokéMods can be easily created."), "http://sourceforge.net/projects/pokegen");
+ KAboutData about("pokemodr", "pokemodr", ki18n("Pokémodr"), VERSION_STRING, ki18n(""), KAboutData::License_Custom, ki18n("©2007-2008 Ben Boeckel"), ki18n("This program offers an easy interface so that Pokémods can be easily created."), "http://sourceforge.net/projects/pokegen");
about.setLicenseTextFile("LICENSE");
about.setProgramName(ki18n("Pokémodr"));
about.addAuthor(ki18n("Ben Boeckel"), ki18n("Lead Programmer"), "MathStuf@gmail.com", "");
- about.addCredit(ki18n("Peter Fernandes"), ki18n("Ideas"), "supersonicandtails@gmail.com", "http://www.hypersonicsoft.org");
+ about.addCredit(ki18n("Peter Fernandes"), ki18n("Ideas, "), "supersonicandtails@gmail.com", "http://www.hypersonicsoft.org");
about.addCredit(ki18n("Kevin Kofler"), ki18n("Qt, KDE, debugging help"), "kevin.kofler@chello.at", "http://www.tigen.org/kevin.kofler");
- about.addCredit(ki18n("Luke Greco"), ki18n("Ideas"), "sirlewk@gmail.com", "");
+ about.addCredit(ki18n("Luke Greco"), ki18n("Ideas, debugging"), "sirlewk@gmail.com", "");
KCmdLineArgs::init(argc, argv, &about);
KCmdLineOptions options;
options.add("+[files]", ki18n("Files to open"));
KCmdLineArgs::addCmdLineOptions(options);
- KApplication* app = new KApplication();
+ KApplication* app = new KApplication;
Pokemodr::PokemodrUI* mainWindow = new Pokemodr::PokemodrUI;
mainWindow->show();
diff --git a/pokemodr/gui/speciesmove.ui b/pokemodr/gui/speciesmove.ui
index 195df075..04b5ecc3 100644
--- a/pokemodr/gui/speciesmove.ui
+++ b/pokemodr/gui/speciesmove.ui
@@ -66,7 +66,7 @@
<item>
<widget class="KIntNumInput" name="varWildLevel" >
<property name="minimum" >
- <number>0</number>
+ <number>1</number>
</property>
</widget>
</item>
diff --git a/pokescripting/Config.h b/pokescripting/Config.h
index 4a186f96..071c6c77 100644
--- a/pokescripting/Config.h
+++ b/pokescripting/Config.h
@@ -19,10 +19,10 @@
#define __POKESCRIPTING_CONFIG__
// Qt includes
-#include <QMap>
-#include <QObject>
-#include <QString>
-#include <QVariant>
+#include <QtCore/QMap>
+#include <QtCore/QObject>
+#include <QtCore/QString>
+#include <QtCore/QVariant>
// Forward declarations
namespace Pokemod