mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
This commit is contained in:
parent
d90a041230
commit
1bd5a29df5
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Reference in New Issue