Refactor company properties
This commit is contained in:
parent
a0152c5158
commit
02141827ff
|
@ -0,0 +1,21 @@
|
||||||
|
#include "company.h"
|
||||||
|
#include "interop/interop.hpp"
|
||||||
|
#include <algorithm>
|
||||||
|
#include <array>
|
||||||
|
|
||||||
|
using namespace openloco::interop;
|
||||||
|
|
||||||
|
namespace openloco
|
||||||
|
{
|
||||||
|
static loco_global_array<company_id_t, 2, 0x00525E3C> _player_company[2];
|
||||||
|
|
||||||
|
bool is_player_company(company_id_t id)
|
||||||
|
{
|
||||||
|
auto& player_company = *((std::array<company_id_t, 2>*)_player_company->get());
|
||||||
|
auto findResult = std::find(
|
||||||
|
player_company.begin(),
|
||||||
|
player_company.end(),
|
||||||
|
id);
|
||||||
|
return findResult != player_company.end();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
|
namespace openloco
|
||||||
|
{
|
||||||
|
using company_id_t = uint8_t;
|
||||||
|
|
||||||
|
namespace company_id
|
||||||
|
{
|
||||||
|
constexpr company_id_t null = std::numeric_limits<company_id_t>::max();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_player_company(company_id_t id);
|
||||||
|
}
|
|
@ -15,6 +15,7 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="audio\audio.cpp" />
|
<ClCompile Include="audio\audio.cpp" />
|
||||||
|
<ClCompile Include="company.cpp" />
|
||||||
<ClCompile Include="config.cpp" />
|
<ClCompile Include="config.cpp" />
|
||||||
<ClCompile Include="console.cpp" />
|
<ClCompile Include="console.cpp" />
|
||||||
<ClCompile Include="date.cpp" />
|
<ClCompile Include="date.cpp" />
|
||||||
|
@ -54,6 +55,7 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="audio\audio.h" />
|
<ClInclude Include="audio\audio.h" />
|
||||||
|
<ClInclude Include="company.h" />
|
||||||
<ClInclude Include="config.h" />
|
<ClInclude Include="config.h" />
|
||||||
<ClInclude Include="console.h" />
|
<ClInclude Include="console.h" />
|
||||||
<ClInclude Include="date.h" />
|
<ClInclude Include="date.h" />
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "station.h"
|
#include "station.h"
|
||||||
|
#include "company.h"
|
||||||
#include "interop/interop.hpp"
|
#include "interop/interop.hpp"
|
||||||
#include "openloco.h"
|
#include "openloco.h"
|
||||||
#include "windowmgr.h"
|
#include "windowmgr.h"
|
||||||
|
@ -140,7 +141,7 @@ namespace openloco
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (var_2A != 384 && var_28 != addr<0x00525E3C, uint8_t>() && var_28 != addr<0x00525E3D, uint8_t>())
|
if (var_2A != 384 && is_player_company(company))
|
||||||
{
|
{
|
||||||
rating += 120;
|
rating += 120;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ namespace openloco
|
||||||
{
|
{
|
||||||
string_id name; // 0x00
|
string_id name; // 0x00
|
||||||
uint8_t pad_02[0x28 - 0x02];
|
uint8_t pad_02[0x28 - 0x02];
|
||||||
uint8_t var_28;
|
uint8_t company; // 0x28
|
||||||
uint8_t var_29;
|
uint8_t var_29;
|
||||||
uint16_t var_2A;
|
uint16_t var_2A;
|
||||||
town_id_t town; // 0x2C
|
town_id_t town; // 0x2C
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "stationmgr.h"
|
#include "stationmgr.h"
|
||||||
|
#include "company.h"
|
||||||
#include "interop/interop.hpp"
|
#include "interop/interop.hpp"
|
||||||
#include "townmgr.h"
|
#include "townmgr.h"
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
@ -55,15 +56,9 @@ namespace openloco::stationmgr
|
||||||
if (station.var_1CE == 0)
|
if (station.var_1CE == 0)
|
||||||
{
|
{
|
||||||
station.var_29++;
|
station.var_29++;
|
||||||
if (station.var_29 != 5)
|
if (station.var_29 != 5 && is_player_company(station.company))
|
||||||
{
|
{
|
||||||
// clang-format off
|
sub_437F29(station.company, 8);
|
||||||
if (station.var_28 == addr<0x00525E3C, uint8_t>() ||
|
|
||||||
station.var_28 == addr<0x00525E3D, uint8_t>())
|
|
||||||
// clang-format on
|
|
||||||
{
|
|
||||||
sub_437F29(station.var_28, 8);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (station.var_29 >= 10)
|
if (station.var_29 >= 10)
|
||||||
{
|
{
|
||||||
|
@ -82,11 +77,7 @@ namespace openloco::stationmgr
|
||||||
if (town != nullptr && !(town->var_06 & town_flags::flag_1))
|
if (town != nullptr && !(town->var_06 & town_flags::flag_1))
|
||||||
{
|
{
|
||||||
town->var_06 |= town_flags::flag_1;
|
town->var_06 |= town_flags::flag_1;
|
||||||
town->var_58 |= (1 << station.var_28);
|
town->adjust_company_rating(station.company, 1);
|
||||||
if (town->var_3A[station.var_28] < 1000)
|
|
||||||
{
|
|
||||||
town->var_3A[station.var_28]++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,22 @@
|
||||||
#include "town.h"
|
#include "town.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
namespace openloco
|
namespace openloco
|
||||||
{
|
{
|
||||||
|
constexpr int32_t min_company_rating = -1000;
|
||||||
|
constexpr int32_t max_company_rating = 1000;
|
||||||
|
|
||||||
bool town::empty() const
|
bool town::empty() const
|
||||||
{
|
{
|
||||||
return var_00 != -1;
|
return var_00 != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void town::adjust_company_rating(company_id_t cid, int amount)
|
||||||
|
{
|
||||||
|
companies_with_rating |= (1 << cid);
|
||||||
|
company_ratings[cid] = std::clamp(
|
||||||
|
company_ratings[cid] + amount,
|
||||||
|
min_company_rating,
|
||||||
|
max_company_rating);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "company.h"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
|
@ -24,12 +25,12 @@ namespace openloco
|
||||||
uint8_t pad_02[0x06 - 0x02];
|
uint8_t pad_02[0x06 - 0x02];
|
||||||
uint16_t var_06;
|
uint16_t var_06;
|
||||||
uint8_t pad_08[0x3A - 0x08];
|
uint8_t pad_08[0x3A - 0x08];
|
||||||
int16_t var_3A[8]; // guess?
|
int16_t company_ratings[15]; // 0x3A
|
||||||
uint8_t pad_42[0x58 - 0x42];
|
uint16_t companies_with_rating; // 0x58
|
||||||
uint16_t var_58;
|
|
||||||
uint8_t pad_5A[0x270 - 0x5A];
|
uint8_t pad_5A[0x270 - 0x5A];
|
||||||
|
|
||||||
bool empty() const;
|
bool empty() const;
|
||||||
|
void adjust_company_rating(company_id_t cid, int amount);
|
||||||
};
|
};
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue