diff --git a/src/ai/api/ai_rail.cpp b/src/ai/api/ai_rail.cpp index 0d734f01c5..681b579666 100644 --- a/src/ai/api/ai_rail.cpp +++ b/src/ai/api/ai_rail.cpp @@ -14,6 +14,7 @@ #include "ai_map.hpp" #include "ai_station.hpp" #include "ai_industrytype.hpp" +#include "ai_cargo.hpp" #include "../../debug.h" #include "../../station_base.h" #include "../../company_func.h" @@ -170,6 +171,7 @@ EnforcePrecondition(false, platform_length > 0 && platform_length <= 0xFF); EnforcePrecondition(false, IsRailTypeAvailable(GetCurrentRailType())); EnforcePrecondition(false, station_id == AIStation::STATION_NEW || station_id == AIStation::STATION_JOIN_ADJACENT || AIStation::IsValidStation(station_id)); + EnforcePrecondition(false, AICargo::IsValidCargo(cargo_id)); EnforcePrecondition(false, source_industry == AIIndustryType::INDUSTRYTYPE_UNKNOWN || source_industry == AIIndustryType::INDUSTRYTYPE_TOWN || AIIndustryType::IsValidIndustryType(source_industry)); EnforcePrecondition(false, goal_industry == AIIndustryType::INDUSTRYTYPE_UNKNOWN || goal_industry == AIIndustryType::INDUSTRYTYPE_TOWN || AIIndustryType::IsValidIndustryType(goal_industry)); diff --git a/src/ai/api/ai_rail.hpp b/src/ai/api/ai_rail.hpp index 5f58c3014b..9bb759ea72 100644 --- a/src/ai/api/ai_rail.hpp +++ b/src/ai/api/ai_rail.hpp @@ -279,6 +279,7 @@ public: * @pre num_platforms > 0 && num_platforms <= 255. * @pre platform_length > 0 && platform_length <= 255. * @pre station_id == AIStation::STATION_NEW || station_id == AIStation::STATION_JOIN_ADJACENT || AIStation::IsValidStation(station_id). + * @pre AICargo::IsValidCargo(cargo_type) * @pre source_industry == AIIndustryType::INDUSTRYTYPE_UNKNOWN || source_industry == AIIndustryType::INDUSTRYTYPE_TOWN || AIIndustryType::IsValidIndustryType(source_industry). * @pre goal_industry == AIIndustryType::INDUSTRYTYPE_UNKNOWN || goal_industry == AIIndustryType::INDUSTRYTYPE_TOWN || AIIndustryType::IsValidIndustryType(goal_industry). * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY diff --git a/src/ai/api/ai_tile.cpp b/src/ai/api/ai_tile.cpp index 3e0b339f77..671567190a 100644 --- a/src/ai/api/ai_tile.cpp +++ b/src/ai/api/ai_tile.cpp @@ -13,6 +13,7 @@ #include "ai_tile.hpp" #include "ai_map.hpp" #include "ai_town.hpp" +#include "ai_cargo.hpp" #include "../../station_func.h" #include "../../company_func.h" #include "../../water_map.h" @@ -192,7 +193,7 @@ /* static */ int32 AITile::GetCargoAcceptance(TileIndex tile, CargoID cargo_type, int width, int height, int radius) { - if (!::IsValidTile(tile) || width <= 0 || height <= 0 || radius < 0) return -1; + if (!::IsValidTile(tile) || width <= 0 || height <= 0 || radius < 0 || !AICargo::IsValidCargo(cargo_type)) return -1; CargoArray acceptance = ::GetAcceptanceAroundTiles(tile, width, height, _settings_game.station.modified_catchment ? radius : (int)CA_UNMODIFIED); return acceptance[cargo_type]; @@ -200,7 +201,7 @@ /* static */ int32 AITile::GetCargoProduction(TileIndex tile, CargoID cargo_type, int width, int height, int radius) { - if (!::IsValidTile(tile) || width <= 0 || height <= 0 || radius < 0) return -1; + if (!::IsValidTile(tile) || width <= 0 || height <= 0 || radius < 0 || !AICargo::IsValidCargo(cargo_type)) return -1; CargoArray produced = ::GetProductionAroundTiles(tile, width, height, _settings_game.station.modified_catchment ? radius : (int)CA_UNMODIFIED); return produced[cargo_type]; diff --git a/src/ai/api/ai_tile.hpp b/src/ai/api/ai_tile.hpp index 944821e007..17a292ae3e 100644 --- a/src/ai/api/ai_tile.hpp +++ b/src/ai/api/ai_tile.hpp @@ -319,6 +319,7 @@ public: * @param height The height of the station. * @param radius The radius of the station. * @pre AIMap::IsValidTile(tile). + * @pre AICargo::IsValidCargo(cargo_type) * @pre width > 0. * @pre height > 0. * @pre radius >= 0. @@ -335,6 +336,7 @@ public: * @param height The height of the station. * @param radius The radius of the station. * @pre AIMap::IsValidTile(tile). + * @pre AICargo::IsValidCargo(cargo_type) * @pre width > 0. * @pre height > 0. * @pre radius >= 0. diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index cbe8976c7a..c5b4385510 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -1640,7 +1640,7 @@ DEF_CONSOLE_CMD(ConCompanyPassword) return false; } - password = NetworkChangeCompanyPassword(company_id, password, false); + password = NetworkChangeCompanyPassword(company_id, password); if (StrEmpty(password)) { IConsolePrintF(CC_WARNING, "Company password cleared"); diff --git a/src/network/network.cpp b/src/network/network.cpp index 1392d79a58..fe3bce70d1 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -156,12 +156,12 @@ byte NetworkSpectatorCount() * @param password The unhashed password we like to set ('*' or '' resets the password) * @return The password. */ -const char *NetworkChangeCompanyPassword(CompanyID company_id, const char *password, bool already_hashed) +const char *NetworkChangeCompanyPassword(CompanyID company_id, const char *password) { if (strcmp(password, "*") == 0) password = ""; if (_network_server) { - NetworkServerSetCompanyPassword(company_id, password, already_hashed); + NetworkServerSetCompanyPassword(company_id, password, false); } else { NetworkClientSetCompanyPassword(password); } diff --git a/src/network/network_func.h b/src/network/network_func.h index af530d0684..015c7dba10 100644 --- a/src/network/network_func.h +++ b/src/network/network_func.h @@ -36,7 +36,7 @@ extern StringList _network_ban_list; byte NetworkSpectatorCount(); void NetworkUpdateClientName(); bool NetworkCompanyHasClients(CompanyID company); -const char *NetworkChangeCompanyPassword(CompanyID company_id, const char *password, bool already_hashed = true); +const char *NetworkChangeCompanyPassword(CompanyID company_id, const char *password); void NetworkReboot(); void NetworkDisconnect(bool blocking = false, bool close_admins = true); void NetworkGameLoop(); diff --git a/src/newgrf_house.cpp b/src/newgrf_house.cpp index 6991303525..93ea1ccf49 100644 --- a/src/newgrf_house.cpp +++ b/src/newgrf_house.cpp @@ -459,7 +459,7 @@ void DrawNewHouseTile(TileInfo *ti, HouseID house_id) /* Limit the building stage to the number of stages supplied. */ const TileLayoutSpriteGroup *tlgroup = (const TileLayoutSpriteGroup *)group; byte stage = GetHouseBuildingStage(ti->tile); - stage = Clamp(stage - 4 + tlgroup->num_building_stages, 0, tlgroup->num_building_stages - 1); + stage = tlgroup->GetConstructionStageOffset(stage); DrawTileLayout(ti, tlgroup, stage, house_id); } } diff --git a/src/newgrf_industrytiles.cpp b/src/newgrf_industrytiles.cpp index 70b27c0f94..e0d5ac7cda 100644 --- a/src/newgrf_industrytiles.cpp +++ b/src/newgrf_industrytiles.cpp @@ -237,7 +237,7 @@ bool DrawNewIndustryTile(TileInfo *ti, Industry *i, IndustryGfx gfx, const Indus /* Limit the building stage to the number of stages supplied. */ const TileLayoutSpriteGroup *tlgroup = (const TileLayoutSpriteGroup *)group; byte stage = GetIndustryConstructionStage(ti->tile); - stage = Clamp(stage - 4 + tlgroup->num_building_stages, 0, tlgroup->num_building_stages - 1); + stage = tlgroup->GetConstructionStageOffset(stage); IndustryDrawTileLayout(ti, tlgroup, i->random_colour, stage, gfx); return true; } diff --git a/src/newgrf_spritegroup.h b/src/newgrf_spritegroup.h index 452d71aed3..ff27435cea 100644 --- a/src/newgrf_spritegroup.h +++ b/src/newgrf_spritegroup.h @@ -287,6 +287,25 @@ struct TileLayoutSpriteGroup : SpriteGroup { byte num_building_stages; ///< Number of building stages to show for this house/industry tile struct DrawTileSprites *dts; + + /** + * Determines which sprite to use from a spriteset for a specific construction stage. + * @param construction_stage Construction stage 0 - 3. + * @return Sprite to use + */ + uint GetConstructionStageOffset(uint construction_stage) const + { + uint num_sprites = this->num_building_stages; + assert(num_sprites > 0); + if (num_sprites > 4) num_sprites = 4; + switch (construction_stage) { + case 0: return 0; + case 1: return num_sprites > 2 ? 1 : 0; + case 2: return num_sprites > 2 ? num_sprites - 2 : 0; + case 3: return num_sprites - 1; + default: NOT_REACHED(); + } + } }; struct IndustryProductionSpriteGroup : SpriteGroup { diff --git a/src/viewport.cpp b/src/viewport.cpp index 16e6bb0b5e..c67277a6bd 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -2778,11 +2778,11 @@ calc_heightdiff_single_direction:; } } - if (t0 != 1 || t1 != 1) { + if (dx != 1 || dy != 1) { int heightdiff = CalcHeightdiff(style, 0, t0, t1); - params[index++] = dx; - params[index++] = dy; + params[index++] = dx - (style & HT_POINT ? 1 : 0); + params[index++] = dy - (style & HT_POINT ? 1 : 0); if (heightdiff != 0) params[index++] = heightdiff; }