(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
This commit is contained in:
@@ -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 */
|
||||
|
@@ -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 :( */
|
||||
|
@@ -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)
|
||||
|
@@ -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)
|
||||
|
@@ -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)
|
||||
|
@@ -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)
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user