Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 9, 2017, 4:22:19 PM (7 years ago)
Author:
patricwi
Message:

space race merged

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/modules/gametypes/SpaceRace.cc

    r11071 r11358  
    2323 *     Mauro Salomon
    2424 *   Co-authors:
    25  *      Celine Egger
    26  *
    27  */
     25 *      Celine Egger*/
     26       
     27
     28
     29
     30/*
     31Edited, Renewed and Revised by
     32        Berkay Berabi
     33        Louis Meile
     34 
     35 
     36To-do- list by Louis Meile and Berkay Berabi for future projects :
     37- improve AI (SpaceRaceController):
     38i) so far bots arent able to evade obstacles. fix that!
     39ii) bots should be able to use pickups
     40- game crashes when bot wins the game(this is a huge problem you should work with the log file to find out what the errors are )
     41- bots rotate while waiting for the countdown to end. make it stop!
     42- add elements to level file to make it even more fun to play. be creative!
     43*/
     44
    2845
    2946#include "SpaceRace.h"
    3047
     48#include "core/CoreIncludes.h"
     49#include "chat/ChatManager.h"
     50#include "util/Convert.h"
     51#include "util/Math.h"
     52#include "infos/Bot.h"
     53#include "items/Engine.h"
     54#include "controllers/HumanController.h"
     55
     56#include "core/CoreIncludes.h"
     57#include "chat/ChatManager.h"
     58#include "infos/PlayerInfo.h"
     59#include "worldentities/pawns/Pawn.h"
     60#include "core/config/ConfigValueIncludes.h"
     61#include "infos/Bot.h"
     62#include "SpaceRaceBot.h"
    3163#include "items/Engine.h"
    3264
     
    3769#include "SpaceRaceBot.h"
    3870#include "items/Engine.h"
     71#include <vector>
     72
    3973
    4074namespace orxonox
     
    4680        RegisterObject(SpaceRace);
    4781
    48         this->botclass_ = Class(SpaceRaceBot);//ClassByString("")
     82        this->botclass_ = Class(SpaceRaceBot); //ClassByString("")
    4983        this->cantMove_ = false;
    5084        this->bTimeIsUp_ = false;
    51         this->numberOfBots_ = 0; // quick fix: don't allow default-bots to enter the race
    52                                  // remove this line, if a raceBot has been created.
    53     }
     85        this->setConfigValues();
     86
     87        this->numberOfBots_ = 5; // quick fix: don't allow default-bots to enter the race
     88        //we fixed the number of bots in order to have the same starting position all the time !
     89    }
     90
     91  void SpaceRace::setConfigValues()
     92    {
     93       
     94   
     95    }
     96
     97    void SpaceRace::start()
     98    {
     99    // define spawn positions of the 5 bots
     100
     101        int startpos[15];
     102       
     103        startpos[0] =100;
     104        startpos[1] =-40;
     105        startpos[2] =0;
     106       
     107        startpos[3] =100;
     108        startpos[4] =-40;
     109        startpos[5] =100;
     110       
     111        startpos[6] =100;
     112        startpos[7] =-40;
     113        startpos[8] =-100;
     114       
     115        startpos[9] =0;
     116        startpos[10] =-40;
     117        startpos[11] =-80;
     118       
     119        startpos[12] =0;
     120        startpos[13] =-40;
     121        startpos[14] =80;
     122       
     123
     124
     125
     126        Gametype::start();
     127   if (true)
     128        {
     129            this->spawnPlayersIfRequested();
     130            this->cantMove_ = true;
     131            //players are unable to move while countdown is running
     132            for (Engine* engine : ObjectList<Engine>()){
     133                engine->setActive(false);
     134               
     135
     136            }
     137           //append spawn positions to bots
     138           int a,b,c;
     139            a=0;
     140            b=1;
     141            c=2;
     142              for (SpaceRaceBot* bot : ObjectList<SpaceRaceBot>()){
     143                bot->getControllableEntity()->setPosition(startpos[a],startpos[b],startpos[c]);
     144               a= a+3;
     145               b = b+3;
     146               c+= 3;
     147            }
     148
     149
     150        }
     151
     152                                               
     153
     154        std::string message("Use headphones to hear the countdown!");
     155        this->getGametypeInfo()->sendAnnounceMessage(message);
     156        ChatManager::message(message);
     157
     158//after 11 seconds , countdownFinished function is called to activate bots` engines
     159Timer* countdownTimer = new Timer();
     160        countdownTimer->setTimer(11, false, createExecutor(createFunctor(&SpaceRace::countdownFinished, this)));
     161    }
     162
     163
     164
    54165
    55166    void SpaceRace::end()
     
    63174        {
    64175            message = multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds !!\n"
    65                         + "You didn't reach the check point  before the time limit. You lose!";
     176                        + "You lose!";
    66177        }
    67178        else
    68179        {
    69             message = "You win!! You have reached the last check point after "+ multi_cast<std::string>(s)
     180            message = "You win!! Final check point reached after "+ multi_cast<std::string>(s)
    70181                        + "." + multi_cast<std::string>(ms) + " seconds.";
    71182        }
     
    78189    }
    79190
    80     void SpaceRace::tick(float dt)
     191
     192void SpaceRace::tick(float dt)
    81193    {
    82194        SUPER(SpaceRace,tick,dt);
    83 
    84         // spawn the players already when the countdown starts, but deactivate their engines
    85         if (this->isStartCountdownRunning() && !this->cantMove_)
    86         {
    87             this->spawnPlayersIfRequested();
    88             this->cantMove_ = true;
    89 
    90             for (Engine* engine : ObjectList<Engine>())
    91                 engine->setActive(false);
    92         }
    93 
    94         // activate the engines again if the countdown ends
    95         if (!this->isStartCountdownRunning() && this->cantMove_)
    96         {
    97             for (Engine* engine : ObjectList<Engine>())
    98                 engine->setActive(true);
    99 
    100             this->cantMove_= false;
    101 
    102             std::string message = "The match has started! Reach the check points as quickly as possible!";
    103             this->getGametypeInfo()->sendAnnounceMessage(message);
    104             ChatManager::message(message);
    105         }
    106     }
     195}
    107196
    108197    void SpaceRace::newCheckpointReached(RaceCheckPoint* checkpoint, PlayerInfo* player)
     
    114203        int ms = this->clock_.getMilliseconds() % 1000;
    115204
    116         const std::string& message = "Checkpoint " + multi_cast<std::string>(checkpoint->getCheckpointIndex() + 1)
    117             + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds.";
     205       
     206   
     207        const std::string& message = player->getName() + " reached the checkpoint " + multi_cast<std::string>(checkpoint->getCheckpointIndex() + 1)
     208        + "after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds.";
     209 this->getGametypeInfo()->sendAnnounceMessage(message);
     210        ChatManager::message(message);
     211
     212    }
     213
     214 void SpaceRace::countdownFinished()//activates the engines of all players
     215    {
     216
     217        std::string message("RACE STARTED ");
    118218        this->getGametypeInfo()->sendAnnounceMessage(message);
    119219        ChatManager::message(message);
    120     }
    121 
     220
     221
     222    for (Engine* engine : ObjectList<Engine>())
     223                engine->setActive(true);
     224
     225
     226   
     227}
     228
     229 void SpaceRace::playerEntered(PlayerInfo* player)
     230    {
     231        Gametype::playerEntered(player);
     232
     233        const std::string& message = player->getName() + " entered the game";
     234        ChatManager::message(message);
     235    }
     236
     237
     238 void SpaceRace::addBots(unsigned int amount) //function that add the bots to the game
     239    {
     240        for (unsigned int i = 1; i <= amount; ++i){
     241            this->botclass_.fabricate(this->getContext());
     242        }
     243    }
     244
     245
     246//set bot configurations
    122247    bool SpaceRace::allowPawnHit(Pawn* victim, Pawn* originator)
    123248    {
     249        return true;
     250    }
     251
     252    bool SpaceRace::allowPawnDamage(Pawn* victim, Pawn* originator)
     253    {
     254        return true;
     255    }
     256
     257    bool SpaceRace::allowPawnDeath(Pawn* victim, Pawn* originator)// false because the bots can not recognize the objects and die to early
     258                                                                    //if they can
     259    {
    124260        return false;
    125261    }
    126 
    127     bool SpaceRace::allowPawnDamage(Pawn* victim, Pawn* originator)
    128     {
    129         return false;
    130     }
    131 
    132     bool SpaceRace::allowPawnDeath(Pawn* victim, Pawn* originator)
    133     {
    134         return false;
    135     }
    136262}
Note: See TracChangeset for help on using the changeset viewer.