fix #3683: Clock Scenery Not Showing Correct Time

This commit is contained in:
Ted John 2016-05-20 20:06:04 +01:00
parent 4944fe1836
commit 73e5d9d431
4 changed files with 34 additions and 9 deletions

View File

@ -14,6 +14,7 @@
*****************************************************************************/
#pragma endregion
#include <time.h>
#include "../addresses.h"
#include "../game.h"
#include "date.h"
@ -36,6 +37,8 @@ const rct_string_id DateFormatStringFormatIds[] = {
STR_DATE_FORMAT_YDM
};
openrct_timeofday gRealTimeOfDay;
int date_get_month(int months)
{
return months % MONTH_COUNT;
@ -61,3 +64,13 @@ void date_reset()
gDateMonthTicks = 0;
gCurrentTicks = 0;
}
void date_update_real_time_of_day()
{
time_t timestamp = time(0);
struct tm *now = localtime(&timestamp);
gRealTimeOfDay.second = now->tm_sec;
gRealTimeOfDay.minute = now->tm_min;
gRealTimeOfDay.hour = now->tm_hour;
}

View File

@ -39,6 +39,12 @@ enum {
DATE_FORMAT_YEAR_DAY_MONTH
};
typedef struct openrct_timeofday {
uint8 second;
uint8 minute;
uint8 hour;
} openrct_timeofday;
extern const sint16 days_in_month[MONTH_COUNT];
extern const rct_string_id DateFormatStringIds[];
extern const rct_string_id DateFormatStringFormatIds[];
@ -46,9 +52,12 @@ extern const rct_string_id DateFormatStringFormatIds[];
#define gDateMonthTicks RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONTH_TICKS, uint16)
#define gDateMonthsElapsed RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONTH_YEAR, uint16)
extern openrct_timeofday gRealTimeOfDay;
int date_get_month(int months);
int date_get_year(int months);
int date_get_total_months(int month, int year);
void date_reset();
void date_update_real_time_of_day();
#endif

View File

@ -19,6 +19,7 @@
#include "../../config.h"
#include "../../game.h"
#include "../../interface/viewport.h"
#include "../../localisation/date.h"
#include "../../paint/paint.h"
#include "../../paint/supports.h"
#include "../../world/map.h"
@ -155,16 +156,16 @@ void scenery_paint(uint8 direction, int height, rct_map_element* mapElement) {
} else
if (entry->small_scenery.flags & SMALL_SCENERY_FLAG_IS_CLOCK) {
// 6E035C:
int si = ((RCT2_GLOBAL(RCT2_ADDRESS_OS_TIME_MINUTE, uint16) + 6) * 17) / 256;
int bx = RCT2_GLOBAL(RCT2_ADDRESS_OS_TIME_HOUR, uint16);
while (bx >= 12) {
bx -= 12;
int minuteImageOffset = ((gRealTimeOfDay.minute + 6) * 17) / 256;
int timeImageBase = gRealTimeOfDay.hour;
while (timeImageBase >= 12) {
timeImageBase -= 12;
}
bx = (bx * 4) + si;
if (bx >= 48) {
bx -= 48;
timeImageBase = (timeImageBase * 4) + minuteImageOffset;
if (timeImageBase >= 48) {
timeImageBase -= 48;
}
int image_id = bx + (direction * 12);
int image_id = timeImageBase + (direction * 12);
if (image_id >= 48) {
image_id -= 48;
}
@ -175,7 +176,7 @@ void scenery_paint(uint8 direction, int height, rct_map_element* mapElement) {
}
sub_98199C(image_id, x_offset, y_offset, boxlength.x, boxlength.y, boxlength.z - 1, height, boxoffset.x, boxoffset.y, boxoffset.z, get_current_rotation());
image_id = RCT2_GLOBAL(RCT2_ADDRESS_OS_TIME_MINUTE, uint16) + (direction * 15);
image_id = gRealTimeOfDay.minute + (direction * 15);
if (image_id >= 60) {
image_id -= 60;
}

View File

@ -448,6 +448,8 @@ void rct2_update()
gPaletteEffectFrame += tick2;
}
date_update_real_time_of_day();
// TODO: screenshot countdown process
network_update();