Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6686 for code


Ignore:
Timestamp:
Apr 12, 2010, 2:52:45 PM (15 years ago)
Author:
jo
Message:

first version- not playable yet

Location:
code/branches/dynamicmatch/src/orxonox
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/dynamicmatch/src/orxonox/controllers/ArtificialController.cc

    r6502 r6686  
    3434#include "worldentities/pawns/TeamBaseMatchBase.h"
    3535#include "gametypes/TeamDeathmatch.h"
     36#include "gametypes/Dynamicmatch.h"
    3637#include "controllers/WaypointPatrolController.h"
     38
    3739
    3840namespace orxonox
     
    244246            }
    245247        }
    246 
    247         return (team1 == team2 && team1 != -1);
    248     }
     248        Dynamicmatch* dynamic = orxonox_cast<Dynamicmatch*>(gametype);
     249        if (dynamic)
     250        {
     251            if (entity1->getPlayer())
     252                team1 = dynamic->getParty(entity1->getPlayer());
     253
     254            if (entity2->getPlayer())
     255                team2 = dynamic->getParty(entity2->getPlayer());
     256        }
     257
     258        return (team1 == team2 && team1 != -1)&&(!dynamic->onlyChasers); //returns false if players are in the same party and there is a victim
     259    }                                                           //-> if there is no victim or the AI-Player is not in the same team the AI attacks
    249260}
  • code/branches/dynamicmatch/src/orxonox/gametypes/CMakeLists.txt

    r5781 r6686  
    66  UnderAttack.cc
    77  Asteroids.cc
     8  Dynamicmatch.cc
    89)
  • code/branches/dynamicmatch/src/orxonox/gametypes/Dynamicmatch.cc

    r6603 r6686  
    2929#include "Dynamicmatch.h"
    3030
     31#include "util/Convert.h"
    3132#include "core/CoreIncludes.h"
    3233#include "network/Host.h"
    3334#include "infos/PlayerInfo.h"
    3435#include "worldentities/pawns/Pawn.h"
    35 
     36#include "core/ConfigValueIncludes.h"
     37#include "interfaces/TeamColourable.h"
     38
     39//toDO: maybe the has entered the game function is not enough... look at TeamDeathmath
    3640namespace orxonox
    3741{
     
    4145    {
    4246        RegisterObject(Dynamicmatch);
    43            this->scoreTimer_.setTimer(10, true, createExecutor(createFunctor(&Dynamicmatch::winPoints, this)));//bad
    44            this->outputTimer_.setTimer(10, true, createExecutor(createFunctor(&Dynamicmatch::showPoints, this)));//bad
    45            for (int player=0; player<50; player++) { this->pointsScored[player]=0;}//
     47        this->gameTime_ = 180;
     48        this->setConfigValues();
     49        this->chaser=0;
     50        this->piggy=1;
     51        this->onlyChasers=true;
     52        this->gameEnded_ =false;
     53        this->timesequence_ = static_cast<int>(this->gameTime_);
     54        this->friendlyfire=true;
     55    }
     56
     57void Dynamicmatch::setPlayerColour(PlayerInfo* player) // not sure if this is the right place - helper function
     58{
     59        std::map<PlayerInfo*, int>::const_iterator it_player = this->playerParty_.find(player);
     60        //if (it_player != this->playerParty_.end() && it_player->second >= 0 && it_player->second < static_cast<int>(this->partyColours_.size()))
     61        // all players are the same colour at the beginning!!
     62            Pawn* pawn = dynamic_cast<Pawn*>(player->getControllableEntity());
     63            if (pawn)
     64            {
     65                pawn->setRadarObjectColour(this->partyColours_[it_player->second]); //does this work? //what about playerParty_[it_player] instead of it_player->second
     66
     67                std::set<WorldEntity*> pawnAttachments = pawn->getAttachedObjects();
     68                for (std::set<WorldEntity*>::iterator it = pawnAttachments.begin(); it != pawnAttachments.end(); ++it)
     69                {
     70                    if ((*it)->isA(Class(TeamColourable)))//not sure if this works
     71                    {
     72                        TeamColourable* tc = orxonox_cast<TeamColourable*>(*it);
     73                        tc->setTeamColour(this->partyColours_[it_player->second]);
     74                    }
     75                }
     76            }
     77}
     78
     79
     80int Dynamicmatch::getParty(PlayerInfo* player) // helper function for ArtificialController
     81{
     82return this->playerParty_[player];
     83}
     84
     85
     86
     87void Dynamicmatch::setConfigValues()
     88    {
     89        SetConfigValue(gameTime_, 180);//just for test cases
     90        SetConfigValue(friendlyfire, true);
     91        static ColourValue colours[] =
     92        {
     93            ColourValue(0.3f, 0.3f, 1.0f),
     94            ColourValue(1.0f, 0.3f, 0.3f)
     95           
     96        };
     97        static std::vector<ColourValue> defaultcolours(colours, colours + sizeof(colours) / sizeof(ColourValue));
     98
     99        SetConfigValue(partyColours_, defaultcolours);
     100    }
     101
     102bool Dynamicmatch::allowPawnDamage(Pawn* victim, Pawn* originator)//
     103    {   
     104
     105        if (victim && victim->getPlayer())
     106        {       //TODO: evtl. ->getPlayer() zugriffe auslagern fuer mehr uebersicht
     107                //Case: 1. onlyChasers==false und victim ist chaser
     108                if ((!onlyChasers)&&(playerParty_[originator->getPlayer()]==chaser)) {
     109                        std::map<PlayerInfo*, Player>::iterator it = this->players_.find(originator->getPlayer());
     110                    if (it != this->players_.end())
     111                    {
     112                        it->second.frags_++;
     113                    }
     114                }
     115                //Case 2: onlyChasers==false und victim ist piggy
     116                else if ((!onlyChasers)&&(playerParty_[originator->getPlayer()]==piggy)){
     117                        //partyswitch: victim bcomes piggy and the orginator(piggy) becomes chaser
     118                        playerParty_[victim->getPlayer()]=piggy;
     119                        playerParty_[originator->getPlayer()]=chaser;
     120                        //announce
     121                        const std::string& messageVictim = victim->getPlayer()->getName() + " is victim";
     122                        COUT(0) << messageVictim << std::endl;
     123                        Host::Broadcast(messageVictim);
     124                //party switch -> colour switch
     125               
     126                setPlayerColour(victim->getPlayer()); //victim colour
     127                setPlayerColour(originator->getPlayer());//orginator colour
     128                }
     129                //Case 3: there are only chasers -> new piggy is needed
     130                else if (onlyChasers){
     131                        //Rollenzuweisung victim wird piggy
     132                        playerParty_[victim->getPlayer()]=piggy;
     133                        onlyChasers=false;
     134                        setPlayerColour(victim->getPlayer()); //victim colour
     135                std::string message("First victim.");
     136                COUT(0) << message << std::endl;
     137                Host::Broadcast(message);
     138                }
     139                else if (friendlyfire)
     140                {
     141                std::map<PlayerInfo*, Player>::iterator it = this->players_.find(originator->getPlayer());
     142                 if (it != this->players_.end())
     143                    {
     144                        it->second.frags_--;
     145                    }
     146                }
     147        }
     148               
     149        return false;
     150    }
     151
    46152       
    47     }
    48 
    49 bool Gametype::allowPawnDamage(Pawn* victim, Pawn* originator)//
     153   
     154
     155bool Dynamicmatch::allowPawnDeath(Pawn* victim, Pawn* originator)//
    50156    {
    51157        return false;
    52158    }
    53159
    54 bool Gametype::allowPawnDeath(Pawn* victim, Pawn* originator)//
    55     {
    56         return false;
    57     }
    58 
    59 void Dynamicmatch::winPoints() // Points scored for each player
    60     {
    61         /* Points: for each hit of the victim - is it possible to destinguish different weapontypes (1pt per hit)
    62                 the victim scores points during the duration of the victim state (1p per second)
    63         */
    64 
    65 
    66 
    67         /*int amountControlled = 0;
    68         int amountControlled2 = 0;
    69 
    70         for (std::set<TeamBaseMatchBase*>::const_iterator it = this->bases_.begin(); it != this->bases_.end(); ++it)
    71         {
    72             if((*it)->getState() == BaseState::ControlTeam1)
    73             {
    74                 amountControlled++;
    75             }
    76             if((*it)->getState() == BaseState::ControlTeam2)
    77             {
    78                 amountControlled2++;
    79             }
    80         }
    81 
    82         this->addTeamPoints(0, (amountControlled * 30));
    83         this->addTeamPoints(1, (amountControlled2 * 30));
    84         */
    85     }
    86 
    87 
    88 
    89     void Dynamicmatch::start()
    90     {
     160void Dynamicmatch::start()
     161    {   
    91162        Gametype::start();
    92163
    93         std::string message("The match has started!");
     164        std::string message("Don't be a victim!");
    94165        COUT(0) << message << std::endl;
    95166        Host::Broadcast(message);
     167       
    96168    }
    97169
     
    100172        Gametype::end();
    101173
    102         std::string message("The match has ended.");
     174        std::string message("Time out. Press F2 to see the soreboard");
    103175        COUT(0) << message << std::endl;
    104176        Host::Broadcast(message);
    105     }
    106 
    107     void Dynamicmatch::playerEntered(PlayerInfo* player)
    108     {
     177        /*for (std::map<PlayerInfo*, int>::iterator it = this->teamnumbers_.begin(); it != this->teamnumbers_.end(); ++it)
     178                {
     179                    if (it->first->getClientID() == CLIENTID_UNKNOWN)
     180                        continue;
     181
     182                    if (it->second == 1)
     183                        this->gtinfo_->sendAnnounceMessage("You have won the match!", it->first->getClientID());
     184                    else
     185                        this->gtinfo_->sendAnnounceMessage("You have lost the match!", it->first->getClientID());
     186                }*/
     187    }
     188
     189   
     190void Dynamicmatch::playerStartsControllingPawn(PlayerInfo* player, Pawn* pawn)
     191    {
     192        if (!player)
     193            return;
     194        playerParty_[player]=chaser;//playerparty
     195        // Set the playercolour
     196        Dynamicmatch::setPlayerColour(player);
     197
     198       
     199    }
     200
     201    void Dynamicmatch::playerEntered(PlayerInfo* player) //standardfunction + party + colouring
     202    {
     203
     204        if (!player)// only for safety
     205            return;
     206
    109207        Gametype::playerEntered(player);
    110 
     208       
     209        //playerParty_[player]=chaser;//playerparty
     210       
     211        // Set the playercolour
     212        //Dynamicmatch::setPlayerColour(player);
     213       
     214       
    111215        const std::string& message = player->getName() + " entered the game";
    112216        COUT(0) << message << std::endl;
     
    114218    }
    115219
    116     bool Dynamicmatch::playerLeft(PlayerInfo* player)
     220    bool Dynamicmatch::playerLeft(PlayerInfo* player) //standardfunction
    117221    {
    118222        bool valid_player = Gametype::playerLeft(player);
    119 
     223       
     224       
    120225        if (valid_player)
    121226        {
     
    123228            COUT(0) << message << std::endl;
    124229            Host::Broadcast(message);
     230                //remove player from map
     231             playerParty_.erase (player); 
    125232        }
    126233
     
    128235    }
    129236
    130     bool Dynamicmatch::playerChangedName(PlayerInfo* player)
     237    bool Dynamicmatch::playerChangedName(PlayerInfo* player) //standardfunction
    131238    {
    132239        bool valid_player = Gametype::playerChangedName(player);
     
    142249    }
    143250
    144     void Dynamicmatch::pawnKilled(Pawn* victim, Pawn* killer)
    145     {
    146         if (victim && victim->getPlayer())
    147         {
    148             std::string message;
    149             if (killer)
     251   
     252
     253 void Dynamicmatch::tick(float dt)
     254    {
     255        SUPER(Dynamicmatch, tick, dt);//TODO - was bedeutet diese Zeile
     256
     257        if (this->hasStarted() && !gameEnded_)
     258        {
     259            gameTime_ = gameTime_ - dt;
     260            if (gameTime_<= 0)
    150261            {
    151                 if (killer->getPlayer())
    152                     message = victim->getPlayer()->getName() + " was killed by " + killer->getPlayer()->getName();
     262                this->gameEnded_ = true;
     263                this->end();       
     264            }
     265                if ( gameTime_ <= timesequence_ && gameTime_ > 0)
     266            {
     267                const std::string& message = multi_cast<std::string>(timesequence_) + " seconds left!";
     268
     269                this->gtinfo_->sendAnnounceMessage(message);
     270
     271                if (timesequence_ >= 30 && timesequence_ <= 60)
     272                {
     273                    timesequence_ = timesequence_ - 10;
     274                }
     275                else if (timesequence_ <= 30)
     276                {
     277                    timesequence_ = timesequence_ - 5;
     278                }
    153279                else
    154                     message = victim->getPlayer()->getName() + " was killed";
     280                {
     281                    timesequence_ = timesequence_ - 30;
     282                }
    155283            }
    156             else
    157                 message = victim->getPlayer()->getName() + " died";
    158 
    159             COUT(0) << message << std::endl;
    160             Host::Broadcast(message);
    161         }
    162 
    163         Gametype::pawnKilled(victim, killer);
    164     }
    165 
    166     void Dynamicmatch::playerScored(PlayerInfo* player)
    167     {
    168         Gametype::playerScored(player);
    169 
    170         if (player)
    171         {
    172             const std::string& message = player->getName() + " scores!";
    173             COUT(0) << message << std::endl;
    174             Host::Broadcast(message);
    175         }
     284        }
    176285    }
    177286}
  • code/branches/dynamicmatch/src/orxonox/gametypes/Dynamicmatch.h

    r6603 r6686  
    3030#define _Dynamicmatch_H__
    3131
     32#include <map>
     33#include <vector>
    3234#include "OrxonoxPrereqs.h"
    3335#include "Gametype.h"
     
    4143            Dynamicmatch(BaseObject* creator);
    4244            virtual ~Dynamicmatch() {}
    43 
    44                 virtual bool allowPawnDamage(Pawn* victim, Pawn* originator = 0);
    45                 virtual bool allowPawnDeath(Pawn* victim, Pawn* originator = 0);
     45               
     46                bool onlyChasers;
     47                int getParty(PlayerInfo* player);
     48                void setPlayerColour(PlayerInfo* player);//own function
     49                void setConfigValues();//done
     50                virtual bool allowPawnDamage(Pawn* victim, Pawn* originator = 0); //ok - score function and management of parties
     51                virtual bool allowPawnDeath(Pawn* victim, Pawn* originator = 0); //ok - simple
    4652            virtual void start();
    4753
    4854                 
    49             virtual void end();
     55            virtual void end(); //Wie geht das mit der Punkteausgabe? frags als Schnittstelle ausreichend?
    5056            virtual void playerEntered(PlayerInfo* player);
    51             virtual bool playerLeft(PlayerInfo* player);
    52             virtual bool playerChangedName(PlayerInfo* player);
    53 
    54             virtual void pawnKilled(Pawn* victim, Pawn* killer = 0);
    55             virtual void playerScored(PlayerInfo* player);
    56                   virtual void showPoints();
    57 
     57                virtual void playerStartsControllingPawn(PlayerInfo* player, Pawn* pawn);//is used to initialize the player's party and colour
     58            virtual bool playerLeft(PlayerInfo* player);//ToDo: extract the player's party record - done?
     59            virtual bool playerChangedName(PlayerInfo* player);//unchanged
     60       
     61           
     62                void tick (float dt);// used to end the game
     63               
     64                //inline const ColourValue& getPlayerColour(int teamnr) const
     65                //{ return this->partyColours_[teamnr]; }
     66               
    5867                protected:
    59                   //points for each player
    60                   int pointsScored[50];//sorry hard coded - each player should be able to score
    61                   void winPoints();
    62                   Timer outputTimer_;
    63                   Timer scoreTimer_;      //?
     68                  //the two different parties
     69                  int chaser;
     70                  int piggy;
     71                  std::map< PlayerInfo*, int > playerParty_; //player's parties are recorded here
     72                  std::vector<ColourValue> partyColours_; //aus TeamDeathmatch           
     73                bool friendlyfire; //goal: player can switch it on/off
     74                float gameTime_;   // from UnderAttack
     75                bool gameEnded_; // true if game is over
     76                int timesequence_; //used for countdown
    6477    };
    6578}
Note: See TracChangeset for help on using the changeset viewer.