Allow for more peep spawns in the future

This commit is contained in:
wolfreak99 2017-03-02 17:02:54 -05:00 committed by Michael Steenbeek
parent 2da540ba5c
commit 38f264cce8
6 changed files with 94 additions and 35 deletions

View File

@ -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 "5"
#define NETWORK_STREAM_VERSION "6"
#define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION
#ifdef __cplusplus

View File

@ -9784,26 +9784,40 @@ sint32 peep_pathfind_choose_direction(sint16 x, sint16 y, uint8 z, rct_peep *pee
}
/**
*
* rct2: 0x006952C0
* Gets the nearest park entrance relative to point, by using Manhattan distance.
* @param x x coordinate of location
* @param y y coordinate of location
* @return Index of gParkEntrance (or 0xFF if no park entrances exist).
*/
static sint32 guest_path_find_entering_park(rct_peep *peep, rct_map_element *map_element, uint8 edges){
static uint8 get_nearest_park_entrance_index(uint16 x, uint16 y)
{
uint8 chosenEntrance = 0xFF;
uint16 nearestDist = 0xFFFF;
for (uint8 entranceNum = 0; entranceNum < MAX_PARK_ENTRANCES; ++entranceNum){
if (gParkEntrances[entranceNum].x == MAP_LOCATION_NULL)
for (uint8 i = 0; i < MAX_PARK_ENTRANCES; i++) {
if (gParkEntrances[i].x == MAP_LOCATION_NULL)
continue;
uint16 dist = abs(gParkEntrances[entranceNum].x - peep->next_x) +
abs(gParkEntrances[entranceNum].y - peep->next_y);
uint16 dist = abs(gParkEntrances[i].x - x) + abs(gParkEntrances[i].y - y);
if (dist >= nearestDist)
continue;
nearestDist = dist;
chosenEntrance = entranceNum;
chosenEntrance = i;
}
return chosenEntrance;
}
/**
*
* rct2: 0x006952C0
*/
static sint32 guest_path_find_entering_park(rct_peep *peep, rct_map_element *map_element, uint8 edges)
{
// Send peeps to the nearest park entrance.
uint8 chosenEntrance = get_nearest_park_entrance_index(peep->next_x, peep->next_y);
// If no defined park entrances are found, walk aimlessly.
if (chosenEntrance == 0xFF)
return guest_path_find_aimless(peep, edges);
@ -9823,17 +9837,44 @@ static sint32 guest_path_find_entering_park(rct_peep *peep, rct_map_element *map
return peep_move_one_tile(chosenDirection, peep);
}
/**
* Gets the nearest peep spawn relative to point, by using Manhattan distance.
* @param x x coordinate of location
* @param y y coordinate of location
* @return Index of gPeepSpawns (or 0xFF if no peep spawns exist).
*/
static uint8 get_nearest_peep_spawn_index(uint16 x, uint16 y)
{
uint8 chosenSpawn = 0xFF;
uint16 nearestDist = 0xFFFF;
for (uint8 i = 0; i < MAX_PEEP_SPAWNS; ++i) {
if (gPeepSpawns[i].x == PEEP_SPAWN_UNDEFINED)
continue;
uint16 dist = abs(gPeepSpawns[i].x - x) + abs(gPeepSpawns[i].y - y);
if (dist >= nearestDist)
continue;
nearestDist = dist;
chosenSpawn = i;
}
return chosenSpawn;
}
/**
*
* rct2: 0x0069536C
*/
static sint32 guest_path_find_leaving_park(rct_peep *peep, rct_map_element *map_element, uint8 edges){
rct2_peep_spawn* peepSpawn = &gPeepSpawns[0];
// Peeps for whatever reason return to their original spawn point
// this in future should look for the nearest.
if (peep->sprite_index & 1 && gPeepSpawns[1].x != PEEP_SPAWN_UNDEFINED) {
peepSpawn++;
}
// Send peeps to the nearest spawn point.
uint8 chosenSpawn = get_nearest_peep_spawn_index(peep->next_x, peep->next_y);
// If no defined spawns were found, walk aimlessly.
if (chosenSpawn == 0xFF)
return guest_path_find_aimless(peep, edges);
rct2_peep_spawn* peepSpawn = &gPeepSpawns[chosenSpawn];
sint16 x = peepSpawn->x & 0xFFE0;
sint16 y = peepSpawn->y & 0xFFE0;

View File

@ -171,6 +171,8 @@ static uint32 _currentLine;
/** rct2: 0x00F1AD68 */
static uint8 (*_mapImageData)[512][512];
static sint32 _nextPeepSpawnIndex = 0;
static void window_map_init_map();
static void window_map_center_on_view_point();
static void window_map_show_default_scenario_editor_buttons(rct_window *w);
@ -364,13 +366,6 @@ static void window_map_mouseup(rct_window *w, sint32 widgetIndex)
if (tool_set(w, widgetIndex, 2))
break;
gLandToolSize = 0;
if (gPeepSpawns[0].x != PEEP_SPAWN_UNDEFINED &&
gPeepSpawns[1].x != PEEP_SPAWN_UNDEFINED
) {
gLandToolSize = 1;
}
show_gridlines();
show_land_rights();
show_construction_rights();
@ -1370,16 +1365,22 @@ static void window_map_set_peep_spawn_tool_down(sint32 x, sint32 y)
mapY = mapY + 16 + (word_981D6C[direction].y * 15);
mapZ = mapElement->base_height / 2;
sint32 peepSpawnIndex = 0;
if (gLandToolSize != 1 && gPeepSpawns[0].x != PEEP_SPAWN_UNDEFINED)
peepSpawnIndex = 1;
sint32 peepSpawnIndex = -1;
for (sint32 i = 0; i < MAX_PEEP_SPAWNS; i++) {
if (gPeepSpawns[i].x == PEEP_SPAWN_UNDEFINED) {
peepSpawnIndex = i;
break;
}
}
if (peepSpawnIndex == -1) {
peepSpawnIndex = _nextPeepSpawnIndex;
_nextPeepSpawnIndex = (peepSpawnIndex + 1) % (MAX_PEEP_SPAWNS + 1);
}
gPeepSpawns[peepSpawnIndex].x = mapX;
gPeepSpawns[peepSpawnIndex].y = mapY;
gPeepSpawns[peepSpawnIndex].z = mapZ;
gPeepSpawns[peepSpawnIndex].direction = direction;
gfx_invalidate_screen();
gLandToolSize = peepSpawnIndex;
}
/**

View File

@ -5289,3 +5289,14 @@ rct_map_element *map_get_wall_element_at(sint32 x, sint32 y, sint32 z, sint32 di
} while (!map_element_is_last_for_tile(mapElement++));
return NULL;
}
uint32 map_get_available_peep_spawn_index_list(uint32* peepSpawnIndexList)
{
uint32 numSpawns = 0;
for (uint8 i = 0; i < MAX_PEEP_SPAWNS; i++) {
if (gPeepSpawns[i].x != PEEP_SPAWN_UNDEFINED) {
peepSpawnIndexList[numSpawns++] = i;
}
}
return numSpawns;
}

View File

@ -552,4 +552,6 @@ void wall_element_set_animation_frame(rct_map_element * wallElement, uint8 frame
uint8 wall_element_get_secondary_colour(rct_map_element * wallElement);
void wall_element_set_secondary_colour(rct_map_element * wallElement, uint8 secondaryColour);
uint32 map_get_available_peep_spawn_index_list(uint32* peepSpawnIndexList);
#endif

View File

@ -474,21 +474,25 @@ static sint32 park_calculate_guest_generation_probability()
return probability;
}
static void get_random_peep_spawn(rct2_peep_spawn *spawn)
/**
* Choose a random peep spawn and iterates through until defined spawn is found.
*/
static uint32 get_random_peep_spawn_index()
{
*spawn = gPeepSpawns[0];
if (gPeepSpawns[1].x != PEEP_SPAWN_UNDEFINED) {
if (scenario_rand() & 0x80000) {
*spawn = gPeepSpawns[1];
}
uint32 spawnIndexList[MAX_PEEP_SPAWNS];
uint32 numSpawns = map_get_available_peep_spawn_index_list(spawnIndexList);
if (numSpawns > 0) {
return spawnIndexList[scenario_rand() % numSpawns];
}
else {
return 0;
}
}
rct_peep *park_generate_new_guest()
{
rct_peep *peep = NULL;
rct2_peep_spawn spawn;
get_random_peep_spawn(&spawn);
rct2_peep_spawn spawn = gPeepSpawns[get_random_peep_spawn_index()];
if (spawn.x != 0xFFFF) {
spawn.direction ^= 2;