diff --git a/src/localisation/string_ids.h b/src/localisation/string_ids.h index e9da964f74..302e2c8ac2 100644 --- a/src/localisation/string_ids.h +++ b/src/localisation/string_ids.h @@ -1069,6 +1069,8 @@ enum { STR_MUSIC_ACKNOWLEDGEMENTS_ELLIPSIS = 2862, STR_MUSIC_ACKNOWLEDGEMENTS = 2863, + STR_TOO_MANY_BANNERS_IN_GAME = 2980, + STR_CHANGE_BANNER_TEXT_TIP = 2986, STR_SET_AS_NO_ENTRY_BANNER_TIP = 2987, STR_DEMOLISH_BANNER_TIP = 2988, diff --git a/src/world/banner.c b/src/world/banner.c index 172ab08f7d..306b1cad26 100644 --- a/src/world/banner.c +++ b/src/world/banner.c @@ -19,6 +19,8 @@ *****************************************************************************/ #include "../addresses.h" +#include "../game.h" +#include "../localisation/localisation.h" #include "banner.h" rct_banner *gBanners = (rct_banner*)0x0135A124; @@ -32,3 +34,34 @@ void banner_init() { gBanners[i].type = BANNER_NULL; } } + +/* rct2: 0x006BA278 + * Creates a new banner and returns the index of the banner + * If the flag GAME_COMMAND_FLAG_APPLY is NOT set then returns + * the first unused index but does NOT mark the banner as created. + * returns 0xFF on failure. + */ +int create_new_banner(uint8 flags){ + int banner_index = 0; + for (; banner_index < MAX_BANNERS; banner_index++){ + if (gBanners[banner_index].type == BANNER_NULL){ + break; + } + } + + if (banner_index == MAX_BANNERS){ + RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_TEXT, rct_string_id) = STR_TOO_MANY_BANNERS_IN_GAME; + return BANNER_NULL; + } + + if (flags & GAME_COMMAND_FLAG_APPLY){ + rct_banner* banner = &gBanners[banner_index]; + + banner->flags = 0; + banner->type = 0; + banner->string_idx = 778; + banner->colour = 2; + banner->text_colour = 2; + } + return banner_index; +} \ No newline at end of file diff --git a/src/world/banner.h b/src/world/banner.h index 5e7843818a..c3ee3300f9 100644 --- a/src/world/banner.h +++ b/src/world/banner.h @@ -44,5 +44,6 @@ enum{ extern rct_banner *gBanners; void banner_init(); +int create_new_banner(uint8 flags); #endif diff --git a/src/world/map.c b/src/world/map.c index db832b1768..a98612d2e6 100644 --- a/src/world/map.c +++ b/src/world/map.c @@ -1711,24 +1711,24 @@ void game_command_place_banner(int* eax, int* ebx, int* ecx, int* edx, int* esi, (map_element->properties.banner.position & 0x3) != edge){ map_element++; if((map_element - 1)->flags & MAP_ELEMENT_FLAG_LAST_TILE){ - uint8 a = sub_6BA278(*ebx); - if(a == 0xFF){ + int banner_index = create_new_banner(*ebx); + if(banner_index == BANNER_NULL){ *ebx = MONEY32_UNDEFINED; return; } - *edi = a; + *edi = banner_index; if(*ebx & GAME_COMMAND_FLAG_APPLY){ rct_map_element* new_map_element = map_element_insert(x / 32, y / 32, (base_height + 1) * 2, 0); - gBanners[a].type = type; - gBanners[a].colour = colour; - gBanners[a].x = x / 32; - gBanners[a].y = y / 32; + gBanners[banner_index].type = type; + gBanners[banner_index].colour = colour; + gBanners[banner_index].x = x / 32; + gBanners[banner_index].y = y / 32; new_map_element->type = MAP_ELEMENT_TYPE_BANNER; new_map_element->clearance_height = new_map_element->base_height + 2; new_map_element->properties.banner.position = edge; new_map_element->properties.banner.flags = 0xFF; new_map_element->properties.banner.unused = 0; - new_map_element->properties.banner.index = a; + new_map_element->properties.banner.index = banner_index; if(*ebx & 0x40){ new_map_element->flags |= 0x10; }