Partially fix station cargo acceptance/supply (without update)
This commit is contained in:
@@ -2416,6 +2416,11 @@ void ResetActivePreview() {
|
||||
_ap.tiles = {};
|
||||
}
|
||||
|
||||
const up<Preview> &GetActivePreview() {
|
||||
return _ap.preview;
|
||||
}
|
||||
|
||||
|
||||
void UpdateActivePreview() {
|
||||
if (_ap.preview == nullptr) return;
|
||||
Point pt = GetTileBelowCursor();
|
||||
|
||||
@@ -60,6 +60,8 @@ void ResetRotateAutodetection();
|
||||
void ResetActivePreview();
|
||||
void SetActivePreview(up<Preview> &&preview);
|
||||
void UpdateActivePreview();
|
||||
const up<Preview> &GetActivePreview();
|
||||
|
||||
|
||||
bool HandlePlacePushButton(Window *w, WidgetID widget, up<Preview> preview);
|
||||
bool HandleMouseMove();
|
||||
|
||||
@@ -33,6 +33,8 @@
|
||||
#include "cm_type.hpp"
|
||||
#include "generated/cm_gen_commands.hpp"
|
||||
|
||||
#include <cstdio>
|
||||
#include <optional>
|
||||
#include <sstream>
|
||||
#include <unordered_set>
|
||||
|
||||
@@ -619,7 +621,11 @@ CargoArray GetProductionAroundTiles(TileIndex tile, int w, int h, int rad)
|
||||
return produced;
|
||||
}
|
||||
|
||||
std::string GetStationCoverageProductionText(TileIndex tile, int w, int h, int rad, StationCoverageType sct) {
|
||||
std::optional<std::string> GetStationCoverageAreaText(TileIndex tile, int w, int h, int rad, StationCoverageType sct, bool supplies) {
|
||||
auto sp = dynamic_cast<StationPreviewBase *>(GetActivePreview().get());
|
||||
if (sp != nullptr)
|
||||
return sp->GetStationCoverageAreaText(rad, sct, supplies);
|
||||
if (!supplies) return std::nullopt;
|
||||
auto production = citymania::GetProductionAroundTiles(tile, w, h, rad);
|
||||
|
||||
std::ostringstream s;
|
||||
@@ -909,7 +915,7 @@ up<Command> DockPreview::GetRemoveCommand() const {
|
||||
}
|
||||
|
||||
bool DockPreview::Execute(up<Command> cmd, bool remove_mode) const {
|
||||
cmd->post(&CcBuildDocks);
|
||||
return cmd->post(&CcBuildDocks);
|
||||
}
|
||||
|
||||
void DockPreview::AddPreviewTiles(HighlightMap &hlmap, SpriteID palette) const {
|
||||
@@ -1028,6 +1034,32 @@ void StationPreviewBase::HandleMouseRelease() {
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<std::string> StationPreviewBase::GetStationCoverageAreaText(int rad, StationCoverageType sct, bool supplies) {
|
||||
auto params = this->type->GetOverlayParams();
|
||||
if (params.area.tile == INVALID_TILE) return std::nullopt;
|
||||
|
||||
CargoArray cargoes;
|
||||
if (supplies) {
|
||||
cargoes = ::GetProductionAroundTiles(params.area.tile, params.area.w, params.area.h, params.radius);
|
||||
} else {
|
||||
cargoes = ::GetAcceptanceAroundTiles(params.area.tile, params.area.w, params.area.h, params.radius);
|
||||
}
|
||||
|
||||
CargoTypes cargo_mask = 0;
|
||||
/* Convert cargo counts to a set of cargo bits, and draw the result. */
|
||||
for (CargoID i = 0; i < NUM_CARGO; i++) {
|
||||
switch (sct) {
|
||||
case SCT_PASSENGERS_ONLY: if (!IsCargoInClass(i, CC_PASSENGERS)) continue; break;
|
||||
case SCT_NON_PASSENGERS_ONLY: if (IsCargoInClass(i, CC_PASSENGERS)) continue; break;
|
||||
case SCT_ALL: break;
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
if (cargoes[i] >= (supplies ? 1U : 8U)) SetBit(cargo_mask, i);
|
||||
}
|
||||
SetDParam(0, cargo_mask);
|
||||
return GetString(supplies ? STR_STATION_BUILD_SUPPLIES_CARGO : STR_STATION_BUILD_ACCEPTS_CARGO);
|
||||
}
|
||||
|
||||
std::vector<std::pair<SpriteID, std::string>> StationPreviewBase::GetOverlayData() {
|
||||
if (this->remove_mode) return {};
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ void MarkCoverageHighlightDirty();
|
||||
bool CheckRedrawStationCoverage();
|
||||
void AbortStationPlacement();
|
||||
|
||||
std::string GetStationCoverageProductionText(TileIndex tile, int w, int h, int rad, StationCoverageType sct);
|
||||
std::optional<std::string> GetStationCoverageAreaText(TileIndex tile, int w, int h, int rad, StationCoverageType sct, bool supplies);
|
||||
|
||||
bool CheckDriveThroughRoadStopDirection(TileArea area, RoadBits r);
|
||||
DiagDirection AutodetectRoadObjectDirection(TileIndex tile, Point pt, RoadType roadtype);
|
||||
@@ -160,6 +160,7 @@ public:
|
||||
void Update(Point pt, TileIndex tile) override;
|
||||
bool HandleMousePress() override;
|
||||
void HandleMouseRelease() override;
|
||||
std::optional<std::string> GetStationCoverageAreaText(int rad, StationCoverageType sct, bool supplies);
|
||||
std::vector<std::pair<SpriteID, std::string>> GetOverlayData();
|
||||
};
|
||||
|
||||
|
||||
@@ -681,11 +681,13 @@ struct BuildRailToolbarWindow : Window {
|
||||
if (!was_open || dragdrop != _settings_client.gui.station_dragdrop) {
|
||||
_settings_client.gui.station_dragdrop = dragdrop;
|
||||
if (citymania::HandleStationPlacePushButton(this, WID_RAT_BUILD_STATION, std::make_shared<citymania::RailStationPreview>()))
|
||||
// if (HandlePlacePushButton(this, WID_RAT_BUILD_STATION, SPR_CURSOR_BRIDGE, HT_RECT, DDSP_BUILD_STATION))
|
||||
ShowStationBuilder(this);
|
||||
}
|
||||
this->last_user_action = WID_RAT_BUILD_STATION;
|
||||
} else { /* button */
|
||||
if (citymania::HandleStationPlacePushButton(this, WID_RAT_BUILD_STATION, std::make_shared<citymania::RailStationPreview>())) {
|
||||
// if (HandlePlacePushButton(this, WID_RAT_BUILD_STATION, SPR_CURSOR_BRIDGE, HT_RECT, DDSP_BUILD_STATION)) {
|
||||
ShowStationBuilder(this);
|
||||
this->last_user_action = WID_RAT_BUILD_STATION;
|
||||
}
|
||||
|
||||
@@ -58,15 +58,16 @@
|
||||
int DrawStationCoverageAreaText(int left, int right, int top, StationCoverageType sct, int rad, bool supplies)
|
||||
{
|
||||
TileIndex tile = TileVirtXY(_thd.pos.x, _thd.pos.y);
|
||||
CargoTypes cargo_mask = 0;
|
||||
if (_thd.drawstyle == HT_RECT && tile < Map::Size()) {
|
||||
|
||||
/* CityMania code begin */
|
||||
if (supplies) {
|
||||
auto s = citymania::GetStationCoverageProductionText(tile, _thd.size.x / TILE_SIZE, _thd.size.y / TILE_SIZE, rad, sct);
|
||||
return DrawStringMultiLine(left, right, top, INT32_MAX, s.c_str());
|
||||
auto s = citymania::GetStationCoverageAreaText(tile, _thd.size.x / TILE_SIZE, _thd.size.y / TILE_SIZE, rad, sct, supplies);
|
||||
if (s.has_value()) {
|
||||
return DrawStringMultiLine(left, right, top, INT32_MAX, s.value());
|
||||
}
|
||||
/* CityMania code end */
|
||||
|
||||
CargoTypes cargo_mask = 0;
|
||||
if (_thd.drawstyle == HT_RECT && tile < Map::Size()) {
|
||||
CargoArray cargoes;
|
||||
if (supplies) {
|
||||
cargoes = GetProductionAroundTiles(tile, _thd.size.x / TILE_SIZE, _thd.size.y / TILE_SIZE, rad);
|
||||
|
||||
Reference in New Issue
Block a user