Base.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #include "Base.h"
  2. #include "Spiel.h"
  3. #include "Ereignis.h"
  4. Base::Base( int id, int x, int y, int width, int height, bool showTimer, Punkt timerPosition, int timerFarbe, int maxTime, Team *team )
  5. : GameObject( BASE, x, y, width, height )
  6. {
  7. this->showTimer = showTimer;
  8. this->timerPosition = timerPosition;
  9. this->timerFarbe = timerFarbe;
  10. this->id = id;
  11. this->maxTime = maxTime;
  12. this->team = team;
  13. inChange = 0;
  14. nextTeam = 0;
  15. leftTime = (float)maxTime;
  16. }
  17. Base::~Base()
  18. {
  19. if( team )
  20. team->release();
  21. if( nextTeam )
  22. nextTeam->release();
  23. }
  24. void Base::setTeam( Team *team, Spiel *zSpiel )
  25. {
  26. Ereignis *e = new Ereignis( BASIS_BESITZERWECHSEL );
  27. e->addParameter( "Betroffene Basis", dynamic_cast<Base *>( getThis() ) );
  28. e->addParameter( "Vorheriges Team", this->team ? dynamic_cast<Team *>( this->team->getThis() ) : new Variable( NICHTS ) );
  29. e->addParameter( "Nächstes Team", team ? dynamic_cast<Team *>( team->getThis() ) : new Variable( NICHTS ) );
  30. if( this->team )
  31. this->team->release();
  32. this->team = team;
  33. zSpiel->setLastTeamChangedBase( dynamic_cast<Base *>( getThis() ) );
  34. zSpiel->throwEvent( e );
  35. }
  36. void Base::startChange( Team *team )
  37. {
  38. if( team == this->team )
  39. {
  40. inChange = 0;
  41. if( nextTeam )
  42. nextTeam = (Team *)nextTeam->release();
  43. team->release();
  44. return;
  45. }
  46. else if( this->team )
  47. {
  48. if( nextTeam )
  49. nextTeam = (Team *)nextTeam->release();
  50. leftTime = (float)maxTime;
  51. inChange = 1;
  52. team->release();
  53. }
  54. else
  55. {
  56. if( nextTeam )
  57. nextTeam = (Team *)nextTeam->release();
  58. nextTeam = team;
  59. leftTime = (float)maxTime;
  60. inChange = 1;
  61. }
  62. }
  63. void Base::tick( double time, Spiel *zSpiel )
  64. {
  65. if( inChange )
  66. {
  67. leftTime -= (float)time;
  68. if( leftTime <= 0 )
  69. {
  70. setTeam( nextTeam, zSpiel );
  71. nextTeam = 0;
  72. inChange = 0;
  73. }
  74. }
  75. }
  76. int Base::getId() const
  77. {
  78. return id;
  79. }
  80. Team *Base::getTeam() const
  81. {
  82. return team ? dynamic_cast<Team *>( team->getThis() ) : 0;
  83. }
  84. Team *Base::zTeam() const
  85. {
  86. return team;
  87. }