diff options
author | rubidium <rubidium@openttd.org> | 2009-07-24 07:38:10 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-07-24 07:38:10 +0000 |
commit | 803cf87885aa8b6382996940d6418250889b678c (patch) | |
tree | 4ba316e76c8156146a7635f9694096ac30471a32 /src | |
parent | c1ffbc3bceafb9a0a47680dc28d010396924bc5c (diff) | |
download | openttd-803cf87885aa8b6382996940d6418250889b678c.tar.xz |
(svn r16934) -Codechange: introduce a simple helper function to check whether a station is pending deletion or not
Diffstat (limited to 'src')
-rw-r--r-- | src/base_station_base.h | 11 | ||||
-rw-r--r-- | src/station_cmd.cpp | 4 | ||||
-rw-r--r-- | src/terraform_gui.cpp | 2 | ||||
-rw-r--r-- | src/viewport.cpp | 2 | ||||
-rw-r--r-- | src/waypoint_cmd.cpp | 2 | ||||
-rw-r--r-- | src/waypoint_gui.cpp | 6 |
6 files changed, 19 insertions, 8 deletions
diff --git a/src/base_station_base.h b/src/base_station_base.h index a4cbb2fc0..407370260 100644 --- a/src/base_station_base.h +++ b/src/base_station_base.h @@ -94,6 +94,17 @@ struct BaseStation : StationPool::PoolItem<&_station_pool> { { return BaseStation::Get(GetStationIndex(tile)); } + + /** + * Check whether the base station currently is in use; in use means + * that it is not scheduled for deletion and that it still has some + * facilities left. + * @return true if still in use + */ + FORCEINLINE bool IsInUse() const + { + return (this->facilities & ~FACIL_WAYPOINT) != 0; + } }; #define FOR_ALL_BASE_STATIONS(var) FOR_ALL_ITEMS_FROM(BaseStation, station_index, var, 0) diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index c9fc22cba..5854ba489 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -2570,7 +2570,7 @@ static VehicleEnterTileStatus VehicleEnter_Station(Vehicle *v, TileIndex tile, i */ static bool StationHandleBigTick(BaseStation *st) { - if ((st->facilities & ~FACIL_WAYPOINT) == 0 && ++st->delete_ctr >= 8) { + if (!st->IsInUse() && ++st->delete_ctr >= 8) { delete st; return false; } @@ -2698,7 +2698,7 @@ static void UpdateStationRating(Station *st) /* called for every station each tick */ static void StationHandleSmallTick(BaseStation *st) { - if ((st->facilities & FACIL_WAYPOINT) != 0 || st->facilities == 0) return; + if ((st->facilities & FACIL_WAYPOINT) != 0 || !st->IsInUse()) return; byte b = st->delete_ctr + 1; if (b >= 185) b = 0; diff --git a/src/terraform_gui.cpp b/src/terraform_gui.cpp index c41b2ac56..026d663f6 100644 --- a/src/terraform_gui.cpp +++ b/src/terraform_gui.cpp @@ -638,7 +638,7 @@ static void ResetLandscapeConfirmationCallback(Window *w, bool confirmed) FOR_ALL_BASE_STATIONS(st) { /* There can be buoys, remove them */ if (IsBuoyTile(st->xy)) DoCommand(st->xy, 0, 0, DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR); - if ((st->facilities & ~FACIL_WAYPOINT) == 0) delete st; + if (!st->IsInUse()) delete st; } MarkWholeScreenDirty(); diff --git a/src/viewport.cpp b/src/viewport.cpp index 100d14c7b..29f1524f2 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -1220,7 +1220,7 @@ static void ViewportAddSigns(DrawPixelInfo *dpi) static void AddWaypoint(const Waypoint *wp, StringID str, uint16 width) { - AddStringToDraw(wp->sign.left + 1, wp->sign.top + 1, str, wp->index, 0, (wp->owner == OWNER_NONE || (wp->facilities & ~FACIL_WAYPOINT) == 0) ? 0xE : _company_colours[wp->owner], width); + AddStringToDraw(wp->sign.left + 1, wp->sign.top + 1, str, wp->index, 0, (wp->owner == OWNER_NONE || !wp->IsInUse()) ? 0xE : _company_colours[wp->owner], width); } diff --git a/src/waypoint_cmd.cpp b/src/waypoint_cmd.cpp index 7891d7aac..96dd5fc74 100644 --- a/src/waypoint_cmd.cpp +++ b/src/waypoint_cmd.cpp @@ -107,7 +107,7 @@ static Waypoint *FindDeletedWaypointCloseTo(TileIndex tile, StringID str) uint thres = 8; FOR_ALL_WAYPOINTS(wp) { - if ((wp->facilities & ~FACIL_WAYPOINT) == 0 && wp->string_id == str && (wp->owner == _current_company || wp->owner == OWNER_NONE)) { + if (!wp->IsInUse() && wp->string_id == str && (wp->owner == _current_company || wp->owner == OWNER_NONE)) { uint cur_dist = DistanceManhattan(tile, wp->xy); if (cur_dist < thres) { diff --git a/src/waypoint_gui.cpp b/src/waypoint_gui.cpp index bfe3f04e9..46478505c 100644 --- a/src/waypoint_gui.cpp +++ b/src/waypoint_gui.cpp @@ -59,9 +59,9 @@ public: virtual void OnPaint() { /* You can only change your own waypoints */ - this->SetWidgetDisabledState(WAYPVW_RENAME, (this->wp->facilities & ~FACIL_WAYPOINT) == 0 || (this->wp->owner != _local_company && this->wp->owner != OWNER_NONE)); - /* Disable the widget for waypoints with no owner (after company bankrupt) */ - this->SetWidgetDisabledState(WAYPVW_SHOW_VEHICLES, (this->wp->facilities & ~FACIL_WAYPOINT) == 0); + this->SetWidgetDisabledState(WAYPVW_RENAME, !this->wp->IsInUse() || (this->wp->owner != _local_company && this->wp->owner != OWNER_NONE)); + /* Disable the widget for waypoints with no use */ + this->SetWidgetDisabledState(WAYPVW_SHOW_VEHICLES, !this->wp->IsInUse()); SetDParam(0, this->wp->index); this->DrawWidgets(); |