Base.cpp 2.0 KB

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