1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-21 14:02:59 +01:00

Refactored, cleaned, and wrapped game_command_hire_new_staff_member

This commit is contained in:
Goddesen
2016-06-11 01:44:58 +02:00
parent 1ba9827a49
commit a35909af31

View File

@@ -74,24 +74,85 @@ void game_command_update_staff_colour(int *eax, int *ebx, int *ecx, int *edx, in
*ebx = 0;
}
/**
*
* rct2: 0x006BEFA1
*/
void game_command_hire_new_staff_member(int* eax, int* ebx, int* ecx, int* edx, int* esi, int* edi, int* ebp)
static inline void staff_autoposition_new_staff_member(rct_peep *newPeep)
{
uint8 staff_type = (*ebx & 0xFF00) >> 8;
uint8 game_command_flags = *ebx & 0xFF;
// Find a location to place new staff member
newPeep->state = PEEP_STATE_FALLING;
sint16 x, y, z;
uint32 count = 0;
uint16 sprite_index;
rct_peep *guest = NULL;
// Count number of walking guests
FOR_ALL_GUESTS(sprite_index, guest) {
if (guest->state == PEEP_STATE_WALKING)
++count;
}
if (count > 0) {
// Place staff at a random guest
uint32 rand = scenario_rand_max(count);
FOR_ALL_GUESTS(sprite_index, guest) {
if (guest->state == PEEP_STATE_WALKING) {
if (rand == 0)
break;
--rand;
}
}
x = guest->x;
y = guest->y;
z = guest->z;
} else {
// No walking guests; pick random park entrance
count = 0;
uint8 i;
for (i = 0; i < 4; ++i) {
if (gParkEntranceX[i] != SPRITE_LOCATION_NULL)
++count;
}
if (count > 0) {
uint32 rand = scenario_rand_max(count);
for (i = 0; i < 4; ++i) {
if (gParkEntranceX[i] != SPRITE_LOCATION_NULL) {
if (rand == 0)
break;
--rand;
}
}
uint8 dir = gParkEntranceDirection[i];
x = gParkEntranceX[i];
y = gParkEntranceY[i];
z = gParkEntranceZ[i];
x += 16 + ((dir & 1) == 0 ? ((dir & 2) ? 32 : -32) : 0);
y += 16 + ((dir & 1) == 1 ? ((dir & 2) ? -32 : 32) : 0);
} else {
// No more options; user must pick a location
newPeep->state = PEEP_STATE_PICKED;
x = newPeep->x;
y = newPeep->y;
z = newPeep->z;
}
}
sprite_move(x, y, z + 16, (rct_sprite *)newPeep);
invalidate_sprite_2((rct_sprite *)newPeep);
}
money32 staff_hire_new_staff_member(uint8 staff_type, uint8 flags, sint16 command_x, sint16 command_y, sint16 command_z, int *newPeep_sprite_index)
{
gCommandExpenditureType = RCT_EXPENDITURE_TYPE_WAGES;
gCommandPosition.x = *eax & 0xFFFF;
gCommandPosition.y = *ecx & 0xFFFF;
gCommandPosition.z = *edx & 0xFFFF;
gCommandPosition.x = command_x;
gCommandPosition.y = command_y;
gCommandPosition.z = command_z;
if (gSpriteListCount[SPRITE_LIST_NULL] < 400) {
*ebx = MONEY32_UNDEFINED;
gGameCommandErrorText = STR_TOO_MANY_PEOPLE_IN_GAME;
return;
return MONEY32_UNDEFINED;
}
int i;
@@ -101,24 +162,21 @@ void game_command_hire_new_staff_member(int* eax, int* ebx, int* ecx, int* edx,
}
if (i == STAFF_MAX_COUNT) {
*ebx = MONEY32_UNDEFINED;
gGameCommandErrorText = STR_TOO_MANY_STAFF_IN_GAME;
return;
return MONEY32_UNDEFINED;
}
int newStaffId = i;
rct_sprite_bounds *spriteBounds;
rct_peep* newPeep = &(create_sprite(game_command_flags)->peep);
rct_peep *newPeep = &(create_sprite(flags)->peep);
if (newPeep == NULL)
{
*ebx = MONEY32_UNDEFINED;
if (newPeep == NULL) {
gGameCommandErrorText = STR_TOO_MANY_PEOPLE_IN_GAME;
return;
return MONEY32_UNDEFINED;
}
if (game_command_flags == 0) {
sprite_remove((rct_sprite*)newPeep);
if (flags == 0) {
sprite_remove((rct_sprite *)newPeep);
} else {
move_sprite_to_list((rct_sprite *)newPeep, SPRITE_LIST_PEEP * 2);
@@ -138,35 +196,33 @@ void game_command_hire_new_staff_member(int* eax, int* ebx, int* ecx, int* edx,
newPeep->paid_on_food = 0;
newPeep->paid_on_souvenirs = 0;
newPeep->staff_orders = 0;
if (staff_type == 0) {
if (staff_type == STAFF_TYPE_HANDYMAN)
newPeep->staff_orders = 7;
}
else if (staff_type == 1) {
else if (staff_type == STAFF_TYPE_MECHANIC)
newPeep->staff_orders = 3;
}
else
newPeep->staff_orders = 0;
uint16 idSearchSpriteIndex;
rct_peep* idSearchPeep;
rct_peep *idSearchPeep;
// We search for the first available id for a given staff type
int newStaffIndex = 0;
for (;;) {
int found = 0;
bool found = false;
newStaffIndex++;
FOR_ALL_STAFF(idSearchSpriteIndex, idSearchPeep) {
if (idSearchPeep->staff_type != staff_type) {
if (idSearchPeep->staff_type != staff_type)
continue;
}
if (idSearchPeep->id == newStaffIndex) {
found = 1;
found = true;
break;
}
}
if (found == 0)
if (!found)
break;
}
@@ -182,65 +238,13 @@ void game_command_hire_new_staff_member(int* eax, int* ebx, int* ecx, int* edx,
newPeep->sprite_height_negative = spriteBounds->sprite_height_negative;
newPeep->sprite_height_positive = spriteBounds->sprite_height_positive;
if ((gConfigGeneral.auto_staff_placement != 0) != ((SDL_GetModState() & KMOD_SHIFT) != 0)) {
newPeep->state = PEEP_STATE_FALLING;
sint16 x, y, z;
uint32 count = 0;
uint16 sprite_index;
rct_peep *guest = NULL;
FOR_ALL_GUESTS(sprite_index, guest)
if (guest->state == PEEP_STATE_WALKING) ++count;
if (count == 0) {
count = 0;
uint8 i;
for (i = 0; i < 4; ++i) {
if (gParkEntranceX[i] != SPRITE_LOCATION_NULL) ++count;
}
if (count > 0) {
uint32 rand = scenario_rand_max(count);
for (i = 0; i < 4; ++i) {
if (gParkEntranceX[i] != SPRITE_LOCATION_NULL) {
if (rand == 0) break;
--rand;
}
}
uint8 dir = gParkEntranceDirection[i];
x = gParkEntranceX[i];
y = gParkEntranceY[i];
z = gParkEntranceZ[i];
x += 16 + ((dir & 1) == 0 ? ((dir & 2) ? 32 : -32) : 0);
y += 16 + ((dir & 1) == 1 ? ((dir & 2) ? -32 : 32) : 0);
} else {
newPeep->state = PEEP_STATE_PICKED;
x = newPeep->x;
y = newPeep->y;
z = newPeep->z;
}
} else {
uint32 rand = scenario_rand_max(count);
FOR_ALL_GUESTS(sprite_index, guest)
if (guest->state == PEEP_STATE_WALKING) {
if (rand == 0) break;
--rand;
}
x = guest->x;
y = guest->y;
z = guest->z;
}
sprite_move(x, y, z + 16, (rct_sprite*)newPeep);
invalidate_sprite_2((rct_sprite*)newPeep);
if (gConfigGeneral.auto_staff_placement != ((SDL_GetModState() & KMOD_SHIFT) != 0)) {
staff_autoposition_new_staff_member(newPeep);
} else {
newPeep->state = PEEP_STATE_PICKED;
sprite_move(newPeep->x, newPeep->y, newPeep->z, (rct_sprite*)newPeep);
invalidate_sprite_2((rct_sprite*)newPeep);
invalidate_sprite_2((rct_sprite *)newPeep);
}
newPeep->time_in_park = gDateMonthsElapsed;
@@ -264,19 +268,33 @@ void game_command_hire_new_staff_member(int* eax, int* ebx, int* ecx, int* edx,
RCT2_ADDRESS(RCT2_ADDRESS_STAFF_MODE_ARRAY, uint8)[newStaffId] = STAFF_MODE_WALK;
for (int edi = 0; edi < 0x80; edi++) {
int addr = RCT2_ADDRESS_STAFF_PATROL_AREAS + (newStaffId << 9) + edi * 4;
for (int i = 0; i < 0x80; i++) {
int addr = RCT2_ADDRESS_STAFF_PATROL_AREAS + (newStaffId << 9) + i * 4;
RCT2_GLOBAL(addr, uint32) = 0;
}
}
if(staff_type == STAFF_TYPE_HANDYMAN && gConfigGeneral.handymen_mow_default) {
int flags = ((newPeep->staff_orders ^ (1 << 3)) << 8) | 1;
game_do_command(newPeep->x, flags, newPeep->y, newPeep->sprite_index, GAME_COMMAND_SET_STAFF_ORDER, (int)newPeep, 0);
if((staff_type == STAFF_TYPE_HANDYMAN) && gConfigGeneral.handymen_mow_default) {
int newPeep_flags = ((newPeep->staff_orders ^ (1 << 3)) << 8) | 1;
game_do_command(newPeep->x, newPeep_flags, newPeep->y, newPeep->sprite_index, GAME_COMMAND_SET_STAFF_ORDER, (int)newPeep, 0);
}
*ebx = 0;
*edi = newPeep->sprite_index;
*newPeep_sprite_index = newPeep->sprite_index;
return 0;
}
/**
*
* rct2: 0x006BEFA1
*/
void game_command_hire_new_staff_member(int* eax, int* ebx, int* ecx, int* edx, int* esi, int* edi, int* ebp)
{
*ebx = staff_hire_new_staff_member((*ebx & 0xFF00) >> 8,
*ebx & 0xFF,
*eax & 0xFFFF,
*ecx & 0xFFFF,
*edx & 0xFFFF,
edi);
}
/**