|
@@ -0,0 +1,87 @@
|
|
|
+#include "Base.h"
|
|
|
+#include "Spiel.h"
|
|
|
+#include "Ereignis.h"
|
|
|
+
|
|
|
+
|
|
|
+Base::Base( int id, int x, int y, int width, int height, int maxTime, Team *team )
|
|
|
+ : GameObject( x, y, width, height )
|
|
|
+{
|
|
|
+ this->id = id;
|
|
|
+ this->maxTime = maxTime;
|
|
|
+ this->team = team;
|
|
|
+ inChange = 0;
|
|
|
+ nextTeam = 0;
|
|
|
+ leftTime = (float)maxTime;
|
|
|
+}
|
|
|
+
|
|
|
+Base::~Base()
|
|
|
+{
|
|
|
+ if( team )
|
|
|
+ team->release();
|
|
|
+ if( nextTeam )
|
|
|
+ nextTeam->release();
|
|
|
+}
|
|
|
+
|
|
|
+void Base::setTeam( Team *team )
|
|
|
+{
|
|
|
+ if( this->team )
|
|
|
+ this->team->release();
|
|
|
+ this->team = team;
|
|
|
+}
|
|
|
+
|
|
|
+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 )
|
|
|
+ {
|
|
|
+ Ereignis *e = new Ereignis( BASIS_BESITZERWECHSEL );
|
|
|
+ e->addParameter( "Betroffene Basis", getThis() );
|
|
|
+ e->addParameter( "Vorheriges Team", team ? team->getThis() : new Variable( NICHTS ) );
|
|
|
+ e->addParameter( "Nächstes Team", nextTeam ? nextTeam->getThis() : new Variable( NICHTS ) );
|
|
|
+ zSpiel->throwEvent( e );
|
|
|
+ this->team->release();
|
|
|
+ this->team = nextTeam;
|
|
|
+ inChange = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+Team *Base::getTeam() const
|
|
|
+{
|
|
|
+ return team ? (Team*)team->getThis() : 0;
|
|
|
+}
|
|
|
+
|
|
|
+Team *Base::zTeam() const
|
|
|
+{
|
|
|
+ return team;
|
|
|
+}
|