diff --git a/console_cmds.c b/console_cmds.c index d426b99d7c..5077c5c4a3 100644 --- a/console_cmds.c +++ b/console_cmds.c @@ -1402,6 +1402,19 @@ DEF_CONSOLE_CMD(ConPatch) return true; } +DEF_CONSOLE_CMD(ConListPatches) +{ + if (argc == 0) { + IConsoleHelp("List patch options. Usage: 'list_patches'"); + return true; + } + + if (argc != 1) return false; + + IConsoleListPatches(); + return true; +} + DEF_CONSOLE_CMD(ConListDumpVariables) { const IConsoleVar *var; @@ -1482,6 +1495,7 @@ void IConsoleStdLibRegister(void) IConsoleCmdRegister("pwd", ConPrintWorkingDirectory); IConsoleCmdRegister("clear", ConClearBuffer); IConsoleCmdRegister("patch", ConPatch); + IConsoleCmdRegister("list_patches", ConListPatches); IConsoleAliasRegister("dir", "ls"); IConsoleAliasRegister("del", "rm %+"); diff --git a/rail_cmd.c b/rail_cmd.c index c8ed51c32b..cf97331749 100644 --- a/rail_cmd.c +++ b/rail_cmd.c @@ -272,7 +272,7 @@ int32 CmdBuildSingleRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) case MP_RAILWAY: if (!CheckTrackCombination(tile, trackbit, flags) || - !EnsureNoVehicle(tile)) { + !EnsureNoVehicleOnGround(tile)) { return CMD_ERROR; } if (!IsTileOwner(tile, _current_player) || @@ -307,7 +307,7 @@ int32 CmdBuildSingleRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) } #undef M - if (!EnsureNoVehicle(tile)) return CMD_ERROR; + if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR; if (GetRoadTileType(tile) == ROAD_TILE_NORMAL) { if (HasRoadWorks(tile)) return_cmd_error(STR_ROAD_WORKS_IN_PROGRESS); @@ -384,7 +384,7 @@ int32 CmdRemoveSingleRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) if (!IsLevelCrossing(tile) || GetCrossingRailBits(tile) != trackbit || (_current_player != OWNER_WATER && !CheckTileOwnership(tile)) || - !EnsureNoVehicle(tile)) { + !EnsureNoVehicleOnGround(tile)) { return CMD_ERROR; } @@ -399,7 +399,7 @@ int32 CmdRemoveSingleRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) if (!IsPlainRailTile(tile) || (_current_player != OWNER_WATER && !CheckTileOwnership(tile)) || - !EnsureNoVehicle(tile)) { + !EnsureNoVehicleOnGround(tile)) { return CMD_ERROR; } @@ -654,7 +654,7 @@ int32 CmdBuildSingleSignal(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) sigvar = HASBIT(p1, 3) ? SIG_SEMAPHORE : SIG_ELECTRIC; pre_signal = HASBIT(p1, 3); - if (!ValParamTrackOrientation(track) || !IsTileType(tile, MP_RAILWAY) || !EnsureNoVehicle(tile)) + if (!ValParamTrackOrientation(track) || !IsTileType(tile, MP_RAILWAY) || !EnsureNoVehicleOnGround(tile)) return CMD_ERROR; /* Protect against invalid signal copying */ @@ -833,7 +833,7 @@ int32 CmdRemoveSingleSignal(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) if (!ValParamTrackOrientation(track) || !IsTileType(tile, MP_RAILWAY) || - !EnsureNoVehicle(tile) || + !EnsureNoVehicleOnGround(tile) || !HasSignalOnTrack(tile, track)) { return CMD_ERROR; } @@ -890,7 +890,7 @@ static int32 DoConvertRail(TileIndex tile, RailType totype, bool exec) if (GetRailType(tile) == totype) return CMD_ERROR; - if (!EnsureNoVehicle(tile) && (!IsCompatibleRail(GetRailType(tile), totype) || IsPlainRailTile(tile))) return CMD_ERROR; + if (!EnsureNoVehicleOnGround(tile) && (!IsCompatibleRail(GetRailType(tile), totype) || IsPlainRailTile(tile))) return CMD_ERROR; // 'hidden' elrails can't be downgraded to normal rail when elrails are disabled if (_patches.disable_elrails && totype == RAILTYPE_RAIL && GetRailType(tile) == RAILTYPE_ELECTRIC) return CMD_ERROR; @@ -993,7 +993,7 @@ static int32 RemoveTrainDepot(TileIndex tile, uint32 flags) if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER) return CMD_ERROR; - if (!EnsureNoVehicle(tile)) + if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR; if (flags & DC_EXEC) { diff --git a/road_cmd.c b/road_cmd.c index 25bf373031..633b001ed2 100644 --- a/road_cmd.c +++ b/road_cmd.c @@ -308,7 +308,7 @@ int32 CmdBuildRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) if ((existing & pieces) == pieces) { return_cmd_error(STR_1007_ALREADY_BUILT); } - if (!EnsureNoVehicle(tile)) return CMD_ERROR; + if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR; break; case ROAD_TILE_CROSSING: @@ -352,7 +352,7 @@ int32 CmdBuildRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) default: goto do_clear; } - if (!EnsureNoVehicle(tile)) return CMD_ERROR; + if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR; if (flags & DC_EXEC) { YapfNotifyTrackLayoutChange(tile, FIND_FIRST_BIT(GetTrackBits(tile))); @@ -436,7 +436,7 @@ int32 DoConvertStreetRail(TileIndex tile, RailType totype, bool exec) if (!IsLevelCrossing(tile)) return CMD_ERROR; // not owned by me? - if (!CheckTileOwnership(tile) || !EnsureNoVehicle(tile)) return CMD_ERROR; + if (!CheckTileOwnership(tile) || !EnsureNoVehicleOnGround(tile)) return CMD_ERROR; if (GetRailTypeCrossing(tile) == totype) return CMD_ERROR; @@ -581,7 +581,7 @@ int32 CmdBuildRoadDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) if (p1 > 3) return CMD_ERROR; // check direction - if (!EnsureNoVehicle(tile)) return CMD_ERROR; + if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR; tileh = GetTileSlope(tile, NULL); if (tileh != SLOPE_FLAT && ( @@ -947,7 +947,7 @@ static void TileLoop_Road(TileIndex tile) if (t->road_build_months != 0 && (DistanceManhattan(t->xy, tile) < 8 || grp != 0) && GetRoadTileType(tile) == ROAD_TILE_NORMAL && (GetRoadBits(tile) == ROAD_X || GetRoadBits(tile) == ROAD_Y)) { - if (GetTileSlope(tile, NULL) == SLOPE_FLAT && EnsureNoVehicle(tile) && CHANCE16(1, 20)) { + if (GetTileSlope(tile, NULL) == SLOPE_FLAT && EnsureNoVehicleOnGround(tile) && CHANCE16(1, 20)) { StartRoadWorks(tile); SndPlayTileFx(SND_21_JACKHAMMER, tile); diff --git a/settings.c b/settings.c index dd98be7549..3257e11015 100644 --- a/settings.c +++ b/settings.c @@ -260,7 +260,13 @@ static IniFile *ini_load(const char *filename) } } else if (group) { // find end of keyname - for (t = s; *t != '\0' && *t != '=' && *t != '\t' && *t != ' '; t++); + if (*s == '\"') { + s++; + for (t = s; *t != '\0' && *t != '\"'; t++); + if (*t == '\"') *t = ' '; + } else { + for (t = s; *t != '\0' && *t != '=' && *t != '\t' && *t != ' '; t++); + } // it's an item in an existing group item = ini_item_alloc(group, s, t-s); @@ -348,11 +354,18 @@ static bool ini_save(const char *filename, IniFile *ini) assert(item->value != NULL); if (item->comment != NULL) fputs(item->comment, f); + /* protect item->name with quotes if needed */ + if (strchr(item->name, ' ') != NULL) { + fprintf(f, "\"%s\"", item->name); + } else { + fprintf(f, "%s", item->name); + } + /* Don't give an equal sign to list items that don't have a parameter */ if (group->type == IGT_LIST && *item->value == '\0') { - fprintf(f, "%s\n", item->name); + fprintf(f, "\n"); } else { - fprintf(f, "%s = %s\n", item->name, item->value); + fprintf(f, " = %s\n", item->value); } } } @@ -1800,6 +1813,26 @@ void IConsoleGetPatchSetting(const char *name) name, value, (sd->desc.flags & SGF_0ISDISABLED) ? "(0) " : "", sd->desc.min, sd->desc.max); } +void IConsoleListPatches(void) +{ + const SettingDesc *sd; + IConsolePrintF(_icolour_warn, "All patches with their current value:"); + + for (sd = _patch_settings; sd->save.cmd != SL_END; sd++) { + char value[80]; + const void *ptr = GetVariableAddress((_game_mode == GM_MENU) ? &_patches_newgame : &_patches, &sd->save); + + if (sd->desc.cmd == SDT_BOOLX) { + snprintf(value, lengthof(value), (*(bool*)ptr == 1) ? "on" : "off"); + } else { + snprintf(value, lengthof(value), "%d", (uint32)ReadValue(ptr, sd->save.conv)); + } + IConsolePrintF(_icolour_def, "%s = %s", sd->desc.name, value); + } + + IConsolePrintF(_icolour_warn, "Use 'patch' command to change a value"); +} + /** Save and load handler for patches/settings * @param osd SettingDesc struct containing all information * @param object can be either NULL in which case we load global variables or diff --git a/settings.h b/settings.h index 0ab3ecef32..e0155ef30d 100644 --- a/settings.h +++ b/settings.h @@ -71,6 +71,7 @@ extern Patches _patches_newgame; bool IConsoleSetPatchSetting(const char *name, int32 value); void IConsoleGetPatchSetting(const char *name); +void IConsoleListPatches(void); const SettingDesc *GetPatchFromName(const char *name, uint *i); bool SetPatchValue(uint index, const Patches *object, int32 value); diff --git a/tunnelbridge_cmd.c b/tunnelbridge_cmd.c index e021ec0dc6..1ef7bf4c62 100644 --- a/tunnelbridge_cmd.c +++ b/tunnelbridge_cmd.c @@ -675,7 +675,7 @@ static int32 DoClearBridge(TileIndex tile, uint32 flags) endtile = GetOtherBridgeEnd(tile); - if (!EnsureNoVehicle(tile) || !EnsureNoVehicle(endtile)) return CMD_ERROR; + if (!EnsureNoVehicleOnGround(tile) || !EnsureNoVehicleOnGround(endtile)) return CMD_ERROR; direction = GetBridgeRampDirection(tile); delta = TileOffsByDiagDir(direction); @@ -828,8 +828,8 @@ int32 DoConvertTunnelBridgeRail(TileIndex tile, RailType totype, bool exec) endtile = GetOtherBridgeEnd(tile); - if (!EnsureNoVehicle(tile) || - !EnsureNoVehicle(endtile) || + if (!EnsureNoVehicleOnGround(tile) || + !EnsureNoVehicleOnGround(endtile) || FindVehicleBetween(tile, endtile, GetBridgeHeightRamp(tile), false) != NULL) { return_cmd_error(STR_8803_TRAIN_IN_THE_WAY); }