Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/storymodeHS14/src/orxonox/gametypes/Mission.cc @ 10253

Last change on this file since 10253 was 10253, checked in by landauf, 5 years ago

improved campaign mode. use config value instead of writing a new file.
moved configuration of campaign (the list of missions) from the lua file to the default config. you need to delete your local orxonox.ini in order to see the changes.

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