Loading

Paste #pfoetz24r

  1. diff --git a/src/person.cpp b/src/person.cpp
  2. --- a/src/person.cpp
  3. +++ b/src/person.cpp
  4. @@ -784,15 +784,13 @@ void Person::DeActivate(AnimateResult ar
  5.  }
  6.  
  7.  /**
  8. - * Update the animation of the guest.
  9. + * Update the animation of a person.
  10.   * @param delay Amount of milliseconds since the last update.
  11. - * @return If \c false, de-activate the person.
  12. - * @todo Merge things common to all persons to Person::OnAnimate.
  13. + * @return Whether to keep the person active or how to deactivate him/her.
  14. + * @return Result code of the visit.
  15.   */
  16. -AnimateResult Guest::OnAnimate(int delay)
  17. +AnimateResult Person::OnAnimate(int delay)
  18.  {
  19. -   if (this->activity == GA_ON_RIDE) return OAR_OK; // Guest is not animated while on ride.
  20. -
  21.     this->frame_time -= delay;
  22.     if (this->frame_time > 0) return OAR_OK;
  23.  
  24. @@ -885,16 +883,8 @@ AnimateResult Guest::OnAnimate(int delay
  25.     assert(this->x_pos >= 0 && this->x_pos < 256);
  26.     assert(this->y_pos >= 0 && this->y_pos < 256);
  27.  
  28. -   /* If the guest ended up off-world, quit. */
  29. -   if (this->x_vox < 0 || this->x_vox >= _world.GetXSize() * 256 ||
  30. -           this->y_vox < 0 || this->y_vox >= _world.GetYSize() * 256) {
  31. -       return OAR_DEACTIVATE;
  32. -   }
  33. -
  34. -   /* If the guest arrived at the 'go home' tile while going home, quit. */
  35. -   if (this->activity == GA_GO_HOME && this->x_vox == _guests.start_voxel.x && this->y_vox == _guests.start_voxel.y) {
  36. -       return OAR_DEACTIVATE;
  37. -   }
  38. +   AnimateResult ar = this->EdgeOfWorldOnAnimate();
  39. +   if (ar != OAR_CONTINUE) return ar;
  40.  
  41.     /* Handle raising of z position. */
  42.     if (this->z_pos > 128) {
  43. @@ -909,22 +899,10 @@ AnimateResult Guest::OnAnimate(int delay
  44.         if (instance >= SRI_FULL_RIDES) {
  45.             assert(exit_edge != INVALID_EDGE);
  46.             RideInstance *ri = _rides_manager.GetRideInstance(instance);
  47. -           if (ri->CanBeVisited(this->x_vox, this->y_vox, this->z_vox, exit_edge) && this->SelectItem(ri) != ITP_NOTHING) {
  48. -               /* All lights are green, let's try to enter the ride. */
  49. -               this->activity = GA_ON_RIDE;
  50. -               this->ride = ri;
  51. -               RideEntryResult rer = ri->EnterRide(this->id, exit_edge);
  52. -               if (rer != RER_REFUSED) {
  53. -                   this->BuyItem(ri);
  54. -                   /* Either the guest is already back at a path or he will be (through ExitRide). */
  55. -                   return OAR_OK;
  56. -               }
  57. +           AnimateResult ar = this->VisitRideOnAnimate(ri, exit_edge);
  58. +           if (ar != OAR_CONTINUE) return ar;
  59.  
  60. -               /* Could not enter, find another ride. */
  61. -               this->ride = nullptr;
  62. -               this->activity = GA_WANDER;
  63. -           }
  64. -           /* Ride is closed, fall-through to reversing movement. */
  65. +           /* Ride is could not be visited, fall-through to reversing movement. */
  66.  
  67.         } else if (HasValidPath(v)) {
  68.             this->AddSelf(v);
  69. @@ -978,13 +956,6 @@ RideVisitDesire Person::WantToVisit(cons
  70.  }
  71.  
  72.  /**
  73. - * @fn AnimateResult Person::OnAnimate(int delay)
  74. - * Update the animation of the person.
  75. - * @param delay Amount of milliseconds since the last update.
  76. - * @return Whether to keep the person active or how to deactivate him/her.
  77. - */
  78. -
  79. -/**
  80.   * @fn bool Person::DailyUpdate()
  81.   * Daily ponderings of a person.
  82.   * @return If \c false, de-activate the person.
  83. @@ -1038,6 +1009,58 @@ void Guest::DeActivate(AnimateResult ar)
  84.     this->Person::DeActivate(ar);
  85.  }
  86.  
  87. +AnimateResult Guest::OnAnimate(int delay)
  88. +{
  89. +   if (this->activity == GA_ON_RIDE) return OAR_OK; // Guest is not animated while on ride.
  90. +   return this->Person::OnAnimate(delay);
  91. +}
  92. +
  93. +/**
  94. + * Handle the case of a guest reaching the end of the game world.
  95. + * @return Result code of the visit.
  96. + */
  97. +AnimateResult Guest::EdgeOfWorldOnAnimate()
  98. +{
  99. +   /* If the guest ended up off-world, quit. */
  100. +   if (this->x_vox < 0 || this->x_vox >= _world.GetXSize() * 256 ||
  101. +           this->y_vox < 0 || this->y_vox >= _world.GetYSize() * 256) {
  102. +       return OAR_DEACTIVATE;
  103. +   }
  104. +
  105. +   /* If the guest arrived at the 'go home' tile while going home, quit. */
  106. +   if (this->activity == GA_GO_HOME && this->x_vox == _guests.start_voxel.x && this->y_vox == _guests.start_voxel.y) {
  107. +       return OAR_DEACTIVATE;
  108. +   }
  109. +
  110. +   return OAR_CONTINUE;
  111. +}
  112. +
  113. +/**
  114. + * Handle guest ride visiting.
  115. + * @param ri Ride that can be visited.
  116. + * @param exit_edge Exit edge being examined.
  117. + * @return Result code of the visit.
  118. + */
  119. +AnimateResult Guest::VisitRideOnAnimate(RideInstance *ri, TileEdge exit_edge)
  120. +{
  121. +   if (ri->CanBeVisited(this->x_vox, this->y_vox, this->z_vox, exit_edge) && this->SelectItem(ri) != ITP_NOTHING) {
  122. +       /* All lights are green, let's try to enter the ride. */
  123. +       this->activity = GA_ON_RIDE;
  124. +       this->ride = ri;
  125. +       RideEntryResult rer = ri->EnterRide(this->id, exit_edge);
  126. +       if (rer != RER_REFUSED) {
  127. +           this->BuyItem(ri);
  128. +           /* Either the guest is already back at a path or he will be (through ExitRide). */
  129. +           return OAR_OK;
  130. +       }
  131. +
  132. +       /* Could not enter, find another ride. */
  133. +       this->ride = nullptr;
  134. +       this->activity = GA_WANDER;
  135. +   }
  136. +   return OAR_CONTINUE;
  137. +}
  138. +
  139.  /**
  140.   * Update the happiness of the guest.
  141.   * @param amount Amount of change.
  142. diff --git a/src/person.h b/src/person.h
  143. --- a/src/person.h
  144. +++ b/src/person.h
  145. @@ -73,6 +73,7 @@ struct WalkInformation {
  146.  
  147.  /** Exit codes of the Person::OnAnimate call. */
  148.  enum AnimateResult {
  149. +   OAR_CONTINUE,   ///< No result yet, continue the routine.
  150.     OAR_OK,         ///< All OK, keep running.
  151.     OAR_REMOVE,     ///< Remove person from the person-list, and de-activate.
  152.     OAR_DEACTIVATE, ///< Person is already removed from the person-list, only de-activate.
  153. @@ -99,7 +100,7 @@ public:
  154.  
  155.     const ImageData *GetSprite(const SpriteStorage *sprites, ViewOrientation orient, const Recolouring **recolour) const override;
  156.  
  157. -   virtual AnimateResult OnAnimate(int delay) = 0;
  158. +   virtual AnimateResult OnAnimate(int delay);
  159.     virtual bool DailyUpdate() = 0;
  160.  
  161.     virtual void Activate(const Point16 &start, PersonType person_type);
  162. @@ -138,6 +139,8 @@ protected:
  163.     void StartAnimation(const WalkInformation *walk);
  164.  
  165.     virtual RideVisitDesire WantToVisit(const RideInstance *ri);
  166. +   virtual AnimateResult EdgeOfWorldOnAnimate() = 0;
  167. +   virtual AnimateResult VisitRideOnAnimate(RideInstance *ri, TileEdge exit_edge) = 0;
  168.  };
  169.  
  170.  /** Activities of the guest. */
  171. @@ -193,6 +196,8 @@ protected:
  172.     RideVisitDesire ComputeExitDesire(TileEdge current_edge, int x, int y, int z, TileEdge exit_edge, bool *seen_wanted_ride);
  173.     uint8 GetExitDirections(const Voxel *v, TileEdge start_edge, bool *seen_wanted_ride, bool *queue_mode);
  174.     RideVisitDesire WantToVisit(const RideInstance *ri) override;
  175. +   AnimateResult EdgeOfWorldOnAnimate() override;
  176. +   AnimateResult VisitRideOnAnimate(RideInstance *ri, TileEdge exit_edge) override;
  177.  
  178.     RideVisitDesire NeedForItem(enum ItemType it, bool use_random);
  179.     void AddItem(ItemType it);

Comments