Integrate staff variables

This commit is contained in:
Ted John 2016-09-10 15:17:18 +01:00
parent 708efdd08c
commit 2299b22cbc
8 changed files with 115 additions and 71 deletions

View File

@ -215,10 +215,6 @@
#define RCT2_ADDRESS_PEEP_SPAWNS 0x013573F2
#define RCT2_ADDRESS_HANDYMAN_COLOUR 0x01357BCD
#define RCT2_ADDRESS_MECHANIC_COLOUR 0x01357BCE
#define RCT2_ADDRESS_SECURITY_COLOUR 0x01357BCF
#define RCT2_ADDRESS_MAP_SIZE_UNITS 0x01358830
#define RCT2_ADDRESS_MAP_SIZE_MINUS_2 0x01358832
#define RCT2_ADDRESS_MAP_SIZE 0x01358834
@ -244,7 +240,6 @@
#define RCT2_ADDRESS_RIDE_MEASUREMENTS 0x0138B60C
#define RCT2_ADDRESS_GRASS_SCENERY_TILEPOS 0x013B0E70
#define RCT2_ADDRESS_STAFF_PATROL_AREAS 0x013B0E72
#define RCT2_ADDRESS_NEWS_ITEM_LIST 0x013CA754
@ -328,8 +323,6 @@
#define RCT2_ADDRESS_AUDIO_INFO 0x01425B40
#define RCT2_ADDRESS_STAFF_MODE_ARRAY 0x013CA672
#pragma endregion
#pragma region Obsolete
@ -538,6 +531,9 @@
#define RCT2_ADDRESS_PARK_ENTRANCE_FEE 0x013573E8
#define RCT2_ADDRESS_GUESTS_IN_PARK 0x01357844
#define RCT2_ADDRESS_GUESTS_HEADING_FOR_PARK 0x01357846
#define RCT2_ADDRESS_HANDYMAN_COLOUR 0x01357BCD
#define RCT2_ADDRESS_MECHANIC_COLOUR 0x01357BCE
#define RCT2_ADDRESS_SECURITY_COLOUR 0x01357BCF
#define RCT2_ADDRESS_CURRENT_PARK_RATING 0x01357CB0
#define RCT2_ADDRESS_PARK_RATING_HISTORY 0x01357CB2
#define RCT2_ADDRESS_GUESTS_IN_PARK_HISTORY 0x01357CD2
@ -589,6 +585,9 @@
#define RCT2_ADDRESS_SAVED_AGE 0x01388698
#define RCT2_ADDRESS_NUM_MAP_ANIMATIONS 0x0138B580
#define RCT2_ADDRESS_STAFF_PATROL_AREAS 0x013B0E72
#define RCT2_ADDRESS_STAFF_MODE_ARRAY 0x013CA672
#define RCT2_ADDRESS_CLIMATE 0x013CA746
#define RCT2_ADDRESS_CURRENT_WEATHER 0x013CA74A
#define RCT2_ADDRESS_NEXT_WEATHER 0x013CA74B

View File

