Loading

Paste #p1qa55iss

  1. diff --git a/src/coaster.cpp b/src/coaster.cpp
  2. --- a/src/coaster.cpp
  3. +++ b/src/coaster.cpp
  4. @@ -602,6 +602,16 @@ uint8 CoasterInstance::GetEntranceDirect
  5.         return 0; /// \todo add entrance bits for the coaster.
  6.  }
  7.  
  8. +bool CoasterInstance::EnterRide(int guest)
  9. +{
  10. +       return true; /// \todo Store the guest number.
  11. +}
  12. +
  13. +void CoasterInstance::GetExit(int guest, uint32 *xpos, uint32 *ypos, uint32 *zpos)
  14. +{
  15. +       assert(false); // Not yet implemented.
  16. +}
  17. +
  18.  /**
  19.   * Check the state of the coaster ride, and set the #state flag.
  20.   * @return The new coaster instance state.
  21. diff --git a/src/coaster.h b/src/coaster.h
  22. --- a/src/coaster.h
  23. +++ b/src/coaster.h
  24. @@ -193,6 +193,8 @@ public:
  25.  
  26.         void GetSprites(uint16 voxel_number, uint8 orient, const ImageData *sprites[4]) const override;
  27.         uint8 GetEntranceDirections(uint16 xvox, uint16 yvox, uint8 zvox) const override;
  28. +       bool EnterRide(int guest) override;
  29. +       void GetExit(int guest, uint32 *xpos, uint32 *ypos, uint32 *zpos) override;
  30.  
  31.         RideInstanceState DecideRideState();
  32.  
  33. diff --git a/src/person.cpp b/src/person.cpp
  34. --- a/src/person.cpp
  35. +++ b/src/person.cpp
  36. @@ -855,8 +855,19 @@ AnimateResult Guest::OnAnimate(int delay
  37.                 if (instance >= SRI_FULL_RIDES) {
  38.                         assert(exit_edge != INVALID_EDGE);
  39.                         RideInstance *ri = _rides_manager.GetRideInstance(instance);
  40. -                       if (ri->CanBeVisited(this->x_vox, this->y_vox, this->z_vox, exit_edge)) {
  41. -                               this->VisitShop(ri);
  42. +                       if (ri->CanBeVisited(this->x_vox, this->y_vox, this->z_vox, exit_edge) && this->VisitRide(ri)) {
  43. +                               /* Visited ride, ask ride where to go. */
  44. +                               if (ri->EnterRide(this->id)) {
  45. +                                       assert(false); // Rides should no request a guest to stay.
  46. +                               }
  47. +                               uint32 xpos, ypos, zpos;
  48. +                               ri->GetExit(this->id, &xpos, &ypos, &zpos);
  49. +                               this->x_vox = xpos >> 8; this->x_pos = xpos & 0xff;
  50. +                               this->y_vox = ypos >> 8; this->y_pos = ypos & 0xff;
  51. +                               this->z_vox = zpos >> 8; this->z_pos = zpos & 0xff;
  52. +                               this->AddSelf(_world.GetCreateVoxel(this->x_vox, this->y_vox, this->z_vox, false));
  53. +                               this->DecideMoveDirection();
  54. +                               return OAR_OK;
  55.                         }
  56.                         /* Ride is closed, fall-through to reversing movement. */
  57.  
  58. @@ -1175,9 +1186,9 @@ void Guest::AddItem(ItemType it)
  59.  /**
  60.   * Visit the shop.
  61.   * @param ri Ride being visited.
  62. - * @note It is called 'shop', but it is quite generic, so it may be usable for more rides (without queue in front of it).
  63. + * @return Guest actually visited the ride, perform the RideInstance::EnterRide protocol, to make the guest stay inside, if needed.
  64.   */
  65. -void Guest::VisitShop(RideInstance *ri)
  66. +bool Guest::VisitRide(RideInstance *ri)
  67.  {
  68.         bool can_buy[NUMBER_ITEM_TYPES_SOLD];
  69.         int count = 0;
  70. @@ -1206,9 +1217,10 @@ void Guest::VisitShop(RideInstance *ri)
  71.                         this->cash -= ri->GetSaleItemPrice(i);
  72.                         this->AddItem(ri->GetSaleItemType(i));
  73.                         this->ChangeHappiness(10);
  74. -                       return;
  75. +                       return true;
  76.                 }
  77.         }
  78.  
  79.         this->ChangeHappiness(-10);
  80. +       return false;
  81.  }
  82. diff --git a/src/person.h b/src/person.h
  83. --- a/src/person.h
  84. +++ b/src/person.h
  85. @@ -160,7 +160,7 @@ public:
  86.         bool DailyUpdate() override;
  87.  
  88.         void ChangeHappiness(int16 amount);
  89. -       void VisitShop(RideInstance *ri);
  90. +       bool VisitRide(RideInstance *ri);
  91.         void NotifyRideDeletion(const RideInstance *ri);
  92.  
  93.         GuestActivity activity; ///< Activity being done by the guest currently.
  94. diff --git a/src/ride_type.cpp b/src/ride_type.cpp
  95. --- a/src/ride_type.cpp
  96. +++ b/src/ride_type.cpp
  97. @@ -200,7 +200,25 @@ const RideType *RideInstance::GetRideTyp
  98.   */
  99.  
  100.  /**
  101. - * Can the ride be visited, assuming the shop is approached from direction \a edge?
  102. + * \fn bool RideInstance::EnterRide(int guest)
  103. + * The given guest enters the ride. If the call returns \c false, the guest should immediately call RideInstance::GetExit
  104. + * to get the exit coordinates. If the call returns \c true, the guest should wait until the ride sends a Guest::ExitRide
  105. + * request (and then call RideInstance::GetExit for the coordinates).
  106. + * @param guest Number of the guest entering the ride.
  107. + * @return Whether the guest should stay in the ride.
  108. + */
  109. +
  110. +/**
  111. + * \fn void RideInstance::GetExit(int guest, uint32 *xpos, uint32 *ypos, uint32 *zpos)
  112. + * Get the exit coordinates of the ride, is near the middle of a tile edge.
  113. + * @param guest Number of the guest querying the exit coordinates.
  114. + * @param xpos X world position of the exit.
  115. + * @param ypos Y world position of the exit.
  116. + * @param zpos Z world position of the exit
  117. + */
  118. +
  119. +/**
  120. + * Can the ride be visited, assuming it is approached from direction \a edge?
  121.   * @param xvox X position of the voxel with the ride.
  122.   * @param yvox Y position of the voxel with the ride.
  123.   * @param zvox Z position of the voxel with the ride.
  124. diff --git a/src/ride_type.h b/src/ride_type.h
  125. --- a/src/ride_type.h
  126. +++ b/src/ride_type.h
  127. @@ -131,6 +131,8 @@ public:
  128.  
  129.         virtual void GetSprites(uint16 voxel_number, uint8 orient, const ImageData *sprites[4]) const = 0;
  130.         virtual uint8 GetEntranceDirections(uint16 xvox, uint16 yvox, uint8 zvox) const = 0;
  131. +       virtual bool EnterRide(int guest) = 0;
  132. +       virtual void GetExit(int guest, uint32 *xpos, uint32 *ypos, uint32 *zpos) = 0;
  133.         bool CanBeVisited(uint16 xvox, uint16 yvox, uint8 zvox, TileEdge edge) const;
  134.  
  135.         void SellItem(int item_index);
  136. diff --git a/src/shop_type.cpp b/src/shop_type.cpp
  137. --- a/src/shop_type.cpp
  138. +++ b/src/shop_type.cpp
  139. @@ -176,3 +176,25 @@ uint8 ShopInstance::GetEntranceDirection
  140.         uint8 entrances = this->GetShopType()->flags & SHF_ENTRANCE_BITS;
  141.         return ROL(entrances, 4, this->orientation);
  142.  }
  143. +
  144. +bool ShopInstance::EnterRide(int guest)
  145. +{
  146. +       return false; // Don't stay inside a shop.
  147. +}
  148. +
  149. +void ShopInstance::GetExit(int guest, uint32 *xpos, uint32 *ypos, uint32 *zpos)
  150. +{
  151. +       /* Put the guest just outside the door. */
  152. +       uint8 entrances = this->GetShopType()->flags & SHF_ENTRANCE_BITS;
  153. +       entrances = ROL(entrances, 4, this->orientation);
  154. +       for (TileEdge edge = EDGE_BEGIN; edge < EDGE_COUNT; edge++) {
  155. +               if ((entrances & (1 << edge)) != 0) {
  156. +                       Point16 dxy = _exit_dxy[edge];
  157. +                       *xpos = this->xpos * 256 + dxy.x;
  158. +                       *ypos = this->ypos * 256 + dxy.y;
  159. +                       *zpos = this->zpos * 256;
  160. +                       return;
  161. +               }
  162. +       }
  163. +       NOT_REACHED();
  164. +}
  165. diff --git a/src/shop_type.h b/src/shop_type.h
  166. --- a/src/shop_type.h
  167. +++ b/src/shop_type.h
  168. @@ -47,6 +47,8 @@ public:
  169.  
  170.         void SetRide(uint8 orientation, uint16 xpos, uint16 ypos, uint8 zpos);
  171.         uint8 GetEntranceDirections(uint16 xvox, uint16 yvox, uint8 zvox) const override;
  172. +       bool EnterRide(int guest) override;
  173. +       void GetExit(int guest, uint32 *xpos, uint32 *ypos, uint32 *zpos) override;
  174.  
  175.         uint8 orientation; ///< Orientation of the shop.
  176.         uint16 xpos;       ///< X position of the shop base voxel.
  177. diff --git a/src/tile.h b/src/tile.h
  178. --- a/src/tile.h
  179. +++ b/src/tile.h
  180. @@ -237,6 +237,7 @@ DECLARE_POSTFIX_INCREMENT(TrackSlope)
  181.  extern const uint8 _corners_at_edge[EDGE_COUNT];
  182.  extern const Point16 _corner_dxy[4];
  183.  extern const Point16 _tile_dxy[EDGE_COUNT];
  184. +extern const Point16 _exit_dxy[EDGE_COUNT];
  185.  
  186.  void ComputeCornerHeight(TileSlope slope, uint8 base_height, uint8 *output);
  187.  void ComputeSlopeAndHeight(uint8 *corners, TileSlope *slope, uint8 *base);
  188. diff --git a/src/tile_func.cpp b/src/tile_func.cpp
  189. --- a/src/tile_func.cpp
  190. +++ b/src/tile_func.cpp
  191. @@ -36,6 +36,14 @@ const Point16 _tile_dxy[EDGE_COUNT] = {
  192.         { 0, -1}, ///< EDGE_NW
  193.  };
  194.  
  195. +/** Pixel position for a guest exiting a ride exit, relative to the base position of the exit voxel of the ride. */
  196. +const Point16 _exit_dxy[EDGE_COUNT] = {
  197. +       { -1, 128}, ///< EDGE_NE
  198. +       {128, 256}, ///< EDGE_SE
  199. +       {256, 128}, ///< EDGE_SW
  200. +       {128,  -1}, ///< EDGE_NW
  201. +};
  202. +
  203.  /**
  204.   * Compute the height of the corners of an expanded ground tile.
  205.   * @param slope Expanded slope.

Comments