Loading

drop litter

  1. # HG changeset patch
  2. # Parent 4234d1b8f0a925fa043995ccdce7fe1ba815fe75
  3.  
  4. diff --git a/src/person.cpp b/src/person.cpp
  5. --- a/src/person.cpp
  6. +++ b/src/person.cpp
  7. @@ -25,6 +25,8 @@
  8.  #include "viewport.h"
  9.  #include "weather.h"
  10.  
  11. +static const int MEAN_LITTER_DROPCOUNT = 30; ///< Average number of tiles after finishing eating to drop wrapper as litter.
  12. +
  13.  static PersonTypeData _person_type_datas[PERSON_TYPE_COUNT]; ///< Data about each type of person.
  14.  
  15.  /**
  16. @@ -382,6 +384,11 @@ TileEdge Person::GetCurrentEdge() const
  17.  }
  18.  
  19.  /**
  20. + * @fn Person::DecideMoveDirection()
  21. + * Decide where to go from the current position.
  22. + */
  23. +
  24. +/**
  25.   * Decide whether visiting the exit edge is useful.
  26.   * @param current_edge Edge at the current position.
  27.   * @param x X coordinate of the current voxel.
  28. @@ -626,13 +633,32 @@ static int GetDesiredEdgeIndex(TileEdge
  29.  }
  30.  
  31.  /**
  32. - * @fn Person::DecideMoveDirection()
  33. - * Decide where to go from the current position.
  34. + * Attempt to drop the wrapper onto the path in the voxel.
  35. + * @param v %Voxel to drop the wrapper.
  36. + * @param wrapper_counter Counter of number of tiles to wait until the wrapper is forcibly dropped.
  37. + * @return Whether or not the wrapper was dropped.
  38.   */
  39. +static bool TryDropWrapper(Voxel *v, uint16 wrapper_counter)
  40. +{
  41. +   uint16 path_instance_data = v->GetInstanceData();
  42. +   if (wrapper_counter > 1 && (GetPathDecoration(path_instance_data) != PDEC_LITTERBIN || GetVisiblePathLitter(path_instance_data) > 0)) {
  43. +       return false; // Wait for a better place to drop the litter.
  44. +   }
  45. +
  46. +   /* Should drop the wrapper asap. */
  47. +   if (GetVisiblePathLitter(path_instance_data) == 3) return false; // Already maximal litter, wait until the next tile.
  48. +
  49. +   uint litter = GetPathLitter(path_instance_data);
  50. +   path_instance_data = SetPathLitter(path_instance_data, litter + 1);
  51. +   v->SetInstanceData(path_instance_data);
  52. +   return true; // Dropped.
  53. +
  54. +}
  55. +
  56.  void Guest::DecideMoveDirection()
  57.  {
  58. -   const VoxelStack *vs = _world.GetStack(this->vox_pos.x, this->vox_pos.y);
  59. -   const Voxel *v = vs->Get(this->vox_pos.z);
  60. +   VoxelStack *vs = _world.GetModifyStack(this->vox_pos.x, this->vox_pos.y);
  61. +   Voxel *v = vs->GetCreate(this->vox_pos.z, false);
  62.     TileEdge start_edge = this->GetCurrentEdge(); // Edge the person is currently.
  63.  
  64.     if (this->activity == GA_ENTER_PARK && vs->owner == OWN_PARK) {
  65. @@ -641,10 +667,19 @@ void Guest::DecideMoveDirection()
  66.         // Add some happiness?? (Somewhat useless as every guest enters the park. On the other hand, a nice point to configure difficulty level perhaps?)
  67.     }
  68.  
  69. -   /* Find feasible exits and shops. */
  70.     uint8 exits, shops;
  71.     bool queue_path;
  72.     if (HasValidPath(v)) {
  73. +       /* Can we drop the wrapper? */
  74. +       if (this->food == 0 && this->drink == 0 && this->wrapper_counter > 0) { // Guest has finished eating, and is holding a wrapper.
  75. +           if (TryDropWrapper(v, this->wrapper_counter)) {
  76. +               this->wrapper_counter = 0;
  77. +           } else {
  78. +               if (this->wrapper_counter > 1) this->wrapper_counter--;
  79. +           }
  80. +       }
  81. +
  82. +       /* Find feasible exits and shops. */
  83.         bool seen_wanted_ride;
  84.         exits = GetExitDirections(v, start_edge, &seen_wanted_ride, &queue_path);
  85.         shops = exits >> 4;
  86. @@ -1019,8 +1054,8 @@ void Guest::Activate(const Point16 &star
  87.     this->has_map = false;
  88.     this->has_umbrella = false;
  89.     this->has_balloon = false;
  90. -   this->has_wrapper = false;
  91.     this->salty_food = false;
  92. +   this->wrapper_counter = 0;
  93.     this->food = 0;
  94.     this->drink = 0;
  95.     this->hunger_level = 50;
  96. @@ -1104,7 +1139,6 @@ void Guest::ChangeHappiness(int16 amount
  97.   * Daily ponderings of a guest.
  98.   * @return If \c false, de-activate the guest.
  99.   * @todo Make going home a bit more random.
  100. - * @todo Implement dropping litter (Guest::has_wrapper) to the path, and also drop the wrapper when passing a non-empty litter bin.
  101.   * @todo Implement nausea (Guest::nausea).
  102.   * @todo Implement energy (for tiredness of guests).
  103.   */
  104. @@ -1134,10 +1168,7 @@ bool Guest::DailyUpdate()
  105.     }
  106.  
  107.     int16 happiness_change = 0;
  108. -   if (!eating) {
  109. -       if (this->has_wrapper && this->rnd.Success1024(25)) this->has_wrapper = false; // XXX Drop litter.
  110. -       if (this->hunger_level > 200) happiness_change--;
  111. -   }
  112. +   if (!eating && this->hunger_level > 200) happiness_change--;
  113.     if (this->waste > 170) happiness_change -= 2;
  114.  
  115.     switch (_weather.GetWeatherType()) {
  116. @@ -1159,7 +1190,10 @@ bool Guest::DailyUpdate()
  117.  
  118.     this->ChangeHappiness(happiness_change);
  119.  
  120. -   if (this->activity == GA_WANDER && this->happiness <= 10) this->activity = GA_GO_HOME; // Go home when bored.
  121. +   if (this->activity == GA_WANDER && this->happiness <= 10) {
  122. +       this->wrapper_counter = 0;
  123. +       this->activity = GA_GO_HOME; // Go home when bored.
  124. +   }
  125.     return true;
  126.  }
  127.  
  128. @@ -1248,23 +1282,23 @@ void Guest::AddItem(ItemType it)
  129.  
  130.         case ITP_DRINK:
  131.             this->drink = 5;
  132. -           this->has_wrapper = true;
  133. +           this->wrapper_counter = this->rnd.Exponential(MEAN_LITTER_DROPCOUNT);
  134.             break;
  135.  
  136.         case ITP_ICE_CREAM:
  137.             this->drink = 7;
  138. -           this->has_wrapper = false;
  139. +           this->wrapper_counter = 0;
  140.             break;
  141.  
  142.         case ITP_NORMAL_FOOD:
  143.             this->food = 10;
  144. -           this->has_wrapper = true;
  145. +           this->wrapper_counter = this->rnd.Exponential(MEAN_LITTER_DROPCOUNT);
  146.             this->salty_food = false;
  147.             break;
  148.  
  149.         case ITP_SALTY_FOOD:
  150.             this->food = 15;
  151. -           this->has_wrapper = true;
  152. +           this->wrapper_counter = this->rnd.Exponential(MEAN_LITTER_DROPCOUNT);
  153.             this->salty_food = true;
  154.             break;
  155.  
  156. diff --git a/src/person.h b/src/person.h
  157. --- a/src/person.h
  158. +++ b/src/person.h
  159. @@ -189,9 +189,9 @@ public:
  160.     /* Possessions of the guest. */
  161.     bool has_map;        ///< Whether guest has a park map.
  162.     bool has_umbrella;   ///< Whether guest has an umbrella.
  163. -   bool has_wrapper;    ///< Guest has a wrapper for the food or drink.
  164.     bool has_balloon;    ///< Guest has a balloon.
  165.     bool salty_food;     ///< The food in #food is salty.
  166. +   uint16 wrapper_counter; ///< When non-zero, guest is holding a wrapper that gets dropped when the counter becomes \c 0.
  167.     uint8 souvenirs;     ///< Number of souvenirs bought by the guest.
  168.     int8 food;           ///< Amount of food in the hand (one unit/day).
  169.     int8 drink;          ///< Amount of drink in the hand (one unit/day).
  170. diff --git a/src/person_gui.cpp b/src/person_gui.cpp
  171. --- a/src/person_gui.cpp
  172. +++ b/src/person_gui.cpp
  173. @@ -107,7 +107,7 @@ void GuestInfoWindow::SetWidgetStringPar
  174.             break;
  175.  
  176.         case GIW_ITEMS:
  177. -           _str_params.SetStrID(1, (this->guest->has_wrapper ? GUI_ITEM_WRAPPER : GUI_ITEM_NONE));
  178. +           _str_params.SetStrID(1, ((this->guest->wrapper_counter > 0) ? GUI_ITEM_WRAPPER : GUI_ITEM_NONE));
  179.             break;
  180.  
  181.         default: break;

Comments