Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/spacerace/src/modules/gametypes/SpaceRace.cc @ 8552

Last change on this file since 8552 was 8552, checked in by msalomon, 13 years ago
File size: 3.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 *     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->checkpointsReached_ = 0;
45        this->bTimeIsUp_ = false;
46        this->numberOfBots_ = 0;
47    }
48   
49    void SpaceRace::tick(float dt)
50    {
51        Gametype::tick(dt);
52    }
53   
54    void SpaceRace::end()
55    {
56        Gametype::end();
57        this->stopTimer();
58        if (this->bTimeIsUp_) {
59            COUT(0) << "Time is up" << std::endl;
60            const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage("Time is up");
61        }
62        else {
63            this->clock_->capture();
64            int s = this->clock_->getSeconds();
65            int ms = this->clock_->getMilliseconds()-1000*s;
66            const std::string& message = "You have reached the last check point after "+ multi_cast<std::string>(s) +
67                                          "." + multi_cast<std::string>(ms) + " seconds.";
68            COUT(0) << message << std::endl;
69            const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
70            Host::Broadcast(message);
71            float time = this->clock_->getSecondsPrecise();
72            this->scores_.insert(time);
73            std::set<float>::iterator it;
74            for (it=this->scores_.begin(); it!=this->scores_.end(); it++)
75            COUT(0) <<  multi_cast<std::string>(*it) << std::endl;
76        }
77    }
78
79    void SpaceRace::start()
80    {
81        Gametype::start();
82       
83        this->startTimer();
84        clock_= new Clock();
85        std::string message("The match has started! Reach the check points as quick as possible!");
86        COUT(0) << message << std::endl;
87        Host::Broadcast(message);
88    }
89   
90    void SpaceRace::newCheckpointReached()
91    {
92        this->checkpointsReached_++;
93        this->clock_->capture();
94        int s = this->clock_->getSeconds();
95        int ms = this->clock_->getMilliseconds()-1000*s;
96        const std::string& message = "Checkpoint " + multi_cast<std::string>(this->getCheckpointsReached()) 
97                                      + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms)
98                                      + " seconds.";
99        COUT(0) << message << std::endl;
100        const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
101        Host::Broadcast(message);
102    }
103
104}
Note: See TracBrowser for help on using the repository browser.