MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / OnInit

Method OnInit

src/misc_gui.cpp:138–278  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

136 }
137
138 void OnInit() override
139 {
140 Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority);
141
142 TileDesc td{};
143 td.owner_type[0] = STR_LAND_AREA_INFORMATION_OWNER; // At least one owner is displayed, though it might be "N/A".
144
145 CargoArray acceptance{};
146 AddAcceptedCargo(tile, acceptance, nullptr);
147 GetTileDesc(tile, td);
148
149 this->landinfo_data.clear();
150
151 /* Tiletype */
152 this->landinfo_data.push_back(GetString(td.str, td.dparam));
153
154 /* Up to four owners */
155 for (uint i = 0; i < 4; i++) {
156 if (td.owner_type[i] == STR_NULL) continue;
157
158 if (td.owner[i] == OWNER_NONE || td.owner[i] == OWNER_WATER) {
159 this->landinfo_data.push_back(GetString(td.owner_type[i], STR_LAND_AREA_INFORMATION_OWNER_N_A, std::monostate{}));
160 } else {
161 auto params = GetParamsForOwnedBy(td.owner[i], tile);
162 this->landinfo_data.push_back(GetStringWithArgs(td.owner_type[i], params));
163 }
164 }
165
166 /* Cost to clear/revenue when cleared */
167 Company *c = Company::GetIfValid(_local_company);
168 if (c != nullptr) {
169 assert(_current_company == _local_company);
170 CommandCost costclear = Command<CMD_LANDSCAPE_CLEAR>::Do(DoCommandFlag::QueryCost, tile);
171 if (costclear.Succeeded()) {
172 Money cost = costclear.GetCost();
173 StringID str;
174 if (cost < 0) {
175 cost = -cost; // Negate negative cost to a positive revenue
176 str = STR_LAND_AREA_INFORMATION_REVENUE_WHEN_CLEARED;
177 } else {
178 str = STR_LAND_AREA_INFORMATION_COST_TO_CLEAR;
179 }
180 this->landinfo_data.push_back(GetString(str, cost));
181 } else {
182 this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_COST_TO_CLEAR_N_A));
183 }
184 } else {
185 this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_COST_TO_CLEAR_N_A));
186 }
187
188 /* Location */
189 this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_LANDINFO_COORDS, TileX(tile), TileY(tile), GetTileZ(tile)));
190
191 /* Tile index */
192 this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_LANDINFO_INDEX, tile, tile));
193
194 /* Local authority */
195 if (t == nullptr) {

Callers

nothing calls this directly

Calls 15

ClosestTownFromTileFunction · 0.85
AddAcceptedCargoFunction · 0.85
GetTileDescFunction · 0.85
GetParamsForOwnedByFunction · 0.85
GetStringWithArgsFunction · 0.85
TileXFunction · 0.85
TileYFunction · 0.85
GetTileZFunction · 0.85
PackVelocityFunction · 0.85
push_backMethod · 0.80
SucceededMethod · 0.80

Tested by

no test coverage detected