Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

autoformatted code and removed commented block

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