@ -740,12 +740,7 @@ void path_paint(uint8 direction, uint16 height, rct_map_element * map_element)
staffType = staff->staff_type;
}
x = (x & 0x1F80) >> 7;
y = (y & 0x1F80) >> 1;
int offset = (x | y) >> 5;
int bitIndex = (x | y) & 0x1F;
int ebx = (staffType + 200) * 512;
if (RCT2_ADDRESS(RCT2_ADDRESS_STAFF_PATROL_AREAS + ebx, uint32)[offset] & (1 << bitIndex)) {
if (staff_is_patrol_area_set(200 + staffType, x, y)) {
uint32 imageId = 2618;
int height = map_element->base_height * 8;
if (footpath_element_is_sloped(map_element)) {

View File

@ -1133,12 +1133,7 @@ void surface_paint(uint8 direction, uint16 height, rct_map_element * mapElement)
staffType = staff->staff_type;
}
x = (x & 0x1F80) >> 7;
y = (y & 0x1F80) >> 1;
int offset = (x | y) >> 5;
int bitIndex = (x | y) & 0x1F;
int ebx = (staffType + 200) * 512;
if (RCT2_ADDRESS(RCT2_ADDRESS_STAFF_PATROL_AREAS + ebx, uint32)[offset] & (1 << bitIndex)) {
if (staff_is_patrol_area_set(200 + staffType, x, y)) {
assert(surfaceShape < countof(byte_97B444));
image_id |= SPR_TERRAIN_SELECTION_PATROL_AREA + byte_97B444[surfaceShape];

View File

@ -1851,7 +1851,7 @@ void peep_sprite_remove(rct_peep* peep){
else{
window_invalidate_by_class(WC_STAFF_LIST);
RCT2_ADDRESS(RCT2_ADDRESS_STAFF_MODE_ARRAY, uint8)[peep->staff_id] = 0;
gStaffModes[peep->staff_id] = 0;
peep->type = 0xFF;
staff_update_greyed_patrol_areas();
peep->type = PEEP_TYPE_STAFF;

View File

@ -28,8 +28,12 @@
#include "peep.h"
#include "staff.h"
uint32 *gStaffPatrolAreas = RCT2_ADDRESS(RCT2_ADDRESS_STAFF_PATROL_AREAS, uint32);
uint8 *gStaffModes = RCT2_ADDRESS(RCT2_ADDRESS_STAFF_MODE_ARRAY, uint8);
uint32 gStaffPatrolAreas[204 * 128];
uint8 gStaffModes[204];
uint16 gStaffDrawPatrolAreas;
colour_t gStaffHandymanColour;
colour_t gStaffMechanicColour;
colour_t gStaffSecurityColour;
/**
*
@ -38,10 +42,10 @@ uint8 *gStaffModes = RCT2_ADDRESS(RCT2_ADDRESS_STAFF_MODE_ARRAY, uint8);
void staff_reset_modes()
{
for (int i = 0; i < 200; i++)
RCT2_ADDRESS(RCT2_ADDRESS_STAFF_MODE_ARRAY, uint8)[i] = STAFF_MODE_NONE;
gStaffModes[i] = STAFF_MODE_NONE;
for (int i = 200; i < 204; i++)
RCT2_ADDRESS(RCT2_ADDRESS_STAFF_MODE_ARRAY, uint8)[i] = STAFF_MODE_WALK;
gStaffModes[i] = STAFF_MODE_WALK;
staff_update_greyed_patrol_areas();
}
@ -60,7 +64,7 @@ void game_command_update_staff_colour(int *eax, int *ebx, int *ecx, int *edx, in
colour = (*edx >> 8) & 0xFF;
if (*ebx & GAME_COMMAND_FLAG_APPLY) {
gStaffColours[staffType] = colour;
staff_set_colour(staffType, colour);
FOR_ALL_PEEPS(spriteIndex, peep) {
if (peep->type == PEEP_TYPE_STAFF && peep->staff_type == staffType) {
@ -165,7 +169,7 @@ static money32 staff_hire_new_staff_member(uint8 staff_type, uint8 flags, sint16
int i;
for (i = 0; i < STAFF_MAX_COUNT; ++i) {
if (!(RCT2_ADDRESS(RCT2_ADDRESS_STAFF_MODE_ARRAY, uint8)[i] & 1))
if (!(gStaffModes[i] & 1))
break;
}
@ -279,7 +283,7 @@ static money32 staff_hire_new_staff_member(uint8 staff_type, uint8 flags, sint16
newPeep->pathfind_goal.z = 0xFF;
newPeep->pathfind_goal.direction = 0xFF;
uint8 colour = gStaffColours[clamp(STAFF_TYPE_HANDYMAN, staff_type, STAFF_TYPE_SECURITY)];
uint8 colour = staff_get_colour(staff_type);
newPeep->tshirt_colour = colour;
newPeep->trousers_colour = colour;
@ -292,11 +296,11 @@ static money32 staff_hire_new_staff_member(uint8 staff_type, uint8 flags, sint16
newPeep->staff_id = newStaffId;
RCT2_ADDRESS(RCT2_ADDRESS_STAFF_MODE_ARRAY, uint8)[newStaffId] = STAFF_MODE_WALK;
gStaffModes[newStaffId] = STAFF_MODE_WALK;
for (int i = 0; i < 0x80; ++i) {
int addr = RCT2_ADDRESS_STAFF_PATROL_AREAS + (newStaffId << 9) + i * 4;
RCT2_GLOBAL(addr, uint32) = 0;
for (int i = 0; i < 128; i++) {
uint32 *addr = (uint32*)((uintptr_t)gStaffPatrolAreas + (newStaffId << 9) + i * 4);
*addr = 0;
}
}
@ -407,21 +411,17 @@ void game_command_set_staff_patrol(int *eax, int *ebx, int *ecx, int *edx, int *
}
rct_peep *peep = &sprite->peep;
int patrolOffset = peep->staff_id * (64 * 64 / 8);
int patrolIndex = ((x & 0x1F80) >> 7) | ((y & 0x1F80) >> 1);
int mask = 1u << (patrolIndex & 0x1F);
int base = patrolIndex >> 5;
uint32 *patrolBits = RCT2_ADDRESS(RCT2_ADDRESS_STAFF_PATROL_AREAS + patrolOffset + (base * 4), uint32);
*patrolBits ^= mask;
staff_toggle_patrol_area(peep->staff_id, x, y);
int ispatrolling = 0;
for(int i = 0; i < 128; i++){
ispatrolling |= RCT2_GLOBAL(RCT2_ADDRESS_STAFF_PATROL_AREAS + patrolOffset + (i * 4), uint32);
ispatrolling |= *((uint32*)((uintptr_t)gStaffPatrolAreas + patrolOffset + (i * 4)));
}
RCT2_ADDRESS(RCT2_ADDRESS_STAFF_MODE_ARRAY, uint8)[peep->staff_id] &= ~2;
gStaffModes[peep->staff_id] &= ~2;
if(ispatrolling){
RCT2_ADDRESS(RCT2_ADDRESS_STAFF_MODE_ARRAY, uint8)[peep->staff_id] |= 2;
gStaffModes[peep->staff_id] |= 2;
}
for(int y2 = 0; y2 < 4; y2++){
@ -502,8 +502,10 @@ void staff_update_greyed_patrol_areas()
for (int staff_type = 0; staff_type < STAFF_TYPE_COUNT; ++staff_type)
{
for (int i = 0; i < 128; ++i)
RCT2_ADDRESS(RCT2_ADDRESS_STAFF_PATROL_AREAS + ((staff_type + STAFF_MAX_COUNT) * 512), uint32)[i] = 0;
uint32 *addr = (uint32*)((uintptr_t)gStaffPatrolAreas + ((staff_type + STAFF_MAX_COUNT) * 512));
for (int i = 0; i < 128; i++) {
addr[i] = 0;
}
for (uint16 sprite_index = gSpriteListHead[SPRITE_LIST_PEEP]; sprite_index != SPRITE_INDEX_NULL; sprite_index = peep->next)
{
@ -511,9 +513,10 @@ void staff_update_greyed_patrol_areas()
if (peep->type == PEEP_TYPE_STAFF && staff_type == peep->staff_type)
{
for (int i = 0; i < 128; ++i)
RCT2_ADDRESS(RCT2_ADDRESS_STAFF_PATROL_AREAS + ((staff_type + STAFF_MAX_COUNT) * 512), uint32)[i] |= RCT2_ADDRESS(RCT2_ADDRESS_STAFF_PATROL_AREAS + (peep->staff_id * 512), uint32)[i];
uint32 *addr2 = (uint32*)((uintptr_t)gStaffPatrolAreas + (peep->staff_id * 512));
for (int i = 0; i < 128; i++) {
addr[i] |= addr2[i];
}
}
}
}
@ -524,13 +527,7 @@ static int staff_is_location_in_patrol_area(rct_peep *peep, int x, int y)
// Patrol quads are stored in a bit map (8 patrol quads per byte)
// Each patrol quad is 4x4
// Therefore there are in total 64 x 64 patrol quads in the 256 x 256 map
int patrolOffset = peep->staff_id * (64 * 64 / 8);
int patrolIndex = ((x & 0x1F80) >> 7) | ((y & 0x1F80) >> 1);
int mask = 1u << (patrolIndex & 0x1F);
int base = patrolIndex >> 5;
uint32 *patrolBits = RCT2_ADDRESS(RCT2_ADDRESS_STAFF_PATROL_AREAS + patrolOffset + (base * 4), uint32);
return (*patrolBits & mask) != 0;
return staff_is_patrol_area_set(peep->staff_id, x, y);
}
/**
@ -544,7 +541,7 @@ int staff_is_location_in_patrol(rct_peep *staff, int x, int y)
return 0;
// Check if staff has patrol area
if (!(RCT2_ADDRESS(RCT2_ADDRESS_STAFF_MODE_ARRAY, uint8)[staff->staff_id] & 2))
if (!(gStaffModes[staff->staff_id] & 2))
return 1;
return staff_is_location_in_patrol_area(staff, x, y);
@ -616,6 +613,33 @@ bool staff_is_patrol_area_set(int staffIndex, int x, int y)
return gStaffPatrolAreas[peepOffset + offset] & (1 << bitIndex);
}
void staff_set_patrol_area(int staffIndex, int x, int y, bool value)
{
x = (x & 0x1F80) >> 7;
y = (y & 0x1F80) >> 1;
int peepOffset = staffIndex * 128;
int offset = (x | y) >> 5;
int bitIndex = (x | y) & 0x1F;
uint32 *addr = &gStaffPatrolAreas[peepOffset + offset];
if (value) {
*addr |= (1 << bitIndex);
} else {
*addr &= ~(1 << bitIndex);
}
}
void staff_toggle_patrol_area(int staffIndex, int x, int y)
{
x = (x & 0x1F80) >> 7;
y = (y & 0x1F80) >> 1;
int peepOffset = staffIndex * 128;
int offset = (x | y) >> 5;
int bitIndex = (x | y) & 0x1F;
gStaffPatrolAreas[peepOffset + offset] ^= (1 << bitIndex);
}
/**
*
* rct2: 0x006BFBE8
@ -1293,3 +1317,33 @@ void game_command_set_staff_name(int *eax, int *ebx, int *ecx, int *edx, int *es
(uint8*)edi
);
}
colour_t staff_get_colour(uint8 staffType)
{
switch (staffType) {
case STAFF_TYPE_HANDYMAN: return gStaffHandymanColour;
case STAFF_TYPE_MECHANIC: return gStaffMechanicColour;
case STAFF_TYPE_SECURITY: return gStaffSecurityColour;
default:
assert(false);
return 0;
}
}
void staff_set_colour(uint8 staffType, colour_t value)
{
switch (staffType) {
case STAFF_TYPE_HANDYMAN:
gStaffHandymanColour = value;
break;
case STAFF_TYPE_MECHANIC:
gStaffMechanicColour = value;
break;
case STAFF_TYPE_SECURITY:
gStaffSecurityColour = value;
break;
default:
assert(false);
break;
}
}

View File

@ -20,8 +20,8 @@
#include "../common.h"
#include "peep.h"
#define STAFF_MAX_COUNT 0xC8
#define STAFF_TYPE_COUNT 0x04
#define STAFF_MAX_COUNT 200
#define STAFF_TYPE_COUNT 4
enum STAFF_MODE {
STAFF_MODE_NONE,
@ -45,14 +45,12 @@ enum STAFF_ORDERS{
STAFF_ORDERS_FIX_RIDES = (1 << 1)
};
extern uint32 *gStaffPatrolAreas;
extern uint8 *gStaffModes;
#define gStaffDrawPatrolAreas RCT2_GLOBAL(0x009DEA50, uint16)
#define gStaffColours RCT2_ADDRESS(RCT2_ADDRESS_HANDYMAN_COLOUR, colour_t)
#define gStaffHandymanColour RCT2_GLOBAL(RCT2_ADDRESS_HANDYMAN_COLOUR, colour_t)
#define gStaffMechanicColour RCT2_GLOBAL(RCT2_ADDRESS_MECHANIC_COLOUR, colour_t)
#define gStaffSecurityColour RCT2_GLOBAL(RCT2_ADDRESS_SECURITY_COLOUR, colour_t)
extern uint32 gStaffPatrolAreas[204 * 128];
extern uint8 gStaffModes[204];
extern uint16 gStaffDrawPatrolAreas;
extern colour_t gStaffHandymanColour;
extern colour_t gStaffMechanicColour;
extern colour_t gStaffSecurityColour;
void game_command_update_staff_colour(int *eax, int *ebx, int *ecx, int *edx, int *esi, int *edi, int *ebp);
void game_command_hire_new_staff_member(int *eax, int *ebx, int *ecx, int *edx, int *esi, int *edi, int *ebp);
@ -69,5 +67,9 @@ int staff_is_location_in_patrol(rct_peep *mechanic, int x, int y);
int staff_path_finding(rct_peep* peep);
void staff_reset_stats();
bool staff_is_patrol_area_set(int staffIndex, int x, int y);
void staff_set_patrol_area(int staffIndex, int x, int y, bool value);
void staff_toggle_patrol_area(int staffIndex, int x, int y);
colour_t staff_get_colour(uint8 staffType);
void staff_set_colour(uint8 staffType, colour_t value);
#endif

View File

@ -550,7 +550,7 @@ void window_staff_overview_mousedown(int widgetIndex, rct_window* w, rct_widget*
rct_peep* peep = GET_PEEP(w->number);
// Disable clear patrol area if no area is set.
if (!(RCT2_ADDRESS(RCT2_ADDRESS_STAFF_MODE_ARRAY, uint8)[peep->staff_id] & 2)) {
if (!(gStaffModes[peep->staff_id] & 2)) {
gDropdownItemsDisabled |= (1ULL << 1);
}
}
@ -568,12 +568,11 @@ void window_staff_overview_dropdown(rct_window *w, int widgetIndex, int dropdown
// Clear patrol
if (dropdownIndex == 1) {
rct_peep* peep = GET_PEEP(w->number);
for (int i = 0; i < 128; i++)
{
RCT2_ADDRESS(RCT2_ADDRESS_STAFF_PATROL_AREAS + (peep->staff_id * 512), uint32)[i] = 0;
uint32 *addr = (uint32*)((uintptr_t)gStaffPatrolAreas + (peep->staff_id * 512));
for (int i = 0; i < 128; i++) {
addr[i] = 0;
}
RCT2_ADDRESS(RCT2_ADDRESS_STAFF_MODE_ARRAY, uint8)[peep->staff_id] &= ~2;
gStaffModes[peep->staff_id] &= ~2;
gfx_invalidate_screen();
staff_update_greyed_patrol_areas();

View File

@ -287,7 +287,7 @@ static void window_staff_list_mousedown(int widgetIndex, rct_window* w, rct_widg
window_staff_list_cancel_tools(w);
break;
case WIDX_STAFF_LIST_UNIFORM_COLOUR_PICKER:
window_dropdown_show_colour(w, widget, w->colours[1], gStaffColours[_windowStaffListSelectedTab]);
window_dropdown_show_colour(w, widget, w->colours[1], staff_get_colour(_windowStaffListSelectedTab));
break;
}
@ -504,7 +504,7 @@ void window_staff_list_invalidate(rct_window *w)
if (tabIndex < 3) {
window_staff_list_widgets[WIDX_STAFF_LIST_UNIFORM_COLOUR_PICKER].type = WWT_COLOURBTN;
window_staff_list_widgets[WIDX_STAFF_LIST_UNIFORM_COLOUR_PICKER].image =
((uint32)gStaffColours[tabIndex] << 19) | 0x60000000 | SPR_PALETTE_BTN;
((uint32)staff_get_colour(tabIndex) << 19) | 0x60000000 | SPR_PALETTE_BTN;
}
if (_quick_fire_mode)
w->pressed_widgets |= (1ULL << WIDX_STAFF_LIST_QUICK_FIRE);
@ -678,7 +678,7 @@ void window_staff_list_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, int sc
gfx_draw_string_left_clipped(dpi, format, gCommonFormatArgs, 0, 175, y - 1, 305);
// True if a patrol path is set for the worker
if (RCT2_ADDRESS(RCT2_ADDRESS_STAFF_MODE_ARRAY, uint8)[peep->staff_id] & 2) {
if (gStaffModes[peep->staff_id] & 2) {
gfx_draw_sprite(dpi, SPR_STAFF_PATROL_PATH, 110, y - 1, 0);
}