Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Final version for presentation.

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