/* $Id: collidableobject.hpp,v 1.26.4.2 2006/01/20 11:33:52 chfreund Exp $ */ #ifndef _COLLIDABLEOBJECT_HPP_ #define _COLLIDABLEOBJECT_HPP_ #include #include "attachableobject.hpp" #include "particles.hpp" /**********************************************************/ class Player; /**********************************************************/ /*! Collidable objects are derived from the Object class. Their additional feature is that they can collide with other collidable objects, earth and/or particles depending on the implementation of CollidableObject::update. */ class CollidableObject : public AttachableObject { public: CollidableObject( void ); virtual ~CollidableObject( void ); ////////// // Health & Damage /*! This method is called to determine the collision with another collidable object or a particle at position \a x, \a c \return \c true if the specified position is on or within the collision rectangle of the object; \c false otherwise. */ bool testHit( const int x, const int y ) { if( ! m_collRectSet ) return false; const bool hit = x >= ROUND( m_pos.x ) + m_collRectX && x <= ROUND( m_pos.x ) + m_collRectX + m_collRectWidth - 1 && y >= ROUND( m_pos.y ) + m_collRectY && y <= ROUND( m_pos.y ) + m_collRectY + m_collRectHeight - 1; DBG( 5 ) { if( ! hit ) { const real dx = m_pos.x - x, dy = m_pos.y - y; INFO( "CollidableObject::testHit:no hit, dist = %6.1f\n" "\tx : %3i, y : %3i\n" "\tx1: %3i, y1: %3i\n" "\tx2: %3i, y2: %3i\n", SQRT_REAL( dx*dx + dy*dy ), x, y, ROUND( m_pos.x ) + m_collRectX, ROUND( m_pos.y ) + m_collRectY, ROUND( m_pos.x ) + m_collRectX + m_collRectWidth - 1, ROUND( m_pos.y ) + m_collRectY + m_collRectHeight - 1 ); } } return hit; } virtual bool testGrounded( void ); /*! This method is called when the object is damaged by the specified particle \a p. Things that have to be done within this method: - add recoil to the object's force - calculate damage and subtract this value from \a m_health - play damage sample and set \a m_damageSampleTimeout to an appropriate value - destroy object if necessary \return the affected damage \todo Move the basic stuff into the base class CollidableObject. */ virtual int applyDamage( const Particles::ParticleData& p ); virtual int applyDamage( const int damage, Player* shooter ); Sint32 getHealth( void ) const { return m_health; } real getMass( void ) const { return m_mass; } Sint32 getCollRectX( void ) const { return m_collRectX; } Sint32 getCollRectY( void ) const { return m_collRectY; } Sint32 getCollRectWidth( void ) const { return m_collRectWidth; } Sint32 getCollRectHeight( void ) const { return m_collRectHeight; } void setHealth( const Sint32 health ) { m_health = health; } bool wasHurt( void ) const { return m_wasHurt; } void setWasHurt( const bool newWasHurt ) { m_wasHurt = newWasHurt; } void setCollRect( void ); void removeCollRect( void ); bool testCollRect( void ); virtual void update( void ); virtual bool preBallistics( const bool continueUpdate = true ); virtual bool doBallistics( const bool continueUpdate = true ); virtual bool postBallistics( const bool continueUpdate = true ); virtual bool collidedWithObstacle( const Sint32 colX, const Sint32 colY ); void setFocusPriority( const int priority ) { m_focusPriority = priority; } int getFocusPriority( void ) { return m_focusPriority; } virtual void serialize( Uint8*& bufferPointer ) const; virtual void deserialize( Uint8*& bufferPointer ); virtual Uint32 getSerializeBufferSize() const; virtual void dump( std::ostream& out ) const; protected: real m_mass; real m_bounceThresholdVel2, m_bounceFactorHLVel, m_bounceFactorLow, m_bounceFactorHigh, m_maxGroundedForce2, m_maxGroundedForceVert; Sint32 m_collRectX, m_collRectY, m_collRectWidth, m_collRectHeight; Sint32 m_health; Sint32 m_damageSampleTimeout; Sint32 m_focusPriority; /* local value which is _not_ serialized */ bool m_collRectSet; bool m_firstUpdate; bool m_wasHurt; }; /**********************************************************/ #endif // _COLLIDABLEOBJECT_HPP_