Changeset - r8846:96858dd9b6bd
[Not reviewed]
master
0 9 0
rubidium - 16 years ago 2008-04-06 22:32:20
rubidium@openttd.org
(svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
9 files changed with 69 insertions and 21 deletions:
0 comments (0 inline, 0 general)
src/airport_gui.cpp
Show inline comments
 
@@ -186,8 +186,9 @@ static void BuildAirportPickerWndProc(Wi
 
		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);
src/dock_gui.cpp
Show inline comments
 
@@ -254,8 +254,9 @@ static void BuildDockStationWndProc(Wind
 
			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);
src/lang/english.txt
Show inline comments
 
@@ -18,6 +18,7 @@ STR_0009                                
 
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
src/misc_gui.cpp
Show inline comments
 
@@ -763,12 +763,12 @@ void GuiShowTooltipsWithArgs(StringID st
 
}
 

	
 

	
 
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
 
			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
 
	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;
src/rail_gui.cpp
Show inline comments
 
@@ -936,8 +936,9 @@ static void StationBuildWndProc(Window *
 
		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);
src/road_gui.cpp
Show inline comments
 
@@ -882,7 +882,10 @@ static void RoadStationPickerWndProc(Win
 

	
 
			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);
src/station_cmd.cpp
Show inline comments
 
@@ -465,12 +465,13 @@ void GetProductionAroundTiles(AcceptedCa
 

	
 
	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) {
src/station_gui.h
Show inline comments
 
@@ -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;
src/town_cmd.cpp
Show inline comments
 
@@ -529,6 +529,33 @@ static CommandCost ClearTile_Town(TileIn
 
	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_to
 
	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 */
0 comments (0 inline, 0 general)