From 5b0743d66bf73a1bbfdd95beca039283091d8d46 Mon Sep 17 00:00:00 2001 From: Celestar Date: Wed, 8 Dec 2004 15:46:13 +0000 Subject: [PATCH] (svn r979) Allow more realistically sized catchment areas --- ai.c | 35 ++++++++++++++++---- ai_new.c | 3 +- airport_gui.c | 21 ++++++++++-- dock_gui.c | 12 ++++++- gui.h | 2 +- lang/english.txt | 1 + macros.h | 10 ++++++ misc_gui.c | 4 +-- rail_gui.c | 12 +++++-- road_gui.c | 19 +++++++++-- settings.c | 2 ++ settings_gui.c | 2 ++ station.h | 17 ++++++++-- station_cmd.c | 85 ++++++++++++++++++++++++++++++++++++++---------- variables.h | 1 + 15 files changed, 188 insertions(+), 38 deletions(-) diff --git a/ai.c b/ai.c index 0ae06f759f..1d8d583f36 100644 --- a/ai.c +++ b/ai.c @@ -1530,6 +1530,7 @@ static bool AiCheckTrackResources(TileIndex tile, const AiDefaultBlockData *p, b uint values[NUM_CARGO]; int w,h; uint tile2; + int rad; for(;p->mode != 4;p++) if (p->mode == 1) { tile2 = TILE_ADD(tile, p->tileoffs); @@ -1538,11 +1539,18 @@ static bool AiCheckTrackResources(TileIndex tile, const AiDefaultBlockData *p, b h = ((p->attr>>4) & 7); if (p->attr&1) intswap(w, h); + + if (_patches.modified_catchment) { + rad = CA_TRAIN; + } else { + rad = 4; + } + if (cargo & 0x80) { - GetProductionAroundTiles(values, tile2, w, h); + GetProductionAroundTiles(values, tile2, w, h, rad); return values[cargo & 0x7F] != 0; } else { - GetAcceptanceAroundTiles(values, tile2, w, h); + GetAcceptanceAroundTiles(values, tile2, w, h, rad); if (!(values[cargo] & ~7)) return false; if (cargo != CT_MAIL) @@ -2472,16 +2480,24 @@ static void AiStateDeleteRailBlocks(Player *p) static bool AiCheckRoadResources(TileIndex tile, const AiDefaultBlockData *p, byte cargo) { uint values[NUM_CARGO]; + int rad; + + if (_patches.modified_catchment) { + rad = CA_TRUCK; //Same as CA_BUS at the moment? + } else { //change that at some point? + rad = 4; + } + for(;;p++) { if (p->mode == 4) { return true; } else if (p->mode == 1) { uint tile2 = TILE_ADD(tile, p->tileoffs); if (cargo & 0x80) { - GetProductionAroundTiles(values, tile2, 1, 1); + GetProductionAroundTiles(values, tile2, 1, 1, rad); return values[cargo & 0x7F] != 0; } else { - GetAcceptanceAroundTiles(values, tile2, 1, 1); + GetAcceptanceAroundTiles(values, tile2, 1, 1, rad); return (values[cargo]&~7) != 0; } } @@ -3336,16 +3352,23 @@ static bool AiCheckAirportResources(TileIndex tile, const AiDefaultBlockData *p, uint values[NUM_CARGO]; int w,h; uint tile2; + int rad; + + if (_patches.modified_catchment) { + rad = CA_AIR_LARGE; //I Have NFI what airport the + } else { //AI is going to build here + rad = 4; + } for(;p->mode==0;p++) { tile2 = TILE_ADD(tile, p->tileoffs); w = _airport_size_x[p->attr]; h = _airport_size_y[p->attr]; if (cargo & 0x80) { - GetProductionAroundTiles(values, tile2, w, h); + GetProductionAroundTiles(values, tile2, w, h, rad); return values[cargo & 0x7F] != 0; } else { - GetAcceptanceAroundTiles(values, tile2, w, h); + GetAcceptanceAroundTiles(values, tile2, w, h, rad); return values[cargo] >= 8; } } diff --git a/ai_new.c b/ai_new.c index 79c503b71e..ba335196a9 100644 --- a/ai_new.c +++ b/ai_new.c @@ -611,7 +611,8 @@ static void AiNew_State_FindStation(Player *p) { if (IS_TILETYPE(new_tile, MP_CLEAR) || IS_TILETYPE(new_tile, MP_TREES)) { // This tile we can build on! // Check acceptance - GetAcceptanceAroundTiles(accepts, new_tile, 1, 1); + // XXX - Get the catchment area + GetAcceptanceAroundTiles(accepts, new_tile, 1, 1, 4); // >> 3 == 0 means no cargo if (accepts[p->ainew.cargo] >> 3 == 0) continue; // See if we can build the station diff --git a/airport_gui.c b/airport_gui.c index 6c14f29e99..20e68b2ed7 100644 --- a/airport_gui.c +++ b/airport_gui.c @@ -134,6 +134,8 @@ void ShowBuildAirToolbar() static void BuildAirportPickerWndProc(Window *w, WindowEvent *e) { + int rad; + switch(e->event) { case WE_PAINT: { int sel; @@ -155,13 +157,28 @@ static void BuildAirportPickerWndProc(Window *w, WindowEvent *e) // select default the coverage area to 'Off' (8) w->click_state = ((1<<3) << sel) | ((1<<8) << _station_show_coverage); SetTileSelectSize(_airport_size_x[sel],_airport_size_y[sel]); - if (_station_show_coverage) SetTileSelectBigSize(-4, -4, 8, 8); + + if (_patches.modified_catchment) { + switch (sel) { + case AT_OILRIG: rad = CA_AIR_OILPAD; break; + case AT_HELIPORT: rad = CA_AIR_HELIPORT; break; + case AT_SMALL: rad = CA_AIR_SMALL; break; + case AT_LARGE: rad = CA_AIR_LARGE; break; + case AT_METROPOLITAN: rad = CA_AIR_METRO; break; + case AT_INTERNATIONAL: rad = CA_AIR_INTER; break; + } + } else { + rad = 4; + } + + + if (_station_show_coverage) SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad); DrawWindowWidgets(w); // strings such as 'Size' and 'Coverage Area' DrawStringCentered(74, 16, STR_305B_SIZE, 0); DrawStringCentered(74, 78, STR_3066_COVERAGE_AREA_HIGHLIGHT, 0); - DrawStationCoverageAreaText(2, 104, (uint)-1); + DrawStationCoverageAreaText(2, 104, (uint)-1, rad); break; } diff --git a/dock_gui.c b/dock_gui.c index b4228922d8..c9444c6e04 100644 --- a/dock_gui.c +++ b/dock_gui.c @@ -2,6 +2,7 @@ #include "ttd.h" #include "table/strings.h" #include "window.h" +#include "station.h" #include "gui.h" #include "viewport.h" #include "gfx.h" @@ -203,12 +204,21 @@ void ShowBuildDocksToolbar() static void BuildDockStationWndProc(Window *w, WindowEvent *e) { + int rad; + switch(e->event) { case WE_PAINT: { if (WP(w,def_d).close) return; DrawWindowWidgets(w); - DrawStationCoverageAreaText(2, 15, (uint)-1); + //Add some code for the coverage area eariler or later!! + if (_patches.modified_catchment) { + rad = CA_DOCK; + } else { + rad = 4; + } + + DrawStationCoverageAreaText(2, 15, (uint)-1, rad); } break; case WE_CLICK: { diff --git a/gui.h b/gui.h index 0e679086ca..da6f05f49c 100644 --- a/gui.h +++ b/gui.h @@ -78,7 +78,7 @@ void ShowPlayerCompany(int player); void ShowEstimatedCostOrIncome(int32 cost, int x, int y); void ShowErrorMessage(StringID msg_1, StringID msg_2, int x, int y); -void DrawStationCoverageAreaText(int sx, int sy, uint mask); +void DrawStationCoverageAreaText(int sx, int sy, uint mask,int rad); void CheckRedrawStationCoverage(Window *w); void ShowSmallMap(); diff --git a/lang/english.txt b/lang/english.txt index 2698535257..06e94ce510 100644 --- a/lang/english.txt +++ b/lang/english.txt @@ -973,6 +973,7 @@ STR_CONFIG_PATCHES_OFF :Off STR_CONFIG_PATCHES_ON :On STR_CONFIG_PATCHES_VEHICLESPEED :{LTBLUE}Show vehicle speed in status bar: {ORANGE}{STRING} STR_CONFIG_PATCHES_BUILDONSLOPES :{LTBLUE}Allow building on slopes and coasts: {ORANGE}{STRING} +STR_CONFIG_PATCHES_CATCHMENT :{LTBLUE}Allow more realistically sized catchment areas: {ORANGE}{STRING} STR_CONFIG_PATCHES_EXTRADYNAMITE :{LTBLUE}Allow removal of more town-owned roads, bridges, tunnels, etc: {ORANGE}{STRING} STR_CONFIG_PATCHES_MAMMOTHTRAINS :{LTBLUE}Enable building very long trains: {ORANGE}{STRING} STR_CONFIG_PATCHES_REALISTICACCEL :{LTBLUE}Enable realistic acceleration for trains: {ORANGE}{STRING} diff --git a/macros.h b/macros.h index 11d01d2b89..7517d6feda 100644 --- a/macros.h +++ b/macros.h @@ -173,6 +173,16 @@ static inline int FindFirstBit2x64(int value) #define CHANCE16R(a,b,r) ((uint16)(r=Random()) <= (uint16)((65536 * a) / b)) #define CHANCE16I(a,b,v) ((uint16)(v) <= (uint16)((65536 * a) / b)) +#define FIND_CATCHMENT_RADIUS(st,rad) \ + {\ + if (st->bus_tile || st->lorry_tile || (st->airport_tile && st->airport_type == AT_OILRIG)) rad = 3; \ + if (st->train_tile || (st->airport_tile && (st->airport_type == AT_HELIPORT || st->airport_type == AT_SMALL))) rad = 4; \ + if (st->dock_tile || (st->airport_tile && st->airport_type == AT_LARGE)) rad = 5; \ + if (st->airport_tile && st->airport_type == AT_METROPOLITAN) rad = 6; \ + if (st->airport_tile && st->airport_type == AT_INTERNATIONAL) rad = 8; } + + + #define BEGIN_TILE_LOOP(var,w,h,tile) \ {int h_cur = h; \ uint var = tile; \ diff --git a/misc_gui.c b/misc_gui.c index 64cebe85cd..cb21f33c94 100644 --- a/misc_gui.c +++ b/misc_gui.c @@ -640,12 +640,12 @@ static void DrawStationCoverageText(const uint *accepts, int str_x, int str_y, u DrawStringMultiLine(str_x, str_y, STR_SPEC_USERSTRING, 144); } -void DrawStationCoverageAreaText(int sx, int sy, uint mask) { +void DrawStationCoverageAreaText(int sx, int sy, uint mask, int rad) { int x = _thd.pos.x; int y = _thd.pos.y; uint accepts[NUM_CARGO]; if (x != -1) { - GetAcceptanceAroundTiles(accepts, TILE_FROM_XY(x,y), _thd.new_size.x >> 4, _thd.new_size.y >> 4); + GetAcceptanceAroundTiles(accepts, TILE_FROM_XY(x,y), _thd.new_size.x >> 4, _thd.new_size.y >> 4, rad); DrawStationCoverageText(accepts, sx, sy, mask); } } diff --git a/rail_gui.c b/rail_gui.c index 7fdde306ab..28f12caaca 100644 --- a/rail_gui.c +++ b/rail_gui.c @@ -849,6 +849,7 @@ static void HandleStationPlacement(uint start, uint end) } static void StationBuildWndProc(Window *w, WindowEvent *e) { + int rad; switch(e->event) { case WE_PAINT: { uint bits; @@ -876,8 +877,15 @@ static void StationBuildWndProc(Window *w, WindowEvent *e) { SetTileSelectSize(x, y); } + if (_patches.modified_catchment) { + rad = CA_TRAIN; + } else { + rad = 4; + } + + if (_station_show_coverage) - SetTileSelectBigSize(-4, -4, 8, 8); + SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad); DrawWindowWidgets(w); @@ -889,7 +897,7 @@ static void StationBuildWndProc(Window *w, WindowEvent *e) { DrawStringCentered(74, 101, STR_3004_PLATFORM_LENGTH, 0); DrawStringCentered(74, 141, STR_3066_COVERAGE_AREA_HIGHLIGHT, 0); - DrawStationCoverageAreaText(2, 166, (uint)-1); + DrawStationCoverageAreaText(2, 166, (uint)-1, rad); } break; case WE_CLICK: { diff --git a/road_gui.c b/road_gui.c index 734535311c..4368b1e402 100644 --- a/road_gui.c +++ b/road_gui.c @@ -7,6 +7,9 @@ #include "gfx.h" #include "sound.h" #include "command.h" +//needed for catchments +#include "station.h" + static void ShowBusStationPicker(); static void ShowTruckStationPicker(); @@ -400,6 +403,9 @@ static void ShowRoadDepotPicker() } static void RoadStationPickerWndProc(Window *w, WindowEvent *e) { + + int rad; + switch(e->event) { case WE_PAINT: { int image; @@ -409,8 +415,15 @@ static void RoadStationPickerWndProc(Window *w, WindowEvent *e) { DrawWindowWidgets(w); SetTileSelectSize(1, 1); + + if (_patches.modified_catchment) { + rad = CA_TRUCK; // = CA_BUS + } else { + rad = 4; + } + if (_station_show_coverage) - SetTileSelectBigSize(-4, -4, 8, 8); + SetTileSelectBigSize(-rad, -rad, 2*rad, 2*rad); image = (w->window_class == WC_BUS_STATION) ? 0x47 : 0x43; @@ -421,8 +434,8 @@ static void RoadStationPickerWndProc(Window *w, WindowEvent *e) { DrawStringCentered(70, 120, STR_3066_COVERAGE_AREA_HIGHLIGHT, 0); DrawStationCoverageAreaText(2, 146, - ((w->window_class == WC_BUS_STATION) ? (1<window_class == WC_BUS_STATION) ? (1<goods[type].last_speed) && // if last_speed is 0, no vehicle has been there. ((st->facilities & (byte)~FACIL_BUS_STOP)!=0 || type==CT_PASSENGERS) && // if we have other fac. than a bus stop, or the cargo is passengers ((st->facilities & (byte)~FACIL_TRUCK_STOP)!=0 || type!=CT_PASSENGERS)) { // if we have other fac. than a cargo bay or the cargo is not passengers + if (_patches.modified_catchment) { + FIND_CATCHMENT_RADIUS(st,rad) + x_min_prod = y_min_prod = 9; + x_max_prod = 8 + w_prod; + y_max_prod = 8 + h_prod; + + x_dist = min(w_cur - x_min_prod, x_max_prod - w_cur); + + if (w_cur < x_min_prod) { + x_dist = x_min_prod - w_cur; + } else { //save cycles + if (w_cur > x_max_prod) x_dist = w_cur - x_max_prod; + } + + y_dist = min(h_cur - y_min_prod, y_max_prod - h_cur); + if (h_cur < y_min_prod) { + y_dist = y_min_prod - h_cur; + } else { + if (h_cur > y_max_prod) y_dist = h_cur - y_max_prod; + } + + } else { + x_dist = y_dist = 0; + } + + if ( !(x_dist > rad) && !(y_dist > rad) ) { - around[i] = st_index; - around_ptr[i] = st; - } + around[i] = st_index; + around_ptr[i] = st; + } + } break; } else if (around[i] == st_index) break; } } - END_TILE_LOOP(cur_tile, w, h, tile - TILE_XY(4,4)) + END_TILE_LOOP(cur_tile, w, h, tile - TILE_XY(max_rad, max_rad)) /* no stations around at all? */ if (around[0] == 0xFF) diff --git a/variables.h b/variables.h index 61cba06e7f..ab84a427ce 100644 --- a/variables.h +++ b/variables.h @@ -82,6 +82,7 @@ VARDEF byte _saved_scrollpos_zoom; // ********* END OF SAVE REGION typedef struct Patches { + bool modified_catchment; //different-size catchment areas bool vehicle_speed; // show vehicle speed bool build_on_slopes; // allow building on slopes bool mammoth_trains; // allow very long trains