-
Notifications
You must be signed in to change notification settings - Fork 149
/
CompetitorObject.cpp
112 lines (98 loc) · 3.66 KB
/
CompetitorObject.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "CompetitorObject.h"
#include "Drawing/SoftwareDrawingEngine.h"
#include "Graphics/Colour.h"
#include "Graphics/Gfx.h"
#include "Interop/Interop.hpp"
#include "Localisation/FormatArguments.hpp"
#include "Localisation/StringIds.h"
namespace OpenLoco
{
// TODO: Should only be defined in ObjectSelectionWindow
static constexpr uint8_t kDescriptionRowHeight = 10;
static constexpr Ui::Size kObjectPreviewSize = { 112, 112 };
// 0x00434D5B
void CompetitorObject::drawPreviewImage(Gfx::RenderTarget& rt, const int16_t x, const int16_t y) const
{
auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext();
drawingCtx.drawRect(rt, 0, 0, kObjectPreviewSize.width, kObjectPreviewSize.height, AdvancedColour(Colour::mutedOrange).inset().u8());
auto image = Gfx::recolour(images[0], Colour::mutedSeaGreen);
drawingCtx.drawImage(&rt, x - 32, y - 32, image);
}
// 0x00434DA7
void CompetitorObject::drawDescription(Gfx::RenderTarget& rt, const int16_t x, const int16_t y, [[maybe_unused]] const int16_t width) const
{
auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext();
Ui::Point rowPosition = { x, y };
{
auto args = FormatArguments();
args.push<uint16_t>(intelligence);
args.push(aiRatingToLevel(intelligence));
drawingCtx.drawStringLeft(rt, rowPosition.x, rowPosition.y, Colour::black, StringIds::company_details_intelligence, &args);
rowPosition.y += kDescriptionRowHeight;
}
{
auto args = FormatArguments();
args.push<uint16_t>(aggressiveness);
args.push(aiRatingToLevel(aggressiveness));
drawingCtx.drawStringLeft(rt, rowPosition.x, rowPosition.y, Colour::black, StringIds::company_details_aggressiveness, &args);
rowPosition.y += kDescriptionRowHeight;
}
{
auto args = FormatArguments();
args.push<uint16_t>(competitiveness);
args.push(aiRatingToLevel(competitiveness));
drawingCtx.drawStringLeft(rt, rowPosition.x, rowPosition.y, Colour::black, StringIds::company_details_competitiveness, &args);
}
}
// 0x00434D24
bool CompetitorObject::validate() const
{
if (!(emotions & (1 << 0)))
{
return false;
}
if (intelligence < 1 || intelligence > 9)
{
return false;
}
if (aggressiveness < 1 || aggressiveness > 9)
{
return false;
}
return competitiveness >= 1 && competitiveness <= 9;
}
// 0x00434CA0
void CompetitorObject::load(const LoadedObjectHandle& handle, stdx::span<const std::byte> data, ObjectManager::DependentObjects*)
{
Interop::registers regs;
regs.esi = Interop::X86Pointer(this);
regs.ebx = handle.id;
regs.ecx = enumValue(handle.type);
Interop::call(0x00434CA0, regs);
}
// 0x00434D08
void CompetitorObject::unload()
{
var_00 = 0;
var_02 = 0;
std::fill(std::begin(images), std::end(images), 0);
}
static std::array<string_id, 10> aiRatingToLevelArray = {
{
StringIds::low,
StringIds::low,
StringIds::low,
StringIds::low,
StringIds::medium,
StringIds::medium,
StringIds::medium,
StringIds::high,
StringIds::high,
StringIds::high,
}
};
[[nodiscard]] string_id aiRatingToLevel(const uint8_t rating)
{
return aiRatingToLevelArray[std::min(rating, static_cast<uint8_t>(aiRatingToLevelArray.size()))];
}
}