Implement more company manager functions (#1096)
* Minor refactor to use isPlayerCompany * Implement CompanyManager::reset (add hook?) * Replace instances of second getOwnerStatus signature * Implement CompanyManager::getOwnerStatus
This commit is contained in:
parent
ae294ad80e
commit
f7fcba0e6a
|
@ -41,6 +41,16 @@ namespace OpenLoco
|
|||
tycoon // 90 - 100%
|
||||
};
|
||||
|
||||
enum ObservationStatus : uint8_t
|
||||
{
|
||||
empty,
|
||||
buildingTrackRoad,
|
||||
buildingAirport,
|
||||
buildingDock,
|
||||
checkingServices,
|
||||
surveyingLandscape,
|
||||
};
|
||||
|
||||
void formatPerformanceIndex(const int16_t performanceIndex, FormatArguments& args);
|
||||
|
||||
constexpr size_t expenditureHistoryCapacity = 16;
|
||||
|
@ -97,11 +107,13 @@ namespace OpenLoco
|
|||
currency48_t vehicleProfit; // 0x8B9E
|
||||
uint16_t transportTypeCount[6]; // 0x8BA4
|
||||
uint8_t var_8BB0[9];
|
||||
uint8_t pad_8BB9[0x8BBC - 0x8BB9];
|
||||
EntityId_t observation_thing; // 0x8BBC;
|
||||
int16_t observation_x; // 0x8BBE;
|
||||
int16_t observation_y; // 0x8BC0;
|
||||
uint8_t pad_8BC2[0x8BCE - 0x8BC2];
|
||||
ObservationStatus observationStatus; // 0x8BB9;
|
||||
TownId_t observationTownId; // 0x8BBA;
|
||||
EntityId_t observation_thing; // 0x8BBC;
|
||||
int16_t observation_x; // 0x8BBE;
|
||||
int16_t observation_y; // 0x8BC0;
|
||||
uint16_t observationObject; // 0x8BC2;
|
||||
uint8_t pad_8BC4[0x8BCE - 0x8BC4];
|
||||
uint32_t cargoDelivered[32]; // 0x8BCE;
|
||||
uint8_t challengeProgress; // 0x8C4E - percent completed on challenge
|
||||
uint8_t pad_8C4F;
|
||||
|
|
|
@ -3,11 +3,17 @@
|
|||
#include "Entities/EntityManager.h"
|
||||
#include "Entities/Misc.h"
|
||||
#include "GameCommands/GameCommands.h"
|
||||
#include "Graphics/Colour.h"
|
||||
#include "Interop/Interop.hpp"
|
||||
#include "Localisation/FormatArguments.hpp"
|
||||
#include "Map/Tile.h"
|
||||
#include "Map/TileManager.h"
|
||||
#include "Objects/AirportObject.h"
|
||||
#include "Objects/DockObject.h"
|
||||
#include "Objects/RoadObject.h"
|
||||
#include "Objects/TrackObject.h"
|
||||
#include "OpenLoco.h"
|
||||
#include "TownManager.h"
|
||||
#include "Ui/WindowManager.h"
|
||||
#include "Vehicles/Vehicle.h"
|
||||
#include "Vehicles/VehicleManager.h"
|
||||
|
@ -30,7 +36,32 @@ namespace OpenLoco::CompanyManager
|
|||
// 0x0042F7F8
|
||||
void reset()
|
||||
{
|
||||
call(0x0042F7F8);
|
||||
// First, empty all non-empty companies.
|
||||
for (auto& company : companies())
|
||||
company.name = StringIds::empty;
|
||||
|
||||
_byte_525FCB = 0;
|
||||
|
||||
// Reset player companies depending on network mode.
|
||||
if (isNetworkHost())
|
||||
{
|
||||
_player_company[0] = 1;
|
||||
_player_company[1] = 0;
|
||||
}
|
||||
else if (isNetworked())
|
||||
{
|
||||
_player_company[0] = 0;
|
||||
_player_company[1] = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
_player_company[0] = 0;
|
||||
_player_company[1] = 0xFF;
|
||||
}
|
||||
|
||||
// Reset primary company colours.
|
||||
_companies[0].mainColours.primary = Colour::saturated_green;
|
||||
updateColours();
|
||||
}
|
||||
|
||||
CompanyId_t updatingCompanyId()
|
||||
|
@ -161,15 +192,11 @@ namespace OpenLoco::CompanyManager
|
|||
int32_t companies_active = 0;
|
||||
for (const auto& company : companies())
|
||||
{
|
||||
auto id = company.id();
|
||||
if (id != _player_company[0] && id != _player_company[1])
|
||||
{
|
||||
if (!isPlayerCompany(company.id()))
|
||||
companies_active++;
|
||||
}
|
||||
}
|
||||
|
||||
auto& prng = gPrng();
|
||||
|
||||
if (prng.randNext(16) == 0)
|
||||
{
|
||||
if (prng.randNext(_company_max_competing) + 1 > companies_active)
|
||||
|
@ -190,28 +217,64 @@ namespace OpenLoco::CompanyManager
|
|||
// Returns a string between 1810 and 1816 with up to two arguments.
|
||||
string_id getOwnerStatus(CompanyId_t id, FormatArguments& args)
|
||||
{
|
||||
registers regs;
|
||||
regs.esi = X86Pointer(get(id));
|
||||
call(0x00438047, regs);
|
||||
auto& company = _companies[id];
|
||||
if (company.challenge_flags & CompanyFlags::bankrupt)
|
||||
return StringIds::company_status_bankrupt;
|
||||
|
||||
args.push(regs.ecx);
|
||||
args.push(regs.edx);
|
||||
return regs.bx;
|
||||
}
|
||||
const string_id observationStatusStrings[] = {
|
||||
StringIds::company_status_empty,
|
||||
StringIds::company_status_building_track_road,
|
||||
StringIds::company_status_building_airport,
|
||||
StringIds::company_status_building_dock,
|
||||
StringIds::company_status_checking_services,
|
||||
StringIds::company_status_surveying_landscape,
|
||||
};
|
||||
|
||||
OwnerStatus getOwnerStatus(CompanyId_t id)
|
||||
{
|
||||
registers regs;
|
||||
regs.esi = X86Pointer(get(id));
|
||||
call(0x00438047, regs);
|
||||
string_id statusString = observationStatusStrings[company.observationStatus];
|
||||
if (company.observationStatus == ObservationStatus::empty || company.observationTownId == 0xFFFF)
|
||||
return StringIds::company_status_empty;
|
||||
|
||||
OwnerStatus ownerStatus;
|
||||
switch (company.observationStatus)
|
||||
{
|
||||
case ObservationStatus::buildingTrackRoad:
|
||||
if (company.observationObject & 0x80)
|
||||
{
|
||||
auto* obj = ObjectManager::get<RoadObject>(company.observationObject & 0xFF7F);
|
||||
if (obj != nullptr)
|
||||
args.push(obj->name);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto* obj = ObjectManager::get<TrackObject>(company.observationObject);
|
||||
if (obj != nullptr)
|
||||
args.push(obj->name);
|
||||
}
|
||||
break;
|
||||
|
||||
ownerStatus.string = regs.bx;
|
||||
ownerStatus.argument1 = regs.ecx;
|
||||
ownerStatus.argument2 = regs.edx;
|
||||
case ObservationStatus::buildingAirport:
|
||||
{
|
||||
auto* obj = ObjectManager::get<AirportObject>(company.observationObject);
|
||||
if (obj != nullptr)
|
||||
args.push(obj->name);
|
||||
break;
|
||||
}
|
||||
|
||||
return ownerStatus;
|
||||
case ObservationStatus::buildingDock:
|
||||
{
|
||||
auto* obj = ObjectManager::get<DockObject>(company.observationObject);
|
||||
if (obj != nullptr)
|
||||
args.push(obj->name);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
auto* town = TownManager::get(company.observationTownId);
|
||||
args.push(town->name);
|
||||
|
||||
return statusString;
|
||||
}
|
||||
|
||||
// 0x004383ED
|
||||
|
|
|
@ -29,16 +29,8 @@ namespace OpenLoco::CompanyManager
|
|||
void determineAvailableVehicles();
|
||||
currency32_t calculateDeliveredCargoPayment(uint8_t cargoItem, int32_t numUnits, int32_t distance, uint16_t numDays);
|
||||
|
||||
struct OwnerStatus
|
||||
{
|
||||
string_id string;
|
||||
uint32_t argument1;
|
||||
uint32_t argument2;
|
||||
};
|
||||
|
||||
Company* getOpponent();
|
||||
string_id getOwnerStatus(CompanyId_t id, FormatArguments& args);
|
||||
OwnerStatus getOwnerStatus(CompanyId_t id);
|
||||
void updateOwnerStatus();
|
||||
void updateColours();
|
||||
|
||||
|
|
|
@ -66,6 +66,11 @@ namespace OpenLoco
|
|||
_buffer = nextOffset;
|
||||
}
|
||||
|
||||
void rewind()
|
||||
{
|
||||
_buffer = _bufferStart;
|
||||
}
|
||||
|
||||
const void* operator&()
|
||||
{
|
||||
return _bufferStart;
|
||||
|
|
|
@ -1366,7 +1366,13 @@ namespace OpenLoco::StringIds
|
|||
constexpr string_id map_key_vegetation = 1807;
|
||||
constexpr string_id map_routes_aircraft = 1808;
|
||||
constexpr string_id map_routes_ships = 1809;
|
||||
|
||||
constexpr string_id company_status_empty = 1810;
|
||||
constexpr string_id company_status_building_track_road = 1811;
|
||||
constexpr string_id company_status_building_airport = 1812;
|
||||
constexpr string_id company_status_building_dock = 1813;
|
||||
constexpr string_id company_status_checking_services = 1814;
|
||||
constexpr string_id company_status_surveying_landscape = 1815;
|
||||
constexpr string_id company_status_bankrupt = 1816;
|
||||
constexpr string_id tooltip_speed_pause = 1817;
|
||||
constexpr string_id tooltip_speed_normal = 1818;
|
||||
constexpr string_id tooltip_speed_fast_forward = 1819;
|
||||
|
|
|
@ -495,12 +495,11 @@ namespace OpenLoco::Ui::Windows::CompanyList
|
|||
}
|
||||
|
||||
{
|
||||
|
||||
auto args = FormatArguments();
|
||||
CompanyManager::OwnerStatus ownerStatus = CompanyManager::getOwnerStatus(company->id());
|
||||
args.push(ownerStatus.string);
|
||||
args.push(ownerStatus.argument1);
|
||||
args.push(ownerStatus.argument2);
|
||||
args.skip(sizeof(string_id));
|
||||
string_id ownerStatus = CompanyManager::getOwnerStatus(company->id(), args);
|
||||
args.rewind();
|
||||
args.push(ownerStatus);
|
||||
|
||||
Gfx::drawString_494BBF(context, 175, yBottom + 7, 208, Colour::black, stringId, &args);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue