Compare commits

...

3 Commits

Author SHA1 Message Date
Peter Nelson f5e4bd1ed7 Fix #15826: Exclude allow any/all options for AI companies (#15834) 2026-07-09 00:20:07 +00:00
Rubidium 5303aa6516 Codechange: use const for writing savegame data 2026-07-09 02:01:13 +02:00
Peter Nelson 5403257dca Codechange: Don't calculate bridge height difference twice (#15831) 2026-07-08 22:23:55 +01:00
6 changed files with 19 additions and 21 deletions
+1 -1
View File
@@ -1685,7 +1685,7 @@ private:
{
DropDownList list;
if (_network_server) list.push_back(MakeDropDownListStringItem(STR_NETWORK_CLIENT_LIST_ADMIN_COMPANY_RESET, to_underlying(DropDownAction::AdminResetCompany), NetworkCompanyHasClients(company_id)));
if (const Company *c = Company::GetIfValid(company_id); c != nullptr) {
if (const Company *c = Company::GetIfValid(company_id); c != nullptr && !c->is_ai) {
list.push_back(MakeDropDownListStringItem(STR_NETWORK_CLIENT_LIST_ADMIN_COMPANY_ALLOW_ANY, to_underlying(DropDownAction::CompanyAllowAny), c->allow_any));
list.push_back(MakeDropDownListStringItem(STR_NETWORK_CLIENT_LIST_ADMIN_COMPANY_ALLOW_LISTED, to_underlying(DropDownAction::CompanyAllowListed), !c->allow_any));
}
+1 -1
View File
@@ -141,7 +141,7 @@ struct PacketWriter : SaveFilter {
return false;
}
void Write(uint8_t *buf, size_t size) override
void Write(const uint8_t *buf, size_t size) override
{
std::lock_guard<std::mutex> lock(this->mutex);
+8 -8
View File
@@ -2429,7 +2429,7 @@ struct FileWriter : SaveFilter {
this->Finish();
}
void Write(uint8_t *buf, size_t size) override
void Write(const uint8_t *buf, size_t size) override
{
/* We're in the process of shutting down, i.e. in "failure" mode. */
if (!this->file.has_value()) return;
@@ -2513,7 +2513,7 @@ struct LZOSaveFilter : SaveFilter {
if (lzo_init() != LZO_E_OK) SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR, "cannot initialize compressor");
}
void Write(uint8_t *buf, size_t size) override
void Write(const uint8_t *buf, size_t size) override
{
const lzo_bytep in = buf;
/* Buffer size is from the LZO docs plus the chunk header size. */
@@ -2568,7 +2568,7 @@ struct NoCompSaveFilter : SaveFilter {
{
}
void Write(uint8_t *buf, size_t size) override
void Write(const uint8_t *buf, size_t size) override
{
this->chain->Write(buf, size);
}
@@ -2650,10 +2650,10 @@ struct ZlibSaveFilter : SaveFilter {
* @param len Amount of bytes to write.
* @param mode Mode for deflate.
*/
void WriteLoop(uint8_t *p, size_t len, int mode)
void WriteLoop(const uint8_t *p, size_t len, int mode)
{
uint n;
this->z.next_in = p;
this->z.next_in = const_cast<uint8_t *>(p); // zlib does not modify the data, but is non-const for legacy reasons
this->z.avail_in = static_cast<uInt>(len);
do {
this->z.next_out = this->fwrite_buf;
@@ -2678,7 +2678,7 @@ struct ZlibSaveFilter : SaveFilter {
} while (this->z.avail_in || !this->z.avail_out);
}
void Write(uint8_t *buf, size_t size) override
void Write(const uint8_t *buf, size_t size) override
{
this->WriteLoop(buf, size, 0);
}
@@ -2776,7 +2776,7 @@ struct LZMASaveFilter : SaveFilter {
* @param len Amount of bytes to write.
* @param action Action for lzma_code.
*/
void WriteLoop(uint8_t *p, size_t len, lzma_action action)
void WriteLoop(const uint8_t *p, size_t len, lzma_action action)
{
size_t n;
this->lzma.next_in = p;
@@ -2796,7 +2796,7 @@ struct LZMASaveFilter : SaveFilter {
} while (this->lzma.avail_in || !this->lzma.avail_out);
}
void Write(uint8_t *buf, size_t size) override
void Write(const uint8_t *buf, size_t size) override
{
this->WriteLoop(buf, size, LZMA_RUN);
}
+1 -1
View File
@@ -75,7 +75,7 @@ struct SaveFilter {
* @param buf The bytes to write.
* @param len The number of bytes to write.
*/
virtual void Write(uint8_t *buf, size_t len) = 0;
virtual void Write(const uint8_t *buf, size_t len) = 0;
/**
* Prepare everything to finish writing the savegame.
+2 -4
View File
@@ -911,11 +911,9 @@ static CommandCost IsStationBridgeAboveOk(TileIndex tile, std::span<const Bridge
/* Get normal error message associated with clearing the tile. */
return Command<Commands::LandscapeClear>::Do(DoCommandFlag::Auto, tile);
}
if (GetTileMaxZ(tile) + height > bridge_height) {
int height_diff = (GetTileMaxZ(tile) + height - bridge_height) * TILE_HEIGHT_STEP;
return CommandCostWithParam(GetBridgeTooLowMessageForStationType(type), height_diff);
}
int height_diff = GetTileMaxZ(tile) + height - bridge_height;
if (height_diff > 0) return CommandCostWithParam(GetBridgeTooLowMessageForStationType(type), height_diff * TILE_HEIGHT_STEP);
return CommandCost{};
}
+6 -6
View File
@@ -371,9 +371,9 @@ static CommandCost DoBuildLock(TileIndex tile, DiagDirection dir, DoCommandFlags
WaterClass wc_upper = IsWaterTile(tile + delta) ? GetWaterClass(tile + delta) : WaterClass::Canal;
for (LockPart lock_part = LockPart::Middle; TileIndex t : {tile, tile - delta, tile + delta}) {
if (IsBridgeAbove(t) && GetBridgeHeight(GetSouthernBridgeEnd(t)) < GetTileMaxZ(t) + GetLockPartMinimalBridgeHeight(lock_part)) {
int height_diff = (GetTileMaxZ(tile) + GetLockPartMinimalBridgeHeight(lock_part) - GetBridgeHeight(GetSouthernBridgeEnd(t))) * TILE_HEIGHT_STEP;
return CommandCostWithParam(STR_ERROR_BRIDGE_TOO_LOW_FOR_LOCK, height_diff);
if (IsBridgeAbove(t)) {
int height_diff = GetTileMaxZ(tile) + GetLockPartMinimalBridgeHeight(lock_part) - GetBridgeHeight(GetSouthernBridgeEnd(t));
if (height_diff > 0) return CommandCostWithParam(STR_ERROR_BRIDGE_TOO_LOW_FOR_LOCK, height_diff * TILE_HEIGHT_STEP);
}
++lock_part;
}
@@ -1470,9 +1470,9 @@ static CommandCost CheckBuildAbove_Water(TileIndex tile, DoCommandFlags flags, [
{
if (IsWater(tile) || IsCoast(tile)) return CommandCost();
if (IsLock(tile)) {
if (GetTileMaxZ(tile) + GetLockPartMinimalBridgeHeight(GetLockPart(tile)) <= height) return CommandCost();
int height_diff = (GetTileMaxZ(tile) + GetLockPartMinimalBridgeHeight(GetLockPart(tile)) - height) * TILE_HEIGHT_STEP;
return CommandCostWithParam(STR_ERROR_BRIDGE_TOO_LOW_FOR_LOCK, height_diff);
int height_diff = GetTileMaxZ(tile) + GetLockPartMinimalBridgeHeight(GetLockPart(tile)) - height;
if (height_diff > 0) return CommandCostWithParam(STR_ERROR_BRIDGE_TOO_LOW_FOR_LOCK, height_diff * TILE_HEIGHT_STEP);
return CommandCost{};
}
return Command<Commands::LandscapeClear>::Do(flags, tile);
}