2009-01-12 17:11:45 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
/** @file script_town.cpp Implementation of ScriptTown. */
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2011-01-22 10:33:16 +00:00
|
|
|
#include "../../stdafx.h"
|
2011-11-29 23:07:38 +00:00
|
|
|
#include "script_town.hpp"
|
|
|
|
#include "script_map.hpp"
|
|
|
|
#include "script_error.hpp"
|
2009-01-12 17:11:45 +00:00
|
|
|
#include "../../town.h"
|
2013-09-19 18:48:05 +00:00
|
|
|
#include "../../townname_func.h"
|
2012-01-08 21:48:05 +00:00
|
|
|
#include "../../string_func.h"
|
2009-01-12 17:11:45 +00:00
|
|
|
#include "../../strings_func.h"
|
|
|
|
#include "../../station_base.h"
|
2011-11-23 16:09:46 +00:00
|
|
|
#include "../../landscape.h"
|
2009-01-12 17:11:45 +00:00
|
|
|
#include "table/strings.h"
|
|
|
|
|
2014-04-23 20:13:33 +00:00
|
|
|
#include "../../safeguards.h"
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
/* static */ int32 ScriptTown::GetTownCount()
|
2009-01-12 17:11:45 +00:00
|
|
|
{
|
2009-05-22 15:23:47 +00:00
|
|
|
return (int32)::Town::GetNumItems();
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
/* static */ bool ScriptTown::IsValidTown(TownID town_id)
|
2009-01-12 17:11:45 +00:00
|
|
|
{
|
2009-05-17 01:00:56 +00:00
|
|
|
return ::Town::IsValidID(town_id);
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
/* static */ char *ScriptTown::GetName(TownID town_id)
|
2009-01-12 17:11:45 +00:00
|
|
|
{
|
|
|
|
if (!IsValidTown(town_id)) return NULL;
|
|
|
|
|
|
|
|
::SetDParam(0, town_id);
|
2012-01-08 21:48:05 +00:00
|
|
|
return GetString(STR_TOWN_NAME);
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
|
|
|
|
2013-09-19 18:48:05 +00:00
|
|
|
/* static */ bool ScriptTown::SetName(TownID town_id, Text *name)
|
|
|
|
{
|
|
|
|
CCountedPtr<Text> counter(name);
|
|
|
|
|
|
|
|
const char *text = NULL;
|
|
|
|
if (name != NULL) {
|
2013-11-14 18:04:31 +00:00
|
|
|
text = name->GetDecodedText();
|
2013-09-19 18:48:05 +00:00
|
|
|
EnforcePreconditionEncodedText(false, text);
|
|
|
|
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_TOWN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
|
|
|
|
}
|
|
|
|
EnforcePrecondition(false, IsValidTown(town_id));
|
|
|
|
|
|
|
|
return ScriptObject::DoCommand(0, town_id, 0, CMD_RENAME_TOWN, text);
|
|
|
|
}
|
|
|
|
|
2011-12-19 21:06:06 +00:00
|
|
|
/* static */ bool ScriptTown::SetText(TownID town_id, Text *text)
|
2011-12-19 21:00:55 +00:00
|
|
|
{
|
2011-12-19 21:06:06 +00:00
|
|
|
CCountedPtr<Text> counter(text);
|
|
|
|
|
|
|
|
EnforcePrecondition(false, text != NULL);
|
2013-06-30 15:59:10 +00:00
|
|
|
const char *encoded_text = text->GetEncodedText();
|
2013-02-08 20:34:27 +00:00
|
|
|
EnforcePreconditionEncodedText(false, encoded_text);
|
2011-12-19 21:00:55 +00:00
|
|
|
EnforcePrecondition(false, IsValidTown(town_id));
|
2011-12-19 21:06:06 +00:00
|
|
|
|
2013-02-08 20:34:27 +00:00
|
|
|
return ScriptObject::DoCommand(::Town::Get(town_id)->xy, town_id, 0, CMD_TOWN_SET_TEXT, encoded_text);
|
2011-12-19 21:00:55 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
/* static */ int32 ScriptTown::GetPopulation(TownID town_id)
|
2009-01-12 17:11:45 +00:00
|
|
|
{
|
|
|
|
if (!IsValidTown(town_id)) return -1;
|
2009-05-16 23:34:14 +00:00
|
|
|
const Town *t = ::Town::Get(town_id);
|
2012-04-25 20:50:13 +00:00
|
|
|
return t->cache.population;
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
/* static */ int32 ScriptTown::GetHouseCount(TownID town_id)
|
2009-01-12 17:11:45 +00:00
|
|
|
{
|
|
|
|
if (!IsValidTown(town_id)) return -1;
|
2009-05-16 23:34:14 +00:00
|
|
|
const Town *t = ::Town::Get(town_id);
|
2012-04-25 20:50:13 +00:00
|
|
|
return t->cache.num_houses;
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
/* static */ TileIndex ScriptTown::GetLocation(TownID town_id)
|
2009-01-12 17:11:45 +00:00
|
|
|
{
|
|
|
|
if (!IsValidTown(town_id)) return INVALID_TILE;
|
2009-05-16 23:34:14 +00:00
|
|
|
const Town *t = ::Town::Get(town_id);
|
2009-01-12 17:11:45 +00:00
|
|
|
return t->xy;
|
|
|
|
}
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
/* static */ int32 ScriptTown::GetLastMonthProduction(TownID town_id, CargoID cargo_id)
|
2009-01-12 17:11:45 +00:00
|
|
|
{
|
|
|
|
if (!IsValidTown(town_id)) return -1;
|
2011-11-29 23:15:35 +00:00
|
|
|
if (!ScriptCargo::IsValidCargo(cargo_id)) return -1;
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2009-05-16 23:34:14 +00:00
|
|
|
const Town *t = ::Town::Get(town_id);
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2011-11-23 16:05:19 +00:00
|
|
|
return t->supplied[cargo_id].old_max;
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
/* static */ int32 ScriptTown::GetLastMonthSupplied(TownID town_id, CargoID cargo_id)
|
2009-01-12 17:11:45 +00:00
|
|
|
{
|
|
|
|
if (!IsValidTown(town_id)) return -1;
|
2011-11-29 23:15:35 +00:00
|
|
|
if (!ScriptCargo::IsValidCargo(cargo_id)) return -1;
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2009-05-16 23:34:14 +00:00
|
|
|
const Town *t = ::Town::Get(town_id);
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2011-11-23 16:05:19 +00:00
|
|
|
return t->supplied[cargo_id].old_act;
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
/* static */ int32 ScriptTown::GetLastMonthTransportedPercentage(TownID town_id, CargoID cargo_id)
|
2009-08-27 13:50:07 +00:00
|
|
|
{
|
|
|
|
if (!IsValidTown(town_id)) return -1;
|
2011-11-29 23:15:35 +00:00
|
|
|
if (!ScriptCargo::IsValidCargo(cargo_id)) return -1;
|
2009-08-27 13:50:07 +00:00
|
|
|
|
2011-11-23 16:05:19 +00:00
|
|
|
const Town *t = ::Town::Get(town_id);
|
|
|
|
return ::ToPercent8(t->GetPercentTransported(cargo_id));
|
|
|
|
}
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
/* static */ int32 ScriptTown::GetLastMonthReceived(TownID town_id, ScriptCargo::TownEffect towneffect_id)
|
2011-11-23 16:05:19 +00:00
|
|
|
{
|
|
|
|
if (!IsValidTown(town_id)) return -1;
|
2011-11-29 23:15:35 +00:00
|
|
|
if (!ScriptCargo::IsValidTownEffect(towneffect_id)) return -1;
|
2011-11-23 16:05:19 +00:00
|
|
|
|
2009-08-27 13:50:07 +00:00
|
|
|
const Town *t = ::Town::Get(town_id);
|
|
|
|
|
2011-11-23 16:05:19 +00:00
|
|
|
return t->received[towneffect_id].old_act;
|
2009-08-27 13:50:07 +00:00
|
|
|
}
|
|
|
|
|
2011-12-19 20:59:19 +00:00
|
|
|
/* static */ bool ScriptTown::SetCargoGoal(TownID town_id, ScriptCargo::TownEffect towneffect_id, uint32 goal)
|
|
|
|
{
|
|
|
|
EnforcePrecondition(false, IsValidTown(town_id));
|
|
|
|
EnforcePrecondition(false, ScriptCargo::IsValidTownEffect(towneffect_id));
|
|
|
|
|
|
|
|
return ScriptObject::DoCommand(::Town::Get(town_id)->xy, town_id | (towneffect_id << 16), goal, CMD_TOWN_CARGO_GOAL);
|
|
|
|
}
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
/* static */ uint32 ScriptTown::GetCargoGoal(TownID town_id, ScriptCargo::TownEffect towneffect_id)
|
2011-11-23 16:09:46 +00:00
|
|
|
{
|
2013-08-10 12:47:13 +00:00
|
|
|
if (!IsValidTown(town_id)) return UINT32_MAX;
|
|
|
|
if (!ScriptCargo::IsValidTownEffect(towneffect_id)) return UINT32_MAX;
|
2011-11-23 16:09:46 +00:00
|
|
|
|
|
|
|
const Town *t = ::Town::Get(town_id);
|
|
|
|
|
|
|
|
switch (t->goal[towneffect_id]) {
|
|
|
|
case TOWN_GROWTH_WINTER:
|
2012-04-25 20:50:13 +00:00
|
|
|
if (TileHeight(t->xy) >= GetSnowLine() && t->cache.population > 90) return 1;
|
2011-11-23 16:09:46 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case TOWN_GROWTH_DESERT:
|
2012-04-25 20:50:13 +00:00
|
|
|
if (GetTropicZone(t->xy) == TROPICZONE_DESERT && t->cache.population > 60) return 1;
|
2011-11-23 16:09:46 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
default: return t->goal[towneffect_id];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-12 15:15:02 +00:00
|
|
|
/* static */ bool ScriptTown::SetGrowthRate(TownID town_id, uint32 days_between_town_growth)
|
2011-12-19 20:59:19 +00:00
|
|
|
{
|
|
|
|
EnforcePrecondition(false, IsValidTown(town_id));
|
2018-05-02 19:01:30 +00:00
|
|
|
uint16 growth_rate;
|
2013-11-12 17:56:35 +00:00
|
|
|
switch (days_between_town_growth) {
|
|
|
|
case TOWN_GROWTH_NORMAL:
|
2018-05-02 19:01:30 +00:00
|
|
|
growth_rate = 0;
|
2013-11-12 17:56:35 +00:00
|
|
|
break;
|
|
|
|
|
2013-11-12 17:57:12 +00:00
|
|
|
case TOWN_GROWTH_NONE:
|
2018-05-02 19:01:30 +00:00
|
|
|
growth_rate = TOWN_GROWTH_RATE_NONE;
|
2013-11-12 17:57:12 +00:00
|
|
|
break;
|
|
|
|
|
2013-11-12 17:56:35 +00:00
|
|
|
default:
|
2019-01-28 16:16:19 +00:00
|
|
|
EnforcePrecondition(false, (days_between_town_growth * DAY_TICKS / TOWN_GROWTH_TICKS) <= MAX_TOWN_GROWTH_TICKS);
|
2018-05-02 19:01:30 +00:00
|
|
|
/* Don't use growth_rate 0 as it means GROWTH_NORMAL */
|
|
|
|
growth_rate = max(days_between_town_growth * DAY_TICKS, 2u) - 1;
|
2013-11-12 17:56:35 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-12-19 20:59:19 +00:00
|
|
|
|
2018-05-02 19:01:30 +00:00
|
|
|
return ScriptObject::DoCommand(::Town::Get(town_id)->xy, town_id, growth_rate, CMD_TOWN_GROWTH_RATE);
|
2011-12-19 20:59:19 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
/* static */ int32 ScriptTown::GetGrowthRate(TownID town_id)
|
2011-11-23 16:09:46 +00:00
|
|
|
{
|
2013-10-28 11:09:02 +00:00
|
|
|
if (!IsValidTown(town_id)) return -1;
|
2011-11-23 16:09:46 +00:00
|
|
|
|
|
|
|
const Town *t = ::Town::Get(town_id);
|
|
|
|
|
2018-05-02 19:01:30 +00:00
|
|
|
if (t->growth_rate == TOWN_GROWTH_RATE_NONE) return TOWN_GROWTH_NONE;
|
2013-11-12 17:57:12 +00:00
|
|
|
|
2018-05-02 19:01:30 +00:00
|
|
|
return RoundDivSU(t->growth_rate + 1, DAY_TICKS);
|
2011-11-23 16:09:46 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
/* static */ int32 ScriptTown::GetDistanceManhattanToTile(TownID town_id, TileIndex tile)
|
2009-01-12 17:11:45 +00:00
|
|
|
{
|
2011-11-29 23:15:35 +00:00
|
|
|
return ScriptMap::DistanceManhattan(tile, GetLocation(town_id));
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
/* static */ int32 ScriptTown::GetDistanceSquareToTile(TownID town_id, TileIndex tile)
|
2009-01-12 17:11:45 +00:00
|
|
|
{
|
2011-11-29 23:15:35 +00:00
|
|
|
return ScriptMap::DistanceSquare(tile, GetLocation(town_id));
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
/* static */ bool ScriptTown::IsWithinTownInfluence(TownID town_id, TileIndex tile)
|
2009-01-12 17:11:45 +00:00
|
|
|
{
|
|
|
|
if (!IsValidTown(town_id)) return false;
|
|
|
|
|
2009-05-16 23:34:14 +00:00
|
|
|
const Town *t = ::Town::Get(town_id);
|
2012-04-25 20:50:13 +00:00
|
|
|
return ((uint32)GetDistanceSquareToTile(town_id, tile) <= t->cache.squared_town_zone_radius[0]);
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
/* static */ bool ScriptTown::HasStatue(TownID town_id)
|
2009-01-12 17:11:45 +00:00
|
|
|
{
|
2011-12-19 21:05:36 +00:00
|
|
|
if (ScriptObject::GetCompany() == OWNER_DEITY) return false;
|
2009-01-12 17:11:45 +00:00
|
|
|
if (!IsValidTown(town_id)) return false;
|
|
|
|
|
2011-12-19 21:05:25 +00:00
|
|
|
return ::HasBit(::Town::Get(town_id)->statues, ScriptObject::GetCompany());
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
/* static */ bool ScriptTown::IsCity(TownID town_id)
|
2010-12-29 12:19:33 +00:00
|
|
|
{
|
|
|
|
if (!IsValidTown(town_id)) return false;
|
|
|
|
|
|
|
|
return ::Town::Get(town_id)->larger_town;
|
|
|
|
}
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
/* static */ int ScriptTown::GetRoadReworkDuration(TownID town_id)
|
2009-01-12 17:11:45 +00:00
|
|
|
{
|
|
|
|
if (!IsValidTown(town_id)) return -1;
|
|
|
|
|
2009-05-16 23:34:14 +00:00
|
|
|
return ::Town::Get(town_id)->road_build_months;
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
|
|
|
|
2013-11-12 17:57:32 +00:00
|
|
|
/* static */ int ScriptTown::GetFundBuildingsDuration(TownID town_id)
|
|
|
|
{
|
|
|
|
if (!IsValidTown(town_id)) return -1;
|
|
|
|
|
|
|
|
return ::Town::Get(town_id)->fund_buildings_months;
|
|
|
|
}
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
/* static */ ScriptCompany::CompanyID ScriptTown::GetExclusiveRightsCompany(TownID town_id)
|
2009-01-12 17:11:45 +00:00
|
|
|
{
|
2011-12-19 21:05:36 +00:00
|
|
|
if (ScriptObject::GetCompany() == OWNER_DEITY) return ScriptCompany::COMPANY_INVALID;
|
2011-11-29 23:15:35 +00:00
|
|
|
if (!IsValidTown(town_id)) return ScriptCompany::COMPANY_INVALID;
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
return (ScriptCompany::CompanyID)(int8)::Town::Get(town_id)->exclusivity;
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
/* static */ int32 ScriptTown::GetExclusiveRightsDuration(TownID town_id)
|
2009-01-12 17:11:45 +00:00
|
|
|
{
|
|
|
|
if (!IsValidTown(town_id)) return -1;
|
|
|
|
|
2009-05-16 23:34:14 +00:00
|
|
|
return ::Town::Get(town_id)->exclusive_counter;
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
/* static */ bool ScriptTown::IsActionAvailable(TownID town_id, TownAction town_action)
|
2009-01-12 17:11:45 +00:00
|
|
|
{
|
2011-12-19 21:05:36 +00:00
|
|
|
if (ScriptObject::GetCompany() == OWNER_DEITY) return false;
|
2009-01-12 17:11:45 +00:00
|
|
|
if (!IsValidTown(town_id)) return false;
|
|
|
|
|
2011-12-19 21:05:25 +00:00
|
|
|
return HasBit(::GetMaskOfTownActions(NULL, ScriptObject::GetCompany(), ::Town::Get(town_id)), town_action);
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
/* static */ bool ScriptTown::PerformTownAction(TownID town_id, TownAction town_action)
|
2009-01-12 17:11:45 +00:00
|
|
|
{
|
2011-12-19 21:05:36 +00:00
|
|
|
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
|
2009-01-12 17:11:45 +00:00
|
|
|
EnforcePrecondition(false, IsValidTown(town_id));
|
|
|
|
EnforcePrecondition(false, IsActionAvailable(town_id, town_action));
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
return ScriptObject::DoCommand(::Town::Get(town_id)->xy, town_id, town_action, CMD_DO_TOWN_ACTION);
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
|
|
|
|
2011-12-19 20:57:51 +00:00
|
|
|
/* static */ bool ScriptTown::ExpandTown(TownID town_id, int houses)
|
|
|
|
{
|
2011-12-19 21:05:36 +00:00
|
|
|
EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
|
2011-12-19 20:57:51 +00:00
|
|
|
EnforcePrecondition(false, IsValidTown(town_id));
|
|
|
|
EnforcePrecondition(false, houses > 0);
|
|
|
|
|
|
|
|
return ScriptObject::DoCommand(::Town::Get(town_id)->xy, town_id, houses, CMD_EXPAND_TOWN);
|
|
|
|
}
|
|
|
|
|
2013-09-19 18:48:05 +00:00
|
|
|
/* static */ bool ScriptTown::FoundTown(TileIndex tile, TownSize size, bool city, RoadLayout layout, Text *name)
|
|
|
|
{
|
|
|
|
CCountedPtr<Text> counter(name);
|
|
|
|
|
|
|
|
EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY || _settings_game.economy.found_town != TF_FORBIDDEN);
|
|
|
|
EnforcePrecondition(false, ::IsValidTile(tile));
|
|
|
|
EnforcePrecondition(false, size == TOWN_SIZE_SMALL || size == TOWN_SIZE_MEDIUM || size == TOWN_SIZE_LARGE)
|
|
|
|
EnforcePrecondition(false, size != TOWN_SIZE_LARGE || ScriptObject::GetCompany() == OWNER_DEITY);
|
|
|
|
if (ScriptObject::GetCompany() == OWNER_DEITY || _settings_game.economy.found_town == TF_CUSTOM_LAYOUT) {
|
|
|
|
EnforcePrecondition(false, layout == ROAD_LAYOUT_ORIGINAL || layout == ROAD_LAYOUT_BETTER_ROADS || layout == ROAD_LAYOUT_2x2 || layout == ROAD_LAYOUT_3x3);
|
|
|
|
} else {
|
|
|
|
/* The layout parameter is ignored for AIs when custom layouts is disabled. */
|
|
|
|
layout = (RoadLayout) (byte)_settings_game.economy.town_layout;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *text = NULL;
|
|
|
|
if (name != NULL) {
|
|
|
|
text = name->GetDecodedText();
|
|
|
|
EnforcePreconditionEncodedText(false, text);
|
|
|
|
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_TOWN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
|
|
|
|
}
|
|
|
|
uint32 townnameparts;
|
2014-01-20 22:34:22 +00:00
|
|
|
if (!GenerateTownName(&townnameparts)) {
|
|
|
|
ScriptObject::SetLastError(ScriptError::ERR_NAME_IS_NOT_UNIQUE);
|
|
|
|
return false;
|
|
|
|
}
|
2013-09-19 18:48:05 +00:00
|
|
|
|
|
|
|
return ScriptObject::DoCommand(tile, size | (city ? 1 << 2 : 0) | layout << 3, townnameparts, CMD_FOUND_TOWN, text);
|
|
|
|
}
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
/* static */ ScriptTown::TownRating ScriptTown::GetRating(TownID town_id, ScriptCompany::CompanyID company_id)
|
2009-01-12 17:11:45 +00:00
|
|
|
{
|
2009-01-16 00:05:26 +00:00
|
|
|
if (!IsValidTown(town_id)) return TOWN_RATING_INVALID;
|
2011-11-29 23:15:35 +00:00
|
|
|
ScriptCompany::CompanyID company = ScriptCompany::ResolveCompanyID(company_id);
|
|
|
|
if (company == ScriptCompany::COMPANY_INVALID) return TOWN_RATING_INVALID;
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2009-05-16 23:34:14 +00:00
|
|
|
const Town *t = ::Town::Get(town_id);
|
2010-07-09 19:50:06 +00:00
|
|
|
if (!HasBit(t->have_ratings, company)) {
|
|
|
|
return TOWN_RATING_NONE;
|
|
|
|
} else if (t->ratings[company] <= RATING_APPALLING) {
|
|
|
|
return TOWN_RATING_APPALLING;
|
|
|
|
} else if (t->ratings[company] <= RATING_VERYPOOR) {
|
|
|
|
return TOWN_RATING_VERY_POOR;
|
|
|
|
} else if (t->ratings[company] <= RATING_POOR) {
|
|
|
|
return TOWN_RATING_POOR;
|
|
|
|
} else if (t->ratings[company] <= RATING_MEDIOCRE) {
|
|
|
|
return TOWN_RATING_MEDIOCRE;
|
|
|
|
} else if (t->ratings[company] <= RATING_GOOD) {
|
|
|
|
return TOWN_RATING_GOOD;
|
|
|
|
} else if (t->ratings[company] <= RATING_VERYGOOD) {
|
|
|
|
return TOWN_RATING_VERY_GOOD;
|
|
|
|
} else if (t->ratings[company] <= RATING_EXCELLENT) {
|
|
|
|
return TOWN_RATING_EXCELLENT;
|
|
|
|
} else {
|
|
|
|
return TOWN_RATING_OUTSTANDING;
|
|
|
|
}
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
/* static */ int ScriptTown::GetAllowedNoise(TownID town_id)
|
2009-01-12 17:11:45 +00:00
|
|
|
{
|
|
|
|
if (!IsValidTown(town_id)) return -1;
|
|
|
|
|
2009-05-16 23:34:14 +00:00
|
|
|
const Town *t = ::Town::Get(town_id);
|
2009-01-12 17:11:45 +00:00
|
|
|
if (_settings_game.economy.station_noise_level) {
|
|
|
|
return t->MaxTownNoise() - t->noise_reached;
|
|
|
|
}
|
|
|
|
|
|
|
|
int num = 0;
|
|
|
|
const Station *st;
|
|
|
|
FOR_ALL_STATIONS(st) {
|
2010-03-18 21:02:20 +00:00
|
|
|
if (st->town == t && (st->facilities & FACIL_AIRPORT) && st->airport.type != AT_OILRIG) num++;
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
|
|
|
return max(0, 2 - num);
|
|
|
|
}
|
2009-02-04 23:26:21 +00:00
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
/* static */ ScriptTown::RoadLayout ScriptTown::GetRoadLayout(TownID town_id)
|
2009-02-04 23:26:21 +00:00
|
|
|
{
|
|
|
|
if (!IsValidTown(town_id)) return ROAD_LAYOUT_INVALID;
|
|
|
|
|
2011-11-29 23:15:35 +00:00
|
|
|
return (ScriptTown::RoadLayout)((TownLayout)::Town::Get(town_id)->layout);
|
2009-02-04 23:26:21 +00:00
|
|
|
}
|