summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2011-10-03 17:26:37 +0000
committerfrosch <frosch@openttd.org>2011-10-03 17:26:37 +0000
commitd071eefc54849a4dade4d71c8c8f7b0ca568deab (patch)
treea101fc4f2e9fa1ee7f52e635c3b1a03b8a5f1bc4 /src
parent23a2f23eb35cec39f7a31fe6b541c95a11e0102f (diff)
downloadopenttd-d071eefc54849a4dade4d71c8c8f7b0ca568deab.tar.xz
(svn r22985) -Feature: Display autoreplace status in group GUI.
Diffstat (limited to 'src')
-rw-r--r--src/autoreplace_cmd.cpp1
-rw-r--r--src/economy.cpp2
-rw-r--r--src/group.h10
-rw-r--r--src/group_cmd.cpp38
-rw-r--r--src/group_gui.cpp25
-rw-r--r--src/table/sprites.h4
-rw-r--r--src/vehicle.cpp1
-rw-r--r--src/vehicle_cmd.cpp1
8 files changed, 78 insertions, 4 deletions
diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp
index 7a5c4c723..67387130f 100644
--- a/src/autoreplace_cmd.cpp
+++ b/src/autoreplace_cmd.cpp
@@ -754,6 +754,7 @@ CommandCost CmdSetAutoReplace(TileIndex tile, DoCommandFlag flags, uint32 p1, ui
cost = RemoveEngineReplacementForCompany(c, old_engine_type, id_g, flags);
}
+ if (flags & DC_EXEC) GroupStatistics::UpdateAutoreplace(_current_company);
if ((flags & DC_EXEC) && IsLocalCompany()) InvalidateAutoreplaceWindow(old_engine_type, id_g);
return cost;
diff --git a/src/economy.cpp b/src/economy.cpp
index edc84dc76..92babd802 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -419,6 +419,8 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
}
}
}
+
+ if (new_owner != INVALID_OWNER) GroupStatistics::UpdateAutoreplace(new_owner);
}
/* Change ownership of tiles */
diff --git a/src/group.h b/src/group.h
index cfc1dd578..7672f3862 100644
--- a/src/group.h
+++ b/src/group.h
@@ -26,6 +26,9 @@ struct GroupStatistics {
uint16 num_vehicle; ///< Number of vehicles.
uint16 *num_engines; ///< Caches the number of engines of each type the company owns.
+ bool autoreplace_defined; ///< Are any autoreplace rules set?
+ bool autoreplace_finished; ///< Have all autoreplacement finished?
+
uint16 num_profit_vehicle; ///< Number of vehicles considered for profit statistics;
Money profit_last_year; ///< Sum of profits for all vehicles.
@@ -40,6 +43,12 @@ struct GroupStatistics {
this->profit_last_year = 0;
}
+ void ClearAutoreplace()
+ {
+ this->autoreplace_defined = false;
+ this->autoreplace_finished = false;
+ }
+
static GroupStatistics &Get(CompanyID company, GroupID id_g, VehicleType type);
static GroupStatistics &Get(const Vehicle *v);
static GroupStatistics &GetAllGroup(const Vehicle *v);
@@ -50,6 +59,7 @@ struct GroupStatistics {
static void UpdateProfits();
static void UpdateAfterLoad();
+ static void UpdateAutoreplace(CompanyID company);
};
/** Group data. */
diff --git a/src/group_cmd.cpp b/src/group_cmd.cpp
index 0656d98ed..9ae39025c 100644
--- a/src/group_cmd.cpp
+++ b/src/group_cmd.cpp
@@ -125,6 +125,10 @@ void GroupStatistics::Clear()
GroupStatistics::CountEngine(v, 1);
if (v->IsPrimaryVehicle()) GroupStatistics::CountVehicle(v, 1);
}
+
+ FOR_ALL_COMPANIES(c) {
+ GroupStatistics::UpdateAutoreplace(c->index);
+ }
}
/**
@@ -203,6 +207,37 @@ void GroupStatistics::Clear()
}
/**
+ * Update autoreplace_defined and autoreplace_finished of all statistics of a company.
+ * @param company Company to update statistics for.
+ */
+/* static */ void GroupStatistics::UpdateAutoreplace(CompanyID company)
+{
+ /* Set up the engine count for all companies */
+ Company *c = Company::Get(company);
+ for (VehicleType type = VEH_BEGIN; type < VEH_COMPANY_END; type++) {
+ c->group_all[type].ClearAutoreplace();
+ c->group_default[type].ClearAutoreplace();
+ }
+
+ /* Recalculate */
+ Group *g;
+ FOR_ALL_GROUPS(g) {
+ if (g->owner != company) continue;
+ g->statistics.ClearAutoreplace();
+ }
+
+ for (EngineRenewList erl = c->engine_renew_list; erl != NULL; erl = erl->next) {
+ const Engine *e = Engine::Get(erl->from);
+ GroupStatistics &stats = GroupStatistics::Get(company, erl->group_id, e->type);
+ if (!stats.autoreplace_defined) {
+ stats.autoreplace_defined = true;
+ stats.autoreplace_finished = true;
+ }
+ if (stats.num_engines[erl->from] > 0) stats.autoreplace_finished = false;
+ }
+}
+
+/**
* Update the num engines of a groupID. Decrease the old one and increase the new one
* @note called in SetTrainGroupID and UpdateTrainGroupID
* @param v Vehicle we have to update
@@ -400,6 +435,7 @@ CommandCost CmdAddVehicleGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, u
}
GroupStatistics::CountVehicle(v, 1);
+ GroupStatistics::UpdateAutoreplace(v->owner);
/* Update the Replace Vehicle Windows */
SetWindowDirty(WC_REPLACE_VEHICLE, v->type);
@@ -544,6 +580,7 @@ void SetTrainGroupID(Train *v, GroupID new_g)
}
/* Update the Replace Vehicle Windows */
+ GroupStatistics::UpdateAutoreplace(v->owner);
SetWindowDirty(WC_REPLACE_VEHICLE, VEH_TRAIN);
}
@@ -567,6 +604,7 @@ void UpdateTrainGroupID(Train *v)
}
/* Update the Replace Vehicle Windows */
+ GroupStatistics::UpdateAutoreplace(v->owner);
SetWindowDirty(WC_REPLACE_VEHICLE, VEH_TRAIN);
}
diff --git a/src/group_gui.cpp b/src/group_gui.cpp
index 5a0a46b7f..058e327a9 100644
--- a/src/group_gui.cpp
+++ b/src/group_gui.cpp
@@ -117,6 +117,8 @@ private:
/* Columns in the group list */
enum ListColumns {
VGC_NAME, ///< Group name.
+ VGC_PROTECT, ///< Autoreplace protect icon.
+ VGC_AUTOREPLACE, ///< Autoreplace active icon.
VGC_PROFIT, ///< Profit icon.
VGC_NUMBER, ///< Number of vehicles in the group.
@@ -186,6 +188,12 @@ private:
this->column_size[VGC_NAME].width = max(170u, this->column_size[VGC_NAME].width);
this->tiny_step_height = this->column_size[VGC_NAME].height;
+ this->column_size[VGC_PROTECT] = GetSpriteSize(SPR_GROUP_REPLACE_PROTECT);
+ this->tiny_step_height = max(this->tiny_step_height, this->column_size[VGC_PROTECT].height);
+
+ this->column_size[VGC_AUTOREPLACE] = GetSpriteSize(SPR_GROUP_REPLACE_ACTIVE);
+ this->tiny_step_height = max(this->tiny_step_height, this->column_size[VGC_AUTOREPLACE].height);
+
this->column_size[VGC_PROFIT].width = 0;
this->column_size[VGC_PROFIT].height = 0;
static const SpriteID profit_sprites[] = {SPR_PROFIT_NA, SPR_PROFIT_NEGATIVE, SPR_PROFIT_SOME, SPR_PROFIT_LOT};
@@ -203,6 +211,8 @@ private:
return WD_FRAMERECT_LEFT + 8 +
this->column_size[VGC_NAME].width + 8 +
+ this->column_size[VGC_PROTECT].width + 2 +
+ this->column_size[VGC_AUTOREPLACE].width + 2 +
this->column_size[VGC_PROFIT].width + 2 +
this->column_size[VGC_NUMBER].width + 2 +
WD_FRAMERECT_RIGHT;
@@ -214,8 +224,9 @@ private:
* @param left Left of the row.
* @param right Right of the row.
* @param g_id Group to list.
+ * @param protection Whether autoreplace protection is set.
*/
- void DrawGroupInfo(int y, int left, int right, GroupID g_id) const
+ void DrawGroupInfo(int y, int left, int right, GroupID g_id, bool protection = false) const
{
/* draw the selected group in white, else we draw it in black */
TextColour colour = g_id == this->vli.index ? TC_WHITE : TC_BLACK;
@@ -235,8 +246,16 @@ private:
int x = rtl ? right - WD_FRAMERECT_RIGHT - 8 - this->column_size[VGC_NAME].width + 1 : left + WD_FRAMERECT_LEFT + 8;
DrawString(x, x + this->column_size[VGC_NAME].width - 1, y + (this->tiny_step_height - this->column_size[VGC_NAME].height) / 2, str, colour);
+ /* draw autoreplace protection */
+ x = rtl ? x - 8 - this->column_size[VGC_PROTECT].width : x + 8 + this->column_size[VGC_NAME].width;
+ if (protection) DrawSprite(SPR_GROUP_REPLACE_PROTECT, PAL_NONE, x, y + (this->tiny_step_height - this->column_size[VGC_PROTECT].height) / 2);
+
+ /* draw autoreplace status */
+ x = rtl ? x - 2 - this->column_size[VGC_AUTOREPLACE].width : x + 2 + this->column_size[VGC_PROTECT].width;
+ if (stats.autoreplace_defined) DrawSprite(SPR_GROUP_REPLACE_ACTIVE, stats.autoreplace_finished ? PALETTE_CRASH : PAL_NONE, x, y + (this->tiny_step_height - this->column_size[VGC_AUTOREPLACE].height) / 2);
+
/* draw the profit icon */
- x = rtl ? x - 8 - this->column_size[VGC_PROFIT].width : x + 8 + this->column_size[VGC_NAME].width;
+ x = rtl ? x - 2 - this->column_size[VGC_PROFIT].width : x + 2 + this->column_size[VGC_AUTOREPLACE].width;
SpriteID spr;
if (stats.num_profit_vehicle == 0) {
spr = SPR_PROFIT_NA;
@@ -489,7 +508,7 @@ public:
assert(g->owner == this->owner);
- DrawGroupInfo(y1, r.left, r.right, g->index);
+ DrawGroupInfo(y1, r.left, r.right, g->index, g->replace_protection);
y1 += this->tiny_step_height;
}
diff --git a/src/table/sprites.h b/src/table/sprites.h
index 65988b568..39012f1ac 100644
--- a/src/table/sprites.h
+++ b/src/table/sprites.h
@@ -56,7 +56,7 @@ static const SpriteID SPR_LARGE_SMALL_WINDOW = 682;
/** Extra graphic spritenumbers */
static const SpriteID SPR_OPENTTD_BASE = 4896;
-static const uint16 OPENTTD_SPRITE_COUNT = 160;
+static const uint16 OPENTTD_SPRITE_COUNT = 162;
/* Halftile-selection sprites */
static const SpriteID SPR_HALFTILE_SELECTION_FLAT = SPR_OPENTTD_BASE;
@@ -123,6 +123,8 @@ static const SpriteID SPR_PROFIT_LOT = SPR_OPENTTD_BASE + 157;
static const SpriteID SPR_UNREAD_NEWS = SPR_OPENTTD_BASE + 158;
static const SpriteID SPR_EXCLUSIVE_TRANSPORT = SPR_OPENTTD_BASE + 159;
+static const SpriteID SPR_GROUP_REPLACE_PROTECT = SPR_OPENTTD_BASE + 160;
+static const SpriteID SPR_GROUP_REPLACE_ACTIVE = SPR_OPENTTD_BASE + 161;
static const SpriteID SPR_GROUP_CREATE_TRAIN = SPR_OPENTTD_BASE + 114;
static const SpriteID SPR_GROUP_CREATE_ROADVEH = SPR_OPENTTD_BASE + 115;
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index dce61e239..4565fc3a0 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -680,6 +680,7 @@ void Vehicle::PreDestructor()
if (this->IsEngineCountable()) {
GroupStatistics::CountEngine(this, -1);
if (this->IsPrimaryVehicle()) GroupStatistics::CountVehicle(this, -1);
+ GroupStatistics::UpdateAutoreplace(this->owner);
if (this->owner == _local_company) InvalidateAutoreplaceWindow(this->engine_type, this->group_id);
DeleteGroupHighlightOfVehicle(this);
diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp
index 41e5e4309..22ebef2fb 100644
--- a/src/vehicle_cmd.cpp
+++ b/src/vehicle_cmd.cpp
@@ -143,6 +143,7 @@ CommandCost CmdBuildVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
}
GroupStatistics::CountEngine(v, 1);
+ GroupStatistics::UpdateAutoreplace(_current_company);
if (v->IsPrimaryVehicle()) {
GroupStatistics::CountVehicle(v, 1);