Zoning: Add mode to show station catchment only where station window open.

pull/6/merge
Jonathan G Rennison 9 years ago
parent c120b810d1
commit 7f84a1c501

@ -4982,5 +4982,6 @@ STR_ZONING_NO_ZONING :Nothing
STR_ZONING_AUTHORITY :Authority
STR_ZONING_CAN_BUILD :Where I can't build
STR_ZONING_STA_CATCH :Station catchment
STR_ZONING_STA_CATCH_OPEN :Station catchment (window open)
STR_ZONING_BUL_UNSER :Unserved buildings
STR_ZONING_IND_UNSER :Unserved industries

@ -33,6 +33,7 @@
#include "town.h"
#include "linkgraph/linkgraph.h"
#include "zoom_func.h"
#include "zoning.h"
#include "widgets/station_widget.h"
@ -1307,10 +1308,12 @@ struct StationViewWindow : public Window {
this->sort_orders[0] = SO_ASCENDING;
this->SelectSortOrder((SortOrder)_settings_client.gui.station_gui_sort_order);
this->owner = Station::Get(window_number)->owner;
ZoningStationWindowOpenClose(Station::Get(window_number));
}
~StationViewWindow()
{
ZoningStationWindowOpenClose(Station::Get(window_number));
DeleteWindowById(WC_TRAINS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_TRAIN, this->owner, this->window_number).Pack(), false);
DeleteWindowById(WC_ROADVEH_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_ROAD, this->owner, this->window_number).Pack(), false);
DeleteWindowById(WC_SHIPS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_SHIP, this->owner, this->window_number).Pack(), false);

@ -23,6 +23,7 @@ enum ZoningEvaluationMode {
ZEM_AUTHORITY, ///< Check the local authority's opinion.
ZEM_CAN_BUILD, ///< Check wither or not the player can build.
ZEM_STA_CATCH, ///< Check catchment area for stations
ZEM_STA_CATCH_WIN, ///< Check catchment area for stations with their station windows open
ZEM_BUL_UNSER, ///< Check for unserved buildings
ZEM_IND_UNSER, ///< Check for unserved industries
};
@ -48,4 +49,9 @@ void ShowZoningToolbar();
void ZoningMarkDirtyStationCoverageArea(const Station *st);
inline void ZoningMarkDirtyStationCoverageArea(const Waypoint *st) { } // no-op
inline void ZoningStationWindowOpenClose(const Station *st)
{
if (_zoning.inner == ZEM_STA_CATCH_WIN || _zoning.outer == ZEM_STA_CATCH_WIN) ZoningMarkDirtyStationCoverageArea(st);
}
#endif /* ZONING_H */

