summaryrefslogtreecommitdiff
path: root/src/ai
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2009-06-10 22:05:01 +0000
committersmatz <smatz@openttd.org>2009-06-10 22:05:01 +0000
commitbea3fe2b8b2352d471149a4c914f93c58aa11b83 (patch)
tree69bd9a4b24333a7da3f2f3d11af4aafff5c92583 /src/ai
parentbc7e9514d247581e085b80a71dabbd6e635e5ded (diff)
downloadopenttd-bea3fe2b8b2352d471149a4c914f93c58aa11b83.tar.xz
(svn r16559) -Codechange: introduce Company::IsValidAiID() and Company::IsValidHumanID(), don't use IsHumanCompany() where possible
Diffstat (limited to 'src/ai')
-rw-r--r--src/ai/ai.hpp2
-rw-r--r--src/ai/ai_core.cpp9
-rw-r--r--src/ai/ai_gui.cpp17
-rw-r--r--src/ai/ai_instance.cpp2
4 files changed, 14 insertions, 16 deletions
diff --git a/src/ai/ai.hpp b/src/ai/ai.hpp
index 7837edee0..267a4b6d1 100644
--- a/src/ai/ai.hpp
+++ b/src/ai/ai.hpp
@@ -54,7 +54,7 @@ public:
/**
* Stop a company to be controlled by an AI.
* @param company The company from which the AI needs to detach.
- * @pre !IsHumanCompany(company).
+ * @pre Company::IsValidAiID(company)
*/
static void Stop(CompanyID company);
diff --git a/src/ai/ai_core.cpp b/src/ai/ai_core.cpp
index 0eb4fe29d..b89d2064f 100644
--- a/src/ai/ai_core.cpp
+++ b/src/ai/ai_core.cpp
@@ -64,7 +64,7 @@
const Company *c;
FOR_ALL_COMPANIES(c) {
- if (!IsHumanCompany(c->index)) {
+ if (c->is_ai) {
_current_company = c->index;
c->ai_instance->GameLoop();
}
@@ -74,8 +74,7 @@
* Effectively collecting garbage once every two months per AI. */
if ((AI::frame_counter & 255) == 0) {
CompanyID cid = (CompanyID)GB(AI::frame_counter, 8, 4);
- Company *com = Company::GetIfValid(cid);
- if (com != NULL && !IsHumanCompany(cid)) com->ai_instance->CollectGarbage();
+ if (Company::IsValidAiID(cid)) Company::Get(cid)->ai_instance->CollectGarbage();
}
_current_company = OWNER_NONE;
@@ -109,7 +108,7 @@
const Company *c;
FOR_ALL_COMPANIES(c) {
- if (!IsHumanCompany(c->index)) AI::Stop(c->index);
+ if (c->is_ai) AI::Stop(c->index);
}
}
@@ -179,7 +178,7 @@
}
/* Only AIs can have an event-queue */
- if (!Company::IsValidID(company) || IsHumanCompany(company)) {
+ if (!Company::IsValidAiID(company)) {
event->Release();
return;
}
diff --git a/src/ai/ai_gui.cpp b/src/ai/ai_gui.cpp
index bf12ce6ba..33585059e 100644
--- a/src/ai/ai_gui.cpp
+++ b/src/ai/ai_gui.cpp
@@ -642,8 +642,7 @@ struct AIDebugWindow : public Window {
{
/* Disable the companies who are not active or not an AI */
for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
- Company *c = Company::GetIfValid(i);
- this->SetWidgetDisabledState(i + AID_WIDGET_COMPANY_BUTTON_START, c == NULL || !c->is_ai);
+ this->SetWidgetDisabledState(i + AID_WIDGET_COMPANY_BUTTON_START, !Company::IsValidAiID(i));
}
this->DisableWidget(AID_WIDGET_RELOAD_TOGGLE);
@@ -661,7 +660,7 @@ struct AIDebugWindow : public Window {
virtual void OnPaint()
{
/* Check if the currently selected company is still active. */
- if (ai_debug_company == INVALID_COMPANY || !Company::IsValidID(ai_debug_company) || !Company::Get(ai_debug_company)->is_ai) {
+ if (ai_debug_company == INVALID_COMPANY || !Company::IsValidAiID(ai_debug_company)) {
if (ai_debug_company != INVALID_COMPANY) {
/* Raise and disable the widget for the previous selection. */
this->RaiseWidget(ai_debug_company + AID_WIDGET_COMPANY_BUTTON_START);
@@ -670,13 +669,13 @@ struct AIDebugWindow : public Window {
ai_debug_company = INVALID_COMPANY;
}
- for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
- Company *c = Company::GetIfValid(i);
- if (c != NULL && c->is_ai) {
+ const Company *c;
+ FOR_ALL_COMPANIES(c) {
+ if (c->is_ai) {
/* Lower the widget corresponding to this company. */
- this->LowerWidget(i + AID_WIDGET_COMPANY_BUTTON_START);
+ this->LowerWidget(c->index + AID_WIDGET_COMPANY_BUTTON_START);
- ai_debug_company = i;
+ ai_debug_company = c->index;
break;
}
}
@@ -696,7 +695,7 @@ struct AIDebugWindow : public Window {
/* Background is grey by default, will be changed to red for dead AIs */
this->widget[i + AID_WIDGET_COMPANY_BUTTON_START].colour = COLOUR_GREY;
- Company *c = Company::GetIfValid(i);
+ const 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)) {
diff --git a/src/ai/ai_instance.cpp b/src/ai/ai_instance.cpp
index 6d264abea..8c70cf177 100644
--- a/src/ai/ai_instance.cpp
+++ b/src/ai/ai_instance.cpp
@@ -363,7 +363,7 @@ void AIInstance::CollectGarbage()
/* static */ AIStorage *AIInstance::GetStorage()
{
- assert(Company::IsValidID(_current_company) && !IsHumanCompany(_current_company));
+ assert(Company::IsValidAiID(_current_company));
return Company::Get(_current_company)->ai_instance->storage;
}