(svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
authorrubidium
Sun, 06 Apr 2008 22:32:20 +0000
changeset 9342 ca61cbfca47a
parent 9341 00c8dbaaf0ee
child 9343 c30fd350dd8c
(svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
src/airport_gui.cpp
src/dock_gui.cpp
src/lang/english.txt
src/misc_gui.cpp
src/rail_gui.cpp
src/road_gui.cpp
src/station_cmd.cpp
src/station_gui.h
src/town_cmd.cpp
--- a/src/airport_gui.cpp	Sun Apr 06 21:54:22 2008 +0000
+++ b/src/airport_gui.cpp	Sun Apr 06 22:32:20 2008 +0000
@@ -186,8 +186,9 @@
 		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);
--- a/src/dock_gui.cpp	Sun Apr 06 21:54:22 2008 +0000
+++ b/src/dock_gui.cpp	Sun Apr 06 22:32:20 2008 +0000
@@ -254,8 +254,9 @@
 			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);
--- a/src/lang/english.txt	Sun Apr 06 21:54:22 2008 +0000
+++ b/src/lang/english.txt	Sun Apr 06 22:32:20 2008 +0000
@@ -18,6 +18,7 @@
 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
--- a/src/misc_gui.cpp	Sun Apr 06 21:54:22 2008 +0000
+++ b/src/misc_gui.cpp	Sun Apr 06 22:32:20 2008 +0000
@@ -763,12 +763,12 @@
 }
 
 
-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 @@
 			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 @@
 	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;
--- a/src/rail_gui.cpp	Sun Apr 06 21:54:22 2008 +0000
+++ b/src/rail_gui.cpp	Sun Apr 06 22:32:20 2008 +0000
@@ -936,8 +936,9 @@
 		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);
--- a/src/road_gui.cpp	Sun Apr 06 21:54:22 2008 +0000
+++ b/src/road_gui.cpp	Sun Apr 06 22:32:20 2008 +0000
@@ -882,7 +882,10 @@
 
 			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);
--- a/src/station_cmd.cpp	Sun Apr 06 21:54:22 2008 +0000
+++ b/src/station_cmd.cpp	Sun Apr 06 22:32:20 2008 +0000
@@ -465,12 +465,13 @@
 
 	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) {
--- a/src/station_gui.h	Sun Apr 06 21:54:22 2008 +0000
+++ b/src/station_gui.h	Sun Apr 06 22:32:20 2008 +0000
@@ -58,7 +58,7 @@
 	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;
--- a/src/town_cmd.cpp	Sun Apr 06 21:54:22 2008 +0000
+++ b/src/town_cmd.cpp	Sun Apr 06 22:32:20 2008 +0000
@@ -529,6 +529,33 @@
 	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 @@
 	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 */