Files
@ r10737:2346af7e04e8
Branch filter:
Location: cpp/openttd-patchpack/source/src/ai/api/ai_town.cpp
r10737:2346af7e04e8
5.2 KiB
text/x-c
(svn r15070) -Update: WebTranslator2 update to 2009-01-13 18:42:22
brazilian_portuguese - 16 fixed by tucalipe (16)
catalan - 8 fixed by arnaullv (8)
croatian - 24 fixed by tifached (24)
czech - 8 fixed by Hadez (8)
dutch - 2 fixed by Excel20 (2)
finnish - 7 fixed, 1 changed by UltimateSephiroth (8)
hungarian - 7 fixed, 2 changed by IPG (2), alyr (7)
indonesian - 23 fixed, 2 changed by fanioz (25)
italian - 7 fixed, 1 changed by lorenzodv (8)
japanese - 59 fixed by ickoonite (59)
polish - 3 fixed by xaxa (3)
romanian - 23 fixed, 1 changed by kkmic (24)
slovak - 59 fixed by James (59)
spanish - 58 fixed by Dominus (30), eusebio (28)
turkish - 7 fixed, 1 changed by Emin (8)
brazilian_portuguese - 16 fixed by tucalipe (16)
catalan - 8 fixed by arnaullv (8)
croatian - 24 fixed by tifached (24)
czech - 8 fixed by Hadez (8)
dutch - 2 fixed by Excel20 (2)
finnish - 7 fixed, 1 changed by UltimateSephiroth (8)
hungarian - 7 fixed, 2 changed by IPG (2), alyr (7)
indonesian - 23 fixed, 2 changed by fanioz (25)
italian - 7 fixed, 1 changed by lorenzodv (8)
japanese - 59 fixed by ickoonite (59)
polish - 3 fixed by xaxa (3)
romanian - 23 fixed, 1 changed by kkmic (24)
slovak - 59 fixed by James (59)
spanish - 58 fixed by Dominus (30), eusebio (28)
turkish - 7 fixed, 1 changed by Emin (8)
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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | /* $Id$ */
/** @file ai_town.cpp Implementation of AITown. */
#include "ai_town.hpp"
#include "ai_map.hpp"
#include "ai_cargo.hpp"
#include "ai_error.hpp"
#include "../../command_type.h"
#include "../../openttd.h"
#include "../../town.h"
#include "../../strings_func.h"
#include "../../core/alloc_func.hpp"
#include "../../company_func.h"
#include "../../station_base.h"
#include "table/strings.h"
/* static */ TownID AITown::GetMaxTownID()
{
return ::GetMaxTownIndex();
}
/* static */ int32 AITown::GetTownCount()
{
return ::GetNumTowns();
}
/* static */ bool AITown::IsValidTown(TownID town_id)
{
return ::IsValidTownID(town_id);
}
/* static */ const char *AITown::GetName(TownID town_id)
{
if (!IsValidTown(town_id)) return NULL;
static const int len = 64;
char *town_name = MallocT<char>(len);
::SetDParam(0, town_id);
::GetString(town_name, STR_TOWN, &town_name[len - 1]);
return town_name;
}
/* static */ int32 AITown::GetPopulation(TownID town_id)
{
if (!IsValidTown(town_id)) return -1;
const Town *t = ::GetTown(town_id);
return t->population;
}
/* static */ int32 AITown::GetHouseCount(TownID town_id)
{
if (!IsValidTown(town_id)) return -1;
const Town *t = ::GetTown(town_id);
return t->num_houses;
}
/* static */ TileIndex AITown::GetLocation(TownID town_id)
{
if (!IsValidTown(town_id)) return INVALID_TILE;
const Town *t = ::GetTown(town_id);
return t->xy;
}
/* static */ int32 AITown::GetLastMonthProduction(TownID town_id, CargoID cargo_id)
{
if (!IsValidTown(town_id)) return -1;
if (!AICargo::IsValidCargo(cargo_id)) return -1;
const Town *t = ::GetTown(town_id);
switch(AICargo::GetTownEffect(cargo_id)) {
case AICargo::TE_PASSENGERS: return t->act_pass;
case AICargo::TE_MAIL: return t->act_mail;
default: return -1;
}
}
/* static */ int32 AITown::GetLastMonthTransported(TownID town_id, CargoID cargo_id)
{
if (!IsValidTown(town_id)) return -1;
if (!AICargo::IsValidCargo(cargo_id)) return -1;
const Town *t = ::GetTown(town_id);
switch(AICargo::GetTownEffect(cargo_id)) {
case AICargo::TE_PASSENGERS: return t->pct_pass_transported;
case AICargo::TE_MAIL: return t->pct_mail_transported;
default: return -1;
}
}
/* static */ int32 AITown::GetMaxProduction(TownID town_id, CargoID cargo_id)
{
if (!IsValidTown(town_id)) return -1;
if (!AICargo::IsValidCargo(cargo_id)) return -1;
const Town *t = ::GetTown(town_id);
switch(AICargo::GetTownEffect(cargo_id)) {
case AICargo::TE_PASSENGERS: return t->max_pass;
case AICargo::TE_MAIL: return t->max_mail;
default: return -1;
}
}
/* static */ int32 AITown::GetDistanceManhattanToTile(TownID town_id, TileIndex tile)
{
return AIMap::DistanceManhattan(tile, GetLocation(town_id));
}
/* static */ int32 AITown::GetDistanceSquareToTile(TownID town_id, TileIndex tile)
{
return AIMap::DistanceSquare(tile, GetLocation(town_id));
}
/* static */ bool AITown::IsWithinTownInfluence(TownID town_id, TileIndex tile)
{
if (!IsValidTown(town_id)) return false;
const Town *t = ::GetTown(town_id);
return ((uint32)GetDistanceSquareToTile(town_id, tile) <= t->squared_town_zone_radius[0]);
}
/* static */ bool AITown::HasStatue(TownID town_id)
{
if (!IsValidTown(town_id)) return false;
return ::HasBit(::GetTown(town_id)->statues, _current_company);
}
/* static */ int AITown::GetRoadReworkDuration(TownID town_id)
{
if (!IsValidTown(town_id)) return -1;
return ::GetTown(town_id)->road_build_months;
}
/* static */ AICompany::CompanyID AITown::GetExclusiveRightsCompany(TownID town_id)
{
if (!IsValidTown(town_id)) return AICompany::INVALID_COMPANY;
return (AICompany::CompanyID)(int8)::GetTown(town_id)->exclusivity;
}
/* static */ int32 AITown::GetExclusiveRightsDuration(TownID town_id)
{
if (!IsValidTown(town_id)) return -1;
return ::GetTown(town_id)->exclusive_counter;
}
extern uint GetMaskOfTownActions(int *nump, CompanyID cid, const Town *t);
/* static */ bool AITown::IsActionAvailable(TownID town_id, TownAction town_action)
{
if (!IsValidTown(town_id)) return false;
return HasBit(::GetMaskOfTownActions(NULL, _current_company, ::GetTown(town_id)), town_action);
}
/* static */ bool AITown::PerformTownAction(TownID town_id, TownAction town_action)
{
EnforcePrecondition(false, IsValidTown(town_id));
EnforcePrecondition(false, IsActionAvailable(town_id, town_action));
return AIObject::DoCommand(::GetTown(town_id)->xy, town_id, town_action, CMD_DO_TOWN_ACTION);
}
/* static */ AITown::TownRating AITown::GetRating(TownID town_id, AICompany::CompanyID company_id)
{
if (!IsValidTown(town_id)) return INVALID_TOWN_RATING;
AICompany::CompanyID company = AICompany::ResolveCompanyID(company_id);
if (company == AICompany::INVALID_COMPANY) return INVALID_TOWN_RATING;
const Town *t = ::GetTown(town_id);
if (!HasBit(t->have_ratings, company)) return TOWN_RATING_NONE;
return max(TOWN_RATING_APPALLING, (TownRating)((t->ratings[company] / 200) + 3));
}
/* static */ int AITown::GetAllowedNoise(TownID town_id)
{
if (!IsValidTown(town_id)) return -1;
const Town *t = ::GetTown(town_id);
if (_settings_game.economy.station_noise_level) {
return t->MaxTownNoise() - t->noise_reached;
}
int num = 0;
const Station *st;
FOR_ALL_STATIONS(st) {
if (st->town == t && st->facilities & FACIL_AIRPORT && st->airport_type != AT_OILRIG) num++;
}
return max(0, 2 - num);
}
|