From 6a1c5fa6ebff5e49755f18a31fdecb6c541eb418 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Fri, 30 May 2014 23:27:11 +0100 Subject: [PATCH 1/2] add initial start to peep update --- src/award.c | 16 ++++---- src/peep.c | 85 +++++++++++++++++++++++++++++++++++++++-- src/peep.h | 10 +++-- src/window_guest_list.c | 6 +-- 4 files changed, 99 insertions(+), 18 deletions(-) diff --git a/src/award.c b/src/award.c index 25c843ddd9..3f76984ebf 100644 --- a/src/award.c +++ b/src/award.c @@ -76,7 +76,7 @@ static int award_is_deserved_most_untidy(int awardType, int activeAwardTypes) if (peep->var_2A != 0) continue; - if (peep->thoughts[0].pad_3 > 5) + if (peep->thoughts[0].var_2 > 5) continue; if (peep->thoughts[0].type == PEEP_THOUGHT_TYPE_BAD_LITTER || @@ -109,7 +109,7 @@ static int award_is_deserved_most_tidy(int awardType, int activeAwardTypes) if (peep->var_2A != 0) continue; - if (peep->thoughts[0].pad_3 > 5) + if (peep->thoughts[0].var_2 > 5) continue; if (peep->thoughts[0].type == PEEP_THOUGHT_VERY_CLEAN) @@ -183,7 +183,7 @@ static int award_is_deserved_most_beautiful(int awardType, int activeAwardTypes) if (peep->var_2A != 0) continue; - if (peep->thoughts[0].pad_3 > 5) + if (peep->thoughts[0].var_2 > 5) continue; if (peep->thoughts[0].type == PEEP_THOUGHT_TYPE_SCENERY) @@ -226,7 +226,7 @@ static int award_is_deserved_safest(int awardType, int activeAwardTypes) FOR_ALL_GUESTS(spriteIndex, peep) { if (peep->var_2A != 0) continue; - if (peep->thoughts[0].pad_3 <= 5 && peep->thoughts[0].type == PEEP_THOUGHT_TYPE_VANDALISM) + if (peep->thoughts[0].var_2 <= 5 && peep->thoughts[0].type == PEEP_THOUGHT_TYPE_VANDALISM) peepsWhoDislikeVandalism++; } @@ -307,7 +307,7 @@ static int award_is_deserved_best_food(int awardType, int activeAwardTypes) if (peep->var_2A != 0) continue; - if (peep->thoughts[0].pad_3 <= 5 && peep->thoughts[0].type == PEEP_THOUGHT_TYPE_HUNGRY) + if (peep->thoughts[0].var_2 <= 5 && peep->thoughts[0].type == PEEP_THOUGHT_TYPE_HUNGRY) hungryPeeps++; } @@ -353,7 +353,7 @@ static int award_is_deserved_worst_food(int awardType, int activeAwardTypes) if (peep->var_2A != 0) continue; - if (peep->thoughts[0].pad_3 <= 5 && peep->thoughts[0].type == PEEP_THOUGHT_TYPE_HUNGRY) + if (peep->thoughts[0].var_2 <= 5 && peep->thoughts[0].type == PEEP_THOUGHT_TYPE_HUNGRY) hungryPeeps++; } @@ -388,7 +388,7 @@ static int award_is_deserved_best_restrooms(int awardType, int activeAwardTypes) if (peep->var_2A != 0) continue; - if (peep->thoughts[0].pad_3 <= 5 && peep->thoughts[0].type == PEEP_THOUGHT_TYPE_BATHROOM) + if (peep->thoughts[0].var_2 <= 5 && peep->thoughts[0].type == PEEP_THOUGHT_TYPE_BATHROOM) guestsWhoNeedRestroom++; } @@ -510,7 +510,7 @@ static int award_is_deserved_most_confusing_layout(int awardType, int activeAwar continue; peepsCounted++; - if (peep->thoughts[0].pad_3 <= 5 && peep->thoughts[0].type == PEEP_THOUGHT_TYPE_LOST || peep->thoughts[0].type == PEEP_THOUGHT_TYPE_CANT_FIND) + if (peep->thoughts[0].var_2 <= 5 && peep->thoughts[0].type == PEEP_THOUGHT_TYPE_LOST || peep->thoughts[0].type == PEEP_THOUGHT_TYPE_CANT_FIND) peepsLost++; } diff --git a/src/peep.c b/src/peep.c index cde8015f4e..7042c04c5d 100644 --- a/src/peep.c +++ b/src/peep.c @@ -28,6 +28,8 @@ #include "sprite.h" #include "window.h" +static void peep_update(rct_peep *peep); + int peep_get_staff_count() { uint16 spriteIndex; @@ -60,17 +62,94 @@ void peep_update_all() spriteIndex = peep->next; if ((i & 0x7F) != (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TICKS, uint32) & 0x7F)) { - RCT2_CALLPROC_X(0x0068FC1E, 0, 0, 0, 0, (int)peep, 0, 0); + peep_update(peep); } else { RCT2_CALLPROC_X(0x0068F41A, 0, 0, 0, i, (int)peep, 0, 0); if (peep->var_08 == 4) - RCT2_CALLPROC_X(0x0068FC1E, 0, 0, 0, 0, (int)peep, 0, 0); + peep_update(peep); } i++; } } +/** + * + * rct2: 0x0068FC1E + */ +static void peep_update(rct_peep *peep) +{ + // RCT2_CALLPROC_X(0x0068FC1E, 0, 0, 0, 0, (int)peep, 0, 0); return; + + int i, j; + + if (peep->type == PEEP_TYPE_GUEST) { + if (peep->var_AD != 255) + if (++peep->var_AE < 720) + peep->var_AD = 255; + + // Update thoughts + i = 0; + int ebp = 0; + int edi = -1; + for (i = 0; i < PEEP_MAX_THOUGHTS; i++) { + if (peep->thoughts[i].type == PEEP_THOUGHT_TYPE_NONE) + break; + + if (peep->thoughts[i].var_2 == 1) { + ebp++; + if (++peep->thoughts[i].var_3 >= 220) { + peep->thoughts[i].var_3 = 0; + peep->thoughts[i].var_2++; + ebp--; + } + } else if (peep->thoughts[i].var_2 >= 0) { + if (++peep->thoughts[i].var_3 > 255) { + if (++peep->thoughts[i].var_3 >= 28) { + peep->var_45 |= 1; + + // Clear top thought, push others up + for (j = i; j < PEEP_MAX_THOUGHTS - 1; j++) + peep->thoughts[j].type = peep->thoughts[j + 1].type; + peep->thoughts[PEEP_MAX_THOUGHTS - 1].type = PEEP_THOUGHT_TYPE_NONE; + } + } + } else { + edi = i; + } + } + if (ebp == 0 && edi != -1) { + peep->thoughts[edi].var_2 = 1; + peep->var_45 |= 1; + } + } + + // Walking speed logic + unsigned int stepsToTake = peep->energy; + if (stepsToTake < 95 && peep->state == PEEP_STATE_QUEUING) + stepsToTake = 95; + if ((peep->flags & PEEP_FLAGS_SLOW_WALK) && peep->state != PEEP_STATE_QUEUING) + stepsToTake /= 2; + if (peep->var_71 == 255 && (RCT2_GLOBAL((int)peep + 0x29, uint8) & 4)) { + stepsToTake /= 2; + if (peep->state == PEEP_STATE_QUEUING) + stepsToTake += stepsToTake / 2; + } + + unsigned int carryCheck = peep->var_73 + stepsToTake; + peep->var_73 = carryCheck; + if (carryCheck <= 255) { + // loc_68FD3A + RCT2_CALLPROC_X(0x0068FD3A, 0, 0, 0, 0, (int)peep, 0, 0); + } else { + // loc_68FD2F + RCT2_CALLPROC_X(0x0068FD2F, 0, 0, 0, 0, (int)peep, 0, 0); + switch (peep->state) { + + } + } +} + /** * @@ -89,7 +168,7 @@ void peep_problem_warnings_update() RCT2_GLOBAL(RCT2_ADDRESS_RIDE_COUNT, sint16) = ride_get_count(); // refactor this to somewhere else FOR_ALL_GUESTS(spriteIndex, peep) { - if (peep->var_2A != 0 || peep->thoughts[0].pad_3 > 5) + if (peep->var_2A != 0 || peep->thoughts[0].var_2 > 5) continue; switch (peep->thoughts[0].type) { diff --git a/src/peep.h b/src/peep.h index 2bac8ed735..74dfd3f6b8 100644 --- a/src/peep.h +++ b/src/peep.h @@ -307,8 +307,8 @@ enum PEEP_ITEM { typedef struct { uint8 type; uint8 item; - uint8 pad_3; - uint8 pad_4; + uint8 var_2; + uint8 var_3; } rct_peep_thought; typedef struct { @@ -376,7 +376,8 @@ typedef struct { uint8 var_70; uint8 var_71; uint8 var_72; - uint8 pad_73[3]; + uint8 var_73; + uint16 pad_74; uint8 var_76; uint8 pad_77; uint8 var_78; @@ -387,7 +388,8 @@ typedef struct { money32 cash_spent; // 0xA4 uint8 pad_A8; sint32 time_in_park; // 0xA9 - uint8 pad_AD[0x3]; + uint8 var_AD; + uint16 var_AE; rct_peep_thought thoughts[PEEP_MAX_THOUGHTS]; // 0xB0 uint8 pad_C4; uint8 var_C5; diff --git a/src/window_guest_list.c b/src/window_guest_list.c index d26c91993a..14fe8d13a7 100644 --- a/src/window_guest_list.c +++ b/src/window_guest_list.c @@ -731,9 +731,9 @@ static void window_guest_list_scrollpaint() thought = &peep->thoughts[j]; if (thought->type == PEEP_THOUGHT_TYPE_NONE) break; - if (thought->pad_3 == 0) + if (thought->var_2 == 0) continue; - if (thought->pad_3 > 5) + if (thought->var_2 > 5) break; ebx = thought->type; @@ -837,7 +837,7 @@ static int sub_69B7EA(rct_peep *peep, int *outEAX) *outEAX = eax; return ebx & 0xFFFF; case VIEW_THOUGHTS: - if (peep->thoughts[0].pad_3 <= 5) { + if (peep->thoughts[0].var_2 <= 5) { eax = peep->thoughts[0].item; ebx = peep->thoughts[0].type; if (peep->thoughts[0].type != PEEP_THOUGHT_TYPE_NONE) { From b1e9c5c786b4d2050a9dd9f0e10fc6d65d15a211 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sat, 31 May 2014 14:43:29 +0100 Subject: [PATCH 2/2] fix format string bugs --- src/string_ids.c | 79 ++++++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 33 deletions(-) diff --git a/src/string_ids.c b/src/string_ids.c index 28c70e4a1a..11a5703f12 100644 --- a/src/string_ids.c +++ b/src/string_ids.c @@ -1085,12 +1085,16 @@ void format_integer(char **dest, int value) *dest = dst; - // Right to left - while (value > 0) { - digit = value % 10; - value /= 10; + if (value == 0) { + *dst++ = '0'; + } else { + // Right to left + while (value > 0) { + digit = value % 10; + value /= 10; - *dst++ = '0' + digit; + *dst++ = '0' + digit; + } } finish = dst; @@ -1121,20 +1125,24 @@ void format_comma_separated_integer(char **dest, int value) *dest = dst; - // Groups of three digits, right to left - groupIndex = 0; - while (value > 0) { - // Append group seperator - if (groupIndex == 3) { - groupIndex = 0; - *dst++ = ','; + if (value == 0) { + *dst++ = '0'; + } else { + // Groups of three digits, right to left + groupIndex = 0; + while (value > 0) { + // Append group seperator + if (groupIndex == 3) { + groupIndex = 0; + *dst++ = ','; + } + + digit = value % 10; + value /= 10; + + *dst++ = '0' + digit; + groupIndex++; } - - digit = value % 10; - value /= 10; - - *dst++ = '0' + digit; - groupIndex++; } finish = dst; @@ -1225,20 +1233,24 @@ void format_currency(char **dest, int value) *dest = dst; - // Groups of three digits, right to left - groupIndex = 0; - while (value > 0) { - // Append group seperator - if (groupIndex == 3) { - groupIndex = 0; - *dst++ = ','; + if (value == 0) { + *dst++ = '0'; + } else { + // Groups of three digits, right to left + groupIndex = 0; + while (value > 0) { + // Append group seperator + if (groupIndex == 3) { + groupIndex = 0; + *dst++ = ','; + } + + digit = value % 10; + value /= 10; + + *dst++ = '0' + digit; + groupIndex++; } - - digit = value % 10; - value /= 10; - - *dst++ = '0' + digit; - groupIndex++; } finish = dst; @@ -1389,11 +1401,12 @@ void format_string_code(unsigned char format_code, char **dest, char **args) value = *((uint16*)*args); *args += 2; - uint16 dateArgs[] = { date_get_year(value), date_get_month(value) }; + uint16 dateArgs[] = { date_get_month(value), date_get_year(value) + 1 }; + uint16 *dateArgs2 = dateArgs; char formatString[] = "?, Year ?"; formatString[0] = FORMAT_MONTH; formatString[8] = FORMAT_COMMA16; - format_string_part_from_raw(dest, formatString, (char**)&dateArgs); + format_string_part_from_raw(dest, formatString, (char**)&dateArgs2); break; case FORMAT_MONTH: // Pop argument