Base.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #include "Base.h"
  2. #include "Spiel.h"
  3. #include "Ereignis.h"
  4. 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 )
  5. : GameObject( BASE, x, y, width, height )
  6. {
  7. this->tr = tr;
  8. tr->setSchriftSize( 12 );
  9. this->showTimer = showTimer;
  10. this->timerPosition = timerPosition;
  11. this->timerFarbe = timerFarbe;
  12. this->id = id;
  13. this->maxTime = maxTime;
  14. this->team = team;
  15. inChange = 0;
  16. nextTeam = 0;
  17. leftTime = (float)maxTime;
  18. resources = dynamic_cast<ResourceRegistry *>( zResources->getThis() );
  19. this->textur = dynamic_cast<Bild *>( resources->zResource( R_BASE, team ? team->getFarbe() : 0 )->getImages()->getThis() );
  20. texturScale = 1;
  21. }
  22. Base::~Base()
  23. {
  24. tr->release();
  25. if( team )
  26. team->release();
  27. if( nextTeam )
  28. nextTeam->release();
  29. resources->release();
  30. }
  31. void Base::setTeam( Team *team, Spiel *zSpiel )
  32. {
  33. Ereignis *e = new Ereignis( BASIS_BESITZERWECHSEL );
  34. e->addParameter( "Betroffene Basis", dynamic_cast<Base *>( getThis() ) );
  35. e->addParameter( "Vorheriges Team", this->team ? dynamic_cast<Base *>( this->team->getThis() ) : new Variable( NICHTS ) );
  36. e->addParameter( "Nächstes Team", team ? dynamic_cast<Team *>( team->getThis() ) : new Variable( NICHTS ) );
  37. if( this->team )
  38. this->team->release();
  39. this->team = team;
  40. if( textur )
  41. textur->release();
  42. textur = dynamic_cast<Bild *>( resources->zResource( R_BASE, team ? team->getFarbe() : 0 )->getImages()->getThis() );
  43. zSpiel->setLastTeamChangedBase( dynamic_cast<Base *>( getThis() ) );
  44. zSpiel->throwEvent( e );
  45. }
  46. void Base::startChange( Team *team )
  47. {
  48. if( team == this->team )
  49. {
  50. inChange = 0;
  51. if( nextTeam )
  52. nextTeam = (Team *)nextTeam->release();
  53. team->release();
  54. return;
  55. }
  56. else if( this->team )
  57. {
  58. if( nextTeam )
  59. nextTeam = (Team *)nextTeam->release();
  60. leftTime = (float)maxTime;
  61. inChange = 1;
  62. team->release();
  63. }
  64. else
  65. {
  66. if( nextTeam )
  67. nextTeam = (Team *)nextTeam->release();
  68. nextTeam = team;
  69. leftTime = (float)maxTime;
  70. inChange = 1;
  71. }
  72. }
  73. void Base::tick( double time, Spiel *zSpiel )
  74. {
  75. if( inChange )
  76. {
  77. leftTime -= (float)time;
  78. if( leftTime <= 0 )
  79. {
  80. setTeam( nextTeam, zSpiel );
  81. nextTeam = 0;
  82. inChange = 0;
  83. }
  84. }
  85. }
  86. void Base::render( Bild &rObj )
  87. {
  88. GameObject::render( rObj );
  89. if( showTimer && inChange )
  90. tr->renderText( timerPosition.x, timerPosition.y, Text( (int)( leftTime * 100 ) / 100.0 ), rObj, timerFarbe );
  91. }
  92. int Base::getId() const
  93. {
  94. return id;
  95. }
  96. Team *Base::getTeam() const
  97. {
  98. return team ? dynamic_cast<Team *>( team->getThis() ) : 0;
  99. }
  100. Team *Base::zTeam() const
  101. {
  102. return team;
  103. }