Base.cpp 2.3 KB

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