Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9728 was 9728, checked in by jo, 11 years ago

Making a Mission endable by a ConsoleCommand such that it can be ended from within a level.

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