OpenTTD Source: src/station_cmd.cpp Source File

OpenTTD Source 12.2

station_cmd.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
7
10 #include "stdafx.h"
11 #include "aircraft.h"
12 #include "bridge_map.h"
13 #include "cmd_helper.h"
14 #include "viewport_func.h"
15 #include "viewport_kdtree.h"
16 #include "command_func.h"
17 #include "town.h"
18 #include "news_func.h"
19 #include "train.h"
20 #include "ship.h"
21 #include "roadveh.h"
22 #include "industry.h"
23 #include "newgrf_cargo.h"
24 #include "newgrf_debug.h"
25 #include "newgrf_station.h"
26 #include "newgrf_canal.h" /* For the buoy */
27 #include "pathfinder/yapf/yapf_cache.h"
28 #include "road_internal.h" /* For drawing catenary/checking road removal */
29 #include "autoslope.h"
30 #include "water.h"
31 #include "strings_func.h"
32 #include "clear_func.h"
33 #include "date_func.h"
34 #include "vehicle_func.h"
35 #include "string_func.h"
36 #include "animated_tile_func.h"
37 #include "elrail_func.h"
38 #include "station_base.h"
39 #include "station_func.h"
40 #include "station_kdtree.h"
41 #include "roadstop_base.h"
42 #include "newgrf_railtype.h"
43 #include "newgrf_roadtype.h"
44 #include "waypoint_base.h"
45 #include "waypoint_func.h"
46 #include "pbs.h"
47 #include "debug.h"
48 #include "core/random_func.hpp"
49 #include "company_base.h"
50 #include "table/airporttile_ids.h"
51 #include "newgrf_airporttiles.h"
52 #include "order_backup.h"
53 #include "newgrf_house.h"
54 #include "company_gui.h"
55 #include "linkgraph/linkgraph_base.h"
56 #include "linkgraph/refresh.h"
57 #include "widgets/station_widget.h"
58 #include "tunnelbridge_map.h"
59
60 #include "table/strings.h"
61
62 #include "safeguards.h"
63
69 /* static */ const FlowStat::SharesMap FlowStat::empty_sharesmap;
70
77 bool IsHangar(TileIndex t)
78 {
79 assert(IsTileType(t, MP_STATION));
80
81 /* If the tile isn't an airport there's no chance it's a hangar. */
82 if (!IsAirport(t)) return false;
83
84 const Station *st = Station::GetByTile(t);
85 const AirportSpec *as = st->airport.GetSpec();
86
87 for (uint i = 0; i < as->nof_depots; i++) {
88 if (st->airport.GetHangarTile(i) == t) return true;
89 }
90
91 return false;
92 }
93
102 template <class T>
103 CommandCost GetStationAround(TileArea ta, StationID closest_station, CompanyID company, T **st)
104 {
105 ta.Expand(1);
106
107 /* check around to see if there are any stations there owned by the company */
108 for (TileIndex tile_cur : ta) {
109 if (IsTileType(tile_cur, MP_STATION)) {
110 StationID t = GetStationIndex(tile_cur);
111 if (!T::IsValidID(t) || Station::Get(t)->owner != company) continue;
112 if (closest_station == INVALID_STATION) {
113 closest_station = t;
114 } else if (closest_station != t) {
115 return_cmd_error(STR_ERROR_ADJOINS_MORE_THAN_ONE_EXISTING);
116 }
117 }
118 }
119 *st = (closest_station == INVALID_STATION) ? nullptr : T::Get(closest_station);
120 return CommandCost();
121 }
122
128 typedef bool (*CMSAMatcher)(TileIndex tile);
129
136 static int CountMapSquareAround(TileIndex tile, CMSAMatcher cmp)
137 {
138 int num = 0;
139
140 for (int dx = -3; dx <= 3; dx++) {
141 for (int dy = -3; dy <= 3; dy++) {
142 TileIndex t = TileAddWrap(tile, dx, dy);
143 if (t != INVALID_TILE && cmp(t)) num++;
144 }
145 }
146
147 return num;
148 }
149
155 static bool CMSAMine(TileIndex tile)
156 {
157 /* No industry */
158 if (!IsTileType(tile, MP_INDUSTRY)) return false;
159
160 const Industry *ind = Industry::GetByTile(tile);
161
162 /* No extractive industry */
163 if ((GetIndustrySpec(ind->type)->life_type & INDUSTRYLIFE_EXTRACTIVE) == 0) return false;
164
165 for (uint i = 0; i < lengthof(ind->produced_cargo); i++) {
166 /* The industry extracts something non-liquid, i.e. no oil or plastic, so it is a mine.
167 * Also the production of passengers and mail is ignored. */
168 if (ind->produced_cargo[i] != CT_INVALID &&
169 (CargoSpec::Get(ind->produced_cargo[i])->classes & (CC_LIQUID | CC_PASSENGERS | CC_MAIL)) == 0) {
170 return true;
171 }
172 }
173
174 return false;
175 }
176
182 static bool CMSAWater(TileIndex tile)
183 {
184 return IsTileType(tile, MP_WATER) && IsWater(tile);
185 }
186
192 static bool CMSATree(TileIndex tile)
193 {
194 return IsTileType(tile, MP_TREES);
195 }
196
197 #define M(x) ((x) - STR_SV_STNAME)
198
199 enum StationNaming {
200 STATIONNAMING_RAIL,
201 STATIONNAMING_ROAD,
202 STATIONNAMING_AIRPORT,
203 STATIONNAMING_OILRIG,
204 STATIONNAMING_DOCK,
205 STATIONNAMING_HELIPORT,
206 };
207
209 struct StationNameInformation {
210 uint32 free_names;
211 bool *indtypes;
212 };
213
222 static bool FindNearIndustryName(TileIndex tile, void *user_data)
223 {
224 /* All already found industry types */
225 StationNameInformation *sni = (StationNameInformation*)user_data;
226 if (!IsTileType(tile, MP_INDUSTRY)) return false;
227
228 /* If the station name is undefined it means that it doesn't name a station */
229 IndustryType indtype = GetIndustryType(tile);
230 if (GetIndustrySpec(indtype)->station_name == STR_UNDEFINED) return false;
231
232 /* In all cases if an industry that provides a name is found two of
233 * the standard names will be disabled. */
234 sni->free_names &= ~(1 << M(STR_SV_STNAME_OILFIELD) | 1 << M(STR_SV_STNAME_MINES));
235 return !sni->indtypes[indtype];
236 }
237
238 static StringID GenerateStationName(Station *st, TileIndex tile, StationNaming name_class)
239 {
240 static const uint32 _gen_station_name_bits[] = {
241 0, // STATIONNAMING_RAIL
242 0, // STATIONNAMING_ROAD
243 1U << M(STR_SV_STNAME_AIRPORT), // STATIONNAMING_AIRPORT
244 1U << M(STR_SV_STNAME_OILFIELD), // STATIONNAMING_OILRIG
245 1U << M(STR_SV_STNAME_DOCKS), // STATIONNAMING_DOCK
246 1U << M(STR_SV_STNAME_HELIPORT), // STATIONNAMING_HELIPORT
247 };
248
249 const Town *t = st->town;
250 uint32 free_names = UINT32_MAX;
251
252 bool indtypes[NUM_INDUSTRYTYPES];
253 memset(indtypes, 0, sizeof(indtypes));
254
255 for (const Station *s : Station::Iterate()) {
256 if (s != st && s->town == t) {
257 if (s->indtype != IT_INVALID) {
258 indtypes[s->indtype] = true;
259 StringID name = GetIndustrySpec(s->indtype)->station_name;
260 if (name != STR_UNDEFINED) {
261 /* Filter for other industrytypes with the same name */
262 for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
263 const IndustrySpec *indsp = GetIndustrySpec(it);
264 if (indsp->enabled && indsp->station_name == name) indtypes[it] = true;
265 }
266 }
267 continue;
268 }
269 uint str = M(s->string_id);
270 if (str <= 0x20) {
271 if (str == M(STR_SV_STNAME_FOREST)) {
272 str = M(STR_SV_STNAME_WOODS);
273 }
274 ClrBit(free_names, str);
275 }
276 }
277 }
278
279 TileIndex indtile = tile;
280 StationNameInformation sni = { free_names, indtypes };
281 if (CircularTileSearch(&indtile, 7, FindNearIndustryName, &sni)) {
282 /* An industry has been found nearby */
283 IndustryType indtype = GetIndustryType(indtile);
284 const IndustrySpec *indsp = GetIndustrySpec(indtype);
285 /* STR_NULL means it only disables oil rig/mines */
286 if (indsp->station_name != STR_NULL) {
287 st->indtype = indtype;
288 return STR_SV_STNAME_FALLBACK;
289 }
290 }
291
292 /* Oil rigs/mines name could be marked not free by looking for a near by industry. */
293 free_names = sni.free_names;
294
295 /* check default names */
296 uint32 tmp = free_names & _gen_station_name_bits[name_class];
297 if (tmp != 0) return STR_SV_STNAME + FindFirstBit(tmp);
298
299 /* check mine? */
300 if (HasBit(free_names, M(STR_SV_STNAME_MINES))) {
301 if (CountMapSquareAround(tile, CMSAMine) >= 2) {
302 return STR_SV_STNAME_MINES;
303 }
304 }
305
306 /* check close enough to town to get central as name? */
307 if (DistanceMax(tile, t->xy) < 8) {
308 if (HasBit(free_names, M(STR_SV_STNAME))) return STR_SV_STNAME;
309
310 if (HasBit(free_names, M(STR_SV_STNAME_CENTRAL))) return STR_SV_STNAME_CENTRAL;
311 }
312
313 /* Check lakeside */
314 if (HasBit(free_names, M(STR_SV_STNAME_LAKESIDE)) &&
315 DistanceFromEdge(tile) < 20 &&
316 CountMapSquareAround(tile, CMSAWater) >= 5) {
317 return STR_SV_STNAME_LAKESIDE;
318 }
319
320 /* Check woods */
321 if (HasBit(free_names, M(STR_SV_STNAME_WOODS)) && (
322 CountMapSquareAround(tile, CMSATree) >= 8 ||
323 CountMapSquareAround(tile, IsTileForestIndustry) >= 2)
324 ) {
325 return _settings_game.game_creation.landscape == LT_TROPIC ? STR_SV_STNAME_FOREST : STR_SV_STNAME_WOODS;
326 }
327
328 /* check elevation compared to town */
329 int z = GetTileZ(tile);
330 int z2 = GetTileZ(t->xy);
331 if (z < z2) {
332 if (HasBit(free_names, M(STR_SV_STNAME_VALLEY))) return STR_SV_STNAME_VALLEY;
333 } else if (z > z2) {
334 if (HasBit(free_names, M(STR_SV_STNAME_HEIGHTS))) return STR_SV_STNAME_HEIGHTS;
335 }
336
337 /* check direction compared to town */
338 static const int8 _direction_and_table[] = {
339 ~( (1 << M(STR_SV_STNAME_WEST)) | (1 << M(STR_SV_STNAME_EAST)) | (1 << M(STR_SV_STNAME_NORTH)) ),
340 ~( (1 << M(STR_SV_STNAME_SOUTH)) | (1 << M(STR_SV_STNAME_WEST)) | (1 << M(STR_SV_STNAME_NORTH)) ),
341 ~( (1 << M(STR_SV_STNAME_SOUTH)) | (1 << M(STR_SV_STNAME_EAST)) | (1 << M(STR_SV_STNAME_NORTH)) ),
342 ~( (1 << M(STR_SV_STNAME_SOUTH)) | (1 << M(STR_SV_STNAME_WEST)) | (1 << M(STR_SV_STNAME_EAST)) ),
343 };
344
345 free_names &= _direction_and_table[
346 (TileX(tile) < TileX(t->xy)) +
347 (TileY(tile) < TileY(t->xy)) * 2];
348
349 tmp = free_names & ((1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 6) | (1 << 7) | (1 << 12) | (1 << 26) | (1 << 27) | (1 << 28) | (1 << 29) | (1 << 30));
350 return (tmp == 0) ? STR_SV_STNAME_FALLBACK : (STR_SV_STNAME + FindFirstBit(tmp));
351 }
352 #undef M
353
359 static Station *GetClosestDeletedStation(TileIndex tile)
360 {
361 uint threshold = 8;
362
363 Station *best_station = nullptr;
364 ForAllStationsRadius(tile, threshold, [&](Station *st) {
365 if (!st->IsInUse() && st->owner == _current_company) {
366 uint cur_dist = DistanceManhattan(tile, st->xy);
367
368 if (cur_dist < threshold) {
369 threshold = cur_dist;
370 best_station = st;
371 } else if (cur_dist == threshold && best_station != nullptr) {
372 /* In case of a tie, lowest station ID wins */
373 if (st->index < best_station->index) best_station = st;
374 }
375 }
376 });
377
378 return best_station;
379 }
380
381
382 void Station::GetTileArea(TileArea *ta, StationType type) const
383 {
384 switch (type) {
385 case STATION_RAIL:
386 *ta = this->train_station;
387 return;
388
389 case STATION_AIRPORT:
390 *ta = this->airport;
391 return;
392
393 case STATION_TRUCK:
394 *ta = this->truck_station;
395 return;
396
397 case STATION_BUS:
398 *ta = this->bus_station;
399 return;
400
401 case STATION_DOCK:
402 case STATION_OILRIG:
403 *ta = this->docking_station;
404 return;
405
406 default: NOT_REACHED();
407 }
408 }
409
413 void Station::UpdateVirtCoord()
414 {
415 Point pt = RemapCoords2(TileX(this->xy) * TILE_SIZE, TileY(this->xy) * TILE_SIZE);
416
417 pt.y -= 32 * ZOOM_LVL_BASE;
418 if ((this->facilities & FACIL_AIRPORT) && this->airport.type == AT_OILRIG) pt.y -= 16 * ZOOM_LVL_BASE;
419
420 if (this->sign.kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeStation(this->index));
421
422 SetDParam(0, this->index);
423 SetDParam(1, this->facilities);
424 this->sign.UpdatePosition(pt.x, pt.y, STR_VIEWPORT_STATION);
425
426 _viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeStation(this->index));
427
428 SetWindowDirty(WC_STATION_VIEW, this->index);
429 }
430
435 void Station::MoveSign(TileIndex new_xy)
436 {
437 if (this->xy == new_xy) return;
438
439 _station_kdtree.Remove(this->index);
440
441 this->BaseStation::MoveSign(new_xy);
442
443 _station_kdtree.Insert(this->index);
444 }
445
447 void UpdateAllStationVirtCoords()
448 {
449 for (BaseStation *st : BaseStation::Iterate()) {
450 st->UpdateVirtCoord();
451 }
452 }
453
454 void BaseStation::FillCachedName() const
455 {
456 char buf[MAX_LENGTH_STATION_NAME_CHARS * MAX_CHAR_LENGTH];
457 int64 args_array[] = { this->index };
458 StringParameters tmp_params(args_array);
459 char *end = GetStringWithArgs(buf, Waypoint::IsExpected(this) ? STR_WAYPOINT_NAME : STR_STATION_NAME, &tmp_params, lastof(buf));
460 this->cached_name.assign(buf, end);
461 }
462
463 void ClearAllStationCachedNames()
464 {
465 for (BaseStation *st : BaseStation::Iterate()) {
466 st->cached_name.clear();
467 }
468 }
469
475 static CargoTypes GetAcceptanceMask(const Station *st)
476 {
477 CargoTypes mask = 0;
478
479 for (CargoID i = 0; i < NUM_CARGO; i++) {
480 if (HasBit(st->goods[i].status, GoodsEntry::GES_ACCEPTANCE)) SetBit(mask, i);
481 }
482 return mask;
483 }
484
489 static void ShowRejectOrAcceptNews(const Station *st, uint num_items, CargoID *cargo, StringID msg)
490 {
491 for (uint i = 0; i < num_items; i++) {
492 SetDParam(i + 1, CargoSpec::Get(cargo[i])->name);
493 }
494
495 SetDParam(0, st->index);
496 AddNewsItem(msg, NT_ACCEPTANCE, NF_INCOLOUR | NF_SMALL, NR_STATION, st->index);
497 }
498
506 CargoArray GetProductionAroundTiles(TileIndex north_tile, int w, int h, int rad)
507 {
508 CargoArray produced;
509 std::set<IndustryID> industries;
510 TileArea ta = TileArea(north_tile, w, h).Expand(rad);
511
512 /* Loop over all tiles to get the produced cargo of
513 * everything except industries */
514 for (TileIndex tile : ta) {
515 if (IsTileType(tile, MP_INDUSTRY)) industries.insert(GetIndustryIndex(tile));
516 AddProducedCargo(tile, produced);
517 }
518
519 /* Loop over the seen industries. They produce cargo for
520 * anything that is within 'rad' of any one of their tiles.
521 */
522 for (IndustryID industry : industries) {
523 const Industry *i = Industry::Get(industry);
524 /* Skip industry with neutral station */
525 if (i->neutral_station != nullptr && !_settings_game.station.serve_neutral_industries) continue;
526
527 for (uint j = 0; j < lengthof(i->produced_cargo); j++) {
528 CargoID cargo = i->produced_cargo[j];
529 if (cargo != CT_INVALID) produced[cargo]++;
530 }
531 }
532
533 return produced;
534 }
535
545 CargoArray GetAcceptanceAroundTiles(TileIndex center_tile, int w, int h, int rad, CargoTypes *always_accepted)
546 {
547 CargoArray acceptance;
548 if (always_accepted != nullptr) *always_accepted = 0;
549
550 TileArea ta = TileArea(center_tile, w, h).Expand(rad);
551
552 for (TileIndex tile : ta) {
553 /* Ignore industry if it has a neutral station. */
554 if (!_settings_game.station.serve_neutral_industries && IsTileType(tile, MP_INDUSTRY) && Industry::GetByTile(tile)->neutral_station != nullptr) continue;
555
556 AddAcceptedCargo(tile, acceptance, always_accepted);
557 }
558
559 return acceptance;
560 }
561
567 static CargoArray GetAcceptanceAroundStation(const Station *st, CargoTypes *always_accepted)
568 {
569 CargoArray acceptance;
570 if (always_accepted != nullptr) *always_accepted = 0;
571
572 BitmapTileIterator it(st->catchment_tiles);
573 for (TileIndex tile = it; tile != INVALID_TILE; tile = ++it) {
574 AddAcceptedCargo(tile, acceptance, always_accepted);
575 }
576
577 return acceptance;
578 }
579
585 void UpdateStationAcceptance(Station *st, bool show_msg)
586 {
587 /* old accepted goods types */
588 CargoTypes old_acc = GetAcceptanceMask(st);
589
590 /* And retrieve the acceptance. */
591 CargoArray acceptance;
592 if (!st->rect.IsEmpty()) {
593 acceptance = GetAcceptanceAroundStation(st, &st->always_accepted);
594 }
595
596 /* Adjust in case our station only accepts fewer kinds of goods */
597 for (CargoID i = 0; i < NUM_CARGO; i++) {
598 uint amt = acceptance[i];
599
600 /* Make sure the station can accept the goods type. */
601 bool is_passengers = IsCargoInClass(i, CC_PASSENGERS);
602 if ((!is_passengers && !(st->facilities & ~FACIL_BUS_STOP)) ||
603 (is_passengers && !(st->facilities & ~FACIL_TRUCK_STOP))) {
604 amt = 0;
605 }
606
607 GoodsEntry &ge = st->goods[i];
608 SB(ge.status, GoodsEntry::GES_ACCEPTANCE, 1, amt >= 8);
609 if (LinkGraph::IsValidID(ge.link_graph)) {
610 (*LinkGraph::Get(ge.link_graph))[ge.node].SetDemand(amt / 8);
611 }
612 }
613
614 /* Only show a message in case the acceptance was actually changed. */
615 CargoTypes new_acc = GetAcceptanceMask(st);
616 if (old_acc == new_acc) return;
617
618 /* show a message to report that the acceptance was changed? */
619 if (show_msg && st->owner == _local_company && st->IsInUse()) {
620 /* List of accept and reject strings for different number of
621 * cargo types */
622 static const StringID accept_msg[] = {
623 STR_NEWS_STATION_NOW_ACCEPTS_CARGO,
624 STR_NEWS_STATION_NOW_ACCEPTS_CARGO_AND_CARGO,
625 };
626 static const StringID reject_msg[] = {
627 STR_NEWS_STATION_NO_LONGER_ACCEPTS_CARGO,
628 STR_NEWS_STATION_NO_LONGER_ACCEPTS_CARGO_OR_CARGO,
629 };
630
631 /* Array of accepted and rejected cargo types */
632 CargoID accepts[2] = { CT_INVALID, CT_INVALID };
633 CargoID rejects[2] = { CT_INVALID, CT_INVALID };
634 uint num_acc = 0;
635 uint num_rej = 0;
636
637 /* Test each cargo type to see if its acceptance has changed */
638 for (CargoID i = 0; i < NUM_CARGO; i++) {
639 if (HasBit(new_acc, i)) {
640 if (!HasBit(old_acc, i) && num_acc < lengthof(accepts)) {
641 /* New cargo is accepted */
642 accepts[num_acc++] = i;
643 }
644 } else {
645 if (HasBit(old_acc, i) && num_rej < lengthof(rejects)) {
646 /* Old cargo is no longer accepted */
647 rejects[num_rej++] = i;
648 }
649 }
650 }
651
652 /* Show news message if there are any changes */
653 if (num_acc > 0) ShowRejectOrAcceptNews(st, num_acc, accepts, accept_msg[num_acc - 1]);
654 if (num_rej > 0) ShowRejectOrAcceptNews(st, num_rej, rejects, reject_msg[num_rej - 1]);
655 }
656
657 /* redraw the station view since acceptance changed */
658 SetWindowWidgetDirty(WC_STATION_VIEW, st->index, WID_SV_ACCEPT_RATING_LIST);
659 }
660
661 static void UpdateStationSignCoord(BaseStation *st)
662 {
663 const StationRect *r = &st->rect;
664
665 if (r->IsEmpty()) return; // no tiles belong to this station
666
667 /* clamp sign coord to be inside the station rect */
668 TileIndex new_xy = TileXY(ClampU(TileX(st->xy), r->left, r->right), ClampU(TileY(st->xy), r->top, r->bottom));
669 st->MoveSign(new_xy);
670
671 if (!Station::IsExpected(st)) return;
672 Station *full_station = Station::From(st);
673 for (CargoID c = 0; c < NUM_CARGO; ++c) {
674 LinkGraphID lg = full_station->goods[c].link_graph;
675 if (!LinkGraph::IsValidID(lg)) continue;
676 (*LinkGraph::Get(lg))[full_station->goods[c].node].UpdateLocation(st->xy);
677 }
678 }
679
689 static CommandCost BuildStationPart(Station **st, DoCommandFlag flags, bool reuse, TileArea area, StationNaming name_class)
690 {
691 /* Find a deleted station close to us */
692 if (*st == nullptr && reuse) *st = GetClosestDeletedStation(area.tile);
693
694 if (*st != nullptr) {
695 if ((*st)->owner != _current_company) {
696 return_cmd_error(CMD_ERROR);
697 }
698
699 CommandCost ret = (*st)->rect.BeforeAddRect(area.tile, area.w, area.h, StationRect::ADD_TEST);
700 if (ret.Failed()) return ret;
701 } else {
702 /* allocate and initialize new station */
703 if (!Station::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_STATIONS_LOADING);
704
705 if (flags & DC_EXEC) {
706 *st = new Station(area.tile);
707 _station_kdtree.Insert((*st)->index);
708
709 (*st)->town = ClosestTownFromTile(area.tile, UINT_MAX);
710 (*st)->string_id = GenerateStationName(*st, area.tile, name_class);
711
712 if (Company::IsValidID(_current_company)) {
713 SetBit((*st)->town->have_ratings, _current_company);
714 }
715 }
716 }
717 return CommandCost();
718 }
719
726 static void DeleteStationIfEmpty(BaseStation *st)
727 {
728 if (!st->IsInUse()) {
729 st->delete_ctr = 0;
730 InvalidateWindowData(WC_STATION_LIST, st->owner, 0);
731 }
732 /* station remains but it probably lost some parts - station sign should stay in the station boundaries */
733 UpdateStationSignCoord(st);
734 }
735
741 void Station::AfterStationTileSetChange(bool adding, StationType type)
742 {
743 this->UpdateVirtCoord();
744 DirtyCompanyInfrastructureWindows(this->owner);
745
746 if (adding) {
747 this->RecomputeCatchment();
748 MarkCatchmentTilesDirty();
749 InvalidateWindowData(WC_STATION_LIST, this->owner, 0);
750 } else {
751 MarkCatchmentTilesDirty();
752 this->RecomputeCatchment();
753 }
754
755 switch (type) {
756 case STATION_RAIL:
757 SetWindowWidgetDirty(WC_STATION_VIEW, this->index, WID_SV_TRAINS);
758 break;
759 case STATION_AIRPORT:
760 break;
761 case STATION_TRUCK:
762 case STATION_BUS:
763 SetWindowWidgetDirty(WC_STATION_VIEW, this->index, WID_SV_ROADVEHS);
764 break;
765 case STATION_DOCK:
766 SetWindowWidgetDirty(WC_STATION_VIEW, this->index, WID_SV_SHIPS);
767 break;
768 default: NOT_REACHED();
769 }
770
771 if (adding) {
772 UpdateStationAcceptance(this, false);
773 InvalidateWindowData(WC_SELECT_STATION, 0, 0);
774 } else {
775 DeleteStationIfEmpty(this);
776 }
777
778 }
779
780 CommandCost ClearTile_Station(TileIndex tile, DoCommandFlag flags);
781
791 CommandCost CheckBuildableTile(TileIndex tile, uint invalid_dirs, int &allowed_z, bool allow_steep, bool check_bridge = true)
792 {
793 if (check_bridge && IsBridgeAbove(tile)) {
794 return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
795 }
796
797 CommandCost ret = EnsureNoVehicleOnGround(tile);
798 if (ret.Failed()) return ret;
799
800 int z;
801 Slope tileh = GetTileSlope(tile, &z);
802
803 /* Prohibit building if
804 * 1) The tile is "steep" (i.e. stretches two height levels).
805 * 2) The tile is non-flat and the build_on_slopes switch is disabled.
806 */
807 if ((!allow_steep && IsSteepSlope(tileh)) ||
808 ((!_settings_game.construction.build_on_slopes) && tileh != SLOPE_FLAT)) {
809 return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED);
810 }
811
812 CommandCost cost(EXPENSES_CONSTRUCTION);
813 int flat_z = z + GetSlopeMaxZ(tileh);
814 if (tileh != SLOPE_FLAT) {
815 /* Forbid building if the tile faces a slope in a invalid direction. */
816 for (DiagDirection dir = DIAGDIR_BEGIN; dir != DIAGDIR_END; dir++) {
817 if (HasBit(invalid_dirs, dir) && !CanBuildDepotByTileh(dir, tileh)) {
818 return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED);
819 }
820 }
821 cost.AddCost(_price[PR_BUILD_FOUNDATION]);
822 }
823
824 /* The level of this tile must be equal to allowed_z. */
825 if (allowed_z < 0) {
826 /* First tile. */
827 allowed_z = flat_z;
828 } else if (allowed_z != flat_z) {
829 return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED);
830 }
831
832 return cost;
833 }
834
841 static CommandCost CheckFlatLandAirport(AirportTileTableIterator tile_iter, DoCommandFlag flags)
842 {
843 CommandCost cost(EXPENSES_CONSTRUCTION);
844 int allowed_z = -1;
845
846 for (; tile_iter != INVALID_TILE; ++tile_iter) {
847 CommandCost ret = CheckBuildableTile(tile_iter, 0, allowed_z, true);
848 if (ret.Failed()) return ret;
849 cost.AddCost(ret);
850
851 ret = DoCommand(tile_iter, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
852 if (ret.Failed()) return ret;
853 cost.AddCost(ret);
854 }
855
856 return cost;
857 }
858
873 static CommandCost CheckFlatLandRailStation(TileArea tile_area, DoCommandFlag flags, Axis axis, StationID *station, RailType rt, std::vector<Train *> &affected_vehicles, StationClassID spec_class, byte spec_index, byte plat_len, byte numtracks)
874 {
875 CommandCost cost(EXPENSES_CONSTRUCTION);
876 int allowed_z = -1;
877 uint invalid_dirs = 5 << axis;
878
879 const StationSpec *statspec = StationClass::Get(spec_class)->GetSpec(spec_index);
880 bool slope_cb = statspec != nullptr && HasBit(statspec->callback_mask, CBM_STATION_SLOPE_CHECK);
881
882 for (TileIndex tile_cur : tile_area) {
883 CommandCost ret = CheckBuildableTile(tile_cur, invalid_dirs, allowed_z, false);
884 if (ret.Failed()) return ret;
885 cost.AddCost(ret);
886
887 if (slope_cb) {
888 /* Do slope check if requested. */
889 ret = PerformStationTileSlopeCheck(tile_area.tile, tile_cur, statspec, axis, plat_len, numtracks);
890 if (ret.Failed()) return ret;
891 }
892
893 /* if station is set, then we have special handling to allow building on top of already existing stations.
894 * so station points to INVALID_STATION if we can build on any station.
895 * Or it points to a station if we're only allowed to build on exactly that station. */
896 if (station != nullptr && IsTileType(tile_cur, MP_STATION)) {
897 if (!IsRailStation(tile_cur)) {
898 return ClearTile_Station(tile_cur, DC_AUTO); // get error message
899 } else {
900 StationID st = GetStationIndex(tile_cur);
901 if (*station == INVALID_STATION) {
902 *station = st;
903 } else if (*station != st) {
904 return_cmd_error(STR_ERROR_ADJOINS_MORE_THAN_ONE_EXISTING);
905 }
906 }
907 } else {
908 /* Rail type is only valid when building a railway station; if station to
909 * build isn't a rail station it's INVALID_RAILTYPE. */
910 if (rt != INVALID_RAILTYPE &&
911 IsPlainRailTile(tile_cur) && !HasSignals(tile_cur) &&
912 HasPowerOnRail(GetRailType(tile_cur), rt)) {
913 /* Allow overbuilding if the tile:
914 * - has rail, but no signals
915 * - it has exactly one track
916 * - the track is in line with the station
917 * - the current rail type has power on the to-be-built type (e.g. convert normal rail to el rail)
918 */
919 TrackBits tracks = GetTrackBits(tile_cur);
920 Track track = RemoveFirstTrack(&tracks);
921 Track expected_track = HasBit(invalid_dirs, DIAGDIR_NE) ? TRACK_X : TRACK_Y;
922
923 if (tracks == TRACK_BIT_NONE && track == expected_track) {
924 /* Check for trains having a reservation for this tile. */
925 if (HasBit(GetRailReservationTrackBits(tile_cur), track)) {
926 Train *v = GetTrainForReservation(tile_cur, track);
927 if (v != nullptr) {
928 affected_vehicles.push_back(v);
929 }
930 }
931 CommandCost ret = DoCommand(tile_cur, 0, track, flags, CMD_REMOVE_SINGLE_RAIL);
932 if (ret.Failed()) return ret;
933 cost.AddCost(ret);
934 /* With flags & ~DC_EXEC CmdLandscapeClear would fail since the rail still exists */
935 continue;
936 }
937 }
938 ret = DoCommand(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
939 if (ret.Failed()) return ret;
940 cost.AddCost(ret);
941 }
942 }
943
944 return cost;
945 }
946
959 static CommandCost CheckFlatLandRoadStop(TileArea tile_area, DoCommandFlag flags, uint invalid_dirs, bool is_drive_through, bool is_truck_stop, Axis axis, StationID *station, RoadType rt)
960 {
961 CommandCost cost(EXPENSES_CONSTRUCTION);
962 int allowed_z = -1;
963
964 for (TileIndex cur_tile : tile_area) {
965 CommandCost ret = CheckBuildableTile(cur_tile, invalid_dirs, allowed_z, !is_drive_through);
966 if (ret.Failed()) return ret;
967 cost.AddCost(ret);
968
969 /* If station is set, then we have special handling to allow building on top of already existing stations.
970 * Station points to INVALID_STATION if we can build on any station.
971 * Or it points to a station if we're only allowed to build on exactly that station. */
972 if (station != nullptr && IsTileType(cur_tile, MP_STATION)) {
973 if (!IsRoadStop(cur_tile)) {
974 return ClearTile_Station(cur_tile, DC_AUTO); // Get error message.
975 } else {
976 if (is_truck_stop != IsTruckStop(cur_tile) ||
977 is_drive_through != IsDriveThroughStopTile(cur_tile)) {
978 return ClearTile_Station(cur_tile, DC_AUTO); // Get error message.
979 }
980 /* Drive-through station in the wrong direction. */
981 if (is_drive_through && IsDriveThroughStopTile(cur_tile) && DiagDirToAxis(GetRoadStopDir(cur_tile)) != axis){
982 return_cmd_error(STR_ERROR_DRIVE_THROUGH_DIRECTION);
983 }
984 StationID st = GetStationIndex(cur_tile);
985 if (*station == INVALID_STATION) {
986 *station = st;
987 } else if (*station != st) {
988 return_cmd_error(STR_ERROR_ADJOINS_MORE_THAN_ONE_EXISTING);
989 }
990 }
991 } else {
992 bool build_over_road = is_drive_through && IsNormalRoadTile(cur_tile);
993 /* Road bits in the wrong direction. */
994 RoadBits rb = IsNormalRoadTile(cur_tile) ? GetAllRoadBits(cur_tile) : ROAD_NONE;
995 if (build_over_road && (rb & (axis == AXIS_X ? ROAD_Y : ROAD_X)) != 0) {
996 /* Someone was pedantic and *NEEDED* three fracking different error messages. */
997 switch (CountBits(rb)) {
998 case 1:
999 return_cmd_error(STR_ERROR_DRIVE_THROUGH_DIRECTION);
1000
1001 case 2:
1002 if (rb == ROAD_X || rb == ROAD_Y) return_cmd_error(STR_ERROR_DRIVE_THROUGH_DIRECTION);
1003 return_cmd_error(STR_ERROR_DRIVE_THROUGH_CORNER);
1004
1005 default: // 3 or 4
1006 return_cmd_error(STR_ERROR_DRIVE_THROUGH_JUNCTION);
1007 }
1008 }
1009
1010 if (build_over_road) {
1011 /* There is a road, check if we can build road+tram stop over it. */
1012 RoadType road_rt = GetRoadType(cur_tile, RTT_ROAD);
1013 if (road_rt != INVALID_ROADTYPE) {
1014 Owner road_owner = GetRoadOwner(cur_tile, RTT_ROAD);
1015 if (road_owner == OWNER_TOWN) {
1016 if (!_settings_game.construction.road_stop_on_town_road) return_cmd_error(STR_ERROR_DRIVE_THROUGH_ON_TOWN_ROAD);
1017 } else if (!_settings_game.construction.road_stop_on_competitor_road && road_owner != OWNER_NONE) {
1018 CommandCost ret = CheckOwnership(road_owner);
1019 if (ret.Failed()) return ret;
1020 }
1021 uint num_pieces = CountBits(GetRoadBits(cur_tile, RTT_ROAD));
1022
1023 if (RoadTypeIsRoad(rt) && !HasPowerOnRoad(rt, road_rt)) return_cmd_error(STR_ERROR_NO_SUITABLE_ROAD);
1024
1025 if (GetDisallowedRoadDirections(cur_tile) != DRD_NONE && road_owner != OWNER_TOWN) {
1026 CommandCost ret = CheckOwnership(road_owner);
1027 if (ret.Failed()) return ret;
1028 }
1029
1030 cost.AddCost(RoadBuildCost(road_rt) * (2 - num_pieces));
1031 } else if (RoadTypeIsRoad(rt)) {
1032 cost.AddCost(RoadBuildCost(rt) * 2);
1033 }
1034
1035 /* There is a tram, check if we can build road+tram stop over it. */
1036 RoadType tram_rt = GetRoadType(cur_tile, RTT_TRAM);
1037 if (tram_rt != INVALID_ROADTYPE) {
1038 Owner tram_owner = GetRoadOwner(cur_tile, RTT_TRAM);
1039 if (Company::IsValidID(tram_owner) &&
1040 (!_settings_game.construction.road_stop_on_competitor_road ||
1041 /* Disallow breaking end-of-line of someone else
1042 * so trams can still reverse on this tile. */
1043 HasExactlyOneBit(GetRoadBits(cur_tile, RTT_TRAM)))) {
1044 CommandCost ret = CheckOwnership(tram_owner);
1045 if (ret.Failed()) return ret;
1046 }
1047 uint num_pieces = CountBits(GetRoadBits(cur_tile, RTT_TRAM));
1048
1049 if (RoadTypeIsTram(rt) && !HasPowerOnRoad(rt, tram_rt)) return_cmd_error(STR_ERROR_NO_SUITABLE_ROAD);
1050
1051 cost.AddCost(RoadBuildCost(tram_rt) * (2 - num_pieces));
1052 } else if (RoadTypeIsTram(rt)) {
1053 cost.AddCost(RoadBuildCost(rt) * 2);
1054 }
1055 } else {
1056 ret = DoCommand(cur_tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
1057 if (ret.Failed()) return ret;
1058 cost.AddCost(ret);
1059 cost.AddCost(RoadBuildCost(rt) * 2);
1060 }
1061 }
1062 }
1063
1064 return cost;
1065 }
1066
1074 CommandCost CanExpandRailStation(const BaseStation *st, TileArea &new_ta, Axis axis)
1075 {
1076 TileArea cur_ta = st->train_station;
1077
1078 /* determine new size of train station region.. */
1079 int x = std::min(TileX(cur_ta.tile), TileX(new_ta.tile));
1080 int y = std::min(TileY(cur_ta.tile), TileY(new_ta.tile));
1081 new_ta.w = std::max(TileX(cur_ta.tile) + cur_ta.w, TileX(new_ta.tile) + new_ta.w) - x;
1082 new_ta.h = std::max(TileY(cur_ta.tile) + cur_ta.h, TileY(new_ta.tile) + new_ta.h) - y;
1083 new_ta.tile = TileXY(x, y);
1084
1085 /* make sure the final size is not too big. */
1086 if (new_ta.w > _settings_game.station.station_spread || new_ta.h > _settings_game.station.station_spread) {
1087 return_cmd_error(STR_ERROR_STATION_TOO_SPREAD_OUT);
1088 }
1089
1090 return CommandCost();
1091 }
1092
1093 static inline byte *CreateSingle(byte *layout, int n)
1094 {
1095 int i = n;
1096 do *layout++ = 0; while (--i);
1097 layout[((n - 1) >> 1) - n] = 2;
1098 return layout;
1099 }
1100
1101 static inline byte *CreateMulti(byte *layout, int n, byte b)
1102 {
1103 int i = n;
1104 do *layout++ = b; while (--i);
1105 if (n > 4) {
1106 layout[0 - n] = 0;
1107 layout[n - 1 - n] = 0;
1108 }
1109 return layout;
1110 }
1111
1119 void GetStationLayout(byte *layout, uint numtracks, uint plat_len, const StationSpec *statspec)
1120 {
1121 if (statspec != nullptr && statspec->layouts.size() >= plat_len &&
1122 statspec->layouts[plat_len - 1].size() >= numtracks &&
1123 !statspec->layouts[plat_len - 1][numtracks - 1].empty()) {
1124 /* Custom layout defined, follow it. */
1125 memcpy(layout, statspec->layouts[plat_len - 1][numtracks - 1].data(),
1126 plat_len * numtracks);
1127 return;
1128 }
1129
1130 if (plat_len == 1) {
1131 CreateSingle(layout, numtracks);
1132 } else {
1133 if (numtracks & 1) layout = CreateSingle(layout, plat_len);
1134 int n = numtracks >> 1;
1135
1136 while (--n >= 0) {
1137 layout = CreateMulti(layout, plat_len, 4);
1138 layout = CreateMulti(layout, plat_len, 6);
1139 }
1140 }
1141 }
1142
1154 template <class T, StringID error_message>
1155 CommandCost FindJoiningBaseStation(StationID existing_station, StationID station_to_join, bool adjacent, TileArea ta, T **st)
1156 {
1157 assert(*st == nullptr);
1158 bool check_surrounding = true;
1159
1160 if (_settings_game.station.adjacent_stations) {
1161 if (existing_station != INVALID_STATION) {
1162 if (adjacent && existing_station != station_to_join) {
1163 /* You can't build an adjacent station over the top of one that
1164 * already exists. */
1165 return_cmd_error(error_message);
1166 } else {
1167 /* Extend the current station, and don't check whether it will
1168 * be near any other stations. */
1169 *st = T::GetIfValid(existing_station);
1170 check_surrounding = (*st == nullptr);
1171 }
1172 } else {
1173 /* There's no station here. Don't check the tiles surrounding this
1174 * one if the company wanted to build an adjacent station. */
1175 if (adjacent) check_surrounding = false;
1176 }
1177 }
1178
1179 if (check_surrounding) {
1180 /* Make sure there is no more than one other station around us that is owned by us. */
1181 CommandCost ret = GetStationAround(ta, existing_station, _current_company, st);
1182 if (ret.Failed()) return ret;
1183 }
1184
1185 /* Distant join */
1186 if (*st == nullptr && station_to_join != INVALID_STATION) *st = T::GetIfValid(station_to_join);
1187
1188 return CommandCost();
1189 }
1190
1200 static CommandCost FindJoiningStation(StationID existing_station, StationID station_to_join, bool adjacent, TileArea ta, Station **st)
1201 {
1202 return FindJoiningBaseStation<Station, STR_ERROR_MUST_REMOVE_RAILWAY_STATION_FIRST>(existing_station, station_to_join, adjacent, ta, st);
1203 }
1204
1214 CommandCost FindJoiningWaypoint(StationID existing_waypoint, StationID waypoint_to_join, bool adjacent, TileArea ta, Waypoint **wp)
1215 {
1216 return FindJoiningBaseStation<Waypoint, STR_ERROR_MUST_REMOVE_RAILWAYPOINT_FIRST>(existing_waypoint, waypoint_to_join, adjacent, ta, wp);
1217 }
1218
1223 static void FreeTrainReservation(Train *v)
1224 {
1225 FreeTrainTrackReservation(v);
1226 if (IsRailStationTile(v->tile)) SetRailStationPlatformReservation(v->tile, TrackdirToExitdir(v->GetVehicleTrackdir()), false);
1227 v = v->Last();
1228 if (IsRailStationTile(v->tile)) SetRailStationPlatformReservation(v->tile, TrackdirToExitdir(ReverseTrackdir(v->GetVehicleTrackdir())), false);
1229 }
1230
1235 static void RestoreTrainReservation(Train *v)
1236 {
1237 if (IsRailStationTile(v->tile)) SetRailStationPlatformReservation(v->tile, TrackdirToExitdir(v->GetVehicleTrackdir()), true);
1238 TryPathReserve(v, true, true);
1239 v = v->Last();
1240 if (IsRailStationTile(v->tile)) SetRailStationPlatformReservation(v->tile, TrackdirToExitdir(ReverseTrackdir(v->GetVehicleTrackdir())), true);
1241 }
1242
1260 CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
1261 {
1262 /* Unpack parameters */
1263 RailType rt = Extract<RailType, 0, 6>(p1);
1264 Axis axis = Extract<Axis, 6, 1>(p1);
1265 byte numtracks = GB(p1, 8, 8);
1266 byte plat_len = GB(p1, 16, 8);
1267 bool adjacent = HasBit(p1, 24);
1268
1269 StationClassID spec_class = Extract<StationClassID, 0, 8>(p2);
1270 byte spec_index = GB(p2, 8, 8);
1271 StationID station_to_join = GB(p2, 16, 16);
1272
1273 /* Does the authority allow this? */
1274 CommandCost ret = CheckIfAuthorityAllowsNewStation(tile_org, flags);
1275 if (ret.Failed()) return ret;
1276
1277 if (!ValParamRailtype(rt)) return CMD_ERROR;
1278
1279 /* Check if the given station class is valid */
1280 if ((uint)spec_class >= StationClass::GetClassCount() || spec_class == STAT_CLASS_WAYP) return CMD_ERROR;
1281 if (spec_index >= StationClass::Get(spec_class)->GetSpecCount()) return CMD_ERROR;
1282 if (plat_len == 0 || numtracks == 0) return CMD_ERROR;
1283
1284 int w_org, h_org;
1285 if (axis == AXIS_X) {
1286 w_org = plat_len;
1287 h_org = numtracks;
1288 } else {
1289 h_org = plat_len;
1290 w_org = numtracks;
1291 }
1292
1293 bool reuse = (station_to_join != NEW_STATION);
1294 if (!reuse) station_to_join = INVALID_STATION;
1295 bool distant_join = (station_to_join != INVALID_STATION);
1296
1297 if (distant_join && (!_settings_game.station.distant_join_stations || !Station::IsValidID(station_to_join))) return CMD_ERROR;
1298
1299 if (h_org > _settings_game.station.station_spread || w_org > _settings_game.station.station_spread) return CMD_ERROR;
1300
1301 /* these values are those that will be stored in train_tile and station_platforms */
1302 TileArea new_location(tile_org, w_org, h_org);
1303
1304 /* Make sure the area below consists of clear tiles. (OR tiles belonging to a certain rail station) */
1305 StationID est = INVALID_STATION;
1306 std::vector<Train *> affected_vehicles;
1307 /* Clear the land below the station. */
1308 CommandCost cost = CheckFlatLandRailStation(new_location, flags, axis, &est, rt, affected_vehicles, spec_class, spec_index, plat_len, numtracks);
1309 if (cost.Failed()) return cost;
1310 /* Add construction expenses. */
1311 cost.AddCost((numtracks * _price[PR_BUILD_STATION_RAIL] + _price[PR_BUILD_STATION_RAIL_LENGTH]) * plat_len);
1312 cost.AddCost(numtracks * plat_len * RailBuildCost(rt));
1313
1314 Station *st = nullptr;
1315 ret = FindJoiningStation(est, station_to_join, adjacent, new_location, &st);
1316 if (ret.Failed()) return ret;
1317
1318 ret = BuildStationPart(&st, flags, reuse, new_location, STATIONNAMING_RAIL);
1319 if (ret.Failed()) return ret;
1320
1321 if (st != nullptr && st->train_station.tile != INVALID_TILE) {
1322 CommandCost ret = CanExpandRailStation(st, new_location, axis);
1323 if (ret.Failed()) return ret;
1324 }
1325
1326 /* Check if we can allocate a custom stationspec to this station */
1327 const StationSpec *statspec = StationClass::Get(spec_class)->GetSpec(spec_index);
1328 int specindex = AllocateSpecToStation(statspec, st, (flags & DC_EXEC) != 0);
1329 if (specindex == -1) return_cmd_error(STR_ERROR_TOO_MANY_STATION_SPECS);
1330
1331 if (statspec != nullptr) {
1332 /* Perform NewStation checks */
1333
1334 /* Check if the station size is permitted */
1335 if (HasBit(statspec->disallowed_platforms, std::min(numtracks - 1, 7)) || HasBit(statspec->disallowed_lengths, std::min(plat_len - 1, 7))) {
1336 return CMD_ERROR;
1337 }
1338
1339 /* Check if the station is buildable */
1340 if (HasBit(statspec->callback_mask, CBM_STATION_AVAIL)) {
1341 uint16 cb_res = GetStationCallback(CBID_STATION_AVAILABILITY, 0, 0, statspec, nullptr, INVALID_TILE);
1342 if (cb_res != CALLBACK_FAILED && !Convert8bitBooleanCallback(statspec->grf_prop.grffile, CBID_STATION_AVAILABILITY, cb_res)) return CMD_ERROR;
1343 }
1344 }
1345
1346 if (flags & DC_EXEC) {
1347 TileIndexDiff tile_delta;
1348 byte *layout_ptr;
1349 byte numtracks_orig;
1350 Track track;
1351
1352 st->train_station = new_location;
1353 st->AddFacility(FACIL_TRAIN, new_location.tile);
1354
1355 st->rect.BeforeAddRect(tile_org, w_org, h_org, StationRect::ADD_TRY);
1356
1357 if (statspec != nullptr) {
1358 /* Include this station spec's animation trigger bitmask
1359 * in the station's cached copy. */
1360 st->cached_anim_triggers |= statspec->animation.triggers;
1361 }
1362
1363 tile_delta = (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
1364 track = AxisToTrack(axis);
1365
1366 layout_ptr = AllocaM(byte, numtracks * plat_len);
1367 GetStationLayout(layout_ptr, numtracks, plat_len, statspec);
1368
1369 numtracks_orig = numtracks;
1370
1371 Company *c = Company::Get(st->owner);
1372 TileIndex tile_track = tile_org;
1373 do {
1374 TileIndex tile = tile_track;
1375 int w = plat_len;
1376 do {
1377 byte layout = *layout_ptr++;
1378 if (IsRailStationTile(tile) && HasStationReservation(tile)) {
1379 /* Check for trains having a reservation for this tile. */
1380 Train *v = GetTrainForReservation(tile, AxisToTrack(GetRailStationAxis(tile)));
1381 if (v != nullptr) {
1382 affected_vehicles.push_back(v);
1383 FreeTrainReservation(v);
1384 }
1385 }
1386
1387 /* Railtype can change when overbuilding. */
1388 if (IsRailStationTile(tile)) {
1389 if (!IsStationTileBlocked(tile)) c->infrastructure.rail[GetRailType(tile)]--;
1390 c->infrastructure.station--;
1391 }
1392
1393 /* Remove animation if overbuilding */
1394 DeleteAnimatedTile(tile);
1395 byte old_specindex = HasStationTileRail(tile) ? GetCustomStationSpecIndex(tile) : 0;
1396 MakeRailStation(tile, st->owner, st->index, axis, layout & ~1, rt);
1397 /* Free the spec if we overbuild something */
1398 DeallocateSpecFromStation(st, old_specindex);
1399
1400 SetCustomStationSpecIndex(tile, specindex);
1401 SetStationTileRandomBits(tile, GB(Random(), 0, 4));
1402 SetAnimationFrame(tile, 0);
1403
1404 if (!IsStationTileBlocked(tile)) c->infrastructure.rail[rt]++;
1405 c->infrastructure.station++;
1406
1407 if (statspec != nullptr) {
1408 /* Use a fixed axis for GetPlatformInfo as our platforms / numtracks are always the right way around */
1409 uint32 platinfo = GetPlatformInfo(AXIS_X, GetStationGfx(tile), plat_len, numtracks_orig, plat_len - w, numtracks_orig - numtracks, false);
1410
1411 /* As the station is not yet completely finished, the station does not yet exist. */
1412 uint16 callback = GetStationCallback(CBID_STATION_TILE_LAYOUT, platinfo, 0, statspec, nullptr, tile);
1413 if (callback != CALLBACK_FAILED) {
1414 if (callback < 8) {
1415 SetStationGfx(tile, (callback & ~1) + axis);
1416 } else {
1417 ErrorUnknownCallbackResult(statspec->grf_prop.grffile->grfid, CBID_STATION_TILE_LAYOUT, callback);
1418 }
1419 }
1420
1421 /* Trigger station animation -- after building? */
1422 TriggerStationAnimation(st, tile, SAT_BUILT);
1423 }
1424
1425 tile += tile_delta;
1426 } while (--w);
1427 AddTrackToSignalBuffer(tile_track, track, _current_company);
1428 YapfNotifyTrackLayoutChange(tile_track, track);
1429 tile_track += tile_delta ^ TileDiffXY(1, 1); // perpendicular to tile_delta
1430 } while (--numtracks);
1431
1432 for (uint i = 0; i < affected_vehicles.size(); ++i) {
1433 /* Restore reservations of trains. */
1434 RestoreTrainReservation(affected_vehicles[i]);
1435 }
1436
1437 /* Check whether we need to expand the reservation of trains already on the station. */
1438 TileArea update_reservation_area;
1439 if (axis == AXIS_X) {
1440 update_reservation_area = TileArea(tile_org, 1, numtracks_orig);
1441 } else {
1442 update_reservation_area = TileArea(tile_org, numtracks_orig, 1);
1443 }
1444
1445 for (TileIndex tile : update_reservation_area) {
1446 /* Don't even try to make eye candy parts reserved. */
1447 if (IsStationTileBlocked(tile)) continue;
1448
1449 DiagDirection dir = AxisToDiagDir(axis);
1450 TileIndexDiff tile_offset = TileOffsByDiagDir(dir);
1451 TileIndex platform_begin = tile;
1452 TileIndex platform_end = tile;
1453
1454 /* We can only account for tiles that are reachable from this tile, so ignore primarily blocked tiles while finding the platform begin and end. */
1455 for (TileIndex next_tile = platform_begin - tile_offset; IsCompatibleTrainStationTile(next_tile, platform_begin); next_tile -= tile_offset) {
1456 platform_begin = next_tile;
1457 }
1458 for (TileIndex next_tile = platform_end + tile_offset; IsCompatibleTrainStationTile(next_tile, platform_end); next_tile += tile_offset) {
1459 platform_end = next_tile;
1460 }
1461
1462 /* If there is at least on reservation on the platform, we reserve the whole platform. */
1463 bool reservation = false;
1464 for (TileIndex t = platform_begin; !reservation && t <= platform_end; t += tile_offset) {
1465 reservation = HasStationReservation(t);
1466 }
1467
1468 if (reservation) {
1469 SetRailStationPlatformReservation(platform_begin, dir, true);
1470 }
1471 }
1472
1473 st->MarkTilesDirty(false);
1474 st->AfterStationTileSetChange(true, STATION_RAIL);
1475 }
1476
1477 return cost;
1478 }
1479
1480 static TileArea MakeStationAreaSmaller(BaseStation *st, TileArea ta, bool (*func)(BaseStation *, TileIndex))
1481 {
1482 restart:
1483
1484 /* too small? */
1485 if (ta.w != 0 && ta.h != 0) {
1486 /* check the left side, x = constant, y changes */
1487 for (uint i = 0; !func(st, ta.tile + TileDiffXY(0, i));) {
1488 /* the left side is unused? */
1489 if (++i == ta.h) {
1490 ta.tile += TileDiffXY(1, 0);
1491 ta.w--;
1492 goto restart;
1493 }
1494 }
1495
1496 /* check the right side, x = constant, y changes */
1497 for (uint i = 0; !func(st, ta.tile + TileDiffXY(ta.w - 1, i));) {
1498 /* the right side is unused? */
1499 if (++i == ta.h) {
1500 ta.w--;
1501 goto restart;
1502 }
1503 }
1504
1505 /* check the upper side, y = constant, x changes */
1506 for (uint i = 0; !func(st, ta.tile + TileDiffXY(i, 0));) {
1507 /* the left side is unused? */
1508 if (++i == ta.w) {
1509 ta.tile += TileDiffXY(0, 1);
1510 ta.h--;
1511 goto restart;
1512 }
1513 }
1514
1515 /* check the lower side, y = constant, x changes */
1516 for (uint i = 0; !func(st, ta.tile + TileDiffXY(i, ta.h - 1));) {
1517 /* the left side is unused? */
1518 if (++i == ta.w) {
1519 ta.h--;
1520 goto restart;
1521 }
1522 }
1523 } else {
1524 ta.Clear();
1525 }
1526
1527 return ta;
1528 }
1529
1530 static bool TileBelongsToRailStation(BaseStation *st, TileIndex tile)
1531 {
1532 return st->TileBelongsToRailStation(tile);
1533 }
1534
1535 static void MakeRailStationAreaSmaller(BaseStation *st)
1536 {
1537 st->train_station = MakeStationAreaSmaller(st, st->train_station, TileBelongsToRailStation);
1538 }
1539
1540 static bool TileBelongsToShipStation(BaseStation *st, TileIndex tile)
1541 {
1542 return IsDockTile(tile) && GetStationIndex(tile) == st->index;
1543 }
1544
1545 static void MakeShipStationAreaSmaller(Station *st)
1546 {
1547 st->ship_station = MakeStationAreaSmaller(st, st->ship_station, TileBelongsToShipStation);
1548 UpdateStationDockingTiles(st);
1549 }
1550
1561 template <class T>
1562 CommandCost RemoveFromRailBaseStation(TileArea ta, std::vector<T *> &affected_stations, DoCommandFlag flags, Money removal_cost, bool keep_rail)
1563 {
1564 /* Count of the number of tiles removed */
1565 int quantity = 0;
1566 CommandCost total_cost(EXPENSES_CONSTRUCTION);
1567 /* Accumulator for the errors seen during clearing. If no errors happen,
1568 * and the quantity is 0 there is no station. Otherwise it will be one
1569 * of the other error that got accumulated. */
1570 CommandCost error;
1571
1572 /* Do the action for every tile into the area */
1573 for (TileIndex tile : ta) {
1574 /* Make sure the specified tile is a rail station */
1575 if (!HasStationTileRail(tile)) continue;
1576
1577 /* If there is a vehicle on ground, do not allow to remove (flood) the tile */
1578 CommandCost ret = EnsureNoVehicleOnGround(tile);
1579 error.AddCost(ret);
1580 if (ret.Failed()) continue;
1581
1582 /* Check ownership of station */
1583 T *st = T::GetByTile(tile);
1584 if (st == nullptr) continue;
1585
1586 if (_current_company != OWNER_WATER) {
1587 CommandCost ret = CheckOwnership(st->owner);
1588 error.AddCost(ret);
1589 if (ret.Failed()) continue;
1590 }
1591
1592 /* If we reached here, the tile is valid so increase the quantity of tiles we will remove */
1593 quantity++;
1594
1595 if (keep_rail || IsStationTileBlocked(tile)) {
1596 /* Don't refund the 'steel' of the track when we keep the
1597 * rail, or when the tile didn't have any rail at all. */
1598 total_cost.AddCost(-_price[PR_CLEAR_RAIL]);
1599 }
1600
1601 if (flags & DC_EXEC) {
1602 /* read variables before the station tile is removed */
1603 uint specindex = GetCustomStationSpecIndex(tile);
1604 Track track = GetRailStationTrack(tile);
1605 Owner owner = GetTileOwner(tile);
1606 RailType rt = GetRailType(tile);
1607 Train *v = nullptr;
1608
1609 if (HasStationReservation(tile)) {
1610 v = GetTrainForReservation(tile, track);
1611 if (v != nullptr) FreeTrainReservation(v);
1612 }
1613
1614 bool build_rail = keep_rail && !IsStationTileBlocked(tile);
1615 if (!build_rail && !IsStationTileBlocked(tile)) Company::Get(owner)->infrastructure.rail[rt]--;
1616
1617 DoClearSquare(tile);
1618 DeleteNewGRFInspectWindow(GSF_STATIONS, tile);
1619 if (build_rail) MakeRailNormal(tile, owner, TrackToTrackBits(track), rt);
1620 Company::Get(owner)->infrastructure.station--;
1621 DirtyCompanyInfrastructureWindows(owner);
1622
1623 st->rect.AfterRemoveTile(st, tile);
1624 AddTrackToSignalBuffer(tile, track, owner);
1625 YapfNotifyTrackLayoutChange(tile, track);
1626
1627 DeallocateSpecFromStation(st, specindex);
1628
1629 include(affected_stations, st);
1630
1631 if (v != nullptr) RestoreTrainReservation(v);
1632 }
1633 }
1634
1635 if (quantity == 0) return error.Failed() ? error : CommandCost(STR_ERROR_THERE_IS_NO_STATION);
1636
1637 for (T *st : affected_stations) {
1638
1639 /* now we need to make the "spanned" area of the railway station smaller
1640 * if we deleted something at the edges.
1641 * we also need to adjust train_tile. */
1642 MakeRailStationAreaSmaller(st);
1643 UpdateStationSignCoord(st);
1644
1645 /* if we deleted the whole station, delete the train facility. */
1646 if (st->train_station.tile == INVALID_TILE) {
1647 st->facilities &= ~FACIL_TRAIN;
1648 SetWindowWidgetDirty(WC_STATION_VIEW, st->index, WID_SV_TRAINS);
1649 MarkCatchmentTilesDirty();
1650 st->UpdateVirtCoord();
1651 DeleteStationIfEmpty(st);
1652 }
1653 }
1654
1655 total_cost.AddCost(quantity * removal_cost);
1656 return total_cost;
1657 }
1658
1670 CommandCost CmdRemoveFromRailStation(TileIndex start, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
1671 {
1672 TileIndex end = p1 == 0 ? start : p1;
1673 if (start >= MapSize() || end >= MapSize()) return CMD_ERROR;
1674
1675 TileArea ta(start, end);
1676 std::vector<Station *> affected_stations;
1677
1678 CommandCost ret = RemoveFromRailBaseStation(ta, affected_stations, flags, _price[PR_CLEAR_STATION_RAIL], HasBit(p2, 0));
1679 if (ret.Failed()) return ret;
1680
1681 /* Do all station specific functions here. */
1682 for (Station *st : affected_stations) {
1683
1684 if (st->train_station.tile == INVALID_TILE) SetWindowWidgetDirty(WC_STATION_VIEW, st->index, WID_SV_TRAINS);
1685 st->MarkTilesDirty(false);
1686 MarkCatchmentTilesDirty();
1687 st->RecomputeCatchment();
1688 }
1689
1690 /* Now apply the rail cost to the number that we deleted */
1691 return ret;
1692 }
1693
1705 CommandCost CmdRemoveFromRailWaypoint(TileIndex start, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
1706 {
1707 TileIndex end = p1 == 0 ? start : p1;
1708 if (start >= MapSize() || end >= MapSize()) return CMD_ERROR;
1709
1710 TileArea ta(start, end);
1711 std::vector<Waypoint *> affected_stations;
1712
1713 return RemoveFromRailBaseStation(ta, affected_stations, flags, _price[PR_CLEAR_WAYPOINT_RAIL], HasBit(p2, 0));
1714 }
1715
1716
1725 template <class T>
1726 CommandCost RemoveRailStation(T *st, DoCommandFlag flags, Money removal_cost)
1727 {
1728 /* Current company owns the station? */
1729 if (_current_company != OWNER_WATER) {
1730 CommandCost ret = CheckOwnership(st->owner);
1731 if (ret.Failed()) return ret;
1732 }
1733
1734 /* determine width and height of platforms */
1735 TileArea ta = st->train_station;
1736
1737 assert(ta.w != 0 && ta.h != 0);
1738
1739 CommandCost cost(EXPENSES_CONSTRUCTION);
1740 /* clear all areas of the station */
1741 for (TileIndex tile : ta) {
1742 /* only remove tiles that are actually train station tiles */
1743 if (st->TileBelongsToRailStation(tile)) {
1744 std::vector<T*> affected_stations; // dummy
1745 CommandCost ret = RemoveFromRailBaseStation(TileArea(tile, 1, 1), affected_stations, flags, removal_cost, false);
1746 if (ret.Failed()) return ret;
1747 cost.AddCost(ret);
1748 }
1749 }
1750
1751 return cost;
1752 }
1753
1760 static CommandCost RemoveRailStation(TileIndex tile, DoCommandFlag flags)
1761 {
1762 /* if there is flooding, remove platforms tile by tile */
1763 if (_current_company == OWNER_WATER) {
1764 return DoCommand(tile, 0, 0, DC_EXEC, CMD_REMOVE_FROM_RAIL_STATION);
1765 }
1766
1767 Station *st = Station::GetByTile(tile);
1768 CommandCost cost = RemoveRailStation(st, flags, _price[PR_CLEAR_STATION_RAIL]);
1769
1770 if (flags & DC_EXEC) st->RecomputeCatchment();
1771
1772 return cost;
1773 }
1774
1781 static CommandCost RemoveRailWaypoint(TileIndex tile, DoCommandFlag flags)
1782 {
1783 /* if there is flooding, remove waypoints tile by tile */
1784 if (_current_company == OWNER_WATER) {
1785 return DoCommand(tile, 0, 0, DC_EXEC, CMD_REMOVE_FROM_RAIL_WAYPOINT);
1786 }
1787
1788 return RemoveRailStation(Waypoint::GetByTile(tile), flags, _price[PR_CLEAR_WAYPOINT_RAIL]);
1789 }
1790
1791
1797 static RoadStop **FindRoadStopSpot(bool truck_station, Station *st)
1798 {
1799 RoadStop **primary_stop = (truck_station) ? &st->truck_stops : &st->bus_stops;
1800
1801 if (*primary_stop == nullptr) {
1802 /* we have no roadstop of the type yet, so write a "primary stop" */
1803 return primary_stop;
1804 } else {
1805 /* there are stops already, so append to the end of the list */
1806 RoadStop *stop = *primary_stop;
1807 while (stop->next != nullptr) stop = stop->next;
1808 return &stop->next;
1809 }
1810 }
1811
1812 static CommandCost RemoveRoadStop(TileIndex tile, DoCommandFlag flags);
1813
1823 static CommandCost FindJoiningRoadStop(StationID existing_stop, StationID station_to_join, bool adjacent, TileArea ta, Station **st)
1824 {
1825 return FindJoiningBaseStation<Station, STR_ERROR_MUST_REMOVE_ROAD_STOP_FIRST>(existing_stop, station_to_join, adjacent, ta, st);
1826 }
1827
1844 CommandCost CmdBuildRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
1845 {
1846 bool type = HasBit(p2, 0);
1847 bool is_drive_through = HasBit(p2, 1);
1848 RoadType rt = Extract<RoadType, 5, 6>(p2);
1849 if (!ValParamRoadType(rt)) return CMD_ERROR;
1850 StationID station_to_join = GB(p2, 16, 16);
1851 bool reuse = (station_to_join != NEW_STATION);
1852 if (!reuse) station_to_join = INVALID_STATION;
1853 bool distant_join = (station_to_join != INVALID_STATION);
1854
1855 uint8 width = (uint8)GB(p1, 0, 8);
1856 uint8 length = (uint8)GB(p1, 8, 8);
1857
1858 /* Check if the requested road stop is too big */
1859 if (width > _settings_game.station.station_spread || length > _settings_game.station.station_spread) return_cmd_error(STR_ERROR_STATION_TOO_SPREAD_OUT);
1860 /* Check for incorrect width / length. */
1861 if (width == 0 || length == 0) return CMD_ERROR;
1862 /* Check if the first tile and the last tile are valid */
1863 if (!IsValidTile(tile) || TileAddWrap(tile, width - 1, length - 1) == INVALID_TILE) return CMD_ERROR;
1864
1865 TileArea roadstop_area(tile, width, length);
1866
1867 if (distant_join && (!_settings_game.station.distant_join_stations || !Station::IsValidID(station_to_join))) return CMD_ERROR;
1868
1869 /* Trams only have drive through stops */
1870 if (!is_drive_through && RoadTypeIsTram(rt)) return CMD_ERROR;
1871
1872 DiagDirection ddir;
1873 Axis axis;
1874 if (is_drive_through) {
1875 /* By definition axis is valid, due to there being 2 axes and reading 1 bit. */
1876 axis = Extract<Axis, 3, 1>(p2);
1877 ddir = AxisToDiagDir(axis);
1878 } else {
1879 /* By definition ddir is valid, due to there being 4 diagonal directions and reading 2 bits. */
1880 ddir = Extract<DiagDirection, 3, 2>(p2);
1881 axis = DiagDirToAxis(ddir);
1882 }
1883
1884 CommandCost ret = CheckIfAuthorityAllowsNewStation(tile, flags);
1885 if (ret.Failed()) return ret;
1886
1887 /* Total road stop cost. */
1888 CommandCost cost(EXPENSES_CONSTRUCTION, roadstop_area.w * roadstop_area.h * _price[type ? PR_BUILD_STATION_TRUCK : PR_BUILD_STATION_BUS]);
1889 StationID est = INVALID_STATION;
1890 ret = CheckFlatLandRoadStop(roadstop_area, flags, is_drive_through ? 5 << axis : 1 << ddir, is_drive_through, type, axis, &est, rt);
1891 if (ret.Failed()) return ret;
1892 cost.AddCost(ret);
1893
1894 Station *st = nullptr;
1895 ret = FindJoiningRoadStop(est, station_to_join, HasBit(p2, 2), roadstop_area, &st);
1896 if (ret.Failed()) return ret;
1897
1898 /* Check if this number of road stops can be allocated. */
1899 if (!RoadStop::CanAllocateItem(roadstop_area.w * roadstop_area.h)) return_cmd_error(type ? STR_ERROR_TOO_MANY_TRUCK_STOPS : STR_ERROR_TOO_MANY_BUS_STOPS);
1900
1901 ret = BuildStationPart(&st, flags, reuse, roadstop_area, STATIONNAMING_ROAD);
1902 if (ret.Failed()) return ret;
1903
1904 if (flags & DC_EXEC) {
1905 /* Check every tile in the area. */
1906 for (TileIndex cur_tile : roadstop_area) {
1907 /* Get existing road types and owners before any tile clearing */
1908 RoadType road_rt = MayHaveRoad(cur_tile) ? GetRoadType(cur_tile, RTT_ROAD) : INVALID_ROADTYPE;
1909 RoadType tram_rt = MayHaveRoad(cur_tile) ? GetRoadType(cur_tile, RTT_TRAM) : INVALID_ROADTYPE;
1910 Owner road_owner = road_rt != INVALID_ROADTYPE ? GetRoadOwner(cur_tile, RTT_ROAD) : _current_company;
1911 Owner tram_owner = tram_rt != INVALID_ROADTYPE ? GetRoadOwner(cur_tile, RTT_TRAM) : _current_company;
1912
1913 if (IsTileType(cur_tile, MP_STATION) && IsRoadStop(cur_tile)) {
1914 RemoveRoadStop(cur_tile, flags);
1915 }
1916
1917 RoadStop *road_stop = new RoadStop(cur_tile);
1918 /* Insert into linked list of RoadStops. */
1919 RoadStop **currstop = FindRoadStopSpot(type, st);
1920 *currstop = road_stop;
1921
1922 if (type) {
1923 st->truck_station.Add(cur_tile);
1924 } else {
1925 st->bus_station.Add(cur_tile);
1926 }
1927
1928 /* Initialize an empty station. */
1929 st->AddFacility((type) ? FACIL_TRUCK_STOP : FACIL_BUS_STOP, cur_tile);
1930
1931 st->rect.BeforeAddTile(cur_tile, StationRect::ADD_TRY);
1932
1933 RoadStopType rs_type = type ? ROADSTOP_TRUCK : ROADSTOP_BUS;
1934 if (is_drive_through) {
1935 /* Update company infrastructure counts. If the current tile is a normal road tile, remove the old
1936 * bits first. */
1937 if (IsNormalRoadTile(cur_tile)) {
1938 UpdateCompanyRoadInfrastructure(road_rt, road_owner, -(int)CountBits(GetRoadBits(cur_tile, RTT_ROAD)));
1939 UpdateCompanyRoadInfrastructure(tram_rt, tram_owner, -(int)CountBits(GetRoadBits(cur_tile, RTT_TRAM)));
1940 }
1941
1942 if (road_rt == INVALID_ROADTYPE && RoadTypeIsRoad(rt)) road_rt = rt;
1943 if (tram_rt == INVALID_ROADTYPE && RoadTypeIsTram(rt)) tram_rt = rt;
1944
1945 UpdateCompanyRoadInfrastructure(road_rt, road_owner, ROAD_STOP_TRACKBIT_FACTOR);
1946 UpdateCompanyRoadInfrastructure(tram_rt, tram_owner, ROAD_STOP_TRACKBIT_FACTOR);
1947
1948 MakeDriveThroughRoadStop(cur_tile, st->owner, road_owner, tram_owner, st->index, rs_type, road_rt, tram_rt, axis);
1949 road_stop->MakeDriveThrough();
1950 } else {
1951 if (road_rt == INVALID_ROADTYPE && RoadTypeIsRoad(rt)) road_rt = rt;
1952 if (tram_rt == INVALID_ROADTYPE && RoadTypeIsTram(rt)) tram_rt = rt;
1953 /* Non-drive-through stop never overbuild and always count as two road bits. */
1954 Company::Get(st->owner)->infrastructure.road[rt] += ROAD_STOP_TRACKBIT_FACTOR;
1955 MakeRoadStop(cur_tile, st->owner, st->index, rs_type, road_rt, tram_rt, ddir);
1956 }
1957 Company::Get(st->owner)->infrastructure.station++;
1958
1959 MarkTileDirtyByTile(cur_tile);
1960 }
1961
1962 if (st != nullptr) {
1963 st->AfterStationTileSetChange(true, type ? STATION_TRUCK: STATION_BUS);
1964 }
1965 }
1966 return cost;
1967 }
1968
1969
1970 static Vehicle *ClearRoadStopStatusEnum(Vehicle *v, void *)
1971 {
1972 if (v->type == VEH_ROAD) {
1973 /* Okay... we are a road vehicle on a drive through road stop.
1974 * But that road stop has just been removed, so we need to make
1975 * sure we are in a valid state... however, vehicles can also
1976 * turn on road stop tiles, so only clear the 'road stop' state
1977 * bits and only when the state was 'in road stop', otherwise
1978 * we'll end up clearing the turn around bits. */
1979 RoadVehicle *rv = RoadVehicle::From(v);
1980 if (HasBit(rv->state, RVS_IN_DT_ROAD_STOP)) rv->state &= RVSB_ROAD_STOP_TRACKDIR_MASK;
1981 }
1982
1983 return nullptr;
1984 }
1985
1986
1993 static CommandCost RemoveRoadStop(TileIndex tile, DoCommandFlag flags)
1994 {
1995 Station *st = Station::GetByTile(tile);
1996
1997 if (_current_company != OWNER_WATER) {
1998 CommandCost ret = CheckOwnership(st->owner);
1999 if (ret.Failed()) return ret;
2000 }
2001
2002 bool is_truck = IsTruckStop(tile);
2003
2004 RoadStop **primary_stop;
2005 RoadStop *cur_stop;
2006 if (is_truck) { // truck stop
2007 primary_stop = &st->truck_stops;
2008 cur_stop = RoadStop::GetByTile(tile, ROADSTOP_TRUCK);
2009 } else {
2010 primary_stop = &st->bus_stops;
2011 cur_stop = RoadStop::GetByTile(tile, ROADSTOP_BUS);
2012 }
2013
2014 assert(cur_stop != nullptr);
2015
2016 /* don't do the check for drive-through road stops when company bankrupts */
2017 if (IsDriveThroughStopTile(tile) && (flags & DC_BANKRUPT)) {
2018 /* remove the 'going through road stop' status from all vehicles on that tile */
2019 if (flags & DC_EXEC) FindVehicleOnPos(tile, nullptr, &ClearRoadStopStatusEnum);
2020 } else {
2021 CommandCost ret = EnsureNoVehicleOnGround(tile);
2022 if (ret.Failed()) return ret;
2023 }
2024
2025 if (flags & DC_EXEC) {
2026 if (*primary_stop == cur_stop) {
2027 /* removed the first stop in the list */
2028 *primary_stop = cur_stop->next;
2029 /* removed the only stop? */
2030 if (*primary_stop == nullptr) {
2031 st->facilities &= (is_truck ? ~FACIL_TRUCK_STOP : ~FACIL_BUS_STOP);
2032 }
2033 } else {
2034 /* tell the predecessor in the list to skip this stop */
2035 RoadStop *pred = *primary_stop;
2036 while (pred->next != cur_stop) pred = pred->next;
2037 pred->next = cur_stop->next;
2038 }
2039
2040 /* Update company infrastructure counts. */
2041 for (RoadTramType rtt : _roadtramtypes) {
2042 RoadType rt = GetRoadType(tile, rtt);
2043 UpdateCompanyRoadInfrastructure(rt, GetRoadOwner(tile, rtt), -static_cast<int>(ROAD_STOP_TRACKBIT_FACTOR));
2044 }
2045
2046 Company::Get(st->owner)->infrastructure.station--;
2047 DirtyCompanyInfrastructureWindows(st->owner);
2048
2049 if (IsDriveThroughStopTile(tile)) {
2050 /* Clears the tile for us */
2051 cur_stop->ClearDriveThrough();
2052 } else {
2053 DoClearSquare(tile);
2054 }
2055
2056 delete cur_stop;
2057
2058 /* Make sure no vehicle is going to the old roadstop */
2059 for (RoadVehicle *v : RoadVehicle::Iterate()) {
2060 if (v->First() == v && v->current_order.IsType(OT_GOTO_STATION) &&
2061 v->dest_tile == tile) {
2062 v->SetDestTile(v->GetOrderStationLocation(st->index));
2063 }
2064 }
2065
2066 st->rect.AfterRemoveTile(st, tile);
2067
2068 st->AfterStationTileSetChange(false, is_truck ? STATION_TRUCK: STATION_BUS);
2069
2070 /* Update the tile area of the truck/bus stop */
2071 if (is_truck) {
2072 st->truck_station.Clear();
2073 for (const RoadStop *rs = st->truck_stops; rs != nullptr; rs = rs->next) st->truck_station.Add(rs->xy);
2074 } else {
2075 st->bus_station.Clear();
2076 for (const RoadStop *rs = st->bus_stops; rs != nullptr; rs = rs->next) st->bus_station.Add(rs->xy);
2077 }
2078 }
2079
2080 return CommandCost(EXPENSES_CONSTRUCTION, _price[is_truck ? PR_CLEAR_STATION_TRUCK : PR_CLEAR_STATION_BUS]);
2081 }
2082
2094 CommandCost CmdRemoveRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
2095 {
2096 uint8 width = (uint8)GB(p1, 0, 8);
2097 uint8 height = (uint8)GB(p1, 8, 8);
2098 bool keep_drive_through_roads = !HasBit(p2, 1);
2099
2100 /* Check for incorrect width / height. */
2101 if (width == 0 || height == 0) return CMD_ERROR;
2102 /* Check if the first tile and the last tile are valid */
2103 if (!IsValidTile(tile) || TileAddWrap(tile, width - 1, height - 1) == INVALID_TILE) return CMD_ERROR;
2104 /* Bankrupting company is not supposed to remove roads, there may be road vehicles. */
2105 if (!keep_drive_through_roads && (flags & DC_BANKRUPT)) return CMD_ERROR;
2106
2107 TileArea roadstop_area(tile, width, height);
2108
2109 CommandCost cost(EXPENSES_CONSTRUCTION);
2110 CommandCost last_error(STR_ERROR_THERE_IS_NO_STATION);
2111 bool had_success = false;
2112
2113 for (TileIndex cur_tile : roadstop_area) {
2114 /* Make sure the specified tile is a road stop of the correct type */
2115 if (!IsTileType(cur_tile, MP_STATION) || !IsRoadStop(cur_tile) || (uint32)GetRoadStopType(cur_tile) != GB(p2, 0, 1)) continue;
2116
2117 /* Save information on to-be-restored roads before the stop is removed. */
2118 RoadBits road_bits = ROAD_NONE;
2119 RoadType road_type[] = { INVALID_ROADTYPE, INVALID_ROADTYPE };
2120 Owner road_owner[] = { OWNER_NONE, OWNER_NONE };
2121 if (IsDriveThroughStopTile(cur_tile)) {
2122 for (RoadTramType rtt : _roadtramtypes) {
2123 road_type[rtt] = GetRoadType(cur_tile, rtt);
2124 if (road_type[rtt] == INVALID_ROADTYPE) continue;
2125 road_owner[rtt] = GetRoadOwner(cur_tile, rtt);
2126 /* If we don't want to preserve our roads then restore only roads of others. */
2127 if (!keep_drive_through_roads && road_owner[rtt] == _current_company) road_type[rtt] = INVALID_ROADTYPE;
2128 }
2129 road_bits = AxisToRoadBits(DiagDirToAxis(GetRoadStopDir(cur_tile)));
2130 }
2131
2132 CommandCost ret = RemoveRoadStop(cur_tile, flags);
2133 if (ret.Failed()) {
2134 last_error = ret;
2135 continue;
2136 }
2137 cost.AddCost(ret);
2138 had_success = true;
2139
2140 /* Restore roads. */
2141 if ((flags & DC_EXEC) && (road_type[RTT_ROAD] != INVALID_ROADTYPE || road_type[RTT_TRAM] != INVALID_ROADTYPE)) {
2142 MakeRoadNormal(cur_tile, road_bits, road_type[RTT_ROAD], road_type[RTT_TRAM], ClosestTownFromTile(cur_tile, UINT_MAX)->index,
2143 road_owner[RTT_ROAD], road_owner[RTT_TRAM]);
2144
2145 /* Update company infrastructure counts. */
2146 int count = CountBits(road_bits);
2147 UpdateCompanyRoadInfrastructure(road_type[RTT_ROAD], road_owner[RTT_ROAD], count);
2148 UpdateCompanyRoadInfrastructure(road_type[RTT_TRAM], road_owner[RTT_TRAM], count);
2149 }
2150 }
2151
2152 return had_success ? cost : last_error;
2153 }
2154
2163 uint8 GetAirportNoiseLevelForDistance(const AirportSpec *as, uint distance)
2164 {
2165 /* 0 cannot be accounted, and 1 is the lowest that can be reduced from town.
2166 * So no need to go any further*/
2167 if (as->noise_level < 2) return as->noise_level;
2168
2169 /* The steps for measuring noise reduction are based on the "magical" (and arbitrary) 8 base distance
2170 * adding the town_council_tolerance 4 times, as a way to graduate, depending of the tolerance.
2171 * Basically, it says that the less tolerant a town is, the bigger the distance before
2172 * an actual decrease can be granted */
2173 uint8 town_tolerance_distance = 8 + (_settings_game.difficulty.town_council_tolerance * 4);
2174
2175 /* now, we want to have the distance segmented using the distance judged bareable by town
2176 * This will give us the coefficient of reduction the distance provides. */
2177 uint noise_reduction = distance / town_tolerance_distance;
2178
2179 /* If the noise reduction equals the airport noise itself, don't give it for free.
2180 * Otherwise, simply reduce the airport's level. */
2181 return noise_reduction >= as->noise_level ? 1 : as->noise_level - noise_reduction;
2182 }
2183
2192 Town *AirportGetNearestTown(const AirportSpec *as, const TileIterator &it, uint &mindist)
2193 {
2194 assert(Town::GetNumItems() > 0);
2195
2196 Town *nearest = nullptr;
2197
2198 uint perimeter_min_x = TileX(it);
2199 uint perimeter_min_y = TileY(it);
2200 uint perimeter_max_x = perimeter_min_x + as->size_x - 1;
2201 uint perimeter_max_y = perimeter_min_y + as->size_y - 1;
2202
2203 mindist = UINT_MAX - 1; // prevent overflow
2204
2205 std::unique_ptr<TileIterator> copy(it.Clone());
2206 for (TileIndex cur_tile = *copy; cur_tile != INVALID_TILE; cur_tile = ++*copy) {
2207 if (TileX(cur_tile) == perimeter_min_x || TileX(cur_tile) == perimeter_max_x || TileY(cur_tile) == perimeter_min_y || TileY(cur_tile) == perimeter_max_y) {
2208 Town *t = CalcClosestTownFromTile(cur_tile, mindist + 1);
2209 if (t == nullptr) continue;
2210
2211 uint dist = DistanceManhattan(t->xy, cur_tile);
2212 if (dist == mindist && t->index < nearest->index) nearest = t;
2213 if (dist < mindist) {
2214 nearest = t;
2215 mindist = dist;
2216 }
2217 }
2218 }
2219
2220 return nearest;
2221 }
2222
2223
2225 void UpdateAirportsNoise()
2226 {
2227 for (Town *t : Town::Iterate()) t->noise_reached = 0;
2228
2229 for (const Station *st : Station::Iterate()) {
2230 if (st->airport.tile != INVALID_TILE && st->airport.type != AT_OILRIG) {
2231 const AirportSpec *as = st->airport.GetSpec();
2232 AirportTileIterator it(st);
2233 uint dist;
2234 Town *nearest = AirportGetNearestTown(as, it, dist);
2235 nearest->noise_reached += GetAirportNoiseLevelForDistance(as, dist);
2236 }
2237 }
2238 }
2239
2253 CommandCost CmdBuildAirport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
2254 {
2255 StationID station_to_join = GB(p2, 16, 16);
2256 bool reuse = (station_to_join != NEW_STATION);
2257 if (!reuse) station_to_join = INVALID_STATION;
2258 bool distant_join = (station_to_join != INVALID_STATION);
2259 byte airport_type = GB(p1, 0, 8);
2260 byte layout = GB(p1, 8, 8);
2261
2262 if (distant_join && (!_settings_game.station.distant_join_stations || !Station::IsValidID(station_to_join))) return CMD_ERROR;
2263
2264 if (airport_type >= NUM_AIRPORTS) return CMD_ERROR;
2265
2266 CommandCost ret = CheckIfAuthorityAllowsNewStation(tile, flags);
2267 if (ret.Failed()) return ret;
2268
2269 /* Check if a valid, buildable airport was chosen for construction */
2270 const AirportSpec *as = AirportSpec::Get(airport_type);
2271 if (!as->IsAvailable() || layout >= as->num_table) return CMD_ERROR;
2272 if (!as->IsWithinMapBounds(layout, tile)) return CMD_ERROR;
2273
2274 Direction rotation = as->rotation[layout];
2275 int w = as->size_x;
2276 int h = as->size_y;
2277 if (rotation == DIR_E || rotation == DIR_W) Swap(w, h);
2278 TileArea airport_area = TileArea(tile, w, h);
2279
2280 if (w > _settings_game.station.station_spread || h > _settings_game.station.station_spread) {
2281 return_cmd_error(STR_ERROR_STATION_TOO_SPREAD_OUT);
2282 }
2283
2284 AirportTileTableIterator iter(as->table[layout], tile);
2285 CommandCost cost = CheckFlatLandAirport(iter, flags);
2286 if (cost.Failed()) return cost;
2287
2288 /* The noise level is the noise from the airport and reduce it to account for the distance to the town center. */
2289 uint dist;
2290 Town *nearest = AirportGetNearestTown(as, iter, dist);
2291 uint newnoise_level = GetAirportNoiseLevelForDistance(as, dist);
2292
2293 /* Check if local auth would allow a new airport */
2294 StringID authority_refuse_message = STR_NULL;
2295 Town *authority_refuse_town = nullptr;
2296
2297 if (_settings_game.economy.station_noise_level) {
2298 /* do not allow to build a new airport if this raise the town noise over the maximum allowed by town */
2299 if ((nearest->noise_reached + newnoise_level) > nearest->MaxTownNoise()) {
2300 authority_refuse_message = STR_ERROR_LOCAL_AUTHORITY_REFUSES_NOISE;
2301 authority_refuse_town = nearest;
2302 }
2303 } else {
2304 Town *t = ClosestTownFromTile(tile, UINT_MAX);
2305 uint num = 0;
2306 for (const Station *st : Station::Iterate()) {
2307 if (st->town == t && (st->facilities & FACIL_AIRPORT) && st->airport.type != AT_OILRIG) num++;
2308 }
2309 if (num >= 2) {
2310 authority_refuse_message = STR_ERROR_LOCAL_AUTHORITY_REFUSES_AIRPORT;
2311 authority_refuse_town = t;
2312 }
2313 }
2314
2315 if (authority_refuse_message != STR_NULL) {
2316 SetDParam(0, authority_refuse_town->index);
2317 return_cmd_error(authority_refuse_message);
2318 }
2319
2320 Station *st = nullptr;
2321 ret = FindJoiningStation(INVALID_STATION, station_to_join, HasBit(p2, 0), airport_area, &st);
2322 if (ret.Failed()) return ret;
2323
2324 /* Distant join */
2325 if (st == nullptr && distant_join) st = Station::GetIfValid(station_to_join);
2326
2327 ret = BuildStationPart(&st, flags, reuse, airport_area, (GetAirport(airport_type)->flags & AirportFTAClass::AIRPLANES) ? STATIONNAMING_AIRPORT : STATIONNAMING_HELIPORT);
2328 if (ret.Failed()) return ret;
2329
2330 if (st != nullptr && st->airport.tile != INVALID_TILE) {
2331 return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_AIRPORT);
2332 }
2333
2334 for (AirportTileTableIterator iter(as->table[layout], tile); iter != INVALID_TILE; ++iter) {
2335 cost.AddCost(_price[PR_BUILD_STATION_AIRPORT]);
2336 }
2337
2338 if (flags & DC_EXEC) {
2339 /* Always add the noise, so there will be no need to recalculate when option toggles */
2340 nearest->noise_reached += newnoise_level;
2341
2342 st->AddFacility(FACIL_AIRPORT, tile);
2343 st->airport.type = airport_type;
2344 st->airport.layout = layout;
2345 st->airport.flags = 0;
2346 st->airport.rotation = rotation;
2347
2348 st->rect.BeforeAddRect(tile, w, h, StationRect::ADD_TRY);
2349
2350 for (AirportTileTableIterator iter(as->table[layout], tile); iter != INVALID_TILE; ++iter) {
2351 MakeAirport(iter, st->owner, st->index, iter.GetStationGfx(), WATER_CLASS_INVALID);
2352 SetStationTileRandomBits(iter, GB(Random(), 0, 4));
2353 st->airport.Add(iter);
2354
2355 if (AirportTileSpec::Get(GetTranslatedAirportTileID(iter.GetStationGfx()))->animation.status != ANIM_STATUS_NO_ANIMATION) AddAnimatedTile(iter);
2356 }
2357
2358 /* Only call the animation trigger after all tiles have been built */
2359 for (AirportTileTableIterator iter(as->table[layout], tile); iter != INVALID_TILE; ++iter) {
2360 AirportTileAnimationTrigger(st, iter, AAT_BUILT);
2361 }
2362
2363 UpdateAirplanesOnNewStation(st);
2364
2365 Company::Get(st->owner)->infrastructure.airport++;
2366
2367 st->AfterStationTileSetChange(true, STATION_AIRPORT);
2368 InvalidateWindowData(WC_STATION_VIEW, st->index, -1);
2369
2370 if (_settings_game.economy.station_noise_level) {
2371 SetWindowDirty(WC_TOWN_VIEW, nearest->index);
2372 }
2373 }
2374
2375 return cost;
2376 }
2377
2384 static CommandCost RemoveAirport(TileIndex tile, DoCommandFlag flags)
2385 {
2386 Station *st = Station::GetByTile(tile);
2387
2388 if (_current_company != OWNER_WATER) {
2389 CommandCost ret = CheckOwnership(st->owner);
2390 if (ret.Failed()) return ret;
2391 }
2392
2393 tile = st->airport.tile;
2394
2395 CommandCost cost(EXPENSES_CONSTRUCTION);
2396
2397 for (const Aircraft *a : Aircraft::Iterate()) {
2398 if (!a->IsNormalAircraft()) continue;
2399 if (a->targetairport == st->index && a->state != FLYING) {
2400 return_cmd_error(STR_ERROR_AIRCRAFT_IN_THE_WAY);
2401 }
2402 }
2403
2404 if (flags & DC_EXEC) {
2405 for (uint i = 0; i < st->airport.GetNumHangars(); ++i) {
2406 TileIndex tile_cur = st->airport.GetHangarTile(i);
2407 OrderBackup::Reset(tile_cur, false);
2408 CloseWindowById(WC_VEHICLE_DEPOT, tile_cur);
2409 }
2410
2411 const AirportSpec *as = st->airport.GetSpec();
2412 /* The noise level is the noise from the airport and reduce it to account for the distance to the town center.
2413 * And as for construction, always remove it, even if the setting is not set, in order to avoid the
2414 * need of recalculation */
2415 AirportTileIterator it(st);
2416 uint dist;
2417 Town *nearest = AirportGetNearestTown(as, it, dist);
2418 nearest->noise_reached -= GetAirportNoiseLevelForDistance(as, dist);
2419
2420 if (_settings_game.economy.station_noise_level) {
2421 SetWindowDirty(WC_TOWN_VIEW, nearest->index);
2422 }
2423 }
2424
2425 for (TileIndex tile_cur : st->airport) {
2426 if (!st->TileBelongsToAirport(tile_cur)) continue;
2427
2428 CommandCost ret = EnsureNoVehicleOnGround(tile_cur);
2429 if (ret.Failed()) return ret;
2430
2431 cost.AddCost(_price[PR_CLEAR_STATION_AIRPORT]);
2432
2433 if (flags & DC_EXEC) {
2434 DeleteAnimatedTile(tile_cur);
2435 DoClearSquare(tile_cur);
2436 DeleteNewGRFInspectWindow(GSF_AIRPORTTILES, tile_cur);
2437 }
2438 }
2439
2440 if (flags & DC_EXEC) {
2441 /* Clear the persistent storage. */
2442 delete st->airport.psa;
2443
2444 st->rect.AfterRemoveRect(st, st->airport);
2445
2446 st->airport.Clear();
2447 st->facilities &= ~FACIL_AIRPORT;
2448
2449 InvalidateWindowData(WC_STATION_VIEW, st->index, -1);
2450
2451 Company::Get(st->owner)->infrastructure.airport--;
2452
2453 st->AfterStationTileSetChange(false, STATION_AIRPORT);
2454
2455 DeleteNewGRFInspectWindow(GSF_AIRPORTS, st->index);
2456 }
2457
2458 return cost;
2459 }
2460
2470 CommandCost CmdOpenCloseAirport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
2471 {
2472 if (!Station::IsValidID(p1)) return CMD_ERROR;
2473 Station *st = Station::Get(p1);
2474
2475 if (!(st->facilities & FACIL_AIRPORT) || st->owner == OWNER_NONE) return CMD_ERROR;
2476
2477 CommandCost ret = CheckOwnership(st->owner);
2478 if (ret.Failed()) return ret;
2479
2480 if (flags & DC_EXEC) {
2481 st->airport.flags ^= AIRPORT_CLOSED_block;
2482 SetWindowWidgetDirty(WC_STATION_VIEW, st->index, WID_SV_CLOSE_AIRPORT);
2483 }
2484 return CommandCost();
2485 }
2486
2493 bool HasStationInUse(StationID station, bool include_company, CompanyID company)
2494 {
2495 for (const Vehicle *v : Vehicle::Iterate()) {
2496 if ((v->owner == company) == include_company) {
2497 for (const Order *order : v->Orders()) {
2498 if ((order->IsType(OT_GOTO_STATION) || order->IsType(OT_GOTO_WAYPOINT)) && order->GetDestination() == station) {
2499 return true;
2500 }
2501 }
2502 }
2503 }
2504 return false;
2505 }
2506
2507 static const TileIndexDiffC _dock_tileoffs_chkaround[] = {
2508 {-1, 0},
2509 { 0, 0},
2510 { 0, 0},
2511 { 0, -1}
2512 };
2513 static const byte _dock_w_chk[4] = { 2, 1, 2, 1 };
2514 static const byte _dock_h_chk[4] = { 1, 2, 1, 2 };
2515
2525 CommandCost CmdBuildDock(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
2526 {
2527 StationID station_to_join = GB(p2, 16, 16);
2528 bool reuse = (station_to_join != NEW_STATION);
2529 if (!reuse) station_to_join = INVALID_STATION;
2530 bool distant_join = (station_to_join != INVALID_STATION);
2531
2532 if (distant_join && (!_settings_game.station.distant_join_stations || !Station::IsValidID(station_to_join))) return CMD_ERROR;
2533
2534 DiagDirection direction = GetInclinedSlopeDirection(GetTileSlope(tile));
2535 if (direction == INVALID_DIAGDIR) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
2536 direction = ReverseDiagDir(direction);
2537
2538 /* Docks cannot be placed on rapids */
2539 if (HasTileWaterGround(tile)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
2540
2541 CommandCost ret = CheckIfAuthorityAllowsNewStation(tile, flags);
2542 if (ret.Failed()) return ret;
2543
2544 if (IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
2545
2546 CommandCost cost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_STATION_DOCK]);
2547 ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
2548 if (ret.Failed()) return ret;
2549 cost.AddCost(ret);
2550
2551 TileIndex tile_cur = tile + TileOffsByDiagDir(direction);
2552
2553 if (!IsTileType(tile_cur, MP_WATER) || !IsTileFlat(tile_cur)) {
2554 return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
2555 }
2556
2557 if (IsBridgeAbove(tile_cur)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
2558
2559 /* Get the water class of the water tile before it is cleared.*/
2560 WaterClass wc = GetWaterClass(tile_cur);
2561
2562 ret = DoCommand(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
2563 if (ret.Failed()) return ret;
2564
2565 tile_cur += TileOffsByDiagDir(direction);
2566 if (!IsTileType(tile_cur, MP_WATER) || !IsTileFlat(tile_cur)) {
2567 return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
2568 }
2569
2570 TileArea dock_area = TileArea(tile + ToTileIndexDiff(_dock_tileoffs_chkaround[direction]),
2571 _dock_w_chk[direction], _dock_h_chk[direction]);
2572
2573 /* middle */
2574 Station *st = nullptr;
2575 ret = FindJoiningStation(INVALID_STATION, station_to_join, HasBit(p1, 0), dock_area, &st);
2576 if (ret.Failed()) return ret;
2577
2578 /* Distant join */
2579 if (st == nullptr && distant_join) st = Station::GetIfValid(station_to_join);
2580
2581 ret = BuildStationPart(&st, flags, reuse, dock_area, STATIONNAMING_DOCK);
2582 if (ret.Failed()) return ret;
2583
2584 if (flags & DC_EXEC) {
2585 st->ship_station.Add(tile);
2586 st->ship_station.Add(tile + TileOffsByDiagDir(direction));
2587 st->AddFacility(FACIL_DOCK, tile);
2588
2589 st->rect.BeforeAddRect(dock_area.tile, dock_area.w, dock_area.h, StationRect::ADD_TRY);
2590
2591 /* If the water part of the dock is on a canal, update infrastructure counts.
2592 * This is needed as we've unconditionally cleared that tile before. */
2593 if (wc == WATER_CLASS_CANAL) {
2594 Company::Get(st->owner)->infrastructure.water++;
2595 }
2596 Company::Get(st->owner)->infrastructure.station += 2;
2597
2598 MakeDock(tile, st->owner, st->index, direction, wc);
2599 UpdateStationDockingTiles(st);
2600
2601 st->AfterStationTileSetChange(true, STATION_DOCK);
2602 }
2603
2604 return cost;
2605 }
2606
2607 void RemoveDockingTile(TileIndex t)
2608 {
2609 for (DiagDirection d = DIAGDIR_BEGIN; d != DIAGDIR_END; d++) {
2610 TileIndex tile = t + TileOffsByDiagDir(d);
2611 if (!IsValidTile(tile)) continue;
2612
2613 if (IsTileType(tile, MP_STATION)) {
2614 Station *st = Station::GetByTile(tile);
2615 if (st != nullptr) UpdateStationDockingTiles(st);
2616 } else if (IsTileType(tile, MP_INDUSTRY)) {
2617 Station *neutral = Industry::GetByTile(tile)->neutral_station;
2618 if (neutral != nullptr) UpdateStationDockingTiles(neutral);
2619 }
2620 }
2621 }
2622
2628 void ClearDockingTilesCheckingNeighbours(TileIndex tile)
2629 {
2630 assert(IsValidTile(tile));
2631
2632 /* Clear and maybe re-set docking tile */
2633 for (DiagDirection d = DIAGDIR_BEGIN; d != DIAGDIR_END; d++) {
2634 TileIndex docking_tile = tile + TileOffsByDiagDir(d);
2635 if (!IsValidTile(docking_tile)) continue;
2636
2637 if (IsPossibleDockingTile(docking_tile)) {
2638 SetDockingTile(docking_tile, false);
2639 CheckForDockingTile(docking_tile);
2640 }
2641 }
2642 }
2643
2650 bool IsValidDockingDirectionForDock(TileIndex t, DiagDirection d)
2651 {
2652 assert(IsDockTile(t));
2653
2654 StationGfx gfx = GetStationGfx(t);
2655 return gfx >= GFX_DOCK_BASE_WATER_PART;
2656 }
2657
2663 static TileIndex FindDockLandPart(TileIndex t)
2664 {
2665 assert(IsDockTile(t));
2666
2667 StationGfx gfx = GetStationGfx(t);
2668 if (gfx < GFX_DOCK_BASE_WATER_PART) return t;
2669
2670 for (DiagDirection d = DIAGDIR_BEGIN; d != DIAGDIR_END; d++) {
2671 TileIndex tile = t + TileOffsByDiagDir(d);
2672 if (!IsValidTile(tile)) continue;
2673 if (!IsDockTile(tile)) continue;
2674 if (GetStationGfx(tile) < GFX_DOCK_BASE_WATER_PART && tile + TileOffsByDiagDir(GetDockDirection(tile)) == t) return tile;
2675 }
2676
2677 return INVALID_TILE;
2678 }
2679
2686 static CommandCost RemoveDock(TileIndex tile, DoCommandFlag flags)
2687 {
2688 Station *st = Station::GetByTile(tile);
2689 CommandCost ret = CheckOwnership(st->owner);
2690 if (ret.Failed()) return ret;
2691
2692 if (!IsDockTile(tile)) return CMD_ERROR;
2693
2694 TileIndex tile1 = FindDockLandPart(tile);
2695 if (tile1 == INVALID_TILE) return CMD_ERROR;
2696 TileIndex tile2 = tile1 + TileOffsByDiagDir(GetDockDirection(tile1));
2697
2698 ret = EnsureNoVehicleOnGround(tile1);
2699 if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile2);
2700 if (ret.Failed()) return ret;
2701
2702 if (flags & DC_EXEC) {
2703 DoClearSquare(tile1);
2704 MarkTileDirtyByTile(tile1);
2705 MakeWaterKeepingClass(tile2, st->owner);
2706
2707 st->rect.AfterRemoveTile(st, tile1);
2708 st->rect.AfterRemoveTile(st, tile2);
2709
2710 MakeShipStationAreaSmaller(st);
2711 if (st->ship_station.tile == INVALID_TILE) {
2712 st->ship_station.Clear();
2713 st->docking_station.Clear();
2714 st->facilities &= ~FACIL_DOCK;
2715 }
2716
2717 Company::Get(st->owner)->infrastructure.station -= 2;
2718
2719 st->AfterStationTileSetChange(false, STATION_DOCK);
2720
2721 ClearDockingTilesCheckingNeighbours(tile1);
2722 ClearDockingTilesCheckingNeighbours(tile2);
2723
2724 for (Ship *s : Ship::Iterate()) {
2725 /* Find all ships going to our dock. */
2726 if (s->current_order.GetDestination() != st->index) {
2727 continue;
2728 }
2729
2730 /* Find ships that are marked as "loading" but are no longer on a
2731 * docking tile. Force them to leave the station (as they were loading
2732 * on the removed dock). */
2733 if (s->current_order.IsType(OT_LOADING) && !(IsDockingTile(s->tile) && IsShipDestinationTile(s->tile, st->index))) {
2734 s->LeaveStation();
2735 }
2736
2737 /* If we no longer have a dock, mark the order as invalid and send
2738 * the ship to the next order (or, if there is none, make it
2739 * wander the world). */
2740 if (s->current_order.IsType(OT_GOTO_STATION) && !(st->facilities & FACIL_DOCK)) {
2741 s->SetDestTile(s->GetOrderStationLocation(st->index));
2742 }
2743 }
2744 }
2745
2746 return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_STATION_DOCK]);
2747 }
2748
2749 #include "table/station_land.h"
2750
2751 const DrawTileSprites *GetStationTileLayout(StationType st, byte gfx)
2752 {
2753 return &_station_display_datas[st][gfx];
2754 }
2755
2765 bool SplitGroundSpriteForOverlay(const TileInfo *ti, SpriteID *ground, RailTrackOffset *overlay_offset)
2766 {
2767 bool snow_desert;
2768 switch (*ground) {
2769 case SPR_RAIL_TRACK_X:
2770 case SPR_MONO_TRACK_X:
2771 case SPR_MGLV_TRACK_X:
2772 snow_desert = false;
2773 *overlay_offset = RTO_X;
2774 break;
2775
2776 case SPR_RAIL_TRACK_Y:
2777 case SPR_MONO_TRACK_Y:
2778 case SPR_MGLV_TRACK_Y:
2779 snow_desert = false;
2780 *overlay_offset = RTO_Y;
2781 break;
2782
2783 case SPR_RAIL_TRACK_X_SNOW:
2784 case SPR_MONO_TRACK_X_SNOW:
2785 case SPR_MGLV_TRACK_X_SNOW:
2786 snow_desert = true;
2787 *overlay_offset = RTO_X;
2788 break;
2789
2790 case SPR_RAIL_TRACK_Y_SNOW:
2791 case SPR_MONO_TRACK_Y_SNOW:
2792 case SPR_MGLV_TRACK_Y_SNOW:
2793 snow_desert = true;
2794 *overlay_offset = RTO_Y;
2795 break;
2796
2797 default:
2798 return false;
2799 }
2800
2801 if (ti != nullptr) {
2802 /* Decide snow/desert from tile */
2803 switch (_settings_game.game_creation.landscape) {
2804 case LT_ARCTIC:
2805 snow_desert = (uint)ti->z > GetSnowLine() * TILE_HEIGHT;
2806 break;
2807
2808 case LT_TROPIC:
2809 snow_desert = GetTropicZone(ti->tile) == TROPICZONE_DESERT;
2810 break;
2811
2812 default:
2813 break;
2814 }
2815 }
2816
2817 *ground = snow_desert ? SPR_FLAT_SNOW_DESERT_TILE : SPR_FLAT_GRASS_TILE;
2818 return true;
2819 }
2820
2821 static void DrawTile_Station(TileInfo *ti)
2822 {
2823 const NewGRFSpriteLayout *layout = nullptr;
2824 DrawTileSprites tmp_rail_layout;
2825 const DrawTileSprites *t = nullptr;
2826 int32 total_offset;
2827 const RailtypeInfo *rti = nullptr;
2828 uint32 relocation = 0;
2829 uint32 ground_relocation = 0;
2830 BaseStation *st = nullptr;
2831 const StationSpec *statspec = nullptr;
2832 uint tile_layout = 0;
2833
2834 if (HasStationRail(ti->tile)) {
2835 rti = GetRailTypeInfo(GetRailType(ti->tile));
2836 total_offset = rti->GetRailtypeSpriteOffset();
2837
2838 if (IsCustomStationSpecIndex(ti->tile)) {
2839 /* look for customization */
2840 st = BaseStation::GetByTile(ti->tile);
2841 statspec = st->speclist[GetCustomStationSpecIndex(ti->tile)].spec;
2842
2843 if (statspec != nullptr) {
2844 tile_layout = GetStationGfx(ti->tile);
2845
2846 if (HasBit(statspec->callback_mask, CBM_STATION_SPRITE_LAYOUT)) {
2847 uint16 callback = GetStationCallback(CBID_STATION_SPRITE_LAYOUT, 0, 0, statspec, st, ti->tile);
2848 if (callback != CALLBACK_FAILED) tile_layout = (callback & ~1) + GetRailStationAxis(ti->tile);
2849 }
2850
2851 /* Ensure the chosen tile layout is valid for this custom station */
2852 if (!statspec->renderdata.empty()) {
2853 layout = &statspec->renderdata[tile_layout < statspec->renderdata.size() ? tile_layout : (uint)GetRailStationAxis(ti->tile)];
2854 if (!layout->NeedsPreprocessing()) {
2855 t = layout;
2856 layout = nullptr;
2857 }
2858 }
2859 }
2860 }
2861 } else {
2862 total_offset = 0;
2863 }
2864
2865 StationGfx gfx = GetStationGfx(ti->tile);
2866 if (IsAirport(ti->tile)) {
2867 gfx = GetAirportGfx(ti->tile);
2868 if (gfx >= NEW_AIRPORTTILE_OFFSET) {
2869 const AirportTileSpec *ats = AirportTileSpec::Get(gfx);
2870 if (ats->grf_prop.spritegroup[0] != nullptr && DrawNewAirportTile(ti, Station::GetByTile(ti->tile), gfx, ats)) {
2871 return;
2872 }
2873 /* No sprite group (or no valid one) found, meaning no graphics associated.
2874 * Use the substitute one instead */
2875 assert(ats->grf_prop.subst_id != INVALID_AIRPORTTILE);
2876 gfx = ats->grf_prop.subst_id;
2877 }
2878 switch (gfx) {
2879 case APT_RADAR_GRASS_FENCE_SW:
2880 t = &_station_display_datas_airport_radar_grass_fence_sw[GetAnimationFrame(ti->tile)];
2881 break;
2882 case APT_GRASS_FENCE_NE_FLAG:
2883 t = &_station_display_datas_airport_flag_grass_fence_ne[GetAnimationFrame(ti->tile)];
2884 break;
2885 case APT_RADAR_FENCE_SW:
2886 t = &_station_display_datas_airport_radar_fence_sw[GetAnimationFrame(ti->tile)];
2887 break;
2888 case APT_RADAR_FENCE_NE:
2889 t = &_station_display_datas_airport_radar_fence_ne[GetAnimationFrame(ti->tile)];
2890 break;
2891 case APT_GRASS_FENCE_NE_FLAG_2:
2892 t = &_station_display_datas_airport_flag_grass_fence_ne_2[GetAnimationFrame(ti->tile)];
2893 break;
2894 }
2895 }
2896
2897 Owner owner = GetTileOwner(ti->tile);
2898
2899 PaletteID palette;
2900 if (Company::IsValidID(owner)) {
2901 palette = COMPANY_SPRITE_COLOUR(owner);
2902 } else {
2903 /* Some stations are not owner by a company, namely oil rigs */
2904 palette = PALETTE_TO_GREY;
2905 }
2906
2907 if (layout == nullptr && (t == nullptr || t->seq == nullptr)) t = GetStationTileLayout(GetStationType(ti->tile), gfx);
2908
2909 /* don't show foundation for docks */
2910 if (ti->tileh != SLOPE_FLAT && !IsDock(ti->tile)) {
2911 if (statspec != nullptr && HasBit(statspec->flags, SSF_CUSTOM_FOUNDATIONS)) {
2912 /* Station has custom foundations.
2913 * Check whether the foundation continues beyond the tile's upper sides. */
2914 uint edge_info = 0;
2915 int z;
2916 Slope slope = GetFoundationPixelSlope(ti->tile, &z);
2917 if (!HasFoundationNW(ti->tile, slope, z)) SetBit(edge_info, 0);
2918 if (!HasFoundationNE(ti->tile, slope, z)) SetBit(edge_info, 1);
2919 SpriteID image = GetCustomStationFoundationRelocation(statspec, st, ti->tile, tile_layout, edge_info);
2920 if (image == 0) goto draw_default_foundation;
2921
2922 if (HasBit(statspec->flags, SSF_EXTENDED_FOUNDATIONS)) {
2923 /* Station provides extended foundations. */
2924
2925 static const uint8 foundation_parts[] = {
2926 0, 0, 0, 0, // Invalid, Invalid, Invalid, SLOPE_SW
2927 0, 1, 2, 3, // Invalid, SLOPE_EW, SLOPE_SE, SLOPE_WSE
2928 0, 4, 5, 6, // Invalid, SLOPE_NW, SLOPE_NS, SLOPE_NWS
2929 7, 8, 9 // SLOPE_NE, SLOPE_ENW, SLOPE_SEN
2930 };
2931
2932 AddSortableSpriteToDraw(image + foundation_parts[ti->tileh], PAL_NONE, ti->x, ti->y, 16, 16, 7, ti->z);
2933 } else {
2934 /* Draw simple foundations, built up from 8 possible foundation sprites. */
2935
2936 /* Each set bit represents one of the eight composite sprites to be drawn.
2937 * 'Invalid' entries will not drawn but are included for completeness. */
2938 static const uint8 composite_foundation_parts[] = {
2939 /* Invalid (00000000), Invalid (11010001), Invalid (11100100), SLOPE_SW (11100000) */
2940 0x00, 0xD1, 0xE4, 0xE0,
2941 /* Invalid (11001010), SLOPE_EW (11001001), SLOPE_SE (11000100), SLOPE_WSE (11000000) */
2942 0xCA, 0xC9, 0xC4, 0xC0,
2943 /* Invalid (11010010), SLOPE_NW (10010001), SLOPE_NS (11100100), SLOPE_NWS (10100000) */
2944 0xD2, 0x91, 0xE4, 0xA0,
2945 /* SLOPE_NE (01001010), SLOPE_ENW (00001001), SLOPE_SEN (01000100) */
2946 0x4A, 0x09, 0x44
2947 };
2948
2949 uint8 parts = composite_foundation_parts[ti->tileh];
2950
2951 /* If foundations continue beyond the tile's upper sides then
2952 * mask out the last two pieces. */
2953 if (HasBit(edge_info, 0)) ClrBit(parts, 6);
2954 if (HasBit(edge_info, 1)) ClrBit(parts, 7);
2955
2956 if (parts == 0) {
2957 /* We always have to draw at least one sprite to make sure there is a boundingbox and a sprite with the
2958 * correct offset for the childsprites.
2959 * So, draw the (completely empty) sprite of the default foundations. */
2960 goto draw_default_foundation;
2961 }
2962
2963 StartSpriteCombine();
2964 for (int i = 0; i < 8; i++) {
2965 if (HasBit(parts, i)) {
2966 AddSortableSpriteToDraw(image + i, PAL_NONE, ti->x, ti->y, 16, 16, 7, ti->z);
2967 }
2968 }
2969 EndSpriteCombine();
2970 }
2971
2972 OffsetGroundSprite(31, 1);
2973 ti->z += ApplyPixelFoundationToSlope(FOUNDATION_LEVELED, &ti->tileh);
2974 } else {
2975 draw_default_foundation:
2976 DrawFoundation(ti, FOUNDATION_LEVELED);
2977 }
2978 }
2979
2980 if (IsBuoy(ti->tile)) {
2981 DrawWaterClassGround(ti);
2982 SpriteID sprite = GetCanalSprite(CF_BUOY, ti->tile);
2983 if (sprite != 0) total_offset = sprite - SPR_IMG_BUOY;
2984 } else if (IsDock(ti->tile) || (IsOilRig(ti->tile) && IsTileOnWater(ti->tile))) {
2985 if (ti->tileh == SLOPE_FLAT) {
2986 DrawWaterClassGround(ti);
2987 } else {
2988 assert(IsDock(ti->tile));
2989 TileIndex water_tile = ti->tile + TileOffsByDiagDir(GetDockDirection(ti->tile));
2990 WaterClass wc = HasTileWaterClass(water_tile) ? GetWaterClass(water_tile) : WATER_CLASS_INVALID;
2991 if (wc == WATER_CLASS_SEA) {
2992 DrawShoreTile(ti->tileh);
2993 } else {
2994 DrawClearLandTile(ti, 3);
2995 }
2996 }
2997 } else {
2998 if (layout != nullptr) {
2999 /* Sprite layout which needs preprocessing */
3000 bool separate_ground = HasBit(statspec->flags, SSF_SEPARATE_GROUND);
3001 uint32 var10_values = layout->PrepareLayout(total_offset, rti->fallback_railtype, 0, 0, separate_ground);
3002 for (uint8 var10 : SetBitIterator(var10_values)) {
3003 uint32 var10_relocation = GetCustomStationRelocation(statspec, st, ti->tile, var10);
3004 layout->ProcessRegisters(var10, var10_relocation, separate_ground);
3005 }
3006 tmp_rail_layout.seq = layout->GetLayout(&tmp_rail_layout.ground);
3007 t = &tmp_rail_layout;
3008 total_offset = 0;
3009 } else if (statspec != nullptr) {
3010 /* Simple sprite layout */
3011 ground_relocation = relocation = GetCustomStationRelocation(statspec, st, ti->tile, 0);
3012 if (HasBit(statspec->flags, SSF_SEPARATE_GROUND)) {
3013 ground_relocation = GetCustomStationRelocation(statspec, st, ti->tile, 1);
3014 }
3015 ground_relocation += rti->fallback_railtype;
3016 }
3017
3018 SpriteID image = t->ground.sprite;
3019 PaletteID pal = t->ground.pal;
3020 RailTrackOffset overlay_offset;
3021 if (rti != nullptr && rti->UsesOverlay() && SplitGroundSpriteForOverlay(ti, &image, &overlay_offset)) {
3022 SpriteID ground = GetCustomRailSprite(rti, ti->tile, RTSG_GROUND);
3023 DrawGroundSprite(image, PAL_NONE);
3024 DrawGroundSprite(ground + overlay_offset, PAL_NONE);
3025
3026 if (_game_mode != GM_MENU && _settings_client.gui.show_track_reservation && HasStationReservation(ti->tile)) {
3027 SpriteID overlay = GetCustomRailSprite(rti, ti->tile, RTSG_OVERLAY);
3028 DrawGroundSprite(overlay + overlay_offset, PALETTE_CRASH);
3029 }
3030 } else {
3031 image += HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE) ? ground_relocation : total_offset;
3032 if (HasBit(pal, SPRITE_MODIFIER_CUSTOM_SPRITE)) pal += ground_relocation;
3033 DrawGroundSprite(image, GroundSpritePaletteTransform(image, pal, palette));
3034
3035 /* PBS debugging, draw reserved tracks darker */
3036 if (_game_mode != GM_MENU && _settings_client.gui.show_track_reservation && HasStationRail(ti->tile) && HasStationReservation(ti->tile)) {
3037 const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile));
3038 DrawGroundSprite(GetRailStationAxis(ti->tile) == AXIS_X ? rti->base_sprites.single_x : rti->base_sprites.single_y, PALETTE_CRASH);
3039 }
3040 }
3041 }
3042
3043 if (HasStationRail(ti->tile) && HasRailCatenaryDrawn(GetRailType(ti->tile))) DrawRailCatenary(ti);
3044
3045 if (IsRoadStop(ti->tile)) {
3046 RoadType road_rt = GetRoadTypeRoad(ti->tile);
3047 RoadType tram_rt = GetRoadTypeTram(ti->tile);
3048 const RoadTypeInfo* road_rti = road_rt == INVALID_ROADTYPE ? nullptr : GetRoadTypeInfo(road_rt);
3049 const RoadTypeInfo* tram_rti = tram_rt == INVALID_ROADTYPE ? nullptr : GetRoadTypeInfo(tram_rt);
3050
3051 if (IsDriveThroughStopTile(ti->tile)) {
3052 Axis axis = GetRoadStopDir(ti->tile) == DIAGDIR_NE ? AXIS_X : AXIS_Y;
3053 uint sprite_offset = axis == AXIS_X ? 1 : 0;
3054
3055 DrawRoadOverlays(ti, PAL_NONE, road_rti, tram_rti, sprite_offset, sprite_offset);
3056 } else {
3057 /* Non-drivethrough road stops are only valid for roads. */
3058 assert(road_rt != INVALID_ROADTYPE && tram_rt == INVALID_ROADTYPE);
3059
3060 if (road_rti->UsesOverlay()) {
3061 DiagDirection dir = GetRoadStopDir(ti->tile);
3062 SpriteID ground = GetCustomRoadSprite(road_rti, ti->tile, ROTSG_ROADSTOP);
3063 DrawGroundSprite(ground + dir, PAL_NONE);
3064 }
3065 }
3066
3067 /* Draw road, tram catenary */
3068 DrawRoadCatenary(ti);
3069 }
3070
3071 if (IsRailWaypoint(ti->tile)) {
3072 /* Don't offset the waypoint graphics; they're always the same. */
3073 total_offset = 0;
3074 }
3075
3076 DrawRailTileSeq(ti, t, TO_BUILDINGS, total_offset, relocation, palette);
3077 }
3078
3079 void StationPickerDrawSprite(int x, int y, StationType st, RailType railtype, RoadType roadtype, int image)
3080 {
3081 int32 total_offset = 0;
3082 PaletteID pal = COMPANY_SPRITE_COLOUR(_local_company);
3083 const DrawTileSprites *t = GetStationTileLayout(st, image);
3084 const RailtypeInfo *rti = nullptr;
3085
3086 if (railtype != INVALID_RAILTYPE) {
3087 rti = GetRailTypeInfo(railtype);
3088 total_offset = rti->GetRailtypeSpriteOffset();
3089 }
3090
3091 SpriteID img = t->ground.sprite;
3092 RailTrackOffset overlay_offset;
3093 if (rti != nullptr && rti->UsesOverlay() && SplitGroundSpriteForOverlay(nullptr, &img, &overlay_offset)) {
3094 SpriteID ground = GetCustomRailSprite(rti, INVALID_TILE, RTSG_GROUND);
3095 DrawSprite(img, PAL_NONE, x, y);
3096 DrawSprite(ground + overlay_offset, PAL_NONE, x, y);
3097 } else {
3098 DrawSprite(img + total_offset, HasBit(img, PALETTE_MODIFIER_COLOUR) ? pal : PAL_NONE, x, y);
3099 }
3100
3101 if (roadtype != INVALID_ROADTYPE) {
3102 const RoadTypeInfo* rti = GetRoadTypeInfo(roadtype);
3103 if (image >= 4) {
3104 /* Drive-through stop */
3105 uint sprite_offset = 5 - image;
3106
3107 /* Road underlay takes precedence over tram */
3108 if (rti->UsesOverlay()) {
3109 SpriteID ground = GetCustomRoadSprite(rti, INVALID_TILE, ROTSG_GROUND);
3110 DrawSprite(ground + sprite_offset, PAL_NONE, x, y);
3111
3112 SpriteID overlay = GetCustomRoadSprite(rti, INVALID_TILE, ROTSG_OVERLAY);
3113 if (overlay) DrawSprite(overlay + sprite_offset, PAL_NONE, x, y);
3114 } else if (RoadTypeIsTram(roadtype)) {
3115 DrawSprite(SPR_TRAMWAY_TRAM + sprite_offset, PAL_NONE, x, y);
3116 }
3117 } else {
3118 /* Drive-in stop */
3119 if (RoadTypeIsRoad(roadtype) && rti->UsesOverlay()) {
3120 SpriteID ground = GetCustomRoadSprite(rti, INVALID_TILE, ROTSG_ROADSTOP);
3121 DrawSprite(ground + image, PAL_NONE, x, y);
3122 }
3123 }
3124 }
3125
3126 /* Default waypoint has no railtype specific sprites */
3127 DrawRailTileSeqInGUI(x, y, t, st == STATION_WAYPOINT ? 0 : total_offset, 0, pal);
3128 }
3129
3130 static int GetSlopePixelZ_Station(TileIndex tile, uint x, uint y)
3131 {
3132 return GetTileMaxPixelZ(tile);
3133 }
3134
3135 static Foundation GetFoundation_Station(TileIndex tile, Slope tileh)
3136 {
3137 return FlatteningFoundation(tileh);
3138 }
3139
3140 static void GetTileDesc_Station(TileIndex tile, TileDesc *td)
3141 {
3142 td->owner[0] = GetTileOwner(tile);
3143
3144 if (IsRoadStopTile(tile)) {
3145 RoadType road_rt = GetRoadTypeRoad(tile);
3146 RoadType tram_rt = GetRoadTypeTram(tile);
3147 Owner road_owner = INVALID_OWNER;
3148 Owner tram_owner = INVALID_OWNER;
3149 if (road_rt != INVALID_ROADTYPE) {
3150 const RoadTypeInfo *rti = GetRoadTypeInfo(road_rt);
3151 td->roadtype = rti->strings.name;
3152 td->road_speed = rti->max_speed / 2;
3153 road_owner = GetRoadOwner(tile, RTT_ROAD);
3154 }
3155
3156 if (tram_rt != INVALID_ROADTYPE) {
3157 const RoadTypeInfo *rti = GetRoadTypeInfo(tram_rt);
3158 td->tramtype = rti->strings.name;
3159 td->tram_speed = rti->max_speed / 2;
3160 tram_owner = GetRoadOwner(tile, RTT_TRAM);
3161 }
3162
3163 if (IsDriveThroughStopTile(tile)) {
3164 /* Is there a mix of owners? */
3165 if ((tram_owner != INVALID_OWNER && tram_owner != td->owner[0]) ||
3166 (road_owner != INVALID_OWNER && road_owner != td->owner[0])) {
3167 uint i = 1;
3168 if (road_owner != INVALID_OWNER) {
3169 td->owner_type[i] = STR_LAND_AREA_INFORMATION_ROAD_OWNER;
3170 td->owner[i] = road_owner;
3171 i++;
3172 }
3173 if (tram_owner != INVALID_OWNER) {
3174 td->owner_type[i] = STR_LAND_AREA_INFORMATION_TRAM_OWNER;
3175 td->owner[i] = tram_owner;
3176 }
3177 }
3178 }
3179 }
3180
3181 td->build_date = BaseStation::GetByTile(tile)->build_date;
3182
3183 if (HasStationTileRail(tile)) {
3184 const StationSpec *spec = GetStationSpec(tile);
3185
3186 if (spec != nullptr) {
3187 td->station_class = StationClass::Get(spec->cls_id)->name;
3188 td->station_name = spec->name;
3189
3190 if (spec->grf_prop.grffile != nullptr) {
3191 const GRFConfig *gc = GetGRFConfig(spec->grf_prop.grffile->grfid);
3192 td->grf = gc->GetName();
3193 }
3194 }
3195
3196 const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(tile));
3197 td->rail_speed = rti->max_speed;
3198 td->railtype = rti->strings.name;
3199 }
3200
3201 if (IsAirport(tile)) {
3202 const AirportSpec *as = Station::GetByTile(tile)->airport.GetSpec();
3203 td->airport_class = AirportClass::Get(as->cls_id)->name;
3204 td->airport_name = as->name;
3205
3206 const AirportTileSpec *ats = AirportTileSpec::GetByTile(tile);
3207 td->airport_tile_name = ats->name;
3208
3209 if (as->grf_prop.grffile != nullptr) {
3210 const GRFConfig *gc = GetGRFConfig(as->grf_prop.grffile->grfid);
3211 td->grf = gc->GetName();
3212 } else if (ats->grf_prop.grffile != nullptr) {
3213 const GRFConfig *gc = GetGRFConfig(ats->grf_prop.grffile->grfid);
3214 td->grf = gc->GetName();
3215 }
3216 }
3217
3218 StringID str;
3219 switch (GetStationType(tile)) {
3220 default: NOT_REACHED();
3221 case STATION_RAIL: str = STR_LAI_STATION_DESCRIPTION_RAILROAD_STATION; break;
3222 case STATION_AIRPORT:
3223 str = (IsHangar(tile) ? STR_LAI_STATION_DESCRIPTION_AIRCRAFT_HANGAR : STR_LAI_STATION_DESCRIPTION_AIRPORT);
3224 break;
3225 case STATION_TRUCK: str = STR_LAI_STATION_DESCRIPTION_TRUCK_LOADING_AREA; break;
3226 case STATION_BUS: str = STR_LAI_STATION_DESCRIPTION_BUS_STATION; break;
3227 case STATION_OILRIG: {
3228 const Industry *i = Station::GetByTile(tile)->industry;
3229 const IndustrySpec *is = GetIndustrySpec(i->type);
3230 td->owner[0] = i->owner;
3231 str = is->name;
3232 if (is->grf_prop.grffile != nullptr) td->grf = GetGRFConfig(is->grf_prop.grffile->grfid)->GetName();
3233 break;
3234 }
3235 case STATION_DOCK: str = STR_LAI_STATION_DESCRIPTION_SHIP_DOCK; break;
3236 case STATION_BUOY: str = STR_LAI_STATION_DESCRIPTION_BUOY; break;
3237 case STATION_WAYPOINT: str = STR_LAI_STATION_DESCRIPTION_WAYPOINT; break;
3238 }
3239 td->str = str;
3240 }
3241
3242
3243 static TrackStatus GetTileTrackStatus_Station(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
3244 {
3245 TrackBits trackbits = TRACK_BIT_NONE;
3246
3247 switch (mode) {
3248 case TRANSPORT_RAIL:
3249 if (HasStationRail(tile) && !IsStationTileBlocked(tile)) {
3250 trackbits = TrackToTrackBits(GetRailStationTrack(tile));
3251 }
3252 break;
3253
3254 case TRANSPORT_WATER:
3255 /* buoy is coded as a station, it is always on open water */
3256 if (IsBuoy(tile)) {
3257 trackbits = TRACK_BIT_ALL;
3258 /* remove tracks that connect NE map edge */
3259 if (TileX(tile) == 0) trackbits &= ~(TRACK_BIT_X | TRACK_BIT_UPPER | TRACK_BIT_RIGHT);
3260 /* remove tracks that connect NW map edge */
3261 if (TileY(tile) == 0) trackbits &= ~(TRACK_BIT_Y | TRACK_BIT_LEFT | TRACK_BIT_UPPER);
3262 }
3263 break;
3264
3265 case TRANSPORT_ROAD:
3266 if (IsRoadStop(tile)) {
3267 RoadTramType rtt = (RoadTramType)sub_mode;
3268 if (!HasTileRoadType(tile, rtt)) break;
3269
3270 DiagDirection dir = GetRoadStopDir(tile);
3271 Axis axis = DiagDirToAxis(dir);
3272
3273 if (side != INVALID_DIAGDIR) {
3274 if (axis != DiagDirToAxis(side) || (IsStandardRoadStopTile(tile) && dir != side)) break;
3275 }
3276
3277 trackbits = AxisToTrackBits(axis);
3278 }
3279 break;
3280
3281 default:
3282 break;
3283 }
3284
3285 return CombineTrackStatus(TrackBitsToTrackdirBits(trackbits), TRACKDIR_BIT_NONE);
3286 }
3287
3288
3289 static void TileLoop_Station(TileIndex tile)
3290 {
3291 /* FIXME -- GetTileTrackStatus_Station -> animated stationtiles
3292 * hardcoded.....not good */
3293 switch (GetStationType(tile)) {
3294 case STATION_AIRPORT:
3295 AirportTileAnimationTrigger(Station::GetByTile(tile), tile, AAT_TILELOOP);
3296 break;
3297
3298 case STATION_DOCK:
3299 if (!IsTileFlat(tile)) break; // only handle water part
3300 FALLTHROUGH;
3301
3302 case STATION_OILRIG: //(station part)
3303 case STATION_BUOY:
3304 TileLoop_Water(tile);
3305 break;
3306
3307 default: break;
3308 }
3309 }
3310
3311
3312 static void AnimateTile_Station(TileIndex tile)
3313 {
3314 if (HasStationRail(tile)) {
3315 AnimateStationTile(tile);
3316 return;
3317 }
3318
3319 if (IsAirport(tile)) {
3320 AnimateAirportTile(tile);
3321 }
3322 }
3323
3324
3325 static bool ClickTile_Station(TileIndex tile)
3326 {
3327 const BaseStation *bst = BaseStation::GetByTile(tile);
3328
3329 if (bst->facilities & FACIL_WAYPOINT) {
3330 ShowWaypointWindow(Waypoint::From(bst));
3331 } else if (IsHangar(tile)) {
3332 const Station *st = Station::From(bst);
3333 ShowDepotWindow(st->airport.GetHangarTile(st->airport.GetHangarNum(tile)), VEH_AIRCRAFT);
3334 } else {
3335 ShowStationViewWindow(bst->index);
3336 }
3337 return true;
3338 }
3339
3340 static VehicleEnterTileStatus VehicleEnter_Station(Vehicle *v, TileIndex tile, int x, int y)
3341 {
3342 if (v->type == VEH_TRAIN) {
3343 StationID station_id = GetStationIndex(tile);
3344 if (!v->current_order.ShouldStopAtStation(v, station_id)) return VETSB_CONTINUE;
3345 if (!IsRailStation(tile) || !v->IsFrontEngine()) return VETSB_CONTINUE;
3346
3347 int station_ahead;
3348 int station_length;
3349 int stop = GetTrainStopLocation(station_id, tile, Train::From(v), &station_ahead, &station_length);
3350
3351 /* Stop whenever that amount of station ahead + the distance from the
3352 * begin of the platform to the stop location is longer than the length
3353 * of the platform. Station ahead 'includes' the current tile where the
3354 * vehicle is on, so we need to subtract that. */
3355 if (stop + station_ahead - (int)TILE_SIZE >= station_length) return VETSB_CONTINUE;
3356
3357 DiagDirection dir = DirToDiagDir(v->direction);
3358
3359 x &= 0xF;
3360 y &= 0xF;
3361
3362 if (DiagDirToAxis(dir) != AXIS_X) Swap(x, y);
3363 if (y == TILE_SIZE / 2) {
3364 if (dir != DIAGDIR_SE && dir != DIAGDIR_SW) x = TILE_SIZE - 1 - x;
3365 stop &= TILE_SIZE - 1;
3366
3367 if (x == stop) {
3368 return VETSB_ENTERED_STATION | (VehicleEnterTileStatus)(station_id << VETS_STATION_ID_OFFSET); // enter station
3369 } else if (x < stop) {
3370 v->vehstatus |= VS_TRAIN_SLOWING;
3371 uint16 spd = std::max(0, (stop - x) * 20 - 15);
3372 if (spd < v->cur_speed) v->cur_speed = spd;
3373 }
3374 }
3375 } else if (v->type == VEH_ROAD) {
3376 RoadVehicle *rv = RoadVehicle::From(v);
3377 if (rv->state < RVSB_IN_ROAD_STOP && !IsReversingRoadTrackdir((Trackdir)rv->state) && rv->frame == 0) {
3378 if (IsRoadStop(tile) && rv->IsFrontEngine()) {
3379 /* Attempt to allocate a parking bay in a road stop */
3380 return RoadStop::GetByTile(tile, GetRoadStopType(tile))->Enter(rv) ? VETSB_CONTINUE : VETSB_CANNOT_ENTER;
3381 }
3382 }
3383 }
3384
3385 return VETSB_CONTINUE;
3386 }
3387
3392 void TriggerWatchedCargoCallbacks(Station *st)
3393 {
3394 /* Collect cargoes accepted since the last big tick. */
3395 CargoTypes cargoes = 0;
3396 for (CargoID cid = 0; cid < NUM_CARGO; cid++) {
3397 if (HasBit(st->goods[cid].status, GoodsEntry::GES_ACCEPTED_BIGTICK)) SetBit(cargoes, cid);
3398 }
3399
3400 /* Anything to do? */
3401 if (cargoes == 0) return;
3402
3403 /* Loop over all houses in the catchment. */
3404 BitmapTileIterator it(st->catchment_tiles);
3405 for (TileIndex tile = it; tile != INVALID_TILE; tile = ++it) {
3406 if (IsTileType(tile, MP_HOUSE)) {
3407 WatchedCargoCallback(tile, cargoes);
3408 }
3409 }
3410 }
3411
3418 static bool StationHandleBigTick(BaseStation *st)
3419 {
3420 if (!st->IsInUse()) {
3421 if (++st->delete_ctr >= 8) delete st;
3422 return false;
3423 }
3424
3425 if (Station::IsExpected(st)) {
3426 TriggerWatchedCargoCallbacks(Station::From(st));
3427
3428 for (CargoID i = 0; i < NUM_CARGO; i++) {
3429 ClrBit(Station::From(st)->goods[i].status, GoodsEntry::GES_ACCEPTED_BIGTICK);
3430 }
3431 }
3432
3433
3434 if ((st->facilities & FACIL_WAYPOINT) == 0) UpdateStationAcceptance(Station::From(st), true);
3435
3436 return true;
3437 }
3438
3439 static inline void byte_inc_sat(byte *p)
3440 {
3441 byte b = *p + 1;
3442 if (b != 0) *p = b;
3443 }
3444
3451 static void TruncateCargo(const CargoSpec *cs, GoodsEntry *ge, uint amount = UINT_MAX)
3452 {
3453 /* If truncating also punish the source stations' ratings to
3454 * decrease the flow of incoming cargo. */
3455
3456 StationCargoAmountMap waiting_per_source;
3457 ge->cargo.Truncate(amount, &waiting_per_source);
3458 for (StationCargoAmountMap::iterator i(waiting_per_source.begin()); i != waiting_per_source.end(); ++i) {
3459 Station *source_station = Station::GetIfValid(i->first);
3460 if (source_station == nullptr) continue;
3461
3462 GoodsEntry &source_ge = source_station->goods[cs->Index()];
3463 source_ge.max_waiting_cargo = std::max(source_ge.max_waiting_cargo, i->second);
3464 }
3465 }
3466
3467 static void UpdateStationRating(Station *st)
3468 {
3469 bool waiting_changed = false;
3470
3471 byte_inc_sat(&st->time_since_load);
3472 byte_inc_sat(&st->time_since_unload);
3473
3474 for (const CargoSpec *cs : CargoSpec::Iterate()) {
3475 GoodsEntry *ge = &st->goods[cs->Index()];
3476 /* Slowly increase the rating back to its original level in the case we
3477 * didn't deliver cargo yet to this station. This happens when a bribe
3478 * failed while you didn't moved that cargo yet to a station. */
3479 if (!ge->HasRating() && ge->rating < INITIAL_STATION_RATING) {
3480 ge->rating++;
3481 }
3482
3483 /* Only change the rating if we are moving this cargo */
3484 if (ge->HasRating()) {
3485 byte_inc_sat(&ge->time_since_pickup);
3486 if (ge->time_since_pickup == 255 && _settings_game.order.selectgoods) {
3487 ClrBit(ge->status, GoodsEntry::GES_RATING);
3488 ge->last_speed = 0;
3489 TruncateCargo(cs, ge);
3490 waiting_changed = true;
3491 continue;
3492 }
3493
3494 bool skip = false;
3495 int rating = 0;
3496 uint waiting = ge->cargo.AvailableCount();
3497
3498 /* num_dests is at least 1 if there is any cargo as
3499 * INVALID_STATION is also a destination.
3500 */
3501 uint num_dests = (uint)ge->cargo.Packets()->MapSize();
3502
3503 /* Average amount of cargo per next hop, but prefer solitary stations
3504 * with only one or two next hops. They are allowed to have more
3505 * cargo waiting per next hop.
3506 * With manual cargo distribution waiting_avg = waiting / 2 as then
3507 * INVALID_STATION is the only destination.
3508 */
3509 uint waiting_avg = waiting / (num_dests + 1);
3510
3511 if (HasBit(cs->callback_mask, CBM_CARGO_STATION_RATING_CALC)) {
3512 /* Perform custom station rating. If it succeeds the speed, days in transit and
3513 * waiting cargo ratings must not be executed. */
3514
3515 /* NewGRFs expect last speed to be 0xFF when no vehicle has arrived yet. */
3516 uint last_speed = ge->HasVehicleEverTriedLoading() ? ge->last_speed : 0xFF;
3517
3518 uint32 var18 = std::min<uint>(ge->time_since_pickup, 0xFFu)
3519 | (std::min<uint>(ge->max_waiting_cargo, 0xFFFFu) << 8)
3520 | (std::min<uint>(last_speed, 0xFFu) << 24);
3521 /* Convert to the 'old' vehicle types */
3522 uint32 var10 = (st->last_vehicle_type == VEH_INVALID) ? 0x0 : (st->last_vehicle_type + 0x10);
3523 uint16 callback = GetCargoCallback(CBID_CARGO_STATION_RATING_CALC, var10, var18, cs);
3524 if (callback != CALLBACK_FAILED) {
3525 skip = true;
3526 rating = GB(callback, 0, 14);
3527
3528 /* Simulate a 15 bit signed value */
3529 if (HasBit(callback, 14)) rating -= 0x4000;
3530 }
3531 }
3532
3533 if (!skip) {
3534 int b = ge->last_speed - 85;
3535 if (b >= 0) rating += b >> 2;
3536
3537 byte waittime = ge->time_since_pickup;
3538 if (st->last_vehicle_type == VEH_SHIP) waittime >>= 2;
3539 if (waittime <= 21) rating += 25;
3540 if (waittime <= 12) rating += 25;
3541 if (waittime <= 6) rating += 45;
3542 if (waittime <= 3) rating += 35;
3543
3544 rating -= 90;
3545 if (ge->max_waiting_cargo <= 1500) rating += 55;
3546 if (ge->max_waiting_cargo <= 1000) rating += 35;
3547 if (ge->max_waiting_cargo <= 600) rating += 10;
3548 if (ge->max_waiting_cargo <= 300) rating += 20;
3549 if (ge->max_waiting_cargo <= 100) rating += 10;
3550 }
3551
3552 if (Company::IsValidID(st->owner) && HasBit(st->town->statues, st->owner)) rating += 26;
3553
3554 byte age = ge->last_age;
3555 if (age < 3) rating += 10;
3556 if (age < 2) rating += 10;
3557 if (age < 1) rating += 13;
3558
3559 {
3560 int or_ = ge->rating; // old rating
3561
3562 /* only modify rating in steps of -2, -1, 0, 1 or 2 */
3563 ge->rating = rating = or_ + Clamp(Clamp(rating, 0, 255) - or_, -2, 2);
3564
3565 /* if rating is <= 64 and more than 100 items waiting on average per destination,
3566 * remove some random amount of goods from the station */
3567 if (rating <= 64 && waiting_avg >= 100) {
3568 int dec = Random() & 0x1F;
3569 if (waiting_avg < 200) dec &= 7;
3570 waiting -= (dec + 1) * num_dests;
3571 waiting_changed = true;
3572 }
3573
3574 /* if rating is <= 127 and there are any items waiting, maybe remove some goods. */
3575 if (rating <= 127 && waiting != 0) {
3576 uint32 r = Random();
3577 if (rating <= (int)GB(r, 0, 7)) {
3578 /* Need to have int, otherwise it will just overflow etc. */
3579 waiting = std::max((int)waiting - (int)((GB(r, 8, 2) - 1) * num_dests), 0);
3580 waiting_changed = true;
3581 }
3582 }
3583
3584 /* At some point we really must cap the cargo. Previously this
3585 * was a strict 4095, but now we'll have a less strict, but
3586 * increasingly aggressive truncation of the amount of cargo. */
3587 static const uint WAITING_CARGO_THRESHOLD = 1 << 12;
3588 static const uint WAITING_CARGO_CUT_FACTOR = 1 << 6;
3589 static const uint MAX_WAITING_CARGO = 1 << 15;
3590
3591 if (waiting > WAITING_CARGO_THRESHOLD) {
3592 uint difference = waiting - WAITING_CARGO_THRESHOLD;
3593 waiting -= (difference / WAITING_CARGO_CUT_FACTOR);
3594
3595 waiting = std::min(waiting, MAX_WAITING_CARGO);
3596 waiting_changed = true;
3597 }
3598
3599 /* We can't truncate cargo that's already reserved for loading.
3600 * Thus StoredCount() here. */
3601 if (waiting_changed && waiting < ge->cargo.AvailableCount()) {
3602 /* Feed back the exact own waiting cargo at this station for the
3603 * next rating calculation. */
3604 ge->max_waiting_cargo = 0;
3605
3606 TruncateCargo(cs, ge, ge->cargo.AvailableCount() - waiting);
3607 } else {
3608 /* If the average number per next hop is low, be more forgiving. */
3609 ge->max_waiting_cargo = waiting_avg;
3610 }
3611 }
3612 }
3613 }
3614
3615 StationID index = st->index;
3616 if (waiting_changed) {
3617 SetWindowDirty(WC_STATION_VIEW, index); // update whole window
3618 } else {
3619 SetWindowWidgetDirty(WC_STATION_VIEW, index, WID_SV_ACCEPT_RATING_LIST); // update only ratings list
3620 }
3621 }
3622
3631 void RerouteCargo(Station *st, CargoID c, StationID avoid, StationID avoid2)
3632 {
3633 GoodsEntry &ge = st->goods[c];
3634
3635 /* Reroute cargo in station. */
3636 ge.cargo.Reroute(UINT_MAX, &ge.cargo, avoid, avoid2, &ge);
3637
3638 /* Reroute cargo staged to be transferred. */
3639 for (std::list<Vehicle *>::iterator it(st->loading_vehicles.begin()); it != st->loading_vehicles.end(); ++it) {
3640 for (Vehicle *v = *it; v != nullptr; v = v->Next()) {
3641 if (v->cargo_type != c) continue;
3642 v->cargo.Reroute(UINT_MAX, &v->cargo, avoid, avoid2, &ge);
3643 }
3644 }
3645 }
3646
3655 void DeleteStaleLinks(Station *from)
3656 {
3657 for (CargoID c = 0; c < NUM_CARGO; ++c) {
3658 const bool auto_distributed = (_settings_game.linkgraph.GetDistributionType(c) != DT_MANUAL);
3659 GoodsEntry &ge = from->goods[c];
3660 LinkGraph *lg = LinkGraph::GetIfValid(ge.link_graph);
3661 if (lg == nullptr) continue;
3662 Node node = (*lg)[ge.node];
3663 for (EdgeIterator it(node.Begin()); it != node.End();) {
3664 Edge edge = it->second;
3665 Station *to = Station::Get((*lg)[it->first].Station());
3666 assert(to->goods[c].node == it->first);
3667 ++it; // Do that before removing the edge. Anything else may crash.
3668 assert(_date >= edge.LastUpdate());
3669 uint timeout = LinkGraph::MIN_TIMEOUT_DISTANCE + (DistanceManhattan(from->xy, to->xy) >> 3);
3670 if ((uint)(_date - edge.LastUpdate()) > timeout) {
3671 bool updated = false;
3672
3673 if (auto_distributed) {
3674 /* Have all vehicles refresh their next hops before deciding to
3675 * remove the node. */
3676 std::vector<Vehicle *> vehicles;
3677 for (OrderList *l : OrderList::Iterate()) {
3678 bool found_from = false;
3679 bool found_to = false;
3680 for (Order *order = l->GetFirstOrder(); order != nullptr; order = order->next) {
3681 if (!order->IsType(OT_GOTO_STATION) && !order->IsType(OT_IMPLICIT)) continue;
3682 if (order->GetDestination() == from->index) {
3683 found_from = true;
3684 if (found_to) break;
3685 } else if (order->GetDestination() == to->index) {
3686 found_to = true;
3687 if (found_from) break;
3688 }
3689 }
3690 if (!found_to || !found_from) continue;
3691 vehicles.push_back(l->GetFirstSharedVehicle());
3692 }
3693
3694 auto iter = vehicles.begin();
3695 while (iter != vehicles.end()) {
3696 Vehicle *v = *iter;
3697 /* Do not refresh links of vehicles that have been stopped in depot for a long time. */
3698 if (!v->IsStoppedInDepot() || static_cast<uint>(_date - v->date_of_last_service) <=
3699 LinkGraph::STALE_LINK_DEPOT_TIMEOUT) {
3700 LinkRefresher::Run(v, false); // Don't allow merging. Otherwise lg might get deleted.
3701 }
3702 if (edge.LastUpdate() == _date) {
3703 updated = true;
3704 break;
3705 }
3706
3707 Vehicle *next_shared = v->NextShared();
3708 if (next_shared) {
3709 *iter = next_shared;
3710 ++iter;
3711 } else {
3712 iter = vehicles.erase(iter);
3713 }
3714
3715 if (iter == vehicles.end()) iter = vehicles.begin();
3716 }
3717 }
3718
3719 if (!updated) {
3720 /* If it's still considered dead remove it. */
3721 node.RemoveEdge(to->goods[c].node);
3722 ge.flows.DeleteFlows(to->index);
3723 RerouteCargo(from, c, to->index, from->index);
3724 }
3725 } else if (edge.LastUnrestrictedUpdate() != INVALID_DATE && (uint)(_date - edge.LastUnrestrictedUpdate()) > timeout) {
3726 edge.Restrict();
3727 ge.flows.RestrictFlows(to->index);
3728 RerouteCargo(from, c, to->index, from->index);
3729 } else if (edge.LastRestrictedUpdate() != INVALID_DATE && (uint)(_date - edge.LastRestrictedUpdate()) > timeout) {
3730 edge.Release();
3731 }
3732 }
3733 assert(_date >= lg->LastCompression());
3734 if ((uint)(_date - lg->LastCompression()) > LinkGraph::COMPRESSION_INTERVAL) {
3735 lg->Compress();
3736 }
3737 }
3738 }
3739
3749 void IncreaseStats(Station *st, CargoID cargo, StationID next_station_id, uint capacity, uint usage, uint32 time, EdgeUpdateMode mode)
3750 {
3751 GoodsEntry &ge1 = st->goods[cargo];
3752 Station *st2 = Station::Get(next_station_id);
3753 GoodsEntry &ge2 = st2->goods[cargo];
3754 LinkGraph *lg = nullptr;
3755 if (ge1.link_graph == INVALID_LINK_GRAPH) {
3756 if (ge2.link_graph == INVALID_LINK_GRAPH) {
3757 if (LinkGraph::CanAllocateItem()) {
3758 lg = new LinkGraph(cargo);
3759 LinkGraphSchedule::instance.Queue(lg);
3760 ge2.link_graph = lg->index;
3761 ge2.node = lg->AddNode(st2);
3762 } else {
3763 Debug(misc, 0, "Can't allocate link graph");
3764 }
3765 } else {
3766 lg = LinkGraph::Get(ge2.link_graph);
3767 }
3768 if (lg) {
3769 ge1.link_graph = lg->index;
3770 ge1.node = lg->AddNode(st);
3771 }
3772 } else if (ge2.link_graph == INVALID_LINK_GRAPH) {
3773 lg = LinkGraph::Get(ge1.link_graph);
3774 ge2.link_graph = lg->index;
3775 ge2.node = lg->AddNode(st2);
3776 } else {
3777 lg = LinkGraph::Get(ge1.link_graph);
3778 if (ge1.link_graph != ge2.link_graph) {
3779 LinkGraph *lg2 = LinkGraph::Get(ge2.link_graph);
3780 if (lg->Size() < lg2->Size()) {
3781 LinkGraphSchedule::instance.Unqueue(lg);
3782 lg2->Merge(lg); // Updates GoodsEntries of lg
3783 lg = lg2;
3784 } else {
3785 LinkGraphSchedule::instance.Unqueue(lg2);
3786 lg->Merge(lg2); // Updates GoodsEntries of lg2
3787 }
3788 }
3789 }
3790 if (lg != nullptr) {
3791 (*lg)[ge1.node].UpdateEdge(ge2.node, capacity, usage, time, mode);
3792 }
3793 }
3794
3801 void IncreaseStats(Station *st, const Vehicle *front, StationID next_station_id, uint32 time)
3802 {
3803 for (const Vehicle *v = front; v != nullptr; v = v->Next()) {
3804 if (v->refit_cap > 0) {
3805 /* The cargo count can indeed be higher than the refit_cap if
3806 * wagons have been auto-replaced and subsequently auto-
3807 * refitted to a higher capacity. The cargo gets redistributed
3808 * among the wagons in that case.
3809 * As usage is not such an important figure anyway we just
3810 * ignore the additional cargo then.*/
3811 IncreaseStats(st, v->cargo_type, next_station_id, v->refit_cap,
3812 std::min<uint>(v->refit_cap, v->cargo.StoredCount()), time, EUM_INCREASE);
3813 }
3814 }
3815 }
3816
3817 /* called for every station each tick */
3818 static void StationHandleSmallTick(BaseStation *st)
3819 {
3820 if ((st->facilities & FACIL_WAYPOINT) != 0 || !st->IsInUse()) return;
3821
3822 byte b = st->delete_ctr + 1;
3823 if (b >= STATION_RATING_TICKS) b = 0;
3824 st->delete_ctr = b;
3825
3826 if (b == 0) UpdateStationRating(Station::From(st));
3827 }
3828
3829 void OnTick_Station()
3830 {
3831 if (_game_mode == GM_EDITOR) return;
3832
3833 for (BaseStation *st : BaseStation::Iterate()) {
3834 StationHandleSmallTick(st);
3835
3836 /* Clean up the link graph about once a week. */
3837 if (Station::IsExpected(st) && (_tick_counter + st->index) % STATION_LINKGRAPH_TICKS == 0) {
3838 DeleteStaleLinks(Station::From(st));
3839 };
3840
3841 /* Run STATION_ACCEPTANCE_TICKS = 250 tick interval trigger for station animation.
3842 * Station index is included so that triggers are not all done
3843 * at the same time. */
3844 if ((_tick_counter + st->index) % STATION_ACCEPTANCE_TICKS == 0) {
3845 /* Stop processing this station if it was deleted */
3846 if (!StationHandleBigTick(st)) continue;
3847 TriggerStationAnimation(st, st->xy, SAT_250_TICKS);
3848 if (Station::IsExpected(st)) AirportAnimationTrigger(Station::From(st), AAT_STATION_250_TICKS);
3849 }
3850 }
3851 }
3852
3854 void StationMonthlyLoop()
3855 {
3856 for (Station *st : Station::Iterate()) {
3857 for (CargoID i = 0; i < NUM_CARGO; i++) {
3858 GoodsEntry *ge = &st->goods[i];
3859 SB(ge->status, GoodsEntry::GES_LAST_MONTH, 1, GB(ge->status, GoodsEntry::GES_CURRENT_MONTH, 1));
3860 ClrBit(ge->status, GoodsEntry::GES_CURRENT_MONTH);
3861 }
3862 }
3863 }
3864
3865
3866 void ModifyStationRatingAround(TileIndex tile, Owner owner, int amount, uint radius)
3867 {
3868 ForAllStationsRadius(tile, radius, [&](Station *st) {
3869 if (st->owner == owner && DistanceManhattan(tile, st->xy) <= radius) {
3870 for (CargoID i = 0; i < NUM_CARGO; i++) {
3871 GoodsEntry *ge = &st->goods[i];
3872
3873 if (ge->status != 0) {
3874 ge->rating = Clamp(ge->rating + amount, 0, 255);
3875 }
3876 }
3877 }
3878 });
3879 }
3880
3881 static uint UpdateStationWaiting(Station *st, CargoID type, uint amount, SourceType source_type, SourceID source_id)
3882 {
3883 /* We can't allocate a CargoPacket? Then don't do anything
3884 * at all; i.e. just discard the incoming cargo. */
3885 if (!CargoPacket::CanAllocateItem()) return 0;
3886
3887 GoodsEntry &ge = st->goods[type];
3888 amount += ge.amount_fract;
3889 ge.amount_fract = GB(amount, 0, 8);
3890
3891 amount >>= 8;
3892 /* No new "real" cargo item yet. */
3893 if (amount == 0) return 0;
3894
3895 StationID next = ge.GetVia(st->index);
3896 ge.cargo.Append(new CargoPacket(st->index, st->xy, amount, source_type, source_id), next);
3897 LinkGraph *lg = nullptr;
3898 if (ge.link_graph == INVALID_LINK_GRAPH) {
3899 if (LinkGraph::CanAllocateItem()) {
3900 lg = new LinkGraph(type);
3901 LinkGraphSchedule::instance.Queue(lg);
3902 ge.link_graph = lg->index;
3903 ge.node = lg->AddNode(st);
3904 } else {
3905 Debug(misc, 0, "Can't allocate link graph");
3906 }
3907 } else {
3908 lg = LinkGraph::Get(ge.link_graph);
3909 }
3910 if (lg != nullptr) (*lg)[ge.node].UpdateSupply(amount);
3911
3912 if (!ge.HasRating()) {
3913 InvalidateWindowData(WC_STATION_LIST, st->index);
3914 SetBit(ge.status, GoodsEntry::GES_RATING);
3915 }
3916
3917 TriggerStationRandomisation(st, st->xy, SRT_NEW_CARGO, type);
3918 TriggerStationAnimation(st, st->xy, SAT_NEW_CARGO, type);
3919 AirportAnimationTrigger(st, AAT_STATION_NEW_CARGO, type);
3920
3921 SetWindowDirty(WC_STATION_VIEW, st->index);
3922 st->MarkTilesDirty(true);
3923 return amount;
3924 }
3925
3926 static bool IsUniqueStationName(const std::string &name)
3927 {
3928 for (const Station *st : Station::Iterate()) {
3929 if (!st->name.empty() && st->name == name) return false;
3930 }
3931
3932 return true;
3933 }
3934
3944 CommandCost CmdRenameStation(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
3945 {
3946 Station *st = Station::GetIfValid(p1);
3947 if (st == nullptr) return CMD_ERROR;
3948
3949 CommandCost ret = CheckOwnership(st->owner);
3950 if (ret.Failed()) return ret;
3951
3952 bool reset = text.empty();
3953
3954 if (!reset) {
3955 if (Utf8StringLength(text) >= MAX_LENGTH_STATION_NAME_CHARS) return CMD_ERROR;
3956 if (!IsUniqueStationName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
3957 }
3958
3959 if (flags & DC_EXEC) {
3960 st->cached_name.clear();
3961 if (reset) {
3962 st->name.clear();
3963 } else {
3964 st->name = text;
3965 }
3966
3967 st->UpdateVirtCoord();
3968 InvalidateWindowData(WC_STATION_LIST, st->owner, 1);
3969 }
3970
3971 return CommandCost();
3972 }
3973
3974 static void AddNearbyStationsByCatchment(TileIndex tile, StationList *stations, StationList &nearby)
3975 {
3976 for (Station *st : nearby) {
3977 if (st->TileIsInCatchment(tile)) stations->insert(st);
3978 }
3979 }
3980
3985 const StationList *StationFinder::GetStations()
3986 {
3987 if (this->tile != INVALID_TILE) {
3988 if (IsTileType(this->tile, MP_HOUSE)) {
3989 /* Town nearby stations need to be filtered per tile. */
3990 assert(this->w == 1 && this->h == 1);
3991 AddNearbyStationsByCatchment(this->tile, &this->stations, Town::GetByTile(this->tile)->stations_near);
3992 } else {
3993 ForAllStationsAroundTiles(*this, [this](Station *st, TileIndex tile) {
3994 this->stations.insert(st);
3995 return true;
3996 });
3997 }
3998 this->tile = INVALID_TILE;
3999 }
4000 return &this->stations;
4001 }
4002
4003
4004 static bool CanMoveGoodsToStation(const Station *st, CargoID type)
4005 {
4006 /* Is the station reserved exclusively for somebody else? */
4007 if (st->owner != OWNER_NONE && st->town->exclusive_counter > 0 && st->town->exclusivity != st->owner) return false;
4008
4009 /* Lowest possible rating, better not to give cargo anymore. */
4010 if (st->goods[type].rating == 0) return false;
4011
4012 /* Selectively servicing stations, and not this one. */
4013 if (_settings_game.order.selectgoods && !st->goods[type].HasVehicleEverTriedLoading()) return false;
4014
4015 if (IsCargoInClass(type, CC_PASSENGERS)) {
4016 /* Passengers are never served by just a truck stop. */
4017 if (st->facilities == FACIL_TRUCK_STOP) return false;
4018 } else {
4019 /* Non-passengers are never served by just a bus stop. */
4020 if (st->facilities == FACIL_BUS_STOP) return false;
4021 }
4022 return true;
4023 }
4024
4025 uint MoveGoodsToStation(CargoID type, uint amount, SourceType source_type, SourceID source_id, const StationList *all_stations, Owner exclusivity)
4026 {
4027 /* Return if nothing to do. Also the rounding below fails for 0. */
4028 if (all_stations->empty()) return 0;
4029 if (amount == 0) return 0;
4030
4031 Station *first_station = nullptr;
4032 typedef std::pair<Station *, uint> StationInfo;
4033 std::vector<StationInfo> used_stations;
4034
4035 for (Station *st : *all_stations) {
4036 if (exclusivity != INVALID_OWNER && exclusivity != st->owner) continue;
4037 if (!CanMoveGoodsToStation(st, type)) continue;
4038
4039 /* Avoid allocating a vector if there is only one station to significantly
4040 * improve performance in this common case. */
4041 if (first_station == nullptr) {
4042 first_station = st;
4043 continue;
4044 }
4045 if (used_stations.empty()) {
4046 used_stations.reserve(2);
4047 used_stations.emplace_back(std::make_pair(first_station, 0));
4048 }
4049 used_stations.emplace_back(std::make_pair(st, 0));
4050 }
4051
4052 /* no stations around at all? */
4053 if (first_station == nullptr) return 0;
4054
4055 if (used_stations.empty()) {
4056 /* only one station around */
4057 amount *= first_station->goods[type].rating + 1;
4058 return UpdateStationWaiting(first_station, type, amount, source_type, source_id);
4059 }
4060
4061 uint company_best[OWNER_NONE + 1] = {}; // best rating for each company, including OWNER_NONE
4062 uint company_sum[OWNER_NONE + 1] = {}; // sum of ratings for each company
4063 uint best_rating = 0;
4064 uint best_sum = 0; // sum of best ratings for each company
4065
4066 for (auto &p : used_stations) {
4067 auto owner = p.first->owner;
4068 auto rating = p.first->goods[type].rating;
4069 if (rating > company_best[owner]) {
4070 best_sum += rating - company_best[owner]; // it's usually faster than iterating companies later
4071 company_best[owner] = rating;
4072 if (rating > best_rating) best_rating = rating;
4073 }
4074 company_sum[owner] += rating;
4075 }
4076
4077 /* From now we'll calculate with fractional cargo amounts.
4078 * First determine how much cargo we really have. */
4079 amount *= best_rating + 1;
4080
4081 uint moving = 0;
4082 for (auto &p : used_stations) {
4083 uint owner = p.first->owner;
4084 /* Multiply the amount by (company best / sum of best for each company) to get cargo allocated to a company
4085 * and by (station rating / sum of ratings in a company) to get the result for a single station. */
4086 p.second = amount * company_best[owner] * p.first->goods[type].rating / best_sum / company_sum[owner];
4087 moving += p.second;
4088 }
4089
4090 /* If there is some cargo left due to rounding issues distribute it among the best rated stations. */
4091 if (amount > moving) {
4092 std::stable_sort(used_stations.begin(), used_stations.end(), [type](const StationInfo &a, const StationInfo &b) {
4093 return b.first->goods[type].rating < a.first->goods[type].rating;
4094 });
4095
4096 assert(amount - moving <= used_stations.size());
4097 for (uint i = 0; i < amount - moving; i++) {
4098 used_stations[i].second++;
4099 }
4100 }
4101
4102 uint moved = 0;
4103 for (auto &p : used_stations) {
4104 moved += UpdateStationWaiting(p.first, type, p.second, source_type, source_id);
4105 }
4106
4107 return moved;
4108 }
4109
4110 void UpdateStationDockingTiles(Station *st)
4111 {
4112 st->docking_station.Clear();
4113
4114 /* For neutral stations, start with the industry area instead of dock area */
4115 const TileArea *area = st->industry != nullptr ? &st->industry->location : &st->ship_station;
4116
4117 if (area->tile == INVALID_TILE) return;
4118
4119 int x = TileX(area->tile);
4120 int y = TileY(area->tile);
4121
4122 /* Expand the area by a tile on each side while
4123 * making sure that we remain inside the map. */
4124 int x2 = std::min<int>(x + area->w + 1, MapSizeX());
4125 int x1 = std::max<int>(x - 1, 0);
4126
4127 int y2 = std::min<int>(y + area->h + 1, MapSizeY());
4128 int y1 = std::max<int>(y - 1, 0);
4129
4130 TileArea ta(TileXY(x1, y1), TileXY(x2 - 1, y2 - 1));
4131 for (TileIndex tile : ta) {
4132 if (IsValidTile(tile) && IsPossibleDockingTile(tile)) CheckForDockingTile(tile);
4133 }
4134 }
4135
4136 void BuildOilRig(TileIndex tile)
4137 {
4138 if (!Station::CanAllocateItem()) {
4139 Debug(misc, 0, "Can't allocate station for oilrig at 0x{:X}, reverting to oilrig only", tile);
4140 return;
4141 }
4142
4143 Station *st = new Station(tile);
4144 _station_kdtree.Insert(st->index);
4145 st->town = ClosestTownFromTile(tile, UINT_MAX);
4146
4147 st->string_id = GenerateStationName(st, tile, STATIONNAMING_OILRIG);
4148
4149 assert(IsTileType(tile, MP_INDUSTRY));
4150 /* Mark industry as associated both ways */
4151 st->industry = Industry::GetByTile(tile);
4152 st->industry->neutral_station = st;
4153 DeleteAnimatedTile(tile);
4154 MakeOilrig(tile, st->index, GetWaterClass(tile));
4155
4156 st->owner = OWNER_NONE;
4157 st->airport.type = AT_OILRIG;
4158 st->airport.Add(tile);
4159 st->ship_station.Add(tile);
4160 st->facilities = FACIL_AIRPORT | FACIL_DOCK;
4161 st->build_date = _date;
4162 UpdateStationDockingTiles(st);
4163
4164 st->rect.BeforeAddTile(tile, StationRect::ADD_FORCE);
4165
4166 st->UpdateVirtCoord();
4167 st->RecomputeCatchment();
4168 UpdateStationAcceptance(st, false);
4169 }
4170
4171 void DeleteOilRig(TileIndex tile)
4172 {
4173 Station *st = Station::GetByTile(tile);
4174
4175 MakeWaterKeepingClass(tile, OWNER_NONE);
4176
4177 /* The oil rig station is not supposed to be shared with anything else */
4178 assert(st->facilities == (FACIL_AIRPORT | FACIL_DOCK) && st->airport.type == AT_OILRIG);
4179 if (st->industry != nullptr && st->industry->neutral_station == st) {
4180 /* Don't leave dangling neutral station pointer */
4181 st->industry->neutral_station = nullptr;
4182 }
4183 delete st;
4184 }
4185
4186 static void ChangeTileOwner_Station(TileIndex tile, Owner old_owner, Owner new_owner)
4187 {
4188 if (IsRoadStopTile(tile)) {
4189 for (RoadTramType rtt : _roadtramtypes) {
4190 /* Update all roadtypes, no matter if they are present */
4191 if (GetRoadOwner(tile, rtt) == old_owner) {
4192 RoadType rt = GetRoadType(tile, rtt);
4193 if (rt != INVALID_ROADTYPE) {
4194 /* A drive-through road-stop has always two road bits. No need to dirty windows here, we'll redraw the whole screen anyway. */
4195 Company::Get(old_owner)->infrastructure.road[rt] -= 2;
4196 if (new_owner != INVALID_OWNER) Company::Get(new_owner)->infrastructure.road[rt] += 2;
4197 }
4198 SetRoadOwner(tile, rtt, new_owner == INVALID_OWNER ? OWNER_NONE : new_owner);
4199 }
4200 }
4201 }
4202
4203 if (!IsTileOwner(tile, old_owner)) return;
4204
4205 if (new_owner != INVALID_OWNER) {
4206 /* Update company infrastructure counts. Only do it here
4207 * if the new owner is valid as otherwise the clear
4208 * command will do it for us. No need to dirty windows
4209 * here, we'll redraw the whole screen anyway.*/
4210 Company *old_company = Company::Get(old_owner);
4211 Company *new_company = Company::Get(new_owner);
4212
4213 /* Update counts for underlying infrastructure. */
4214 switch (GetStationType(tile)) {
4215 case STATION_RAIL:
4216 case STATION_WAYPOINT:
4217 if (!IsStationTileBlocked(tile)) {
4218 old_company->infrastructure.rail[GetRailType(tile)]--;
4219 new_company->infrastructure.rail[GetRailType(tile)]++;
4220 }
4221 break;
4222
4223 case STATION_BUS:
4224 case STATION_TRUCK:
4225 /* Road stops were already handled above. */
4226 break;
4227
4228 case STATION_BUOY:
4229 case STATION_DOCK:
4230 if (GetWaterClass(tile) == WATER_CLASS_CANAL) {
4231 old_company->infrastructure.water--;
4232 new_company->infrastructure.water++;
4233 }
4234 break;
4235
4236 default:
4237 break;
4238 }
4239
4240 /* Update station tile count. */
4241 if (!IsBuoy(tile) && !IsAirport(tile)) {
4242 old_company->infrastructure.station--;
4243 new_company->infrastructure.station++;
4244 }
4245
4246 /* for buoys, owner of tile is owner of water, st->owner == OWNER_NONE */
4247 SetTileOwner(tile, new_owner);
4248 InvalidateWindowClassesData(WC_STATION_LIST, 0);
4249 } else {
4250 if (IsDriveThroughStopTile(tile)) {
4251 /* Remove the drive-through road stop */
4252 DoCommand(tile, 1 | 1 << 8, (GetStationType(tile) == STATION_TRUCK) ? ROADSTOP_TRUCK : ROADSTOP_BUS, DC_EXEC | DC_BANKRUPT, CMD_REMOVE_ROAD_STOP);
4253 assert(IsTileType(tile, MP_ROAD));
4254 /* Change owner of tile and all roadtypes */
4255 ChangeTileOwner(tile, old_owner, new_owner);
4256 } else {
4257 DoCommand(tile, 0, 0, DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR);
4258 /* Set tile owner of water under (now removed) buoy and dock to OWNER_NONE.
4259 * Update owner of buoy if it was not removed (was in orders).
4260 * Do not update when owned by OWNER_WATER (sea and rivers). */
4261 if ((IsTileType(tile, MP_WATER) || IsBuoyTile(tile)) && IsTileOwner(tile, old_owner)) SetTileOwner(tile, OWNER_NONE);
4262 }
4263 }
4264 }
4265
4274 static bool CanRemoveRoadWithStop(TileIndex tile, DoCommandFlag flags)
4275 {
4276 /* Yeah... water can always remove stops, right? */
4277 if (_current_company == OWNER_WATER) return true;
4278
4279 if (GetRoadTypeTram(tile) != INVALID_ROADTYPE) {
4280 Owner tram_owner = GetRoadOwner(tile, RTT_TRAM);
4281 if (tram_owner != OWNER_NONE && CheckOwnership(tram_owner).Failed()) return false;
4282 }
4283 if (GetRoadTypeRoad(tile) != INVALID_ROADTYPE) {
4284 Owner road_owner = GetRoadOwner(tile, RTT_ROAD);
4285 if (road_owner != OWNER_TOWN) {
4286 if (road_owner != OWNER_NONE && CheckOwnership(road_owner).Failed()) return false;
4287 } else {
4288 if (CheckAllowRemoveRoad(tile, GetAnyRoadBits(tile, RTT_ROAD), OWNER_TOWN, RTT_ROAD, flags).Failed()) return false;
4289 }
4290 }
4291
4292 return true;
4293 }
4294
4301 CommandCost ClearTile_Station(TileIndex tile, DoCommandFlag flags)
4302 {
4303 if (flags & DC_AUTO) {
4304 switch (GetStationType(tile)) {
4305 default: break;
4306 case STATION_RAIL: return_cmd_error(STR_ERROR_MUST_DEMOLISH_RAILROAD);
4307 case STATION_WAYPOINT: return_cmd_error(STR_ERROR_BUILDING_MUST_BE_DEMOLISHED);
4308 case STATION_AIRPORT: return_cmd_error(STR_ERROR_MUST_DEMOLISH_AIRPORT_FIRST);
4309 case STATION_TRUCK: return_cmd_error(HasTileRoadType(tile, RTT_TRAM) ? STR_ERROR_MUST_DEMOLISH_CARGO_TRAM_STATION_FIRST : STR_ERROR_MUST_DEMOLISH_TRUCK_STATION_FIRST);
4310 case STATION_BUS: return_cmd_error(HasTileRoadType(tile, RTT_TRAM) ? STR_ERROR_MUST_DEMOLISH_PASSENGER_TRAM_STATION_FIRST : STR_ERROR_MUST_DEMOLISH_BUS_STATION_FIRST);
4311 case STATION_BUOY: return_cmd_error(STR_ERROR_BUOY_IN_THE_WAY);
4312 case STATION_DOCK: return_cmd_error(STR_ERROR_MUST_DEMOLISH_DOCK_FIRST);
4313 case STATION_OILRIG:
4314 SetDParam(1, STR_INDUSTRY_NAME_OIL_RIG);
4315 return_cmd_error(STR_ERROR_GENERIC_OBJECT_IN_THE_WAY);
4316 }
4317 }
4318
4319 switch (GetStationType(tile)) {
4320 case STATION_RAIL: return RemoveRailStation(tile, flags);
4321 case STATION_WAYPOINT: return RemoveRailWaypoint(tile, flags);
4322 case STATION_AIRPORT: return RemoveAirport(tile, flags);
4323 case STATION_TRUCK:
4324 if (IsDriveThroughStopTile(tile) && !CanRemoveRoadWithStop(tile, flags)) {
4325 return_cmd_error(STR_ERROR_MUST_DEMOLISH_TRUCK_STATION_FIRST);
4326 }
4327 return RemoveRoadStop(tile, flags);
4328 case STATION_BUS:
4329 if (IsDriveThroughStopTile(tile) && !CanRemoveRoadWithStop(tile, flags)) {
4330 return_cmd_error(STR_ERROR_MUST_DEMOLISH_BUS_STATION_FIRST);
4331 }
4332 return RemoveRoadStop(tile, flags);
4333 case STATION_BUOY: return RemoveBuoy(tile, flags);
4334 case STATION_DOCK: return RemoveDock(tile, flags);
4335 default: break;
4336 }
4337
4338 return CMD_ERROR;
4339 }
4340
4341 static CommandCost TerraformTile_Station(TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new)
4342 {
4343 if (_settings_game.construction.build_on_slopes && AutoslopeEnabled()) {
4344 /* TODO: If you implement newgrf callback 149 'land slope check', you have to decide what to do with it here.
4345 * TTDP does not call it.
4346 */
4347 if (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new)) {
4348 switch (GetStationType(tile)) {
4349 case STATION_WAYPOINT:
4350 case STATION_RAIL: {
4351 DiagDirection direction = AxisToDiagDir(GetRailStationAxis(tile));
4352 if (!AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, direction)) break;
4353 if (!AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, ReverseDiagDir(direction))) break;
4354 return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
4355 }
4356
4357 case STATION_AIRPORT:
4358 return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
4359
4360 case STATION_TRUCK:
4361 case STATION_BUS: {
4362 DiagDirection direction = GetRoadStopDir(tile);
4363 if (!AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, direction)) break;
4364 if (IsDriveThroughStopTile(tile)) {
4365 if (!AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, ReverseDiagDir(direction))) break;
4366 }
4367 return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
4368 }
4369
4370 default: break;
4371 }
4372 }
4373 }
4374 return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
4375 }
4376
4382 uint FlowStat::GetShare(StationID st) const
4383 {
4384 uint32 prev = 0;
4385 for (SharesMap::const_iterator it = this->shares.begin(); it != this->shares.end(); ++it) {
4386 if (it->second == st) {
4387 return it->first - prev;
4388 } else {
4389 prev = it->first;
4390 }
4391 }
4392 return 0;
4393 }
4394
4401 StationID FlowStat::GetVia(StationID excluded, StationID excluded2) const
4402 {
4403 if (this->unrestricted == 0) return INVALID_STATION;
4404 assert(!this->shares.empty());
4405 SharesMap::const_iterator it = this->shares.upper_bound(RandomRange(this->unrestricted));
4406 assert(it != this->shares.end() && it->first <= this->unrestricted);
4407 if (it->second != excluded && it->second != excluded2) return it->second;
4408
4409 /* We've hit one of the excluded stations.
4410 * Draw another share, from outside its range. */
4411
4412 uint end = it->first;
4413 uint begin = (it == this->shares.begin() ? 0 : (--it)->first);
4414 uint interval = end - begin;
4415 if (interval >= this->unrestricted) return INVALID_STATION; // Only one station in the map.
4416 uint new_max = this->unrestricted - interval;
4417 uint rand = RandomRange(new_max);
4418 SharesMap::const_iterator it2 = (rand < begin) ? this->shares.upper_bound(rand) :
4419 this->shares.upper_bound(rand + interval);
4420 assert(it2 != this->shares.end() && it2->first <= this->unrestricted);
4421 if (it2->second != excluded && it2->second != excluded2) return it2->second;
4422
4423 /* We've hit the second excluded station.
4424 * Same as before, only a bit more complicated. */
4425
4426 uint end2 = it2->first;
4427 uint begin2 = (it2 == this->shares.begin() ? 0 : (--it2)->first);
4428 uint interval2 = end2 - begin2;
4429 if (interval2 >= new_max) return INVALID_STATION; // Only the two excluded stations in the map.
4430 new_max -= interval2;
4431 if (begin > begin2) {
4432 Swap(begin, begin2);
4433 Swap(end, end2);
4434 Swap(interval, interval2);
4435 }
4436 rand = RandomRange(new_max);
4437 SharesMap::const_iterator it3 = this->shares.upper_bound(this->unrestricted);
4438 if (rand < begin) {
4439 it3 = this->shares.upper_bound(rand);
4440 } else if (rand < begin2 - interval) {
4441 it3 = this->shares.upper_bound(rand + interval);
4442 } else {
4443 it3 = this->shares.upper_bound(rand + interval + interval2);
4444 }
4445 assert(it3 != this->shares.end() && it3->first <= this->unrestricted);
4446 return it3->second;
4447 }
4448
4454 void FlowStat::Invalidate()
4455 {
4456 assert(!this->shares.empty());
4457 SharesMap new_shares;
4458 uint i = 0;
4459 for (SharesMap::iterator it(this->shares.begin()); it != this->shares.end(); ++it) {
4460 new_shares[++i] = it->second;
4461 if (it->first == this->unrestricted) this->unrestricted = i;
4462 }
4463 this->shares.swap(new_shares);
4464 assert(!this->shares.empty() && this->unrestricted <= (--this->shares.end())->first);
4465 }
4466
4473 void FlowStat::ChangeShare(StationID st, int flow)
4474 {
4475 /* We assert only before changing as afterwards the shares can actually
4476 * be empty. In that case the whole flow stat must be deleted then. */
4477 assert(!this->shares.empty());
4478
4479 uint removed_shares = 0;
4480 uint added_shares = 0;
4481 uint last_share = 0;
4482 SharesMap new_shares;
4483 for (SharesMap::iterator it(this->shares.begin()); it != this->shares.end(); ++it) {
4484 if (it->second == st) {
4485 if (flow < 0) {
4486 uint share = it->first - last_share;
4487 if (flow == INT_MIN || (uint)(-flow) >= share) {
4488 removed_shares += share;
4489 if (it->first <= this->unrestricted) this->unrestricted -= share;
4490 if (flow != INT_MIN) flow += share;
4491 last_share = it->first;
4492 continue; // remove the whole share
4493 }
4494 removed_shares += (uint)(-flow);
4495 } else {
4496 added_shares += (uint)(flow);
4497 }
4498 if (it->first <= this->unrestricted) this->unrestricted += flow;
4499
4500 /* If we don't continue above the whole flow has been added or
4501 * removed. */
4502 flow = 0;
4503 }
4504 new_shares[it->first + added_shares - removed_shares] = it->second;
4505 last_share = it->first;
4506 }
4507 if (flow > 0) {
4508 new_shares[last_share + (uint)flow] = st;
4509 if (this->unrestricted < last_share) {
4510 this->ReleaseShare(st);
4511 } else {
4512 this->unrestricted += flow;
4513 }
4514 }
4515 this->shares.swap(new_shares);
4516 }
4517
4523 void FlowStat::RestrictShare(StationID st)
4524 {
4525 assert(!this->shares.empty());
4526 uint flow = 0;
4527 uint last_share = 0;
4528 SharesMap new_shares;
4529 for (SharesMap::iterator it(this->shares.begin()); it != this->shares.end(); ++it) {
4530 if (flow == 0) {
4531 if (it->first > this->unrestricted) return; // Not present or already restricted.
4532 if (it->second == st) {
4533 flow = it->first - last_share;
4534 this->unrestricted -= flow;
4535 } else {
4536 new_shares[it->first] = it->second;
4537 }
4538 } else {
4539 new_shares[it->first - flow] = it->second;
4540 }
4541 last_share = it->first;
4542 }
4543 if (flow == 0) return;
4544 new_shares[last_share + flow] = st;
4545 this->shares.swap(new_shares);
4546 assert(!this->shares.empty());
4547 }
4548
4554 void FlowStat::ReleaseShare(StationID st)
4555 {
4556 assert(!this->shares.empty());
4557 uint flow = 0;
4558 uint next_share = 0;
4559 bool found = false;
4560 for (SharesMap::reverse_iterator it(this->shares.rbegin()); it != this->shares.rend(); ++it) {
4561 if (it->first < this->unrestricted) return; // Note: not <= as the share may hit the limit.
4562 if (found) {
4563 flow = next_share - it->first;
4564 this->unrestricted += flow;
4565 break;
4566 } else {
4567 if (it->first == this->unrestricted) return; // !found -> Limit not hit.
4568 if (it->second == st) found = true;
4569 }
4570 next_share = it->first;
4571 }
4572 if (flow == 0) return;
4573 SharesMap new_shares;
4574 new_shares[flow] = st;
4575 for (SharesMap::iterator it(this->shares.begin()); it != this->shares.end(); ++it) {
4576 if (it->second != st) {
4577 new_shares[flow + it->first] = it->second;
4578 } else {
4579 flow = 0;
4580 }
4581 }
4582 this->shares.swap(new_shares);
4583 assert(!this->shares.empty());
4584 }
4585
4591 void FlowStat::ScaleToMonthly(uint runtime)
4592 {
4593 assert(runtime > 0);
4594 SharesMap new_shares;
4595 uint share = 0;
4596 for (SharesMap::iterator i = this->shares.begin(); i != this->shares.end(); ++i) {
4597 share = std::max(share + 1, i->first * 30 / runtime);
4598 new_shares[share] = i->second;
4599 if (this->unrestricted == i->first) this->unrestricted = share;
4600 }
4601 this->shares.swap(new_shares);
4602 }
4603
4610 void FlowStatMap::AddFlow(StationID origin, StationID via, uint flow)
4611 {
4612 FlowStatMap::iterator origin_it = this->find(origin);
4613 if (origin_it == this->end()) {
4614 this->insert(std::make_pair(origin, FlowStat(via, flow)));
4615 } else {
4616 origin_it->second.ChangeShare(via, flow);
4617 assert(!origin_it->second.GetShares()->empty());
4618 }
4619 }
4620
4629 void FlowStatMap::PassOnFlow(StationID origin, StationID via, uint flow)
4630 {
4631 FlowStatMap::iterator prev_it = this->find(origin);
4632 if (prev_it == this->end()) {
4633 FlowStat fs(via, flow);
4634 fs.AppendShare(INVALID_STATION, flow);
4635 this->insert(std::make_pair(origin, fs));
4636 } else {
4637 prev_it->second.ChangeShare(via, flow);
4638 prev_it->second.ChangeShare(INVALID_STATION, flow);
4639 assert(!prev_it->second.GetShares()->empty());
4640 }
4641 }
4642
4647 void FlowStatMap::FinalizeLocalConsumption(StationID self)
4648 {
4649 for (FlowStatMap::iterator i = this->begin(); i != this->end(); ++i) {
4650 FlowStat &fs = i->second;
4651 uint local = fs.GetShare(INVALID_STATION);
4652 if (local > INT_MAX) { // make sure it fits in an int
4653 fs.ChangeShare(self, -INT_MAX);
4654 fs.ChangeShare(INVALID_STATION, -INT_MAX);
4655 local -= INT_MAX;
4656 }
4657 fs.ChangeShare(self, -(int)local);
4658 fs.ChangeShare(INVALID_STATION, -(int)local);
4659
4660 /* If the local share is used up there must be a share for some
4661 * remote station. */
4662 assert(!fs.GetShares()->empty());
4663 }
4664 }
4665
4672 StationIDStack FlowStatMap::DeleteFlows(StationID via)
4673 {
4674 StationIDStack ret;
4675 for (FlowStatMap::iterator f_it = this->begin(); f_it != this->end();) {
4676 FlowStat &s_flows = f_it->second;
4677 s_flows.ChangeShare(via, INT_MIN);
4678 if (s_flows.GetShares()->empty()) {
4679 ret.Push(f_it->first);
4680 this->erase(f_it++);
4681 } else {
4682 ++f_it;
4683 }
4684 }
4685 return ret;
4686 }
4687
4692 void FlowStatMap::RestrictFlows(StationID via)
4693 {
4694 for (FlowStatMap::iterator it = this->begin(); it != this->end(); ++it) {
4695 it->second.RestrictShare(via);
4696 }
4697 }
4698
4703 void FlowStatMap::ReleaseFlows(StationID via)
4704 {
4705 for (FlowStatMap::iterator it = this->begin(); it != this->end(); ++it) {
4706 it->second.ReleaseShare(via);
4707 }
4708 }
4709
4714 uint FlowStatMap::GetFlow() const
4715 {
4716 uint ret = 0;
4717 for (FlowStatMap::const_iterator i = this->begin(); i != this->end(); ++i) {
4718 ret += (--(i->second.GetShares()->end()))->first;
4719 }
4720 return ret;
4721 }
4722
4728 uint FlowStatMap::GetFlowVia(StationID via) const
4729 {
4730 uint ret = 0;
4731 for (FlowStatMap::const_iterator i = this->begin(); i != this->end(); ++i) {
4732 ret += i->second.GetShare(via);
4733 }
4734 return ret;
4735 }
4736
4742 uint FlowStatMap::GetFlowFrom(StationID from) const
4743 {
4744 FlowStatMap::const_iterator i = this->find(from);
4745 if (i == this->end()) return 0;
4746 return (--(i->second.GetShares()->end()))->first;
4747 }
4748
4755 uint FlowStatMap::GetFlowFromVia(StationID from, StationID via) const
4756 {
4757 FlowStatMap::const_iterator i = this->find(from);
4758 if (i == this->end()) return 0;
4759 return i->second.GetShare(via);
4760 }
4761
4762 extern const TileTypeProcs _tile_type_station_procs = {
4763 DrawTile_Station, // draw_tile_proc
4764 GetSlopePixelZ_Station, // get_slope_z_proc
4765 ClearTile_Station, // clear_tile_proc
4766 nullptr, // add_accepted_cargo_proc
4767 GetTileDesc_Station, // get_tile_desc_proc
4768 GetTileTrackStatus_Station, // get_tile_track_status_proc
4769 ClickTile_Station, // click_tile_proc
4770 AnimateTile_Station, // animate_tile_proc
4771 TileLoop_Station, // tile_loop_proc
4772 ChangeTileOwner_Station, // change_tile_owner_proc
4773 nullptr, // add_produced_cargo_proc
4774 VehicleEnter_Station, // vehicle_enter_tile_proc
4775 GetFoundation_Station, // get_foundation_proc
4776 TerraformTile_Station, // terraform_tile_proc
4777 };
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition: vehicle_type.h:27
DrawRailTileSeqInGUI
static void DrawRailTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32 total_offset, uint32 newgrf_offset, PaletteID default_palette)
Draw tile sprite sequence in GUI with railroad specifics.
Definition: sprite.h:99
VETS_STATION_ID_OFFSET
@ VETS_STATION_ID_OFFSET
Shift the VehicleEnterTileStatus this many bits to the right to get the station ID when VETS_ENTERED_...
Definition: tile_cmd.h:30
AllocateSpecToStation
int AllocateSpecToStation(const StationSpec *statspec, BaseStation *st, bool exec)
Allocate a StationSpec to a Station.
Definition: newgrf_station.cpp:680
RoadVehicle
Buses, trucks and trams belong to this class.
Definition: roadveh.h:107
AAT_STATION_250_TICKS
@ AAT_STATION_250_TICKS
Triggered every 250 ticks (for all tiles at the same time).
Definition: newgrf_animation_type.h:51
TileInfo::z
int z
Height.
Definition: tile_cmd.h:47
TileDesc::airport_class
StringID airport_class
Name of the airport class.
Definition: tile_cmd.h:58
MP_HOUSE
@ MP_HOUSE
A house by a town.
Definition: tile_type.h:49
DeleteNewGRFInspectWindow
void DeleteNewGRFInspectWindow(GrfSpecFeature feature, uint index)
Delete inspect window for a given feature and index.
Definition: newgrf_debug_gui.cpp:734
IsTileFlat
bool IsTileFlat(TileIndex tile, int *h)
Check if a given tile is flat.
Definition: tile_map.cpp:100
BaseStation::facilities
StationFacility facilities
The facilities that this station has.
Definition: base_station_base.h:63
DIAGDIR_SE
@ DIAGDIR_SE
Southeast.
Definition: direction_type.h:80
TileDesc::grf
const char * grf
newGRF used for the tile contents
Definition: tile_cmd.h:61
SplitGroundSpriteForOverlay
bool SplitGroundSpriteForOverlay(const TileInfo *ti, SpriteID *ground, RailTrackOffset *overlay_offset)
Check whether a sprite is a track sprite, which can be replaced by a non-track ground sprite and a ra...
Definition: station_cmd.cpp:2765
RemoveRailWaypoint
static CommandCost RemoveRailWaypoint(TileIndex tile, DoCommandFlag flags)
Remove a rail waypoint.
Definition: station_cmd.cpp:1781
VETSB_CANNOT_ENTER
@ VETSB_CANNOT_ENTER
The vehicle cannot enter the tile.
Definition: tile_cmd.h:37
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:83
VehicleCargoList::StoredCount
uint StoredCount() const
Returns sum of cargo on board the vehicle (ie not only reserved).
Definition: cargopacket.h:352
TROPICZONE_DESERT
@ TROPICZONE_DESERT
Tile is desert.
Definition: tile_type.h:76
INVALID_AIRPORTTILE
static const uint INVALID_AIRPORTTILE
id for an invalid airport tile
Definition: airport.h:25
FlowStat::ScaleToMonthly
void ScaleToMonthly(uint runtime)
Scale all shares from link graph's runtime to monthly values.
Definition: station_cmd.cpp:4591
RoadTypeInfo
Definition: road.h:75
RoadVehicle::state
byte state
Definition: roadveh.h:109
Station::docking_station
TileArea docking_station
Tile area the docking tiles cover.
Definition: station_base.h:463
ROTSG_GROUND
@ ROTSG_GROUND
Required: Main group of ground images.
Definition: road.h:60
InvalidateWindowData
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
Definition: window.cpp:3234
Industry::owner
Owner owner
owner of the industry. Which SHOULD always be (imho) OWNER_NONE
Definition: industry.h:84
FlowStat::Invalidate
void Invalidate()
Reduce all flows to minimum capacity so that they don't get in the way of link usage statistics too m...
Definition: station_cmd.cpp:4454
RailtypeInfo::single_x
SpriteID single_x
single piece of rail in X direction, without ground
Definition: rail.h:134
SmallStack
Minimal stack that uses a pool to avoid pointers.
Definition: smallstack_type.hpp:136
Station::goods
GoodsEntry goods[NUM_CARGO]
Goods at this station.
Definition: station_base.h:476
TRACK_BIT_NONE
@ TRACK_BIT_NONE
No track.
Definition: track_type.h:39
NUM_INDUSTRYTYPES
static const IndustryType NUM_INDUSTRYTYPES
total number of industry types, new and old; limited to 240 because we need some special ids like INV...
Definition: industry_type.h:26
StationRect
StationRect - used to track station spread out rectangle - cheaper than scanning whole map.
Definition: base_station_base.h:29
StationGfx
byte StationGfx
Copy from station_map.h.
Definition: newgrf_airport.h:20
linkgraph_base.h
RailtypeInfo::max_speed
uint16 max_speed
Maximum speed for vehicles travelling on this rail type.
Definition: rail.h:228
newgrf_station.h
newgrf_house.h
DoCommand
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
Definition: command.cpp:450
GetAcceptanceAroundStation
static CargoArray GetAcceptanceAroundStation(const Station *st, CargoTypes *always_accepted)
Get the acceptance of cargoes around the station in.
Definition: station_cmd.cpp:567
FlowStat::unrestricted
uint unrestricted
Limit for unrestricted shares.
Definition: station_base.h:145
Order::IsType
bool IsType(OrderType type) const
Check whether this order is of the given type.
Definition: order_base.h:64
LinkGraph::COMPRESSION_INTERVAL
static const uint COMPRESSION_INTERVAL
Minimum number of days between subsequent compressions of a LG.
Definition: linkgraph.h:454
Pool::PoolItem<&_industry_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:337
StationSpec::flags
byte flags
Bitmask of flags, bit 0: use different sprite set; bit 1: divide cargo about by station size.
Definition: newgrf_station.h:160
GetDockDirection
static DiagDirection GetDockDirection(TileIndex t)
Get the direction of a dock.
Definition: station_map.h:429
station_kdtree.h
TileOffsByDiagDir
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition: map_func.h:341
Direction
Direction
Defines the 8 directions on the map.
Definition: direction_type.h:24
FindJoiningWaypoint
CommandCost FindJoiningWaypoint(StationID existing_waypoint, StationID waypoint_to_join, bool adjacent, TileArea ta, Waypoint **wp)
Find a nearby waypoint that joins this waypoint.
Definition: station_cmd.cpp:1214
FlowStatMap::GetFlowVia
uint GetFlowVia(StationID via) const
Get the sum of flows via a specific station from this FlowStatMap.
Definition: station_cmd.cpp:4728
Airport::GetHangarNum
uint GetHangarNum(TileIndex tile) const
Get the hangar number of the hangar at a specific tile.
Definition: station_base.h:400
GameSettings::station
StationSettings station
settings related to station management
Definition: settings_type.h:588
AirportSpec::IsWithinMapBounds
bool IsWithinMapBounds(byte table, TileIndex index) const
Check if the airport would be within the map bounds at the given tile.
Definition: newgrf_airport.cpp:138
IsRoadStop
static bool IsRoadStop(TileIndex t)
Is the station at t a road station?
Definition: station_map.h:202
SetWindowDirty
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3136
water.h
LinkGraph
A connected component of a link graph.
Definition: linkgraph.h:39
GetTileMaxZ
int GetTileMaxZ(TileIndex t)
Get top height of the tile inside the map.
Definition: tile_map.cpp:141
STATION_RATING_TICKS
static const int STATION_RATING_TICKS
cycle duration for updating station rating
Definition: date_type.h:33
StationSpec::renderdata
std::vector< NewGRFSpriteLayout > renderdata
Number of tile layouts.
Definition: newgrf_station.h:148
GB
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:32
GetAcceptanceAroundTiles
CargoArray GetAcceptanceAroundTiles(TileIndex center_tile, int w, int h, int rad, CargoTypes *always_accepted)
Get the acceptance of cargoes around the tile in 1/8.
Definition: station_cmd.cpp:545
Station::AfterStationTileSetChange
void AfterStationTileSetChange(bool adding, StationType type)
After adding/removing tiles to station, update some station-related stuff.
Definition: station_cmd.cpp:741
DrawRoadOverlays
void DrawRoadOverlays(const TileInfo *ti, PaletteID pal, const RoadTypeInfo *road_rti, const RoadTypeInfo *tram_rti, uint road_offset, uint tram_offset)
Draw road underlay and overlay sprites.
Definition: road_cmd.cpp:1518
FlowStatMap::GetFlow
uint GetFlow() const
Get the sum of all flows from this FlowStatMap.
Definition: station_cmd.cpp:4714
train.h
VehicleCargoList::Reroute
uint Reroute(uint max_move, VehicleCargoList *dest, StationID avoid, StationID avoid2, const GoodsEntry *ge)
Routes packets with station "avoid" as next hop to a different place.
Definition: cargopacket.cpp:669
AirportTileTableIterator::GetStationGfx
StationGfx GetStationGfx() const
Get the StationGfx for the current tile.
Definition: newgrf_airport.h:56
HasTileWaterClass
static bool HasTileWaterClass(TileIndex t)
Checks whether the tile has an waterclass associated.
Definition: water_map.h:95
command_func.h
SmallStack::Push
void Push(const Titem &item)
Pushes a new item onto the stack if there is still space in the underlying pool.
Definition: smallstack_type.hpp:193
NewGRFSpriteLayout::PrepareLayout
uint32 PrepareLayout(uint32 orig_offset, uint32 newgrf_ground_offset, uint32 newgrf_offset, uint constr_stage, bool separate_ground) const
Prepares a sprite layout before resolving action-1-2-3 chains.
Definition: newgrf_commons.cpp:660
YapfNotifyTrackLayoutChange
void YapfNotifyTrackLayoutChange(TileIndex tile, Track track)
Use this function to notify YAPF that track layout (or signal configuration) has change.
Definition: yapf_rail.cpp:640
TileInfo::x
uint x
X position of the tile in unit coordinates.
Definition: tile_cmd.h:43
LinkGraph::Node
Updatable node class.
Definition: linkgraph.h:380
Pool::PoolItem<&_link_graph_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:348
RerouteCargo
void RerouteCargo(Station *st, CargoID c, StationID avoid, StationID avoid2)
Reroute cargo of type c at station st or in any vehicles unloading there.
Definition: station_cmd.cpp:3631
CMD_ERROR
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition: command_func.h:23
UpdateAirplanesOnNewStation
void UpdateAirplanesOnNewStation(const Station *st)
Updates the status of the Aircraft heading or in the station.
Definition: aircraft_cmd.cpp:2139
AutoslopeCheckForEntranceEdge
static bool AutoslopeCheckForEntranceEdge(TileIndex tile, int z_new, Slope tileh_new, DiagDirection entrance)
Autoslope check for tiles with an entrance on an edge.
Definition: autoslope.h:31
SSF_EXTENDED_FOUNDATIONS
@ SSF_EXTENDED_FOUNDATIONS
Extended foundation block instead of simple.
Definition: newgrf_station.h:99
ClosestTownFromTile
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold.
Definition: town_cmd.cpp:3592
SAT_250_TICKS
@ SAT_250_TICKS
Trigger station every 250 ticks.
Definition: newgrf_animation_type.h:33
TO_BUILDINGS
@ TO_BUILDINGS
company buildings - depots, stations, HQ, ...
Definition: transparency.h:27
TileInfo
Tile information, used while rendering the tile.
Definition: tile_cmd.h:42
StationHandleBigTick
static bool StationHandleBigTick(BaseStation *st)
This function is called for each station once every 250 ticks.
Definition: station_cmd.cpp:3418
FlowStat::ReleaseShare
void ReleaseShare(StationID st)
Release ("unrestrict") a flow by moving it to the begin of the map and increasing the amount of unres...
Definition: station_cmd.cpp:4554
GameCreationSettings::landscape
byte landscape
the landscape we're currently in
Definition: settings_type.h:321
TileDesc::railtype
StringID railtype
Type of rail on the tile.
Definition: tile_cmd.h:63
Town::statues
CompanyMask statues
which companies have a statue?
Definition: town.h:66
GetCustomStationRelocation
SpriteID GetCustomStationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint32 var10)
Resolve sprites for drawing a station tile.
Definition: newgrf_station.cpp:606
company_base.h
Vehicle::Next
Vehicle * Next() const
Get the next vehicle of this vehicle.
Definition: vehicle_base.h:596
TRANSPORT_RAIL
@ TRANSPORT_RAIL
Transport by train.
Definition: transport_type.h:27
tunnelbridge_map.h
CargoList::Packets
const Tcont * Packets() const
Returns a pointer to the cargo packet list (so you can iterate over it etc).
Definition: cargopacket.h:247
BaseStation::town
Town * town
The town this station is associated with.
Definition: base_station_base.h:61
SetRailStationPlatformReservation
void SetRailStationPlatformReservation(TileIndex start, DiagDirection dir, bool b)
Set the reservation for a complete station platform.
Definition: pbs.cpp:57
LinkGraph::EdgeWrapper::LastRestrictedUpdate
Date LastRestrictedUpdate() const
Get the date of the last update to the edge's restricted capacity.
Definition: linkgraph.h:117
SetCustomStationSpecIndex
static void SetCustomStationSpecIndex(TileIndex t, byte specindex)
Set the custom station spec for this tile.
Definition: station_map.h:481
FACIL_TRUCK_STOP
@ FACIL_TRUCK_STOP
Station with truck stops.
Definition: station_type.h:53
CBM_CARGO_STATION_RATING_CALC
@ CBM_CARGO_STATION_RATING_CALC
custom station rating for this cargo type
Definition: newgrf_callbacks.h:341
TileDesc::owner
Owner owner[4]
Name of the owner(s)
Definition: tile_cmd.h:53
AirportSpec::size_y
byte size_y
size of airport in y direction
Definition: newgrf_airport.h:106
GetFoundationPixelSlope
static Slope GetFoundationPixelSlope(TileIndex tile, int *z)
Get slope of a tile on top of a (possible) foundation If a tile does not have a foundation,...
Definition: landscape.h:66
CBID_STATION_AVAILABILITY
@ CBID_STATION_AVAILABILITY
Determine whether a newstation should be made available to build.
Definition: newgrf_callbacks.h:39
Station
Station data structure.
Definition: station_base.h:447
BaseStation::GetByTile
static BaseStation * GetByTile(TileIndex tile)
Get the base station belonging to a specific tile.
Definition: base_station_base.h:155
company_gui.h
Station::RecomputeCatchment
void RecomputeCatchment()
Recompute tiles covered in our catchment area.
Definition: station.cpp:406
AAT_STATION_NEW_CARGO
@ AAT_STATION_NEW_CARGO
Triggered when new cargo arrives at the station (for all tiles at the same time).
Definition: newgrf_animation_type.h:49
LinkGraph::EdgeWrapper::LastUpdate
Date LastUpdate() const
Get the date of the last update to any part of the edge's capacity.
Definition: linkgraph.h:123
PALETTE_MODIFIER_COLOUR
@ PALETTE_MODIFIER_COLOUR
this bit is set when a recolouring process is in action
Definition: sprites.h:1540
elrail_func.h
NR_STATION
@ NR_STATION
Reference station. Scroll to station when clicking on the news. Delete news when station is deleted.
Definition: news_type.h:53
AirportSpec::name
StringID name
name of this airport
Definition: newgrf_airport.h:111
INVALID_ROADTYPE
@ INVALID_ROADTYPE
flag for invalid roadtype
Definition: road_type.h:27
CMSAWater
static bool CMSAWater(TileIndex tile)
Check whether the tile is water.
Definition: station_cmd.cpp:182
SAT_NEW_CARGO
@ SAT_NEW_CARGO
Trigger station on new cargo arrival.
Definition: newgrf_animation_type.h:28
TileDesc::station_class
StringID station_class
Class of station.
Definition: tile_cmd.h:56
DiagDirToAxis
static Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
Definition: direction_func.h:214
RemoveRailStation
CommandCost RemoveRailStation(T *st, DoCommandFlag flags, Money removal_cost)
Remove a rail station/waypoint.
Definition: station_cmd.cpp:1726
DifficultySettings::town_council_tolerance
byte town_council_tolerance
minimum required town ratings to be allowed to demolish stuff
Definition: settings_type.h:92
GetIndustryType
IndustryType GetIndustryType(TileIndex tile)
Retrieve the type for this industry.
Definition: industry_cmd.cpp:104
IsCustomStationSpecIndex
static bool IsCustomStationSpecIndex(TileIndex t)
Is there a custom rail station spec on this tile?
Definition: station_map.h:469
BitmapTileIterator
Iterator to iterate over all tiles belonging to a bitmaptilearea.
Definition: bitmap_type.h:107
Vehicle::vehstatus
byte vehstatus
Status.
Definition: vehicle_base.h:328
Town::noise_reached
uint16 noise_reached
level of noise that all the airports are generating
Definition: town.h:64
AAT_BUILT
@ AAT_BUILT
Triggered when the airport is built (for all tiles at the same time).
Definition: newgrf_animation_type.h:47
LinkGraphSchedule::instance
static LinkGraphSchedule instance
Static instance of LinkGraphSchedule.
Definition: linkgraphschedule.h:52
DIAGDIR_END
@ DIAGDIR_END
Used for iterations.
Definition: direction_type.h:83
CompanyInfrastructure::water
uint32 water
Count of company owned track bits for canals.
Definition: company_base.h:34
IsRailStation
static bool IsRailStation(TileIndex t)
Is this station tile a rail station?
Definition: station_map.h:92
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:235
DrawRoadCatenary
void DrawRoadCatenary(const TileInfo *ti)
Draws the catenary for the given tile.
Definition: road_cmd.cpp:1455
IsHangar
bool IsHangar(TileIndex t)
Check whether the given tile is a hangar.
Definition: station_cmd.cpp:77
RVSB_IN_ROAD_STOP
@ RVSB_IN_ROAD_STOP
The vehicle is in a road stop.
Definition: roadveh.h:50
CargoSpec::Get
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
Definition: cargotype.h:119
GetRailStationTrack
static Track GetRailStationTrack(TileIndex t)
Get the rail track of a rail station tile.
Definition: station_map.h:349
LinkGraph::Node::Begin
EdgeIterator Begin()
Get an iterator pointing to the start of the edges array.
Definition: linkgraph.h:403
FindJoiningBaseStation
CommandCost FindJoiningBaseStation(StationID existing_station, StationID station_to_join, bool adjacent, TileArea ta, T **st)
Find a nearby station that joins this station.
Definition: station_cmd.cpp:1155
AxisToTrackBits
static TrackBits AxisToTrackBits(Axis a)
Maps an Axis to the corresponding TrackBits value.
Definition: track_func.h:87
HasPowerOnRail
static bool HasPowerOnRail(RailType enginetype, RailType tiletype)
Checks if an engine of the given RailType got power on a tile with a given RailType.
Definition: rail.h:332
LinkGraph::EdgeIterator
An iterator for non-const edges.
Definition: linkgraph.h:330
CargoArray
Class for storing amounts of cargo.
Definition: cargo_type.h:82
TRACK_X
@ TRACK_X
Track along the x-axis (north-east to south-west)
Definition: track_type.h:21
PalSpriteID::sprite
SpriteID sprite
The 'real' sprite.
Definition: gfx_type.h:23
DT_MANUAL
@ DT_MANUAL
Manual distribution. No link graph calculations are run.
Definition: linkgraph_type.h:25
ClampU
static uint ClampU(const uint a, const uint min, const uint max)
Clamp an unsigned integer between an interval.
Definition: math_func.hpp:122
AirportSpec::noise_level
byte noise_level
noise that this airport generates
Definition: newgrf_airport.h:107
FlowStatMap::PassOnFlow
void PassOnFlow(StationID origin, StationID via, uint amount)
Pass on some flow, remembering it as invalid, for later subtraction from locally consumed flow.
Definition: station_cmd.cpp:4629
RailtypeInfo::single_y
SpriteID single_y
single piece of rail in Y direction, without ground
Definition: rail.h:135
FindFirstBit
uint8 FindFirstBit(uint64 x)
Search the first set bit in a 64 bit variable.
Definition: bitmath_func.cpp:37
GameSettings::difficulty
DifficultySettings difficulty
settings related to the difficulty
Definition: settings_type.h:576
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
TileDesc::tram_speed
uint16 tram_speed
Speed limit of tram (bridges and track)
Definition: tile_cmd.h:68
CheckFlatLandRailStation
static CommandCost CheckFlatLandRailStation(TileArea tile_area, DoCommandFlag flags, Axis axis, StationID *station, RailType rt, std::vector< Train * > &affected_vehicles, StationClassID spec_class, byte spec_index, byte plat_len, byte numtracks)
Checks if a rail station can be built at the given area.
Definition: station_cmd.cpp:873
GetTileZ
int GetTileZ(TileIndex tile)
Get bottom height of the tile.
Definition: tile_map.cpp:121
ship.h
CBID_CARGO_STATION_RATING_CALC
@ CBID_CARGO_STATION_RATING_CALC
Called to calculate part of a station rating.
Definition: newgrf_callbacks.h:200
CompanyInfrastructure::station
uint32 station
Count of company owned station tiles.
Definition: company_base.h:35
NewGRFSpriteLayout::ProcessRegisters
void ProcessRegisters(uint8 resolved_var10, uint32 resolved_sprite, bool separate_ground) const
Evaluates the register modifiers and integrates them into the preprocessed sprite layout.
Definition: newgrf_commons.cpp:731
AddNewsItem
void AddNewsItem(StringID string, NewsType type, NewsFlag flags, NewsReferenceType reftype1=NR_NONE, uint32 ref1=UINT32_MAX, NewsReferenceType reftype2=NR_NONE, uint32 ref2=UINT32_MAX, const NewsAllocatedData *data=nullptr)
Add a new newsitem to be shown.
Definition: news_gui.cpp:807
RailtypeInfo
This struct contains all the info that is needed to draw and construct tracks.
Definition: rail.h:124
ROAD_X
@ ROAD_X
Full road along the x-axis (south-west + north-east)
Definition: road_type.h:56
include
bool include(std::vector< T > &vec, const T &item)
Helper function to append an item to a vector if it is not already contained Consider using std::set,...
Definition: smallvec_type.hpp:27
ClrBit
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
Definition: bitmath_func.hpp:151
IsCompatibleTrainStationTile
static bool IsCompatibleTrainStationTile(TileIndex test_tile, TileIndex station_tile)
Check if a tile is a valid continuation to a railstation tile.
Definition: station_map.h:378
GetRoadStopType
static RoadStopType GetRoadStopType(TileIndex t)
Get the road stop type of this tile.
Definition: station_map.h:56
VETSB_CONTINUE
@ VETSB_CONTINUE
Bit sets of the above specified bits.
Definition: tile_cmd.h:34
Station::MoveSign
void MoveSign(TileIndex new_xy) override
Move the station main coordinate somewhere else.
Definition: station_cmd.cpp:435
Waypoint
Representation of a waypoint.
Definition: waypoint_base.h:16
CBM_STATION_SLOPE_CHECK
@ CBM_STATION_SLOPE_CHECK
Check slope of new station tiles.
Definition: newgrf_callbacks.h:307
station_land.h
Airport::layout
byte layout
Airport layout number.
Definition: station_base.h:307
IsStandardRoadStopTile
static bool IsStandardRoadStopTile(TileIndex t)
Is tile t a standard (non-drive through) road stop station?
Definition: station_map.h:223
SetStationGfx
static void SetStationGfx(TileIndex t, StationGfx gfx)
Set the station graphics of this tile.
Definition: station_map.h:80
WaterClass
WaterClass
classes of water (for WATER_TILE_CLEAR water tile type).
Definition: water_map.h:47
RoadStop::GetByTile
static RoadStop * GetByTile(TileIndex tile, RoadStopType type)
Find a roadstop at given tile.
Definition: roadstop.cpp:266
SetRoadOwner
static void SetRoadOwner(TileIndex t, RoadTramType rtt, Owner o)
Set the owner of a specific road type.
Definition: road_map.h:250
EUM_INCREASE
@ EUM_INCREASE
Increase capacity.
Definition: linkgraph_type.h:53
IsDriveThroughStopTile
static bool IsDriveThroughStopTile(TileIndex t)
Is tile t a drive through road stop station?
Definition: station_map.h:233
aircraft.h
TILE_SIZE
static const uint TILE_SIZE
Tile size in world coordinates.
Definition: tile_type.h:13
LinkGraph::Node::End
EdgeIterator End()
Get an iterator pointing beyond the end of the edges array.
Definition: linkgraph.h:409
GetTrackBits
static TrackBits GetTrackBits(TileIndex tile)
Gets the track bits of the given tile.
Definition: rail_map.h:136
CargoSpec::Iterate
static IterateWrapper Iterate(size_t from=0)
Returns an iterable ensemble of all valid CargoSpec.
Definition: cargotype.h:168
SpecializedStation< Station, false >::Get
static Station * Get(size_t index)
Gets station with given index.
Definition: base_station_base.h:219
TileInfo::y
uint y
Y position of the tile in unit coordinates.
Definition: tile_cmd.h:44
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:52
HasSignals
static bool HasSignals(TileIndex t)
Checks if a rail tile has signals.
Definition: rail_map.h:72
Town::xy
TileIndex xy
town center tile
Definition: town.h:51
CargoSpec
Specification of a cargo type.
Definition: cargotype.h:57
SpecializedStation< Station, false >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index is a valid index for station of this type.
Definition: base_station_base.h:210
MP_INDUSTRY
@ MP_INDUSTRY
Part of an industry.
Definition: tile_type.h:54
newgrf_debug.h
town.h
TileY
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:215
CC_LIQUID
@ CC_LIQUID
Liquids (Oil, Water, Rubber)
Definition: cargotype.h:47
OrthogonalTileArea::Add
void Add(TileIndex to_add)
Add a single tile to a tile area; enlarge if needed.
Definition: tilearea.cpp:43
TileDesc::airport_tile_name
StringID airport_tile_name
Name of the airport tile.
Definition: tile_cmd.h:60
Company::infrastructure
CompanyInfrastructure infrastructure
NOSAVE: Counts of company owned infrastructure.
Definition: company_base.h:128
VS_TRAIN_SLOWING
@ VS_TRAIN_SLOWING
Train is slowing down.
Definition: vehicle_base.h:35
RandomRange
static uint32 RandomRange(uint32 limit)
Pick a random number between 0 and limit - 1, inclusive.
Definition: random_func.hpp:81
LinkGraph::Size
NodeID Size() const
Get the current size of the component.
Definition: linkgraph.h:508
CMD_REMOVE_FROM_RAIL_WAYPOINT
@ CMD_REMOVE_FROM_RAIL_WAYPOINT
remove a (rectangle of) tiles from a rail waypoint
Definition: command_type.h:195
WC_STATION_VIEW
@ WC_STATION_VIEW
Station view; Window numbers:
Definition: window_type.h:337
IndustrySpec::station_name
StringID station_name
Default name for nearby station.
Definition: industrytype.h:132
AirportGetNearestTown
Town * AirportGetNearestTown(const AirportSpec *as, const TileIterator &it, uint &mindist)
Finds the town nearest to given airport.
Definition: station_cmd.cpp:2192
DIR_W
@ DIR_W
West.
Definition: direction_type.h:32
RoadStop::Enter
bool Enter(RoadVehicle *rv)
Enter the road stop.
Definition: roadstop.cpp:233
TransportType
TransportType
Available types of transport.
Definition: transport_type.h:19
RailtypeInfo::fallback_railtype
byte fallback_railtype
Original railtype number to use when drawing non-newgrf railtypes, or when drawing stations.
Definition: rail.h:198
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
CC_PASSENGERS
@ CC_PASSENGERS
Passengers.
Definition: cargotype.h:41
Vehicle::cur_speed
uint16 cur_speed
current speed
Definition: vehicle_base.h:304
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:221
Industry
Defines the internal data of a functional industry.
Definition: industry.h:66
Vehicle::owner
Owner owner
Which company owns the vehicle?
Definition: vehicle_base.h:285
RestoreTrainReservation
static void RestoreTrainReservation(Train *v)
Restore platform reservation during station building/removing.
Definition: station_cmd.cpp:1235
Train::GetVehicleTrackdir
Trackdir GetVehicleTrackdir() const
Get the tracks of the train vehicle.
Definition: train_cmd.cpp:4035
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
GetStationAround
CommandCost GetStationAround(TileArea ta, StationID closest_station, CompanyID company, T **st)
Look for a station owned by the given company around the given tile area.
Definition: station_cmd.cpp:103
CmdRemoveFromRailWaypoint
CommandCost CmdRemoveFromRailWaypoint(TileIndex start, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
Remove a single tile from a waypoint.
Definition: station_cmd.cpp:1705
DC_EXEC
@ DC_EXEC
execute the given command
Definition: command_type.h:348
DeallocateSpecFromStation
void DeallocateSpecFromStation(BaseStation *st, byte specindex)
Deallocate a StationSpec from a Station.
Definition: newgrf_station.cpp:733
FlowStatMap::FinalizeLocalConsumption
void FinalizeLocalConsumption(StationID self)
Subtract invalid flows from locally consumed flow.
Definition: station_cmd.cpp:4647
BaseStation::owner
Owner owner
The owner of this station.
Definition: base_station_base.h:62
IsTruckStop
static bool IsTruckStop(TileIndex t)
Is the station at t a truck stop?
Definition: station_map.h:180
MP_ROAD
@ MP_ROAD
A tile with road (or tram tracks)
Definition: tile_type.h:48
AirportSpec
Defines the data structure for an airport.
Definition: newgrf_airport.h:98
TileDesc
Tile description for the 'land area information' tool.
Definition: tile_cmd.h:51
FlowStat::GetShare
uint GetShare(StationID st) const
Get flow for a station.
Definition: station_cmd.cpp:4382
CanBuildDepotByTileh
static bool CanBuildDepotByTileh(DiagDirection direction, Slope tileh)
Find out if the slope of the tile is suitable to build a depot of given direction.
Definition: depot_func.h:26
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:196
TileDesc::airport_name
StringID airport_name
Name of the airport.
Definition: tile_cmd.h:59
CheckIfAuthorityAllowsNewStation
CommandCost CheckIfAuthorityAllowsNewStation(TileIndex tile, DoCommandFlag flags)
Checks whether the local authority allows construction of a new station (rail, road,...
Definition: town_cmd.cpp:3553
GoodsEntry::status
byte status
Status of this cargo, see GoodsEntryStatus.
Definition: station_base.h:223
DoCommandFlag
DoCommandFlag
List of flags for a command.
Definition: command_type.h:346
Foundation
Foundation
Enumeration for Foundations.
Definition: slope_type.h:93
EdgeUpdateMode
EdgeUpdateMode
Special modes for updating links.
Definition: linkgraph_type.h:52
EnsureNoVehicleOnGround
CommandCost EnsureNoVehicleOnGround(TileIndex tile)
Ensure there is no vehicle at the ground at the given position.
Definition: vehicle.cpp:539
CmdRemoveRoadStop
CommandCost CmdRemoveRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
Remove bus or truck stops.
Definition: station_cmd.cpp:2094
RemoveFirstTrack
static Track RemoveFirstTrack(TrackBits *tracks)
Removes first Track from TrackBits and returns it.
Definition: track_func.h:130
LinkGraph::Edge
An updatable edge class.
Definition: linkgraph.h:299
Industry::neutral_station
Station * neutral_station
Associated neutral station.
Definition: industry.h:69
FlatteningFoundation
static Foundation FlatteningFoundation(Slope s)
Returns the foundation needed to flatten a slope.
Definition: slope_func.h:369
TRACK_BIT_UPPER
@ TRACK_BIT_UPPER
Upper track.
Definition: track_type.h:42
GetAirport
const AirportFTAClass * GetAirport(const byte airport_type)
Get the finite state machine of an airport type.
Definition: airport.cpp:207
CommandCost::Succeeded
bool Succeeded() const
Did this command succeed?
Definition: command_type.h:150
GoodsEntry::amount_fract
byte amount_fract
Fractional part of the amount in the cargo list.
Definition: station_base.h:251
TrackToTrackBits
static TrackBits TrackToTrackBits(Track track)
Maps a Track to the corresponding TrackBits value.
Definition: track_func.h:76
pbs.h
TileX
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:205
GetRailReservationTrackBits
static TrackBits GetRailReservationTrackBits(TileIndex t)
Returns the reserved track bits of the tile.
Definition: rail_map.h:194
Kdtree::Remove
void Remove(const T &element)
Remove a single element from the tree, if it exists.
Definition: kdtree.hpp:419
BaseStation::TileBelongsToRailStation
virtual bool TileBelongsToRailStation(TileIndex tile) const =0
Check whether a specific tile belongs to this station.
TileIterator::Clone
virtual TileIterator * Clone() const =0
Allocate a new iterator that is a copy of this one.
AAT_TILELOOP
@ AAT_TILELOOP
Triggered in the periodic tile loop.
Definition: newgrf_animation_type.h:48
CountBits
static uint CountBits(T value)
Counts the number of set bits in a variable.
Definition: bitmath_func.hpp:251
BaseStation::string_id
StringID string_id
Default name (town area) of station.
Definition: base_station_base.h:58
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition: settings_type.h:577
RoadStop::MakeDriveThrough
void MakeDriveThrough()
Join this road stop to another 'base' road stop if possible; fill all necessary data to become an act...
Definition: roadstop.cpp:62
BaseStation::cached_anim_triggers
uint8 cached_anim_triggers
NOSAVE: Combined animation trigger bitmask, used to determine if trigger processing should happen.
Definition: base_station_base.h:72
OrthogonalTileArea::Clear
void Clear()
Clears the 'tile area', i.e.
Definition: tilearea_type.h:40
MAX_CHAR_LENGTH
static const int MAX_CHAR_LENGTH
Max. length of UTF-8 encoded unicode character.
Definition: strings_type.h:18
FlowStatMap::RestrictFlows
void RestrictFlows(StationID via)
Restrict all flows at a station for specific cargo and destination.
Definition: station_cmd.cpp:4692
SpecializedStation< Station, false >::Iterate
static Pool::IterateWrapper< Station > Iterate(size_t from=0)
Returns an iterable ensemble of all valid stations of type T.
Definition: base_station_base.h:270
WID_SV_ROADVEHS
@ WID_SV_ROADVEHS
List of scheduled road vehs button.
Definition: station_widget.h:28
TRACK_BIT_RIGHT
@ TRACK_BIT_RIGHT
Right track.
Definition: track_type.h:45
ROADSTOP_BUS
@ ROADSTOP_BUS
A standard stop for buses.
Definition: station_type.h:45
FlowStatMap::GetFlowFrom
uint GetFlowFrom(StationID from) const
Get the sum of flows from a specific station from this FlowStatMap.
Definition: station_cmd.cpp:4742
LinkGraph::STALE_LINK_DEPOT_TIMEOUT
static const uint STALE_LINK_DEPOT_TIMEOUT
Number of days before deleting links served only by vehicles stopped in depot.
Definition: linkgraph.h:451
Aircraft
Aircraft, helicopters, rotors and their shadows belong to this class.
Definition: aircraft.h:74
TileInfo::tileh
Slope tileh
Slope of the tile.
Definition: tile_cmd.h:45
SpriteID
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
AxisToRoadBits
static RoadBits AxisToRoadBits(Axis a)
Create the road-part which belongs to the given Axis.
Definition: road_func.h:111
SSF_SEPARATE_GROUND
@ SSF_SEPARATE_GROUND
Use different sprite set for ground sprites.
Definition: newgrf_station.h:95
MapSizeX
static uint MapSizeX()
Get the size of the map along the X.
Definition: map_func.h:72
IsTileOnWater
static bool IsTileOnWater(TileIndex t)
Tests if the tile was built on water.
Definition: water_map.h:130
SLOPE_FLAT
@ SLOPE_FLAT
a flat tile
Definition: slope_type.h:49
FlowStat
Flow statistics telling how much flow should be sent along a link.
Definition: station_base.h:33
ClearDockingTilesCheckingNeighbours
void ClearDockingTilesCheckingNeighbours(TileIndex tile)
Clear docking tile status from tiles around a removed dock, if the tile has no neighbours which would...
Definition: station_cmd.cpp:2628
GetStringWithArgs
char * GetStringWithArgs(char *buffr, StringID string, StringParameters *args, const char *last, uint case_index, bool game_script)
Get a parsed string with most special stringcodes replaced by the string parameters.
Definition: strings.cpp:221
ChangeTileOwner
void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner)
Change the owner of a tile.
Definition: landscape.cpp:601
RailtypeInfo::name
StringID name
Name of this rail type.
Definition: rail.h:173
GoodsEntry::cargo
StationCargoList cargo
The cargo packets of cargo waiting in this station.
Definition: station_base.h:252
LinkGraphSchedule::Queue
void Queue(LinkGraph *lg)
Queue a link graph for execution.
Definition: linkgraphschedule.h:67
TileDesc::build_date
Date build_date
Date of construction of tile contents.
Definition: tile_cmd.h:55
StationType
StationType
Station types.
Definition: station_type.h:32
TRANSPORT_ROAD
@ TRANSPORT_ROAD
Transport by road vehicle.
Definition: transport_type.h:28
RoadBits
RoadBits
Enumeration for the road parts on a tile.
Definition: road_type.h:50
DrawTileSprites::ground
PalSpriteID ground
Palette and sprite for the ground.
Definition: sprite.h:59
GetRailTypeInfo
static const RailtypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Definition: rail.h:304
ValParamRailtype
bool ValParamRailtype(const RailType rail)
Validate functions for rail building.
Definition: rail.cpp:206
ROAD_NONE
@ ROAD_NONE
No road-part is build.
Definition: road_type.h:51
SetWindowWidgetDirty
void SetWindowWidgetDirty(WindowClass cls, WindowNumber number, byte widget_index)
Mark a particular widget in a particular window as dirty (in need of repainting)
Definition: window.cpp:3149
AirportTileSpec
Defines the data structure of each individual tile of an airport.
Definition: newgrf_airporttiles.h:66
StationSpec::cls_id
StationClassID cls_id
The class to which this spec belongs.
Definition: newgrf_station.h:126
GetAllRoadBits
static RoadBits GetAllRoadBits(TileIndex tile)
Get all set RoadBits on the given tile.
Definition: road_map.h:140
GetCustomRoadSprite
SpriteID GetCustomRoadSprite(const RoadTypeInfo *rti, TileIndex tile, RoadTypeSpriteGroup rtsg, TileContext context, uint *num_results)
Get the sprite to draw for the given tile.
Definition: newgrf_roadtype.cpp:113
Utf8StringLength
size_t Utf8StringLength(const char *s)
Get the length of an UTF-8 encoded string in number of characters and thus not the number of bytes th...
Definition: string.cpp:417
MakeOilrig
static void MakeOilrig(TileIndex t, StationID sid, WaterClass wc)
Make the given tile an oilrig tile.
Definition: station_map.h:665
newgrf_airporttiles.h
ToTileIndexDiff
static TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
Return the offset between to tiles from a TileIndexDiffC struct.
Definition: map_func.h:230
GameSettings::order
OrderSettings order
settings related to orders
Definition: settings_type.h:584
GetRoadBits
static RoadBits GetRoadBits(TileIndex t, RoadTramType rtt)
Get the present road bits for a specific road type.
Definition: road_map.h:127
Vehicle::Orders
IterateWrapper Orders() const
Returns an iterable ensemble of orders of a vehicle.
Definition: vehicle_base.h:1038
GetStationLayout
void GetStationLayout(byte *layout, uint numtracks, uint plat_len, const StationSpec *statspec)
Create the station layout for the given number of tracks and platform length.
Definition: station_cmd.cpp:1119
CheckBuildableTile
CommandCost CheckBuildableTile(TileIndex tile, uint invalid_dirs, int &allowed_z, bool allow_steep, bool check_bridge=true)
Checks if the given tile is buildable, flat and has a certain height.
Definition: station_cmd.cpp:791
WATER_CLASS_INVALID
@ WATER_CLASS_INVALID
Used for industry tiles on land (also for oilrig if newgrf says so).
Definition: water_map.h:51
StationNameInformation::free_names
uint32 free_names
Current bitset of free names (we can remove names).
Definition: station_cmd.cpp:210
GetPlatformInfo
uint32 GetPlatformInfo(Axis axis, byte tile, int platforms, int length, int x, int y, bool centred)
Evaluate a tile's position within a station, and return the result in a bit-stuffed format.
Definition: newgrf_station.cpp:105
DistanceManhattan
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
Definition: map.cpp:157
DIAGDIR_SW
@ DIAGDIR_SW
Southwest.
Definition: direction_type.h:81
DrawRailTileSeq
static void DrawRailTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32 total_offset, uint32 newgrf_offset, PaletteID default_palette)
Draw tile sprite sequence on tile with railroad specifics.
Definition: sprite.h:89
GetSlopeMaxZ
static int GetSlopeMaxZ(Slope s)
Returns the height of the highest corner of a slope relative to TileZ (= minimal height)
Definition: slope_func.h:160
RoadStop::next
struct RoadStop * next
Next stop of the given type at this station.
Definition: roadstop_base.h:69
FACIL_BUS_STOP
@ FACIL_BUS_STOP
Station with bus stops.
Definition: station_type.h:54
Airport::rotation
Direction rotation
How this airport is rotated.
Definition: station_base.h:308
GetProductionAroundTiles
CargoArray GetProductionAroundTiles(TileIndex north_tile, int w, int h, int rad)
Get the cargo types being produced around the tile (in a rectangle).
Definition: station_cmd.cpp:506
FlowStatMap::DeleteFlows
StationIDStack DeleteFlows(StationID via)
Delete all flows at a station for specific cargo and destination.
Definition: station_cmd.cpp:4672
CheckForDockingTile
void CheckForDockingTile(TileIndex t)
Mark the supplied tile as a docking tile if it is suitable for docking.
Definition: water_cmd.cpp:182
CargoSpec::Index
CargoID Index() const
Determines index of this cargospec.
Definition: cargotype.h:90
AirportSpec::rotation
const Direction * rotation
the rotation of each tiletable
Definition: newgrf_airport.h:101
CmdBuildAirport
CommandCost CmdBuildAirport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
Place an Airport.
Definition: station_cmd.cpp:2253
GetAnimationFrame
static byte GetAnimationFrame(TileIndex t)
Get the current animation frame.
Definition: tile_map.h:250
EconomySettings::station_noise_level
bool station_noise_level
build new airports when the town noise level is still within accepted limits
Definition: settings_type.h:520
StationCargoList::Reroute
uint Reroute(uint max_move, StationCargoList *dest, StationID avoid, StationID avoid2, const GoodsEntry *ge)
Routes packets with station "avoid" as next hop to a different place.
Definition: cargopacket.cpp:860
CheckOwnership
CommandCost CheckOwnership(Owner owner, TileIndex tile)
Check whether the current owner owns something.
Definition: company_cmd.cpp:311
Vehicle::dest_tile
TileIndex dest_tile
Heading for this tile.
Definition: vehicle_base.h:249
DirToDiagDir
static DiagDirection DirToDiagDir(Direction dir)
Convert a Direction to a DiagDirection.
Definition: direction_func.h:166
AXIS_Y
@ AXIS_Y
The y axis.
Definition: direction_type.h:125
StationSettings::serve_neutral_industries
bool serve_neutral_industries
company stations can serve industries with attached neutral stations
Definition: settings_type.h:549
GetAirportGfx
static StationGfx GetAirportGfx(TileIndex t)
Get the station graphics of this airport tile.
Definition: station_map.h:244
return_cmd_error
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
Definition: command_func.h:33
StationFinder::stations
StationList stations
List of stations nearby.
Definition: station_type.h:101
MapSize
static uint MapSize()
Get the size of the map.
Definition: map_func.h:92
CheckFlatLandAirport
static CommandCost CheckFlatLandAirport(AirportTileTableIterator tile_iter, DoCommandFlag flags)
Checks if an airport can be built at the given location and clear the area.
Definition: station_cmd.cpp:841
LinkGraph::EdgeWrapper::LastUnrestrictedUpdate
Date LastUnrestrictedUpdate() const
Get the date of the last update to the edge's unrestricted capacity.
Definition: linkgraph.h:111
EXPENSES_CONSTRUCTION
@ EXPENSES_CONSTRUCTION
Construction costs.
Definition: economy_type.h:158
BaseStation::sign
TrackedViewportSign sign
NOSAVE: Dimensions of sign.
Definition: base_station_base.h:54
RailType
RailType
Enumeration for all possible railtypes.
Definition: rail_type.h:27
TileAddWrap
TileIndex TileAddWrap(TileIndex tile, int addx, int addy)
This function checks if we add addx/addy to tile, if we do wrap around the edges.
Definition: map.cpp:114
STAT_CLASS_WAYP
@ STAT_CLASS_WAYP
Waypoint class.
Definition: newgrf_station.h:86
IsSteepSlope
static bool IsSteepSlope(Slope s)
Checks if a slope is steep.
Definition: slope_func.h:36
FlowStatMap::ReleaseFlows
void ReleaseFlows(StationID via)
Release all flows at a station for specific cargo and destination.
Definition: station_cmd.cpp:4703
CommandCost
Common return value for all commands.
Definition: command_type.h:23
GetSnowLine
byte GetSnowLine()
Get the current snow line, either variable or static.
Definition: landscape.cpp:645
Industry::location
TileArea location
Location of the industry.
Definition: industry.h:67
GetCustomStationSpecIndex
static uint GetCustomStationSpecIndex(TileIndex t)
Get the custom station spec for this tile.
Definition: station_map.h:493
TRACK_Y
@ TRACK_Y
Track along the y-axis (north-west to south-east)
Definition: track_type.h:22
HasTileWaterGround
static bool HasTileWaterGround(TileIndex t)
Checks whether the tile has water at the ground.
Definition: water_map.h:344
AirportSpec::Get
static const AirportSpec * Get(byte type)
Retrieve airport spec for the given airport.
Definition: newgrf_airport.cpp:97
SetBitIterator
Iterable ensemble of each set bit in a value.
Definition: bitmath_func.hpp:329
cmd_helper.h
AirportSpec::cls_id
AirportClassID cls_id
the class to which this airport type belongs
Definition: newgrf_airport.h:113
_date
Date _date
Current date in days (day counter)
Definition: date.cpp:28
SourceID
uint16 SourceID
Contains either industry ID, town ID or company ID (or INVALID_SOURCE)
Definition: cargo_type.h:153
HasStationRail
static bool HasStationRail(TileIndex t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint?
Definition: station_map.h:135
CircularTileSearch
bool CircularTileSearch(TileIndex *tile, uint size, TestTileOnSearchProc proc, void *user_data)
Function performing a search around a center tile and going outward, thus in circle.
Definition: map.cpp:258
RemoveAirport
static CommandCost RemoveAirport(TileIndex tile, DoCommandFlag flags)
Remove an airport.
Definition: station_cmd.cpp:2384
GRFConfig
Information about GRF, used in the game and (part of it) in savegames.
Definition: newgrf_config.h:155
clear_func.h
AxisToTrack
static Track AxisToTrack(Axis a)
Convert an Axis to the corresponding Track AXIS_X -> TRACK_X AXIS_Y -> TRACK_Y Uses the fact that the...
Definition: track_func.h:65
StationMonthlyLoop
void StationMonthlyLoop()
Monthly loop for stations.
Definition: station_cmd.cpp:3854
BaseStation::train_station
TileArea train_station
Tile area the train 'station' part covers.
Definition: base_station_base.h:75
GetAnyRoadBits
RoadBits GetAnyRoadBits(TileIndex tile, RoadTramType rtt, bool straight_tunnel_bridge_entrance)
Returns the RoadBits on an arbitrary tile Special behaviour:
Definition: road_map.cpp:33
STATION_ACCEPTANCE_TICKS
static const int STATION_ACCEPTANCE_TICKS
cycle duration for updating station acceptance
Definition: date_type.h:34
HasExactlyOneBit
static bool HasExactlyOneBit(T value)
Test whether value has exactly 1 bit set.
Definition: bitmath_func.hpp:274
NF_INCOLOUR
@ NF_INCOLOUR
Bit value for coloured news.
Definition: news_type.h:71
Industry::GetByTile
static Industry * GetByTile(TileIndex tile)
Get the industry of the given tile.
Definition: industry.h:144
AirportSpec::num_table
byte num_table
number of elements in the table
Definition: newgrf_airport.h:102
DirtyCompanyInfrastructureWindows
void DirtyCompanyInfrastructureWindows(CompanyID company)
Redraw all windows with company infrastructure counts.
Definition: company_gui.cpp:2709
DIR_E
@ DIR_E
East.
Definition: direction_type.h:28
CalcClosestTownFromTile
Town * CalcClosestTownFromTile(TileIndex tile, uint threshold=UINT_MAX)
Return the town closest to the given tile within threshold.
Definition: town_cmd.cpp:3574
StationSpec::layouts
std::vector< std::vector< std::vector< byte > > > layouts
Custom platform layouts.
Definition: newgrf_station.h:176
Industry::type
IndustryType type
type of industry.
Definition: industry.h:83
DRD_NONE
@ DRD_NONE
None of the directions are disallowed.
Definition: road_map.h:286
roadstop_base.h
TrackBitsToTrackdirBits
static TrackdirBits TrackBitsToTrackdirBits(TrackBits bits)
Converts TrackBits to TrackdirBits while allowing both directions.
Definition: track_func.h:318
BaseStation::rect
StationRect rect
NOSAVE: Station spread out rectangle maintained by StationRect::xxx() functions.
Definition: base_station_base.h:76
TriggerWatchedCargoCallbacks
void TriggerWatchedCargoCallbacks(Station *st)
Run the watched cargo callback for all houses in the catchment area.
Definition: station_cmd.cpp:3392
TileIndexDiff
int32 TileIndexDiff
An offset value between to tiles.
Definition: map_func.h:154
GoodsEntry::HasRating
bool HasRating() const
Does this cargo have a rating at this station?
Definition: station_base.h:270
Vehicle::tile
TileIndex tile
Current tile index.
Definition: vehicle_base.h:242
FindNearIndustryName
static bool FindNearIndustryName(TileIndex tile, void *user_data)
Find a station action 0 property 24 station name, or reduce the free_names if needed.
Definition: station_cmd.cpp:222
autoslope.h
Convert8bitBooleanCallback
bool Convert8bitBooleanCallback(const GRFFile *grffile, uint16 cbid, uint16 cb_res)
Converts a callback result into a boolean.
Definition: newgrf_commons.cpp:569
TileIterator
Base class for tile iterators.
Definition: tilearea_type.h:105
CMSAMine
static bool CMSAMine(TileIndex tile)
Check whether the tile is a mine.
Definition: station_cmd.cpp:155
DistanceFromEdge
uint DistanceFromEdge(TileIndex tile)
Param the minimum distance to an edge.
Definition: map.cpp:217
CanExpandRailStation
CommandCost CanExpandRailStation(const BaseStation *st, TileArea &new_ta, Axis axis)
Check whether we can expand the rail part of the given station.
Definition: station_cmd.cpp:1074
Station::MarkTilesDirty
void MarkTilesDirty(bool cargo_change) const
Marks the tiles of the station as dirty.
Definition: station.cpp:217
TrackdirToExitdir
static DiagDirection TrackdirToExitdir(Trackdir trackdir)
Maps a trackdir to the (4-way) direction the tile is exited when following that trackdir.
Definition: track_func.h:438
Kdtree::Insert
void Insert(const T &element)
Insert a single element in the tree.
Definition: kdtree.hpp:400
TileDesc::roadtype
StringID roadtype
Type of road on the tile.
Definition: tile_cmd.h:65
GoodsEntry::last_speed
byte last_speed
Maximum speed (up to 255) of the last vehicle that tried to load this cargo.
Definition: station_base.h:243
RailtypeInfo::base_sprites
struct RailtypeInfo::@36 base_sprites
Struct containing the main sprites.
GoodsEntry::GES_ACCEPTED_BIGTICK
@ GES_ACCEPTED_BIGTICK
Set when cargo was delivered for final delivery during the current STATION_ACCEPTANCE_TICKS interval.
Definition: station_base.h:208
SB
static T SB(T &x, const uint8 s, const uint8 n, const U d)
Set n bits in x starting at bit s to d.
Definition: bitmath_func.hpp:58
FlowStat::GetShares
const SharesMap * GetShares() const
Get the actual shares as a const pointer so that they can be iterated over.
Definition: station_base.h:89
GoodsEntry::GetVia
StationID GetVia(StationID source) const
Get the best next hop for a cargo packet from station source.
Definition: station_base.h:280
CmdOpenCloseAirport
CommandCost CmdOpenCloseAirport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
Open/close an airport to incoming aircraft.
Definition: station_cmd.cpp:2470
SpecializedStation< Waypoint, true >::IsExpected
static bool IsExpected(const BaseStation *st)
Helper for checking whether the given station is of this type.
Definition: base_station_base.h:200
MakeDriveThroughRoadStop
static void MakeDriveThroughRoadStop(TileIndex t, Owner station, Owner road, Owner tram, StationID sid, RoadStopType rst, RoadType road_rt, RoadType tram_rt, Axis a)
Make the given tile a drivethrough roadstop tile.
Definition: station_map.h:610
IsBuoy
static bool IsBuoy(TileIndex t)
Is tile t a buoy tile?
Definition: station_map.h:306
INVALID_OWNER
@ INVALID_OWNER
An invalid owner.
Definition: company_type.h:29
OrthogonalTileArea::w
uint16 w
The width of the area.
Definition: tilearea_type.h:20
MP_WATER
@ MP_WATER
Water tile.
Definition: tile_type.h:52
Station::truck_station
TileArea truck_station
Tile area the truck 'station' part covers.
Definition: station_base.h:459
UpdateAirportsNoise
void UpdateAirportsNoise()
Recalculate the noise generated by the airports of each town.
Definition: station_cmd.cpp:2225
Industry::produced_cargo
CargoID produced_cargo[INDUSTRY_NUM_OUTPUTS]
16 production cargo slots
Definition: industry.h:70
GoodsEntry::node
NodeID node
ID of node in link graph referring to this goods entry.
Definition: station_base.h:255
Vehicle::cargo
VehicleCargoList cargo
The cargo this vehicle is carrying.
Definition: vehicle_base.h:320
FreeTrainReservation
static void FreeTrainReservation(Train *v)
Clear platform reservation during station building/removing.
Definition: station_cmd.cpp:1223
GetStationType
static StationType GetStationType(TileIndex t)
Get the station type of this tile.
Definition: station_map.h:44
CommandCost::Failed
bool Failed() const
Did this command fail?
Definition: command_type.h:159
FindRoadStopSpot
static RoadStop ** FindRoadStopSpot(bool truck_station, Station *st)
Definition: station_cmd.cpp:1797
station_func.h
Vehicle::current_order
Order current_order
The current order (+ status, like: loading)
Definition: vehicle_base.h:329
Airport::GetHangarTile
TileIndex GetHangarTile(uint hangar_num) const
Get the first tile of the given hangar.
Definition: station_base.h:370
ShowRejectOrAcceptNews
static void ShowRejectOrAcceptNews(const Station *st, uint num_items, CargoID *cargo, StringID msg)
Items contains the two cargo names that are to be accepted or rejected.
Definition: station_cmd.cpp:489
IncreaseStats
void IncreaseStats(Station *st, CargoID cargo, StationID next_station_id, uint capacity, uint usage, uint32 time, EdgeUpdateMode mode)
Increase capacity for a link stat given by station cargo and next hop.
Definition: station_cmd.cpp:3749
Station::airport
Airport airport
Tile area the airport covers.
Definition: station_base.h:461
AirportTileTableIterator
Iterator to iterate over all tiles belonging to an airport spec.
Definition: newgrf_airport.h:29
OrthogonalTileArea
Represents the covered area of e.g.
Definition: tilearea_type.h:18
Station::AddFacility
void AddFacility(StationFacility new_facility_bit, TileIndex facil_xy)
Called when new facility is built on the station.
Definition: station.cpp:201
MultiMap::MapSize
size_t MapSize() const
Count the number of ranges with equal keys in this MultiMap.
Definition: multimap.hpp:350
EndSpriteCombine
void EndSpriteCombine()
Terminates a block of sprites started by StartSpriteCombine.
Definition: viewport.cpp:771
CMSATree
static bool CMSATree(TileIndex tile)
Check whether the tile is a tree.
Definition: station_cmd.cpp:192
Vehicle::IsFrontEngine
bool IsFrontEngine() const
Check if the vehicle is a front engine.
Definition: vehicle_base.h:899
SRT_NEW_CARGO
@ SRT_NEW_CARGO
Trigger station on new cargo arrival.
Definition: newgrf_station.h:104
HasTileRoadType
static bool HasTileRoadType(TileIndex t, RoadTramType rtt)
Check if a tile has a road or a tram road type.
Definition: road_map.h:210
AirportTileSpec::GetByTile
static const AirportTileSpec * GetByTile(TileIndex tile)
Retrieve airport tile spec for the given airport tile.
Definition: newgrf_airporttiles.cpp:49
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:53
ANIM_STATUS_NO_ANIMATION
static const uint8 ANIM_STATUS_NO_ANIMATION
There is no animation.
Definition: newgrf_animation_type.h:15
GetTropicZone
static TropicZone GetTropicZone(TileIndex tile)
Get the tropic zone.
Definition: tile_map.h:238
Station::indtype
IndustryType indtype
Industry type to get the name from.
Definition: station_base.h:465
Town::MaxTownNoise
uint16 MaxTownNoise() const
Calculate the max town noise.
Definition: town.h:117
GameSettings::economy
EconomySettings economy
settings to change the economy
Definition: settings_type.h:586
RailBuildCost
static Money RailBuildCost(RailType railtype)
Returns the cost of building the specified railtype.
Definition: rail.h:372
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
RemoveDock
static CommandCost RemoveDock(TileIndex tile, DoCommandFlag flags)
Remove a dock.
Definition: station_cmd.cpp:2686
TRACK_BIT_X
@ TRACK_BIT_X
X-axis track.
Definition: track_type.h:40
_tick_counter
uint16 _tick_counter
Ever incrementing (and sometimes wrapping) tick counter for setting off various events.
Definition: date.cpp:30
NewGRFSpriteLayout
NewGRF supplied spritelayout.
Definition: newgrf_commons.h:113
CmdRemoveFromRailStation
CommandCost CmdRemoveFromRailStation(TileIndex start, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
Remove a single tile from a rail station.
Definition: station_cmd.cpp:1670
HasStationTileRail
static bool HasStationTileRail(TileIndex t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint?
Definition: station_map.h:146
industry.h
safeguards.h
CombineTrackStatus
static TrackStatus CombineTrackStatus(TrackdirBits trackdirbits, TrackdirBits red_signals)
Builds a TrackStatus.
Definition: track_func.h:387
SetDockingTile
static void SetDockingTile(TileIndex t, bool b)
Set the docking tile state of a tile.
Definition: water_map.h:355
StationSpec::name
StringID name
Name of this station.
Definition: newgrf_station.h:127
ROTSG_ROADSTOP
@ ROTSG_ROADSTOP
Required: Drive-in stop surface.
Definition: road.h:68
ClearTile_Station
CommandCost ClearTile_Station(TileIndex tile, DoCommandFlag flags)
Clear a single tile of a station.
Definition: station_cmd.cpp:4301
NewGRFSpriteLayout::NeedsPreprocessing
bool NeedsPreprocessing() const
Tests whether this spritelayout needs preprocessing by PrepareLayout() and ProcessRegisters(),...
Definition: newgrf_commons.h:150
Train
'Train' is either a loco or a wagon.
Definition: train.h:86
VEH_INVALID
@ VEH_INVALID
Non-existing type of vehicle.
Definition: vehicle_type.h:35
IsValidTile
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
Definition: tile_map.h:161
Airport::flags
uint64 flags
stores which blocks on the airport are taken. was 16 bit earlier on, then 32
Definition: station_base.h:305
FreeTrainTrackReservation
void FreeTrainTrackReservation(const Train *v)
Free the reserved path in front of a vehicle.
Definition: train_cmd.cpp:2260
GetCanalSprite
SpriteID GetCanalSprite(CanalFeature feature, TileIndex tile)
Lookup the base sprite to use for a canal.
Definition: newgrf_canal.cpp:140
SetStationTileRandomBits
static void SetStationTileRandomBits(TileIndex t, byte random_bits)
Set the random bits for a station tile.
Definition: station_map.h:505
ReverseDiagDir
static DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
Definition: direction_func.h:118
GetTileSlope
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
Definition: tile_map.cpp:59
StationNameInformation::indtypes
bool * indtypes
Array of bools telling whether an industry type has been found.
Definition: station_cmd.cpp:211
ROADSTOP_TRUCK
@ ROADSTOP_TRUCK
A standard stop for trucks.
Definition: station_type.h:46
SPRITE_MODIFIER_CUSTOM_SPRITE
@ SPRITE_MODIFIER_CUSTOM_SPRITE
Set when a sprite originates from an Action 1.
Definition: sprites.h:1537
IsTileOwner
static bool IsTileOwner(TileIndex tile, Owner owner)
Checks if a tile belongs to the given owner.
Definition: tile_map.h:214
HasStationReservation
static bool HasStationReservation(TileIndex t)
Get the reservation state of the rail station.
Definition: station_map.h:393
MakeAirport
static void MakeAirport(TileIndex t, Owner o, StationID sid, byte section, WaterClass wc)
Make the given tile an airport tile.
Definition: station_map.h:626
NUM_AIRPORTS
@ NUM_AIRPORTS
Maximal number of airports in total.
Definition: airport.h:41
CMD_REMOVE_SINGLE_RAIL
@ CMD_REMOVE_SINGLE_RAIL
remove a single rail track
Definition: command_type.h:179
BaseStation::name
std::string name
Custom name.
Definition: base_station_base.h:57
STATION_LINKGRAPH_TICKS
static const int STATION_LINKGRAPH_TICKS
cycle duration for cleaning dead links
Definition: date_type.h:35
DrawTileSprites
Ground palette sprite of a tile, together with its sprite layout.
Definition: sprite.h:58
CheckFlatLandRoadStop
static CommandCost CheckFlatLandRoadStop(TileArea tile_area, DoCommandFlag flags, uint invalid_dirs, bool is_drive_through, bool is_truck_stop, Axis axis, StationID *station, RoadType rt)
Checks if a road stop can be built at the given tile.
Definition: station_cmd.cpp:959
FlowStat::RestrictShare
void RestrictShare(StationID st)
Restrict a flow by moving it to the end of the map and decreasing the amount of unrestricted flow.
Definition: station_cmd.cpp:4523
StartSpriteCombine
void StartSpriteCombine()
Starts a block of sprites, which are "combined" into a single bounding box.
Definition: viewport.cpp:761
INVALID_DIAGDIR
@ INVALID_DIAGDIR
Flag for an invalid DiagDirection.
Definition: direction_type.h:84
DrawSprite
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Definition: gfx.cpp:1042
Station::bus_station
TileArea bus_station
Tile area the bus 'station' part covers.
Definition: station_base.h:457
RemoveBuoy
CommandCost RemoveBuoy(TileIndex tile, DoCommandFlag flags)
Remove a buoy.
Definition: waypoint_cmd.cpp:360
AutoslopeEnabled
static bool AutoslopeEnabled()
Tests if autoslope is enabled for _current_company.
Definition: autoslope.h:44
road_internal.h
waypoint_func.h
RTSG_GROUND
@ RTSG_GROUND
Main group of ground images.
Definition: rail.h:49
airporttile_ids.h
GoodsEntry::rating
byte rating
Station rating for this cargo.
Definition: station_base.h:232
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
TileDesc::station_name
StringID station_name
Type of station within the class.
Definition: tile_cmd.h:57
RoadTypeInfo::name
StringID name
Name of this rail type.
Definition: road.h:100
ValParamRoadType
bool ValParamRoadType(RoadType roadtype)
Validate functions for rail building.
Definition: road.cpp:142
GameSettings::linkgraph
LinkGraphSettings linkgraph
settings for link graph calculations
Definition: settings_type.h:587
DeleteStaleLinks
void DeleteStaleLinks(Station *from)
Check all next hops of cargo packets in this station for existence of a a valid link they may use to ...
Definition: station_cmd.cpp:3655
GetRoadStopDir
static DiagDirection GetRoadStopDir(TileIndex t)
Gets the direction the road stop entrance points towards.
Definition: station_map.h:257
Slope
Slope
Enumeration for the slope-type.
Definition: slope_type.h:48
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition: direction_type.h:77
MapSizeY
static uint MapSizeY()
Get the size of the map along the Y.
Definition: map_func.h:82
StationCargoList::AvailableCount
uint AvailableCount() const
Returns sum of cargo still available for loading at the sation.
Definition: cargopacket.h:508
GFX_DOCK_BASE_WATER_PART
static const int GFX_DOCK_BASE_WATER_PART
The offset for the water parts.
Definition: station_map.h:35
TRACK_BIT_ALL
@ TRACK_BIT_ALL
All possible tracks.
Definition: track_type.h:53
FACIL_DOCK
@ FACIL_DOCK
Station with a dock.
Definition: station_type.h:56
OffsetGroundSprite
void OffsetGroundSprite(int x, int y)
Called when a foundation has been drawn for the current tile.
Definition: viewport.cpp:593
FlowStat::AppendShare
void AppendShare(StationID st, uint flow, bool restricted=false)
Add some flow to the end of the shares map.
Definition: station_base.h:67
CBM_STATION_AVAIL
@ CBM_STATION_AVAIL
Availability of station in construction window.
Definition: newgrf_callbacks.h:303
SpecializedStation< Station, false >::From
static Station * From(BaseStation *st)
Converts a BaseStation to SpecializedStation with type checking.
Definition: base_station_base.h:248
StationSettings::station_spread
byte station_spread
amount a station may spread
Definition: settings_type.h:553
Station::always_accepted
CargoTypes always_accepted
Bitmask of always accepted cargo types (by houses, HQs, industry tiles when industry doesn't accept c...
Definition: station_base.h:477
ShowStationViewWindow
void ShowStationViewWindow(StationID station)
Opens StationViewWindow for given station.
Definition: station_gui.cpp:2142
date_func.h
IsRailStationTile
static bool IsRailStationTile(TileIndex t)
Is this tile a station tile and a rail station?
Definition: station_map.h:102
CommandCost::AddCost
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
Definition: command_type.h:62
TruncateCargo
static void TruncateCargo(const CargoSpec *cs, GoodsEntry *ge, uint amount=UINT_MAX)
Truncate the cargo by a specific amount.
Definition: station_cmd.cpp:3451
CBID_STATION_TILE_LAYOUT
@ CBID_STATION_TILE_LAYOUT
Called when building a station to customize the tile layout.
Definition: newgrf_callbacks.h:96
GUISettings::show_track_reservation
bool show_track_reservation
highlight reserved tracks.
Definition: settings_type.h:159
WATER_CLASS_CANAL
@ WATER_CLASS_CANAL
Canal.
Definition: water_map.h:49
StationSpec::disallowed_platforms
byte disallowed_platforms
Bitmask of number of platforms available for the station.
Definition: newgrf_station.h:133
stdafx.h
CheckAllowRemoveRoad
CommandCost CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, RoadTramType rtt, DoCommandFlag flags, bool town_check)
Is it allowed to remove the given road bits from the given tile?
Definition: road_cmd.cpp:266
CmdBuildRailStation
CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
Build rail station.
Definition: station_cmd.cpp:1260
RoadType
RoadType
The different roadtypes we support.
Definition: road_type.h:22
TileTypeProcs
Set of callback functions for performing tile operations of a given tile type.
Definition: tile_cmd.h:145
StationFinder::GetStations
const StationList * GetStations()
Run a tile loop to find stations around a tile, on demand.
Definition: station_cmd.cpp:3985
SAT_BUILT
@ SAT_BUILT
Trigger tile when built.
Definition: newgrf_animation_type.h:27
BuildStationPart
static CommandCost BuildStationPart(Station **st, DoCommandFlag flags, bool reuse, TileArea area, StationNaming name_class)
Common part of building various station parts and possibly attaching them to an existing one.
Definition: station_cmd.cpp:689
GoodsEntry::link_graph
LinkGraphID link_graph
Link graph this station belongs to.
Definition: station_base.h:254
Station::truck_stops
RoadStop * truck_stops
All the truck stops.
Definition: station_base.h:458
CMD_REMOVE_FROM_RAIL_STATION
@ CMD_REMOVE_FROM_RAIL_STATION
remove a (rectangle of) tiles from a rail station
Definition: command_type.h:190
IndustrySpec
Defines the data structure for constructing industry.
Definition: industrytype.h:107
Station::industry
Industry * industry
NOSAVE: Associated industry for neutral stations. (Rebuilt on load from Industry->st)
Definition: station_base.h:480
OrderBackup::Reset
static void Reset(TileIndex tile=INVALID_TILE, bool from_gui=true)
Reset the OrderBackups from GUI/game logic.
Definition: order_backup.cpp:183
DC_BANKRUPT
@ DC_BANKRUPT
company bankrupts, skip money check, skip vehicle on tile check in some cases
Definition: command_type.h:354
IsValidDockingDirectionForDock
bool IsValidDockingDirectionForDock(TileIndex t, DiagDirection d)
Check if a dock tile can be docked from the given direction.
Definition: station_cmd.cpp:2650
AirportTileIterator
Iterator to iterate over all tiles belonging to an airport.
Definition: station_base.h:527
AirportSpec::IsAvailable
bool IsAvailable() const
Check whether this airport is available to build.
Definition: newgrf_airport.cpp:124
RTSG_OVERLAY
@ RTSG_OVERLAY
Images for overlaying track.
Definition: rail.h:48
viewport_func.h
AxisToDiagDir
static DiagDirection AxisToDiagDir(Axis a)
Converts an Axis to a DiagDirection.
Definition: direction_func.h:232
StationList
std::set< Station *, StationCompare > StationList
List of stations.
Definition: station_type.h:94
TileLoop_Water
void TileLoop_Water(TileIndex tile)
Let a water tile floods its diagonal adjoining tiles called from tunnelbridge_cmd,...
Definition: water_cmd.cpp:1223
bridge_map.h
IsTileType
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
GetTrainStopLocation
int GetTrainStopLocation(StationID station_id, TileIndex tile, const Train *v, int *station_ahead, int *station_length)
Get the stop location of (the center) of the front vehicle of a train at a platform of a station.
Definition: train_cmd.cpp:259
FACIL_WAYPOINT
@ FACIL_WAYPOINT
Station is a waypoint.
Definition: station_type.h:57
animated_tile_func.h
GetTileOwner
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
Definition: tile_map.h:178
IsAirport
static bool IsAirport(TileIndex t)
Is this station tile an airport?
Definition: station_map.h:157
AddSortableSpriteToDraw
void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, int x, int y, int w, int h, int dz, int z, bool transparent, int bb_offset_x, int bb_offset_y, int bb_offset_z, const SubSprite *sub)
Draw a (transparent) sprite at given coordinates with a given bounding box.
Definition: viewport.cpp:665
FindJoiningRoadStop
static CommandCost FindJoiningRoadStop(StationID existing_stop, StationID station_to_join, bool adjacent, TileArea ta, Station **st)
Find a nearby station that joins this road stop.
Definition: station_cmd.cpp:1823
yapf_cache.h
GroundSpritePaletteTransform
static PaletteID GroundSpritePaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
Applies PALETTE_MODIFIER_COLOUR to a palette entry of a ground sprite.
Definition: sprite.h:168
Vehicle::direction
Direction direction
facing
Definition: vehicle_base.h:283
FlowStatMap::AddFlow
void AddFlow(StationID origin, StationID via, uint amount)
Add some flow from "origin", going via "via".
Definition: station_cmd.cpp:4610
OrthogonalTileArea::h
uint16 h
The height of the area.
Definition: tilearea_type.h:21
IsTileForestIndustry
bool IsTileForestIndustry(TileIndex tile)
Check whether the tile is a forest.
Definition: industry_cmd.cpp:962
ApplyPixelFoundationToSlope
static uint ApplyPixelFoundationToSlope(Foundation f, Slope *s)
Applies a foundation to a slope.
Definition: landscape.h:129
DistanceMax
uint DistanceMax(TileIndex t0, TileIndex t1)
Gets the biggest distance component (x or y) between the two given tiles.
Definition: map.cpp:189
AirportSpec::size_x
byte size_x
size of airport in x direction
Definition: newgrf_airport.h:105
MP_TREES
@ MP_TREES
Tile got trees.
Definition: tile_type.h:50
TileIndexDiffC
A pair-construct of a TileIndexDiff.
Definition: map_type.h:57
DrawFoundation
void DrawFoundation(TileInfo *ti, Foundation f)
Draw foundation f at tile ti.
Definition: landscape.cpp:471
MAX_LENGTH_STATION_NAME_CHARS
static const uint MAX_LENGTH_STATION_NAME_CHARS
The maximum length of a station name in characters including '\0'.
Definition: station_type.h:87
SSF_CUSTOM_FOUNDATIONS
@ SSF_CUSTOM_FOUNDATIONS
Draw custom foundations.
Definition: newgrf_station.h:98
LinkGraph::LastCompression
Date LastCompression() const
Get date of last compression.
Definition: linkgraph.h:514
ForAllStationsRadius
void ForAllStationsRadius(TileIndex center, uint radius, Func func)
Call a function on all stations whose sign is within a radius of a center tile.
Definition: station_kdtree.h:29
FlowStat::empty_sharesmap
static const SharesMap empty_sharesmap
Static instance of FlowStat::SharesMap.
Definition: station_base.h:37
ConstructionSettings::road_stop_on_competitor_road
bool road_stop_on_competitor_road
allow building of drive-through road stops on roads owned by competitors
Definition: settings_type.h:343
RemoveFromRailBaseStation
CommandCost RemoveFromRailBaseStation(TileArea ta, std::vector< T * > &affected_stations, DoCommandFlag flags, Money removal_cost, bool keep_rail)
Remove a number of tiles from any rail station within the area.
Definition: station_cmd.cpp:1562
string_func.h
IndustrySpec::enabled
bool enabled
entity still available (by default true).newgrf can disable it, though
Definition: industrytype.h:140
AIRPORT_CLOSED_block
static const uint64 AIRPORT_CLOSED_block
Dummy block for indicating a closed airport.
Definition: airport.h:128
IsStationTileBlocked
bool IsStationTileBlocked(TileIndex tile)
Check whether a rail station tile is NOT traversable.
Definition: newgrf_station.cpp:867
GoodsEntry::GES_CURRENT_MONTH
@ GES_CURRENT_MONTH
Set when cargo was delivered for final delivery this month.
Definition: station_base.h:202
CALLBACK_FAILED
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Definition: newgrf_callbacks.h:404
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
IsDockTile
static bool IsDockTile(TileIndex t)
Is tile t a dock tile?
Definition: station_map.h:295
TRACKDIR_BIT_NONE
@ TRACKDIR_BIT_NONE
No track build.
Definition: track_type.h:102
IsBuoyTile
static bool IsBuoyTile(TileIndex t)
Is tile t a buoy tile?
Definition: station_map.h:316
GetDisallowedRoadDirections
static DisallowedRoadDirections GetDisallowedRoadDirections(TileIndex t)
Gets the disallowed directions.
Definition: road_map.h:301
IsRoadStopTile
static bool IsRoadStopTile(TileIndex t)
Is tile t a road stop station?
Definition: station_map.h:213
Ship
All ships have this type.
Definition: ship.h:26
GetCustomRailSprite
SpriteID GetCustomRailSprite(const RailtypeInfo *rti, TileIndex tile, RailTypeSpriteGroup rtsg, TileContext context, uint *num_results)
Get the sprite to draw for the given tile.
Definition: newgrf_railtype.cpp:95
GoodsEntry
Stores station stats for a single cargo.
Definition: station_base.h:167
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:47
vehicle_func.h
WC_SELECT_STATION
@ WC_SELECT_STATION
Select station (when joining stations); Window numbers:
Definition: window_type.h:234
station_base.h
SourceType
SourceType
Types of cargo source and destination.
Definition: cargo_type.h:147
Clamp
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:77
DeleteStationIfEmpty
static void DeleteStationIfEmpty(BaseStation *st)
This is called right after a station was deleted.
Definition: station_cmd.cpp:726
PALETTE_CRASH
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
Definition: sprites.h:1600
Pool::PoolItem<&_station_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:386
GRFFilePropsBase::spritegroup
const struct SpriteGroup * spritegroup[Tcnt]
pointer to the different sprites of the entity
Definition: newgrf_commons.h:321
strings_func.h
StationSpec
Station specification.
Definition: newgrf_station.h:113
Vehicle::First
Vehicle * First() const
Get the first vehicle of this vehicle chain.
Definition: vehicle_base.h:609
GetWaterClass
static WaterClass GetWaterClass(TileIndex t)
Get the water class at a tile.
Definition: water_map.h:106
CountMapSquareAround
static int CountMapSquareAround(TileIndex tile, CMSAMatcher cmp)
Counts the numbers of tiles matching a specific type in the area around.
Definition: station_cmd.cpp:136
newgrf_roadtype.h
StringParameters
Definition: strings_func.h:60
GoodsEntry::last_age
byte last_age
Age in years (up to 255) of the last vehicle that tried to load this cargo.
Definition: station_base.h:249
TRACK_BIT_LEFT
@ TRACK_BIT_LEFT
Left track.
Definition: track_type.h:44
IsRailWaypoint
static bool IsRailWaypoint(TileIndex t)
Is this station tile a rail waypoint?
Definition: station_map.h:113
LinkGraph::AddNode
NodeID AddNode(const Station *st)
Add a node to the component and create empty edges associated with it.
Definition: linkgraph.cpp:164
LinkGraph::Node::RemoveEdge
void RemoveEdge(NodeID to)
Remove an outgoing edge from this node.
Definition: linkgraph.cpp:233
refresh.h
Pool::PoolItem<&_town_pool >::GetNumItems
static size_t GetNumItems()
Returns number of valid items in the pool.
Definition: pool_type.hpp:367
DeleteAnimatedTile
void DeleteAnimatedTile(TileIndex tile)
Removes the given tile from the animated tile table.
Definition: animated_tile.cpp:26
TileXY
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition: map_func.h:163
RoadStop::ClearDriveThrough
void ClearDriveThrough()
Prepare for removal of this stop; update other neighbouring stops if needed.
Definition: roadstop.cpp:130
INVALID_DATE
static const Date INVALID_DATE
Representation of an invalid date.
Definition: date_type.h:111
PerformStationTileSlopeCheck
CommandCost PerformStationTileSlopeCheck(TileIndex north_tile, TileIndex cur_tile, const StationSpec *statspec, Axis axis, byte plat_len, byte numtracks)
Check the slope of a tile of a new station.
Definition: newgrf_station.cpp:652
FACIL_TRAIN
@ FACIL_TRAIN
Station with train station.
Definition: station_type.h:52
TrackedViewportSign::UpdatePosition
void UpdatePosition(int center, int top, StringID str, StringID str_small=STR_NULL)
Update the position of the viewport sign.
Definition: viewport_type.h:64
TryPathReserve
bool TryPathReserve(Train *v, bool mark_as_stuck=false, bool first_tile_okay=false)
Try to reserve a path to a safe position.
Definition: train_cmd.cpp:2698
SpecializedVehicle< RoadVehicle, Type >::From
static RoadVehicle * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Definition: vehicle_base.h:1166
GetStationGfx
static StationGfx GetStationGfx(TileIndex t)
Get the station graphics of this tile.
Definition: station_map.h:68
GetRailStationAxis
static Axis GetRailStationAxis(TileIndex t)
Get the rail direction of a rail station.
Definition: station_map.h:337
RoadStopType
RoadStopType
Types of RoadStops.
Definition: station_type.h:44
GoodsEntry::flows
FlowStatMap flows
Planned flows through this station.
Definition: station_base.h:256
RailTrackOffset
RailTrackOffset
Offsets for sprites within an overlay/underlay set.
Definition: rail.h:67
OrthogonalTileArea::tile
TileIndex tile
The base tile of the area.
Definition: tilearea_type.h:19
PaletteID
uint32 PaletteID
The number of the palette.
Definition: gfx_type.h:18
LinkGraph::MIN_TIMEOUT_DISTANCE
static const uint MIN_TIMEOUT_DISTANCE
Minimum effective distance for timeout calculation.
Definition: linkgraph.h:448
HasRailCatenaryDrawn
static bool HasRailCatenaryDrawn(RailType rt)
Test if we should draw rail catenary.
Definition: elrail_func.h:30
ConstructionSettings::build_on_slopes
bool build_on_slopes
allow building on slopes
Definition: settings_type.h:335
ROTSG_OVERLAY
@ ROTSG_OVERLAY
Optional: Images for overlaying track.
Definition: road.h:59
InvalidateWindowClassesData
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
Definition: window.cpp:3251
RTO_X
@ RTO_X
Piece of rail in X direction.
Definition: rail.h:68
AirportSpec::grf_prop
struct GRFFileProps grf_prop
Properties related to the grf file.
Definition: newgrf_airport.h:118
WID_SV_ACCEPT_RATING_LIST
@ WID_SV_ACCEPT_RATING_LIST
List of accepted cargoes / rating of cargoes.
Definition: station_widget.h:22
OrderList
Shared order list linking together the linked list of orders and the list of vehicles sharing this or...
Definition: order_base.h:253
GetIndustryIndex
static IndustryID GetIndustryIndex(TileIndex t)
Get the industry ID of the given tile.
Definition: industry_map.h:63
CMD_REMOVE_ROAD_STOP
@ CMD_REMOVE_ROAD_STOP
remove a road stop
Definition: command_type.h:198
MarkTileDirtyByTile
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
Definition: viewport.cpp:1987
TRANSPORT_WATER
@ TRANSPORT_WATER
Transport over water.
Definition: transport_type.h:29
Vehicle::NextShared
Vehicle * NextShared() const
Get the next vehicle of the shared vehicle chain.
Definition: vehicle_base.h:678
OWNER_NONE
@ OWNER_NONE
The tile has no ownership.
Definition: company_type.h:25
FOUNDATION_LEVELED
@ FOUNDATION_LEVELED
The tile is leveled up to a flat slope.
Definition: slope_type.h:95
CompanyInfrastructure::rail
uint32 rail[RAILTYPE_END]
Count of company owned track bits for each rail type.
Definition: company_base.h:33
Station::UpdateVirtCoord
void UpdateVirtCoord() override
Update the virtual coords needed to draw the station sign.
Definition: station_cmd.cpp:413
MakeRoadNormal
static void MakeRoadNormal(TileIndex t, RoadBits bits, RoadType road_rt, RoadType tram_rt, TownID town, Owner road, Owner tram)
Make a normal road tile.
Definition: road_map.h:635
TileDiffXY
static TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
Definition: map_func.h:179
GetRailType
static RailType GetRailType(TileIndex t)
Gets the rail type of the given tile.
Definition: rail_map.h:115
WC_VEHICLE_DEPOT
@ WC_VEHICLE_DEPOT
Depot view; Window numbers:
Definition: window_type.h:343
CargoSpec::classes
uint16 classes
Classes of this cargo type.
Definition: cargotype.h:80
MP_STATION
@ MP_STATION
A tile of a station.
Definition: tile_type.h:51
IndustrySpec::grf_prop
GRFFileProps grf_prop
properties related to the grf file
Definition: industrytype.h:141
NUM_CARGO
@ NUM_CARGO
Maximal number of cargo types in a game.
Definition: cargo_type.h:65
GoodsEntry::GES_ACCEPTANCE
@ GES_ACCEPTANCE
Set when the station accepts the cargo currently for final deliveries.
Definition: station_base.h:174
GetStationIndex
static StationID GetStationIndex(TileIndex t)
Get StationID from a tile.
Definition: station_map.h:28
SpecializedStation< Station, false >::GetByTile
static Station * GetByTile(TileIndex tile)
Get the station belonging to a specific tile.
Definition: base_station_base.h:238
waypoint_base.h
GoodsEntry::time_since_pickup
byte time_since_pickup
Number of rating-intervals (up to 255) since the last vehicle tried to load this cargo.
Definition: station_base.h:230
StationClassID
StationClassID
Definition: newgrf_station.h:83
BaseStation::cached_name
std::string cached_name
NOSAVE: Cache of the resolved name of the station, if not using a custom name.
Definition: base_station_base.h:59
TrackedViewportSign::kdtree_valid
bool kdtree_valid
Are the sign data valid for use with the _viewport_sign_kdtree?
Definition: viewport_type.h:58
ROAD_Y
@ ROAD_Y
Full road along the y-axis (north-west + south-east)
Definition: road_type.h:57
ForAllStationsAroundTiles
void ForAllStationsAroundTiles(const TileArea &ta, Func func)
Call a function on all stations that have any part of the requested area within their catchment.
Definition: station_base.h:566
FindVehicleOnPos
void FindVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc)
Find a vehicle from a specific location.
Definition: vehicle.cpp:498
UpdateCompanyRoadInfrastructure
void UpdateCompanyRoadInfrastructure(RoadType rt, Owner o, int count)
Update road infrastructure counts for a company.
Definition: road_cmd.cpp:194
RTO_Y
@ RTO_Y
Piece of rail in Y direction.
Definition: rail.h:69
Pool::PoolItem<&_station_pool >::CanAllocateItem
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
Definition: pool_type.hpp:307
FlowStat::GetVia
StationID GetVia() const
Get a station a package can be routed to.
Definition: station_base.h:131
DIAGDIR_BEGIN
@ DIAGDIR_BEGIN
Used for iterations.
Definition: direction_type.h:78
GetRoadTypeInfo
static const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition: road.h:224
MakeRoadStop
static void MakeRoadStop(TileIndex t, Owner o, StationID sid, RoadStopType rst, RoadType road_rt, RoadType tram_rt, DiagDirection d)
Make the given tile a roadstop tile.
Definition: station_map.h:590
NewGRFClass::name
StringID name
Name of this class.
Definition: newgrf_class.h:39
RemoveRoadStop
static CommandCost RemoveRoadStop(TileIndex tile, DoCommandFlag flags)
Remove a bus station/truck stop.
Definition: station_cmd.cpp:1993
Station::catchment_tiles
BitmapTileArea catchment_tiles
NOSAVE: Set of individual tiles covered by catchment area.
Definition: station_base.h:467
LinkGraph::Merge
void Merge(LinkGraph *other)
Merge a link graph with another one.
Definition: linkgraph.cpp:89
TileDesc::str
StringID str
Description of the tile.
Definition: tile_cmd.h:52
GetTranslatedAirportTileID
StationGfx GetTranslatedAirportTileID(StationGfx gfx)
Do airporttile gfx ID translation for NewGRFs.
Definition: newgrf_airporttiles.cpp:95
DC_AUTO
@ DC_AUTO
don't allow building on structures
Definition: command_type.h:349
BaseStation::xy
TileIndex xy
Base tile of the station.
Definition: base_station_base.h:53
AddTrackToSignalBuffer
void AddTrackToSignalBuffer(TileIndex tile, Track track, Owner owner)
Add track to signal update buffer.
Definition: signal.cpp:578
GetTileMaxPixelZ
static int GetTileMaxPixelZ(TileIndex tile)
Get top height of the tile.
Definition: tile_map.h:304
BaseStation
Base class for all station-ish types.
Definition: base_station_base.h:52
HasStationInUse
bool HasStationInUse(StationID station, bool include_company, CompanyID company)
Tests whether the company's vehicles have this station in orders.
Definition: station_cmd.cpp:2493
AnimationInfo::triggers
uint16 triggers
The triggers that trigger animation.
Definition: newgrf_animation_type.h:22
SpecializedVehicle< RoadVehicle, Type >::Iterate
static Pool::IterateWrapper< RoadVehicle > Iterate(size_t from=0)
Returns an iterable ensemble of all valid vehicles of type T.
Definition: vehicle_base.h:1235
BaseStation::delete_ctr
byte delete_ctr
Delete counter. If greater than 0 then it is decremented until it reaches 0; the waypoint is then is ...
Definition: base_station_base.h:55
IndustrySpec::life_type
IndustryLifeType life_type
This is also known as Industry production flag, in newgrf specs.
Definition: industrytype.h:123
Order::ShouldStopAtStation
bool ShouldStopAtStation(const Vehicle *v, StationID station) const
Check whether the given vehicle should stop at the given station based on this order and the non-stop...
Definition: order_cmd.cpp:2231
TileArea
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
Definition: tilearea_type.h:102
TriggerStationRandomisation
void TriggerStationRandomisation(Station *st, TileIndex trigger_tile, StationRandomTrigger trigger, CargoID cargo_type)
Trigger station randomisation.
Definition: newgrf_station.cpp:964
StationSettings::distant_join_stations
bool distant_join_stations
allow to join non-adjacent stations
Definition: settings_type.h:551
error
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
Definition: openttd.cpp:132
BaseStation::speclist
StationSpecList * speclist
List of station specs of this station.
Definition: base_station_base.h:66
Airport::GetNumHangars
uint GetNumHangars() const
Get the number of hangars on this airport.
Definition: station_base.h:407
TrackBits
TrackBits
Bitfield corresponding to Track.
Definition: track_type.h:38
IsDockingTile
static bool IsDockingTile(TileIndex t)
Checks whether the tile is marked as a dockling tile.
Definition: water_map.h:365
DrawTileSprites::seq
const DrawTileSeqStruct * seq
Array of child sprites. Terminated with a terminator entry.
Definition: sprite.h:60
StationSettings::adjacent_stations
bool adjacent_stations
allow stations to be built directly adjacent to other stations
Definition: settings_type.h:550
Debug
#define Debug(name, level, format_string,...)
Ouptut a line of debugging information.
Definition: debug.h:37
AnimationInfo::status
uint8 status
Status; 0: no looping, 1: looping, 0xFF: no animation.
Definition: newgrf_animation_type.h:20
SetBit
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
Town
Town data structure.
Definition: town.h:50
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:378
TileDesc::rail_speed
uint16 rail_speed
Speed limit of rail (bridges and track)
Definition: tile_cmd.h:64
StationSpec::grf_prop
GRFFilePropsBase< NUM_CARGO+3 > grf_prop
Properties related the the grf file.
Definition: newgrf_station.h:125
LinkRefresher::Run
static void Run(Vehicle *v, bool allow_merge=true, bool is_full_loading=false)
Refresh all links the given vehicle will visit.
Definition: refresh.cpp:26
NewGRFClass::Get
static NewGRFClass * Get(Tid cls_id)
Get a particular class.
Definition: newgrf_class_func.h:103
CargoPacket
Container for cargo from the same location and time.
Definition: cargopacket.h:43
RoadTypeInfo::max_speed
uint16 max_speed
Maximum speed for vehicles travelling on this road type.
Definition: road.h:139
IsDock
static bool IsDock(TileIndex t)
Is tile t a dock tile?
Definition: station_map.h:285
random_func.hpp
SpecializedStation< Station, false >::GetIfValid
static Station * GetIfValid(size_t index)
Returns station if the index is a valid index for this station type.
Definition: base_station_base.h:228
newgrf_canal.h
TILE_HEIGHT
static const uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in #ZOOM_LVL_BASE.
Definition: tile_type.h:16
OverflowSafeInt< int64 >
Airport::type
byte type
Type of this airport,.
Definition: station_base.h:306
IsOilRig
static bool IsOilRig(TileIndex t)
Is tile t part of an oilrig?
Definition: station_map.h:274
NF_SMALL
@ NF_SMALL
Small news item. (Information window with text and viewport)
Definition: news_type.h:77
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:20
Vehicle::IsStoppedInDepot
bool IsStoppedInDepot() const
Check whether the vehicle is in the depot and stopped.
Definition: vehicle_base.h:529
GetCustomStationFoundationRelocation
SpriteID GetCustomStationFoundationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint layout, uint edge_info)
Resolve the sprites for custom station foundations.
Definition: newgrf_station.cpp:623
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force)
Close a window by its class and window number (if it is open).
Definition: window.cpp:1176
IsPlainRailTile
static bool IsPlainRailTile(TileIndex t)
Checks whether the tile is a rail tile or rail tile with signals.
Definition: rail_map.h:60
DrawRailCatenary
void DrawRailCatenary(const TileInfo *ti)
Draws overhead wires and pylons for electric railways.
Definition: elrail.cpp:565
GetAcceptanceMask
static CargoTypes GetAcceptanceMask(const Station *st)
Get a mask of the cargo types that the station accepts.
Definition: station_cmd.cpp:475
RoadBuildCost
static Money RoadBuildCost(RoadType roadtype)
Returns the cost of building the specified roadtype.
Definition: road.h:249
IsShipDestinationTile
bool IsShipDestinationTile(TileIndex tile, StationID station)
Test if a tile is a docking tile for the given station.
Definition: ship_cmd.cpp:609
NT_ACCEPTANCE
@ NT_ACCEPTANCE
A type of cargo is (no longer) accepted.
Definition: news_type.h:34
HasPowerOnRoad
static bool HasPowerOnRoad(RoadType enginetype, RoadType tiletype)
Checks if an engine of the given RoadType got power on a tile with a given RoadType.
Definition: road.h:239
INVALID_TILE
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:88
IsNormalRoadTile
static bool IsNormalRoadTile(TileIndex t)
Return whether a tile is a normal road tile.
Definition: road_map.h:73
NEW_AIRPORTTILE_OFFSET
static const uint NEW_AIRPORTTILE_OFFSET
offset of first newgrf airport tile
Definition: airport.h:24
Axis
Axis
Allow incrementing of DiagDirDiff variables.
Definition: direction_type.h:123
NewGRFSpriteLayout::GetLayout
const DrawTileSeqStruct * GetLayout(PalSpriteID *ground) const
Returns the result spritelayout after preprocessing.
Definition: newgrf_commons.h:163
MakeRailStation
static void MakeRailStation(TileIndex t, Owner o, StationID sid, Axis a, byte section, RailType rt)
Make the given tile a rail station tile.
Definition: station_map.h:557
VETSB_ENTERED_STATION
@ VETSB_ENTERED_STATION
The vehicle entered a station.
Definition: tile_cmd.h:35
Vehicle::cargo_type
CargoID cargo_type
type of cargo this vehicle is carrying
Definition: vehicle_base.h:316
GoodsEntry::max_waiting_cargo
uint max_waiting_cargo
Max cargo from this station waiting at any station.
Definition: station_base.h:257
OrthogonalTileArea::Expand
OrthogonalTileArea & Expand(int rad)
Expand a tile area by rad tiles in each direction, keeping within map bounds.
Definition: tilearea.cpp:123
StationCargoList::Append
void Append(CargoPacket *cp, StationID next)
Appends the given cargo packet to the range of packets with the same next station.
Definition: cargopacket.cpp:690
WC_TOWN_VIEW
@ WC_TOWN_VIEW
Town view; Window numbers:
Definition: window_type.h:325
GetRoadOwner
static Owner GetRoadOwner(TileIndex t, RoadTramType rtt)
Get the owner of a specific road type.
Definition: road_map.h:233
TileDesc::owner_type
StringID owner_type[4]
Type of each owner.
Definition: tile_cmd.h:54
ReverseTrackdir
static Trackdir ReverseTrackdir(Trackdir trackdir)
Maps a trackdir to the reverse trackdir.
Definition: track_func.h:246
Station::bus_stops
RoadStop * bus_stops
All the road stops.
Definition: station_base.h:456
RVS_IN_DT_ROAD_STOP
@ RVS_IN_DT_ROAD_STOP
The vehicle is in a drive-through road stop.
Definition: roadveh.h:47
ROAD_STOP_TRACKBIT_FACTOR
static const uint ROAD_STOP_TRACKBIT_FACTOR
Multiplier for how many regular track bits a bay stop counts.
Definition: economy_type.h:228
SetTileOwner
static void SetTileOwner(TileIndex tile, Owner owner)
Sets the owner of a tile.
Definition: tile_map.h:198
LinkGraphSchedule::Unqueue
void Unqueue(LinkGraph *lg)
Remove a link graph from the execution queue.
Definition: linkgraphschedule.h:77
PalSpriteID::pal
PaletteID pal
The palette (use PAL_NONE) if not needed)
Definition: gfx_type.h:24
BaseStation::IsInUse
bool IsInUse() const
Check whether the base station currently is in use; in use means that it is not scheduled for deletio...
Definition: base_station_base.h:166
TRACK_BIT_Y
@ TRACK_BIT_Y
Y-axis track.
Definition: track_type.h:41
TileInfo::tile
TileIndex tile
Tile index.
Definition: tile_cmd.h:46
IsReversingRoadTrackdir
static bool IsReversingRoadTrackdir(Trackdir dir)
Checks whether the trackdir means that we are reversing.
Definition: track_func.h:672
GameSettings::construction
ConstructionSettings construction
construction of things in-game
Definition: settings_type.h:578
FlowStat::shares
SharesMap shares
Shares of flow to be sent via specified station (or consumed locally).
Definition: station_base.h:144
ErrorUnknownCallbackResult
void ErrorUnknownCallbackResult(uint32 grfid, uint16 cbid, uint16 cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
Definition: newgrf_commons.cpp:516
Trackdir
Trackdir
Enumeration for tracks and directions.
Definition: track_type.h:70
GetIndustrySpec
const IndustrySpec * GetIndustrySpec(IndustryType thistype)
Accessor for array _industry_specs.
Definition: industry_cmd.cpp:121
AirportSpec::nof_depots
byte nof_depots
the number of hangar tiles in this airport
Definition: newgrf_airport.h:104
WID_SV_CLOSE_AIRPORT
@ WID_SV_CLOSE_AIRPORT
'Close airport' button.
Definition: station_widget.h:26
StationSpec::callback_mask
byte callback_mask
Bitmask of station callbacks that have to be called.
Definition: newgrf_station.h:158
OrderSettings::selectgoods
bool selectgoods
only send the goods to station if a train has been there
Definition: settings_type.h:470
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
IndustrySpec::name
StringID name
Displayed name of the industry.
Definition: industrytype.h:127
Pool::PoolItem<&_link_graph_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:326
StationSpec::disallowed_lengths
byte disallowed_lengths
Bitmask of platform lengths available for the station.
Definition: newgrf_station.h:138
RailtypeInfo::strings
struct RailtypeInfo::@39 strings
Strings associated with the rail type.
RoadStop
A Stop for a Road Vehicle.
Definition: roadstop_base.h:22
BaseVehicle::type
VehicleType type
Type of vehicle.
Definition: vehicle_type.h:52
WATER_CLASS_SEA
@ WATER_CLASS_SEA
Sea.
Definition: water_map.h:48
GetAirportNoiseLevelForDistance
uint8 GetAirportNoiseLevelForDistance(const AirportSpec *as, uint distance)
Get a possible noise reduction factor based on distance from town center.
Definition: station_cmd.cpp:2163
BaseStation::UpdateVirtCoord
virtual void UpdateVirtCoord()=0
Update the coordinated of the sign (as shown in the viewport).
GRFFilePropsBase::grffile
const struct GRFFile * grffile
grf file that introduced this entity
Definition: newgrf_commons.h:320
FACIL_AIRPORT
@ FACIL_AIRPORT
Station with an airport.
Definition: station_type.h:55
TileDesc::tramtype
StringID tramtype
Type of tram on the tile.
Definition: tile_cmd.h:67
IsWater
static bool IsWater(TileIndex t)
Is it a plain water tile?
Definition: water_map.h:141
CBM_STATION_SPRITE_LAYOUT
@ CBM_STATION_SPRITE_LAYOUT
Use callback to select a sprite layout to use.
Definition: newgrf_callbacks.h:304
AirportTileSpec::name
StringID name
Tile Subname string, land information on this tile will give you "AirportName (TileSubname)".
Definition: newgrf_airporttiles.h:68
WatchedCargoCallback
void WatchedCargoCallback(TileIndex tile, CargoTypes trigger_cargoes)
Run watched cargo accepted callback for a house.
Definition: newgrf_house.cpp:651
CanRemoveRoadWithStop
static bool CanRemoveRoadWithStop(TileIndex tile, DoCommandFlag flags)
Check if a drive-through road stop tile can be cleared.
Definition: station_cmd.cpp:4274
Swap
static void Swap(T &a, T &b)
Type safe swap operation.
Definition: math_func.hpp:215
Airport::psa
PersistentStorage * psa
Persistent storage for NewGRF airports.
Definition: station_base.h:310
Track
Track
These are used to specify a single track.
Definition: track_type.h:19
Airport::GetSpec
const AirportSpec * GetSpec() const
Get the AirportSpec that from the airport type of this airport.
Definition: station_base.h:317
MakeDock
static void MakeDock(TileIndex t, Owner o, StationID sid, DiagDirection d, WaterClass wc)
Make the given tile a dock tile.
Definition: station_map.h:653
order_backup.h
AirportSpec::table
const AirportTileTable *const * table
list of the tiles composing the airport
Definition: newgrf_airport.h:100
CT_INVALID
@ CT_INVALID
Invalid cargo type.
Definition: cargo_type.h:69
IsCargoInClass
static bool IsCargoInClass(CargoID c, CargoClass cc)
Does cargo c have cargo class cc?
Definition: cargotype.h:194
SetAnimationFrame
static void SetAnimationFrame(TileIndex t, byte frame)
Set a new animation frame.
Definition: tile_map.h:262
AirportTileSpec::Get
static const AirportTileSpec * Get(StationGfx gfx)
Retrieve airport tile spec for the given airport tile.
Definition: newgrf_airporttiles.cpp:36
ShowDepotWindow
void ShowDepotWindow(TileIndex tile, VehicleType type)
Opens a depot window.
Definition: depot_gui.cpp:1103
DIAGDIR_NE
@ DIAGDIR_NE
Northeast, upper right on your monitor.
Definition: direction_type.h:79
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition: vehicle_type.h:26
WID_SV_SHIPS
@ WID_SV_SHIPS
List of scheduled ships button.
Definition: station_widget.h:29
RemapCoords2
static Point RemapCoords2(int x, int y)
Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap.
Definition: landscape.h:98
Station::GetTileArea
void GetTileArea(TileArea *ta, StationType type) const override
Get the tile area for a given station type.
Definition: station_cmd.cpp:382
Company
Definition: company_base.h:115
CMSAMatcher
bool(* CMSAMatcher)(TileIndex tile)
Function to check whether the given tile matches some criterion.
Definition: station_cmd.cpp:128
AirportFTAClass::AIRPLANES
@ AIRPLANES
Can planes land on this airport type?
Definition: airport.h:147
SpecializedVehicle::Last
T * Last()
Get the last vehicle in the chain.
Definition: vehicle_base.h:1069
CC_MAIL
@ CC_MAIL
Mail.
Definition: cargotype.h:42
Town::exclusivity
CompanyID exclusivity
which company has exclusivity
Definition: town.h:71
AirportTileSpec::grf_prop
GRFFileProps grf_prop
properties related the the grf file
Definition: newgrf_airporttiles.h:72
UpdateAllStationVirtCoords
void UpdateAllStationVirtCoords()
Update the virtual coords needed to draw the station sign for all stations.
Definition: station_cmd.cpp:447
OWNER_WATER
@ OWNER_WATER
The tile/execution is done by "water".
Definition: company_type.h:26
Town::exclusive_counter
uint8 exclusive_counter
months till the exclusivity expires
Definition: town.h:72
BaseStation::build_date
Date build_date
Date of construction.
Definition: base_station_base.h:68
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:394
WC_STATION_LIST
@ WC_STATION_LIST
Station list; Window numbers:
Definition: window_type.h:294
Order::next
Order * next
Pointer to next order. If nullptr, end of list.
Definition: order_base.h:52
ShowWaypointWindow
void ShowWaypointWindow(const Waypoint *wp)
Show the window for the given waypoint.
Definition: waypoint_gui.cpp:181
Order
Definition: order_base.h:33
CBID_STATION_SPRITE_LAYOUT
@ CBID_STATION_SPRITE_LAYOUT
Choose a sprite layout to draw, instead of the standard 0-7 range.
Definition: newgrf_callbacks.h:42
WID_SV_TRAINS
@ WID_SV_TRAINS
List of scheduled trains button.
Definition: station_widget.h:27
GetClosestDeletedStation
static Station * GetClosestDeletedStation(TileIndex tile)
Find the closest deleted station of the current company.
Definition: station_cmd.cpp:359
newgrf_cargo.h
FindJoiningStation
static CommandCost FindJoiningStation(StationID existing_station, StationID station_to_join, bool adjacent, TileArea ta, Station **st)
Find a nearby station that joins this station.
Definition: station_cmd.cpp:1200
GoodsEntry::GES_RATING
@ GES_RATING
This indicates whether a cargo has a rating at the station.
Definition: station_base.h:184
GoodsEntry::HasVehicleEverTriedLoading
bool HasVehicleEverTriedLoading() const
Reports whether a vehicle has ever tried to load the cargo at this station.
Definition: station_base.h:264
StationCargoList::Truncate
uint Truncate(uint max_move=UINT_MAX, StationCargoAmountMap *cargo_per_source=nullptr)
Truncates where each destination loses roughly the same percentage of its cargo.
Definition: cargopacket.cpp:769
Station::ship_station
TileArea ship_station
Tile area the ship 'station' part covers.
Definition: station_base.h:462
RailtypeInfo::GetRailtypeSpriteOffset
uint GetRailtypeSpriteOffset() const
Offset between the current railtype and normal rail.
Definition: rail.h:292
CmdBuildRoadStop
CommandCost CmdBuildRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
Build a bus or truck stop.
Definition: station_cmd.cpp:1844
FlowStat::ChangeShare
void ChangeShare(StationID st, int flow)
Change share for specified station.
Definition: station_cmd.cpp:4473
VehicleEnterTileStatus
VehicleEnterTileStatus
The returned bits of VehicleEnterTile.
Definition: tile_cmd.h:20
CMD_LANDSCAPE_CLEAR
@ CMD_LANDSCAPE_CLEAR
demolish a tile
Definition: command_type.h:180
GetGRFConfig
GRFConfig * GetGRFConfig(uint32 grfid, uint32 mask)
Retrieve a NewGRF from the current config by its grfid.
Definition: newgrf_config.cpp:762
FLYING
@ FLYING
Vehicle is flying in the air.
Definition: airport.h:75
OWNER_TOWN
@ OWNER_TOWN
A town owns the tile, or a town is expanding.
Definition: company_type.h:24
FindDockLandPart
static TileIndex FindDockLandPart(TileIndex t)
Find the part of a dock that is land-based.
Definition: station_cmd.cpp:2663
newgrf_railtype.h
ConstructionSettings::road_stop_on_town_road
bool road_stop_on_town_road
allow building of drive-through road stops on town owned roads
Definition: settings_type.h:342
FlowStatMap::GetFlowFromVia
uint GetFlowFromVia(StationID from, StationID via) const
Get the flow from a specific station via a specific other station.
Definition: station_cmd.cpp:4755
Vehicle::GetOrderStationLocation
virtual TileIndex GetOrderStationLocation(StationID station)
Determine the location for the station where the vehicle goes to next.
Definition: vehicle_base.h:755
DrawGroundSprite
void DrawGroundSprite(SpriteID image, PaletteID pal, const SubSprite *sub, int extra_offs_x, int extra_offs_y)
Draws a ground sprite for the current tile.
Definition: viewport.cpp:581
AT_OILRIG
@ AT_OILRIG
Oilrig airport.
Definition: airport.h:38
StationNameInformation
Information to handle station action 0 property 24 correctly.
Definition: station_cmd.cpp:209
RVSB_ROAD_STOP_TRACKDIR_MASK
@ RVSB_ROAD_STOP_TRACKDIR_MASK
Only bits 0 and 3 are used to encode the trackdir for road stops.
Definition: roadveh.h:58
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:594
station_widget.h
CmdRenameStation
CommandCost CmdRenameStation(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
Rename a station.
Definition: station_cmd.cpp:3944
debug.h
GetTrainForReservation
Train * GetTrainForReservation(TileIndex tile, Track track)
Find the train which has reserved a specific path.
Definition: pbs.cpp:331
Vehicle::refit_cap
uint16 refit_cap
Capacity left over from before last refit.
Definition: vehicle_base.h:319
MayHaveRoad
static bool MayHaveRoad(TileIndex t)
Test whether a tile can have road/tram types.
Definition: road_map.h:32
GetInclinedSlopeDirection
static DiagDirection GetInclinedSlopeDirection(Slope s)
Returns the direction of an inclined slope.
Definition: slope_func.h:239
Vehicle::date_of_last_service
Date date_of_last_service
Last date the vehicle had a service at a depot.
Definition: vehicle_base.h:272
GRFConfig::GetName
const char * GetName() const
Get the name of this grf.
Definition: newgrf_config.cpp:105
GoodsEntry::GES_LAST_MONTH
@ GES_LAST_MONTH
Set when cargo was delivered for final delivery last month.
Definition: station_base.h:196
UpdateStationAcceptance
void UpdateStationAcceptance(Station *st, bool show_msg)
Update the acceptance for a station.
Definition: station_cmd.cpp:585
AirportTileSpec::animation
AnimationInfo animation
Information about the animation.
Definition: newgrf_airporttiles.h:67
news_func.h
RoadTypeInfo::strings
struct RoadTypeInfo::@42 strings
Strings associated with the rail type.
IsBridgeAbove
static bool IsBridgeAbove(TileIndex t)
checks if a bridge is set above the ground of this tile
Definition: bridge_map.h:45
AddAnimatedTile
void AddAnimatedTile(TileIndex tile)
Add the given tile to the animated tile table (if it does not exist on that table yet).
Definition: animated_tile.cpp:41
roadveh.h
INVALID_RAILTYPE
@ INVALID_RAILTYPE
Flag for invalid railtype.
Definition: rail_type.h:34
CmdBuildDock
CommandCost CmdBuildDock(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
Build a dock/haven.
Definition: station_cmd.cpp:2525
AllocaM
#define AllocaM(T, num_elements)
alloca() has to be called in the parent function, so define AllocaM() as a macro
Definition: alloc_func.hpp:132
TileDesc::road_speed
uint16 road_speed
Speed limit of road (bridges and track)
Definition: tile_cmd.h:66
AXIS_X
@ AXIS_X
The X axis.
Definition: direction_type.h:124
INDUSTRYLIFE_EXTRACTIVE
@ INDUSTRYLIFE_EXTRACTIVE
Like mines.
Definition: industrytype.h:30