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