Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/gametypes/Mission.cc @ 10624

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

merged branch core7 back to trunk

  • Property svn:eol-style set to native
File size: 3.9 KB
RevLine 
[8904]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 *      Johannes Ritz
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "Mission.h"
[10258]30
[8923]31#include "items/Engine.h"
[8941]32#include "controllers/ArtificialController.h"
[8904]33
34#include "core/CoreIncludes.h"
[10624]35#include "core/command/ConsoleCommandIncludes.h"
[9729]36#include "infos/PlayerInfo.h"
[8904]37#include "network/Host.h"
38#include "worldentities/pawns/Pawn.h"
[10258]39#include "LevelManager.h"
[8904]40
41namespace orxonox
42{
[9728]43    SetConsoleCommand("Mission", "endMission", &Mission::endMission);
[9729]44    SetConsoleCommand("Mission", "setLives", &Mission::setLivesWrapper);
[9667]45    RegisterUnloadableClass(Mission);
[8904]46
[9667]47    Mission::Mission(Context* context) : TeamGametype(context)
[8904]48    {
49        RegisterObject(Mission);
50        this->missionAccomplished_ = false;
51        this->lives_ = 10; // should be 1 as default value
52        this->numberOfBots_ = 0; //sets number of default bots temporarly to 0
53    }
54
55    void Mission::tick(float dt)
56    {
57        SUPER(Mission, tick, dt);
58
59        if (missionAccomplished_)
60        {
61            this->gtinfo_->sendAnnounceMessage("Mission accomplished!");
62            this->end();
63        }
[9730]64        else if (this->lives_ == 0)
65        {
66            this->missionAccomplished_ = false;
67            this->end();
68        }
[8904]69    }
70
71    void Mission::pawnKilled(Pawn* victim, Pawn* killer)
72    {
[10258]73        if (victim && victim->getPlayer() && victim->getPlayer()->isHumanPlayer())
[8904]74        {
[9729]75            this->lives_--;
[8904]76        }
77    }
78
79    void Mission::start()
80    {
81        Gametype::start();
[8941]82        this->setTeams();
[8997]83
[8904]84        this->gtinfo_->sendAnnounceMessage("Your mission has started!");
85    }
86
87    void Mission::end()
88    {
[9986]89        if (this->missionAccomplished_ && !this->gtinfo_->hasEnded())
[10258]90        {
[8904]91            this->gtinfo_->sendAnnounceMessage("Mission accomplished!");
[10258]92
93            LevelManager::getInstance().setLastFinishedCampaignMission(this->getFilename());
94        }
[9986]95        else if (!this->gtinfo_->hasEnded())
[8904]96            this->gtinfo_->sendAnnounceMessage("Mission failed!");
[10258]97
[9986]98        Gametype::end();
[8904]99    }
[8941]100
101    void Mission::setTeams()
[10258]102    { //Set pawn-colours
[8941]103        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it)
[8942]104        {
105            Pawn* pawn = static_cast<Pawn*>(*it);
[10258]106            if (!pawn)
107                continue;
108            this->setDefaultObjectColour(pawn);
[8942]109        }
[8941]110    }
[9728]111    void Mission::endMission(bool accomplished)
112    {
113        for (ObjectList<Mission>::iterator it = ObjectList<Mission>::begin(); it != ObjectList<Mission>::end(); ++it)
[10258]114        { //TODO: make sure that only the desired mission is ended !! This is a dirty HACK, that would end ALL missions!
[9728]115            it->setMissionAccomplished(accomplished);
116            it->end();
117        }
118    }
[10258]119
[9729]120    void Mission::setLivesWrapper(unsigned int amount)
121    {
122        for (ObjectList<Mission>::iterator it = ObjectList<Mission>::begin(); it != ObjectList<Mission>::end(); ++it)
[10258]123        { //TODO: make sure that only the desired mission is ended !! This is a dirty HACK, that would affect ALL missions!
[9729]124            it->setLives(amount);
125        }
126    }
[8904]127}
Note: See TracBrowser for help on using the repository browser.