diff options
author | smatz <smatz@openttd.org> | 2009-05-18 16:21:28 +0000 |
---|---|---|
committer | smatz <smatz@openttd.org> | 2009-05-18 16:21:28 +0000 |
commit | 8808f3beea881af5652716c883a21c8031b5e390 (patch) | |
tree | bc14c65d1e66c407b72d254fc926d105eea2f1e4 /src/ai | |
parent | 5fe906e14992f7a301ae94c357e80af076ab7a63 (diff) | |
download | openttd-8808f3beea881af5652716c883a21c8031b5e390.tar.xz |
(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
Diffstat (limited to 'src/ai')
-rw-r--r-- | src/ai/ai_core.cpp | 15 | ||||
-rw-r--r-- | src/ai/ai_gui.cpp | 9 | ||||
-rw-r--r-- | src/ai/api/ai_group.cpp | 3 | ||||
-rw-r--r-- | src/ai/api/ai_sign.cpp | 3 | ||||
-rw-r--r-- | src/ai/api/ai_station.cpp | 3 | ||||
-rw-r--r-- | src/ai/api/ai_vehicle.cpp | 5 | ||||
-rw-r--r-- | src/ai/api/ai_waypoint.cpp | 3 |
7 files changed, 24 insertions, 17 deletions
diff --git a/src/ai/ai_core.cpp b/src/ai/ai_core.cpp index df470d035..0eb4fe29d 100644 --- a/src/ai/ai_core.cpp +++ b/src/ai/ai_core.cpp @@ -74,7 +74,8 @@ * Effectively collecting garbage once every two months per AI. */ if ((AI::frame_counter & 255) == 0) { CompanyID cid = (CompanyID)GB(AI::frame_counter, 8, 4); - if (Company::IsValidID(cid) && !IsHumanCompany(cid)) Company::Get(cid)->ai_instance->CollectGarbage(); + Company *com = Company::GetIfValid(cid); + if (com != NULL && !IsHumanCompany(cid)) com->ai_instance->CollectGarbage(); } _current_company = OWNER_NONE; @@ -227,12 +228,12 @@ void CcAI(bool success, TileIndex tile, uint32 p1, uint32 p2) /* static */ void AI::Save(CompanyID company) { if (!_networking || _network_server) { - assert(Company::IsValidID(company)); - assert(Company::Get(company)->ai_instance != NULL); + Company *c = Company::GetIfValid(company); + assert(c != NULL && c->ai_instance != NULL); CompanyID old_company = _current_company; _current_company = company; - Company::Get(company)->ai_instance->Save(); + c->ai_instance->Save(); _current_company = old_company; } else { AIInstance::SaveEmpty(); @@ -242,12 +243,12 @@ void CcAI(bool success, TileIndex tile, uint32 p1, uint32 p2) /* static */ void AI::Load(CompanyID company, int version) { if (!_networking || _network_server) { - assert(Company::IsValidID(company)); - assert(Company::Get(company)->ai_instance != NULL); + Company *c = Company::GetIfValid(company); + assert(c != NULL && c->ai_instance != NULL); CompanyID old_company = _current_company; _current_company = company; - Company::Get(company)->ai_instance->Load(version); + c->ai_instance->Load(version); _current_company = old_company; } else { /* Read, but ignore, the load data */ diff --git a/src/ai/ai_gui.cpp b/src/ai/ai_gui.cpp index f0ffee121..3f4746a02 100644 --- a/src/ai/ai_gui.cpp +++ b/src/ai/ai_gui.cpp @@ -641,7 +641,8 @@ struct AIDebugWindow : public Window { { /* Disable the companies who are not active or not an AI */ for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) { - this->SetWidgetDisabledState(i + AID_WIDGET_COMPANY_BUTTON_START, !Company::IsValidID(i) || !Company::Get(i)->is_ai); + Company *c = Company::GetIfValid(i); + this->SetWidgetDisabledState(i + AID_WIDGET_COMPANY_BUTTON_START, c == NULL || !c->is_ai); } this->DisableWidget(AID_WIDGET_RELOAD_TOGGLE); @@ -669,7 +670,8 @@ struct AIDebugWindow : public Window { } for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) { - if (Company::IsValidID(i) && Company::Get(i)->is_ai) { + Company *c = Company::GetIfValid(i); + if (c != NULL && c->is_ai) { /* Lower the widget corresponding to this company. */ this->LowerWidget(i + AID_WIDGET_COMPANY_BUTTON_START); @@ -690,7 +692,8 @@ struct AIDebugWindow : public Window { /* Paint the company icons */ for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) { - if (!Company::IsValidID(i) || !Company::Get(i)->is_ai) { + Company *c = Company::GetIfValid(i); + if (c == NULL || !c->is_ai) { /* Check if we have the company as an active company */ if (!this->IsWidgetDisabled(i + AID_WIDGET_COMPANY_BUTTON_START)) { /* Bah, company gone :( */ diff --git a/src/ai/api/ai_group.cpp b/src/ai/api/ai_group.cpp index 6f4d25de9..cbcc8162b 100644 --- a/src/ai/api/ai_group.cpp +++ b/src/ai/api/ai_group.cpp @@ -16,7 +16,8 @@ /* static */ bool AIGroup::IsValidGroup(GroupID group_id) { - return ::Group::IsValidID(group_id) && ::Group::Get(group_id)->owner == _current_company; + const Group *g = ::Group::GetIfValid(group_id); + return g != NULL && g->owner == _current_company; } /* static */ AIGroup::GroupID AIGroup::CreateGroup(AIVehicle::VehicleType vehicle_type) diff --git a/src/ai/api/ai_sign.cpp b/src/ai/api/ai_sign.cpp index 349bf42a1..63bce8fdf 100644 --- a/src/ai/api/ai_sign.cpp +++ b/src/ai/api/ai_sign.cpp @@ -20,7 +20,8 @@ /* static */ bool AISign::IsValidSign(SignID sign_id) { - return ::Sign::IsValidID(sign_id) && ::Sign::Get(sign_id)->owner == _current_company; + const Sign *si = ::Sign::GetIfValid(sign_id); + return si != NULL && si->owner == _current_company; } /* static */ bool AISign::SetName(SignID sign_id, const char *name) diff --git a/src/ai/api/ai_station.cpp b/src/ai/api/ai_station.cpp index cc1167ddc..5d73b147b 100644 --- a/src/ai/api/ai_station.cpp +++ b/src/ai/api/ai_station.cpp @@ -17,7 +17,8 @@ /* static */ bool AIStation::IsValidStation(StationID station_id) { - return ::Station::IsValidID(station_id) && ::Station::Get(station_id)->owner == _current_company; + const Station *st = ::Station::GetIfValid(station_id); + return st != NULL && st->owner == _current_company; } /* static */ StationID AIStation::GetStationID(TileIndex tile) diff --git a/src/ai/api/ai_vehicle.cpp b/src/ai/api/ai_vehicle.cpp index 5d1579364..3e30601fe 100644 --- a/src/ai/api/ai_vehicle.cpp +++ b/src/ai/api/ai_vehicle.cpp @@ -19,9 +19,8 @@ /* static */ bool AIVehicle::IsValidVehicle(VehicleID vehicle_id) { - if (!::Vehicle::IsValidID(vehicle_id)) return false; - const Vehicle *v = ::Vehicle::Get(vehicle_id); - return v->owner == _current_company && (v->IsPrimaryVehicle() || (v->type == VEH_TRAIN && ::IsFreeWagon(v))); + const Vehicle *v = ::Vehicle::GetIfValid(vehicle_id); + return v != NULL && v->owner == _current_company && (v->IsPrimaryVehicle() || (v->type == VEH_TRAIN && ::IsFreeWagon(v))); } /* static */ int32 AIVehicle::GetNumWagons(VehicleID vehicle_id) diff --git a/src/ai/api/ai_waypoint.cpp b/src/ai/api/ai_waypoint.cpp index 0c1e3194b..b98274b63 100644 --- a/src/ai/api/ai_waypoint.cpp +++ b/src/ai/api/ai_waypoint.cpp @@ -14,7 +14,8 @@ /* static */ bool AIWaypoint::IsValidWaypoint(WaypointID waypoint_id) { - return ::Waypoint::IsValidID(waypoint_id) && ::Waypoint::Get(waypoint_id)->owner == _current_company; + const Waypoint *wp = ::Waypoint::GetIfValid(waypoint_id); + return wp != NULL && wp->owner == _current_company; } /* static */ WaypointID AIWaypoint::GetWaypointID(TileIndex tile) |