From dfd27efabadc21f30199c201cc7ab077ca6e2adf Mon Sep 17 00:00:00 2001 From: zaxcav Date: Mon, 10 Oct 2016 22:21:19 +0200 Subject: [PATCH 1/7] Correct condition on running out of money thought. --- src/peep/peep.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/peep/peep.c b/src/peep/peep.c index 06513d1987..440cd91f5c 100644 --- a/src/peep/peep.c +++ b/src/peep/peep.c @@ -1089,11 +1089,17 @@ static void sub_68F41A(rct_peep *peep, int index) possible_thoughts[num_thoughts++] = PEEP_THOUGHT_TYPE_BATHROOM; } - // Not sure why the happiness check is like that seems wrong to me if (!(gParkFlags & PARK_FLAGS_NO_MONEY) && peep->cash_in_pocket <= MONEY(9, 00) && peep->happiness >= 105 && - peep->happiness >= 70){ + peep->energy >= 70){ + /* The energy check was originally a second check on happiness. + * This was superfluous so should probably check something else. + * Guessed that this should really be checking energy, since + * the addresses for happiness and energy are quite close, + * 70 is also the threshold for tired thoughts (see above) and + * it makes sense that a tired peep might not think about getting + * more money. */ possible_thoughts[num_thoughts++] = PEEP_THOUGHT_TYPE_RUNNING_OUT; } } From 6011429630d5687c2dfb5329c6d77dd98d67640c Mon Sep 17 00:00:00 2001 From: zaxcav Date: Mon, 10 Oct 2016 22:24:33 +0200 Subject: [PATCH 2/7] Fix potential under/over-flow of happiness, hunger, thirst in peep generation. --- src/peep/peep.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/src/peep/peep.c b/src/peep/peep.c index 440cd91f5c..e318b12eb2 100644 --- a/src/peep/peep.c +++ b/src/peep/peep.c @@ -6987,23 +6987,39 @@ rct_peep *peep_generate(int x, int y, int z) peep->nausea_tolerance = nausea_tolerance_distribution[nausea_tolerance]; - sint8 happiness = (scenario_rand() & 0x1F) - 15 + gGuestInitialHappiness; - + /* Scenario editor limits initial guest happiness to between 37..253. + * To be on the safe side, assume the value could have been hacked + * to any value 0..255. */ + peep->happiness = gGuestInitialHappiness; + /* Assume a default initial happiness of 0 is wrong and set + * to 128 (50%) instead. */ if (gGuestInitialHappiness == 0) - happiness += 0x80; - - peep->happiness = happiness; - peep->happiness_growth_rate = happiness; + peep->happiness = 0x80; + /* Initial value will vary by -15..16 */ + sint8 happiness_delta = (scenario_rand() & 0x1F) - 15; + /* Adjust by the delta, clamping at min=0 and max=255. */ + peep->happiness = clamp(0, peep->happiness + happiness_delta, 255); + peep->happiness_growth_rate = peep->happiness; peep->nausea = 0; peep->nausea_growth_rate = 0; - sint8 hunger = (scenario_rand() & 0x1F) - 15 + gGuestInitialHunger; + /* Scenario editor limits initial guest hunger to between 37..253. + * To be on the safe side, assume the value could have been hacked + * to any value 0..255. */ + peep->hunger = gGuestInitialHunger; + /* Initial value will vary by -15..16 */ + sint8 hunger_delta = (scenario_rand() & 0x1F) - 15; + /* Adjust by the delta, clamping at min=0 and max=255. */ + peep->hunger = clamp(0, peep->hunger + hunger_delta, 255); - peep->hunger = hunger; - - sint8 thirst = (scenario_rand() & 0x1F) - 15 + gGuestInitialThirst; - - peep->thirst = thirst; + /* Scenario editor limits initial guest thirst to between 37..253. + * To be on the safe side, assume the value could have been hacked + * to any value 0..255. */ + peep->thirst = gGuestInitialThirst; + /* Initial value will vary by -15..16 */ + sint8 thirst_delta = (scenario_rand() & 0x1F) - 15; + /* Adjust by the delta, clamping at min=0 and max=255. */ + peep->thirst = clamp(0, peep->thirst + thirst_delta, 0xFF); peep->bathroom = 0; peep->var_42 = 0; From 68f89c6b073efb82f813782f7721e3614cef6335 Mon Sep 17 00:00:00 2001 From: zaxcav Date: Mon, 10 Oct 2016 22:28:50 +0200 Subject: [PATCH 3/7] Comment peep update code related to updating happiness, etc. --- src/peep/peep.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/peep/peep.c b/src/peep/peep.c index e318b12eb2..f465d43dee 100644 --- a/src/peep/peep.c +++ b/src/peep/peep.c @@ -746,6 +746,8 @@ static void peep_leave_park(rct_peep* peep){ } /** + * Main purpose is to decide when peeps leave the park due to + * low happiness, low energy and (if appropriate) low money. * * rct2: 0x0068F8CD */ @@ -763,6 +765,9 @@ static void sub_68F8CD(rct_peep *peep) return; } + /* Peeps that are happy enough, have enough energy and + * (if appropriate) have enough money will always stay + * in the park. */ if (!(peep->peep_flags & PEEP_FLAGS_LEAVING_PARK)){ if (gParkFlags & PARK_FLAGS_NO_MONEY) { if (peep->energy >= 70 && peep->happiness >= 60) { @@ -779,10 +784,12 @@ static void sub_68F8CD(rct_peep *peep) } } + // Approx 95% chance of staying in the park if ((scenario_rand() & 0xFFFF) > 3276) { return; } + // In the remaining 5% chance the peep leaves the park. peep_leave_park(peep); } @@ -956,6 +963,10 @@ static void sub_68F41A(rct_peep *peep, int index) } if ((index & 0x1FF) == (gCurrentTicks & 0x1FF)){ + /* Affect of masking with 0x1FF here vs mask 0x7F, + * which is the condition for calling this function, is + * to reduce how often the content in this conditional + * is executed to once every four calls. */ if (peep->peep_flags & PEEP_FLAGS_CROWDED){ uint8 thought_type = crowded_thoughts[scenario_rand() & 0xF]; if (thought_type != PEEP_THOUGHT_TYPE_NONE){ @@ -1059,6 +1070,11 @@ static void sub_68F41A(rct_peep *peep, int index) } if ((index & 0x3FF) == (gCurrentTicks & 0x3FF)){ + /* Affect of masking with 0x3FF here vs mask 0x1FF, + * which is used in the encompassing conditional, is + * to reduce how often the content in this conditional + * is executed to once every second time the encompassing + * conditional executes. */ if (peep->outside_of_park == 0 && (peep->state == PEEP_STATE_WALKING || peep->state == PEEP_STATE_SITTING)){ @@ -1127,6 +1143,10 @@ static void sub_68F41A(rct_peep *peep, int index) } } else{ + /* This branch of the conditional is executed on the + * remaining times the encompassing conditional is + * executed (which is also every second time, but + * the alternate time to the true branch). */ if (peep->nausea >= 140){ uint8 thought_type = PEEP_THOUGHT_TYPE_SICK; if (peep->nausea >= 200){ @@ -1166,6 +1186,8 @@ static void sub_68F41A(rct_peep *peep, int index) case PEEP_STATE_QUEUING: if (peep->time_in_queue >= 2000){ + /* Peep happiness is affected once the peep has been waiting + * too long in a queue. */ rct_map_element* mapElement = map_get_first_element_at(peep->next_x / 32, peep->next_y / 32); uint8 found = 0; do { @@ -1186,6 +1208,10 @@ static void sub_68F41A(rct_peep *peep, int index) } while (!map_element_is_last_for_tile(mapElement++)); if (found){ + /* Queue line TV monitors make the peeps waiting in the queue + * slowly happier, up to a certain level. */ + /* Why don't queue line TV monitors start affecting the peeps + * as soon as they join the queue?? */ if (peep->happiness_growth_rate < 90) peep->happiness_growth_rate = 90; @@ -1193,6 +1219,8 @@ static void sub_68F41A(rct_peep *peep, int index) peep->happiness_growth_rate += 2; } else{ + /* Without a queue line TV monitor peeps waiting too long + * in a queue get less happy. */ peep->happiness_growth_rate = max(peep->happiness_growth_rate - 4, 0); } } @@ -1208,6 +1236,7 @@ static void sub_68F41A(rct_peep *peep, int index) } loc_68F9F3: + // Idle peep happiness tends towards 127 (50%). if (peep->happiness_growth_rate >= 128) peep->happiness_growth_rate--; else @@ -1245,6 +1274,9 @@ static void sub_68F41A(rct_peep *peep, int index) } } } + + // Remaining content is executed every call. + // 68FA89 if (peep->var_42 == 0 && peep_has_food(peep)){ @@ -1313,6 +1345,7 @@ static void sub_68F41A(rct_peep *peep, int index) if (energy < 32) energy = 32; + /* This suggests 100% energy is 128. */ if (energy > 128) energy = 128; @@ -5631,7 +5664,7 @@ static void peep_update_using_bin(rct_peep* peep){ } // Original bug: This would clear any rubbish placed by the previous function - //rubbish_in_bin = 0x3 & (map_element->properties.path.addition_status >> selected_bin); + //space_left_in_bin = 0x3 & (map_element->properties.path.addition_status >> selected_bin); empty_containers = peep_empty_container_extra_flag(peep); for (uint8 cur_container = 0; cur_container < 32; cur_container++){ @@ -7076,6 +7109,8 @@ rct_peep *peep_generate(int x, int y, int z) uint8 trousers_colour = scenario_rand() % countof(trouser_colours); peep->trousers_colour = trouser_colours[trousers_colour]; + /* It looks like 65 is about 50% energy level, so this initialises + * a peep with approx 50%-100% energy. */ uint8 energy = (scenario_rand() & 0x3F) + 65; peep->energy = energy; peep->energy_growth_rate = energy; From b92cddf536452d4d52c2306604022794ec88aa19 Mon Sep 17 00:00:00 2001 From: zaxcav Date: Tue, 11 Oct 2016 07:38:41 +0200 Subject: [PATCH 4/7] Bump network version. --- src/network/network.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/network/network.h b/src/network/network.h index da25dfe391..9a641049f0 100644 --- a/src/network/network.h +++ b/src/network/network.h @@ -55,7 +55,7 @@ extern "C" { // This define specifies which version of network stream current build uses. // It is used for making sure only compatible builds get connected, even within // single OpenRCT2 version. -#define NETWORK_STREAM_VERSION "14" +#define NETWORK_STREAM_VERSION "15" #define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION #ifdef __cplusplus From d36c756ee74a07120100b4d84cdabe3ef3d98119 Mon Sep 17 00:00:00 2001 From: zaxcav Date: Wed, 12 Oct 2016 13:23:47 +0200 Subject: [PATCH 5/7] Spelling corrections in code comments. --- src/peep/peep.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/peep/peep.c b/src/peep/peep.c index f465d43dee..7b44536f80 100644 --- a/src/peep/peep.c +++ b/src/peep/peep.c @@ -963,7 +963,7 @@ static void sub_68F41A(rct_peep *peep, int index) } if ((index & 0x1FF) == (gCurrentTicks & 0x1FF)){ - /* Affect of masking with 0x1FF here vs mask 0x7F, + /* Effect of masking with 0x1FF here vs mask 0x7F, * which is the condition for calling this function, is * to reduce how often the content in this conditional * is executed to once every four calls. */ @@ -1070,7 +1070,7 @@ static void sub_68F41A(rct_peep *peep, int index) } if ((index & 0x3FF) == (gCurrentTicks & 0x3FF)){ - /* Affect of masking with 0x3FF here vs mask 0x1FF, + /* Effect of masking with 0x3FF here vs mask 0x1FF, * which is used in the encompassing conditional, is * to reduce how often the content in this conditional * is executed to once every second time the encompassing From 989a8fc4bc6ff4452b964ae5fde4d5f146b95cdc Mon Sep 17 00:00:00 2001 From: zaxcav Date: Wed, 12 Oct 2016 13:35:07 +0200 Subject: [PATCH 6/7] Update comment with new limits of ride satisfaction following commit 7f58c89. --- src/peep/peep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/peep/peep.c b/src/peep/peep.c index 7b44536f80..b1f0397a9a 100644 --- a/src/peep/peep.c +++ b/src/peep/peep.c @@ -10120,7 +10120,7 @@ static void peep_on_enter_ride(rct_peep *peep, int rideIndex) { rct_ride *ride = get_ride(rideIndex); - // Calculate how satisfying the ride is for the peep. Can range from -140 to +140. + // Calculate how satisfying the ride is for the peep. Can range from -140 to +105. sint16 satisfaction = peep_calculate_ride_satisfaction(peep, ride); // Update the satisfaction stat of the ride. From b85e53e8988698dc1b4555b8e1b2b520d4641849 Mon Sep 17 00:00:00 2001 From: zaxcav Date: Thu, 20 Oct 2016 10:39:48 +0200 Subject: [PATCH 7/7] Replace hex number with decimal number per PR review comments. --- src/peep/peep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/peep/peep.c b/src/peep/peep.c index b1f0397a9a..b8cae51d06 100644 --- a/src/peep/peep.c +++ b/src/peep/peep.c @@ -7027,7 +7027,7 @@ rct_peep *peep_generate(int x, int y, int z) /* Assume a default initial happiness of 0 is wrong and set * to 128 (50%) instead. */ if (gGuestInitialHappiness == 0) - peep->happiness = 0x80; + peep->happiness = 128; /* Initial value will vary by -15..16 */ sint8 happiness_delta = (scenario_rand() & 0x1F) - 15; /* Adjust by the delta, clamping at min=0 and max=255. */