#include "Base.h" #include "Spiel.h" #include "Ereignis.h" Base::Base( ResourceRegistry *zResources, int id, int x, int y, int width, int height, bool showTimer, Punkt timerPosition, int timerFarbe, TextRenderer *tr, int maxTime, Team *team ) : GameObject( BASE, x, y, width, height ) { this->tr = tr; tr->setSchriftSize( 12 ); this->showTimer = showTimer; this->timerPosition = timerPosition; this->timerFarbe = timerFarbe; this->id = id; this->maxTime = maxTime; this->team = team; inChange = 0; nextTeam = 0; leftTime = (float)maxTime; resources = dynamic_cast( zResources->getThis() ); this->textur = dynamic_cast( resources->zResource( R_BASE, team ? team->getFarbe() : 0 )->getImages()->getThis() ); texturScale = 1; } Base::~Base() { tr->release(); if( team ) team->release(); if( nextTeam ) nextTeam->release(); resources->release(); } void Base::setTeam( Team *team, Spiel *zSpiel ) { Ereignis *e = new Ereignis( BASIS_BESITZERWECHSEL ); e->addParameter( "Betroffene Basis", dynamic_cast( getThis() ) ); e->addParameter( "Vorheriges Team", this->team ? dynamic_cast( this->team->getThis() ) : new Variable( NICHTS ) ); e->addParameter( "Nächstes Team", team ? dynamic_cast( team->getThis() ) : new Variable( NICHTS ) ); if( this->team ) this->team->release(); this->team = team; if( textur ) textur->release(); textur = dynamic_cast( resources->zResource( R_BASE, team ? team->getFarbe() : 0 )->getImages()->getThis() ); zSpiel->setLastTeamChangedBase( dynamic_cast( getThis() ) ); zSpiel->throwEvent( e ); } void Base::startChange( Team *team ) { if( team == this->team ) { inChange = 0; if( nextTeam ) nextTeam = (Team *)nextTeam->release(); team->release(); return; } else if( this->team ) { if( nextTeam ) nextTeam = (Team *)nextTeam->release(); leftTime = (float)maxTime; inChange = 1; team->release(); } else { if( nextTeam ) nextTeam = (Team *)nextTeam->release(); nextTeam = team; leftTime = (float)maxTime; inChange = 1; } } void Base::tick( double time, Spiel *zSpiel ) { if( inChange ) { leftTime -= (float)time; if( leftTime <= 0 ) { setTeam( nextTeam, zSpiel ); nextTeam = 0; inChange = 0; } } } void Base::render( Bild &rObj ) { GameObject::render( rObj ); if( showTimer && inChange ) tr->renderText( timerPosition.x, timerPosition.y, Text( (int)( leftTime * 100 ) / 100.0 ), rObj, timerFarbe ); } int Base::getId() const { return id; } Team *Base::getTeam() const { return team ? dynamic_cast( team->getThis() ) : 0; } Team *Base::zTeam() const { return team; }