summaryrefslogtreecommitdiffstats
path: root/sigencore/Arena.h
blob: f38efb2ac5a35945156a9dff2013b4f5a025f96a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
 * Copyright 2007-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 SIGENCORE_ARENA
#define SIGENCORE_ARENA

// Sigencore includes
#include "Global.h"
#include "TeamMember.h"

// Sigscript includes
#include <sigscript/Config.h>

// Qt includes
#include <QtCore/QList>
#include <QtCore/QMap>
#include <QtCore/QMetaType>
#include <QtCore/QPair>
#include <QtCore/QUuid>

// Forward declarations
class QGraphicsScene;
namespace Kross
{
class Action;
class ActionCollection;
}
namespace Sigcore
{
class Script;
}
namespace Sigscript
{
class GameWrapper;
class WeatherWrapper;
}

namespace Sigencore
{
class Client;
class Player;
class Team;

class SIGENCORE_EXPORT Arena : public Sigscript::Config
{
    Q_OBJECT
    Q_ENUMS(State)
    
    public:
        enum State
        {
            Setup = 0,
            InProgress = 1,
            Completed = 2
        };
        
        typedef QPair<int, int> Spoil;
        static const int Spectator;
        static const int Fighters;
        static const int AllTeams;
        static const int NoTeam;
        
        Q_SCRIPTABLE Sigscript::GameWrapper* game() const;
        
        Q_SCRIPTABLE QList<TeamMember*> active(const int team) const;
        Q_SCRIPTABLE QList<TeamMember*> active(Client* client) const;
        Q_SCRIPTABLE QList<Client*> teamPlayers(const int team) const;
        Q_SCRIPTABLE Player* player(TeamMember* teamMember) const;
        Q_SCRIPTABLE int team(Client* client) const;
        Q_SCRIPTABLE int team(TeamMember* teamMember) const;
        Q_SCRIPTABLE int numTeams() const;
        Q_SCRIPTABLE int numPlayers() const;
        Q_SCRIPTABLE int numTeamMembers() const;
        
        Q_SCRIPTABLE State state() const;
        
        Q_SCRIPTABLE QList<Sigscript::WeatherWrapper*> weathers() const;
        Q_SCRIPTABLE void setWeather(TeamMember* teamMember, Sigscript::WeatherWrapper* weather);
        Q_SCRIPTABLE bool unsetWeather(Sigscript::WeatherWrapper* weather);
    public slots:
        bool addClient(Client* client, const int team);
        void removeClient(Client* client);
    signals:
        void battleAboutToStart();
        void battleStarted();
        void battleAboutToEnd();
        void battleEnded();
        
        void cleanupArena();
        
        void aboutToClearActions();
        
        void weatherStarted(TeamMember* teamMember, Sigscript::WeatherWrapper* weather);
        void weatherEnded(Sigscript::WeatherWrapper* weather);
        
        void clientAdded(Sigencore::Client* client, const int team);
        void clientRemoved(Sigencore::Client* client, const int team);
    protected:
        Arena(Sigscript::GameWrapper* game, Sigscript::Config* parent);
        virtual ~Arena();
        
        virtual void handleAction(TeamMember* teamMember, TeamMember::Action action);
        
        virtual bool isTeamAllowed(Team* team) = 0;
        
        virtual void setupBattle();
        
        virtual void distributeWinnings();
        virtual void checkForLosers();
        
        TeamMember* findMember(const QUuid& id);
        
        Sigscript::GameWrapper* m_game;
        QMap<Client*, int> m_teams;
        Kross::ActionCollection* m_actions;
        QMap<Sigscript::WeatherWrapper*, Kross::Action*> m_weathers;
        QMap<Player*, Spoil> m_spoils;
        QList<Player*> m_losers;
    protected slots:
        virtual void registerScript(const Sigcore::Script& script);
        
        virtual void cleanUp();
    private:
        State m_state;
        const QUuid m_id;
};

SIGENCORE_EXPORT TeamMember::RequestedAction requestDecision(TeamMember* teamMember);
SIGENCORE_EXPORT TeamMember::Action decision(Player* player, TeamMember* teamMember);

}
Q_DECLARE_METATYPE(Sigencore::Arena*)
Q_DECLARE_METATYPE(Sigencore::Arena::State)

#endif