Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 25, 2011, 9:41:29 PM (14 years ago)
Author:
dafrick
Message:

Merging game immersion branch into presentation branch.

Location:
code/branches/presentation
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation

  • code/branches/presentation/src/orxonox/worldentities/ControllableEntity.cc

    r8579 r8580  
    8484        this->client_angular_velocity_ = Vector3::ZERO;
    8585
    86 
    8786        this->setConfigValues();
    8887        this->setPriority( Priority::VeryHigh );
  • code/branches/presentation/src/orxonox/worldentities/ControllableEntity.h

    r8579 r8580  
    9393            virtual void reload() {}
    9494
    95             virtual void boost() {}
     95            /**
     96            @brief Tells the ControllableEntity to either start or stop boosting.
     97                   This doesn't mean, that the ControllableEntity will do so, there might be additional restrictions on boosting, but if it can, then it will.
     98            @param bBoost If true the ControllableEntity is told to start boosting, if false it is told to stop.
     99            */
     100            virtual void boost(bool bBoost) {}
     101           
    96102            virtual void greet() {}
    97103            virtual void switchCamera();
  • code/branches/presentation/src/orxonox/worldentities/pawns/Pawn.cc

    r8579 r8580  
    2323 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    25  *      ...
     25 *      simonmie
    2626 *
    2727 */
     
    6464        this->maxHealth_ = 0;
    6565        this->initialHealth_ = 0;
     66
    6667        this->shieldHealth_ = 0;
     68        this->initialShieldHealth_ = 0;
     69        this->maxShieldHealth_ = 100; //otherwise shield might increase to float_max
    6770        this->shieldAbsorption_ = 0.5;
     71
     72        this->reloadRate_ = 0;
     73        this->reloadWaitTime_ = 1.0f;
     74        this->reloadWaitCountdown_ = 0;
    6875
    6976        this->lastHitOriginator_ = 0;
     
    109116
    110117        XMLPortParam(Pawn, "shieldhealth", setShieldHealth, getShieldHealth, xmlelement, mode).defaultValues(0);
     118        XMLPortParam(Pawn, "initialshieldhealth", setInitialShieldHealth, getInitialShieldHealth, xmlelement, mode).defaultValues(0);
     119        XMLPortParam(Pawn, "maxshieldhealth", setMaxShieldHealth, getMaxShieldHealth, xmlelement, mode).defaultValues(100);
    111120        XMLPortParam(Pawn, "shieldabsorption", setShieldAbsorption, getShieldAbsorption, xmlelement, mode).defaultValues(0);
    112121
     
    118127        XMLPortObject(Pawn, WeaponSet, "weaponsets", addWeaponSet, getWeaponSet, xmlelement, mode);
    119128        XMLPortObject(Pawn, WeaponPack, "weapons", addWeaponPackXML, getWeaponPack, xmlelement, mode);
     129
     130        XMLPortParam(Pawn, "reloadrate", setReloadRate, getReloadRate, xmlelement, mode).defaultValues(0);
     131        XMLPortParam(Pawn, "reloadwaittime", setReloadWaitTime, getReloadWaitTime, xmlelement, mode).defaultValues(1.0f);
    120132    }
    121133
     
    124136        registerVariable(this->bAlive_,           VariableDirection::ToClient);
    125137        registerVariable(this->health_,           VariableDirection::ToClient);
    126         registerVariable(this->initialHealth_,    VariableDirection::ToClient);
     138        registerVariable(this->maxHealth_,        VariableDirection::ToClient);
    127139        registerVariable(this->shieldHealth_,     VariableDirection::ToClient);
     140        registerVariable(this->maxShieldHealth_,  VariableDirection::ToClient);
    128141        registerVariable(this->shieldAbsorption_, VariableDirection::ToClient);
    129142        registerVariable(this->bReload_,          VariableDirection::ToServer);
     
    137150        this->bReload_ = false;
    138151
     152        // TODO: use the existing timer functions instead
     153        if(this->reloadWaitCountdown_ > 0)
     154        {
     155            this->decreaseReloadCountdownTime(dt);
     156        }
     157        else
     158        {
     159            this->addShieldHealth(this->getReloadRate() * dt);
     160            this->resetReloadCountdown();
     161        }
     162
    139163        if (GameMode::isMaster())
     164        {
    140165            if (this->health_ <= 0 && bAlive_)
    141166            {
    142                 this->fireEvent(); // Event to notify anyone who want's to know about the death.
     167                this->fireEvent(); // Event to notify anyone who wants to know about the death.
    143168                this->death();
    144169            }
     170        }
    145171    }
    146172
     
    168194    }
    169195
     196
    170197    void Pawn::setHealth(float health)
    171198    {
    172         this->health_ = std::min(health, this->maxHealth_);
    173     }
    174 
    175     void Pawn::damage(float damage, Pawn* originator)
     199        this->health_ = std::min(health, this->maxHealth_); //Health can't be set to a value bigger than maxHealth, otherwise it will be reduced at first hit
     200    }
     201
     202    void Pawn::setShieldHealth(float shieldHealth)
     203    {
     204        this->shieldHealth_ = std::min(shieldHealth, this->maxShieldHealth_);
     205    }
     206
     207    void Pawn::setMaxShieldHealth(float maxshieldhealth)
     208    {
     209        this->maxShieldHealth_ = maxshieldhealth;
     210    }
     211
     212    void Pawn::setReloadRate(float reloadrate)
     213    {
     214        this->reloadRate_ = reloadrate;
     215    }
     216
     217    void Pawn::setReloadWaitTime(float reloadwaittime)
     218    {
     219        this->reloadWaitTime_ = reloadwaittime;
     220    }
     221
     222    void Pawn::decreaseReloadCountdownTime(float dt)
     223    {
     224        this->reloadWaitCountdown_ -= dt;
     225    }
     226
     227    void Pawn::damage(float damage, float healthdamage, float shielddamage, Pawn* originator)
    176228    {
    177229        if (this->getGametype() && this->getGametype()->allowPawnDamage(this, originator))
    178230        {
    179             //share the dealt damage to the shield and the Pawn.
    180             float shielddamage = damage*this->shieldAbsorption_;
    181             float healthdamage = damage*(1-this->shieldAbsorption_);
    182 
    183             // In case the shield can not take all the shield damage.
    184             if (shielddamage > this->getShieldHealth())
     231            if (shielddamage >= this->getShieldHealth())
    185232            {
    186                 healthdamage += shielddamage-this->getShieldHealth();
    187233                this->setShieldHealth(0);
     234                this->setHealth(this->health_ - (healthdamage + damage));
    188235            }
    189 
    190             this->setHealth(this->health_ - healthdamage);
    191 
    192             if (this->getShieldHealth() > 0)
     236            else
    193237            {
    194238                this->setShieldHealth(this->shieldHealth_ - shielddamage);
     239
     240                // remove remaining shieldAbsorpton-Part of damage from shield
     241                shielddamage = damage * this->shieldAbsorption_;
     242                shielddamage = std::min(this->getShieldHealth(),shielddamage);
     243                this->setShieldHealth(this->shieldHealth_ - shielddamage);
     244
     245                // set remaining damage to health
     246                this->setHealth(this->health_ - (damage - shielddamage) - healthdamage);
    195247            }
    196248
    197249            this->lastHitOriginator_ = originator;
    198 
    199             // play damage effect
    200         }
    201     }
    202 
    203     void Pawn::hit(Pawn* originator, const Vector3& force, float damage)
     250        }
     251    }
     252
     253// TODO: Still valid?
     254/* HIT-Funktionen
     255    Die hit-Funktionen muessen auch in src/orxonox/controllers/Controller.h angepasst werden! (Visuelle Effekte)
     256
     257*/
     258
     259    void Pawn::hit(Pawn* originator, const Vector3& force, float damage, float healthdamage, float shielddamage)
    204260    {
    205261        if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) )
    206262        {
    207             this->damage(damage, originator);
     263            this->damage(damage, healthdamage, shielddamage, originator);
    208264            this->setVelocity(this->getVelocity() + force);
    209 
    210             // play hit effect
    211         }
    212     }
    213 
    214     void Pawn::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage)
     265        }
     266    }
     267
     268
     269    void Pawn::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage, float healthdamage, float shielddamage)
    215270    {
    216271        if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) )
    217272        {
    218             this->damage(damage, originator);
     273            this->damage(damage, healthdamage, shielddamage, originator);
    219274
    220275            if ( this->getController() )
    221                 this->getController()->hit(originator, contactpoint, damage);
    222 
    223             // play hit effect
    224         }
    225     }
     276                this->getController()->hit(originator, contactpoint, damage); // changed to damage, why shielddamage?
     277        }
     278    }
     279
    226280
    227281    void Pawn::kill()
  • code/branches/presentation/src/orxonox/worldentities/pawns/Pawn.h

    r8579 r8580  
    7272                { return this->initialHealth_; }
    7373
    74             inline void setShieldHealth(float shieldHealth)
    75             { this->shieldHealth_ = shieldHealth; }
     74            virtual void setShieldHealth(float shieldHealth);
     75
    7676            inline float getShieldHealth()
    7777            { return this->shieldHealth_; }
     78
     79            inline void addShieldHealth(float amount)
     80            { this->setShieldHealth(this->shieldHealth_ + amount); }
     81
     82            inline bool hasShield()
     83            { return (this->getShieldHealth() > 0); }
     84
     85            virtual void setMaxShieldHealth(float maxshieldhealth);
     86            inline float getMaxShieldHealth() const
     87                { return this->maxShieldHealth_; }
     88
     89            inline void setInitialShieldHealth(float initialshieldhealth)
     90                { this->initialShieldHealth_ = initialshieldhealth; this->setShieldHealth(initialshieldhealth); }
     91            inline float getInitialShieldHealth() const
     92                { return this->initialShieldHealth_; }
     93
     94            inline void restoreInitialShieldHealth()
     95                { this->setShieldHealth(this->initialShieldHealth_); }
     96            inline void restoreMaxShieldHealth()
     97                { this->setShieldHealth(this->maxShieldHealth_); }
    7898
    7999            inline void setShieldAbsorption(float shieldAbsorption)
     
    82102            { return this->shieldAbsorption_; }
    83103
     104            // TODO: Rename to shieldRechargeRate
     105            virtual void setReloadRate(float reloadrate);
     106            inline float getReloadRate() const
     107                { return this->reloadRate_; }
     108
     109            virtual void setReloadWaitTime(float reloadwaittime);
     110            inline float getReloadWaitTime() const
     111                { return this->reloadWaitTime_; }
     112
     113            inline void resetReloadCountdown()
     114            { this->reloadWaitCountdown_ = 0; }
     115
     116            inline void startReloadCountdown()
     117            { this->reloadWaitCountdown_ = this->getReloadWaitTime(); } // TODO: Implement in Projectile.cc
     118
     119            virtual void decreaseReloadCountdownTime(float dt);
     120
    84121            inline ControllableEntity* getLastHitOriginator() const
    85122                { return this->lastHitOriginator_; }
    86123
    87             virtual void hit(Pawn* originator, const Vector3& force, float damage);
    88             virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage);
     124            //virtual void hit(Pawn* originator, const Vector3& force, float damage);
     125            //virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage);
     126            virtual void hit(Pawn* originator, const Vector3& force, float damage, float healthdamage = 0.0f, float shielddamage = 0.0f);
     127            virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage, float healthdamage = 0.0f, float shielddamage = 0.0f);
     128
    89129            virtual void kill();
    90130
     
    142182            virtual void spawneffect();
    143183
    144             virtual void damage(float damage, Pawn* originator = 0);
     184            //virtual void damage(float damage, Pawn* originator = 0);
     185            virtual void damage(float damage, float healthdamage = 0.0f, float shielddamage = 0.0f, Pawn* originator = NULL);
    145186
    146187            bool bAlive_;
     
    154195            float maxHealth_;
    155196            float initialHealth_;
     197           
    156198            float shieldHealth_;
     199            float maxShieldHealth_;
     200            float initialShieldHealth_;
    157201            float shieldAbsorption_; // Has to be between 0 and 1
     202            float reloadRate_;
     203            float reloadWaitTime_;
     204            float reloadWaitCountdown_;
    158205
    159206            WeakPtr<Pawn> lastHitOriginator_;
  • code/branches/presentation/src/orxonox/worldentities/pawns/SpaceShip.cc

    r8579 r8580  
    3636#include "core/XMLPort.h"
    3737#include "items/Engine.h"
     38#include "graphics/Camera.h"
     39#include "CameraManager.h"
     40#include "util/Math.h"
    3841
    3942namespace orxonox
     
    5356        this->localAngularAcceleration_.setValue(0, 0, 0);
    5457        this->bBoost_ = false;
    55         this->bPermanentBoost_ = false;
    5658        this->steering_ = Vector3::ZERO;
    5759        this->engine_ = 0;
     
    7678        this->setConfigValues();
    7779        this->registerVariables();
     80       
     81        Camera* camera = CameraManager::getInstance().getActiveCamera();
     82        this->cameraOriginalPosition_ = camera->getPosition();
     83        this->cameraOriginalOrientation_ = camera->getOrientation();
     84
     85        this->shakeFrequency_ = 15;
     86        this->shakeAmplitude_ = 5;
     87        this->shakeDt_ = 0;
    7888    }
    7989
     
    96106        XMLPortParamVariable(SpaceShip, "boostRate", boostRate_, xmlelement, mode);
    97107        XMLPortParamVariable(SpaceShip, "boostCooldownDuration", boostCooldownDuration_, xmlelement, mode);
     108        XMLPortParamVariable(SpaceShip, "shakeFrequency", shakeFrequency_, xmlelement, mode);
     109        XMLPortParamVariable(SpaceShip, "shakeAmplitude", shakeAmplitude_, xmlelement, mode);
    98110    }
    99111
     
    103115        registerVariable(this->auxilaryThrust_, VariableDirection::ToClient);
    104116        registerVariable(this->rotationThrust_, VariableDirection::ToClient);
     117        // TODO: Synchronization of boost needed?
     118        registerVariable(this->boostPower_, VariableDirection::ToClient);
     119        registerVariable(this->boostPowerRate_, VariableDirection::ToClient);
     120        registerVariable(this->boostRate_, VariableDirection::ToClient);
     121        registerVariable(this->boostCooldownDuration_, VariableDirection::ToClient);
     122        registerVariable(this->shakeFrequency_, VariableDirection::ToClient);
     123        registerVariable(this->shakeAmplitude_, VariableDirection::ToClient);
    105124    }
    106125
     
    128147        if (this->hasLocalController())
    129148        {
     149
    130150/*
    131151            this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxilaryThrust_);
     
    150170                this->boostPower_ += this->boostPowerRate_*dt;
    151171            }
     172
    152173            if(this->bBoost_)
    153174            {
     
    155176                if(this->boostPower_ <= 0.0f)
    156177                {
    157                     this->bBoost_ = false;
     178                    this->boost(false);
    158179                    this->bBoostCooldown_ = true;
    159180                    this->timer_.setTimer(this->boostCooldownDuration_, false, createExecutor(createFunctor(&SpaceShip::boostCooledDown, this)));
     181
    160182                }
    161             }
    162         }
    163     }
    164 
    165     void SpaceShip::boostCooledDown(void)
    166     {
    167         this->bBoostCooldown_ = false;
     183
     184                shakeCamera(dt);
     185            }
     186        }
    168187    }
    169188
     
    207226    }
    208227
    209     // TODO: something seems to call this function every tick, could probably handled a little more efficiently!
    210     void SpaceShip::setBoost(bool bBoost)
    211     {
    212         if(bBoost == this->bBoost_)
     228    void SpaceShip::fire()
     229    {
     230    }
     231
     232    /**
     233    @brief
     234        Starts or stops boosting.
     235    @param bBoost
     236        Whether to start or stop boosting.
     237    */
     238    void SpaceShip::boost(bool bBoost)
     239    {
     240        if(bBoost && !this->bBoostCooldown_)
     241        {
     242            //COUT(0) << "Boost startet!\n";
     243            this->bBoost_ = true;
     244        }
     245        if(!bBoost)
     246        {
     247            //COUT(0) << "Boost stoppt\n";
     248            this->resetCamera();
     249            this->bBoost_ = false;
     250        }
     251    }
     252   
     253    void SpaceShip::boostCooledDown(void)
     254    {
     255        this->bBoostCooldown_ = false;
     256    }
     257   
     258    void SpaceShip::shakeCamera(float dt)
     259    {
     260        //make sure the ship is only shaking if it's moving
     261        if (this->getVelocity().squaredLength() > 80)
     262        {
     263            this->shakeDt_ += dt;
     264   
     265            int frequency = this->shakeFrequency_ * (this->getVelocity().squaredLength());
     266   
     267            if (this->shakeDt_ >= 1 /(frequency))
     268            {
     269                this->shakeDt_ -= 1/(frequency);
     270            }
     271   
     272            Degree angle = Degree(sin(this->shakeDt_ * 2* math::pi * frequency) * this->shakeAmplitude_);
     273   
     274            //COUT(0) << "Angle: " << angle << std::endl;
     275            Camera* c = this->getCamera();
     276
     277            //Shaking Camera effect
     278            if (c != 0)
     279            {
     280                c->setOrientation(Vector3::UNIT_X, angle);
     281            }
     282        }
     283    }
     284   
     285    void SpaceShip::resetCamera()
     286    {
     287   
     288        //COUT(0) << "Resetting camera\n";
     289        Camera *c = this->getCamera();
     290   
     291        if (c == 0)
     292        {
     293            COUT(2) << "Failed to reset camera!";
    213294            return;
    214 
    215         if(bBoost)
    216             this->boost();
    217         else
    218         {
    219             this->bBoost_ = false;
    220         }
    221     }
    222 
    223     void SpaceShip::fire()
    224     {
    225     }
    226 
    227     void SpaceShip::boost()
    228     {
    229         if(!this->bBoostCooldown_)
    230             this->bBoost_ = true;
     295        }
     296   
     297        shakeDt_ = 0;
     298        //
     299        c->setPosition(this->cameraOriginalPosition_);
     300        c->setOrientation(this->cameraOriginalOrientation_);
    231301    }
    232302
     
    273343        return list;
    274344    }
     345   
     346
    275347}
  • code/branches/presentation/src/orxonox/worldentities/pawns/SpaceShip.h

    r8579 r8580  
    5959
    6060            virtual void fire();
    61             virtual void boost();
     61            virtual void boost(bool bBoost); // Starts or stops boosting.
    6262
    6363            void setEngine(Engine* engine);
     
    7070                { return this->steering_; }
    7171
    72             void setBoost(bool bBoost);
    7372            inline bool getBoost() const
    7473                { return this->bBoost_; }
     
    7978                { return this->enginetemplate_; }
    8079
    81             inline void setPermanentBoost(bool bPermanent)
    82                 { this->bPermanentBoost_ = bPermanent; }
    83             inline bool getPermanentBoost() const
    84                 { return this->bPermanentBoost_; }
    85 
    8680        protected:
    8781            virtual std::vector<PickupCarrier*>* getCarrierChildren(void) const;
     
    9084            bool bBoost_;
    9185            bool bBoostCooldown_;
    92             bool bPermanentBoost_;
    9386            float boostPower_;
    9487            float initialBoostPower_;
     
    10396            btVector3 localAngularAcceleration_;
    10497
     98            float shakeFrequency_;
     99            float shakeAmplitude_;
     100
    105101        private:
    106102            void registerVariables();
     
    110106           
    111107            void boostCooledDown(void);
     108       
     109            void resetCamera();
     110            void shakeCamera(float dt);
    112111
    113112            std::string enginetemplate_;
    114113            Engine* engine_;
    115114            Timer timer_;
     115            Vector3 cameraOriginalPosition_;
     116            Quaternion cameraOriginalOrientation_;
     117       
     118            float shakeDt_;
    116119    };
    117120}
Note: See TracChangeset for help on using the changeset viewer.