diff options
-rw-r--r-- | ai.c | 35 | ||||
-rw-r--r-- | ai_new.c | 3 | ||||
-rw-r--r-- | airport_gui.c | 21 | ||||
-rw-r--r-- | dock_gui.c | 12 | ||||
-rw-r--r-- | gui.h | 2 | ||||
-rw-r--r-- | lang/english.txt | 1 | ||||
-rw-r--r-- | macros.h | 10 | ||||
-rw-r--r-- | misc_gui.c | 4 | ||||
-rw-r--r-- | rail_gui.c | 12 | ||||
-rw-r--r-- | road_gui.c | 19 | ||||
-rw-r--r-- | settings.c | 2 | ||||
-rw-r--r-- | settings_gui.c | 2 | ||||
-rw-r--r-- | station.h | 17 | ||||
-rw-r--r-- | station_cmd.c | 87 | ||||
-rw-r--r-- | variables.h | 1 |
15 files changed, 189 insertions, 39 deletions
@@ -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; } } @@ -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 6c14f29e9..20e68b2ed 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 b4228922d..c9444c6e0 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: { @@ -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 269853525..06e94ce51 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} @@ -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 64cebe85c..cb21f33c9 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 7fdde306a..28f12caac 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 734535311..4368b1e40 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<<CT_PASSENGERS) : ~(1<<CT_PASSENGERS)) - ); + ((w->window_class == WC_BUS_STATION) ? (1<<CT_PASSENGERS) : ~(1<<CT_PASSENGERS)), + 3); } break; diff --git a/settings.c b/settings.c index f165e70a2..2212f06b9 100644 --- a/settings.c +++ b/settings.c @@ -795,6 +795,8 @@ const SettingDesc patch_settings[] = { {"join_stations", SDT_BOOL, (void*)true, &_patches.join_stations, NULL}, {"station_spread", SDT_UINT8, (void*)12, &_patches.station_spread, NULL}, {"full_load_any", SDT_BOOL, (void*)true, &_patches.full_load_any, NULL}, + {"modified_catchment", SDT_BOOL, (void*)true, &_patches.modified_catchment}, + {"inflation", SDT_BOOL, (void*)true, &_patches.inflation, NULL}, {"selectgoods", SDT_BOOL, (void*)true, &_patches.selectgoods, NULL}, diff --git a/settings_gui.c b/settings_gui.c index 328c20ab0..117f1eba8 100644 --- a/settings_gui.c +++ b/settings_gui.c @@ -640,6 +640,8 @@ static const PatchEntry _patches_stations[] = { {PE_BOOL, 0, STR_CONFIG_PATCHES_NONUNIFORM_STATIONS, &_patches.nonuniform_stations, 0, 0, 0, NULL}, {PE_UINT8, 0, STR_CONFIG_PATCHES_STATION_SPREAD, &_patches.station_spread, 4, 64, 1, NULL}, {PE_BOOL, 0, STR_CONFIG_PATCHES_SERVICEATHELIPAD, &_patches.serviceathelipad, 0, 0, 0, NULL}, + {PE_BOOL, 0, STR_CONFIG_PATCHES_CATCHMENT, &_patches.modified_catchment}, + }; static const PatchEntry _patches_economy[] = { @@ -73,6 +73,19 @@ enum { HVOT_BUOY = 1 << 6 }; +enum { + CA_BUS = 3, + CA_TRUCK = 3, + CA_AIR_OILPAD = 3, + CA_TRAIN = 4, + CA_AIR_HELIPORT = 4, + CA_AIR_SMALL = 4, + CA_AIR_LARGE = 5, + CA_DOCK = 5, + CA_AIR_METRO = 6, + CA_AIR_INTER = 8, +}; + void ModifyStationRatingAround(TileIndex tile, byte owner, int amount, uint radius); TileIndex GetStationTileForVehicle(Vehicle *v, Station *st); @@ -88,8 +101,8 @@ VARDEF bool _global_station_sort_dirty; #define FOR_ALL_STATIONS(st) for(st=_stations; st != endof(_stations); st++) -void GetProductionAroundTiles(uint *produced, uint tile, int w, int h); -void GetAcceptanceAroundTiles(uint *accepts, uint tile, int w, int h); +void GetProductionAroundTiles(uint *produced, uint tile, int w, int h, int rad); +void GetAcceptanceAroundTiles(uint *accepts, uint tile, int w, int h, int rad); uint GetStationPlatforms(Station *st, uint tile); diff --git a/station_cmd.c b/station_cmd.c index 57fa3c4ea..6c8bc987d 100644 --- a/station_cmd.c +++ b/station_cmd.c @@ -376,7 +376,7 @@ static void ShowRejectOrAcceptNews(Station *st, uint32 items, StringID msg) } // Get a list of the cargo types being produced around the tile. -void GetProductionAroundTiles(uint *produced, uint tile, int w, int h) +void GetProductionAroundTiles(uint *produced, uint tile, int w, int h, int rad) { int x,y; int x1,y1,x2,y2; @@ -390,11 +390,11 @@ void GetProductionAroundTiles(uint *produced, uint tile, int w, int h) // expand the region by 4 tiles on each side // while making sure that we remain inside the board. - x2 = min(x + w+4, TILE_X_MAX+1); - x1 = max(x-4, 0); + x2 = min(x + w + rad, TILE_X_MAX+1); + x1 = max(x-rad, 0); - y2 = min(y + h+4, TILE_Y_MAX+1); - y1 = max(y-4, 0); + y2 = min(y + h + rad, TILE_Y_MAX+1); + y1 = max(y-rad, 0); assert(x1 < x2); assert(y1 < y2); @@ -425,7 +425,7 @@ void GetProductionAroundTiles(uint *produced, uint tile, int w, int h) } // Get a list of the cargo types that are accepted around the tile. -void GetAcceptanceAroundTiles(uint *accepts, uint tile, int w, int h) +void GetAcceptanceAroundTiles(uint *accepts, uint tile, int w, int h, int rad) { int x,y; int x1,y1,x2,y2; @@ -438,10 +438,10 @@ void GetAcceptanceAroundTiles(uint *accepts, uint tile, int w, int h) // expand the region by 4 tiles on each side // while making sure that we remain inside the board. - x2 = min(x + w + 4, TILE_X_MAX+1); - y2 = min(y + h + 4, TILE_Y_MAX+1); - x1 = max(x-4, 0); - y1 = max(y-4, 0); + x2 = min(x + w + rad, TILE_X_MAX+1); + y2 = min(y + h + rad, TILE_Y_MAX+1); + x1 = max(x-rad, 0); + y1 = max(y-rad, 0); assert(x1 < x2); assert(y1 < y2); @@ -473,6 +473,7 @@ static void UpdateStationAcceptance(Station *st, bool show_msg) TileIndex span[1+1+2+2+1]; int i; int min_x, min_y, max_x, max_y; + int rad = 4; //Put this to surpress a compiler warning uint accepts[NUM_CARGO]; // Don't update acceptance for a buoy @@ -509,10 +510,15 @@ static void UpdateStationAcceptance(Station *st, bool show_msg) max_y = max(max_y,GET_TILE_Y(tile)); } } + if (_patches.modified_catchment) { + FIND_CATCHMENT_RADIUS(st,rad) + } else { + rad = 4; + } // And retrieve the acceptance. if (max_x != 0) { - GetAcceptanceAroundTiles(accepts, TILE_XY(min_x, min_y), max_x - min_x + 1, max_y-min_y+1); + GetAcceptanceAroundTiles(accepts, TILE_XY(min_x, min_y), max_x - min_x + 1, max_y-min_y+1,rad); } else { memset(accepts, 0, sizeof(accepts)); } @@ -2451,13 +2457,29 @@ uint MoveGoodsToStation(uint tile, int w, int h, int type, uint amount) uint best_rating, best_rating2; Station *st1, *st2; int t; + int rad=0; + int w_prod=0, h_prod=0; //width and height of the "producer" of the cargo + int x_min_prod, x_max_prod; //min and max coordinates of the producer + int y_min_prod, y_max_prod; //relative + int x_dist, y_dist; + int max_rad; + memset(around, 0xff, sizeof(around)); - w += 8; - h += 8; + if (_patches.modified_catchment) { + w_prod = w; + h_prod = h; + w += 16; + h += 16; + max_rad = 8; + } else { + w += 8; + h += 8; + max_rad = 4; + } - BEGIN_TILE_LOOP(cur_tile, w, h, tile - TILE_XY(4,4)) + BEGIN_TILE_LOOP(cur_tile, w, h, tile - TILE_XY(max_rad,max_rad)) cur_tile = TILE_MASK(cur_tile); if (IS_TILETYPE(cur_tile, MP_STATION)) { st_index = _map2[cur_tile]; @@ -2470,16 +2492,43 @@ uint MoveGoodsToStation(uint tile, int w, int h, int type, uint amount) (!_patches.selectgoods || st->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 - - around[i] = st_index; - around_ptr[i] = st; - } + 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; + } + } 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 61cba06e7..ab84a427c 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 |