Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10157 was 10157, checked in by maxima, 9 years ago

Changes of Phillip. He couldn't upload himself. New Campaign Menu added.

  • Property svn:eol-style set to native
File size: 7.0 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                myfile.open("/home/pmao/pmao-extra-0/orxonox/storymodeHS14/data/gui/scripts/campaign.txt");
85                std::string line;
86                std::string mission=this->getFilename();
87                int k=58-mission.length();
88                std::string helperstring = "";
89                if(myfile.is_open()){
90                        while (k>1) {
91                                helperstring=helperstring+" ";
92                                k=k-1;
93                        }
94                        helperstring=helperstring+".";
95                       while(getline (myfile,line)){
96                          if(line==mission+" 0"+helperstring){
97                                  long pos = myfile.tellp();
98                                  myfile.seekp (pos-61);
99                                  myfile << mission+" 1"+helperstring;
100                          }
101                        }}
102                else{
103                        this->end();
104                }
105                        myfile.flush();
106                        myfile.clear();
107                        myfile.close();
108        Gametype::start();
109        this->setTeams();
110
111        this->gtinfo_->sendAnnounceMessage("Your mission has started!");
112    }
113
114    std::string GenerateHelperString(int number){
115        std::string helperstring = "";
116        while (number>1) {
117                helperstring=helperstring+" ";
118                number=number-1;
119        }
120        helperstring=helperstring+".";
121        return helperstring;
122    }
123
124    void Mission::end()
125    {
126
127        if (this->missionAccomplished_ && !this->gtinfo_->hasEnded()){
128            this->gtinfo_->sendAnnounceMessage("Mission accomplished!");
129            std::fstream myfile;
130                                myfile.open("/home/pmao/pmao-extra-0/orxonox/storymodeHS14/data/gui/scripts/campaign.txt");
131                                std::string line;
132                                std::string mission=this->getFilename();
133                                int k=58-mission.length();
134                                std::string helperstring = "";
135                                if(myfile.is_open()){
136                                        while (k>1) {
137                                                helperstring=helperstring+" ";
138                                                k=k-1;
139                                        }
140                                        helperstring=helperstring+".";
141                                       while(getline (myfile,line)){
142                                          if(line==mission+" 0"+helperstring){
143                                                  long pos = myfile.tellp();
144                                                  myfile.seekp (pos-61);
145                                                  myfile << mission+" 1"+helperstring;
146                                          }
147                                        }}
148                                        myfile.flush();
149                                        myfile.clear();
150                                        myfile.close();
151                  }
152
153        else if (!this->gtinfo_->hasEnded())
154            this->gtinfo_->sendAnnounceMessage("Mission failed!");
155        Gametype::end();
156    }
157
158    void Mission::setTeams()
159    {//Set pawn-colours
160        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it)
161        {
162            Pawn* pawn = static_cast<Pawn*>(*it);
163            if(!pawn) continue;
164                this->setDefaultObjectColour(pawn);
165        }
166    }
167    void Mission::endMission(bool accomplished)
168    {
169        for (ObjectList<Mission>::iterator it = ObjectList<Mission>::begin(); it != ObjectList<Mission>::end(); ++it)
170        {//TODO: make sure that only the desired mission is ended !! This is a dirty HACK, that would end ALL missions!
171            if(accomplished){
172                std::fstream myfile;
173                        myfile.open("/home/pmao/pmao-extra-0/orxonox/storymodeHS14/data/gui/scripts/campaign.txt");
174                        std::string line;
175                        std::string mission=it->getFilename();
176                        int k=58-mission.length();
177                    std::string helperstring = "";
178                    if(myfile.is_open()){
179                        while (k>1) {
180                                helperstring=helperstring+" ";
181                            k=k-1;
182                                    }
183                    helperstring=helperstring+".";
184                        while(getline (myfile,line)){
185                                if(line==mission+" 0"+helperstring){
186                                long pos = myfile.tellp();
187                            myfile.seekp (pos-61);
188                            myfile << mission+" 1"+helperstring;
189                                          }
190                        }
191                    }
192                    myfile.flush();
193                    myfile.clear();
194                    myfile.close();
195            }
196                it->setMissionAccomplished(accomplished);
197            it->end();
198
199        }
200    }
201
202    void Mission::setLivesWrapper(unsigned int amount)
203    {
204        for (ObjectList<Mission>::iterator it = ObjectList<Mission>::begin(); it != ObjectList<Mission>::end(); ++it)
205        {//TODO: make sure that only the desired mission is ended !! This is a dirty HACK, that would affect ALL missions!
206            it->setLives(amount);
207        }
208    }
209
210
211}
Note: See TracBrowser for help on using the repository browser.