@ -23,6 +23,7 @@
#include "station_func.h"
#include "station_map.h"
#include "town.h"
#include "window_func.h"
#include "zoning.h"
Zoning _zoning;
@ -82,9 +83,11 @@ bool IsAreaWithinAcceptanceZoneOfStation(TileArea area, Owner owner, StationFaci
* the owner of the stations
* @param StationFacility facility_mask
* one or more facilities in the mask must be present for a station to be used
* @param open_window_only
* only use stations which have their station window open
* @return true if a station is found
*/
bool IsTileWithinAcceptanceZoneOfStation(TileIndex tile, Owner owner, StationFacility facility_mask)
bool IsTileWithinAcceptanceZoneOfStation(TileIndex tile, Owner owner, StationFacility facility_mask, bool open_window_only)
{
int catchment = _settings_game.station.station_spread + (_settings_game.station.modified_catchment ? MAX_CATCHMENT : CA_UNMODIFIED);
@ -97,7 +100,9 @@ bool IsTileWithinAcceptanceZoneOfStation(TileIndex tile, Owner owner, StationFac
Rect rect = st->GetCatchmentRect();
if ((uint)rect.left <= TileX(tile) && TileX(tile) <= (uint)rect.right
&& (uint)rect.top <= TileY(tile) && TileY(tile) <= (uint)rect.bottom) {
return true;
if (!open_window_only || FindWindowById(WC_STATION_VIEW, st->index) != NULL) {
return true;
}
}
}
@ -182,10 +187,12 @@ SpriteID TileZoneCheckOpinionEvaluation(TileIndex tile, Owner owner)
*
* @param TileIndex tile
* @param Owner owner
* @param open_window_only
* only use stations which have their station window open
* @return black if within, light blue if only in acceptance zone
* and nothing if no nearby station.
*/
SpriteID TileZoneCheckStationCatchmentEvaluation(TileIndex tile, Owner owner)
SpriteID TileZoneCheckStationCatchmentEvaluation(TileIndex tile, Owner owner, bool open_window_only)
{
// Never on a station.
if (IsTileType(tile, MP_STATION)) {
@ -198,12 +205,14 @@ SpriteID TileZoneCheckStationCatchmentEvaluation(TileIndex tile, Owner owner)
for (Station * const *st_iter = stations.GetStations()->Begin(); st_iter != stations.GetStations()->End(); ++st_iter) {
const Station *st = *st_iter;
if (st->owner == owner) {
return SPR_ZONING_INNER_HIGHLIGHT_BLACK;
if (!open_window_only || FindWindowById(WC_STATION_VIEW, st->index) != NULL) {
return SPR_ZONING_INNER_HIGHLIGHT_BLACK;
}
}
}
// For accepted goods
if (IsTileWithinAcceptanceZoneOfStation(tile, owner, ~FACIL_NONE)) {
if (IsTileWithinAcceptanceZoneOfStation(tile, owner, ~FACIL_NONE, open_window_only)) {
return SPR_ZONING_INNER_HIGHLIGHT_LIGHT_BLUE;
}
@ -247,7 +256,7 @@ SpriteID TileZoneCheckUnservedBuildingsEvaluation(TileIndex tile, Owner owner)
}
// For accepted goods
if (IsTileWithinAcceptanceZoneOfStation(tile, owner, ~FACIL_NONE)) {
if (IsTileWithinAcceptanceZoneOfStation(tile, owner, ~FACIL_NONE, false)) {
return SPR_ZONING_INNER_HIGHLIGHT_ORANGE;
}
@ -301,12 +310,13 @@ SpriteID TileZoneCheckUnservedIndustriesEvaluation(TileIndex tile, Owner owner)
SpriteID TileZoningSpriteEvaluation(TileIndex tile, Owner owner, ZoningEvaluationMode ev_mode)
{
switch (ev_mode) {
case ZEM_CAN_BUILD: return TileZoneCheckBuildEvaluation(tile, owner);
case ZEM_AUTHORITY: return TileZoneCheckOpinionEvaluation(tile, owner);
case ZEM_STA_CATCH: return TileZoneCheckStationCatchmentEvaluation(tile, owner);
case ZEM_BUL_UNSER: return TileZoneCheckUnservedBuildingsEvaluation(tile, owner);
case ZEM_IND_UNSER: return TileZoneCheckUnservedIndustriesEvaluation(tile, owner);
default: return ZONING_INVALID_SPRITE_ID;
case ZEM_CAN_BUILD: return TileZoneCheckBuildEvaluation(tile, owner);
case ZEM_AUTHORITY: return TileZoneCheckOpinionEvaluation(tile, owner);
case ZEM_STA_CATCH: return TileZoneCheckStationCatchmentEvaluation(tile, owner, false);
case ZEM_STA_CATCH_WIN: return TileZoneCheckStationCatchmentEvaluation(tile, owner, true);
case ZEM_BUL_UNSER: return TileZoneCheckUnservedBuildingsEvaluation(tile, owner);
case ZEM_IND_UNSER: return TileZoneCheckUnservedIndustriesEvaluation(tile, owner);
default: return ZONING_INVALID_SPRITE_ID;
}
}
@ -335,6 +345,7 @@ static uint GetZoningModeDependantStationCoverageRadius(const Station *st, Zonin
{
switch (ev_mode) {
case ZEM_STA_CATCH: return st->GetCatchmentRadius();
case ZEM_STA_CATCH_WIN: return st->GetCatchmentRadius();
case ZEM_BUL_UNSER: return st->GetCatchmentRadius();
case ZEM_IND_UNSER: return st->GetCatchmentRadius() + 10; // this is to wholly update industries partially within the region
default: return 0;

@ -38,6 +38,7 @@ static const StringID _zone_type_strings[] = {
STR_ZONING_AUTHORITY,
STR_ZONING_CAN_BUILD,
STR_ZONING_STA_CATCH,
STR_ZONING_STA_CATCH_OPEN,
STR_ZONING_BUL_UNSER,
STR_ZONING_IND_UNSER,
INVALID_STRING_ID
@ -48,6 +49,7 @@ static const ZoningEvaluationMode _zone_type_modes[] = {
ZEM_AUTHORITY,
ZEM_CAN_BUILD,
ZEM_STA_CATCH,
ZEM_STA_CATCH_WIN,
ZEM_BUL_UNSER,
ZEM_IND_UNSER,
};

Loading…
Cancel
Save