Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6848 for code


Ignore:
Timestamp:
May 3, 2010, 4:57:54 PM (15 years ago)
Author:
jo
Message:

enhanced level, Teamspawnpoints - almost playable version

Location:
code/branches/dynamicmatch/src/orxonox/gametypes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/dynamicmatch/src/orxonox/gametypes/Dynamicmatch.cc

    r6812 r6848  
    5656#include "items/Engine.h"
    5757#include "tools/Timer.h"
     58#include "worldentities/TeamSpawnPoint.h"
    5859
    5960namespace orxonox
     
    99100    }
    100101
    101     bool Dynamicmatch::allowPawnDamage(Pawn* victim, Pawn* originator)//tested - works fine
     102    bool Dynamicmatch::allowPawnDamage(Pawn* victim, Pawn* originator)
    102103    {   
    103104        if (!originator||!victim)
     
    113114                       
    114115                numberOf[target]--;                             //decrease numberof victims's party
    115                 const std::string& message = std::string(" Chasers ") + multi_cast<std::string>(numberOf[chaser]); COUT(0) << message << std::endl; Host::Broadcast(message);
    116116                playerParty_[victim->getPlayer()]=piggy;        //victim's new party: pig
    117117                setPlayerColour(victim->getPlayer());           //victim's new colour
    118118                numberOf[piggy]++;                              //party switch: number of players is not affected (decrease and increase)
    119                 const std::string& message1 = std::string(" Pig") + multi_cast<std::string>(numberOf[piggy]); COUT(0) << message1 << std::endl; Host::Broadcast(message1);
    120119                    if (notEnoughKillers)                       //reward the originator
    121120                    {
    122121                        numberOf[source]--;                     //decrease numberof originator's party
    123                         const std::string& message = std::string(" Chasers ") + multi_cast<std::string>(numberOf[chaser]); COUT(0) << message << std::endl; Host::Broadcast(message);
    124122                        playerParty_[originator->getPlayer()]=killer;           //originator's new party: killer
    125123                        setPlayerColour(originator->getPlayer());               //originator's new colour
    126124                        numberOf[killer]++;
    127                         const std::string& message2 = std::string(" Killers ") + multi_cast<std::string>(numberOf[killer]); COUT(0) << message2 << std::endl; Host::Broadcast(message2);
    128125                    }
    129126                evaluatePlayerParties();                        //check if the party change has to trigger futher party changes
     
    137134                    new Timer(10, false, &createExecutor(createFunctor(&Dynamicmatch::resetSpeedFactor, this))->setDefaultValue(0, ptr), true);
    138135                }
    139                 std::string message5("First victim.");// for testing purposes
    140                 COUT(0) << message5 << std::endl;
    141                 Host::Broadcast(message5);
    142136            }
    143137
     
    149143                setPlayerColour(victim->getPlayer());           //victim colour
    150144                numberOf[killer]++;                             //party switch: number of players is not affected (decrease and increase)
    151                 const std::string& message = std::string(" Killers ") + multi_cast<std::string>(numberOf[killer]); COUT(0) << message << std::endl; Host::Broadcast(message);
    152145                evaluatePlayerParties();                        //check if the party change has to trigger futher party changes
    153146            }
     
    159152                setPlayerColour(victim->getPlayer());           //victim colour
    160153                numberOf[chaser]++;                             //party switch: number of players is not affected (decrease and increase)
    161                 const std::string& message = std::string(" Chasers ") + multi_cast<std::string>(numberOf[chaser]); COUT(0) << message << std::endl; Host::Broadcast(message);
    162154                evaluatePlayerParties();                        //check if the party change has to trigger futher party changes
    163155            }
     
    184176                playerParty_[victim->getPlayer()]=piggy;
    185177                playerParty_[originator->getPlayer()]=chaser;
    186                 //announce
    187                 const std::string& messageVictim = victim->getPlayer()->getName() + " is victim";
    188                 COUT(0) << messageVictim << std::endl;
    189                 Host::Broadcast(messageVictim);
    190178
    191179                //party switch -> colour switch         
     
    203191
    204192            }
    205             //TODO: killer vs piggy
     193            // killer vs piggy
    206194            else if (source==killer &&target==piggy)            //party and colour switch       
    207195            {
     
    260248            return;
    261249        playerParty_[player]=chaser;            //Set playerparty
    262         numberOf[chaser]++; const std::string& message = std::string(" Chasers ") + multi_cast<std::string>(numberOf[chaser]); COUT(0) << message << std::endl; Host::Broadcast(message);
     250        numberOf[chaser]++;
    263251        Gametype::playerEntered(player);
    264252        const std::string& message6 = player->getName() + " entered the game";
     
    290278    }
    291279
    292    
    293 
    294    
    295280
    296281    void Dynamicmatch::tick(float dt)
    297282    {
    298         SUPER(Dynamicmatch, tick, dt);//TODO - was bedeutet diese Zeile
     283        SUPER(Dynamicmatch, tick, dt);
    299284
    300285        if (this->hasStarted() && !gameEnded_)
     
    336321    {
    337322        //durch alle Spieler iterieren
     323        /*std::string message("Game started!");
     324            COUT(0) << message << std::endl;
     325            Host::Broadcast(message);*/
    338326        // allen Spielern mit der Pig-party frags++
    339327        ;
     
    369357        //chasers: there are more chasers than killers + pigs
    370358        if (numberOf[piggy]+numberOf[killer] > numberOf[chaser]) {notEnoughChasers=true;}
    371         else {notEnoughChasers=false; const std::string& message = "Players Evaluated";COUT(0) << message << std::endl; Host::Broadcast(message);}
    372         const std::string& messagetest = multi_cast<std::string>(numberOf[piggy]+numberOf[chaser]+numberOf[killer]) + "   players!";
    373         COUT(0) << messagetest << std::endl; Host::Broadcast(messagetest);     
     359        else {notEnoughChasers=false;} 
    374360    }
    375361
     
    440426        COUT(0) << message << std::endl;
    441427        Host::Broadcast(message);
    442         /*for (std::map<PlayerInfo*, int>::iterator it = this->teamnumbers_.begin(); it != this->teamnumbers_.end(); ++it)
     428        /*for (std::map<PlayerInfo*, int>::iterator it = this->playerParty_.begin(); it != this->playerParty_.end(); ++it)
    443429                {
    444430                    if (it->first->getClientID() == CLIENTID_UNKNOWN)
     
    451437                }*/
    452438    }
     439    SpawnPoint* Dynamicmatch::getBestSpawnPoint(PlayerInfo* player) const
     440    {
     441        int desiredTeamNr = -1;
     442        std::map<PlayerInfo*, int>::const_iterator it_player = this->playerParty_.find(player);
     443        if (it_player != this->playerParty_.end())
     444            desiredTeamNr = it_player->second;
     445
     446        // Only use spawnpoints of the own team (or non-team-spawnpoints)
     447        std::set<SpawnPoint*> teamSpawnPoints = this->spawnpoints_;
     448        for (std::set<SpawnPoint*>::iterator it = teamSpawnPoints.begin(); it != teamSpawnPoints.end(); )
     449        {
     450            if ((*it)->isA(Class(TeamSpawnPoint)))
     451            {
     452                TeamSpawnPoint* tsp = orxonox_cast<TeamSpawnPoint*>(*it);
     453                if (tsp && static_cast<int>(tsp->getTeamNumber()) != desiredTeamNr)//getTeamNumber!!
     454                {
     455                    teamSpawnPoints.erase(it++);
     456                    continue;
     457                }
     458            }
     459
     460            ++it;
     461        }
     462
     463        if (teamSpawnPoints.size() > 0)
     464        {
     465            unsigned int randomspawn = static_cast<unsigned int>(rnd(static_cast<float>(teamSpawnPoints.size())));
     466            unsigned int index = 0;
     467            for (std::set<SpawnPoint*>::const_iterator it = teamSpawnPoints.begin(); it != teamSpawnPoints.end(); ++it)
     468            {
     469                if (index == randomspawn)
     470                    return (*it);
     471
     472                ++index;
     473            }
     474        }
     475
     476        return 0;
     477    }
    453478
    454479}
  • code/branches/dynamicmatch/src/orxonox/gametypes/Dynamicmatch.h

    r6812 r6848  
    6464            void resetSpeedFactor(WeakPtr<Engine>* ptr); 
    6565            void tick (float dt);// used to end the game
    66             //three different parties   TODO const machen!     
     66            SpawnPoint* getBestSpawnPoint(PlayerInfo* player) const;
     67            //three different parties   
    6768            int chaser;
    6869            int piggy;
     
    7879            unsigned int numberOf[3]; //array to count number of chasers, pigs, killers
    7980            float pointsPerTime;
    80             float gameTime_;   // from UnderAttack better: use gametype interface!!!
     81            float gameTime_;   // from UnderAttack
    8182            bool gameEnded_; // true if game is over
    8283            int timesequence_; //used for countdown
Note: See TracChangeset for help on using the changeset viewer.