Base.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 )
  22. {
  23. if( this->team )
  24. this->team->release();
  25. this->team = team;
  26. }
  27. void Base::startChange( Team *team )
  28. {
  29. if( team == this->team )
  30. {
  31. inChange = 0;
  32. if( nextTeam )
  33. nextTeam = (Team*)nextTeam->release();
  34. team->release();
  35. return;
  36. }
  37. else if( this->team )
  38. {
  39. if( nextTeam )
  40. nextTeam = (Team *)nextTeam->release();
  41. leftTime = (float)maxTime;
  42. inChange = 1;
  43. team->release();
  44. }
  45. else
  46. {
  47. if( nextTeam )
  48. nextTeam = (Team *)nextTeam->release();
  49. nextTeam = team;
  50. leftTime = (float)maxTime;
  51. inChange = 1;
  52. }
  53. }
  54. void Base::tick( double time, Spiel *zSpiel )
  55. {
  56. if( inChange )
  57. {
  58. leftTime -= (float)time;
  59. if( leftTime <= 0 )
  60. {
  61. Ereignis *e = new Ereignis( BASIS_BESITZERWECHSEL );
  62. e->addParameter( "Betroffene Basis", getThis() );
  63. e->addParameter( "Vorheriges Team", team ? team->getThis() : new Variable( NICHTS ) );
  64. e->addParameter( "Nächstes Team", nextTeam ? nextTeam->getThis() : new Variable( NICHTS ) );
  65. zSpiel->throwEvent( e );
  66. this->team->release();
  67. this->team = nextTeam;
  68. inChange = 0;
  69. }
  70. }
  71. }
  72. Team *Base::getTeam() const
  73. {
  74. return team ? (Team*)team->getThis() : 0;
  75. }
  76. Team *Base::zTeam() const
  77. {
  78. return team;
  79. }