OpenLoco/src/openloco/Town.cpp

52 lines
1.3 KiB
C++
Raw Normal View History

2020-09-07 07:42:02 +02:00
#include "Town.h"
#include "interop/interop.hpp"
#include "localisation/string_ids.h"
2018-01-25 20:03:46 +01:00
#include <algorithm>
2018-01-25 00:24:16 +01:00
using namespace openloco::interop;
2018-01-25 00:24:16 +01:00
namespace openloco
{
2018-01-25 20:03:46 +01:00
constexpr int32_t min_company_rating = -1000;
constexpr int32_t max_company_rating = 1000;
2018-01-25 00:24:16 +01:00
bool town::empty() const
{
2018-01-27 00:01:23 +01:00
return name == string_ids::null;
2018-01-25 00:24:16 +01:00
}
2018-01-25 20:03:46 +01:00
// 0x0049742F
void town::update()
{
registers regs;
regs.esi = (int32_t)this;
call(0x0049742F, regs);
}
void town::adjustCompanyRating(company_id_t cid, int amount)
2018-01-25 20:03:46 +01:00
{
companies_with_rating |= (1 << cid);
company_ratings[cid] = std::clamp(
company_ratings[cid] + amount,
min_company_rating,
max_company_rating);
}
string_id town::getTownSizeString() const
{
static string_id townSizeNames[5] = {
string_ids::town_size_hamlet,
string_ids::town_size_village,
string_ids::town_size_town,
string_ids::town_size_city,
string_ids::town_size_metropolis
};
if (static_cast<uint8_t>(size) < std::size(townSizeNames))
{
return townSizeNames[static_cast<uint8_t>(size)];
}
return string_ids::town_size_hamlet;
}
2018-01-25 00:24:16 +01:00
}