Update to 1.11.0-beta1
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include "company_base.h"
|
||||
#include "company_func.h"
|
||||
#include "company_gui.h"
|
||||
#include "core/backup_type.hpp"
|
||||
#include "town.h"
|
||||
#include "news_func.h"
|
||||
#include "cmd_helper.h"
|
||||
@@ -208,7 +209,7 @@ bool CheckCompanyHasMoney(CommandCost &cost)
|
||||
* @param c Company to pay the bill.
|
||||
* @param cost Money to pay.
|
||||
*/
|
||||
static void SubtractMoneyFromAnyCompany(Company *c, CommandCost cost)
|
||||
static void SubtractMoneyFromAnyCompany(Company *c, const CommandCost &cost)
|
||||
{
|
||||
if (cost.GetCost() == 0) return;
|
||||
assert(cost.GetExpensesType() != INVALID_EXPENSES);
|
||||
@@ -237,7 +238,7 @@ static void SubtractMoneyFromAnyCompany(Company *c, CommandCost cost)
|
||||
* Subtract money from the #_current_company, if the company is valid.
|
||||
* @param cost Money to pay.
|
||||
*/
|
||||
void SubtractMoneyFromCompany(CommandCost cost)
|
||||
void SubtractMoneyFromCompany(const CommandCost &cost)
|
||||
{
|
||||
Company *c = Company::GetIfValid(_current_company);
|
||||
if (c != nullptr) SubtractMoneyFromAnyCompany(c, cost);
|
||||
@@ -248,7 +249,7 @@ void SubtractMoneyFromCompany(CommandCost cost)
|
||||
* @param company Company paying the bill.
|
||||
* @param cst Cost of a command.
|
||||
*/
|
||||
void SubtractMoneyFromCompanyFract(CompanyID company, CommandCost cst)
|
||||
void SubtractMoneyFromCompanyFract(CompanyID company, const CommandCost &cst)
|
||||
{
|
||||
Company *c = Company::Get(company);
|
||||
byte m = c->money_fraction;
|
||||
@@ -264,9 +265,9 @@ void SubtractMoneyFromCompanyFract(CompanyID company, CommandCost cst)
|
||||
void UpdateLandscapingLimits()
|
||||
{
|
||||
for (Company *c : Company::Iterate()) {
|
||||
c->terraform_limit = min(c->terraform_limit + _settings_game.construction.terraform_per_64k_frames, (uint32)_settings_game.construction.terraform_frame_burst << 16);
|
||||
c->clear_limit = min(c->clear_limit + _settings_game.construction.clear_per_64k_frames, (uint32)_settings_game.construction.clear_frame_burst << 16);
|
||||
c->tree_limit = min(c->tree_limit + _settings_game.construction.tree_per_64k_frames, (uint32)_settings_game.construction.tree_frame_burst << 16);
|
||||
c->terraform_limit = std::min<uint32>(c->terraform_limit + _settings_game.construction.terraform_per_64k_frames, _settings_game.construction.terraform_frame_burst << 16);
|
||||
c->clear_limit = std::min<uint32>(c->clear_limit + _settings_game.construction.clear_per_64k_frames, _settings_game.construction.clear_frame_burst << 16);
|
||||
c->tree_limit = std::min<uint32>(c->tree_limit + _settings_game.construction.tree_per_64k_frames, _settings_game.construction.tree_frame_burst << 16);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -353,7 +354,7 @@ static void GenerateCompanyName(Company *c)
|
||||
|
||||
StringID str;
|
||||
uint32 strp;
|
||||
if (t->name == nullptr && IsInsideMM(t->townnametype, SPECSTR_TOWNNAME_START, SPECSTR_TOWNNAME_LAST + 1)) {
|
||||
if (t->name.empty() && IsInsideMM(t->townnametype, SPECSTR_TOWNNAME_START, SPECSTR_TOWNNAME_LAST + 1)) {
|
||||
str = t->townnametype - SPECSTR_TOWNNAME_START + SPECSTR_COMPANY_NAME_START;
|
||||
strp = t->townnameparts;
|
||||
|
||||
@@ -553,7 +554,7 @@ Company *DoStartupNewCompany(bool is_ai, CompanyID company = INVALID_COMPANY)
|
||||
ResetCompanyLivery(c);
|
||||
_company_colours[c->index] = (Colours)c->colour;
|
||||
|
||||
c->money = c->current_loan = (100000ll * _economy.inflation_prices >> 16) / 50000 * 50000;
|
||||
c->money = c->current_loan = (std::min<int64>(INITIAL_LOAN, _economy.max_loan) * _economy.inflation_prices >> 16) / 50000 * 50000;
|
||||
|
||||
c->share_owners[0] = c->share_owners[1] = c->share_owners[2] = c->share_owners[3] = INVALID_OWNER;
|
||||
|
||||
@@ -707,7 +708,7 @@ void OnTick_Companies()
|
||||
|
||||
if (_next_competitor_start == 0) {
|
||||
/* AI::GetStartNextTime() can return 0. */
|
||||
_next_competitor_start = max(1, AI::GetStartNextTime() * DAY_TICKS);
|
||||
_next_competitor_start = std::max(1, AI::GetStartNextTime() * DAY_TICKS);
|
||||
}
|
||||
|
||||
if (_game_mode != GM_MENU && AI::CanStartNew() && --_next_competitor_start == 0) {
|
||||
@@ -1043,7 +1044,7 @@ CommandCost CmdSetCompanyColour(TileIndex tile, DoCommandFlag flags, uint32 p1,
|
||||
static bool IsUniqueCompanyName(const char *name)
|
||||
{
|
||||
for (const Company *c : Company::Iterate()) {
|
||||
if (c->name != nullptr && strcmp(c->name, name) == 0) return false;
|
||||
if (!c->name.empty() && c->name == name) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -1069,8 +1070,11 @@ CommandCost CmdRenameCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
Company *c = Company::Get(_current_company);
|
||||
free(c->name);
|
||||
c->name = reset ? nullptr : stredup(text);
|
||||
if (reset) {
|
||||
c->name.clear();
|
||||
} else {
|
||||
c->name = text;
|
||||
}
|
||||
MarkWholeScreenDirty();
|
||||
CompanyAdminUpdate(c);
|
||||
}
|
||||
@@ -1086,7 +1090,7 @@ CommandCost CmdRenameCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
|
||||
static bool IsUniquePresidentName(const char *name)
|
||||
{
|
||||
for (const Company *c : Company::Iterate()) {
|
||||
if (c->president_name != nullptr && strcmp(c->president_name, name) == 0) return false;
|
||||
if (!c->president_name.empty() && c->president_name == name) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -1112,14 +1116,13 @@ CommandCost CmdRenamePresident(TileIndex tile, DoCommandFlag flags, uint32 p1, u
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
Company *c = Company::Get(_current_company);
|
||||
free(c->president_name);
|
||||
|
||||
if (reset) {
|
||||
c->president_name = nullptr;
|
||||
c->president_name.clear();
|
||||
} else {
|
||||
c->president_name = stredup(text);
|
||||
c->president_name = text;
|
||||
|
||||
if (c->name_1 == STR_SV_UNNAMED && c->name == nullptr) {
|
||||
if (c->name_1 == STR_SV_UNNAMED && c->name.empty()) {
|
||||
char buf[80];
|
||||
|
||||
seprintf(buf, lastof(buf), "%s Transport", text);
|
||||
@@ -1177,3 +1180,50 @@ uint32 CompanyInfrastructure::GetTramTotal() const
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transfer funds (money) from one company to another.
|
||||
* To prevent abuse in multiplayer games you can only send money to other
|
||||
* companies if you have paid off your loan (either explicitly, or implicitly
|
||||
* given the fact that you have more money than loan).
|
||||
* @param tile unused
|
||||
* @param flags operation to perform
|
||||
* @param p1 the amount of money to transfer; max 20.000.000
|
||||
* @param p2 the company to transfer the money to
|
||||
* @param text unused
|
||||
* @return the cost of this operation or an error
|
||||
*/
|
||||
CommandCost CmdGiveMoney(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||
{
|
||||
if (!_settings_game.economy.give_money) return CMD_ERROR;
|
||||
|
||||
const Company *c = Company::Get(_current_company);
|
||||
CommandCost amount(EXPENSES_OTHER, std::min<Money>(p1, 20000000LL));
|
||||
CompanyID dest_company = (CompanyID)p2;
|
||||
|
||||
/* You can only transfer funds that is in excess of your loan */
|
||||
if (c->money - c->current_loan < amount.GetCost() || amount.GetCost() < 0) return_cmd_error(STR_ERROR_INSUFFICIENT_FUNDS);
|
||||
if (!Company::IsValidID(dest_company)) return CMD_ERROR;
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
/* Add money to company */
|
||||
Backup<CompanyID> cur_company(_current_company, dest_company, FILE_LINE);
|
||||
SubtractMoneyFromCompany(CommandCost(EXPENSES_OTHER, -amount.GetCost()));
|
||||
cur_company.Restore();
|
||||
|
||||
if (_networking) {
|
||||
char dest_company_name[MAX_LENGTH_COMPANY_NAME_CHARS * MAX_CHAR_LENGTH];
|
||||
SetDParam(0, dest_company);
|
||||
GetString(dest_company_name, STR_COMPANY_NAME, lastof(dest_company_name));
|
||||
|
||||
char from_company_name[MAX_LENGTH_COMPANY_NAME_CHARS * MAX_CHAR_LENGTH];
|
||||
SetDParam(0, _current_company);
|
||||
GetString(from_company_name, STR_COMPANY_NAME, lastof(from_company_name));
|
||||
|
||||
NetworkTextMessage(NETWORK_ACTION_GIVE_MONEY, GetDrawStringCompanyColour(_current_company), false, from_company_name, dest_company_name, amount.GetCost());
|
||||
}
|
||||
}
|
||||
|
||||
/* Subtract money from local-company */
|
||||
return amount;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user