/* $Id: invisiblecorona.cpp,v 1.6 2005/10/14 14:17:20 pohlt Exp $ */ #include "invisiblecorona.hpp" #include "world.hpp" #include "random.hpp" /**********************************************************/ #define MAX_DELAY 3 #define BOOT_SEQUENCE 0 #define WORK_SEQUENCE 1 /**********************************************************/ InvisibleCorona::InvisibleCorona() : m_direction( FORWARD ) { } /**********************************************************/ InvisibleCorona::~InvisibleCorona() { } /**********************************************************/ void InvisibleCorona::update() { // if the corona is in the boot sequence if( getSequence() == BOOT_SEQUENCE ) { // check, wheter it is booting ... if( m_direction == FORWARD ) { if( ++m_Frame >= m_SequenceLength ) { setSequence( WORK_SEQUENCE ); setFrame( 0 ); } // ... or shutting down } else { if( --m_Frame < 0 ) { m_removeMeAfterUpdate = true; return; } } } else { if( m_direction == FORWARD ) { if( ++m_Frame >= m_SequenceLength ) { m_direction = BACKWARD; m_Frame--; } } else { if( --m_Frame <= 0 ) { m_direction = FORWARD; m_Frame++; } } } } /**********************************************************/ void InvisibleCorona::signalShutdown() { setSequence( BOOT_SEQUENCE ); setFrame( m_SequenceLength - 1 ); m_direction = BACKWARD; } /**********************************************************/ void InvisibleCorona::reboot() { m_direction = FORWARD; } /**********************************************************/ Uint32 InvisibleCorona::getSerializeBufferSize() const { return NonCollidableObject::getSerializeBufferSize() + Serialize::sizeOf( m_direction ) // adds additional size for debugging (see serialize.hpp), // but only, if the tags are used PLUS_TAG_SIZE( 1 ); } /**********************************************************/ void InvisibleCorona::serialize( Uint8*& bufferPointer ) const { // expands to a check of the buffer movement START_OBJECT_SERIALIZED_SIZE_CHECK( bufferPointer ); NonCollidableObject::serialize( bufferPointer ); Serialize::serialize( m_direction, bufferPointer ); // expands to tag serialization SERIALIZE_OBJECT_TAG( bufferPointer ); // expands to a check of the buffer movement END_OBJECT_SERIALIZED_SIZE_CHECK( bufferPointer, InvisibleCorona ); } /**********************************************************/ void InvisibleCorona::deserialize( Uint8*& bufferPointer ) { NonCollidableObject::deserialize( bufferPointer ); Serialize::deserialize( bufferPointer, m_direction ); // expands to tag deserialization DESERIALIZE_OBJECT_TAG( bufferPointer ); } /**********************************************************/