Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

use relative path

  • Property svn:eol-style set to native
File size: 5.4 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 "infos/PlayerInfo.h"
39#include "network/Host.h"
40#include "worldentities/pawns/Pawn.h"
41#include <iostream>
42#include <fstream>
43#include <string>
44#include <ios>
45
46namespace orxonox
47{
48    SetConsoleCommand("Mission", "endMission", &Mission::endMission);
49    SetConsoleCommand("Mission", "setLives", &Mission::setLivesWrapper);
50    RegisterUnloadableClass(Mission);
51
52    Mission::Mission(Context* context) : TeamGametype(context)
53    {
54        RegisterObject(Mission);
55        this->missionAccomplished_ = false;
56        this->lives_ = 10; // should be 1 as default value
57        this->numberOfBots_ = 0; //sets number of default bots temporarly to 0
58    }
59
60    void Mission::tick(float dt)
61    {
62        SUPER(Mission, tick, dt);
63
64        if (missionAccomplished_)
65        {
66            this->gtinfo_->sendAnnounceMessage("Mission accomplished!");
67            this->end();
68        }
69        else if (this->lives_ == 0)
70        {
71            this->missionAccomplished_ = false;
72            this->end();
73        }
74    }
75
76    void Mission::pawnKilled(Pawn* victim, Pawn* killer)
77    {
78        if (victim && victim->getPlayer() && victim->getPlayer()->isHumanPlayer())
79        {
80            this->lives_--;
81        }
82    }
83
84    void Mission::start()
85    {
86        std::fstream myfile;
87
88        Gametype::start();
89        this->setTeams();
90        //just for testing
91        //this->missionAccomplished_=true;
92        this->gtinfo_->sendAnnounceMessage("Your mission has started!");
93    }
94
95    std::string GenerateHelperString(int number)
96    {
97        std::string helperstring = "";
98        while (number > 1)
99        {
100            helperstring = helperstring + " ";
101            number = number - 1;
102        }
103        helperstring = helperstring + ".";
104        return helperstring;
105    }
106
107    void Mission::end()
108    {
109
110        if (this->missionAccomplished_ && !this->gtinfo_->hasEnded())
111        {
112            this->gtinfo_->sendAnnounceMessage("Mission accomplished!");
113
114            boost::filesystem::path filepath("campaign.txt");
115            std::fstream myfile;
116            myfile.open(filepath.string().c_str(), std::fstream::out);
117
118            std::string line;
119            std::string mission = this->getFilename();
120            int k = 58 - mission.length();
121            std::string helperstring = "";
122            if (myfile.is_open())
123            {
124                while (k > 1)
125                {
126                    helperstring = helperstring + " ";
127                    k = k - 1;
128                }
129                helperstring = helperstring + ".";
130                while (getline(myfile, line))
131                {
132                    if (line == mission + " 0" + helperstring)
133                    {
134                        long pos = (long) myfile.tellp();
135                        myfile.seekp(pos - 61);
136                        myfile << mission + " 1" + helperstring;
137                    }
138                }
139            } else {
140                orxout(internal_warning) << "failed to open campaign file" << endl;
141            }
142            myfile.flush();
143            myfile.clear();
144            myfile.close();
145        }
146
147        else if (!this->gtinfo_->hasEnded())
148            this->gtinfo_->sendAnnounceMessage("Mission failed!");
149        Gametype::end();
150    }
151
152    void Mission::setTeams()
153    { //Set pawn-colours
154        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it)
155        {
156            Pawn* pawn = static_cast<Pawn*>(*it);
157            if (!pawn)
158                continue;
159            this->setDefaultObjectColour(pawn);
160        }
161    }
162    void Mission::endMission(bool accomplished)
163    {
164        for (ObjectList<Mission>::iterator it = ObjectList<Mission>::begin(); it != ObjectList<Mission>::end(); ++it)
165        { //TODO: make sure that only the desired mission is ended !! This is a dirty HACK, that would end ALL missions!
166            it->setMissionAccomplished(accomplished);
167            it->end();
168
169        }
170    }
171
172    void Mission::setLivesWrapper(unsigned int amount)
173    {
174        for (ObjectList<Mission>::iterator it = ObjectList<Mission>::begin(); it != ObjectList<Mission>::end(); ++it)
175        { //TODO: make sure that only the desired mission is ended !! This is a dirty HACK, that would affect ALL missions!
176            it->setLives(amount);
177        }
178    }
179
180}
Note: See TracBrowser for help on using the repository browser.