Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/mini4dgame/Mini4Dgame.cc @ 12146

Last change on this file since 12146 was 11071, checked in by landauf, 9 years ago

merged branch cpp11_v3 back to trunk

  • Property svn:eol-style set to native
File size: 5.5 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      ...
24 *   Co-authors:
25 *      Johannes Ritz
26 *
27 *
28 *
29 *
30 *TASK c) end the game in a nicer way
31 *TASK d) save the highscore
32 *TASK e) eye candy
33 */
34
35/**
36    @file Tetris.cc
37    @brief Implementation of the Mini4Dgame class.
38*/
39
40#include "Mini4Dgame.h"
41
42#include "core/CoreIncludes.h"
43#include "core/EventIncludes.h"
44#include "core/command/Executor.h"
45#include "core/config/ConfigValueIncludes.h"
46#include "infos/PlayerInfo.h"
47#include "core/command/ConsoleCommandIncludes.h"
48
49#include "gamestates/GSLevel.h"
50#include "chat/ChatManager.h"
51
52namespace orxonox
53{
54
55    SetConsoleCommand("Mini4Dgame", "setStone", &Mini4Dgame::setStone).addShortcut();
56    SetConsoleCommand("Mini4Dgame", "undoStone", &Mini4Dgame::undoStone).addShortcut();
57
58    RegisterUnloadableClass(Mini4Dgame);
59
60    /**
61    @brief
62        Constructor. Registers and initializes the object.
63    */
64    Mini4Dgame::Mini4Dgame(Context* context) : Deathmatch(context)
65    {
66        RegisterObject(Mini4Dgame);
67
68        this->board_ = nullptr;
69
70        // Set the type of Bots for this particular Gametype.
71        //this->botclass_ = Class(Mini4DgameBot);
72    }
73
74    /**
75    @brief
76        Destructor. Cleans up, if initialized.
77    */
78    Mini4Dgame::~Mini4Dgame()
79    {
80        if (this->isInitialized())
81            this->cleanup();
82    }
83
84    /**
85    @brief
86        Cleans up the Gametype.
87    */
88    void Mini4Dgame::cleanup()
89    {
90        if(this->board_ != nullptr)// Destroy the board, if present.
91        {
92            //this->board_->destroy();
93            this->board_ = nullptr;
94        }
95    }
96
97    /**
98    @brief
99        Starts the mini4Dgame.
100    */
101    void Mini4Dgame::start()
102    {
103        if (this->board_ != nullptr) // There needs to be a Mini4DgameCenterpoint, i.e. the area the game takes place.
104        {
105            /*
106            if (this->board_ == nullptr)
107            {
108                this->board_ = new Mini4DgameBoard(this->board_->getContext());
109                // Apply the template for the ball specified by the centerpoint.
110                this->board_->addTemplate(this->center_->getBoardtemplate());
111            }
112            */
113
114            // Attach the board to the centerpoint and set the parameters as specified in the centerpoint, the ball is attached to.
115
116            this->board_->setPosition(0, 0, 0);
117
118        }
119        else // If no centerpoint was specified, an error is thrown and the level is exited.
120        {
121            orxout(internal_error) << "Mini4Dgame: No Centerpoint specified." << endl;
122            GSLevel::startMainMenu();
123            return;
124        }
125
126        // Set variable to temporarily force the player to spawn.
127        bool temp = this->bForceSpawn_;
128        this->bForceSpawn_ = true;
129
130        // Call start for the parent class.
131        Deathmatch::start();
132
133        // Reset the variable.
134        this->bForceSpawn_ = temp;
135    }
136
137    /**
138    @brief
139        Ends the Mini4Dgame minigame.
140    */
141    void Mini4Dgame::end()
142    {
143        this->cleanup();
144
145        // Call end for the parent class.
146        Deathmatch::end();
147    }
148
149
150    /**
151    @brief
152        Spawns player.
153    */
154    void Mini4Dgame::spawnPlayersIfRequested()
155    {
156        // first spawn human players to assign always the left bat to the player in singleplayer
157        for (const auto& mapEntry : this->players_)
158            if (mapEntry.first->isHumanPlayer() && (mapEntry.first->isReadyToSpawn() || this->bForceSpawn_))
159                this->spawnPlayer(mapEntry.first);
160        // now spawn bots
161        for (const auto& mapEntry : this->players_)
162            if (!mapEntry.first->isHumanPlayer() && (mapEntry.first->isReadyToSpawn() || this->bForceSpawn_))
163                this->spawnPlayer(mapEntry.first);
164    }
165
166    /**
167    @brief
168        Spawns the input player.
169    @param player
170        The player to be spawned.
171    */
172    void Mini4Dgame::spawnPlayer(PlayerInfo* player)
173    {
174        assert(player);
175
176        if(false)//this->player_ == nullptr)
177        {
178            //this->player_ = player;
179            this->players_[player].state_ = PlayerState::Alive;
180        }
181    }
182
183    void Mini4Dgame::undoStone()//Vector4 move, const int playerColor)
184    {
185        ObjectList<Mini4DgameBoard>::iterator it = ObjectList<Mini4DgameBoard>().begin();
186        it->undoMove();
187    }
188
189    //void Mini4Dgame::setStone(Vector4 move, const int playerColor, Mini4DgameBoard* board)
190    void Mini4Dgame::setStone(int x,int y,int z,int w)//Vector4 move, const int playerColor)
191    {
192        Mini4DgamePosition move = Mini4DgamePosition(x,y,z,w);
193        ObjectList<Mini4DgameBoard>::iterator it = ObjectList<Mini4DgameBoard>().begin();
194        it->makeMove(move);
195    }
196
197    void Mini4Dgame::win(Mini4DgameWinner winner)
198    {
199
200    }
201}
Note: See TracBrowser for help on using the repository browser.