Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/output/src/modules/gametypes/SpaceRace.cc @ 8740

Last change on this file since 8740 was 8740, checked in by landauf, 13 years ago

fixed some warnings, added vs to ignore list

  • Property svn:eol-style set to native
File size: 3.8 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 *     Mauro Salomon
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "SpaceRace.h"
30
31#include "core/CoreIncludes.h"
32#include "network/Host.h"
33#include <util/Clock.h>
34#include <util/Math.h>
35#include "util/Convert.h"
36
37namespace orxonox
38{
39    CreateUnloadableFactory(SpaceRace);
40   
41    SpaceRace::SpaceRace(BaseObject* creator) : Gametype(creator)
42    {
43        RegisterObject(SpaceRace);
44        this->bCheckpointsReached_ = 0;
45        this->bTimeIsUp_ = false;
46        this->numberOfBots_ = 0;
47    }
48   
49    void SpaceRace::end()
50    {
51        this->Gametype::end();
52         
53        if (this->bTimeIsUp_)
54        {
55            this->clock_.capture();
56            int s = this->clock_.getSeconds();
57            int ms = static_cast<int>(this->clock_.getMilliseconds()-1000*s);
58            const std::string& message = multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds !!\n"
59                        + "You didn't reach the check point " + multi_cast<std::string>(this->bCheckpointsReached_+1)
60                        + " before the time limit. You lose!";
61            COUT(3) << message;
62            const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
63            Host::Broadcast(message);
64        }
65        else
66        {
67            this->clock_.capture();
68            int s = this->clock_.getSeconds();
69            int ms = static_cast<int>(this->clock_.getMilliseconds()-1000*s);
70            const std::string& message = "You win!! You have reached the last check point after "+ multi_cast<std::string>(s)
71                        + "." + multi_cast<std::string>(ms) + " seconds.";
72            COUT(3) << message << std::endl;
73            const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
74            Host::Broadcast(message);
75            float time = this->clock_.getSecondsPrecise();
76            this->scores_.insert(time);
77            std::set<float>::iterator it;
78            for (it=this->scores_.begin(); it!=this->scores_.end(); it++)
79            COUT(3) <<  multi_cast<std::string>(*it) << std::endl;
80        }
81    }
82
83    void SpaceRace::start()
84    {
85        Gametype::start();
86
87        std::string message("The match has started! Reach the check points as quickly as possible!");
88        COUT(3) << message << std::endl;
89        Host::Broadcast(message);
90    }
91   
92    void SpaceRace::newCheckpointReached()
93    {
94        this->bCheckpointsReached_++;
95        this->clock_.capture();
96        int s = this->clock_.getSeconds();
97        int ms = static_cast<int>(this->clock_.getMilliseconds()-1000*s);
98        const std::string& message = "Checkpoint " + multi_cast<std::string>(this->getCheckpointsReached())
99                        + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms)
100                        + " seconds.\n";
101        COUT(3) << message;
102        const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
103        Host::Broadcast(message);
104    }
105
106}
Note: See TracBrowser for help on using the repository browser.