Base.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. if( team )
  68. team->release();
  69. team = nextTeam;
  70. inChange = 0;
  71. }
  72. }
  73. }
  74. int Base::getId() const
  75. {
  76. return id;
  77. }
  78. Team *Base::getTeam() const
  79. {
  80. return team ? (Team *)team->getThis() : 0;
  81. }
  82. Team *Base::zTeam() const
  83. {
  84. return team;
  85. }