/* $Id: staticgun_i.cpp,v 1.21 2005/12/20 16:47:40 uwe Exp $ */ #include "staticgun_i.hpp" #include "weaponmissile.hpp" #include "weapongrenade.hpp" #include "weaponhook.hpp" /**********************************************************/ #define MIN_AIMING_ANGLE 60.0 #define MAX_AIMING_ANGLE 150.0 #define START_ANGLE 90.0 #define AIMING_ANGLE_INC 2.5 #define AIMING_LENGTH 35.0 #define SPRITE_ANGLE_INC 5 #define BARREL_DELAY_1 5 #define BARREL_DELAY_2 3 /**********************************************************/ const IntVector StaticGunI::m_checkPoint( 9, -4 ); const AreaItem StaticGunI::m_lockedArea( AreaItem::CIRCLE, -20, 0, 120 ); /**********************************************************/ StaticGunI::StaticGunI( World* wp ) : m_barrelTimer(0) { m_worldPointer = wp; m_Direction = LEFT; m_minAimingAngle = MIN_AIMING_ANGLE; m_maxAimingAngle = MAX_AIMING_ANGLE; m_aimingAngle = START_ANGLE; m_aimingAngleInc = AIMING_ANGLE_INC; m_aimingLength = AIMING_LENGTH; // initial update to fix the sequence updateSpriteSelection(); // initialise the random weapons // For this kind of stationary gun we will select the weapons // MISSILE, GRENADE, HOOK, and HOMING_MISSILE with equal // probability weights. Sint32 weaponWeights[] = { 1, 1, 1, 1 }; Sint32 weaponList[] = { WEAPON_MISSILE, WEAPON_GRENADE, WEAPON_HOOK, WEAPON_HOMING_MISSILE, INVALID_WEAPON }; // set the weapon list in the stationary gun setWeaponList( weaponList, weaponWeights, RANDOM ); changeWeapon(); } /**********************************************************/ StaticGunI::~StaticGunI() { } /**********************************************************/ void StaticGunI::updateSpriteSelection() { // the sequence depends exclusively on the aiming angle setSequence( (int)( (m_aimingAngle - MIN_AIMING_ANGLE) / SPRITE_ANGLE_INC) ); // the frame depends exclusively on the barrel state // getFrame() > 0: barrel "relaxes" if( getFrame() > 0 ) { // observe delay of barrel animation if( --m_barrelTimer <= 0 ) { // if the barrel animation is finished, fix barrel, ... if( ++m_Frame >= m_SequenceLength ) { setFrame( 0 ); // ... otherwise animate barrel } else { m_barrelTimer = m_Frame == 1 ? BARREL_DELAY_1 : BARREL_DELAY_2; } } } } /**********************************************************/ void StaticGunI::registerPilot( Avatar *const avatar ) { changeWeapon(); StationaryGun::registerPilot( avatar ); } /**********************************************************/ void StaticGunI::serialize( Uint8*& bufferPointer ) const { // expands to a check of the buffer movement START_OBJECT_SERIALIZED_SIZE_CHECK( bufferPointer ); StationaryGun::serialize( bufferPointer ); Serialize::serialize( m_barrelTimer, bufferPointer ); // expands to tag serialization SERIALIZE_OBJECT_TAG( bufferPointer ); // expands to a check of the buffer movement END_OBJECT_SERIALIZED_SIZE_CHECK( bufferPointer, StaticGunI ); } /**********************************************************/ void StaticGunI::deserialize( Uint8*& bufferPointer ) { StationaryGun::deserialize( bufferPointer ); Serialize::deserialize( bufferPointer, m_barrelTimer ); // expands to tag deserialization DESERIALIZE_OBJECT_TAG( bufferPointer ); } /**********************************************************/ Uint32 StaticGunI::getSerializeBufferSize() const { return StationaryGun::getSerializeBufferSize() + Serialize::sizeOf( m_barrelTimer ) // adds additional size for debugging (see serialize.hpp), // but only, if the tags are used PLUS_TAG_SIZE( 1 ); } /**********************************************************/ void StaticGunI::doShot() { // The reload time of the static gun is limited by // the sequence of the barrel movement. if( getFrame() > 0 ) return; setFrame( 1 ); StationaryGun::doShot(); } /**********************************************************/