mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r9584) [0.5] -Backport frmo trunk (r9542, r9565, r9573):
- Fix: when checking for no vehicle on ground-tiles, don't take into account vehicles that are in the air (r9542) - Feature: add list_patches to console commands; shows all patches and values (r9565) - Fix: enclose settings names containing spaces with quotes (r9573)
This commit is contained in:
parent
c04f0af19b
commit
ac6aefa07b
|
@ -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 %+");
|
||||
|
|
16
rail_cmd.c
16
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) {
|
||||
|
|
10
road_cmd.c
10
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);
|
||||
|
|
39
settings.c
39
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
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue