Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2462


Ignore:
Timestamp:
Dec 15, 2008, 1:38:02 AM (15 years ago)
Author:
landauf
Message:
  • fixed a small speedbar-initialization problem
  • added new console-commands:
    • pause
    • suicide
    • addBots [number]
    • killBots [number]
Location:
code/branches/objecthierarchy2
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy2/bin/def_keybindings.ini

    r2254 r2462  
    100100KeyPageDown=
    101101KeyPageUp=
    102 KeyPause=
     102KeyPause=pause
    103103KeyPeriod=
    104104KeyPlayPause=
  • code/branches/objecthierarchy2/src/orxonox/gamestates/GSRoot.cc

    r2406 r2462  
    6969        : RootGameState("root")
    7070        , timeFactor_(1.0f)
     71        , bPaused_(false)
     72        , timeFactorPauseBackup_(1.0f)
    7173        , settings_(0)
    7274        , tclBind_(0)
     
    7880
    7981        this->ccSetTimeFactor_ = 0;
     82        this->ccPause_ = 0;
    8083    }
    8184
     
    125128            setThreadAffinity((unsigned int)(limitToCPU - 1));
    126129
    127         // add console commands
    128         FunctorMember<GSRoot>* functor1 = createFunctor(&GSRoot::exitGame);
    129         functor1->setObject(this);
    130         ccExit_ = createConsoleCommand(functor1, "exit");
    131         CommandExecutor::addConsoleCommandShortcut(ccExit_);
    132 
    133         // add console commands
    134         FunctorMember01<GameStateBase, const std::string&>* functor2 = createFunctor(&GameStateBase::requestState);
    135         functor2->setObject(this);
    136         ccSelectGameState_ = createConsoleCommand(functor2, "selectGameState");
    137         CommandExecutor::addConsoleCommandShortcut(ccSelectGameState_);
    138 
    139         // time factor console command
    140         FunctorMember<GSRoot>* functor = createFunctor(&GSRoot::setTimeFactor);
    141         functor->setObject(this);
    142         ccSetTimeFactor_ = createConsoleCommand(functor, "setTimeFactor");
    143         CommandExecutor::addConsoleCommandShortcut(ccSetTimeFactor_).accessLevel(AccessLevel::Offline).defaultValue(0, 1.0);;
     130        {
     131            // add console commands
     132            FunctorMember<GSRoot>* functor = createFunctor(&GSRoot::exitGame);
     133            functor->setObject(this);
     134            this->ccExit_ = createConsoleCommand(functor, "exit");
     135            CommandExecutor::addConsoleCommandShortcut(this->ccExit_);
     136        }
     137
     138        {
     139            // add console commands
     140            FunctorMember01<GameStateBase, const std::string&>* functor = createFunctor(&GameStateBase::requestState);
     141            functor->setObject(this);
     142            this->ccSelectGameState_ = createConsoleCommand(functor, "selectGameState");
     143            CommandExecutor::addConsoleCommandShortcut(this->ccSelectGameState_);
     144        }
     145
     146        {
     147            // time factor console command
     148            FunctorMember<GSRoot>* functor = createFunctor(&GSRoot::setTimeFactor);
     149            functor->setObject(this);
     150            this->ccSetTimeFactor_ = createConsoleCommand(functor, "setTimeFactor");
     151            CommandExecutor::addConsoleCommandShortcut(this->ccSetTimeFactor_).accessLevel(AccessLevel::Offline).defaultValue(0, 1.0);
     152        }
     153
     154        {
     155            // time factor console command
     156            FunctorMember<GSRoot>* functor = createFunctor(&GSRoot::pause);
     157            functor->setObject(this);
     158            this->ccPause_ = createConsoleCommand(functor, "pause");
     159            CommandExecutor::addConsoleCommandShortcut(this->ccPause_).accessLevel(AccessLevel::Offline);
     160        }
    144161    }
    145162
     
    161178            delete this->ccSetTimeFactor_;
    162179            this->ccSetTimeFactor_ = 0;
     180        }
     181
     182        if (this->ccPause_)
     183        {
     184            delete this->ccPause_;
     185            this->ccPause_ = 0;
    163186        }
    164187    }
     
    229252        if (Core::isMaster())
    230253        {
    231             TimeFactorListener::timefactor_s = factor;
    232 
    233             for (ObjectList<TimeFactorListener>::iterator it = ObjectList<TimeFactorListener>::begin(); it != ObjectList<TimeFactorListener>::end(); ++it)
    234                 it->changedTimeFactor(factor, this->timeFactor_);
    235 
    236             this->timeFactor_ = factor;
     254            if (!this->bPaused_)
     255            {
     256                TimeFactorListener::timefactor_s = factor;
     257
     258                for (ObjectList<TimeFactorListener>::iterator it = ObjectList<TimeFactorListener>::begin(); it != ObjectList<TimeFactorListener>::end(); ++it)
     259                    it->changedTimeFactor(factor, this->timeFactor_);
     260
     261                this->timeFactor_ = factor;
     262            }
     263            else
     264                this->timeFactorPauseBackup_ = factor;
     265        }
     266    }
     267
     268    void GSRoot::pause()
     269    {
     270        if (Core::isMaster())
     271        {
     272            if (!this->bPaused_)
     273            {
     274                this->timeFactorPauseBackup_ = this->timeFactor_;
     275                this->setTimeFactor(0.0f);
     276                this->bPaused_ = true;
     277            }
     278            else
     279            {
     280                this->bPaused_ = false;
     281                this->setTimeFactor(this->timeFactorPauseBackup_);
     282            }
    237283        }
    238284    }
  • code/branches/objecthierarchy2/src/orxonox/gamestates/GSRoot.h

    r2406 r2462  
    5050        // when taking the function address.
    5151        void setTimeFactor(float factor);
     52        void pause();
    5253        float getTimeFactor() { return this->timeFactor_; }
    5354
     
    6162
    6263        float                 timeFactor_;       //!< A factor that sets the gamespeed. 1 is normal.
     64        bool                  bPaused_;
     65        float                 timeFactorPauseBackup_;
    6366        Settings*             settings_;
    6467        TclBind*              tclBind_;
     
    7174        ConsoleCommand*       ccSelectGameState_;
    7275        ConsoleCommand*       ccSetTimeFactor_;
     76        ConsoleCommand*       ccPause_;
    7377    };
    7478
  • code/branches/objecthierarchy2/src/orxonox/objects/controllers/HumanController.cc

    r2254 r2462  
    3333#include "core/ConsoleCommand.h"
    3434#include "objects/worldentities/ControllableEntity.h"
     35#include "objects/worldentities/pawns/Pawn.h"
     36#include "objects/gametypes/Gametype.h"
    3537
    3638namespace orxonox
     
    4850    SetConsoleCommand(HumanController, use,           true);
    4951    SetConsoleCommand(HumanController, switchCamera,  true);
     52    SetConsoleCommand(HumanController, suicide,       true);
     53    SetConsoleCommand(HumanController, addBots,       true).defaultValues(1);
     54    SetConsoleCommand(HumanController, killBots,      true).defaultValues(0);
    5055
    5156    CreateUnloadableFactory(HumanController);
     
    136141            HumanController::localController_s->controllableEntity_->switchCamera();
    137142    }
     143
     144    void HumanController::suicide()
     145    {
     146        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
     147        {
     148            Pawn* pawn = dynamic_cast<Pawn*>(HumanController::localController_s->controllableEntity_);
     149            if (pawn)
     150                pawn->kill();
     151        }
     152    }
     153
     154    void HumanController::addBots(unsigned int amount)
     155    {
     156        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype())
     157            HumanController::localController_s->controllableEntity_->getGametype()->addBots(amount);
     158    }
     159
     160    void HumanController::killBots(unsigned int amount)
     161    {
     162        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype())
     163            HumanController::localController_s->controllableEntity_->getGametype()->killBots(amount);
     164    }
    138165}
  • code/branches/objecthierarchy2/src/orxonox/objects/controllers/HumanController.h

    r2254 r2462  
    5959            static void switchCamera();
    6060
     61            static void suicide();
     62
     63            static void addBots(unsigned int amount);
     64            static void killBots(unsigned int amount = 0);
     65
    6166        private:
    6267            static HumanController* localController_s;
  • code/branches/objecthierarchy2/src/orxonox/objects/gametypes/Gametype.cc

    r2447 r2462  
    3636#include "core/ConfigValueIncludes.h"
    3737#include "objects/infos/PlayerInfo.h"
     38#include "objects/infos/Bot.h"
    3839#include "objects/worldentities/pawns/Spectator.h"
    3940#include "objects/worldentities/SpawnPoint.h"
     
    5051        RegisterObject(Gametype);
    5152
     53        this->setGametype(this);
     54
    5255        this->defaultControllableEntity_ = Class(Spectator);
    5356
    5457        this->bAutoStart_ = false;
    5558        this->bForceSpawn_ = false;
     59        this->numberOfBots_ = 0;
    5660
    5761        this->initialStartCountdown_ = 3;
    5862
    5963        this->setConfigValues();
     64
     65        this->addBots(this->numberOfBots_);
    6066    }
    6167
     
    6571        SetConfigValue(bAutoStart_, false);
    6672        SetConfigValue(bForceSpawn_, false);
     73        SetConfigValue(numberOfBots_, 0);
    6774    }
    6875
     
    293300        }
    294301    }
     302
     303    void Gametype::addBots(unsigned int amount)
     304    {
     305        for (unsigned int i = 0; i < amount; ++i)
     306            new Bot(this);
     307    }
     308
     309    void Gametype::killBots(unsigned int amount)
     310    {
     311        unsigned int i = 0;
     312        for (ObjectList<Bot>::iterator it = ObjectList<Bot>::begin(); (it != ObjectList<Bot>::end()) && ((amount == 0) || (i < amount)); )
     313        {
     314            if (it->getGametype() == this)
     315            {
     316                delete (*(it++));
     317                ++i;
     318            }
     319        }
     320    }
    295321}
  • code/branches/objecthierarchy2/src/orxonox/objects/gametypes/Gametype.h

    r2428 r2462  
    9898                { return this->gtinfo_.startCountdown_; }
    9999
     100            void addBots(unsigned int amount);
     101            void killBots(unsigned int amount = 0);
     102
    100103        private:
    101104            virtual SpawnPoint* getBestSpawnPoint(PlayerInfo* player) const;
     
    116119
    117120            float initialStartCountdown_;
     121            unsigned int numberOfBots_;
    118122
    119123            std::map<PlayerInfo*, PlayerState::Enum> players_;
  • code/branches/objecthierarchy2/src/orxonox/objects/infos/PlayerInfo.cc

    r2438 r2462  
    6565                this->controller_ = 0;
    6666            }
     67
     68            if (this->getGametype())
     69                this->getGametype()->playerLeft(this);
    6770        }
    6871    }
  • code/branches/objecthierarchy2/src/orxonox/overlays/hud/HUDBar.cc

    r2369 r2462  
    8484        this->bar_->setMaterialName(materialname);
    8585
    86         this->setValue(0.0f);
     86        this->value_ = 1.0f;  // initielize with 1.0f to trigger a change when calling setValue(0.0f) on the line below
     87        this->setValue(0.0f); // <--
    8788        this->setRightToLeft(false);
    8889        this->setAutoColour(true);
Note: See TracChangeset for help on using the changeset viewer.