File diff r9913:5ef437117969 → r9914:213bce2115cb
src/station_cmd.cpp
Show inline comments
 
@@ -2788,49 +2788,51 @@ static void UpdateStationWaiting(Station
 
}
 

	
 
static bool IsUniqueStationName(const char *name)
 
{
 
	const Station *st;
 
	char buf[512];
 

	
 
	FOR_ALL_STATIONS(st) {
 
		SetDParam(0, st->index);
 
		GetString(buf, STR_STATION, lastof(buf));
 
		if (strcmp(buf, name) == 0) return false;
 
	}
 

	
 
	return true;
 
}
 

	
 
/** Rename a station
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 station ID that is to be renamed
 
 * @param p2 unused
 
 */
 
CommandCost CmdRenameStation(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	if (!IsValidStationID(p1) || StrEmpty(_cmd_text)) return CMD_ERROR;
 
	if (!IsValidStationID(p1))
 
	if (StrEmpty(_cmd_text) || strlen(_cmd_text) >= MAX_LENGTH_STATION_NAME_BYTES) return CMD_ERROR;
 

	
 
	Station *st = GetStation(p1);
 

	
 
	if (!CheckOwnership(st->owner)) return CMD_ERROR;
 

	
 
	if (!IsUniqueStationName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
 

	
 
	if (flags & DC_EXEC) {
 
		free(st->name);
 
		st->name = strdup(_cmd_text);
 

	
 
		UpdateStationVirtCoord(st);
 
		InvalidateWindowData(WC_STATION_LIST, st->owner, 1);
 
		MarkWholeScreenDirty();
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Find all (non-buoy) stations around an industry tile
 
 *
 
 * @param tile: Center tile to search from
 
 * @param w: Width of the center
 
 * @param h: Height of the center