Base.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #include "Base.h"
  2. #include "Spiel.h"
  3. #include "Ereignis.h"
  4. Base::Base( ResourceRegistry *zResources, 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. resources = zResources->getThis();
  14. this->textur = resources->zResource( R_BASE, team ? team->getFarbe() : 0 )->getImages()->getThis();
  15. texturScale = 1;
  16. }
  17. Base::~Base()
  18. {
  19. if( team )
  20. team->release();
  21. if( nextTeam )
  22. nextTeam->release();
  23. resources->release();
  24. }
  25. void Base::setTeam( Team *team, Spiel *zSpiel )
  26. {
  27. if( this->team )
  28. this->team->release();
  29. this->team = team;
  30. if( textur )
  31. textur->release();
  32. textur = resources->zResource( R_BASE, team ? team->getFarbe() : 0 )->getImages()->getThis();
  33. zSpiel->setLastTeamChangedBase( (Base *)getThis() );
  34. }
  35. void Base::startChange( Team *team )
  36. {
  37. if( team == this->team )
  38. {
  39. inChange = 0;
  40. if( nextTeam )
  41. nextTeam = (Team *)nextTeam->release();
  42. team->release();
  43. return;
  44. }
  45. else if( this->team )
  46. {
  47. if( nextTeam )
  48. nextTeam = (Team *)nextTeam->release();
  49. leftTime = (float)maxTime;
  50. inChange = 1;
  51. team->release();
  52. }
  53. else
  54. {
  55. if( nextTeam )
  56. nextTeam = (Team *)nextTeam->release();
  57. nextTeam = team;
  58. leftTime = (float)maxTime;
  59. inChange = 1;
  60. }
  61. }
  62. void Base::tick( double time, Spiel *zSpiel )
  63. {
  64. if( inChange )
  65. {
  66. leftTime -= (float)time;
  67. if( leftTime <= 0 )
  68. {
  69. Ereignis *e = new Ereignis( BASIS_BESITZERWECHSEL );
  70. e->addParameter( "Betroffene Basis", getThis() );
  71. e->addParameter( "Vorheriges Team", team ? team->getThis() : new Variable( NICHTS ) );
  72. e->addParameter( "Nächstes Team", nextTeam ? nextTeam->getThis() : new Variable( NICHTS ) );
  73. zSpiel->throwEvent( e );
  74. if( team )
  75. team->release();
  76. team = nextTeam;
  77. inChange = 0;
  78. }
  79. }
  80. }
  81. int Base::getId() const
  82. {
  83. return id;
  84. }
  85. Team *Base::getTeam() const
  86. {
  87. return team ? (Team *)team->getThis() : 0;
  88. }
  89. Team *Base::zTeam() const
  90. {
  91. return team;
  92. }