mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-21 22:13:07 +01:00
fix new ride design count and track design listing
This commit is contained in:
@@ -199,7 +199,7 @@ rct_ride *get_ride(int index)
|
||||
|
||||
rct_ride_entry *get_ride_entry(int index)
|
||||
{
|
||||
if (index < 0 || index >= object_entry_group_counts[0])
|
||||
if (index < 0 || index >= object_entry_group_counts[OBJECT_TYPE_RIDE])
|
||||
{
|
||||
log_error("invalid index %d for ride type", index);
|
||||
return NULL;
|
||||
@@ -207,6 +207,19 @@ rct_ride_entry *get_ride_entry(int index)
|
||||
return gRideTypeList[index];
|
||||
}
|
||||
|
||||
void get_ride_entry_name(char *name, int index)
|
||||
{
|
||||
if (index < 0 || index >= object_entry_group_counts[OBJECT_TYPE_RIDE])
|
||||
{
|
||||
log_error("invalid index %d for ride type", index);
|
||||
return;
|
||||
}
|
||||
|
||||
const char *entryName = object_entry_groups[OBJECT_TYPE_RIDE].entries[index].name;
|
||||
memcpy(name, entryName, 8);
|
||||
name[8] = '\0';
|
||||
}
|
||||
|
||||
rct_ride_measurement *get_ride_measurement(int index)
|
||||
{
|
||||
return &(RCT2_ADDRESS(RCT2_ADDRESS_RIDE_MEASUREMENTS, rct_ride_measurement)[index]);
|
||||
|
||||
@@ -874,6 +874,7 @@ enum {
|
||||
/** Helper macros until rides are stored in this module. */
|
||||
rct_ride *get_ride(int index);
|
||||
rct_ride_entry *get_ride_entry(int index);
|
||||
void get_ride_entry_name(char *name, int index);
|
||||
rct_ride_measurement *get_ride_measurement(int index);
|
||||
|
||||
/**
|
||||
|
||||
@@ -124,6 +124,7 @@ int sub_6D01B3(rct_track_td6 *td6, uint8 bl, uint8 rideIndex, int x, int y, int
|
||||
int install_track(char* source_path, char* dest_name);
|
||||
|
||||
void track_design_index_create();
|
||||
size_t track_design_index_get_count_for_ride(uint8 rideType, const char *entry);
|
||||
size_t track_design_index_get_for_ride(track_design_file_ref **tdRefs, uint8 rideType, const char *entry);
|
||||
utf8 *track_design_get_name_from_path(const utf8 *path);
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ typedef struct {
|
||||
utf8 path[MAX_PATH];
|
||||
} td_index_item;
|
||||
|
||||
static bool track_design_index_read_header(SDL_RWops *file, uint32 *tdidxCount);
|
||||
static void track_design_index_scan();
|
||||
static int track_design_index_item_compare(const void *a, const void *b);
|
||||
static void track_design_index_include(const utf8 *directory);
|
||||
@@ -47,6 +48,36 @@ void track_design_index_create()
|
||||
}
|
||||
}
|
||||
|
||||
size_t track_design_index_get_count_for_ride(uint8 rideType, const char *entry)
|
||||
{
|
||||
log_verbose("reading track design index (tracks.idx)");
|
||||
|
||||
utf8 path[MAX_PATH];
|
||||
track_design_index_get_path(path, sizeof(path));
|
||||
|
||||
// Return list
|
||||
size_t refsCount = 0;
|
||||
SDL_RWops *file = SDL_RWFromFile(path, "rb");
|
||||
if (file != NULL) {
|
||||
uint32 tdidxCount;
|
||||
if (!track_design_index_read_header(file, &tdidxCount)) {
|
||||
SDL_RWclose(file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (uint32 i = 0; i < tdidxCount; i++) {
|
||||
td_index_item tdItem;
|
||||
SDL_RWread(file, &tdItem, sizeof(td_index_item), 1);
|
||||
|
||||
if (tdItem.ride_type != rideType) continue;
|
||||
if (entry != NULL && _strcmpi(entry, tdItem.ride_entry) != 0) continue;
|
||||
refsCount++;
|
||||
}
|
||||
}
|
||||
|
||||
return refsCount;
|
||||
}
|
||||
|
||||
size_t track_design_index_get_for_ride(track_design_file_ref **tdRefs, uint8 rideType, const char *entry)
|
||||
{
|
||||
log_verbose("reading track design index (tracks.idx)");
|
||||
@@ -61,17 +92,8 @@ size_t track_design_index_get_for_ride(track_design_file_ref **tdRefs, uint8 rid
|
||||
|
||||
SDL_RWops *file = SDL_RWFromFile(path, "rb");
|
||||
if (file != NULL) {
|
||||
uint32 tdidxMagicNumber, tdidxVersion, tdidxCount;
|
||||
SDL_RWread(file, &tdidxMagicNumber, 4, 1);
|
||||
SDL_RWread(file, &tdidxVersion, 4, 1);
|
||||
SDL_RWread(file, &tdidxCount, 4, 1);
|
||||
if (tdidxMagicNumber != TrackIndexMagicNumber) {
|
||||
log_error("invalid track index file");
|
||||
SDL_RWclose(file);
|
||||
return 0;
|
||||
}
|
||||
if (tdidxVersion != TrackIndexVersion) {
|
||||
log_error("unsupported track index file version");
|
||||
uint32 tdidxCount;
|
||||
if (!track_design_index_read_header(file, &tdidxCount)) {
|
||||
SDL_RWclose(file);
|
||||
return 0;
|
||||
}
|
||||
@@ -115,6 +137,23 @@ utf8 *track_design_get_name_from_path(const utf8 *path)
|
||||
return strndup(filename, nameLength);
|
||||
}
|
||||
|
||||
static bool track_design_index_read_header(SDL_RWops *file, uint32 *tdidxCount)
|
||||
{
|
||||
uint32 tdidxMagicNumber, tdidxVersion;
|
||||
SDL_RWread(file, &tdidxMagicNumber, 4, 1);
|
||||
SDL_RWread(file, &tdidxVersion, 4, 1);
|
||||
SDL_RWread(file, tdidxCount, 4, 1);
|
||||
if (tdidxMagicNumber != TrackIndexMagicNumber) {
|
||||
log_error("invalid track index file");
|
||||
return false;
|
||||
}
|
||||
if (tdidxVersion != TrackIndexVersion) {
|
||||
log_error("unsupported track index file version");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void track_design_index_scan()
|
||||
{
|
||||
utf8 directory[MAX_PATH];
|
||||
|
||||
@@ -150,7 +150,7 @@ void window_install_track_open(const char* path)
|
||||
static void window_install_track_select(rct_window *w, int index)
|
||||
{
|
||||
utf8 *trackDesignItem, *trackDesignList = RCT2_ADDRESS(RCT2_ADDRESS_TRACK_LIST, utf8);
|
||||
rct_track_design *trackDesign;
|
||||
// rct_track_design *trackDesign;
|
||||
|
||||
w->track_list.var_480 = index;
|
||||
|
||||
|
||||
@@ -842,15 +842,17 @@ static ride_list_item window_new_ride_scroll_get_ride_list_item_at(rct_window *w
|
||||
|
||||
static int get_num_track_designs(ride_list_item item)
|
||||
{
|
||||
// track_load_list(item);
|
||||
|
||||
char *trackDesignList = RCT2_ADDRESS(RCT2_ADDRESS_TRACK_LIST, char);
|
||||
int count = 0;
|
||||
while (*trackDesignList != 0 && trackDesignList < (char*)0x00F635EC) {
|
||||
trackDesignList += 128;
|
||||
count++;
|
||||
char entry[9];
|
||||
const char *entryPtr = NULL;
|
||||
if (item.type < 0x80) {
|
||||
rct_ride_entry *rideEntry = get_ride_entry(item.entry_index);
|
||||
if ((rideEntry->flags & RIDE_ENTRY_FLAG_SEPARATE_RIDE) && !rideTypeShouldLoseSeparateFlag(rideEntry)) {
|
||||
get_ride_entry_name(entry, item.entry_index);
|
||||
entryPtr = entry;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
|
||||
return track_design_index_get_count_for_ride(item.type, entryPtr);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -943,10 +945,7 @@ static void window_new_ride_select(rct_window *w)
|
||||
#endif
|
||||
|
||||
if (allowTrackDesigns && ride_type_has_flag(item.type, RIDE_TYPE_FLAG_HAS_TRACK)) {
|
||||
// track_load_list(item);
|
||||
|
||||
char *trackDesignList = RCT2_ADDRESS(RCT2_ADDRESS_TRACK_LIST, char);
|
||||
if (*trackDesignList != 0) {
|
||||
if (_lastTrackDesignCount > 0) {
|
||||
window_track_list_open(item);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -113,7 +113,16 @@ void window_track_list_open(ride_list_item item)
|
||||
window_close_construction_windows();
|
||||
_window_track_list_item = item;
|
||||
|
||||
_trackDesignsCount = track_design_index_get_for_ride(&_trackDesigns, item.type, NULL);
|
||||
char entry[9];
|
||||
const char *entryPtr = NULL;
|
||||
if (item.type < 0x80) {
|
||||
rct_ride_entry *rideEntry = get_ride_entry(item.entry_index);
|
||||
if ((rideEntry->flags & RIDE_ENTRY_FLAG_SEPARATE_RIDE) && !rideTypeShouldLoseSeparateFlag(rideEntry)) {
|
||||
get_ride_entry_name(entry, item.entry_index);
|
||||
entryPtr = entry;
|
||||
}
|
||||
}
|
||||
_trackDesignsCount = track_design_index_get_for_ride(&_trackDesigns, item.type, entryPtr);
|
||||
|
||||
if (RCT2_GLOBAL(0x00F635ED, uint8) & 1)
|
||||
window_error_open(STR_WARNING, STR_TOO_MANY_TRACK_DESIGNS_OF_THIS_TYPE);
|
||||
|
||||
Reference in New Issue
Block a user