Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Making the setLives function more flexible. The game can be immediately ended by setting the lives to zero.

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