Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 11847 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
RevLine 
[10097]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"
[10101]43#include "core/EventIncludes.h"
[10097]44#include "core/command/Executor.h"
45#include "core/config/ConfigValueIncludes.h"
[10101]46#include "infos/PlayerInfo.h"
[10624]47#include "core/command/ConsoleCommandIncludes.h"
[10097]48
49#include "gamestates/GSLevel.h"
50#include "chat/ChatManager.h"
51
52namespace orxonox
53{
54
[10230]55    SetConsoleCommand("Mini4Dgame", "setStone", &Mini4Dgame::setStone).addShortcut();
56    SetConsoleCommand("Mini4Dgame", "undoStone", &Mini4Dgame::undoStone).addShortcut();
[10131]57
[10097]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
[11071]68        this->board_ = nullptr;
[10131]69
70        // Set the type of Bots for this particular Gametype.
71        //this->botclass_ = Class(Mini4DgameBot);
[10097]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    {
[11071]90        if(this->board_ != nullptr)// Destroy the board, if present.
[10230]91        {
92            //this->board_->destroy();
[11071]93            this->board_ = nullptr;
[10230]94        }
[10097]95    }
96
97    /**
98    @brief
[10131]99        Starts the mini4Dgame.
[10097]100    */
101    void Mini4Dgame::start()
102    {
[11071]103        if (this->board_ != nullptr) // There needs to be a Mini4DgameCenterpoint, i.e. the area the game takes place.
[10097]104        {
[10230]105            /*
[11071]106            if (this->board_ == nullptr)
[10230]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            */
[10131]113
[10230]114            // Attach the board to the centerpoint and set the parameters as specified in the centerpoint, the ball is attached to.
[10156]115
[10230]116            this->board_->setPosition(0, 0, 0);
[10131]117
[10097]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    {
[10230]143        this->cleanup();
[10097]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    {
[10100]156        // first spawn human players to assign always the left bat to the player in singleplayer
[11071]157        for (const auto& mapEntry : this->players_)
158            if (mapEntry.first->isHumanPlayer() && (mapEntry.first->isReadyToSpawn() || this->bForceSpawn_))
159                this->spawnPlayer(mapEntry.first);
[10100]160        // now spawn bots
[11071]161        for (const auto& mapEntry : this->players_)
162            if (!mapEntry.first->isHumanPlayer() && (mapEntry.first->isReadyToSpawn() || this->bForceSpawn_))
163                this->spawnPlayer(mapEntry.first);
[10097]164    }
165
166    /**
167    @brief
168        Spawns the input player.
169    @param player
170        The player to be spawned.
171    */
[10100]172    void Mini4Dgame::spawnPlayer(PlayerInfo* player)
[10097]173    {
174        assert(player);
175
[11071]176        if(false)//this->player_ == nullptr)
[10097]177        {
[10100]178            //this->player_ = player;
[10097]179            this->players_[player].state_ = PlayerState::Alive;
180        }
181    }
182
[10168]183    void Mini4Dgame::undoStone()//Vector4 move, const int playerColor)
184    {
[11071]185        ObjectList<Mini4DgameBoard>::iterator it = ObjectList<Mini4DgameBoard>().begin();
[10168]186        it->undoMove();
187    }
188
[10156]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)
[10131]191    {
[10229]192        Mini4DgamePosition move = Mini4DgamePosition(x,y,z,w);
[11071]193        ObjectList<Mini4DgameBoard>::iterator it = ObjectList<Mini4DgameBoard>().begin();
[10168]194        it->makeMove(move);
[10131]195    }
[10097]196
[10131]197    void Mini4Dgame::win(Mini4DgameWinner winner)
198    {
199
200    }
[10097]201}
Note: See TracBrowser for help on using the repository browser.