summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2008-04-06 22:32:20 +0000
committerrubidium <rubidium@openttd.org>2008-04-06 22:32:20 +0000
commitbd432258cbbf29a2d37154914aa2361bdc218fbb (patch)
tree397ef733d88fb8d1a2ef21941b6a693ad03870e0
parent949762fc65121d152d85f82902e2a67f95546db0 (diff)
downloadopenttd-bd432258cbbf29a2d37154914aa2361bdc218fbb.tar.xz
(svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
-rw-r--r--src/airport_gui.cpp5
-rw-r--r--src/dock_gui.cpp5
-rw-r--r--src/lang/english.txt1
-rw-r--r--src/misc_gui.cpp29
-rw-r--r--src/rail_gui.cpp5
-rw-r--r--src/road_gui.cpp5
-rw-r--r--src/station_cmd.cpp7
-rw-r--r--src/station_gui.h2
-rw-r--r--src/town_cmd.cpp29
9 files changed, 68 insertions, 20 deletions
diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp
index 85c839c00..b8a647705 100644
--- a/src/airport_gui.cpp
+++ b/src/airport_gui.cpp
@@ -186,8 +186,9 @@ static void BuildAirportPickerWndProc(Window *w, WindowEvent *e)
DrawWindowWidgets(w);
// strings such as 'Size' and 'Coverage Area'
// 'Coverage Area'
- int text_end = DrawStationCoverageAreaText(2, 206, SCT_ALL, rad) + 4;
- if (text_end > w->widget[6].bottom) {
+ int text_end = DrawStationCoverageAreaText(2, 206, SCT_ALL, rad, false);
+ text_end = DrawStationCoverageAreaText(2, text_end + 4, SCT_ALL, rad, true) + 4;
+ if (text_end != w->widget[6].bottom) {
SetWindowDirty(w);
ResizeWindowForWidget(w, 6, 0, text_end - w->widget[6].bottom);
SetWindowDirty(w);
diff --git a/src/dock_gui.cpp b/src/dock_gui.cpp
index 18e4a053f..32d7eb00e 100644
--- a/src/dock_gui.cpp
+++ b/src/dock_gui.cpp
@@ -254,8 +254,9 @@ static void BuildDockStationWndProc(Window *w, WindowEvent *e)
SetTileSelectSize(1, 1);
}
- int text_end = DrawStationCoverageAreaText(4, 50, SCT_ALL, rad) + 4;
- if (text_end > w->widget[2].bottom) {
+ int text_end = DrawStationCoverageAreaText(4, 50, SCT_ALL, rad, false);
+ text_end = DrawStationCoverageAreaText(4, text_end + 4, SCT_ALL, rad, true) + 4;
+ if (text_end != w->widget[2].bottom) {
SetWindowDirty(w);
ResizeWindowForWidget(w, 2, 0, text_end - w->widget[2].bottom);
SetWindowDirty(w);
diff --git a/src/lang/english.txt b/src/lang/english.txt
index b15148a57..66d541ba8 100644
--- a/src/lang/english.txt
+++ b/src/lang/english.txt
@@ -18,6 +18,7 @@ STR_0009 :{WHITE}{CARGO}
STR_EN_ROUTE_FROM :{YELLOW}({SHORTCARGO} en-route from {STATION})
STR_000C_ACCEPTS :{BLACK}Accepts: {WHITE}
STR_000D_ACCEPTS :{BLACK}Accepts: {GOLD}
+STR_SUPPLIES :{BLACK}Supplies: {GOLD}
STR_000E :
STR_000F_PASSENGERS :Passengers
STR_0010_COAL :Coal
diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp
index 59d3d779c..518c36864 100644
--- a/src/misc_gui.cpp
+++ b/src/misc_gui.cpp
@@ -763,12 +763,12 @@ void GuiShowTooltipsWithArgs(StringID str, uint paramcount, const uint64 params[
}
-static int DrawStationCoverageText(const AcceptedCargo accepts,
- int str_x, int str_y, StationCoverageType sct)
+static int DrawStationCoverageText(const AcceptedCargo cargo,
+ int str_x, int str_y, StationCoverageType sct, bool supplies)
{
bool first = true;
- char *b = InlineString(_userstring, STR_000D_ACCEPTS);
+ char *b = InlineString(_userstring, supplies ? STR_SUPPLIES : STR_000D_ACCEPTS);
for (CargoID i = 0; i < NUM_CARGO; i++) {
if (b >= lastof(_userstring) - (1 + 2 * 4)) break; // ',' or ' ' and two calls to Utf8Encode()
@@ -778,7 +778,7 @@ static int DrawStationCoverageText(const AcceptedCargo accepts,
case SCT_ALL: break;
default: NOT_REACHED();
}
- if (accepts[i] >= 8) {
+ if (cargo[i] >= (supplies ? 1 : 8)) {
if (first) {
first = false;
} else {
@@ -801,13 +801,26 @@ static int DrawStationCoverageText(const AcceptedCargo accepts,
return DrawStringMultiLine(str_x, str_y, STR_SPEC_USERSTRING, 144);
}
-int DrawStationCoverageAreaText(int sx, int sy, StationCoverageType sct, int rad)
+/**
+ * Calculates and draws the accepted or supplied cargo around the selected tile(s)
+ * @param sx x position where the string is to be drawn
+ * @param sy y position where the string is to be drawn
+ * @param sct which type of cargo is to be displayed (passengers/non-passengers)
+ * @param rad radius around selected tile(s) to be searched
+ * @param supplies if supplied cargos should be drawn, else accepted cargos
+ * @return Returns the y value below the string that was drawn
+ */
+int DrawStationCoverageAreaText(int sx, int sy, StationCoverageType sct, int rad, bool supplies)
{
TileIndex tile = TileVirtXY(_thd.pos.x, _thd.pos.y);
- AcceptedCargo accepts;
+ AcceptedCargo cargo;
if (tile < MapSize()) {
- GetAcceptanceAroundTiles(accepts, tile, _thd.size.x / TILE_SIZE, _thd.size.y / TILE_SIZE , rad);
- return sy + DrawStationCoverageText(accepts, sx, sy, sct);
+ if (supplies) {
+ GetProductionAroundTiles(cargo, tile, _thd.size.x / TILE_SIZE, _thd.size.y / TILE_SIZE , rad);
+ } else {
+ GetAcceptanceAroundTiles(cargo, tile, _thd.size.x / TILE_SIZE, _thd.size.y / TILE_SIZE , rad);
+ }
+ return sy + DrawStationCoverageText(cargo, sx, sy, sct, supplies);
}
return sy;
diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp
index f69ada958..fdfdf3364 100644
--- a/src/rail_gui.cpp
+++ b/src/rail_gui.cpp
@@ -936,8 +936,9 @@ static void StationBuildWndProc(Window *w, WindowEvent *e)
DrawStringCentered(74, 101 + y_offset, STR_3004_PLATFORM_LENGTH, TC_FROMSTRING);
DrawStringCentered(74, 141 + y_offset, STR_3066_COVERAGE_AREA_HIGHLIGHT, TC_FROMSTRING);
- int text_end = DrawStationCoverageAreaText(2, 166 + y_offset, SCT_ALL, rad) + 4;
- if (text_end > w->widget[BRSW_BACKGROUND].bottom) {
+ int text_end = DrawStationCoverageAreaText(2, 166 + y_offset, SCT_ALL, rad, false);
+ text_end = DrawStationCoverageAreaText(2, text_end + 4, SCT_ALL, rad, true) + 4;
+ if (text_end != w->widget[BRSW_BACKGROUND].bottom) {
SetWindowDirty(w);
ResizeWindowForWidget(w, BRSW_BACKGROUND, 0, text_end - w->widget[BRSW_BACKGROUND].bottom);
SetWindowDirty(w);
diff --git a/src/road_gui.cpp b/src/road_gui.cpp
index 31c1dad26..c483b3fa6 100644
--- a/src/road_gui.cpp
+++ b/src/road_gui.cpp
@@ -882,7 +882,10 @@ static void RoadStationPickerWndProc(Window *w, WindowEvent *e)
int text_end = DrawStationCoverageAreaText(2, 146,
(w->window_class == WC_BUS_STATION) ? SCT_PASSENGERS_ONLY : SCT_NON_PASSENGERS_ONLY,
- 3) + 4;
+ 3, false);
+ text_end = DrawStationCoverageAreaText(2, text_end + 4,
+ (w->window_class == WC_BUS_STATION) ? SCT_PASSENGERS_ONLY : SCT_NON_PASSENGERS_ONLY,
+ 3, true) + 4;
if (text_end > w->widget[BRSW_BACKGROUND].bottom) {
SetWindowDirty(w);
ResizeWindowForWidget(w, BRSW_BACKGROUND, 0, text_end - w->widget[BRSW_BACKGROUND].bottom);
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index fad63166c..555689149 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -465,12 +465,13 @@ void GetProductionAroundTiles(AcceptedCargo produced, TileIndex tile,
for (int yc = y1; yc != y2; yc++) {
for (int xc = x1; xc != x2; xc++) {
- if (!(IsInsideBS(xc, x, w) && IsInsideBS(yc, y, h))) {
- TileIndex tile = TileXY(xc, yc);
+ TileIndex tile = TileXY(xc, yc);
+ if (!IsTileType(tile, MP_STATION)) {
GetProducedCargoProc *gpc = _tile_type_procs[GetTileType(tile)]->get_produced_cargo_proc;
if (gpc != NULL) {
- CargoID cargos[2] = { CT_INVALID, CT_INVALID };
+ CargoID cargos[256]; // Required for CBID_HOUSE_PRODUCE_CARGO.
+ memset(cargos, CT_INVALID, 256);
gpc(tile, cargos);
for (uint i = 0; i < lengthof(cargos); ++i) {
diff --git a/src/station_gui.h b/src/station_gui.h
index ad1db88db..eddb7e249 100644
--- a/src/station_gui.h
+++ b/src/station_gui.h
@@ -58,7 +58,7 @@ enum StationCoverageType {
SCT_ALL
};
-int DrawStationCoverageAreaText(int sx, int sy, StationCoverageType sct, int rad);
+int DrawStationCoverageAreaText(int sx, int sy, StationCoverageType sct, int rad, bool supplies);
void CheckRedrawStationCoverage(const Window *w);
extern bool _station_show_coverage;
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index 350811bb9..eda83df20 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -529,6 +529,33 @@ static CommandCost ClearTile_Town(TileIndex tile, byte flags)
return cost;
}
+static void GetProducedCargo_Town(TileIndex tile, CargoID *b)
+{
+ HouseID house_id = GetHouseType(tile);
+ const HouseSpec *hs = GetHouseSpecs(house_id);
+ Town *t = GetTownByTile(tile);
+
+ if (HasBit(hs->callback_mask, CBM_HOUSE_PRODUCE_CARGO)) {
+ for (uint i = 0; i < 256; i++) {
+ uint16 callback = GetHouseCallback(CBID_HOUSE_PRODUCE_CARGO, i, 0, house_id, t, tile);
+
+ if (callback == CALLBACK_FAILED || callback == CALLBACK_HOUSEPRODCARGO_END) break;
+
+ CargoID cargo = GetCargoTranslation(GB(callback, 8, 7), hs->grffile);
+
+ if (cargo == CT_INVALID) continue;
+ *(b++) = cargo;
+ }
+ } else {
+ if (hs->population > 0) {
+ *(b++) = CT_PASSENGERS;
+ }
+ if (hs->mail_generation > 0) {
+ *(b++) = CT_MAIL;
+ }
+ }
+}
+
static void GetAcceptedCargo_Town(TileIndex tile, AcceptedCargo ac)
{
const HouseSpec *hs = GetHouseSpecs(GetHouseType(tile));
@@ -2529,7 +2556,7 @@ extern const TileTypeProcs _tile_type_town_procs = {
AnimateTile_Town, /* animate_tile_proc */
TileLoop_Town, /* tile_loop_clear */
ChangeTileOwner_Town, /* change_tile_owner_clear */
- NULL, /* get_produced_cargo_proc */
+ GetProducedCargo_Town, /* get_produced_cargo_proc */
NULL, /* vehicle_enter_tile_proc */
GetFoundation_Town, /* get_foundation_proc */
TerraformTile_Town, /* terraform_tile_proc */