1
0
mirror of https://github.com/OpenTTD/OpenTTD.git synced 2025-08-27 08:29:11 +00:00

Compare commits

..

6 Commits

Author SHA1 Message Date
Susan
573b55cf9f Codechange: remove magic number 2024-05-28 01:59:17 +01:00
Su
23f8519624 Codefix: Remove typos and use correct formatting
Co-authored-by: Tyler Trahan <tyler@tylertrahan.com>
2024-05-28 01:59:17 +01:00
Sylvain Devidal
ac06b4a7a6 Fix: "Alone" trees are now replaced after death. They also can spread on their own tile. 2024-05-28 01:59:17 +01:00
Sylvain Devidal
3a3b1c5f04 Codechange: Merged "Improved" and "Forest" options. 2024-05-28 01:59:17 +01:00
Sylvain Devidal
a2dd8ed419 Codechange: Use of proper FALLTHROUGH macro 2024-05-28 01:59:17 +01:00
Sylvain Devidal
53d2153844 Feature: New Trees Placement Algorithm "Forest" 2024-05-28 01:59:17 +01:00
589 changed files with 16491 additions and 21673 deletions

View File

@@ -5,8 +5,8 @@ tag=$(git name-rev --name-only --tags --no-undefined HEAD 2>/dev/null | sed 's@\
# If we are a tag, show the part of the changelog till (but excluding) the last stable
if [ -n "$tag" ]; then
grep='^[0-9]\+\.[0-9]\+[^-]'
next=$(cat changelog.md | grep '^[0-9]' | awk 'BEGIN { show="false" } // { if (show=="true") print $0; if ($1=="'$tag'") show="true"} ' | grep "$grep" | head -n1 | sed 's/ .*//')
cat changelog.md | awk 'BEGIN { show="false" } /^[0-9]+.[0-9]+/ { if ($1=="'$next'") show="false"; if ($1=="'$tag'") show="true";} // { if (show=="true") print $0 }'
next=$(cat changelog.txt | grep '^[0-9]' | awk 'BEGIN { show="false" } // { if (show=="true") print $0; if ($1=="'$tag'") show="true"} ' | grep "$grep" | head -n1 | sed 's/ .*//')
cat changelog.txt | awk 'BEGIN { show="false" } /^[0-9]+.[0-9]+/ { if ($1=="'$next'") show="false"; if ($1=="'$tag'") show="true";} // { if (show=="true") print $0 }'
exit 0
fi

View File

@@ -39,6 +39,7 @@ def read_language_file(filename, strings_found, errors):
skip = SkipType.NONE
length = 0
common_prefix = ""
last_tiny_string = ""
with open(filename) as fp:
for line in fp.readlines():
@@ -113,6 +114,17 @@ def read_language_file(filename, strings_found, errors):
name = line.split(":")[0].strip()
strings_defined.append(name)
# If a string ends on _TINY or _SMALL, it can be the {TINY} variant.
# Check for this by some fuzzy matching.
if name.endswith(("_SMALL", "_TINY")):
last_tiny_string = name
elif last_tiny_string:
matching_name = "_".join(last_tiny_string.split("_")[:-1])
if name == matching_name:
strings_found.add(last_tiny_string)
else:
last_tiny_string = ""
if skip == SkipType.EXTERNAL:
strings_found.add(name)
skip = SkipType.LENGTH

View File

@@ -26,8 +26,8 @@ jobs:
matrix:
include:
- name: Clang
compiler: clang
cxxcompiler: clang++
compiler: clang-15
cxxcompiler: clang++-15
libraries: libsdl2-dev
- name: GCC - SDL2
compiler: gcc
@@ -80,8 +80,10 @@ jobs:
fail-fast: false
matrix:
include:
- arch: x86
- arch: x64
- os: windows-latest
arch: x86
- os: windows-latest
arch: x64
name: Windows (${{ matrix.arch }})
@@ -89,6 +91,7 @@ jobs:
secrets: inherit
with:
os: ${{ matrix.os }}
arch: ${{ matrix.arch }}
check_annotations:

View File

@@ -10,7 +10,7 @@ jobs:
emscripten:
name: CI
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
container:
# If you change this version, change the number in the cache step too.
image: emscripten/emsdk:3.1.57
@@ -19,10 +19,6 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Fix dubious ownership
run: |
git config --global --add safe.directory ${GITHUB_WORKSPACE}
- name: Setup cache
uses: actions/cache@v4
with:

View File

@@ -23,7 +23,7 @@ jobs:
linux:
name: CI
runs-on: ubuntu-24.04
runs-on: ubuntu-latest
env:
CC: ${{ inputs.compiler }}
CXX: ${{ inputs.cxxcompiler }}
@@ -60,9 +60,6 @@ jobs:
libicu-dev \
liblzma-dev \
liblzo2-dev \
libogg-dev \
libopus-dev \
libopusfile-dev \
${{ inputs.libraries }} \
zlib1g-dev \
# EOF

View File

@@ -21,7 +21,7 @@ jobs:
macos:
name: CI
runs-on: macos-latest
runs-on: macos-14
env:
MACOSX_DEPLOYMENT_TARGET: 10.13

View File

@@ -37,9 +37,6 @@ jobs:
mingw-w64-${{ inputs.arch }}-libpng
mingw-w64-${{ inputs.arch }}-lld
mingw-w64-${{ inputs.arch }}-ninja
mingw-w64-${{ inputs.arch }}-libogg
mingw-w64-${{ inputs.arch }}-opus
mingw-w64-${{ inputs.arch }}-opusfile
- name: Install OpenGFX
shell: bash

View File

@@ -6,6 +6,9 @@ on:
arch:
required: true
type: string
os:
required: true
type: string
env:
CTEST_OUTPUT_ON_FAILURE: 1
@@ -14,7 +17,7 @@ jobs:
windows:
name: CI
runs-on: windows-latest
runs-on: ${{ inputs.os }}
steps:
- name: Checkout

View File

@@ -54,8 +54,6 @@ jobs:
libicu-dev \
liblzma-dev \
liblzo2-dev \
libopus-dev \
libopusfile-dev \
libsdl2-dev \
zlib1g-dev \
# EOF

View File

@@ -11,7 +11,7 @@ jobs:
docs:
name: Docs
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- name: Download source

View File

@@ -12,7 +12,7 @@ jobs:
macos:
name: MacOS
runs-on: macos-latest
runs-on: macos-14
env:
MACOSX_DEPLOYMENT_TARGET: 10.13
@@ -86,7 +86,7 @@ jobs:
echo "::endgroup::"
- name: Import code signing certificates
uses: Apple-Actions/import-codesign-certs@v3
uses: Apple-Actions/import-codesign-certs@v2
with:
# The certificates in a PKCS12 file encoded as a base64 string
p12-file-base64: ${{ secrets.APPLE_DEVELOPER_CERTIFICATE_P12_BASE64 }}

View File

@@ -18,7 +18,7 @@ jobs:
source:
name: Source
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
outputs:
version: ${{ steps.metadata.outputs.version }}
@@ -127,7 +127,7 @@ jobs:
fi
mkdir -p build/bundles
cp .changelog build/bundles/changelog.md
cp .changelog build/bundles/changelog.txt
cp .release_date build/bundles/released.txt
cp README.md build/bundles/README.md
echo "::endgroup::"

View File

@@ -11,7 +11,7 @@ jobs:
upload:
name: Upload (GOG)
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- name: Download source

View File

@@ -14,7 +14,7 @@ jobs:
upload:
name: Upload (Steam)
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- name: Download source

View File

@@ -152,10 +152,9 @@ if(NOT OPTION_DEDICATED)
find_package(Fontconfig)
endif()
find_package(Harfbuzz)
find_package(ICU OPTIONAL_COMPONENTS i18n uc)
find_package(ICU OPTIONAL_COMPONENTS i18n)
endif()
endif()
find_package(OpusFile)
endif()
if(APPLE)
enable_language(OBJCXX)
@@ -332,8 +331,6 @@ if(NOT OPTION_DEDICATED)
link_package(Fontconfig TARGET Fontconfig::Fontconfig)
link_package(Harfbuzz TARGET harfbuzz::harfbuzz)
link_package(ICU_i18n)
link_package(ICU_uc)
link_package(OpusFile TARGET OpusFile::opusfile)
if(SDL2_FOUND AND OPENGL_FOUND AND UNIX)
# SDL2 dynamically loads OpenGL if needed, so do not link to OpenGL when
@@ -391,8 +388,8 @@ if(EMSCRIPTEN)
target_link_libraries(WASM::WASM INTERFACE "--preload-file ${CMAKE_SOURCE_DIR}/CREDITS.md@/CREDITS.md")
target_link_libraries(WASM::WASM INTERFACE "--preload-file ${CMAKE_SOURCE_DIR}/CONTRIBUTING.md@/CONTRIBUTING.md")
target_link_libraries(WASM::WASM INTERFACE "--preload-file ${CMAKE_SOURCE_DIR}/COPYING.md@/COPYING.md")
target_link_libraries(WASM::WASM INTERFACE "--preload-file ${CMAKE_SOURCE_DIR}/known-bugs.md@/known-bugs.md")
target_link_libraries(WASM::WASM INTERFACE "--preload-file ${CMAKE_SOURCE_DIR}/changelog.md@/changelog.md")
target_link_libraries(WASM::WASM INTERFACE "--preload-file ${CMAKE_SOURCE_DIR}/known-bugs.txt@/known-bugs.txt")
target_link_libraries(WASM::WASM INTERFACE "--preload-file ${CMAKE_SOURCE_DIR}/changelog.txt@/changelog.txt")
target_link_libraries(WASM::WASM INTERFACE "--preload-file ${CMAKE_SOURCE_DIR}/docs/admin_network.md@/docs/admin_network.md")
target_link_libraries(WASM::WASM INTERFACE "--preload-file ${CMAKE_SOURCE_DIR}/docs/debugging_desyncs.md@/docs/debugging_desyncs.md")
target_link_libraries(WASM::WASM INTERFACE "--preload-file ${CMAKE_SOURCE_DIR}/docs/desync.md@/docs/desync.md")

View File

@@ -254,40 +254,6 @@ int Func();
* If you are writing one or more template class in the dedicated header file, use file.hpp for its name instead of file.h. This will let others know that it is template library (includes also implementation), not just header with declarations.
### Code Comment Vertical Alignment
When adding code or comments to an existing formatted section, follow the existing style if possible without editing the preexisting lines.
If your addition cannot be aligned with existing code, do not align the comments with anything and use only a single space between the code and the comment.
Good:
```c++
enum Vehicle {
BUS, ///< Take the bus.
+ CAR, ///< Drive your car.
BIKE, ///< Ride your bike
+ TRAIN, ///< Catch the train.
}
```
"Car" is shorter than Bike which allows you to easily align the new comment. "Train" is longer. It is *NOT* desirable to change the vertical comment alignment of this enum.
Bad:
```c++
enum Vehicle {
- BUS, ///< Take the bus.
- BIKE, ///< Ride your bike
+ BUS, ///< Take the bus.
+ CAR, ///< Drive your car.
+ BIKE, ///< Ride your bike
+ TRAIN, ///< Catch the train.
}
```
OpenTTD used to vertically-align inline Doxygen comments as shown above. OpenTTD has since stopped strictly following this rule to keep diffs smaller and reduce pollution to the git blame history for non-functional changes.
### Other important rules
* Put a space before and after binary operators: "a + b", "a == b", "a & b", "a <<= b", etc.. Exceptions are ".", "->" and "[]" (no spaces) and "," (just space after it).
* Put parenthesis where it improves readability: "*(b++)" instead of "*b++", and "if ((a & b) && c == 2)" instead of "if (a & b && c == 2)".
@@ -482,7 +448,7 @@ Do not mention two keywords; if two apply, pick one that best represents the com
The `<details>` part starts with a capital and does not end with a dot.
Try to be descriptive to what the player will notice, not to what is actually being changed in the code.
See `changelog.md` for inspiration.
See `changelog.txt` for inspiration.
To further structure the changelog, you can add components. Example are:
* "Network" for network specific changes.

File diff suppressed because it is too large Load Diff

View File

@@ -10,7 +10,6 @@ macro(compile_flags)
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_compile_options(
/Zc:preprocessor # Needed for __VA_OPT__() in macros.
/MP # Enable multi-threaded compilation.
/FC # Display the full path of source code files passed to the compiler in diagnostics.
)
@@ -56,11 +55,6 @@ macro(compile_flags)
# This flag disables the broken optimisation to work around the bug
add_compile_options(/d2ssa-rse-)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_compile_options(
-Wno-multichar
)
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
add_compile_options(
-W

View File

@@ -1,37 +0,0 @@
include(FindPackageHandleStandardArgs)
find_library(Ogg_LIBRARY
NAMES ogg
)
set(Ogg_COMPILE_OPTIONS "" CACHE STRING "Extra compile options of ogg")
set(Ogg_LINK_LIBRARIES "" CACHE STRING "Extra link libraries of ogg")
set(Ogg_LINK_FLAGS "" CACHE STRING "Extra link flags of ogg")
find_path(Ogg_INCLUDE_PATH
NAMES ogg.h
PATH_SUFFIXES ogg
)
find_package_handle_standard_args(Ogg
REQUIRED_VARS Ogg_LIBRARY Ogg_INCLUDE_PATH
)
if (Ogg_FOUND)
set(Ogg_dirs ${Ogg_INCLUDE_PATH})
if(EXISTS "${Ogg_INCLUDE_PATH}/ogg")
list(APPEND Ogg_dirs "${Ogg_INCLUDE_PATH}/ogg")
endif()
if (NOT TARGET Ogg::ogg)
add_library(Ogg::ogg UNKNOWN IMPORTED)
set_target_properties(Ogg::ogg PROPERTIES
IMPORTED_LOCATION "${Ogg_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${Ogg_dirs}"
INTERFACE_COMPILE_OPTIONS "${Ogg_COMPILE_OPTIONS}"
INTERFACE_LINK_LIBRARIES "${Ogg_LINK_LIBRARIES}"
INTERFACE_LINK_FLAGS "${Ogg_LINK_FLAGS}"
)
endif()
endif()

View File

@@ -1,37 +0,0 @@
include(FindPackageHandleStandardArgs)
find_library(Opus_LIBRARY
NAMES opus
)
set(Opus_COMPILE_OPTIONS "" CACHE STRING "Extra compile options of opus")
set(Opus_LINK_LIBRARIES "" CACHE STRING "Extra link libraries of opus")
set(Opus_LINK_FLAGS "" CACHE STRING "Extra link flags of opus")
find_path(Opus_INCLUDE_PATH
NAMES opus.h
PATH_SUFFIXES opus
)
find_package_handle_standard_args(Opus
REQUIRED_VARS Opus_LIBRARY Opus_INCLUDE_PATH
)
if (Opus_FOUND)
set(Opus_dirs ${Opus_INCLUDE_PATH})
if(EXISTS "${Opus_INCLUDE_PATH}/opus")
list(APPEND Opus_dirs "${Opus_INCLUDE_PATH}/opus")
endif()
if (NOT TARGET Opus::opus)
add_library(Opus::opus UNKNOWN IMPORTED)
set_target_properties(Opus::opus PROPERTIES
IMPORTED_LOCATION "${Opus_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${Opus_dirs}"
INTERFACE_COMPILE_OPTIONS "${Opus_COMPILE_OPTIONS}"
INTERFACE_LINK_LIBRARIES "${Opus_LINK_LIBRARIES}"
INTERFACE_LINK_FLAGS "${Opus_LINK_FLAGS}"
)
endif()
endif()

View File

@@ -1,40 +0,0 @@
include(FindPackageHandleStandardArgs)
find_library(OpusFile_LIBRARY
NAMES opusfile
)
set(OpusFile_COMPILE_OPTIONS "" CACHE STRING "Extra compile options of opusfile")
set(OpusFile_LINK_LIBRARIES "" CACHE STRING "Extra link libraries of opusfile")
set(OpusFile_LINK_FLAGS "" CACHE STRING "Extra link flags of opusfile")
find_path(OpusFile_INCLUDE_PATH
NAMES opusfile.h
PATH_SUFFIXES opus
)
find_package_handle_standard_args(OpusFile
REQUIRED_VARS OpusFile_LIBRARY OpusFile_INCLUDE_PATH
)
find_package(Ogg)
find_package(Opus)
if (OpusFile_FOUND)
set(OpusFile_dirs ${OpusFile_INCLUDE_PATH})
if(EXISTS "${OpusFile_INCLUDE_PATH}/opus")
list(APPEND OpusFile_dirs "${OpusFile_INCLUDE_PATH}/opus")
endif()
if (NOT TARGET OpusFile::opusfile)
add_library(OpusFile::opusfile UNKNOWN IMPORTED)
set_target_properties(OpusFile::opusfile PROPERTIES
IMPORTED_LOCATION "${OpusFile_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${OpusFile_dirs}"
INTERFACE_COMPILE_OPTIONS "${OpusFile_COMPILE_OPTIONS}"
INTERFACE_LINK_LIBRARIES "Ogg::ogg;Opus::opus;${OpusFile_LINK_LIBRARIES}"
INTERFACE_LINK_FLAGS "${OpusFile_LINK_FLAGS}"
)
endif()
endif()

View File

@@ -51,8 +51,8 @@ install(FILES
${CMAKE_SOURCE_DIR}/README.md
${CMAKE_SOURCE_DIR}/CREDITS.md
${CMAKE_SOURCE_DIR}/CONTRIBUTING.md
${CMAKE_SOURCE_DIR}/changelog.md
${CMAKE_SOURCE_DIR}/known-bugs.md
${CMAKE_SOURCE_DIR}/changelog.txt
${CMAKE_SOURCE_DIR}/known-bugs.txt
DESTINATION ${DOCS_DESTINATION_DIR}
COMPONENT docs)

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.16)
cmake_minimum_required(VERSION 3.5)
#
# Create a single baseset meta file with the correct translations.

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.16)
cmake_minimum_required(VERSION 3.5)
#
# Create a single GRF file based on sprites/<grfname>.nfo and sprites/*.png

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.16)
cmake_minimum_required(VERSION 3.5)
#
# Create a desktop file with the correct translations.

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.16)
cmake_minimum_required(VERSION 3.5)
if(NOT REV_MAJOR)
set(REV_MAJOR 0)
@@ -57,6 +57,7 @@ if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
)
string(REGEX REPLACE "([0-9]+)-([0-9]+)-([0-9]+).*" "\\1\\2\\3" COMMITDATE "${COMMITDATE}")
set(REV_ISODATE "${COMMITDATE}")
string(SUBSTRING "${REV_ISODATE}" 0 4 REV_YEAR)
# Get the branch
execute_process(COMMAND ${GIT_EXECUTABLE} symbolic-ref -q HEAD
@@ -113,6 +114,7 @@ elseif(EXISTS "${CMAKE_SOURCE_DIR}/.ottdrev")
list(GET OTTDREV 3 REV_HASH)
list(GET OTTDREV 4 REV_ISTAG)
list(GET OTTDREV 5 REV_ISSTABLETAG)
list(GET OTTDREV 6 REV_YEAR)
else()
message(WARNING "No version detected; this build will NOT be network compatible")
set(REV_VERSION "norev0000")
@@ -121,19 +123,14 @@ else()
set(REV_HASH "unknown")
set(REV_ISTAG 0)
set(REV_ISSTABLETAG 0)
set(REV_YEAR "1970")
endif()
# Extract REV_YEAR and REV_DATE from REV_ISODATE
string(SUBSTRING "${REV_ISODATE}" 0 4 REV_YEAR)
string(SUBSTRING "${REV_ISODATE}" 4 4 REV_DATE)
# Drop leading 0 in REV_DATE if any
string(REGEX REPLACE "^0?([0-9]+)" "\\1" REV_DATE "${REV_DATE}")
message(STATUS "Version string: ${REV_VERSION}")
if(GENERATE_OTTDREV)
message(STATUS "Generating .ottdrev")
file(WRITE ${CMAKE_SOURCE_DIR}/.ottdrev "${REV_VERSION}\t${REV_ISODATE}\t${REV_MODIFIED}\t${REV_HASH}\t${REV_ISTAG}\t${REV_ISSTABLETAG}\n")
file(WRITE ${CMAKE_SOURCE_DIR}/.ottdrev "${REV_VERSION}\t${REV_ISODATE}\t${REV_MODIFIED}\t${REV_HASH}\t${REV_ISTAG}\t${REV_ISSTABLETAG}\t${REV_YEAR}\n")
else()
message(STATUS "Generating rev.cpp")
configure_file("${CMAKE_SOURCE_DIR}/src/rev.cpp.in"

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.16)
cmake_minimum_required(VERSION 3.5)
#
# CMake script to automatically generate the enums in script_window.hpp

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.16)
cmake_minimum_required(VERSION 3.5)
#
# Runs a single regressoion test

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.16)
cmake_minimum_required(VERSION 3.5)
if(NOT SCRIPT_API_SOURCE_FILE)
message(FATAL_ERROR "Script needs SCRIPT_API_SOURCE_FILE defined")

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.16)
cmake_minimum_required(VERSION 3.5)
if(NOT INCLUDES_SOURCE_FILE)
message(FATAL_ERROR "Script needs INCLUDES_SOURCE_FILE defined")

View File

@@ -1,6 +1,6 @@
# OpenTTD's admin network
Last updated: 2024-03-26
Last updated: 2011-01-20
## Table of contents
@@ -49,29 +49,10 @@ Last updated: 2024-03-26
Create a TCP connection to the server on port 3977. The application is
expected to authenticate within 10 seconds.
To authenticate send either an `ADMIN_PACKET_ADMIN_JOIN` or an
`ADMIN_PACKET_ADMIN_JOIN_SECURE` packet.
To authenticate send a `ADMIN_PACKET_ADMIN_JOIN` packet.
The `ADMIN_PACKET_ADMIN_JOIN` packet sends the password without any
encryption or safeguards over the connection, and as such has been disabled
by default.
The `ADMIN_PACKET_ADMIN_JOIN_SECURE` packet initiates a key exchange
authentication schema which tells te server which methods the client
supports and the server makes a choice. The server will then send an
`ADMIN_PACKET_SERVER_AUTH_REQUEST` packet to which the client has to respond
with an `ADMIN_PACKET_ADMIN_AUTH_RESPONSE` packet.
The current choices for secure authentication are authorized keys, where
the client has a private key and the server a list of authorized public
keys, and a so-called password-authenticated key exchange which allows to
authenticate using a password without actually sending the password.
The server falls back to password authentication when the client's key is
not in the list of authorized keys.
When authentication has succeeded for either of the `JOIN` schemas, the
server will reply with `ADMIN_PACKET_SERVER_PROTOCOL` followed directly
by `ADMIN_PACKET_SERVER_WELCOME`.
The server will reply with `ADMIN_PACKET_SERVER_PROTOCOL` followed directly by
`ADMIN_PACKET_SERVER_WELCOME`.
`ADMIN_PACKET_SERVER_PROTOCOL` contains details about the protocol version.
It is the job of your application to check this number and decide whether

View File

@@ -1,97 +0,0 @@
# Importing Town Data into OpenTTD
To aid players in scenario creation, OpenTTD's Scenario Editor can import town data from external JSON files. This enables players to use an image editing program to align town coordinates with a real-world heightmap using a map underlay, instead of guessing at the correct locations in Scenario Editor itself.
This town data consists of a JSON file storing an array of town data objects, each containing a name, location, target OpenTTD population, and whether it is marked as a city in the game.
This document describes the standard format for this JSON file and outlines a workflow for creating this data effectively.
## Table of contents
- Why load external data?
- How to use this feature
- Creating geodata
- Town data format standards
- Town data values
- Loading geodata into OpenTTD
- Tutorial: Creating town data
## Why load external data?
There are three benefits to using an image editing program to create towns instead of the OpenTTD Scenario Editor.
1. Placing towns accurately is much easier using a map underlay such as OpenStreetMap to match town locations with the corresponding heightmap.
2. Storing town data in a JSON file instead of as an OpenTTD Scenario (.scn) doesn't require choosing your NewGRF house set before placing towns.
3. Town coordinates are scaled by the map size, so you can load the data onto whatever size map you like.
## How to use this feature
### Creating geodata
Town data is a text file in the JSON format, with a list of towns, each containing a coordinate location and properties: name, population, and whether or not it should be a city in OpenTTD.
The format of this file is standardized for importing into OpenTTD and must be followed for OpenTTD to properly parse the data.
For use in OpenTTD, you will also need a matching heightmap of the terrain features, as a PNG.
#### Town data format standards
The following code sample is complete and can be used in OpenTTD.
- The list of towns is enclosed in an array marked with square brackets `[]`
- Each town is enclosed in curly braces `{}`, with a comma after each town except for the last in the list.
- The properties separated by commas except for the last.
- Property names are enclosed in double quotes `""` with a colon `:` separating it from the property value.
- The name property value is enclosed in double quotes `"London"`, while all other property values `44910`, `true`, etc., are not.
```
[
{
"name": "London",
"population": 44910,
"city": true,
"x": 0.7998046875,
"y": 0.708984375
},
{
"name": "Canterbury",
"population": 217.16,
"city": false,
"x": 0.83251953125,
"y": 0.828125
}
]
```
#### Town data values
- Population is scaled down for use in OpenTTD. It is possible to generate huge cities by using a large number, but there is a practical limit to town size. The larger the town, the longer it will take to import town data, since towns are placed at a relatively small size and then expanded until the population is greater than the player-defined target.
- X and Y coordinates are a proportion of the total map dimension, between 0 and 1. Just take the pixel coordinates of the town's location in the corresponding heightmap (more detail in the tutorial below) and divide each by the maximum value.
- For example, London is at `726, 1638` in a 1024 px by 2048 px heightmap, so `726 / 1024 = 0.7998046875` and `1638 / 2048 = 0.708984375` gives the correct coordinates for OpenTTD.
- The reason for these proportional coordinates is so the data can be used for any map size.
- 0,0 is (approximately) the very top tile in OpenTTD. You can see tile coordinates in-game with the Land Info Tool.
- In most image editing programs, 0,0 is the top-left corner of the image. You can rotate the image however you want relative to compass north to orient the map to your liking. Make sure you crop and resize the image before recording town locations.
- In OpenTTD, X and Y axis are swapped compared to most image editing programs and the standard Cartesian coordinate system. From the 0,0 origin at top left, X is the axis along the left side and Y is the axis along the right side. You can still measure X and Y coordinates in your image editing program, just swap them before importing into OpenTTD or towns won't line up with your heightmap.
### Loading geodata into OpenTTD
Using geodata to create a real-world location in OpenTTD is done in the Scenario Editor.
1. Choose the NewGRFs you want to use in the game.
2. Load the heightmap which you created in the geodata workflow. Either rotation will work, but the clockwise rotation is considered "correct" and the coordinates in the Land Info Tool will match your data; counter clockwise maps will align properly but the coordinates won't match your data.
3. In the Town Generation window, click `Load from file` and choose the .json file containing town data. The default directory to search for town data is `OpenTTD\scenario\heightmap`.
4. (Optional) Manually add industries, rivers, trees, and objects.
5. Save the game as a Scenario and exit to the main menu.
6. Load the game with Play Scenario and enjoy.
Sometimes it's not possible to place a town, such as when the heightmap is very rough and a flat tile can't be found with a 16-tile radius of the target tile. In such cases, a sign will be placed on the target tile with the name of the town. The player can then place the town manually or change the heightmap settings and try again. This fallback also helps debug errors with data creation, such as if towns end up in the ocean.
## Tutorial: Creating town data
1. Load both your heightmap and a labeled map like OpenStreetMap as layers in an image editing program. You can use a free/open-source program like QGIS to acquire, align, and export these map images, if you like.
2. Crop the image to your desired bounds, ensuring the aspect ratio is supported in OpenTTD (1:1, 1:2, 1:4, etc.).
3. Resize the image to one of OpenTTD's supported map sizes, such as 512 px by 1024 px. Some image editors let you do this part of step 2. You can always load heightmaps and town data at a reduced size, so you may want to make this larger than your intended use in case you want it later.
4. Use the labeled map layer to find the pixel coordinates of each town you'd like to include in your map. In GIMP this is displayed in the bottom left corner of the image window, and in Photoshop you need to enable the Info panel (F8) and switch to pixel units of measurement if not already.
5. Some spreadsheets including Google Sheets can export data as JSON, so you may want to record it there, to export after step 8. Or you can build the JSON file manually.
6. Adjust population numbers for OpenTTD.
7. Change coordinates from pixels to proportion (0-1) of the total dimension: `x / maximum_x` and `y / maximum_y`, as described in "Town data values" above.
8. Swap X and Y coordinates before importing to OpenTTD, since OpenTTD uses a reverse X and Y system than most image editors.
9. Save the heightmap and town data files in your `OpenTTD\scenario\heightmap` folder.

View File

@@ -721,9 +721,10 @@
</ul>
</li>
</ul>
<li>m3 bits 6..5 : free</li>
<li>m3 bit 6 : bit 8 of house type (m4), allowing 512 different types.</li>
<li>m3 bit 5 : free</li>
<li>m3 bits 4..0 : triggers activated <a href="#newhouses">(newhouses)</a></li>
<li>m4 : free</li>
<li>m4 : <a href="landscape_externals.html">town building type</a> (with m3[6] bit)</li>
<li>m5 : see m3 bit 7</li>
<li>m6 :
<ul>
@@ -739,7 +740,6 @@
</li>
</ul>
</li>
<li>m6: bits 1..0: animated tile state</li>
<li>m7 :
<ul>
<li>If <a href="#newhouses">newhouses</a> is activated
@@ -759,12 +759,10 @@
</li>
</ul>
</li>
<li>m8 bits 15..12 : free</li>
<li>m8 bits 11..0 : <a href="landscape_externals.html">town building type</a></li>
</ul>
<small><a name="newhouses"></a>Newhouses is the name englobing a newGRF feature developed by TTDPatch devs (mainly Csaboka).<br>
It allows the replacement of the properties as well as the graphics of houses in the game.<br>
To distinguish between the standard behaviour and the newGRF one, HouseID is tested for anything above 110.<br>
To distinguish between the standard behaviour and the newGRF one, HouseID (m4 + m3[6]) is tested for anything above 110.<br>
110 is the count of standard houses. So above 110 means there is a new definition of at least one house</small>
</td>
</tr>
@@ -878,25 +876,6 @@
<li>m2: index into the array of stations</li>
<li>m3 bits 7..4: persistent random data for railway stations/waypoints and airports)</li>
<li>m3 bits 7..4: <a href="#OwnershipInfo">owner</a> of tram tracks (road stop)</li>
<li>m3 bits 3..2: ground type (road waypoints)
<table>
<tr>
<td><tt>0</tt>&nbsp; </td>
<td>on bare land</td>
</tr>
<tr>
<td><tt>1</tt>&nbsp; </td>
<td>on grass</td>
</tr>
<tr>
<td><tt>2</tt>&nbsp; </td>
<td>paved</td>
</tr>
</table>
</li>
<li>m3 bit 2: rail station / waypoint may have catenary pylons</li>
<li>m3 bit 1: rail station / waypoint may have catenary wires</li>
<li>m3 bit 0: rail station / waypoint is blocked</li>
<li>m4: custom station id; 0 means standard graphics</li>
<li>m4: <a href="#RoadType">Roadtype</a> for road stops</li>
<li>m5: graphics index (range from 0..255 for each station type):
@@ -977,22 +956,6 @@
</td>
</tr>
<tr>
<td nowrap valign=top><tt>04</tt>..<tt>05</tt>&nbsp; </td>
<td align=left>road waypoints
<table>
<tr>
<td><tt>04</tt>&nbsp; </td>
<td align=left>drive through X</td>
</tr>
<tr>
<td><tt>05</tt>&nbsp; </td>
<td align=left>drive through Y</td>
</tr>
</table>
</td>
</tr>
<tr>
<td nowrap valign=top><tt>00</tt>..<tt>05</tt>&nbsp; </td>
<td align=left>ship dock
@@ -1026,16 +989,17 @@
</tr>
</table>
</li>
<li>m6 bits 6..3: the station type (rail, airport, truck, bus, oilrig, dock, buoy, waypoint, road waypoint)</li>
<li>m6 bit 7: rail station / waypoint may have catenary pylons</li>
<li>m6 bit 6: rail station / waypoint may have catenary wires</li>
<li>m6 bits 5..3: the station type (rail, airport, truck, bus, oilrig, dock, buoy, waypoint)</li>
<li>m6 bit 2: pbs reservation state for railway stations/waypoints</li>
<li>m6 bits 1..0: animated tile state</li>
<li>m6 bit 0: rail station / waypoint is blocked</li>
<li>m7 bits 4..0: <a href="#OwnershipInfo">owner</a> of road (road stops)</li>
<li>m7: animation frame (railway stations/waypoints, airports)</li>
<li>m8 bit 15: Snow or desert present (road waypoints)</li>
<li>m8 bits 11..6: <a href="#TramType">Tramtype</a></li>
<li>m8 bits 5..0: <a href="#TrackType">track type</a> for railway stations/waypoints</li>
<li>m8 bits 5..0: custom road stop/waypoint id; 0 means standard graphics</li>
<li>m8 bits 5..0: custom road stop id; 0 means standard graphics</li>
</ul>
</td>
</tr>
@@ -1052,94 +1016,99 @@
<li>m1 bits 6..5 : Water class (sea, canal or river)
<li>m1 bits 4..0: <a href="#OwnershipInfo">owner</a> (for sea, rivers, and coasts normally <tt>11</tt>)</li>
<li>m2: Depot index (for depots only)</li>
<li>m3 bit 0: Non-flooding state</li>
<li>m4: Random data for canal or river tiles</li>
<li>m5 bits 7..4: Water tile type:
<li>m5: tile type:
<table>
<tr>
<td><tt>0</tt>&nbsp; </td>
<td>water, canal or river</td>
</tr>
<tr>
<td><tt>1</tt>&nbsp; </td>
<td>coast or riverbank</td>
</tr>
<tr>
<td nowrap valign=top><tt>2</tt>&nbsp; </td>
<td>canal lock<br>
<ul>
<li>m5 bits 3..2: Lock part
<table>
<tr>
<td><tt>0</tt>&nbsp; </td>
<td>Middle part</td>
</tr>
<tr>
<td><tt>1</tt>&nbsp; </td>
<td>Lower part</td>
</tr>
<tr>
<td><tt>2</tt>&nbsp; </td>
<td>Upper part</td>
</tr>
</table>
</li>
<li>m5 bits 1..0: Lock direction
<table>
<tr>
<td><tt>0</tt>&nbsp; </td>
<td>NE raised</td>
</tr>
<tr>
<td><tt>1</tt>&nbsp; </td>
<td>SE raised</td>
</tr>
<tr>
<td><tt>2</tt>&nbsp; </td>
<td>SW raised</td>
</tr>
<tr>
<td><tt>3</tt>&nbsp; </td>
<td>NW raised</td>
</tr>
</table>
</li>
</ul>
</td>
</tr>
<tr>
<td nowrap valign=top><tt>3</tt>&nbsp; </td>
<td>depot<br>
<ul>
<li>m5 bit 1: Depot axis
<table>
<tr>
<td><tt>0</tt>&nbsp; </td>
<td>X direction (NE-SW)</td>
</tr>
<tr>
<td><tt>1</tt>&nbsp; </td>
<td>Y direction (NW-SE)</td>
</tr>
</table>
</li>
<li>m5 bit 0: Depot part
<table>
<tr>
<td><tt>0</tt>&nbsp; </td>
<td>North part</td>
</tr>
<tr>
<td><tt>1</tt>&nbsp; </td>
<td>South part</td>
</tr>
</table>
</li>
</ul>
</td>
</tr>
</table>
</li>
<tr>
<td nowrap valign=top><tt>00</tt>&nbsp; </td>
<td align=left>water, canal or river</td>
</tr>
<tr>
<td nowrap valign=top><tt>01</tt>&nbsp; </td>
<td align=left>coast or riverbank</td>
</tr>
<tr>
<td nowrap valign=top><tt>10</tt>..<tt>1B</tt>&nbsp; </td>
<td align=left>canal locks
<table>
<tr>
<td nowrap valign=top><tt>10</tt>&nbsp; </td>
<td align=left>middle part, (SW-NE direction)</td>
</tr>
<tr>
<td nowrap valign=top><tt>11</tt>&nbsp; </td>
<td align=left>middle part, (NW-SE direction)</td>
</tr>
<tr>
<td nowrap valign=top><tt>12</tt>&nbsp; </td>
<td align=left>middle part, (NE-SW direction)</td>
</tr>
<tr>
<td nowrap valign=top><tt>13</tt>&nbsp; </td>
<td align=left>middle part, (SE-NW direction)</td>
</tr>
<tr>
<td nowrap valign=top><tt>14</tt>&nbsp; </td>
<td align=left>lower part, (SW-NE direction)</td>
</tr>
<tr>
<td nowrap valign=top><tt>15</tt>&nbsp; </td>
<td align=left>lower part, (NW-SE direction)</td>
</tr>
<tr>
<td nowrap valign=top><tt>16</tt>&nbsp; </td>
<td align=left>lower part, (NE-SW direction)</td>
</tr>
<tr>
<td nowrap valign=top><tt>17</tt>&nbsp; </td>
<td align=left>lower part, (SE-NW direction)</td>
</tr>
<tr>
<td nowrap valign=top><tt>18</tt>&nbsp; </td>
<td align=left>upper part, (SW-NE direction)</td>
</tr>
<tr>
<td nowrap valign=top><tt>19</tt>&nbsp; </td>
<td align=left>upper part, (NW-SE direction)</td>
</tr>
<tr>
<td nowrap valign=top><tt>1A</tt>&nbsp; </td>
<td align=left>upper part, (NE-SW direction)</td>
</tr>
<tr>
<td nowrap valign=top><tt>1B</tt>&nbsp; </td>
<td align=left>upper part, (SE-NW direction)</td>
</tr>
</table>
</td>
</tr>
<tr>
<td nowrap valign=top><tt>80</tt>..<tt>83</tt>&nbsp; </td>
<td align=left>ship depots
<table>
<tr>
<td nowrap valign=top><tt>80</tt>&nbsp; </td>
<td align=left>ship depot, NE part (X direction)</td>
</tr>
<tr>
<td nowrap valign=top><tt>81</tt>&nbsp; </td>
<td align=left>ship depot, SW part (X direction)</td>
</tr>
<tr>
<td nowrap valign=top><tt>82</tt>&nbsp; </td>
<td align=left>ship depot, NW part (Y direction)</td>
</tr>
<tr>
<td nowrap valign=top><tt>83</tt>&nbsp; </td>
<td align=left>ship depot, SE part (Y direction)</td>
</tr>
</table>
</td>
</tr>
</table>
</li>
</ul>
</td>
@@ -1482,7 +1451,6 @@
</li>
<li>m6 bits 5..3: random triggers (NewGRF)</li>
<li>m6 bit 2: bit 8 of type (see m5)</li>
<li>m6 bits 1..0: animated tile state</li>
<li>m7: animation frame</li>
</ul>
</td>
@@ -1655,7 +1623,6 @@
<li>m2: index into the array of objects, bits 0 to 15 (upper bits in m5)</li>
<li>m3: random bits</li>
<li>m5: index into the array of objects, bits 16 to 23 (lower bits in m2)</li>
<li>m6 bits 1..0: animated tile state</li>
<li>m7: animation counter</li>
</ul>
</td>

View File

@@ -79,8 +79,8 @@ the array so you can quickly see what is used and what is not.
<tr>
<td rowspan="2">0</td>
<td class="caption">ground</td>
<td class="bits" rowspan=29><span class="used" title="Tile type">XXXX</span> <span class="used" title="Presence and direction of bridge above">XX</span> <span class="used" title="Tropic Zone: only meaningful in tropic climate. It contains the definition of the available zones">XX</span></td>
<td class="bits" rowspan=29><span class="used" title="Tile height">XXXX XXXX</span></td>
<td class="bits" rowspan=27><span class="used" title="Tile type">XXXX</span> <span class="used" title="Presence and direction of bridge above">XX</span> <span class="used" title="Tropic Zone: only meaningful in tropic climate. It contains the definition of the available zones">XX</span></td>
<td class="bits" rowspan=27><span class="used" title="Tile height">XXXX XXXX</span></td>
<td class="bits" rowspan=2><span class="free">OOO</span><span class="usable" title="Owner (always OWNER_NONE)">1 OOOO</span></td>
<td class="bits"><span class="free">OOOO OOOO OOOO OOOO</span></td>
<td class="bits"><span class="used" title="Type of hedge on NE border">XXX</span> <span class="used" title="Snow presence">X</span><span class="free">OOOO</span></td>
@@ -130,7 +130,7 @@ the array so you can quickly see what is used and what is not.
<td class="bits"><span class="used" title="Tile type: simple road (00), level crossing (01), road depot (10)">OO</span> <span class="used" title="Disallow vehicles to go a specific direction">XX</span> <span class="used" title="Road pieces">XXXX</span></td>
<td class="bits"><span class="free">OO</span> <span class="used" title="Pavement type">XXX</span><span class="free">OOO</span></td>
<td class="bits"><span class="free">OO</span><span class="used" title="Snow/desert present">X</span> <span class="free">O</span><span class="used" title="Roadworks counter">XXXX</span></td>
<td class="bits" rowspan=1><span class="free">OOOO</span> <span class="used" title="Tram type">XXXX XX</span><span class="free">OO OOOO</span></td>
<td class="bits" rowspan=1><span class="free">OOOO</span> <span class="used" title="Tram type">XXXX XX<span class="free">OO OOOO</span></td>
</tr>
<tr>
<td class="caption">level crossing</td>
@@ -156,17 +156,17 @@ the array so you can quickly see what is used and what is not.
<td class="caption">finished house</td>
<td class="bits" rowspan=2><span class="used" title="House random bits">XXXX XXXX</span></td>
<td class="bits" rowspan=2><span class="pool" title="Town index on pool">XXXX XXXX XXXX XXXX</span></td>
<td class="bits"><span class="used" title="House is complete/in construction (see m5)">1</span><span class="free">OO</span><span class="usable" title="Activated triggers (bits 2..4 don't have a meaning)">X XX</span><span class="used" title="Activated triggers (bits 2..4 don't have a meaning)">XX</span></td>
<td class="bits" rowspan=2><span class="free">OOOO OOOO</span></td>
<td class="bits"><span class="used" title="House is complete/in construction (see m5)">1</span> <span class="used" title="House type (m4 + m3[6])">X</span><span class="free">O</span><span class="usable" title="Activated triggers (bits 2..4 don't have a meaning)">XXX</span><span class="used" title="Activated triggers (bits 2..4 don't have a meaning)">XX</span></td>
<td class="bits" rowspan=2><span class="used" title="House type (m4 + m3[6])">XXXX XXXX</span></td>
<td class="bits"><span class="used" title="Age in years, clamped at 255">XXXX XXXX</span></td>
<td class="bits" rowspan=2><span class="abuse" title="Newhouses activated: periodic processing time remaining; if not, lift position for houses 04 and 05">XXXX XX</span><span class="used" title="Animated tile state">XX</span></td>
<td class="bits" rowspan=2><span class="abuse" title="Newhouses activated: periodic processing time remaining; if not, lift position for houses 04 and 05">XXXX XX</span><span class="free">OO</span></td>
<td class="bits" rowspan=2><span class="abuse" title="If newhouses active, m7 is the current animation frame">XXXX</span> <span class="abuse" title="If newhouses active, m7 is the current animantion frame; if not, lift behaviour for houses 04 and 05">XXXX</span></td>
<td class="bits" rowspan=2><span class="free">OOOO</span> <span class="used" title="House type">XXXX XXXX XXXX</span></td>
<td class="bits" rowspan=2><span class="free">OOOO OOOO OOOO OOOO</span></td>
</tr>
<tr>
<td class="caption">house under construction</td>
<td class="bits"><span class="used" title="House is complete/in construction (see m5)">O</span><span class="used" title="House type (m4 + m3[6])">X</span><span class="free">O</span><span class="usable" title="Activated triggers (bits 2..4 don't have a meaning)">X XX</span><span class="used" title="Activated triggers (bits 2..4 don't have a meaning)">XX</span></td>
<td class="bits"><span class="free">OOO</span><span class="used" title="Construction stage">X X</span><span class="used" title="Construction counter">XXX</span></td>
<td class="bits"><span class="used" title="House is complete/in construction (see m5)">O</span> <span class="used" title="House type (m4 + m3[6])">X</span><span class="free">O</span><span class="usable" title="Activated triggers (bits 2..4 don't have a meaning)">XXX</span><span class="used" title="Activated triggers (bits 2..4 don't have a meaning)">XX</span></td>
<td class="bits"><span class="free">OOO</span><span class="used" title="Construction stage">XX</span> <span class="used" title="Construction counter">XXX</span></td>
</tr>
<tr>
<td>4</td>
@@ -181,14 +181,14 @@ the array so you can quickly see what is used and what is not.
<td class="bits"><span class="free">OOOO OOOO OOOO OOOO</span></td>
</tr>
<tr>
<td rowspan=8>5</td>
<td rowspan=7>5</td>
<td class="caption">rail station</td>
<td class="bits" rowspan=8><span class="free">O</span><span class="used" title="Water class">XX</span> <span class="used" title="Owner">XXXXX</span></td>
<td class="bits" rowspan=8><span class="pool" title="Station index on pool">XXXX XXXX XXXX XXXX</span></td>
<td class="bits" rowspan=2><span class="used" title="Random bits">XXXX</span> <span class="free">O</span><span class="used" title="May have pylons">X</span><span class="used" title="May have wires">X</span><span class="used" title="Tile is blocked">X</span></td>
<td class="bits" rowspan=7><span class="free">O</span><span class="used" title="Water class">XX</span> <span class="used" title="Owner">XXXXX</span></td>
<td class="bits" rowspan=7><span class="pool" title="Station index on pool">XXXX XXXX XXXX XXXX</span></td>
<td class="bits" rowspan=2><span class="used" title="Random bits">XXXX</span> <span class="free">OOOO</span></td>
<td class="bits" rowspan=2><span class="used" title="Custom station specifications ID">XXXX XXXX</span></td>
<td class="bits"><span class="used" title="Graphics index">XXXX XXXX</span></td>
<td class="bits" rowspan=2><span class="free">O</span><span class="used" title="Station type">XXX X</span><span class="used" title="Reserved track">X</span><span class="used" title="Animated tile state">XX</span></td>
<td class="bits" rowspan=2><span class="used" title="May have pylons">X</span><span class="used" title="May have wires">X</span><span class="used" title="Station type">XXX</span> <span class="used" title="Reserved track">X</span><span class="free">O</span><span class="used" title="Tile is blocked">X</span></td>
<td class="bits" rowspan=2><span class="used" title="Animation frame">XXXX XXXX</span></td>
<td class="bits" rowspan=2><span class="free">OOOO OOOO OO</span><span class="used" title="Railway type">XX XXXX</span></td>
</tr>
@@ -199,17 +199,12 @@ the array so you can quickly see what is used and what is not.
<tr>
<td class="caption">road stop</td>
<td class="bits"><span class="used" title="Owner of tram">XXXX</span> <span class="free">OOOO</span></td>
<td class="bits" rowspan=2><span class="free">OO</span><span class="used" title="Roadtype for road stop">XX XXXX</span></td>
<td class="bits" rowspan=2><span class="usable" title="Graphics index">OOOO O</span><span class="used" title="Graphics index: 00 (exit towards NE), 01 (exit towards SE), 02 (exit towards SW), 03 (exit towards NW), 04 (drive through X), 05 (drive through Y)">XXX</span></td>
<td class="bits" rowspan=6><span class="free">O</span><span class="used" title="Station type">XXX X</span><span class="free">O</span><span class="used" title="Animated tile state">XX</span></td>
<td class="bits" rowspan=2><span class="free">OOO</span><span class="used" title="Owner of road">X XXXX</span></td>
<td class="bits"><span class="free">OO</span><span class="used" title="Roadtype for road stop">XX XXXX</span></td>
<td class="bits"><span class="usable" title="Graphics index">OOOO O</span><span class="used" title="Graphics index: 00 (exit towards NE), 01 (exit towards SE), 02 (exit towards SW), 03 (exit towards NW), 04 (drive through X), 05 (drive through Y)">XXX</span></td>
<td class="bits" rowspan=5><span class="free">OO</span><span class="used" title="Station type">XX X</span><span class="free">OOO</span></td>
<td class="bits"><span class="free">OOO</span><span class="used" title="Owner of road">X XXXX</span></td>
<td class="bits"><span class="free">OOOO</span> <span class="used" title="Tram type">XXXX XX</span> <span class="used" title="Custom road stops specifications ID">XXXXXX</span></td>
</tr>
<tr>
<td class="caption">road waypoint</td>
<td class="bits"><span class="used" title="Owner of tram">XXXX</span> <span class="used" title="Pavement type">XX</span><span class="free">OO</span></td>
<td class="bits"><span class="used" title="Snow/desert present">X</span><span class="free">OOO</span> <span class="used" title="Tram type">XXXX XX</span> <span class="used" title="Custom road stops specifications ID">XXXXXX</span></td>
</tr>
<tr>
<td class="caption">airport</td>
<td class="bits"><span class="used" title="Random bits">XXXX</span> <span class="free">OOOO</span></td>
@@ -240,37 +235,32 @@ the array so you can quickly see what is used and what is not.
<td class="bits"><span class="free">OOOO OOOO</span></td>
</tr>
<tr>
<td rowspan=5>6</td>
<td class="caption">sea</td>
<td class="bits" rowspan=5><span class="used" title="Ship docking tile status">X</span> <span class="used" title="Water class">XX</span> <span class="used" title="Owner">XXXXX</span></td>
<td class="bits" rowspan=4><span class="free">OOOO OOOO OOOO OOOO</span></td>
<td class="bits" rowspan=5><span class="free">OOOO OOO</span><span class="used" title="Non-flooding state">X</span></td>
<td rowspan=4>6</td>
<td class="caption">sea, shore</td>
<td class="bits" rowspan=4><span class="used" title="Ship docking tile status">X</span> <span class="used" title="Water class">XX</span> <span class="used" title="Owner">XXXXX</span></td>
<td class="bits" rowspan=3><span class="free">OOOO OOOO OOOO OOOO</span></td>
<td class="bits" rowspan=4><span class="free">OOOO OOOO</span></td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
<td class="bits"><span class="used" title="Water tile type: coast, clear, lock, depot">0000</span> <span class="free">OOO0</span></td>
<td class="bits" rowspan=5><span class="free">OOOO OOOO</span></td>
<td class="bits" rowspan=5><span class="free">OOOO OOOO</span></td>
<td class="bits" rowspan=5><span class="free">OOOO OOOO OOOO OOOO</span></td>
<td class="bits"><span class="used" title="Water tile type: coast, clear, lock, depot">O<span class="usable">OO</span>O</span> <span class="free">OOO</span><span class="used" title="Sea shore flag">X</span></td>
<td class="bits" rowspan=4><span class="free">OOOO OOOO</span></td>
<td class="bits" rowspan=4><span class="free">OOOO OOOO</td>
<td class="bits" rowspan=4><span class="free">OOOO OOOO OOOO OOOO</span></td>
</tr>
<tr>
<td class="caption">canal, river</td>
<td class="bits"><span class="used" title="Canal/river random bits">XXXX XXXX</span></td>
<td class="bits"><span class="used" title="Water tile type: coast, clear, lock, depot">0000</span> <span class="free">OOOO</span></td>
</tr>
<tr>
<td class="caption">shore</td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
<td class="bits"><span class="used" title="Water tile type: coast, clear, lock, depot">0001</span> <span class="free">OOOO</span></td>
<td class="bits"><span class="used" title="Water tile type: coast, clear, lock, depot">O<span class="usable">OO</span>O</span> <span class="free">OOOO</span></td>
</tr>
<tr>
<td class="caption">lock</td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
<td class="bits"><span class="used" title="Water tile type: coast, clear, lock, depot">0010</span> <span class="used" title="Lock part">XX</span><span class="used" title="Lock orientation m5[1..0]">XX</span></td>
<td class="bits"><span class="used" title="Water tile type: coast, clear, lock, depot">O<span class="usable">OO</span>1</span> <span class="used" title="Lock part">XX</span> <span class="used" title="Lock orientation m5[1..0]">XX</span></td>
</tr>
<tr>
<td class="caption">shipdepot</td>
<td class="bits"><span class="pool" title="Depot index on pool">XXXX XXXX XXXX XXXX</span></td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
<td class="bits"><span class="used" title="Water tile type: coast, clear, lock, depot">0011</span> <span class="free">OO</span><span class="used" title="Depot axis">X</span><span class="used" title="Depot part">X</span></td>
<td class="bits"><span class="used" title="Water tile type: coast, clear, lock, depot">1<span class="usable">OOO</span></span> <span class="free">OO</span><span class="used" title="Depot axis">X</span> <span class="used" title="Depot part">X</span></td>
</tr>
<tr>
<td rowspan=2>8</td>
@@ -280,7 +270,7 @@ the array so you can quickly see what is used and what is not.
<td class="bits" rowspan=2><span class="used" title="Random bits">XXXX XXXX</span></td>
<td class="bits" rowspan=2><span class="used" title="Animation loop">XXXX XXXX</span></td>
<td class="bits" rowspan=2><span class="used" title="Industry graphics ID (m5 + m6[2])">XXXX XXXX</span></td>
<td class="bits" rowspan=2><span class="free">OO</span><span class="used" title="Random triggers (NewGRF)">XXX</span> <span class="used" title="Industry graphics ID (m5 + m6[2])">X</span><span class="used" title="Animated tile state">XX</span></td>
<td class="bits" rowspan=2><span class="free">OO</span><span class="used" title="Random triggers (NewGRF)">XXX</span> <span class="used" title="Industry graphics ID (m5 + m6[2])">X</span><span class="free">OO</span></td>
<td class="bits" rowspan=2><span class="used" title="Animation frame">XXXX XXXX</span></td>
<td class="bits" rowspan=2><span class="free">OOOO OOOO OOOO OOOO</span></td>
</tr>
@@ -313,7 +303,7 @@ the array so you can quickly see what is used and what is not.
<td class="bits"><span class="used" title="Random bits">XXXX XXXX</span></td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
<td class="bits"><span class="pool" title="Object index on pool (m2 + m5)">XXXX XXXX</span></td>
<td class="bits"><span class="free">OOOO OO</span><span class="used" title="Animated tile state">XX</span></td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
<td class="bits"><span class="used" title="Animation counter">XXXX XXXX</span></td>
<td class="bits" rowspan=1><span class="free">OOOO OOOO OOOO OOOO</span></td>
</tr>

View File

@@ -20,7 +20,7 @@ This guide is for OpenTTD developers/maintainers, to release a new version of Op
## Step 1: Prepare changelog documentation
1. Update the [changelog](../changelog.md) with new changes since the last release.
1. Update the [changelog](../changelog.txt) with new changes since the last release.
* Changelog entries are typically PR titles, but can be edited to be more helpful without context.
* Don't include fixes to things which haven't previously been released (like fixes to features which are in the same changelog).
* Order the entries by importance: `Feature > Add > Change > Fix`, then numerically by PR number.

View File

@@ -1,426 +0,0 @@
# OpenTTD's known bugs
## Table of contents
- 1.0) About
- 2.0) Known bugs
## 1.0) About
All bugs listed below are marked as known. Please do not submit any bugs
that are the same as these. If you do, do not act surprised, because
we WILL flame you!
The current list of known bugs that we intend to fix can be found in our
bug tracking system at https://github.com/OpenTTD/OpenTTD/issues
Also check the closed bugs when searching for your bug in this system as we
might have fixed the bug in the mean time.
## 2.0) Known bugs
This section lists all known bugs that we do not intend to fix and the
reasons why we think that fixing them is infeasible. We might make some
minor improvements that reduce the scope of these bugs, but we will not
be able to completely fix them.
### No suitable AI can be found:
If you have no AIs and an AI is started the so-called 'dummy' AI will
be loaded. This AI does nothing but writing a message on the AI debug
window and showing a red warning. There are basically two solutions
for this problem: Either you set the number of AI players to 0 so that
no AI is started. You find that setting at the top of the window in the
"AI / Game Scripts Settings" window.
The other solution is acquiring (downloading) some AI. The easiest way
to do this is via the "Check Online Content" button in the main (intro)
menu or directly in the "AI / Game Scripts Settings" dialogue via the
"Check Online Content" button.
### After a while of playing, colours get corrupted:
In Windows 7 the background slideshow corrupts the colour mapping
of OpenTTD's 8bpp screen modes. Workarounds for this are:
* Switching to windowed mode, instead of fullscreen
* Switching off background slideshow
* Setting up the `32bpp-anim` or `32bpp-optimized` blitter
### Custom vehicle type name is incorrectly aligned:
Some NewGRFs use sprites that are bigger than normal in the "buy
vehicle" window. Due to this they have to encode an offset for
the vehicle type name. Upon renaming the vehicle type this encoded
offset is stripped from the name because the "edit box" cannot show
this encoding. As a result the custom vehicle type names will get
the default alignment. The only way to (partially) fix this is by
adding spaces to the custom name.
### Clipping problems [#119]:
In some cases sprites are not drawn as one would expect. Examples of
this are aircraft that might be hidden below the runway or trees that
in some cases are rendered over vehicles.
The primary cause of this problem is that OpenTTD does not have enough
data (like a 3D model) to properly determine what needs to be drawn in
front of what. OpenTTD has bounding boxes but in lots of cases they
are either too big or too small and then cause problems with what
needs to be drawn in front of what. Also some visual tricks are used.
For example trains at 8 pixels high, the catenary needs to be drawn
above that. When you want to draw bridges on top of that, which are
only one height level (= 8 pixels) higher, you are getting into some
big problems.
We can not change the height levels; it would require us to either
redraw all vehicle or all landscape graphics. Doing so would mean we
leave the Transport Tycoon graphics, which in effect means OpenTTD
will not be a Transport Tycoon clone anymore.
### Mouse scrolling not possible at the edges of the screen [#383] [#3966]:
Scrolling the viewport with the mouse cursor at the edges of the screen
in the same direction of the edge will fail. If the cursor is near the
edge the scrolling will be very slow.
OpenTTD only receives cursor position updates when the cursor is inside
OpenTTD's window. It is not told how far you have moved the cursor
outside of OpenTTD's window.
### Lost trains ignore (block) exit signals [#1473]:
If trains are lost they ignore block exit signals, blocking junctions
with presignals. This is caused because the path finders cannot tell
where the train needs to go. As such a random direction is chosen at
each junction. This causes the trains to occasionally to make choices
that are unwanted from a player's point of view.
This will not be fixed because lost trains are in almost all cases a
network problem, e.g. a train can never reach a specific place. This
makes the impact of fixing the bug enormously small against the amount
of work needed to write a system that prevents the lost trains from
taking the wrong direction.
### Vehicle owner of last transfer leg gets paid for all [#2427]:
When you make a transfer system that switches vehicle owners. This
is only possible with 'industry stations', e.g. the oil rig station
the owner of the vehicle that does the final delivery gets paid for
the whole trip. It is not shared amongst the different vehicle
owners that have participated in transporting the cargo.
This sharing is not done because it would enormously increase the
memory and CPU usage in big games for something that is happening
in only one corner case. We think it is not worth the effort until
sharing of stations is an official feature.
### Forbid 90 degree turns does not work for crossing PBS paths [#2737]:
When you run a train through itself on a X junction with PBS turned on
the train will not obey the 'forbid 90 degree turns' setting. This is
due to the fact that we can not be sure that the setting was turned
off when the track was reserved, which means that we assume it was
turned on and that the setting does not hold at the time. We made it
this way to allow one to change the setting in-game, but it breaks
slightly when you are running your train through itself. Running a
train through means that your network is broken and is thus a user
error which OpenTTD tries to graciously handle.
Fixing this bug means that we need to record whether this particular
setting was turned on or off at the time the reservation was made. This
means adding quite a bit of data to the savegame for solving an issue
that is basically an user error. We think it is not worth the effort.
### Duplicate (station) names after renaming [#3204]:
After renaming stations one can create duplicate station names. This
is done giving a station the same custom name as another station with
an automatically generated name.
The major part of this problem is that station names are translatable.
Meaning that a station is called e.g. '<TOWN> Central' in English and
'<TOWN> Centraal' in Dutch. This means that in network games the
renaming of a town could cause the rename to succeed on some clients
and fail at others. This creates an inconsistent game state that will
be seen as a 'desync'. Secondly the custom names are intended to fall
completely outside of the '<TOWN> <name>' naming of stations, so when
you rename a town all station names are updated accordingly.
As a result the decision has been made that all custom names are only
compared to the other custom names in the same class and not compared
to the automatically generated names.
### Extreme CPU usage/hangs when using SDL and PulseAudio [#3294], OpenTTD hangs/freezes when closing, OpenTTD is slow, OpenTTD uses a lot of CPU:
OpenTTD can be extremely slow/use a lot of CPU when the sound is
played via SDL and then through PulseAudio's ALSA wrapper. Under the
same configuration OpenTTD, or rather SDL, might hang when exiting
the game. This problem is seen most in Ubuntu 9.04 and higher.
This is because recent versions of the PulseAudio sound server
are configured to use timer-based audio scheduling rather than
interrupt-based audio scheduling. Configuring PulseAudio to force
use of interrupt-based scheduling may resolve sound problems for
some users. Under recent versions of Ubuntu Linux (9.04 and higher)
this can be accomplished by changing the following line in the
`/etc/pulse/default.pa` file:
`load-module module-udev-detect`
to
`load-module module-udev-detect tsched=0`
Note that PulseAudio must be restarted for changes to take effect. Older
versions of PulseAudio may use the module-hal-detect module instead.
Adding tsched=0 to the end of that line will have a similar effect.
Another possible solution is selecting the "pulse" backend of SDL
by either using `SDL_AUDIODRIVER=pulse openttd` at the command
prompt or installing the `libsdl1.2debian-pulseaudio` package from
Ubuntu's Universe repository. For other distributions a similar
package needs to be installed.
### OpenTTD not properly resizing with SDL on X [#3305]:
Under some X window managers OpenTTD's window does not properly
resize. You will either end up with a black bar at the right/bottom
side of the window or you cannot see the right/bottom of the window,
e.g. you cannot see the status bar. The problem is that OpenTTD does
not always receive a resize event from SDL making it impossible for
OpenTTD to know that the window was resized; sometimes moving the
window will solve the problem.
Window managers that are known to exhibit this behaviour are GNOME's
and KDE's. With the XFCE's and LXDE's window managers the resize
event is sent when the user releases the mouse.
### Incorrect colours, crashes upon exit, debug warnings and smears upon window resizing with SDL on macOS [#3447]:
Video handling with (lib)SDL under macOS is known to fail on some
versions of macOS with some hardware configurations. Some of
the problems happen only under some circumstances whereas others
are always present.
We suggest that the SDL video/sound backend is not used for OpenTTD
in combinations with macOS.
### Train crashes entering same junction from block and path signals [#3928]:
When a train has reserved a path from a path signal to a two way
block signal and the reservation passes a path signal through the
back another train can enter the reserved path (only) via that
same two way block signal.
The reason for this has to do with optimisation; to fix this issue
the signal update has to pass all path signals until it finds either
a train or a backwards facing signal. This is a very expensive task.
The (signal) setups that allow these crashes can furthermore be
considered incorrectly signalled; one extra safe waiting point for
the train entering from path signal just after the backwards facing
signal (from the path signal train) resolves the issue.
### Crashes when run in a VM using Parallels Desktop [#4003]:
When the Windows version of OpenTTD is executed in a VM under
Parallels Desktop a privileged instruction exception may be thrown.
As OpenTTD works natively on macOS as well as natively on Windows and
these native builds both don't exhibit this behaviour this crash is
most likely due to a bug in the virtual machine, something out of
the scope of OpenTTD. Most likely this is due to Parallels Desktop
lacking support for RDTSC calls. The problem can be avoided by using
other VM-software, Wine, or running natively on macOS.
### Entry- and exit signals are not dragged [#4378]:
Unlike all other signal types, the entry- and exit signals are not
dragged but instead normal signals are placed on subsequent track
sections. This is done on purpose as this is the usually more
convenient solution. There are little to no occasions where more
than one entry or exit signal in a row are useful. This is different
for all other signal types where several in a row can serve one
purpose or another.
### (Temporary) wrong colours when switching to full screen [#4511]:
On Windows it can happen that you temporarily see wrong colours
when switching to full screen OpenTTD, either by starting
OpenTTD in full screen mode, changing to full screen mode or by
ALT-TAB-ing into a full screen OpenTTD. This is caused by the
fact that OpenTTD, by default, uses 8bpp paletted output. The
wrong colours you are seeing is a temporary effect of the video
driver switching to 8bpp palette mode.
This issue can be worked around in two ways:
* Setting fullscreen_bpp to 32
* Setting up the 32bpp-anim or 32bpp-optimized blitter
### Can't run OpenTTD with the -d option from a MSYS console [#4587]:
The MSYS console does not allow OpenTTD to open an extra console for
debugging output. Compiling OpenTTD with the --enable-console
configure option prevents this issue and allows the -d option to use
the MSYS console for its output.
### Unreadable characters for non-latin locales [#4607]:
OpenTTD does not ship a non-latin font in its graphics files. As a
result OpenTTD needs to acquire the font from somewhere else. What
OpenTTD does is ask the operating system, or a system library, for
the best font for a given language if the currently loaded font
does not provide all characters of the chosen translation. This
means that OpenTTD has no influence over the quality of the chosen
font; it just does the best it can do.
If the text is unreadable there are several steps that you can take
to improve this. The first step is finding a good font and configure
this in the configuration file. See section 9.0 of README.md for
more information. You can also increase the font size to make the
characters bigger and possible better readable.
If the problem is with the clarity of the font you might want to
enable anti-aliasing by setting the small_aa/medium_aa/large_aa
settings to "true". However, anti-aliasing only works when a 32-bit
blitter has been selected, e.g. `blitter = "32bpp-anim"`, as with the
8 bits blitter there are not enough colours to properly perform the
anti-aliasing.
### Train does not crash with itself [#4635]:
When a train drives in a circle the front engine passes through
wagons of the same train without crashing. This is intentional.
Signals are only aware of tracks, they do not consider the train
length and whether there would be enough room for a train in some
circle it might drive on. Also the path a train might take is not
necessarily known when passing a signal.
Checking all circumstances would take a lot of additional
computational power for signals, which is not considered worth
the effort, as it does not add anything to gameplay.
Nevertheless trains shall not crash in normal operation, so making
a train not crash with itself is the best solution for everyone.
### Aircraft coming through wall in rotated airports [#4705]:
With rotated airports, specifically hangars, you will see that the
aircraft will show a part through the back wall of the hangar.
This can be solved by only drawing a part of the plane when being
at the back of the hangar, however then with transparency turned on
the aircraft would be shown partially which would be even weirder.
As such the current behaviour is deemed the least bad.
The same applies to overly long ships and their depots.
### Vehicles not keeping their "maximum" speed [#4815]:
Vehicles that have not enough power to reach and maintain their
advertised maximum speed might be constantly jumping between two
speeds. This is due to the fact that speed and its calculations
are done with integral numbers instead of floating point numbers.
As a result of this a vehicle will never reach its equilibrium
between the drag/friction and propulsion. So in effect it will be
in a vicious circle of speeding up and slowing down due to being
just at the other side of the equilibrium.
Not speeding up when near the equilibrium will cause the vehicle to
never come in the neighbourhood of the equilibrium and not slowing
down when near the equilibrium will cause the vehicle to never slow
down towards the equilibrium once it has come down a hill.
It is possible to calculate whether the equilibrium will be passed,
but then all acceleration calculations need to be done twice.
### Settings not saved when OpenTTD crashes [#4846]:
The settings are not saved when OpenTTD crashes for several reasons.
The most important is that the game state is broken and as such the
settings might contain invalid values, or the settings have not even
been loaded yet. This would cause invalid or totally wrong settings
to be written to the configuration file.
A solution to that would be saving the settings whenever one changes,
however due to the way the configuration file is saved this requires
a flush of the file to the disk and OpenTTD needs to wait till that
is finished. On some file system implementations this causes the
flush of all 'write-dirty' caches, which can be a significant amount
of data to be written. This can further be aggravated by spinning
down disks to conserve power, in which case this disk needs to be
spun up first. This means that many seconds may pass before the
configuration file is actually written, and all that time OpenTTD
will not be able to show any progress. Changing the way the
configuration file is saved is not an option as that leaves us more
vulnerable to corrupt configuration files.
Finally, crashes should not be happening. If they happen they should
be reported and fixed, so essentially fixing this is fixing the wrong
thing. If you really need the configuration changes to be saved,
and you need to run a version that crashes regularly, then you can
use the `saveconfig` command in the console to save the settings.
### Not all NewGRFs, AIs, game scripts are found [#4887]:
Under certain situations, where the path for the content within a
tar file is the same as other content on the file system or in another
tar file, it is possible that content is not found. A more thorough
explanation and solutions are described in section 4.4 of README.md.
### Mouse cursor going missing with SDL [#4997]:
Under certain circumstances SDL does not notify OpenTTD of changes with
respect to the mouse pointer, specifically whether the mouse pointer
is within the bounds of OpenTTD or not. For example, if you "Alt-Tab"
to another application the mouse cursor will still be shown in OpenTTD,
and when you move the mouse outside of the OpenTTD window so the cursor
gets hidden, open/move another application on top of the OpenTTD window
and then Alt-tab back into OpenTTD the cursor will not be shown.
We cannot fix this problem as SDL simply does not provide the required
information in these corner cases. This is a bug in SDL and as such
there is little that we can do about it.
### Trains might not stop at platforms that are currently being changed [#5553]:
If you add tiles to or remove tiles from a platform while a train is
approaching to stop at the same platform, that train can miss the place
where it's supposed to stop and pass the station without stopping.
This is caused by the fact that the train is considered to already
have stopped if it's beyond its assigned stopping location. We can't
let the train stop just anywhere in the station because then it would
never leave the station if you have the same station in the order
list multiple times in a row or if there is only one station
in theorder list (see #5684).
### Some houses and industries are not affected by transparency [#5817]:
Some of the default houses and industries (f.e. the iron ore mine) are
not affected by the transparency options. This is because the graphics
do not (completely) separate the ground from the building.
This is a bug of the original graphics, and unfortunately cannot be
fixed with OpenGFX for the sake of maintaining compatibility with
the original graphics.
### Involuntary cargo exchange with cargodist via neutral station [#6114]:
When two players serve a neutral station at an industry, a cross-company
chain for cargo flow can and will be established which can only be
interrupted if one of the players stops competing for the resources of
that industry. There is an easy fix for this: If you are loading at the
shared station make the order "no unload" and if you're unloading make
it "no load". Cargodist will then figure out that it should not create
such a route.
### Incorrect ending year displayed in end of game newspaper [#8625]
The ending year of the game is configurable, but the date displayed in
the newspaper at the end of the game is part of the graphics, not text.
So to fix this would involve fixing the graphics in every baseset,
including the original. Additionally, basesets are free to put this
text in different positions (which they do), making a proper solution
to this infinitely more complex for a part of the game that fewer than
1% of players ever see.

389
known-bugs.txt Normal file
View File

@@ -0,0 +1,389 @@
OpenTTD's known bugs
------------------------------------------------------------------------
Table of contents
-----------------
1.0) About
2.0) Known bugs
1.0) About
---- -----
All bugs listed below are marked as known. Please do not submit any bugs
that are the same as these. If you do, do not act surprised, because
we WILL flame you!
The current list of known bugs that we intend to fix can be found in our
bug tracking system at https://github.com/OpenTTD/OpenTTD/issues
Also check the closed bugs when searching for your bug in this system as we
might have fixed the bug in the mean time.
2.0) Known bugs
---- ----------------------------------
This section lists all known bugs that we do not intend to fix and the
reasons why we think that fixing them is infeasible. We might make some
minor improvements that reduce the scope of these bugs, but we will not
be able to completely fix them.
No suitable AI can be found:
If you have no AIs and an AI is started the so-called 'dummy' AI will
be loaded. This AI does nothing but writing a message on the AI debug
window and showing a red warning. There are basically two solutions
for this problem: Either you set the number of AI players to 0 so that
no AI is started. You find that setting at the top of the window in the
"AI / Game Scripts Settings" window.
The other solution is acquiring (downloading) some AI. The easiest way
to do this is via the "Check Online Content" button in the main (intro)
menu or directly in the "AI / Game Scripts Settings" dialogue via the
"Check Online Content" button.
After a while of playing, colours get corrupted:
In Windows 7 the background slideshow corrupts the colour mapping
of OpenTTD's 8bpp screen modes. Workarounds for this are:
a) Switching to windowed mode, instead of fullscreen
b) Switching off background slideshow
c) Setting up the 32bpp-anim or 32bpp-optimized blitter
Custom vehicle type name is incorrectly aligned:
Some NewGRFs use sprites that are bigger than normal in the "buy
vehicle" window. Due to this they have to encode an offset for
the vehicle type name. Upon renaming the vehicle type this encoded
offset is stripped from the name because the "edit box" cannot show
this encoding. As a result the custom vehicle type names will get
the default alignment. The only way to (partially) fix this is by
adding spaces to the custom name.
Clipping problems [#119]:
In some cases sprites are not drawn as one would expect. Examples of
this are aircraft that might be hidden below the runway or trees that
in some cases are rendered over vehicles.
The primary cause of this problem is that OpenTTD does not have enough
data (like a 3D model) to properly determine what needs to be drawn in
front of what. OpenTTD has bounding boxes but in lots of cases they
are either too big or too small and then cause problems with what
needs to be drawn in front of what. Also some visual tricks are used.
For example trains at 8 pixels high, the catenary needs to be drawn
above that. When you want to draw bridges on top of that, which are
only one height level (= 8 pixels) higher, you are getting into some
big problems.
We can not change the height levels; it would require us to either
redraw all vehicle or all landscape graphics. Doing so would mean we
leave the Transport Tycoon graphics, which in effect means OpenTTD
will not be a Transport Tycoon clone anymore.
Mouse scrolling not possible at the edges of the screen [#383] [#3966]:
Scrolling the viewport with the mouse cursor at the edges of the screen
in the same direction of the edge will fail. If the cursor is near the
edge the scrolling will be very slow.
OpenTTD only receives cursor position updates when the cursor is inside
OpenTTD's window. It is not told how far you have moved the cursor
outside of OpenTTD's window.
Lost trains ignore (block) exit signals [#1473]:
If trains are lost they ignore block exit signals, blocking junctions
with presignals. This is caused because the path finders cannot tell
where the train needs to go. As such a random direction is chosen at
each junction. This causes the trains to occasionally to make choices
that are unwanted from a player's point of view.
This will not be fixed because lost trains are in almost all cases a
network problem, e.g. a train can never reach a specific place. This
makes the impact of fixing the bug enormously small against the amount
of work needed to write a system that prevents the lost trains from
taking the wrong direction.
Vehicle owner of last transfer leg gets paid for all [#2427]:
When you make a transfer system that switches vehicle owners. This
is only possible with 'industry stations', e.g. the oil rig station
the owner of the vehicle that does the final delivery gets paid for
the whole trip. It is not shared amongst the different vehicle
owners that have participated in transporting the cargo.
This sharing is not done because it would enormously increase the
memory and CPU usage in big games for something that is happening
in only one corner case. We think it is not worth the effort until
sharing of stations is an official feature.
Forbid 90 degree turns does not work for crossing PBS paths [#2737]:
When you run a train through itself on a X junction with PBS turned on
the train will not obey the 'forbid 90 degree turns' setting. This is
due to the fact that we can not be sure that the setting was turned
off when the track was reserved, which means that we assume it was
turned on and that the setting does not hold at the time. We made it
this way to allow one to change the setting in-game, but it breaks
slightly when you are running your train through itself. Running a
train through means that your network is broken and is thus a user
error which OpenTTD tries to graciously handle.
Fixing this bug means that we need to record whether this particular
setting was turned on or off at the time the reservation was made. This
means adding quite a bit of data to the savegame for solving an issue
that is basically an user error. We think it is not worth the effort.
Duplicate (station) names after renaming [#3204]:
After renaming stations one can create duplicate station names. This
is done giving a station the same custom name as another station with
an automatically generated name.
The major part of this problem is that station names are translatable.
Meaning that a station is called e.g. '<TOWN> Central' in English and
'<TOWN> Centraal' in Dutch. This means that in network games the
renaming of a town could cause the rename to succeed on some clients
and fail at others. This creates an inconsistent game state that will
be seen as a 'desync'. Secondly the custom names are intended to fall
completely outside of the '<TOWN> <name>' naming of stations, so when
you rename a town all station names are updated accordingly.
As a result the decision has been made that all custom names are only
compared to the other custom names in the same class and not compared
to the automatically generated names.
Extreme CPU usage/hangs when using SDL and PulseAudio [#3294],
OpenTTD hangs/freezes when closing, OpenTTD is slow, OpenTTD uses a lot of CPU:
OpenTTD can be extremely slow/use a lot of CPU when the sound is
played via SDL and then through PulseAudio's ALSA wrapper. Under the
same configuration OpenTTD, or rather SDL, might hang when exiting
the game. This problem is seen most in Ubuntu 9.04 and higher.
This is because recent versions of the PulseAudio sound server
are configured to use timer-based audio scheduling rather than
interrupt-based audio scheduling. Configuring PulseAudio to force
use of interrupt-based scheduling may resolve sound problems for
some users. Under recent versions of Ubuntu Linux (9.04 and higher)
this can be accomplished by changing the following line in the
/etc/pulse/default.pa file:
load-module module-udev-detect
to
load-module module-udev-detect tsched=0
Note that PulseAudio must be restarted for changes to take effect. Older
versions of PulseAudio may use the module-hal-detect module instead.
Adding tsched=0 to the end of that line will have a similar effect.
Another possible solution is selecting the "pulse" backend of SDL
by either using "SDL_AUDIODRIVER=pulse openttd" at the command
prompt or installing the 'libsdl1.2debian-pulseaudio' package from
Ubuntu's Universe repository. For other distributions a similar
package needs to be installed.
OpenTTD not properly resizing with SDL on X [#3305]:
Under some X window managers OpenTTD's window does not properly
resize. You will either end up with a black bar at the right/bottom
side of the window or you cannot see the right/bottom of the window,
e.g. you cannot see the status bar. The problem is that OpenTTD does
not always receive a resize event from SDL making it impossible for
OpenTTD to know that the window was resized; sometimes moving the
window will solve the problem.
Window managers that are known to exhibit this behaviour are GNOME's
and KDE's. With the XFCE's and LXDE's window managers the resize
event is sent when the user releases the mouse.
Incorrect colours, crashes upon exit, debug warnings and smears upon
window resizing with SDL on macOS [#3447]:
Video handling with (lib)SDL under macOS is known to fail on some
versions of macOS with some hardware configurations. Some of
the problems happen only under some circumstances whereas others
are always present.
We suggest that the SDL video/sound backend is not used for OpenTTD
in combinations with macOS.
Train crashes entering same junction from block and path signals [#3928]:
When a train has reserved a path from a path signal to a two way
block signal and the reservation passes a path signal through the
back another train can enter the reserved path (only) via that
same two way block signal.
The reason for this has to do with optimisation; to fix this issue
the signal update has to pass all path signals until it finds either
a train or a backwards facing signal. This is a very expensive task.
The (signal) setups that allow these crashes can furthermore be
considered incorrectly signalled; one extra safe waiting point for
the train entering from path signal just after the backwards facing
signal (from the path signal train) resolves the issue.
Crashes when run in a VM using Parallels Desktop [#4003]:
When the Windows version of OpenTTD is executed in a VM under
Parallels Desktop a privileged instruction exception may be thrown.
As OpenTTD works natively on macOS as well as natively on Windows and
these native builds both don't exhibit this behaviour this crash is
most likely due to a bug in the virtual machine, something out of
the scope of OpenTTD. Most likely this is due to Parallels Desktop
lacking support for RDTSC calls. The problem can be avoided by using
other VM-software, Wine, or running natively on macOS.
Entry- and exit signals are not dragged [#4378]:
Unlike all other signal types, the entry- and exit signals are not
dragged but instead normal signals are placed on subsequent track
sections. This is done on purpose as this is the usually more
convenient solution. There are little to no occasions where more
than one entry or exit signal in a row are useful. This is different
for all other signal types where several in a row can serve one
purpose or another.
Station build date is incorrect [#4415]:
The tile query tool will show the date of the last (re)construction
at the station and not the date of the first construction. This is
due to compatibility reasons with NewGRFs and the fact that it is
wrong to say that the station is built in a particular year when it
was completely destroyed/rebuilt later on.
The tile query tool can be fixed by changing the "Build date" text
to "Date at which the last (re)construction took place" but this is
deemed too specific and long for that window.
(Temporary) wrong colours when switching to full screen [#4511]:
On Windows it can happen that you temporarily see wrong colours
when switching to full screen OpenTTD, either by starting
OpenTTD in full screen mode, changing to full screen mode or by
ALT-TAB-ing into a full screen OpenTTD. This is caused by the
fact that OpenTTD, by default, uses 8bpp paletted output. The
wrong colours you are seeing is a temporary effect of the video
driver switching to 8bpp palette mode.
This issue can be worked around in two ways:
a) Setting fullscreen_bpp to 32
b) Setting up the 32bpp-anim or 32bpp-optimized blitter
Can't run OpenTTD with the -d option from a MSYS console [#4587]:
The MSYS console does not allow OpenTTD to open an extra console for
debugging output. Compiling OpenTTD with the --enable-console
configure option prevents this issue and allows the -d option to use
the MSYS console for its output.
Unreadable characters for non-latin locales [#4607]:
OpenTTD does not ship a non-latin font in its graphics files. As a
result OpenTTD needs to acquire the font from somewhere else. What
OpenTTD does is ask the operating system, or a system library, for
the best font for a given language if the currently loaded font
does not provide all characters of the chosen translation. This
means that OpenTTD has no influence over the quality of the chosen
font; it just does the best it can do.
If the text is unreadable there are several steps that you can take
to improve this. The first step is finding a good font and configure
this in the configuration file. See section 9.0 of README.md for
more information. You can also increase the font size to make the
characters bigger and possible better readable.
If the problem is with the clarity of the font you might want to
enable anti-aliasing by setting the small_aa/medium_aa/large_aa
settings to "true". However, anti-aliasing only works when a 32-bit
blitter has been selected, e.g. blitter = "32bpp-anim", as with the
8 bits blitter there are not enough colours to properly perform the
anti-aliasing.
Train does not crash with itself [#4635]:
When a train drives in a circle the front engine passes through
wagons of the same train without crashing. This is intentional.
Signals are only aware of tracks, they do not consider the train
length and whether there would be enough room for a train in some
circle it might drive on. Also the path a train might take is not
necessarily known when passing a signal.
Checking all circumstances would take a lot of additional
computational power for signals, which is not considered worth
the effort, as it does not add anything to gameplay.
Nevertheless trains shall not crash in normal operation, so making
a train not crash with itself is the best solution for everyone.
Aircraft coming through wall in rotated airports [#4705]:
With rotated airports, specifically hangars, you will see that the
aircraft will show a part through the back wall of the hangar.
This can be solved by only drawing a part of the plane when being
at the back of the hangar, however then with transparency turned on
the aircraft would be shown partially which would be even weirder.
As such the current behaviour is deemed the least bad.
The same applies to overly long ships and their depots.
Vehicles not keeping their "maximum" speed [#4815]:
Vehicles that have not enough power to reach and maintain their
advertised maximum speed might be constantly jumping between two
speeds. This is due to the fact that speed and its calculations
are done with integral numbers instead of floating point numbers.
As a result of this a vehicle will never reach its equilibrium
between the drag/friction and propulsion. So in effect it will be
in a vicious circle of speeding up and slowing down due to being
just at the other side of the equilibrium.
Not speeding up when near the equilibrium will cause the vehicle to
never come in the neighbourhood of the equilibrium and not slowing
down when near the equilibrium will cause the vehicle to never slow
down towards the equilibrium once it has come down a hill.
It is possible to calculate whether the equilibrium will be passed,
but then all acceleration calculations need to be done twice.
Settings not saved when OpenTTD crashes [#4846]:
The settings are not saved when OpenTTD crashes for several reasons.
The most important is that the game state is broken and as such the
settings might contain invalid values, or the settings have not even
been loaded yet. This would cause invalid or totally wrong settings
to be written to the configuration file.
A solution to that would be saving the settings whenever one changes,
however due to the way the configuration file is saved this requires
a flush of the file to the disk and OpenTTD needs to wait till that
is finished. On some file system implementations this causes the
flush of all 'write-dirty' caches, which can be a significant amount
of data to be written. This can further be aggravated by spinning
down disks to conserve power, in which case this disk needs to be
spun up first. This means that many seconds may pass before the
configuration file is actually written, and all that time OpenTTD
will not be able to show any progress. Changing the way the
configuration file is saved is not an option as that leaves us more
vulnerable to corrupt configuration files.
Finally, crashes should not be happening. If they happen they should
be reported and fixed, so essentially fixing this is fixing the wrong
thing. If you really need the configuration changes to be saved,
and you need to run a version that crashes regularly, then you can
use the 'saveconfig' command in the console to save the settings.
Not all NewGRFs, AIs, game scripts are found [#4887]:
Under certain situations, where the path for the content within a
tar file is the same as other content on the file system or in another
tar file, it is possible that content is not found. A more thorough
explanation and solutions are described in section 4.4 of README.md.
Mouse cursor going missing with SDL [#4997]:
Under certain circumstances SDL does not notify OpenTTD of changes with
respect to the mouse pointer, specifically whether the mouse pointer
is within the bounds of OpenTTD or not. For example, if you "Alt-Tab"
to another application the mouse cursor will still be shown in OpenTTD,
and when you move the mouse outside of the OpenTTD window so the cursor
gets hidden, open/move another application on top of the OpenTTD window
and then Alt-tab back into OpenTTD the cursor will not be shown.
We cannot fix this problem as SDL simply does not provide the required
information in these corner cases. This is a bug in SDL and as such
there is little that we can do about it.
Trains might not stop at platforms that are currently being changed [#5553]:
If you add tiles to or remove tiles from a platform while a train is
approaching to stop at the same platform, that train can miss the place
where it's supposed to stop and pass the station without stopping.
This is caused by the fact that the train is considered to already
have stopped if it's beyond its assigned stopping location. We can't
let the train stop just anywhere in the station because then it would
never leave the station if you have the same station in the order
list multiple times in a row or if there is only one station
in theorder list (see #5684).
Some houses and industries are not affected by transparency [#5817]:
Some of the default houses and industries (f.e. the iron ore mine) are
not affected by the transparency options. This is because the graphics
do not (completely) separate the ground from the building.
This is a bug of the original graphics, and unfortunately cannot be
fixed with OpenGFX for the sake of maintaining compatibility with
the original graphics.
Involuntary cargo exchange with cargodist via neutral station [#6114]:
When two players serve a neutral station at an industry, a cross-company
chain for cargo flow can and will be established which can only be
interrupted if one of the players stops competing for the resources of
that industry. There is an easy fix for this: If you are loading at the
shared station make the order "no unload" and if you're unloading make
it "no load". Cargodist will then figure out that it should not create
such a route.
Incorrect ending year displayed in end of game newspaper [#8625]
The ending year of the game is configurable, but the date displayed in
the newspaper at the end of the game is part of the graphics, not text.
So to fix this would involve fixing the graphics in every baseset,
including the original. Additionally, basesets are free to put this
text in different positions (which they do), making a proper solution
to this infinitely more complex for a part of the game that fewer than
1% of players ever see.

Binary file not shown.

View File

@@ -1 +1 @@
8bc3926cb50e19747de498357417d973
4f03553f614a06d86dc06376db3353c7

View File

@@ -20,7 +20,6 @@ if(GRFCODEC_FOUND)
${CMAKE_CURRENT_SOURCE_DIR}/openttdgui.nfo
${CMAKE_CURRENT_SOURCE_DIR}/palette.nfo
${CMAKE_CURRENT_SOURCE_DIR}/roadstops.nfo
${CMAKE_CURRENT_SOURCE_DIR}/road_waypoints.nfo
${CMAKE_CURRENT_SOURCE_DIR}/signals.nfo
${CMAKE_CURRENT_SOURCE_DIR}/sloped_tracks.nfo
${CMAKE_CURRENT_SOURCE_DIR}/tramtracks.nfo
@@ -43,7 +42,6 @@ if(GRFCODEC_FOUND)
${CMAKE_CURRENT_SOURCE_DIR}/openttdgui_convert_tram.png
${CMAKE_CURRENT_SOURCE_DIR}/openttdgui_group_livery.png
${CMAKE_CURRENT_SOURCE_DIR}/roadstops.png
${CMAKE_CURRENT_SOURCE_DIR}/road_waypoints.png
${CMAKE_CURRENT_SOURCE_DIR}/signals.png
${CMAKE_CURRENT_SOURCE_DIR}/sloped_tracks.png
${CMAKE_CURRENT_SOURCE_DIR}/tramtracks.png

View File

@@ -98,4 +98,3 @@
#include "mono.nfo"
#include "tunnel_portals.nfo"
#include "palette.nfo"
#include "road_waypoints.nfo"

View File

@@ -1,14 +0,0 @@
// This file is part of OpenTTD.
// OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
// OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
//
-1 * 0 0C "Road waypoints"
//@@LINT OFF
-1 * 3 05 19 04
//@@LINT ON
-1 sprites/road_waypoints.png 8bpp 10 10 64 40 -5 -22 normal
-1 sprites/road_waypoints.png 8bpp 90 10 64 40 -31 -9 normal
-1 sprites/road_waypoints.png 8bpp 170 10 64 35 -31 -4 normal
-1 sprites/road_waypoints.png 8bpp 240 10 64 35 -57 -17 normal

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.4 KiB

View File

@@ -1,5 +1,3 @@
add_subdirectory(tests)
add_files(
scriptrun.cpp
scriptrun.h

View File

@@ -184,6 +184,13 @@ UBool ScriptRun::next()
parenStack[++startSP].scriptCode = scriptCode;
}
}
// if this character is a close paired character,
// pop it from the stack
if (pairIndex >= 0 && (pairIndex & 1) != 0 && parenSP >= 0) {
parenSP -= 1;
startSP -= 1;
}
} else {
// if the run broke on a surrogate pair,
// end it before the high surrogate

View File

@@ -1,4 +0,0 @@
add_test_files(
test_srtest.cpp
CONDITION ICU_i18n_FOUND
)

View File

@@ -1,66 +0,0 @@
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
* %W% %E%
*
* (C) Copyright IBM Corp. 2001-2016 - All Rights Reserved
*
*/
/** @file test_srtest.cpp Test icu::ScriptRun result. */
#include "../../../stdafx.h"
#include "../../../3rdparty/catch2/catch.hpp"
#include "../../../3rdparty/fmt/core.h"
#include "../scriptrun.h"
#include <span>
#include <unicode/uscript.h>
static void TestScriptRun(std::span<const char16_t> testChars, std::span<const std::string_view> testResults)
{
icu::ScriptRun scriptRun(testChars.data(), 0, std::size(testChars));
size_t i = 0;
while (scriptRun.next()) {
int32_t start = scriptRun.getScriptStart();
int32_t end = scriptRun.getScriptEnd();
UScriptCode code = scriptRun.getScriptCode();
REQUIRE(i < std::size(testResults));
CHECK(fmt::format("Script '{}' from {} to {}.", uscript_getName(code), start, end) == testResults[i]);
++i;
}
REQUIRE(i == std::size(testResults));
}
TEST_CASE("ICU ScriptRun")
{
/** Example string sequence as in srtest.cpp. */
static const char16_t testChars[] = {
0x0020, 0x0946, 0x0939, 0x093F, 0x0928, 0x094D, 0x0926, 0x0940, 0x0020,
0x0627, 0x0644, 0x0639, 0x0631, 0x0628, 0x064A, 0x0629, 0x0020,
0x0420, 0x0443, 0x0441, 0x0441, 0x043A, 0x0438, 0x0439, 0x0020,
'E', 'n', 'g', 'l', 'i', 's', 'h', 0x0020,
0x6F22, 0x5B75, 0x3068, 0x3072, 0x3089, 0x304C, 0x306A, 0x3068,
0x30AB, 0x30BF, 0x30AB, 0x30CA,
0xD801, 0xDC00, 0xD801, 0xDC01, 0xD801, 0xDC02, 0xD801, 0xDC03
};
/** Expected results from script run. */
static const std::string_view testResults[] = {
"Script 'Devanagari' from 0 to 9.",
"Script 'Arabic' from 9 to 17.",
"Script 'Cyrillic' from 17 to 25.",
"Script 'Latin' from 25 to 33.",
"Script 'Han' from 33 to 35.",
"Script 'Hiragana' from 35 to 41.",
"Script 'Katakana' from 41 to 45.",
"Script 'Deseret' from 45 to 53.",
};
TestScriptRun(testChars, testResults);
}

View File

@@ -39,11 +39,6 @@ add_files(
CONDITION ICU_i18n_FOUND AND HARFBUZZ_FOUND
)
add_files(
soundloader_opus.cpp
CONDITION OpusFile_FOUND
)
add_files(
aircraft.h
aircraft_cmd.cpp
@@ -55,7 +50,6 @@ add_files(
airport_gui.cpp
animated_tile.cpp
animated_tile_func.h
animated_tile_map.h
articulated_vehicles.cpp
articulated_vehicles.h
autocompletion.cpp
@@ -313,7 +307,6 @@ add_files(
newgrf_storage.h
newgrf_text.cpp
newgrf_text.h
newgrf_text_type.h
newgrf_town.cpp
newgrf_town.h
newgrf_townname.cpp
@@ -350,7 +343,6 @@ add_files(
picker_gui.h
progress.cpp
progress.h
provider_manager.h
querystring_gui.h
rail.cpp
rail.h
@@ -422,11 +414,6 @@ add_files(
sound.cpp
sound_func.h
sound_type.h
soundloader.cpp
soundloader_func.h
soundloader_type.h
soundloader_raw.cpp
soundloader_wav.cpp
sprite.cpp
sprite.h
spritecache.cpp

View File

@@ -242,15 +242,18 @@
/* static */ void AI::NewEvent(CompanyID company, ScriptEvent *event)
{
ScriptObjectRef counter(event);
/* AddRef() and Release() need to be called at least once, so do it here */
event->AddRef();
/* Clients should ignore events */
if (_networking && !_network_server) {
event->Release();
return;
}
/* Only AIs can have an event-queue */
if (!Company::IsValidAiID(company)) {
event->Release();
return;
}
@@ -258,14 +261,18 @@
Backup<CompanyID> cur_company(_current_company, company);
Company::Get(_current_company)->ai_instance->InsertEvent(event);
cur_company.Restore();
event->Release();
}
/* static */ void AI::BroadcastNewEvent(ScriptEvent *event, CompanyID skip_company)
{
ScriptObjectRef counter(event);
/* AddRef() and Release() need to be called at least once, so do it here */
event->AddRef();
/* Clients should ignore events */
if (_networking && !_network_server) {
event->Release();
return;
}
@@ -273,6 +280,8 @@
for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
if (c != skip_company) AI::NewEvent(c, event);
}
event->Release();
}
/* static */ void AI::Save(CompanyID company)

View File

@@ -86,7 +86,7 @@ static WindowDesc _ai_config_desc(
WDP_CENTER, nullptr, 0, 0,
WC_GAME_OPTIONS, WC_NONE,
0,
_nested_ai_config_widgets
std::begin(_nested_ai_config_widgets), std::end(_nested_ai_config_widgets)
);
/**
@@ -97,7 +97,7 @@ struct AIConfigWindow : public Window {
int line_height; ///< Height of a single AI-name line.
Scrollbar *vscroll; ///< Cache of the vertical scrollbar.
AIConfigWindow() : Window(_ai_config_desc)
AIConfigWindow() : Window(&_ai_config_desc)
{
this->InitNested(WN_GAME_OPTIONS_AI); // Initializes 'this->line_height' as a side effect.
this->vscroll = this->GetScrollbar(WID_AIC_SCROLLBAR);

View File

@@ -17,10 +17,12 @@
* Base values for flight levels above ground level for 'normal' flight and holding patterns.
* Due to speed and direction, the actual flight level may be higher.
*/
static constexpr int AIRCRAFT_MIN_FLYING_ALTITUDE = 120; ///< Minimum flying altitude above tile.
static constexpr int AIRCRAFT_MAX_FLYING_ALTITUDE = 360; ///< Maximum flying altitude above tile.
static constexpr int PLANE_HOLD_MAX_FLYING_ALTITUDE = 150; ///< holding flying altitude above tile of planes.
static constexpr int HELICOPTER_HOLD_MAX_FLYING_ALTITUDE = 184; ///< holding flying altitude above tile of helicopters.
enum AircraftFlyingAltitude {
AIRCRAFT_MIN_FLYING_ALTITUDE = 120, ///< Minimum flying altitude above tile.
AIRCRAFT_MAX_FLYING_ALTITUDE = 360, ///< Maximum flying altitude above tile.
PLANE_HOLD_MAX_FLYING_ALTITUDE = 150, ///< holding flying altitude above tile of planes.
HELICOPTER_HOLD_MAX_FLYING_ALTITUDE = 184 ///< holding flying altitude above tile of helicopters.
};
struct Aircraft;

View File

@@ -630,11 +630,13 @@ void UpdateAircraftCache(Aircraft *v, bool update_range)
/**
* Special velocities for aircraft
*/
static constexpr uint16_t SPEED_LIMIT_TAXI = 50; ///< Maximum speed of an aircraft while taxiing
static constexpr uint16_t SPEED_LIMIT_APPROACH = 230; ///< Maximum speed of an aircraft on finals
static constexpr uint16_t SPEED_LIMIT_BROKEN = 320; ///< Maximum speed of an aircraft that is broken
static constexpr uint16_t SPEED_LIMIT_HOLD = 425; ///< Maximum speed of an aircraft that flies the holding pattern
static constexpr uint16_t SPEED_LIMIT_NONE = UINT16_MAX; ///< No environmental speed limit. Speed limit is type dependent
enum AircraftSpeedLimits {
SPEED_LIMIT_TAXI = 50, ///< Maximum speed of an aircraft while taxiing
SPEED_LIMIT_APPROACH = 230, ///< Maximum speed of an aircraft on finals
SPEED_LIMIT_BROKEN = 320, ///< Maximum speed of an aircraft that is broken
SPEED_LIMIT_HOLD = 425, ///< Maximum speed of an aircraft that flies the holding pattern
SPEED_LIMIT_NONE = 0xFFFF, ///< No environmental speed limit. Speed limit is type dependent
};
/**
* Sets the new speed for an aircraft
@@ -1320,10 +1322,10 @@ void Aircraft::MarkDirty()
uint Aircraft::Crash(bool flooded)
{
uint victims = Vehicle::Crash(flooded) + 2; // pilots
uint pass = Vehicle::Crash(flooded) + 2; // pilots
this->crashed_counter = flooded ? 9000 : 0; // max 10000, disappear pretty fast when flooded
return victims;
return pass;
}
/**
@@ -1334,8 +1336,8 @@ static void CrashAirplane(Aircraft *v)
{
CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE);
uint victims = v->Crash();
SetDParam(0, victims);
uint pass = v->Crash();
SetDParam(0, pass);
v->cargo.Truncate();
v->Next()->cargo.Truncate();
@@ -1349,8 +1351,8 @@ static void CrashAirplane(Aircraft *v)
newsitem = STR_NEWS_AIRCRAFT_CRASH;
}
AI::NewEvent(v->owner, new ScriptEventVehicleCrashed(v->index, vt, st == nullptr ? ScriptEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT : ScriptEventVehicleCrashed::CRASH_PLANE_LANDING, victims));
Game::NewEvent(new ScriptEventVehicleCrashed(v->index, vt, st == nullptr ? ScriptEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT : ScriptEventVehicleCrashed::CRASH_PLANE_LANDING, victims));
AI::NewEvent(v->owner, new ScriptEventVehicleCrashed(v->index, vt, st == nullptr ? ScriptEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT : ScriptEventVehicleCrashed::CRASH_PLANE_LANDING));
Game::NewEvent(new ScriptEventVehicleCrashed(v->index, vt, st == nullptr ? ScriptEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT : ScriptEventVehicleCrashed::CRASH_PLANE_LANDING));
NewsType newstype = NT_ACCIDENT;
if (v->owner != _local_company) {

View File

@@ -97,17 +97,6 @@ void DrawAircraftImage(const Vehicle *v, const Rect &r, VehicleID selection, Eng
PaletteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
seq.Draw(x, y, pal, (v->vehstatus & VS_CRASHED) != 0);
/* Aircraft can store cargo in their shadow, show this if present. */
const Vehicle *u = v->Next();
assert(u != nullptr);
int dx = 0;
if (u->cargo_cap > 0 && u->cargo_type != v->cargo_type) {
dx = GetLargestCargoIconSize().width / 2;
DrawCargoIconOverlay(x + dx, y, u->cargo_type);
}
if (v->cargo_cap > 0) DrawCargoIconOverlay(x - dx, y, v->cargo_type);
if (helicopter) {
const Aircraft *a = Aircraft::From(v);
VehicleSpriteSeq rotor_seq;

View File

@@ -83,7 +83,7 @@ static void PlaceAirport(TileIndex tile)
struct BuildAirToolbarWindow : Window {
int last_user_action; // Last started user action.
BuildAirToolbarWindow(WindowDesc &desc, WindowNumber window_number) : Window(desc)
BuildAirToolbarWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
{
this->InitNested(window_number);
this->OnInvalidateData();
@@ -212,7 +212,7 @@ static WindowDesc _air_toolbar_desc(
WDP_ALIGN_TOOLBAR, "toolbar_air", 0, 0,
WC_BUILD_TOOLBAR, WC_NONE,
WDF_CONSTRUCTION,
_nested_air_toolbar_widgets,
std::begin(_nested_air_toolbar_widgets), std::end(_nested_air_toolbar_widgets),
&BuildAirToolbarWindow::hotkeys
);
@@ -228,7 +228,7 @@ Window *ShowBuildAirToolbar()
if (!Company::IsValidID(_local_company)) return nullptr;
CloseWindowByClass(WC_BUILD_TOOLBAR);
return AllocateWindowDescFront<BuildAirToolbarWindow>(_air_toolbar_desc, TRANSPORT_AIR);
return AllocateWindowDescFront<BuildAirToolbarWindow>(&_air_toolbar_desc, TRANSPORT_AIR);
}
class BuildAirportWindow : public PickerWindowBase {
@@ -249,7 +249,7 @@ class BuildAirportWindow : public PickerWindowBase {
}
public:
BuildAirportWindow(WindowDesc &desc, Window *parent) : PickerWindowBase(desc, parent)
BuildAirportWindow(WindowDesc *desc, Window *parent) : PickerWindowBase(desc, parent)
{
this->CreateNestedTree();
@@ -384,14 +384,13 @@ public:
case WID_AP_AIRPORT_LIST: {
Rect row = r.WithHeight(this->line_height).Shrink(WidgetDimensions::scaled.bevel);
Rect text = r.WithHeight(this->line_height).Shrink(WidgetDimensions::scaled.matrix);
const auto specs = AirportClass::Get(_selected_airport_class)->Specs();
auto [first, last] = this->vscroll->GetVisibleRangeIterators(specs);
for (auto it = first; it != last; ++it) {
const AirportSpec *as = *it;
AirportClass *apclass = AirportClass::Get(_selected_airport_class);
for (uint i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < apclass->GetSpecCount(); i++) {
const AirportSpec *as = apclass->GetSpec(i);
if (!as->IsAvailable()) {
GfxFillRect(row, PC_BLACK, FILLRECT_CHECKER);
}
DrawString(text, as->name, (static_cast<int>(as->index) == _selected_airport_index) ? TC_WHITE : TC_BLACK);
DrawString(text, as->name, ((int)i == _selected_airport_index) ? TC_WHITE : TC_BLACK);
row = row.Translate(0, this->line_height);
text = text.Translate(0, this->line_height);
}
@@ -537,9 +536,10 @@ public:
{
/* First try to select an airport in the selected class. */
AirportClass *sel_apclass = AirportClass::Get(_selected_airport_class);
for (const AirportSpec *as : sel_apclass->Specs()) {
for (uint i = 0; i < sel_apclass->GetSpecCount(); i++) {
const AirportSpec *as = sel_apclass->GetSpec(i);
if (as->IsAvailable()) {
this->SelectOtherAirport(as->index);
this->SelectOtherAirport(i);
return;
}
}
@@ -551,7 +551,7 @@ public:
if (as->IsAvailable()) {
_selected_airport_class = cls.Index();
this->vscroll->SetCount(cls.GetSpecCount());
this->SelectOtherAirport(as->index);
this->SelectOtherAirport(as->GetIndex());
return;
}
}
@@ -621,12 +621,12 @@ static WindowDesc _build_airport_desc(
WDP_AUTO, nullptr, 0, 0,
WC_BUILD_STATION, WC_BUILD_TOOLBAR,
WDF_CONSTRUCTION,
_nested_build_airport_widgets
std::begin(_nested_build_airport_widgets), std::end(_nested_build_airport_widgets)
);
static void ShowBuildAirportPicker(Window *parent)
{
new BuildAirportWindow(_build_airport_desc, parent);
new BuildAirportWindow(&_build_airport_desc, parent);
}
void InitializeAirportGui()

View File

@@ -8,8 +8,7 @@
/** @file animated_tile.cpp Everything related to animated tiles. */
#include "stdafx.h"
#include "animated_tile_func.h"
#include "animated_tile_map.h"
#include "core/container_func.hpp"
#include "tile_cmd.h"
#include "viewport_func.h"
#include "framerate_type.h"
@@ -20,53 +19,28 @@
std::vector<TileIndex> _animated_tiles;
/**
* Stops animation on the given tile.
* Removes the given tile from the animated tile table.
* @param tile the tile to remove
* @param immediate immediately delete the tile from the animated tile list instead of waiting for the next tick.
*/
void DeleteAnimatedTile(TileIndex tile, bool immediate)
void DeleteAnimatedTile(TileIndex tile)
{
if (immediate) {
if (GetAnimatedTileState(tile) == AnimatedTileState::None) return;
/* The tile may be switched to a non-animatable tile soon, so we should remove it from the
* animated tile list early. */
SetAnimatedTileState(tile, AnimatedTileState::None);
/* To avoid having to move everything after this tile in the animated tile list, look for this tile
* in the animated tile list and replace with last entry if not last. */
auto it = std::ranges::find(_animated_tiles, tile);
if (it == std::end(_animated_tiles)) return;
if (std::next(it) != std::end(_animated_tiles)) *it = _animated_tiles.back();
_animated_tiles.pop_back();
return;
auto to_remove = std::find(_animated_tiles.begin(), _animated_tiles.end(), tile);
if (to_remove != _animated_tiles.end()) {
/* The order of the remaining elements must stay the same, otherwise the animation loop may miss a tile. */
_animated_tiles.erase(to_remove);
MarkTileDirtyByTile(tile);
}
/* If the tile was animated, mark it for deletion from the tile list on the next animation loop. */
if (GetAnimatedTileState(tile) == AnimatedTileState::Animated) SetAnimatedTileState(tile, AnimatedTileState::Deleted);
}
/**
* Add the given tile to the animated tile table (if it does not exist yet).
* Add the given tile to the animated tile table (if it does not exist
* on that table yet). Also increases the size of the table if necessary.
* @param tile the tile to make animated
* @param mark_dirty whether to also mark the tile dirty.
*/
void AddAnimatedTile(TileIndex tile, bool mark_dirty)
void AddAnimatedTile(TileIndex tile)
{
if (mark_dirty) MarkTileDirtyByTile(tile);
const AnimatedTileState state = GetAnimatedTileState(tile);
/* Tile is already animated so nothing needs to happen. */
if (state == AnimatedTileState::Animated) return;
/* Tile has no previous animation state, so add to the tile list. If the state is anything
* other than None (e.g. Deleted) then the tile will still be in the list and does not need to be added again. */
if (state == AnimatedTileState::None) _animated_tiles.push_back(tile);
SetAnimatedTileState(tile, AnimatedTileState::Animated);
MarkTileDirtyByTile(tile);
include(_animated_tiles, tile);
}
/**
@@ -74,29 +48,22 @@ void AddAnimatedTile(TileIndex tile, bool mark_dirty)
*/
void AnimateAnimatedTiles()
{
PerformanceAccumulator landscape_framerate(PFE_GL_LANDSCAPE);
PerformanceAccumulator framerate(PFE_GL_LANDSCAPE);
for (auto it = std::begin(_animated_tiles); it != std::end(_animated_tiles); /* nothing */) {
TileIndex &tile = *it;
if (GetAnimatedTileState(tile) != AnimatedTileState::Animated) {
/* Tile should not be animated any more, mark it as not animated and erase it from the list. */
SetAnimatedTileState(tile, AnimatedTileState::None);
/* Removing the last entry, no need to swap and continue. */
if (std::next(it) == std::end(_animated_tiles)) {
_animated_tiles.pop_back();
break;
}
/* Replace the current list entry with the back of the list to avoid moving elements. */
*it = _animated_tiles.back();
_animated_tiles.pop_back();
continue;
}
AnimateTile(tile);
++it;
const TileIndex *ti = _animated_tiles.data();
while (ti < _animated_tiles.data() + _animated_tiles.size()) {
const TileIndex curr = *ti;
AnimateTile(curr);
/* During the AnimateTile call, DeleteAnimatedTile could have been called,
* deleting an element we've already processed and pushing the rest one
* slot to the left. We can detect this by checking whether the index
* in the current slot has changed - if it has, an element has been deleted,
* and we should process the current slot again instead of going forward.
* NOTE: this will still break if more than one animated tile is being
* deleted during the same AnimateTile call, but no code seems to
* be doing this anyway.
*/
if (*ti == curr) ++ti;
}
}

View File

@@ -12,8 +12,8 @@
#include "tile_type.h"
void AddAnimatedTile(TileIndex tile, bool mark_dirty = true);
void DeleteAnimatedTile(TileIndex tile, bool immediate = false);
void AddAnimatedTile(TileIndex tile);
void DeleteAnimatedTile(TileIndex tile);
void AnimateAnimatedTiles();
void InitializeAnimatedTiles();

View File

@@ -1,44 +0,0 @@
/*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file animated_tile_map.h Maps accessors for animated tiles. */
#ifndef ANIMATED_TILE_MAP_H
#define ANIMATED_TILE_MAP_H
#include "core/bitmath_func.hpp"
#include "map_func.h"
/**
* Animation state of a possibly-animated tile.
*/
enum class AnimatedTileState : uint8_t {
None = 0, ///< Tile is not animated.
Deleted = 1, ///< Tile was animated but should be removed.
Animated = 3, ///< Tile is animated.
};
/**
* Get the animated state of a tile.
* @param t The tile.
* @returns true iff the tile is animated.
*/
inline AnimatedTileState GetAnimatedTileState(Tile t)
{
return static_cast<AnimatedTileState>(GB(t.m6(), 0, 2));
}
/**
* Set the animated state of a tile.
* @param t The tile.
*/
inline void SetAnimatedTileState(Tile t, AnimatedTileState state)
{
SB(t.m6(), 0, 2, to_underlying(state));
}
#endif /* ANIMATED_TILE_MAP_H */

View File

@@ -99,15 +99,18 @@ uint CountArticulatedParts(EngineID engine_type, bool purchase_window)
/**
* Returns the default (non-refitted) cargo and capacity of a specific EngineID.
* Returns the default (non-refitted) capacity of a specific EngineID.
* @param engine the EngineID of interest
* @return cargo and capacity
* @param cargo_type returns the default cargo type, if needed
* @return capacity
*/
static inline std::pair<CargoID, uint16_t> GetVehicleDefaultCapacity(EngineID engine)
static inline uint16_t GetVehicleDefaultCapacity(EngineID engine, CargoID *cargo_type)
{
const Engine *e = Engine::Get(engine);
CargoID cargo = e->CanCarryCargo() ? e->GetDefaultCargoType() : INVALID_CARGO;
return {cargo, IsValidCargoID(cargo) ? e->GetDisplayDefaultCapacity() : 0};
CargoID cargo = (e->CanCarryCargo() ? e->GetDefaultCargoType() : INVALID_CARGO);
if (cargo_type != nullptr) *cargo_type = cargo;
if (!IsValidCargoID(cargo)) return 0;
return e->GetDisplayDefaultCapacity();
}
/**
@@ -140,9 +143,9 @@ CargoArray GetCapacityOfArticulatedParts(EngineID engine)
CargoArray capacity{};
const Engine *e = Engine::Get(engine);
if (auto [cargo, cap] = GetVehicleDefaultCapacity(engine); IsValidCargoID(cargo)) {
capacity[cargo] = cap;
}
CargoID cargo_type;
uint16_t cargo_capacity = GetVehicleDefaultCapacity(engine, &cargo_type);
if (cargo_type < NUM_CARGO) capacity[cargo_type] = cargo_capacity;
if (!e->IsGroundVehicle()) return capacity;
@@ -152,9 +155,8 @@ CargoArray GetCapacityOfArticulatedParts(EngineID engine)
EngineID artic_engine = GetNextArticulatedPart(i, engine);
if (artic_engine == INVALID_ENGINE) break;
if (auto [cargo, cap] = GetVehicleDefaultCapacity(artic_engine); IsValidCargoID(cargo)) {
capacity[cargo] += cap;
}
cargo_capacity = GetVehicleDefaultCapacity(artic_engine, &cargo_type);
if (cargo_type < NUM_CARGO) capacity[cargo_type] += cargo_capacity;
}
return capacity;
@@ -170,9 +172,9 @@ CargoTypes GetCargoTypesOfArticulatedParts(EngineID engine)
CargoTypes cargoes = 0;
const Engine *e = Engine::Get(engine);
if (auto [cargo, cap] = GetVehicleDefaultCapacity(engine); IsValidCargoID(cargo) && cap > 0) {
SetBit(cargoes, cargo);
}
CargoID cargo_type;
uint16_t cargo_capacity = GetVehicleDefaultCapacity(engine, &cargo_type);
if (cargo_type < NUM_CARGO && cargo_capacity > 0) SetBit(cargoes, cargo_type);
if (!e->IsGroundVehicle()) return cargoes;
@@ -182,9 +184,8 @@ CargoTypes GetCargoTypesOfArticulatedParts(EngineID engine)
EngineID artic_engine = GetNextArticulatedPart(i, engine);
if (artic_engine == INVALID_ENGINE) break;
if (auto [cargo, cap] = GetVehicleDefaultCapacity(artic_engine); IsValidCargoID(cargo) && cap > 0) {
SetBit(cargoes, cargo);
}
cargo_capacity = GetVehicleDefaultCapacity(artic_engine, &cargo_type);
if (cargo_type < NUM_CARGO && cargo_capacity > 0) SetBit(cargoes, cargo_type);
}
return cargoes;

View File

@@ -167,7 +167,7 @@ class ReplaceVehicleWindow : public Window {
if (side == 1) {
/* ensure primary engine of variant group is in list */
for (const auto &variant : variants) {
if (std::ranges::find(list, variant, &GUIEngineListItem::engine_id) == list.end()) {
if (std::find(list.begin(), list.end(), variant) == list.end()) {
const Engine *e = Engine::Get(variant);
list.emplace_back(variant, e->info.variant_id, e->display_flags | EngineDisplayFlags::Shaded, 0);
}
@@ -263,7 +263,7 @@ class ReplaceVehicleWindow : public Window {
}
public:
ReplaceVehicleWindow(WindowDesc &desc, VehicleType vehicletype, GroupID id_g) : Window(desc)
ReplaceVehicleWindow(WindowDesc *desc, VehicleType vehicletype, GroupID id_g) : Window(desc)
{
this->sel_railtype = INVALID_RAILTYPE;
this->sel_roadtype = INVALID_ROADTYPE;
@@ -594,7 +594,7 @@ public:
if (it != this->engines[click_side].end()) {
const auto &item = *it;
const Rect r = this->GetWidget<NWidgetBase>(widget)->GetCurrentRect().Shrink(WidgetDimensions::scaled.matrix).WithWidth(WidgetDimensions::scaled.hsep_indent * (item.indent + 1), _current_text_dir == TD_RTL);
if (HasFlag(item.flags, EngineDisplayFlags::HasVariants) && IsInsideMM(r.left, r.right, pt.x)) {
if ((item.flags & EngineDisplayFlags::HasVariants) != EngineDisplayFlags::None && IsInsideMM(r.left, r.right, pt.x)) {
/* toggle folded flag on engine */
assert(item.variant_id != INVALID_ENGINE);
Engine *engine = Engine::Get(item.variant_id);
@@ -604,7 +604,7 @@ public:
InvalidateWindowClassesData(WC_BUILD_VEHICLE); // The build windows needs updating as well
return;
}
if (!HasFlag(item.flags, EngineDisplayFlags::Shaded)) e = item.engine_id;
if ((item.flags & EngineDisplayFlags::Shaded) == EngineDisplayFlags::None) e = item.engine_id;
}
/* If Ctrl is pressed on the left side and we don't have any engines of the selected type, stop autoreplacing.
@@ -715,10 +715,10 @@ static constexpr NWidgetPart _nested_replace_rail_vehicle_widgets[] = {
EndContainer(),
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
NWidget(WWT_PANEL, COLOUR_GREY),
NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_REPLACE_VEHICLE_VEHICLES_IN_USE, STR_REPLACE_VEHICLE_VEHICLES_IN_USE_TOOLTIP), SetFill(1, 1), SetMinimalTextLines(1, WidgetDimensions::unscaled.framerect.Vertical()), SetResize(1, 0),
NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_REPLACE_VEHICLE_VEHICLES_IN_USE, STR_REPLACE_VEHICLE_VEHICLES_IN_USE_TOOLTIP), SetFill(1, 1), SetMinimalSize(0, 12), SetResize(1, 0),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_GREY),
NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES, STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES_TOOLTIP), SetFill(1, 1), SetMinimalTextLines(1, WidgetDimensions::unscaled.framerect.Vertical()), SetResize(1, 0),
NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES, STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES_TOOLTIP), SetFill(1, 1), SetMinimalSize(0, 12), SetResize(1, 0),
EndContainer(),
EndContainer(),
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
@@ -766,7 +766,7 @@ static WindowDesc _replace_rail_vehicle_desc(
WDP_AUTO, "replace_vehicle_train", 500, 140,
WC_REPLACE_VEHICLE, WC_NONE,
WDF_CONSTRUCTION,
_nested_replace_rail_vehicle_widgets
std::begin(_nested_replace_rail_vehicle_widgets), std::end(_nested_replace_rail_vehicle_widgets)
);
static constexpr NWidgetPart _nested_replace_road_vehicle_widgets[] = {
@@ -779,10 +779,10 @@ static constexpr NWidgetPart _nested_replace_road_vehicle_widgets[] = {
EndContainer(),
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
NWidget(WWT_PANEL, COLOUR_GREY),
NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_REPLACE_VEHICLE_VEHICLES_IN_USE, STR_REPLACE_VEHICLE_VEHICLES_IN_USE_TOOLTIP), SetFill(1, 1), SetMinimalTextLines(1, WidgetDimensions::unscaled.framerect.Vertical()), SetResize(1, 0),
NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_REPLACE_VEHICLE_VEHICLES_IN_USE, STR_REPLACE_VEHICLE_VEHICLES_IN_USE_TOOLTIP), SetFill(1, 1), SetMinimalSize(0, 12), SetResize(1, 0),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_GREY),
NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES, STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES_TOOLTIP), SetFill(1, 1), SetMinimalTextLines(1, WidgetDimensions::unscaled.framerect.Vertical()), SetResize(1, 0),
NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES, STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES_TOOLTIP), SetFill(1, 1), SetMinimalSize(0, 12), SetResize(1, 0),
EndContainer(),
EndContainer(),
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
@@ -824,7 +824,7 @@ static WindowDesc _replace_road_vehicle_desc(
WDP_AUTO, "replace_vehicle_road", 500, 140,
WC_REPLACE_VEHICLE, WC_NONE,
WDF_CONSTRUCTION,
_nested_replace_road_vehicle_widgets
std::begin(_nested_replace_road_vehicle_widgets), std::end(_nested_replace_road_vehicle_widgets)
);
static constexpr NWidgetPart _nested_replace_vehicle_widgets[] = {
@@ -837,10 +837,10 @@ static constexpr NWidgetPart _nested_replace_vehicle_widgets[] = {
EndContainer(),
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
NWidget(WWT_PANEL, COLOUR_GREY),
NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_REPLACE_VEHICLE_VEHICLES_IN_USE, STR_REPLACE_VEHICLE_VEHICLES_IN_USE_TOOLTIP), SetFill(1, 1), SetMinimalTextLines(1, WidgetDimensions::unscaled.framerect.Vertical()), SetResize(1, 0),
NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_REPLACE_VEHICLE_VEHICLES_IN_USE, STR_REPLACE_VEHICLE_VEHICLES_IN_USE_TOOLTIP), SetFill(1, 1), SetMinimalSize(0, 12), SetResize(1, 0),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_GREY),
NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES, STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES_TOOLTIP), SetFill(1, 1), SetMinimalTextLines(1, WidgetDimensions::unscaled.framerect.Vertical()), SetResize(1, 0),
NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES, STR_REPLACE_VEHICLE_AVAILABLE_VEHICLES_TOOLTIP), SetFill(1, 1), SetMinimalSize(0, 12), SetResize(1, 0),
EndContainer(),
EndContainer(),
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
@@ -878,7 +878,7 @@ static WindowDesc _replace_vehicle_desc(
WDP_AUTO, "replace_vehicle", 456, 118,
WC_REPLACE_VEHICLE, WC_NONE,
WDF_CONSTRUCTION,
_nested_replace_vehicle_widgets
std::begin(_nested_replace_vehicle_widgets), std::end(_nested_replace_vehicle_widgets)
);
/**
@@ -889,9 +889,11 @@ static WindowDesc _replace_vehicle_desc(
void ShowReplaceGroupVehicleWindow(GroupID id_g, VehicleType vehicletype)
{
CloseWindowById(WC_REPLACE_VEHICLE, vehicletype);
WindowDesc *desc;
switch (vehicletype) {
case VEH_TRAIN: new ReplaceVehicleWindow(_replace_rail_vehicle_desc, vehicletype, id_g); break;
case VEH_ROAD: new ReplaceVehicleWindow(_replace_road_vehicle_desc, vehicletype, id_g); break;
default: new ReplaceVehicleWindow(_replace_vehicle_desc, vehicletype, id_g); break;
case VEH_TRAIN: desc = &_replace_rail_vehicle_desc; break;
case VEH_ROAD: desc = &_replace_road_vehicle_desc; break;
default: desc = &_replace_vehicle_desc; break;
}
new ReplaceVehicleWindow(desc, vehicletype, id_g);
}

View File

@@ -16,7 +16,7 @@
/**
* Autoslope check for tiles with an entrance on an edge.
* E.g. depots and bay road-stops.
* E.g. depots and non-drive-through-road-stops.
*
* The test succeeds if the slope is not steep and at least one corner of the entrance edge is on the TileMaxZ() level.
*
@@ -34,27 +34,6 @@ inline bool AutoslopeCheckForEntranceEdge(TileIndex tile, int z_new, Slope tileh
return ((tileh_new == SLOPE_FLAT) || CanBuildDepotByTileh(entrance, tileh_new));
}
/**
* Autoslope check for tiles with something built along an axis.
* E.g. railway stations and drive through road stops.
*
* The test succeeds if the slope is not steep and at least one corner at either of the entrance edges is on the TileMaxZ() level.
*
* @note The test does not check if autoslope is enabled at all.
*
* @param tile The tile.
* @param z_new New TileZ.
* @param tileh_new New TileSlope.
* @param axis The axis.
* @return true iff terraforming is allowed.
*/
inline bool AutoslopeCheckForAxis(TileIndex tile, int z_new, Slope tileh_new, Axis axis)
{
DiagDirection direction = AxisToDiagDir(axis);
return AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, direction) &&
AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, ReverseDiagDir(direction));
}
/**
* Tests if autoslope is enabled for _current_company.
*

View File

@@ -196,11 +196,11 @@ struct BaseStation : StationPool::PoolItem<&_station_pool> {
}
private:
bool SetRoadStopTileData(TileIndex tile, uint8_t data, bool animation);
void SetRoadStopTileData(TileIndex tile, uint8_t data, bool animation);
public:
inline void SetRoadStopRandomBits(TileIndex tile, uint8_t random_bits) { this->SetRoadStopTileData(tile, random_bits, false); }
inline bool SetRoadStopAnimationFrame(TileIndex tile, uint8_t frame) { return this->SetRoadStopTileData(tile, frame, true); }
inline void SetRoadStopAnimationFrame(TileIndex tile, uint8_t frame) { this->SetRoadStopTileData(tile, frame, true); }
void RemoveRoadStopTileData(TileIndex tile);
static void PostDestructor(size_t index);

View File

@@ -39,7 +39,7 @@ public:
template <BlitterMode mode, Blitter_32bppSSE_Base::ReadMode read_mode, Blitter_32bppSSE_Base::BlockType bt_last, bool translucent, bool animated>
void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom);
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator) override {
Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator) override {
return Blitter_32bppSSE_Base::Encode(sprite, allocator);
}
std::string_view GetName() override { return "32bpp-sse4-anim"; }

View File

@@ -285,7 +285,7 @@ void Blitter_32bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode,
this->Draw<false>(bp, mode, zoom);
}
template <bool Tpal_to_rgb> Sprite *Blitter_32bppOptimized::EncodeInternal(const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator)
template <bool Tpal_to_rgb> Sprite *Blitter_32bppOptimized::EncodeInternal(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator)
{
/* streams of pixels (a, r, g, b channels)
*
@@ -414,7 +414,7 @@ template <bool Tpal_to_rgb> Sprite *Blitter_32bppOptimized::EncodeInternal(const
len += lengths[z][0] + lengths[z][1];
}
Sprite *dest_sprite = allocator.Allocate<Sprite>(sizeof(*dest_sprite) + sizeof(SpriteData) + len);
Sprite *dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + sizeof(SpriteData) + len);
dest_sprite->height = sprite[ZOOM_LVL_MIN].height;
dest_sprite->width = sprite[ZOOM_LVL_MIN].width;
@@ -438,10 +438,10 @@ template <bool Tpal_to_rgb> Sprite *Blitter_32bppOptimized::EncodeInternal(const
return dest_sprite;
}
template Sprite *Blitter_32bppOptimized::EncodeInternal<true>(const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator);
template Sprite *Blitter_32bppOptimized::EncodeInternal<false>(const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator);
template Sprite *Blitter_32bppOptimized::EncodeInternal<true>(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator);
template Sprite *Blitter_32bppOptimized::EncodeInternal<false>(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator);
Sprite *Blitter_32bppOptimized::Encode(const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator)
Sprite *Blitter_32bppOptimized::Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator)
{
return this->EncodeInternal<true>(sprite, allocator);
}

View File

@@ -22,7 +22,7 @@ public:
};
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator) override;
Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator) override;
std::string_view GetName() override { return "32bpp-optimized"; }
@@ -30,7 +30,7 @@ public:
protected:
template <bool Tpal_to_rgb> void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
template <bool Tpal_to_rgb> Sprite *EncodeInternal(const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator);
template <bool Tpal_to_rgb> Sprite *EncodeInternal(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator);
};
/** Factory for the optimised 32 bpp blitter (without palette animation). */

View File

@@ -115,10 +115,10 @@ void Blitter_32bppSimple::DrawColourMappingRect(void *dst, int width, int height
Debug(misc, 0, "32bpp blitter doesn't know how to draw this colour table ('{}')", pal);
}
Sprite *Blitter_32bppSimple::Encode(const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator)
Sprite *Blitter_32bppSimple::Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator)
{
Blitter_32bppSimple::Pixel *dst;
Sprite *dest_sprite = allocator.Allocate<Sprite>(sizeof(*dest_sprite) + static_cast<size_t>(sprite[ZOOM_LVL_MIN].height) * static_cast<size_t>(sprite[ZOOM_LVL_MIN].width) * sizeof(*dst));
Sprite *dest_sprite = static_cast<Sprite *>(allocator(sizeof(*dest_sprite) + static_cast<size_t>(sprite[ZOOM_LVL_MIN].height) * static_cast<size_t>(sprite[ZOOM_LVL_MIN].width) * sizeof(*dst)));
dest_sprite->height = sprite[ZOOM_LVL_MIN].height;
dest_sprite->width = sprite[ZOOM_LVL_MIN].width;

View File

@@ -26,7 +26,7 @@ class Blitter_32bppSimple : public Blitter_32bppBase {
public:
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) override;
Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator) override;
Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator) override;
std::string_view GetName() override { return "32bpp-simple"; }
};

View File

@@ -20,7 +20,7 @@
/** Instantiation of the SSE2 32bpp blitter factory. */
static FBlitter_32bppSSE2 iFBlitter_32bppSSE2;
Sprite *Blitter_32bppSSE_Base::Encode(const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator)
Sprite *Blitter_32bppSSE_Base::Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator)
{
/* First uint32_t of a line = the number of transparent pixels from the left.
* Second uint32_t of a line = the number of transparent pixels from the right.
@@ -51,7 +51,7 @@ Sprite *Blitter_32bppSSE_Base::Encode(const SpriteLoader::SpriteCollection &spri
all_sprites_size += rgba_size + mv_size;
}
Sprite *dst_sprite = allocator.Allocate<Sprite>(sizeof(Sprite) + sizeof(SpriteData) + all_sprites_size);
Sprite *dst_sprite = (Sprite *) allocator(sizeof(Sprite) + sizeof(SpriteData) + all_sprites_size);
dst_sprite->height = sprite[ZOOM_LVL_MIN].height;
dst_sprite->width = sprite[ZOOM_LVL_MIN].width;
dst_sprite->x_offs = sprite[ZOOM_LVL_MIN].x_offs;

View File

@@ -76,7 +76,7 @@ public:
uint8_t data[]; ///< Data, all zoomlevels.
};
Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator);
Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator);
};
DECLARE_ENUM_AS_BIT_SET(Blitter_32bppSSE_Base::SpriteFlags);
@@ -88,7 +88,7 @@ public:
template <BlitterMode mode, Blitter_32bppSSE_Base::ReadMode read_mode, Blitter_32bppSSE_Base::BlockType bt_last, bool translucent>
void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom);
Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator) override {
Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator) override {
return Blitter_32bppSSE_Base::Encode(sprite, allocator);
}

View File

@@ -397,7 +397,7 @@ void Blitter_40bppAnim::DrawColourMappingRect(void *dst, int width, int height,
}
}
Sprite *Blitter_40bppAnim::Encode(const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator)
Sprite *Blitter_40bppAnim::Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator)
{
return this->EncodeInternal<false>(sprite, allocator);
}

View File

@@ -27,7 +27,7 @@ public:
void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y) override;
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) override;
Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator) override;
Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator) override;
size_t BufferSize(uint width, uint height) override;
Blitter::PaletteAnimation UsePaletteAnimation() override;
bool NeedsAnimationBuffer() override;

View File

@@ -120,7 +120,7 @@ void Blitter_8bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Z
}
}
Sprite *Blitter_8bppOptimized::Encode(const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator)
Sprite *Blitter_8bppOptimized::Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator)
{
/* Make memory for all zoom-levels */
uint memory = sizeof(SpriteData);
@@ -219,7 +219,7 @@ Sprite *Blitter_8bppOptimized::Encode(const SpriteLoader::SpriteCollection &spri
assert(size < memory);
/* Allocate the exact amount of memory we need */
Sprite *dest_sprite = allocator.Allocate<Sprite>(sizeof(*dest_sprite) + size);
Sprite *dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + size);
dest_sprite->height = sprite[ZOOM_LVL_MIN].height;
dest_sprite->width = sprite[ZOOM_LVL_MIN].width;

View File

@@ -23,7 +23,7 @@ public:
};
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator) override;
Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator) override;
std::string_view GetName() override { return "8bpp-optimized"; }
};

View File

@@ -61,10 +61,10 @@ void Blitter_8bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Zoom
}
}
Sprite *Blitter_8bppSimple::Encode(const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator)
Sprite *Blitter_8bppSimple::Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator)
{
Sprite *dest_sprite;
dest_sprite = allocator.Allocate<Sprite>(sizeof(*dest_sprite) + static_cast<size_t>(sprite[ZOOM_LVL_MIN].height) * static_cast<size_t>(sprite[ZOOM_LVL_MIN].width));
dest_sprite = static_cast<Sprite *>(allocator(sizeof(*dest_sprite) + static_cast<size_t>(sprite[ZOOM_LVL_MIN].height) * static_cast<size_t>(sprite[ZOOM_LVL_MIN].width)));
dest_sprite->height = sprite[ZOOM_LVL_MIN].height;
dest_sprite->width = sprite[ZOOM_LVL_MIN].width;

View File

@@ -17,7 +17,7 @@
class Blitter_8bppSimple final : public Blitter_8bppBase {
public:
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator) override;
Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator) override;
std::string_view GetName() override { return "8bpp-simple"; }
};

View File

@@ -15,10 +15,10 @@
/** Instantiation of the null blitter factory. */
static FBlitter_Null iFBlitter_Null;
Sprite *Blitter_Null::Encode(const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator)
Sprite *Blitter_Null::Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator)
{
Sprite *dest_sprite;
dest_sprite = allocator.Allocate<Sprite>(sizeof(*dest_sprite));
dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite));
dest_sprite->height = sprite[ZOOM_LVL_MIN].height;
dest_sprite->width = sprite[ZOOM_LVL_MIN].width;

View File

@@ -18,7 +18,7 @@ public:
uint8_t GetScreenDepth() override { return 0; }
void Draw(Blitter::BlitterParams *, BlitterMode, ZoomLevel) override {};
void DrawColourMappingRect(void *, int, int, PaletteID) override {};
Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator) override;
Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator) override;
void *MoveTo(void *, int, int) override { return nullptr; };
void SetPixel(void *, int, int, uint8_t) override {};
void DrawRect(void *, int, int, uint8_t) override {};

View File

@@ -8,32 +8,97 @@
/** @file bmp.cpp Read and write support for bmps. */
#include "stdafx.h"
#include "random_access_file_type.h"
#include "bmp.h"
#include "core/bitmath_func.hpp"
#include "core/alloc_func.hpp"
#include "core/mem_func.hpp"
#include "safeguards.h"
void BmpInitializeBuffer(BmpBuffer *buffer, FILE *file)
{
buffer->pos = -1;
buffer->file = file;
buffer->read = 0;
buffer->real_pos = ftell(file);
}
static inline void AdvanceBuffer(BmpBuffer *buffer)
{
if (buffer->read < 0) return;
buffer->read = (int)fread(buffer->data, 1, BMP_BUFFER_SIZE, buffer->file);
buffer->pos = 0;
}
static inline bool EndOfBuffer(BmpBuffer *buffer)
{
if (buffer->read < 0) return false;
if (buffer->pos == buffer->read || buffer->pos < 0) AdvanceBuffer(buffer);
return buffer->pos == buffer->read;
}
static inline uint8_t ReadByte(BmpBuffer *buffer)
{
if (buffer->read < 0) return 0;
if (buffer->pos == buffer->read || buffer->pos < 0) AdvanceBuffer(buffer);
buffer->real_pos++;
return buffer->data[buffer->pos++];
}
static inline uint16_t ReadWord(BmpBuffer *buffer)
{
uint16_t var = ReadByte(buffer);
return var | (ReadByte(buffer) << 8);
}
static inline uint32_t ReadDword(BmpBuffer *buffer)
{
uint32_t var = ReadWord(buffer);
return var | (ReadWord(buffer) << 16);
}
static inline void SkipBytes(BmpBuffer *buffer, int bytes)
{
int i;
for (i = 0; i < bytes; i++) ReadByte(buffer);
}
static inline void SetStreamOffset(BmpBuffer *buffer, int offset)
{
if (fseek(buffer->file, offset, SEEK_SET) < 0) {
buffer->read = -1;
}
buffer->pos = -1;
buffer->real_pos = offset;
AdvanceBuffer(buffer);
}
/**
* Reads a 1 bpp uncompressed bitmap
* The bitmap is converted to a 8 bpp bitmap
*/
static inline bool BmpRead1(RandomAccessFile &file, BmpInfo &info, BmpData &data)
static inline bool BmpRead1(BmpBuffer *buffer, BmpInfo *info, BmpData *data)
{
uint8_t pad = GB(4 - info.width / 8, 0, 2);
for (uint y = info.height; y > 0; y--) {
uint x = 0;
uint8_t *pixel_row = &data.bitmap[(y - 1) * static_cast<size_t>(info.width)];
while (x < info.width) {
if (file.AtEndOfFile()) return false; // the file is shorter than expected
uint8_t b = file.ReadByte();
for (uint i = 8; i > 0; i--) {
if (x < info.width) *pixel_row++ = GB(b, i - 1, 1);
uint x, y, i;
uint8_t pad = GB(4 - info->width / 8, 0, 2);
uint8_t *pixel_row;
uint8_t b;
for (y = info->height; y > 0; y--) {
x = 0;
pixel_row = &data->bitmap[(y - 1) * info->width];
while (x < info->width) {
if (EndOfBuffer(buffer)) return false; // the file is shorter than expected
b = ReadByte(buffer);
for (i = 8; i > 0; i--) {
if (x < info->width) *pixel_row++ = GB(b, i - 1, 1);
x++;
}
}
/* Padding for 32 bit align */
file.SkipBytes(pad);
SkipBytes(buffer, pad);
}
return true;
}
@@ -42,24 +107,27 @@ static inline bool BmpRead1(RandomAccessFile &file, BmpInfo &info, BmpData &data
* Reads a 4 bpp uncompressed bitmap
* The bitmap is converted to a 8 bpp bitmap
*/
static inline bool BmpRead4(RandomAccessFile &file, BmpInfo &info, BmpData &data)
static inline bool BmpRead4(BmpBuffer *buffer, BmpInfo *info, BmpData *data)
{
uint8_t pad = GB(4 - info.width / 2, 0, 2);
for (uint y = info.height; y > 0; y--) {
uint x = 0;
uint8_t *pixel_row = &data.bitmap[(y - 1) * static_cast<size_t>(info.width)];
while (x < info.width) {
if (file.AtEndOfFile()) return false; // the file is shorter than expected
uint8_t b = file.ReadByte();
uint x, y;
uint8_t pad = GB(4 - info->width / 2, 0, 2);
uint8_t *pixel_row;
uint8_t b;
for (y = info->height; y > 0; y--) {
x = 0;
pixel_row = &data->bitmap[(y - 1) * info->width];
while (x < info->width) {
if (EndOfBuffer(buffer)) return false; // the file is shorter than expected
b = ReadByte(buffer);
*pixel_row++ = GB(b, 4, 4);
x++;
if (x < info.width) {
if (x < info->width) {
*pixel_row++ = GB(b, 0, 4);
x++;
}
}
/* Padding for 32 bit align */
file.SkipBytes(pad);
SkipBytes(buffer, pad);
}
return true;
}
@@ -68,56 +136,56 @@ static inline bool BmpRead4(RandomAccessFile &file, BmpInfo &info, BmpData &data
* Reads a 4-bit RLE compressed bitmap
* The bitmap is converted to a 8 bpp bitmap
*/
static inline bool BmpRead4Rle(RandomAccessFile &file, BmpInfo &info, BmpData &data)
static inline bool BmpRead4Rle(BmpBuffer *buffer, BmpInfo *info, BmpData *data)
{
uint x = 0;
uint y = info.height - 1;
uint8_t *pixel = &data.bitmap[y * static_cast<size_t>(info.width)];
while (y != 0 || x < info.width) {
if (file.AtEndOfFile()) return false; // the file is shorter than expected
uint y = info->height - 1;
uint8_t *pixel = &data->bitmap[y * info->width];
while (y != 0 || x < info->width) {
if (EndOfBuffer(buffer)) return false; // the file is shorter than expected
uint8_t n = file.ReadByte();
uint8_t c = file.ReadByte();
uint8_t n = ReadByte(buffer);
uint8_t c = ReadByte(buffer);
if (n == 0) {
switch (c) {
case 0: // end of line
x = 0;
if (y == 0) return false;
pixel = &data.bitmap[--y * static_cast<size_t>(info.width)];
pixel = &data->bitmap[--y * info->width];
break;
case 1: // end of bitmap
return true;
case 2: { // delta
if (file.AtEndOfFile()) return false;
uint8_t dx = file.ReadByte();
uint8_t dy = file.ReadByte();
if (EndOfBuffer(buffer)) return false;
uint8_t dx = ReadByte(buffer);
uint8_t dy = ReadByte(buffer);
/* Check for over- and underflow. */
if (x + dx >= info.width || x + dx < x || dy > y) return false;
if (x + dx >= info->width || x + dx < x || dy > y) return false;
x += dx;
y -= dy;
pixel = &data.bitmap[y * info.width + x];
pixel = &data->bitmap[y * info->width + x];
break;
}
default: { // uncompressed
uint i = 0;
while (i++ < c) {
if (file.AtEndOfFile() || x >= info.width) return false;
uint8_t b = file.ReadByte();
if (EndOfBuffer(buffer) || x >= info->width) return false;
uint8_t b = ReadByte(buffer);
*pixel++ = GB(b, 4, 4);
x++;
if (i++ < c) {
if (x >= info.width) return false;
if (x >= info->width) return false;
*pixel++ = GB(b, 0, 4);
x++;
}
}
/* Padding for 16 bit align */
file.SkipBytes(((c + 1) / 2) % 2);
SkipBytes(buffer, ((c + 1) / 2) % 2);
break;
}
}
@@ -126,10 +194,10 @@ static inline bool BmpRead4Rle(RandomAccessFile &file, BmpInfo &info, BmpData &d
* pixels to be written is higher than the remaining line width.
* Ignore the superfluous pixels instead of reporting an error. */
uint i = 0;
while (x < info.width && i++ < n) {
while (x < info->width && i++ < n) {
*pixel++ = GB(c, 4, 4);
x++;
if (x < info.width && i++ < n) {
if (x < info->width && i++ < n) {
*pixel++ = GB(c, 0, 4);
x++;
}
@@ -142,15 +210,18 @@ static inline bool BmpRead4Rle(RandomAccessFile &file, BmpInfo &info, BmpData &d
/**
* Reads a 8 bpp bitmap
*/
static inline bool BmpRead8(RandomAccessFile &file, BmpInfo &info, BmpData &data)
static inline bool BmpRead8(BmpBuffer *buffer, BmpInfo *info, BmpData *data)
{
uint8_t pad = GB(4 - info.width, 0, 2);
for (uint y = info.height; y > 0; y--) {
if (file.AtEndOfFile()) return false; // the file is shorter than expected
uint8_t *pixel = &data.bitmap[(y - 1) * static_cast<size_t>(info.width)];
for (uint i = 0; i < info.width; i++) *pixel++ = file.ReadByte();
uint i;
uint y;
uint8_t pad = GB(4 - info->width, 0, 2);
uint8_t *pixel;
for (y = info->height; y > 0; y--) {
if (EndOfBuffer(buffer)) return false; // the file is shorter than expected
pixel = &data->bitmap[(y - 1) * info->width];
for (i = 0; i < info->width; i++) *pixel++ = ReadByte(buffer);
/* Padding for 32 bit align */
file.SkipBytes(pad);
SkipBytes(buffer, pad);
}
return true;
}
@@ -158,49 +229,49 @@ static inline bool BmpRead8(RandomAccessFile &file, BmpInfo &info, BmpData &data
/**
* Reads a 8-bit RLE compressed bpp bitmap
*/
static inline bool BmpRead8Rle(RandomAccessFile &file, BmpInfo &info, BmpData &data)
static inline bool BmpRead8Rle(BmpBuffer *buffer, BmpInfo *info, BmpData *data)
{
uint x = 0;
uint y = info.height - 1;
uint8_t *pixel = &data.bitmap[y * static_cast<size_t>(info.width)];
while (y != 0 || x < info.width) {
if (file.AtEndOfFile()) return false; // the file is shorter than expected
uint y = info->height - 1;
uint8_t *pixel = &data->bitmap[y * info->width];
while (y != 0 || x < info->width) {
if (EndOfBuffer(buffer)) return false; // the file is shorter than expected
uint8_t n = file.ReadByte();
uint8_t c = file.ReadByte();
uint8_t n = ReadByte(buffer);
uint8_t c = ReadByte(buffer);
if (n == 0) {
switch (c) {
case 0: // end of line
x = 0;
if (y == 0) return false;
pixel = &data.bitmap[--y * static_cast<size_t>(info.width)];
pixel = &data->bitmap[--y * info->width];
break;
case 1: // end of bitmap
return true;
case 2: { // delta
if (file.AtEndOfFile()) return false;
uint8_t dx = file.ReadByte();
uint8_t dy = file.ReadByte();
if (EndOfBuffer(buffer)) return false;
uint8_t dx = ReadByte(buffer);
uint8_t dy = ReadByte(buffer);
/* Check for over- and underflow. */
if (x + dx >= info.width || x + dx < x || dy > y) return false;
if (x + dx >= info->width || x + dx < x || dy > y) return false;
x += dx;
y -= dy;
pixel = &data.bitmap[y * static_cast<size_t>(info.width) + x];
pixel = &data->bitmap[y * info->width + x];
break;
}
default: { // uncompressed
for (uint i = 0; i < c; i++) {
if (file.AtEndOfFile() || x >= info.width) return false;
*pixel++ = file.ReadByte();
if (EndOfBuffer(buffer) || x >= info->width) return false;
*pixel++ = ReadByte(buffer);
x++;
}
/* Padding for 16 bit align */
file.SkipBytes(c % 2);
SkipBytes(buffer, c % 2);
break;
}
}
@@ -208,7 +279,7 @@ static inline bool BmpRead8Rle(RandomAccessFile &file, BmpInfo &info, BmpData &d
/* Apparently it is common to encounter BMPs where the count of
* pixels to be written is higher than the remaining line width.
* Ignore the superfluous pixels instead of reporting an error. */
for (uint i = 0; x < info.width && i < n; i++) {
for (uint i = 0; x < info->width && i < n; i++) {
*pixel++ = c;
x++;
}
@@ -220,20 +291,22 @@ static inline bool BmpRead8Rle(RandomAccessFile &file, BmpInfo &info, BmpData &d
/**
* Reads a 24 bpp uncompressed bitmap
*/
static inline bool BmpRead24(RandomAccessFile &file, BmpInfo &info, BmpData &data)
static inline bool BmpRead24(BmpBuffer *buffer, BmpInfo *info, BmpData *data)
{
uint8_t pad = GB(4 - info.width * 3, 0, 2);
for (uint y = info.height; y > 0; --y) {
uint8_t *pixel_row = &data.bitmap[(y - 1) * static_cast<size_t>(info.width) * 3];
for (uint x = 0; x < info.width; ++x) {
if (file.AtEndOfFile()) return false; // the file is shorter than expected
*(pixel_row + 2) = file.ReadByte(); // green
*(pixel_row + 1) = file.ReadByte(); // blue
*pixel_row = file.ReadByte(); // red
uint x, y;
uint8_t pad = GB(4 - info->width * 3, 0, 2);
uint8_t *pixel_row;
for (y = info->height; y > 0; y--) {
pixel_row = &data->bitmap[(y - 1) * info->width * 3];
for (x = 0; x < info->width; x++) {
if (EndOfBuffer(buffer)) return false; // the file is shorter than expected
*(pixel_row + 2) = ReadByte(buffer); // green
*(pixel_row + 1) = ReadByte(buffer); // blue
*pixel_row = ReadByte(buffer); // red
pixel_row += 3;
}
/* Padding for 32 bit align */
file.SkipBytes(pad);
SkipBytes(buffer, pad);
}
return true;
}
@@ -241,98 +314,109 @@ static inline bool BmpRead24(RandomAccessFile &file, BmpInfo &info, BmpData &dat
/*
* Reads bitmap headers, and palette (if any)
*/
bool BmpReadHeader(RandomAccessFile &file, BmpInfo &info, BmpData &data)
bool BmpReadHeader(BmpBuffer *buffer, BmpInfo *info, BmpData *data)
{
info = {};
uint32_t header_size;
assert(info != nullptr);
MemSetT(info, 0);
/* Reading BMP header */
if (file.ReadWord() != 0x4D42) return false; // signature should be 'BM'
file.SkipBytes(8); // skip file size and reserved
info.offset = file.ReadDword() + file.GetStartPos();
if (ReadWord(buffer) != 0x4D42) return false; // signature should be 'BM'
SkipBytes(buffer, 8); // skip file size and reserved
info->offset = ReadDword(buffer);
/* Reading info header */
uint32_t header_size = file.ReadDword();
header_size = ReadDword(buffer);
if (header_size < 12) return false; // info header should be at least 12 bytes long
info.os2_bmp = (header_size == 12); // OS/2 1.x or windows 2.x info header is 12 bytes long
info->os2_bmp = (header_size == 12); // OS/2 1.x or windows 2.x info header is 12 bytes long
if (info.os2_bmp) {
info.width = file.ReadWord();
info.height = file.ReadWord();
if (info->os2_bmp) {
info->width = ReadWord(buffer);
info->height = ReadWord(buffer);
header_size -= 8;
} else {
info.width = file.ReadDword();
info.height = file.ReadDword();
info->width = ReadDword(buffer);
info->height = ReadDword(buffer);
header_size -= 12;
}
if (file.ReadWord() != 1) return false; // BMP can have only 1 plane
if (ReadWord(buffer) != 1) return false; // BMP can have only 1 plane
info.bpp = file.ReadWord();
if (info.bpp != 1 && info.bpp != 4 && info.bpp != 8 && info.bpp != 24) {
info->bpp = ReadWord(buffer);
if (info->bpp != 1 && info->bpp != 4 && info->bpp != 8 && info->bpp != 24) {
/* Only 1 bpp, 4 bpp, 8bpp and 24 bpp bitmaps are supported */
return false;
}
/* Reads compression method if available in info header*/
if ((header_size -= 4) >= 4) {
info.compression = file.ReadDword();
info->compression = ReadDword(buffer);
header_size -= 4;
}
/* Only 4-bit and 8-bit rle compression is supported */
if (info.compression > 2 || (info.compression > 0 && !(info.bpp == 4 || info.bpp == 8))) return false;
if (info->compression > 2 || (info->compression > 0 && !(info->bpp == 4 || info->bpp == 8))) return false;
if (info->bpp <= 8) {
uint i;
if (info.bpp <= 8) {
/* Reads number of colours if available in info header */
if (header_size >= 16) {
file.SkipBytes(12); // skip image size and resolution
info.palette_size = file.ReadDword(); // number of colours in palette
file.SkipBytes(header_size - 16); // skip the end of info header
SkipBytes(buffer, 12); // skip image size and resolution
info->palette_size = ReadDword(buffer); // number of colours in palette
SkipBytes(buffer, header_size - 16); // skip the end of info header
}
uint maximum_palette_size = 1U << info.bpp;
if (info.palette_size == 0) info.palette_size = maximum_palette_size;
uint maximum_palette_size = 1U << info->bpp;
if (info->palette_size == 0) info->palette_size = maximum_palette_size;
/* More palette colours than palette indices is not supported. */
if (info.palette_size > maximum_palette_size) return false;
if (info->palette_size > maximum_palette_size) return false;
data.palette.resize(info.palette_size);
data->palette = CallocT<Colour>(info->palette_size);
for (auto &colour : data.palette) {
colour.b = file.ReadByte();
colour.g = file.ReadByte();
colour.r = file.ReadByte();
if (!info.os2_bmp) file.SkipBytes(1); // unused
for (i = 0; i < info->palette_size; i++) {
data->palette[i].b = ReadByte(buffer);
data->palette[i].g = ReadByte(buffer);
data->palette[i].r = ReadByte(buffer);
if (!info->os2_bmp) SkipBytes(buffer, 1); // unused
}
}
return file.GetPos() <= info.offset;
return buffer->real_pos <= info->offset;
}
/*
* Reads the bitmap
* 1 bpp and 4 bpp bitmaps are converted to 8 bpp bitmaps
*/
bool BmpReadBitmap(RandomAccessFile &file, BmpInfo &info, BmpData &data)
bool BmpReadBitmap(BmpBuffer *buffer, BmpInfo *info, BmpData *data)
{
data.bitmap.resize(static_cast<size_t>(info.width) * info.height * ((info.bpp == 24) ? 3 : 1));
assert(info != nullptr && data != nullptr);
data->bitmap = CallocT<uint8_t>(static_cast<size_t>(info->width) * info->height * ((info->bpp == 24) ? 3 : 1));
/* Load image */
file.SeekTo(info.offset, SEEK_SET);
switch (info.compression) {
case 0: // no compression
switch (info.bpp) {
case 1: return BmpRead1(file, info, data);
case 4: return BmpRead4(file, info, data);
case 8: return BmpRead8(file, info, data);
case 24: return BmpRead24(file, info, data);
default: NOT_REACHED();
}
break;
case 1: return BmpRead8Rle(file, info, data); // 8-bit RLE compression
case 2: return BmpRead4Rle(file, info, data); // 4-bit RLE compression
SetStreamOffset(buffer, info->offset);
switch (info->compression) {
case 0: // no compression
switch (info->bpp) {
case 1: return BmpRead1(buffer, info, data);
case 4: return BmpRead4(buffer, info, data);
case 8: return BmpRead8(buffer, info, data);
case 24: return BmpRead24(buffer, info, data);
default: NOT_REACHED();
}
case 1: return BmpRead8Rle(buffer, info, data); // 8-bit RLE compression
case 2: return BmpRead4Rle(buffer, info, data); // 4-bit RLE compression
default: NOT_REACHED();
}
}
void BmpDestroyData(BmpData *data)
{
assert(data != nullptr);
free(data->palette);
free(data->bitmap);
}

View File

@@ -11,10 +11,9 @@
#define BMP_H
#include "gfx_type.h"
#include "random_access_file_type.h"
struct BmpInfo {
size_t offset; ///< offset of bitmap data from .bmp file beginning
uint32_t offset; ///< offset of bitmap data from .bmp file beginning
uint32_t width; ///< bitmap width
uint32_t height; ///< bitmap height
bool os2_bmp; ///< true if OS/2 1.x or windows 2.x bitmap
@@ -24,11 +23,23 @@ struct BmpInfo {
};
struct BmpData {
std::vector<Colour> palette;
std::vector<uint8_t> bitmap;
Colour *palette;
uint8_t *bitmap;
};
bool BmpReadHeader(RandomAccessFile &file, BmpInfo &info, BmpData &data);
bool BmpReadBitmap(RandomAccessFile &file, BmpInfo &info, BmpData &data);
#define BMP_BUFFER_SIZE 1024
struct BmpBuffer {
uint8_t data[BMP_BUFFER_SIZE];
int pos;
int read;
FILE *file;
uint real_pos;
};
void BmpInitializeBuffer(BmpBuffer *buffer, FILE *file);
bool BmpReadHeader(BmpBuffer *buffer, BmpInfo *info, BmpData *data);
bool BmpReadBitmap(BmpBuffer *buffer, BmpInfo *info, BmpData *data);
void BmpDestroyData(BmpData *data);
#endif /* BMP_H */

View File

@@ -44,13 +44,13 @@ static WindowDesc _background_desc(
WDP_MANUAL, nullptr, 0, 0,
WC_BOOTSTRAP, WC_NONE,
WDF_NO_CLOSE,
_background_widgets
std::begin(_background_widgets), std::end(_background_widgets)
);
/** The background for the game. */
class BootstrapBackground : public Window {
public:
BootstrapBackground() : Window(_background_desc)
BootstrapBackground() : Window(&_background_desc)
{
this->InitNested(0);
CLRBITS(this->flags, WF_WHITE_BORDER);
@@ -80,13 +80,13 @@ static WindowDesc _bootstrap_errmsg_desc(
WDP_CENTER, nullptr, 0, 0,
WC_BOOTSTRAP, WC_NONE,
WDF_MODAL | WDF_NO_CLOSE,
_nested_bootstrap_errmsg_widgets
std::begin(_nested_bootstrap_errmsg_widgets), std::end(_nested_bootstrap_errmsg_widgets)
);
/** The window for a failed bootstrap. */
class BootstrapErrorWindow : public Window {
public:
BootstrapErrorWindow() : Window(_bootstrap_errmsg_desc)
BootstrapErrorWindow() : Window(&_bootstrap_errmsg_desc)
{
this->InitNested(1);
}
@@ -137,7 +137,7 @@ static WindowDesc _bootstrap_download_status_window_desc(
WDP_CENTER, nullptr, 0, 0,
WC_NETWORK_STATUS_WINDOW, WC_NONE,
WDF_MODAL | WDF_NO_CLOSE,
_nested_bootstrap_download_status_window_widgets
std::begin(_nested_bootstrap_download_status_window_widgets), std::end(_nested_bootstrap_download_status_window_widgets)
);
@@ -145,7 +145,7 @@ static WindowDesc _bootstrap_download_status_window_desc(
struct BootstrapContentDownloadStatusWindow : public BaseNetworkContentDownloadStatusWindow {
public:
/** Simple call the constructor of the superclass. */
BootstrapContentDownloadStatusWindow() : BaseNetworkContentDownloadStatusWindow(_bootstrap_download_status_window_desc)
BootstrapContentDownloadStatusWindow() : BaseNetworkContentDownloadStatusWindow(&_bootstrap_download_status_window_desc)
{
}
@@ -189,7 +189,7 @@ static WindowDesc _bootstrap_query_desc(
WDP_CENTER, nullptr, 0, 0,
WC_CONFIRM_POPUP_QUERY, WC_NONE,
WDF_NO_CLOSE,
_bootstrap_query_widgets
std::begin(_bootstrap_query_widgets), std::end(_bootstrap_query_widgets)
);
/** The window for the query. It can't use the generic query window as that uses sprites that don't exist yet. */
@@ -198,7 +198,7 @@ class BootstrapAskForDownloadWindow : public Window, ContentCallback {
public:
/** Start listening to the content client events. */
BootstrapAskForDownloadWindow() : Window(_bootstrap_query_desc)
BootstrapAskForDownloadWindow() : Window(&_bootstrap_query_desc)
{
this->InitNested(WN_CONFIRM_POPUP_QUERY_BOOTSTRAP);
_network_content_client.AddCallback(this);

View File

@@ -27,13 +27,12 @@ enum BridgePieces {
BRIDGE_PIECE_MIDDLE_ODD,
BRIDGE_PIECE_MIDDLE_EVEN,
BRIDGE_PIECE_HEAD,
NUM_BRIDGE_PIECES,
BRIDGE_PIECE_INVALID,
};
DECLARE_POSTFIX_INCREMENT(BridgePieces)
static const uint MAX_BRIDGES = 13; ///< Maximal number of available bridge specs.
constexpr uint SPRITES_PER_BRIDGE_PIECE = 32; ///< Number of sprites there are per bridge piece.
typedef uint BridgeType; ///< Bridge spec number.

View File

@@ -151,7 +151,7 @@ private:
}
public:
BuildBridgeWindow(WindowDesc &desc, TileIndex start, TileIndex end, TransportType transport_type, uint8_t road_rail_type, GUIBridgeList &&bl) : Window(desc),
BuildBridgeWindow(WindowDesc *desc, TileIndex start, TileIndex end, TransportType transport_type, uint8_t road_rail_type, GUIBridgeList &&bl) : Window(desc),
start_tile(start),
end_tile(end),
transport_type(transport_type),
@@ -338,7 +338,7 @@ static WindowDesc _build_bridge_desc(
WDP_AUTO, "build_bridge", 200, 114,
WC_BUILD_BRIDGE, WC_BUILD_TOOLBAR,
WDF_CONSTRUCTION,
_nested_build_bridge_widgets
std::begin(_nested_build_bridge_widgets), std::end(_nested_build_bridge_widgets)
);
/**
@@ -435,7 +435,7 @@ void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transpo
}
if (!bl.empty()) {
new BuildBridgeWindow(_build_bridge_desc, start, end, transport_type, road_rail_type, std::move(bl));
new BuildBridgeWindow(&_build_bridge_desc, start, end, transport_type, road_rail_type, std::move(bl));
} else {
ShowErrorMessage(STR_ERROR_CAN_T_BUILD_BRIDGE_HERE, errmsg, WL_INFO, TileX(end) * TILE_SIZE, TileY(end) * TILE_SIZE);
}

View File

@@ -1048,9 +1048,9 @@ void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_li
for (auto it = first; it != last; ++it) {
const auto &item = *it;
uint indent = item.indent * WidgetDimensions::scaled.hsep_indent;
bool has_variants = HasFlag(item.flags, EngineDisplayFlags::HasVariants);
bool is_folded = HasFlag(item.flags, EngineDisplayFlags::IsFolded);
bool shaded = HasFlag(item.flags, EngineDisplayFlags::Shaded);
bool has_variants = (item.flags & EngineDisplayFlags::HasVariants) != EngineDisplayFlags::None;
bool is_folded = (item.flags & EngineDisplayFlags::IsFolded) != EngineDisplayFlags::None;
bool shaded = (item.flags & EngineDisplayFlags::Shaded) != EngineDisplayFlags::None;
if (item.indent > 0) {
/* Draw tree continuation lines. */
@@ -1138,9 +1138,9 @@ void GUIEngineListAddChildren(GUIEngineList &dst, const GUIEngineList &src, Engi
dst.emplace_back(e->display_last_variant == INVALID_ENGINE ? item.engine_id : e->display_last_variant, item.engine_id, flags, indent);
/* Add variants if not folded */
if (HasFlag(item.flags, EngineDisplayFlags::HasVariants) && !HasFlag(item.flags, EngineDisplayFlags::IsFolded)) {
if ((item.flags & (EngineDisplayFlags::HasVariants | EngineDisplayFlags::IsFolded)) == EngineDisplayFlags::HasVariants) {
/* Add this engine again as a child */
if (!HasFlag(item.flags, EngineDisplayFlags::Shaded)) {
if ((item.flags & EngineDisplayFlags::Shaded) == EngineDisplayFlags::None) {
dst.emplace_back(item.engine_id, item.engine_id, EngineDisplayFlags::None, indent + 1);
}
GUIEngineListAddChildren(dst, src, item.engine_id, indent + 1);
@@ -1201,7 +1201,7 @@ struct BuildVehicleWindow : Window {
}
}
BuildVehicleWindow(WindowDesc &desc, TileIndex tile, VehicleType type) : Window(desc), vehicle_editbox(MAX_LENGTH_VEHICLE_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_VEHICLE_NAME_CHARS)
BuildVehicleWindow(WindowDesc *desc, TileIndex tile, VehicleType type) : Window(desc), vehicle_editbox(MAX_LENGTH_VEHICLE_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_VEHICLE_NAME_CHARS)
{
this->vehicle_type = type;
this->listview_mode = tile == INVALID_TILE;
@@ -1256,7 +1256,7 @@ struct BuildVehicleWindow : Window {
/* Select the first unshaded engine in the list as default when opening the window */
EngineID engine = INVALID_ENGINE;
auto it = std::ranges::find_if(this->eng_list, [&](GUIEngineListItem &item) { return !HasFlag(item.flags, EngineDisplayFlags::Shaded); });
auto it = std::find_if(this->eng_list.begin(), this->eng_list.end(), [&](GUIEngineListItem &item) { return (item.flags & EngineDisplayFlags::Shaded) == EngineDisplayFlags::None; });
if (it != this->eng_list.end()) engine = it->engine_id;
this->SelectEngine(engine);
}
@@ -1353,7 +1353,7 @@ struct BuildVehicleWindow : Window {
this->eng_list.Filter(this->cargo_filter_criteria);
if (0 == this->eng_list.size()) { // no engine passed through the filter, invalidate the previously selected engine
this->SelectEngine(INVALID_ENGINE);
} else if (std::ranges::find(this->eng_list, this->sel_engine, &GUIEngineListItem::engine_id) == this->eng_list.end()) { // previously selected engine didn't pass the filter, select the first engine of the list
} else if (std::find(this->eng_list.begin(), this->eng_list.end(), this->sel_engine) == this->eng_list.end()) { // previously selected engine didn't pass the filter, select the first engine of the list
this->SelectEngine(this->eng_list[0].engine_id);
}
}
@@ -1426,7 +1426,7 @@ struct BuildVehicleWindow : Window {
/* ensure primary engine of variant group is in list */
for (const auto &variant : variants) {
if (std::ranges::find(list, variant, &GUIEngineListItem::engine_id) == list.end()) {
if (std::find(list.begin(), list.end(), variant) == list.end()) {
const Engine *e = Engine::Get(variant);
list.emplace_back(variant, e->info.variant_id, e->display_flags | EngineDisplayFlags::Shaded, 0);
if (e->u.rail.railveh_type != RAILVEH_WAGON) num_engines++;
@@ -1568,7 +1568,7 @@ struct BuildVehicleWindow : Window {
}
for (const auto &variant : variants) {
if (std::ranges::find(this->eng_list, variant, &GUIEngineListItem::engine_id) == this->eng_list.end()) {
if (std::find(this->eng_list.begin(), this->eng_list.end(), variant) == this->eng_list.end()) {
const Engine *e = Engine::Get(variant);
this->eng_list.emplace_back(variant, e->info.variant_id, e->display_flags | EngineDisplayFlags::Shaded, 0);
}
@@ -1606,35 +1606,6 @@ struct BuildVehicleWindow : Window {
return list;
}
void BuildVehicle()
{
EngineID sel_eng = this->sel_engine;
if (sel_eng == INVALID_ENGINE) return;
CargoID cargo = this->cargo_filter_criteria;
if (cargo == CargoFilterCriteria::CF_ANY || cargo == CargoFilterCriteria::CF_ENGINES || cargo == CargoFilterCriteria::CF_NONE) cargo = INVALID_CARGO;
if (this->vehicle_type == VEH_TRAIN && RailVehInfo(sel_eng)->railveh_type == RAILVEH_WAGON) {
Command<CMD_BUILD_VEHICLE>::Post(GetCmdBuildVehMsg(this->vehicle_type), CcBuildWagon, this->window_number, sel_eng, true, cargo, INVALID_CLIENT_ID);
} else {
Command<CMD_BUILD_VEHICLE>::Post(GetCmdBuildVehMsg(this->vehicle_type), CcBuildPrimaryVehicle, this->window_number, sel_eng, true, cargo, INVALID_CLIENT_ID);
}
/* Update last used variant in hierarchy and refresh if necessary. */
bool refresh = false;
EngineID parent = sel_eng;
while (parent != INVALID_ENGINE) {
Engine *e = Engine::Get(parent);
refresh |= (e->display_last_variant != sel_eng);
e->display_last_variant = sel_eng;
parent = e->info.variant_id;
}
if (refresh) {
InvalidateWindowData(WC_REPLACE_VEHICLE, this->vehicle_type, 0); // Update the autoreplace window
InvalidateWindowClassesData(WC_BUILD_VEHICLE); // The build windows needs updating as well
}
}
void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
{
switch (widget) {
@@ -1659,7 +1630,7 @@ struct BuildVehicleWindow : Window {
if (it != this->eng_list.end()) {
const auto &item = *it;
const Rect r = this->GetWidget<NWidgetBase>(widget)->GetCurrentRect().Shrink(WidgetDimensions::scaled.matrix).WithWidth(WidgetDimensions::scaled.hsep_indent * (item.indent + 1), _current_text_dir == TD_RTL);
if (HasFlag(item.flags, EngineDisplayFlags::HasVariants) && IsInsideMM(r.left, r.right, pt.x)) {
if ((item.flags & EngineDisplayFlags::HasVariants) != EngineDisplayFlags::None && IsInsideMM(r.left, r.right, pt.x)) {
/* toggle folded flag on engine */
assert(item.variant_id != INVALID_ENGINE);
Engine *engine = Engine::Get(item.variant_id);
@@ -1669,7 +1640,7 @@ struct BuildVehicleWindow : Window {
InvalidateWindowClassesData(WC_BUILD_VEHICLE); // The build windows needs updating as well
return;
}
if (!HasFlag(item.flags, EngineDisplayFlags::Shaded)) e = item.engine_id;
if ((item.flags & EngineDisplayFlags::Shaded) == EngineDisplayFlags::None) e = item.engine_id;
}
this->SelectEngine(e);
this->SetDirty();
@@ -1697,9 +1668,34 @@ struct BuildVehicleWindow : Window {
break;
}
case WID_BV_BUILD:
this->BuildVehicle();
case WID_BV_BUILD: {
EngineID sel_eng = this->sel_engine;
if (sel_eng != INVALID_ENGINE) {
CargoID cargo = this->cargo_filter_criteria;
if (cargo == CargoFilterCriteria::CF_ANY || cargo == CargoFilterCriteria::CF_ENGINES || cargo == CargoFilterCriteria::CF_NONE) cargo = INVALID_CARGO;
if (this->vehicle_type == VEH_TRAIN && RailVehInfo(sel_eng)->railveh_type == RAILVEH_WAGON) {
Command<CMD_BUILD_VEHICLE>::Post(GetCmdBuildVehMsg(this->vehicle_type), CcBuildWagon, this->window_number, sel_eng, true, cargo, INVALID_CLIENT_ID);
} else {
Command<CMD_BUILD_VEHICLE>::Post(GetCmdBuildVehMsg(this->vehicle_type), CcBuildPrimaryVehicle, this->window_number, sel_eng, true, cargo, INVALID_CLIENT_ID);
}
/* Update last used variant in hierarchy and refresh if necessary. */
bool refresh = false;
EngineID parent = sel_eng;
while (parent != INVALID_ENGINE) {
Engine *e = Engine::Get(parent);
refresh |= (e->display_last_variant != sel_eng);
e->display_last_variant = sel_eng;
parent = e->info.variant_id;
}
if (refresh) {
InvalidateWindowData(WC_REPLACE_VEHICLE, this->vehicle_type, 0); // Update the autoreplace window
InvalidateWindowClassesData(WC_BUILD_VEHICLE); // The build windows needs updating as well
return;
}
}
break;
}
case WID_BV_RENAME: {
EngineID sel_eng = this->sel_engine;
@@ -1857,11 +1853,11 @@ struct BuildVehicleWindow : Window {
}
}
void OnQueryTextFinished(std::optional<std::string> str) override
void OnQueryTextFinished(char *str) override
{
if (!str.has_value()) return;
if (str == nullptr) return;
Command<CMD_RENAME_ENGINE>::Post(STR_ERROR_CAN_T_RENAME_TRAIN_TYPE + this->vehicle_type, this->rename_engine, *str);
Command<CMD_RENAME_ENGINE>::Post(STR_ERROR_CAN_T_RENAME_TRAIN_TYPE + this->vehicle_type, this->rename_engine, str);
}
void OnDropdownSelect(WidgetID widget, int index) override
@@ -1926,7 +1922,7 @@ static WindowDesc _build_vehicle_desc(
WDP_AUTO, "build_vehicle", 240, 268,
WC_BUILD_VEHICLE, WC_NONE,
WDF_CONSTRUCTION,
_nested_build_vehicle_widgets,
std::begin(_nested_build_vehicle_widgets), std::end(_nested_build_vehicle_widgets),
&BuildVehicleWindow::hotkeys
);
@@ -1942,5 +1938,5 @@ void ShowBuildVehicleWindow(TileIndex tile, VehicleType type)
CloseWindowById(WC_BUILD_VEHICLE, num);
new BuildVehicleWindow(_build_vehicle_desc, tile, type);
new BuildVehicleWindow(&_build_vehicle_desc, tile, type);
}

View File

@@ -128,7 +128,7 @@ struct CargoArray : std::array<uint, NUM_CARGO> {
*/
inline uint GetCount() const
{
return std::ranges::count_if(*this, [](uint amount) { return amount != 0; });
return std::count_if(this->begin(), this->end(), [](uint amount) { return amount != 0; });
}
};

View File

@@ -107,7 +107,7 @@ bool CargoDelivery::operator()(CargoPacket *cp)
{
uint remove = this->Preprocess(cp);
this->source->RemoveFromMeta(cp, VehicleCargoList::MTA_DELIVER, remove);
this->payment->PayFinalDelivery(this->cargo, cp, remove, this->current_tile);
this->payment->PayFinalDelivery(cp, remove, this->current_tile);
return this->Postprocess(cp, remove);
}

View File

@@ -40,10 +40,9 @@ class CargoDelivery : public CargoRemoval<VehicleCargoList> {
protected:
TileIndex current_tile; ///< Current tile cargo delivery is happening.
CargoPayment *payment; ///< Payment object where payments will be registered.
CargoID cargo; ///< The cargo type of the cargo.
public:
CargoDelivery(VehicleCargoList *source, uint max_move, CargoID cargo, CargoPayment *payment, TileIndex current_tile) :
CargoRemoval<VehicleCargoList>(source, max_move), current_tile(current_tile), payment(payment), cargo(cargo) {}
CargoDelivery(VehicleCargoList *source, uint max_move, CargoPayment *payment, TileIndex current_tile) :
CargoRemoval<VehicleCargoList>(source, max_move), current_tile(current_tile), payment(payment) {}
bool operator()(CargoPacket *cp);
};

View File

@@ -35,14 +35,17 @@ extern CargoMonitorMap _cargo_pickups;
extern CargoMonitorMap _cargo_deliveries;
/* Constants for encoding and extracting cargo monitors. */
constexpr uint8_t CCB_TOWN_IND_NUMBER_START = 0; ///< Start bit of the town or industry number.
constexpr uint8_t CCB_TOWN_IND_NUMBER_LENGTH = 16; ///< Number of bits of the town or industry number.
constexpr uint8_t CCB_IS_INDUSTRY_BIT = 16; ///< Bit indicating the town/industry number is an industry.
constexpr uint8_t CCB_CARGO_TYPE_START = 19; ///< Start bit of the cargo type field.
constexpr uint8_t CCB_CARGO_TYPE_LENGTH = 6; ///< Number of bits of the cargo type field.
constexpr uint8_t CCB_COMPANY_START = 25; ///< Start bit of the company field.
constexpr uint8_t CCB_COMPANY_LENGTH = 4; ///< Number of bits of the company field.
/** Constants for encoding and extracting cargo monitors. */
enum CargoCompanyBits {
CCB_TOWN_IND_NUMBER_START = 0, ///< Start bit of the town or industry number.
CCB_TOWN_IND_NUMBER_LENGTH = 16, ///< Number of bits of the town or industry number.
CCB_IS_INDUSTRY_BIT = 16, ///< Bit indicating the town/industry number is an industry.
CCB_IS_INDUSTRY_BIT_VALUE = 1ul << CCB_IS_INDUSTRY_BIT, ///< Value of the #CCB_IS_INDUSTRY_BIT bit.
CCB_CARGO_TYPE_START = 19, ///< Start bit of the cargo type field.
CCB_CARGO_TYPE_LENGTH = 6, ///< Number of bits of the cargo type field.
CCB_COMPANY_START = 25, ///< Start bit of the company field.
CCB_COMPANY_LENGTH = 4, ///< Number of bits of the company field.
};
static_assert(NUM_CARGO <= (1 << CCB_CARGO_TYPE_LENGTH));
static_assert(MAX_COMPANIES <= (1 << CCB_COMPANY_LENGTH));

View File

@@ -432,12 +432,11 @@ void VehicleCargoList::AgeCargo()
* @param next_station ID of the station the vehicle will go to next.
* @param order_flags OrderUnloadFlags that will apply to the unload operation.
* @param ge GoodsEntry for getting the flows.
* @param cargo The cargo type of the cargo.
* @param payment Payment object for registering transfers.
* @param current_tile Current tile the cargo handling is happening on.
* return If any cargo will be unloaded.
*/
bool VehicleCargoList::Stage(bool accepted, StationID current_station, StationIDStack next_station, uint8_t order_flags, const GoodsEntry *ge, CargoID cargo, CargoPayment *payment, TileIndex current_tile)
bool VehicleCargoList::Stage(bool accepted, StationID current_station, StationIDStack next_station, uint8_t order_flags, const GoodsEntry *ge, CargoPayment *payment, TileIndex current_tile)
{
this->AssertCountConsistency();
assert(this->action_counts[MTA_LOAD] == 0);
@@ -513,7 +512,7 @@ bool VehicleCargoList::Stage(bool accepted, StationID current_station, StationID
case MTA_TRANSFER:
this->packets.push_front(cp);
/* Add feeder share here to allow reusing field for next station. */
share = payment->PayTransfer(cargo, cp, cp->count, current_tile);
share = payment->PayTransfer(cp, cp->count, current_tile);
cp->AddFeederShare(share);
this->feeder_share += share;
cp->next_hop = cargo_next;
@@ -620,12 +619,11 @@ uint VehicleCargoList::Shift(uint max_move, VehicleCargoList *dest)
* ranges defined by designation_counts.
* @param dest StationCargoList to add transferred cargo to.
* @param max_move Maximum amount of cargo to move.
* @param cargo The cargo type of the cargo.
* @param payment Payment object to register payments in.
* @param current_tile Current tile the cargo handling is happening on.
* @return Amount of cargo actually unloaded.
*/
uint VehicleCargoList::Unload(uint max_move, StationCargoList *dest, CargoID cargo, CargoPayment *payment, TileIndex current_tile)
uint VehicleCargoList::Unload(uint max_move, StationCargoList *dest, CargoPayment *payment, TileIndex current_tile)
{
uint moved = 0;
if (this->action_counts[MTA_TRANSFER] > 0) {
@@ -635,7 +633,7 @@ uint VehicleCargoList::Unload(uint max_move, StationCargoList *dest, CargoID car
}
if (this->action_counts[MTA_TRANSFER] == 0 && this->action_counts[MTA_DELIVER] > 0 && moved < max_move) {
uint move = std::min(this->action_counts[MTA_DELIVER], max_move - moved);
this->ShiftCargo(CargoDelivery(this, move, cargo, payment, current_tile));
this->ShiftCargo(CargoDelivery(this, move, payment, current_tile));
moved += move;
}
return moved;

View File

@@ -478,7 +478,7 @@ public:
void InvalidateCache();
bool Stage(bool accepted, StationID current_station, StationIDStack next_station, uint8_t order_flags, const GoodsEntry *ge, CargoID cargo, CargoPayment *payment, TileIndex current_tile);
bool Stage(bool accepted, StationID current_station, StationIDStack next_station, uint8_t order_flags, const GoodsEntry *ge, CargoPayment *payment, TileIndex current_tile);
/**
* Marks all cargo in the vehicle as to be kept. This is mostly useful for
@@ -498,7 +498,7 @@ public:
template<MoveToAction Tfrom, MoveToAction Tto>
uint Reassign(uint max_move);
uint Return(uint max_move, StationCargoList *dest, StationID next_station, TileIndex current_tile);
uint Unload(uint max_move, StationCargoList *dest, CargoID cargo, CargoPayment *payment, TileIndex current_tile);
uint Unload(uint max_move, StationCargoList *dest, CargoPayment *payment, TileIndex current_tile);
uint Shift(uint max_move, VehicleCargoList *dest);
uint Truncate(uint max_move = UINT_MAX);
uint Reroute(uint max_move, VehicleCargoList *dest, StationID avoid, StationID avoid2, const GoodsEntry *ge);

View File

@@ -19,8 +19,6 @@
#include "table/strings.h"
#include "table/cargo_const.h"
#include <sstream>
#include "safeguards.h"
CargoSpec CargoSpec::array[NUM_CARGO];
@@ -43,20 +41,6 @@ CargoTypes _standard_cargo_mask;
*/
static std::vector<CargoLabel> _default_cargo_labels;
/**
* Default cargo translation for upto version 7 NewGRFs.
* This maps the original 12 cargo slots to their original label. If a climate dependent cargo is not present it will
* map to CT_INVALID. For default cargoes this ends up as a 1:1 mapping via climate slot -> label -> cargo ID.
*/
static std::array<CargoLabel, 12> _climate_dependent_cargo_labels;
/**
* Default cargo translation for version 8+ NewGRFs.
* This maps the 32 "bitnum" cargo slots to their original label. If a bitnum is not present it will
* map to CT_INVALID.
*/
static std::array<CargoLabel, 32> _climate_independent_cargo_labels;
/**
* Set up the default cargo types for the given landscape type.
* @param l Landscape
@@ -67,37 +51,30 @@ void SetupCargoForClimate(LandscapeID l)
_cargo_mask = 0;
_default_cargo_labels.clear();
_climate_dependent_cargo_labels.fill(CT_INVALID);
_climate_independent_cargo_labels.fill(CT_INVALID);
/* Copy from default cargo by label or index. */
auto insert = std::begin(CargoSpec::array);
for (const auto &cl : _default_climate_cargo[l]) {
struct visitor {
const CargoSpec &operator()(const int &index)
{
/* Copy the default cargo by index. */
return _default_cargo[index];
}
const CargoSpec &operator()(const CargoLabel &label)
{
/* Search for label in default cargo types and copy if found. */
auto found = std::ranges::find(_default_cargo, label, &CargoSpec::label);
if (found != std::end(_default_cargo)) return *found;
/* Check if value is an index into the cargo table */
if (std::holds_alternative<int>(cl)) {
/* Copy the default cargo by index. */
*insert = _default_cargo[std::get<int>(cl)];
} else {
/* Search for label in default cargo types and copy if found. */
CargoLabel label = std::get<CargoLabel>(cl);
auto found = std::find_if(std::begin(_default_cargo), std::end(_default_cargo), [&label](const CargoSpec &cs) { return cs.label == label; });
if (found != std::end(_default_cargo)) {
*insert = *found;
} else {
/* Index or label is invalid, this should not happen. */
NOT_REACHED();
}
};
*insert = std::visit(visitor{}, cl);
}
if (insert->IsValid()) {
SetBit(_cargo_mask, insert->Index());
_default_cargo_labels.push_back(insert->label);
_climate_dependent_cargo_labels[insert->Index()] = insert->label;
_climate_independent_cargo_labels[insert->bitnum] = insert->label;
}
++insert;
}
@@ -108,24 +85,6 @@ void SetupCargoForClimate(LandscapeID l)
BuildCargoLabelMap();
}
/**
* Get default climate-dependent cargo translation table for a NewGRF, used if the NewGRF does not provide its own.
* @return Default translation table for GRF version.
*/
std::span<const CargoLabel> GetClimateDependentCargoTranslationTable()
{
return _climate_dependent_cargo_labels;
}
/**
* Get default climate-independent cargo translation table for a NewGRF, used if the NewGRF does not provide its own.
* @return Default translation table for GRF version.
*/
std::span<const CargoLabel> GetClimateIndependentCargoTranslationTable()
{
return _climate_independent_cargo_labels;
}
/**
* Build cargo label map.
* This is called multiple times during NewGRF initialization as cargos are defined, so that TranslateRefitMask() and
@@ -171,6 +130,23 @@ Dimension GetLargestCargoIconSize()
return size;
}
/**
* Find the CargoID of a 'bitnum' value.
* @param bitnum 'bitnum' to find.
* @return First CargoID with the given bitnum, or #INVALID_CARGO if not found or if the provided \a bitnum is invalid.
*/
CargoID GetCargoIDByBitnum(uint8_t bitnum)
{
if (bitnum == INVALID_CARGO_BITNUM) return INVALID_CARGO;
for (const CargoSpec *cs : CargoSpec::Iterate()) {
if (cs->bitnum == bitnum) return cs->Index();
}
/* No matching label was found, so it is invalid */
return INVALID_CARGO;
}
/**
* Get sprite for showing cargo of this type.
* @return Sprite number to use.
@@ -259,41 +235,3 @@ uint64_t CargoSpec::WeightOfNUnitsInTrain(uint32_t n) const
if (this->is_freight) n *= _settings_game.vehicle.freight_trains;
return this->WeightOfNUnits(n);
}
/**
* Build comma-separated cargo acceptance string.
* @param acceptance CargoArray filled with accepted cargo.
* @param label Label to prefix cargo acceptance list.
* @return String of accepted cargo, or nullopt if no cargo is accepted.
*/
std::optional<std::string> BuildCargoAcceptanceString(const CargoArray &acceptance, StringID label)
{
std::string_view list_separator = GetListSeparator();
/* Cargo acceptance is displayed in a extra multiline */
std::stringstream line;
line << GetString(label);
bool found = false;
for (const CargoSpec *cs : _sorted_cargo_specs) {
CargoID cid = cs->Index();
if (acceptance[cid] > 0) {
/* Add a comma between each item. */
if (found) line << list_separator;
found = true;
/* If the accepted value is less than 8, show it in 1/8:ths */
if (acceptance[cid] < 8) {
SetDParam(0, acceptance[cid]);
SetDParam(1, cs->name);
line << GetString(STR_LAND_AREA_INFORMATION_CARGO_EIGHTS);
} else {
line << GetString(cs->name);
}
}
}
if (found) return line.str();
return std::nullopt;
}

View File

@@ -45,7 +45,7 @@ enum TownProductionEffect : uint8_t {
};
/** Cargo classes. */
enum CargoClass : uint16_t {
enum CargoClass {
CC_NOAVAILABLE = 0, ///< No cargo class has been specified
CC_PASSENGERS = 1 << 0, ///< Passengers
CC_MAIL = 1 << 1, ///< Mail
@@ -57,17 +57,9 @@ enum CargoClass : uint16_t {
CC_REFRIGERATED = 1 << 7, ///< Refrigerated cargo (Food, Fruit)
CC_HAZARDOUS = 1 << 8, ///< Hazardous cargo (Nuclear Fuel, Explosives, etc.)
CC_COVERED = 1 << 9, ///< Covered/Sheltered Freight (Transportation in Box Vans, Silo Wagons, etc.)
CC_OVERSIZED = 1 << 10, ///< Oversized (stake/flatbed wagon)
CC_POWDERIZED = 1 << 11, ///< Powderized, moist protected (powder/silo wagon)
CC_NOT_POURABLE = 1 << 12, ///< Not Pourable (open wagon, but not hopper wagon)
CC_POTABLE = 1 << 13, ///< Potable / food / clean.
CC_NON_POTABLE = 1 << 14, ///< Non-potable / non-food / dirty.
CC_SPECIAL = 1 << 15, ///< Special bit used for livery refit tricks instead of normal cargoes.
};
/** Bitmask of cargo classes. */
using CargoClasses = uint16_t;
static const uint8_t INVALID_CARGO_BITNUM = 0xFF; ///< Constant representing invalid cargo
static const uint TOWN_PRODUCTION_DIVISOR = 256;
@@ -80,7 +72,7 @@ struct CargoSpec {
uint8_t rating_colour;
uint8_t weight; ///< Weight of a single unit of this cargo type in 1/16 ton (62.5 kg).
uint16_t multiplier = 0x100; ///< Capacity multiplier for vehicles. (8 fractional bits)
CargoClasses classes; ///< Classes of this cargo type. @see CargoClass
uint16_t classes; ///< Classes of this cargo type. @see CargoClass
int32_t initial_payment; ///< Initial payment rate before inflation is applied.
uint8_t transit_periods[2];
@@ -213,8 +205,7 @@ extern CargoTypes _standard_cargo_mask;
void SetupCargoForClimate(LandscapeID l);
bool IsDefaultCargo(CargoID cid);
void BuildCargoLabelMap();
std::optional<std::string> BuildCargoAcceptanceString(const CargoArray &acceptance, StringID label);
CargoID GetCargoIDByBitnum(uint8_t bitnum);
inline CargoID GetCargoIDByLabel(CargoLabel label)
{

View File

@@ -20,3 +20,20 @@ void InitializeCheats()
{
memset(&_cheats, 0, sizeof(Cheats));
}
/**
* Return true if any cheat has been used, false otherwise
* @return has a cheat been used?
*/
bool CheatHasBeenUsed()
{
/* Cannot use lengthof because _cheats is of type Cheats, not Cheat */
const Cheat *cht = (Cheat*)&_cheats;
const Cheat *cht_last = &cht[sizeof(_cheats) / sizeof(Cheat)];
for (; cht != cht_last; cht++) {
if (cht->been_used) return true;
}
return false;
}

View File

@@ -16,5 +16,6 @@ extern Cheats _cheats;
void ShowCheatWindow();
bool CheatHasBeenUsed();
#endif /* CHEAT_FUNC_H */

View File

@@ -129,7 +129,6 @@ static int32_t ClickChangeDateCheat(int32_t new_value, int32_t)
InvalidateWindowClassesData(WC_BUS_STATION, 0);
InvalidateWindowClassesData(WC_TRUCK_STATION, 0);
InvalidateWindowClassesData(WC_BUILD_OBJECT, 0);
InvalidateWindowClassesData(WC_FINANCES, 0);
ResetSignalVariant();
return TimerGameCalendar::year.base();
}
@@ -146,7 +145,7 @@ static int32_t ClickChangeMaxHlCheat(int32_t new_value, int32_t)
/* Check if at least one mountain on the map is higher than the new value.
* If yes, disallow the change. */
for (const auto t : Map::Iterate()) {
for (TileIndex t = 0; t < Map::Size(); t++) {
if ((int32_t)TileHeight(t) > new_value) {
ShowErrorMessage(STR_CONFIG_SETTING_TOO_HIGH_MOUNTAIN, INVALID_STRING_ID, WL_ERROR);
/* Return old, unchanged value */
@@ -231,7 +230,7 @@ struct CheatWindow : Window {
uint line_height;
Dimension icon; ///< Dimension of company icon sprite
CheatWindow(WindowDesc &desc) : Window(desc)
CheatWindow(WindowDesc *desc) : Window(desc)
{
this->InitNested();
}
@@ -405,14 +404,14 @@ struct CheatWindow : Window {
this->SetDirty();
}
void OnQueryTextFinished(std::optional<std::string> str) override
void OnQueryTextFinished(char *str) override
{
/* Was 'cancel' pressed or nothing entered? */
if (!str.has_value() || str->empty()) return;
if (str == nullptr || StrEmpty(str)) return;
const CheatEntry *ce = &_cheats_ui[clicked_widget];
int oldvalue = (int32_t)ReadValue(ce->variable, ce->type);
int value = atoi(str->c_str());
int value = atoi(str);
*ce->been_used = true;
value = ce->proc(value, value - oldvalue);
@@ -430,12 +429,12 @@ static WindowDesc _cheats_desc(
WDP_AUTO, "cheats", 0, 0,
WC_CHEATS, WC_NONE,
0,
_nested_cheat_widgets
std::begin(_nested_cheat_widgets), std::end(_nested_cheat_widgets)
);
/** Open cheat window. */
void ShowCheatWindow()
{
CloseWindowById(WC_CHEATS, 0);
new CheatWindow(_cheats_desc);
new CheatWindow(&_cheats_desc);
}

View File

@@ -144,11 +144,27 @@ static void UpdateFences(TileIndex tile)
assert(IsTileType(tile, MP_CLEAR) && IsClearGround(tile, CLEAR_FIELDS));
bool dirty = false;
for (DiagDirection dir = DIAGDIR_BEGIN; dir < DIAGDIR_END; dir++) {
if (GetFence(tile, dir) != 0) continue;
TileIndex neighbour = tile + TileOffsByDiagDir(dir);
if (IsTileType(neighbour, MP_CLEAR) && IsClearGround(neighbour, CLEAR_FIELDS)) continue;
SetFence(tile, dir, 3);
bool neighbour = (IsTileType(TileAddXY(tile, 1, 0), MP_CLEAR) && IsClearGround(TileAddXY(tile, 1, 0), CLEAR_FIELDS));
if (!neighbour && GetFence(tile, DIAGDIR_SW) == 0) {
SetFence(tile, DIAGDIR_SW, 3);
dirty = true;
}
neighbour = (IsTileType(TileAddXY(tile, 0, 1), MP_CLEAR) && IsClearGround(TileAddXY(tile, 0, 1), CLEAR_FIELDS));
if (!neighbour && GetFence(tile, DIAGDIR_SE) == 0) {
SetFence(tile, DIAGDIR_SE, 3);
dirty = true;
}
neighbour = (IsTileType(TileAddXY(tile, -1, 0), MP_CLEAR) && IsClearGround(TileAddXY(tile, -1, 0), CLEAR_FIELDS));
if (!neighbour && GetFence(tile, DIAGDIR_NE) == 0) {
SetFence(tile, DIAGDIR_NE, 3);
dirty = true;
}
neighbour = (IsTileType(TileAddXY(tile, 0, -1), MP_CLEAR) && IsClearGround(TileAddXY(tile, 0, -1), CLEAR_FIELDS));
if (!neighbour && GetFence(tile, DIAGDIR_NW) == 0) {
SetFence(tile, DIAGDIR_NW, 3);
dirty = true;
}
@@ -161,28 +177,30 @@ static void TileLoopClearAlps(TileIndex tile)
{
int k = GetTileZ(tile) - GetSnowLine() + 1;
if (!IsSnowTile(tile)) {
if (k < 0) {
/* Below the snow line, do nothing if no snow. */
if (!IsSnowTile(tile)) return;
} else {
/* At or above the snow line, make snow tile if needed. */
if (k >= 0) {
if (!IsSnowTile(tile)) {
MakeSnow(tile);
MarkTileDirtyByTile(tile);
return;
}
return;
}
/* Update snow density. */
uint current_density = GetClearDensity(tile);
uint req_density = (k < 0) ? 0u : std::min<uint>(k, 3u);
if (current_density == req_density) {
if (current_density < req_density) {
AddClearDensity(tile, 1);
} else if (current_density > req_density) {
AddClearDensity(tile, -1);
} else {
/* Density at the required level. */
if (k >= 0) return;
ClearSnow(tile);
} else {
AddClearDensity(tile, current_density < req_density ? 1 : -1);
}
MarkTileDirtyByTile(tile);
}

View File

@@ -27,6 +27,16 @@
*/
static const CommandCost CMD_ERROR = CommandCost(INVALID_STRING_ID);
/**
* Returns from a function with a specific StringID as error.
*
* This macro is used to return from a function. The parameter contains the
* StringID which will be returned.
*
* @param errcode The StringID to return
*/
#define return_cmd_error(errcode) return CommandCost(errcode);
void NetworkSendCommand(Commands cmd, StringID err_message, CommandCallback *callback, CompanyID company, const CommandDataBuffer &cmd_data);
bool IsValidCommand(Commands cmd);

View File

@@ -21,12 +21,12 @@ struct GRFFile;
* a possible error message/state together.
*/
class CommandCost {
ExpensesType expense_type; ///< the type of expence as shown on the finances view
Money cost; ///< The cost of this action
StringID message; ///< Warning message for when success is unset
ExpensesType expense_type; ///< the type of expence as shown on the finances view
bool success; ///< Whether the command went fine up to this moment
const GRFFile *textref_stack_grffile = nullptr; ///< NewGRF providing the #TextRefStack content.
uint textref_stack_size = 0; ///< Number of uint32_t values to put on the #TextRefStack for the error message.
const GRFFile *textref_stack_grffile; ///< NewGRF providing the #TextRefStack content.
uint textref_stack_size; ///< Number of uint32_t values to put on the #TextRefStack for the error message.
StringID extra_message = INVALID_STRING_ID; ///< Additional warning message for when success is unset
static uint32_t textref_stack[16];
@@ -35,25 +35,25 @@ public:
/**
* Creates a command cost return with no cost and no error
*/
CommandCost() : cost(0), message(INVALID_STRING_ID), expense_type(INVALID_EXPENSES), success(true) {}
CommandCost() : expense_type(INVALID_EXPENSES), cost(0), message(INVALID_STRING_ID), success(true), textref_stack_grffile(nullptr), textref_stack_size(0) {}
/**
* Creates a command return value with one, or optionally two, error message strings.
*/
explicit CommandCost(StringID msg, StringID extra_msg = INVALID_STRING_ID) : cost(0), message(msg), expense_type(INVALID_EXPENSES), success(false), extra_message(extra_msg) {}
explicit CommandCost(StringID msg, StringID extra_msg = INVALID_STRING_ID) : expense_type(INVALID_EXPENSES), cost(0), message(msg), success(false), textref_stack_grffile(nullptr), textref_stack_size(0), extra_message(extra_msg) {}
/**
* Creates a command cost with given expense type and start cost of 0
* @param ex_t the expense type
*/
explicit CommandCost(ExpensesType ex_t) : cost(0), message(INVALID_STRING_ID), expense_type(ex_t), success(true) {}
explicit CommandCost(ExpensesType ex_t) : expense_type(ex_t), cost(0), message(INVALID_STRING_ID), success(true), textref_stack_grffile(nullptr), textref_stack_size(0) {}
/**
* Creates a command return value with the given start cost and expense type
* @param ex_t the expense type
* @param cst the initial cost of this command
*/
CommandCost(ExpensesType ex_t, const Money &cst) : cost(cst), message(INVALID_STRING_ID), expense_type(ex_t), success(true) {}
CommandCost(ExpensesType ex_t, const Money &cst) : expense_type(ex_t), cost(cst), message(INVALID_STRING_ID), success(true), textref_stack_grffile(nullptr), textref_stack_size(0) {}
/**
@@ -207,9 +207,6 @@ enum Commands : uint16_t {
CMD_RENAME_WAYPOINT, ///< rename a waypoint
CMD_REMOVE_FROM_RAIL_WAYPOINT, ///< remove a (rectangle of) tiles from a rail waypoint
CMD_BUILD_ROAD_WAYPOINT, ///< build a road waypoint
CMD_REMOVE_FROM_ROAD_WAYPOINT, ///< remove a (rectangle of) tiles from a road waypoint
CMD_BUILD_ROAD_STOP, ///< build a road stop
CMD_REMOVE_ROAD_STOP, ///< remove a road stop
CMD_BUILD_LONG_ROAD, ///< build a complete road (not a "half" one)

View File

@@ -92,7 +92,6 @@ struct CompanyProperties {
TileIndex last_build_coordinate; ///< Coordinate of the last build thing by this company.
TimerGameEconomy::Year inaugurated_year; ///< Economy year of starting the company.
TimerGameCalendar::Year inaugurated_year_calendar; ///< Calendar year of starting the company. Used to display proper Inauguration year while in wallclock mode.
uint8_t months_empty = 0; ///< NOSAVE: Number of months this company has not had a client in multiplayer.
uint8_t months_of_bankruptcy; ///< Number of months that the company is unable to pay its debts

View File

@@ -368,7 +368,7 @@ CommandCost CheckOwnership(Owner owner, TileIndex tile)
if (owner == _current_company) return CommandCost();
SetDParamsForOwnedBy(owner, tile);
return CommandCost(STR_ERROR_OWNED_BY);
return_cmd_error(STR_ERROR_OWNED_BY);
}
/**
@@ -388,7 +388,7 @@ CommandCost CheckTileOwnership(TileIndex tile)
/* no need to get the name of the owner unless we're the local company (saves some time) */
if (IsLocalCompany()) SetDParamsForOwnedBy(owner, tile);
return CommandCost(STR_ERROR_OWNED_BY);
return_cmd_error(STR_ERROR_OWNED_BY);
}
/**
@@ -426,12 +426,12 @@ set_name:;
MarkWholeScreenDirty();
if (c->is_ai) {
auto cni = std::make_unique<CompanyNewsInformation>(c);
CompanyNewsInformation *cni = new CompanyNewsInformation(c);
SetDParam(0, STR_NEWS_COMPANY_LAUNCH_TITLE);
SetDParam(1, STR_NEWS_COMPANY_LAUNCH_DESCRIPTION);
SetDParamStr(2, cni->company_name);
SetDParam(3, t->index);
AddNewsItem(STR_MESSAGE_NEWS_FORMAT, NT_COMPANY_INFO, NF_COMPANY, NR_TILE, c->last_build_coordinate.base(), NR_NONE, UINT32_MAX, std::move(cni));
AddNewsItem(STR_MESSAGE_NEWS_FORMAT, NT_COMPANY_INFO, NF_COMPANY, NR_TILE, c->last_build_coordinate.base(), NR_NONE, UINT32_MAX, cni);
}
return;
}
@@ -608,7 +608,6 @@ Company *DoStartupNewCompany(bool is_ai, CompanyID company = INVALID_COMPANY)
c->avail_railtypes = GetCompanyRailTypes(c->index);
c->avail_roadtypes = GetCompanyRoadTypes(c->index);
c->inaugurated_year = TimerGameEconomy::year;
c->inaugurated_year_calendar = TimerGameCalendar::year;
/* If starting a player company in singleplayer and a favorite company manager face is selected, choose it. Otherwise, use a random face.
* In a network game, we'll choose the favorite face later in CmdCompanyCtrl to sync it to all clients. */
@@ -796,7 +795,7 @@ static IntervalTimer<TimerGameEconomy> _economy_companies_yearly({TimerGameEcono
/* Move expenses to previous years. */
std::rotate(std::rbegin(c->yearly_expenses), std::rbegin(c->yearly_expenses) + 1, std::rend(c->yearly_expenses));
c->yearly_expenses[0] = {};
InvalidateWindowData(WC_FINANCES, c->index);
SetWindowDirty(WC_FINANCES, c->index);
}
if (_settings_client.gui.show_finances && _local_company != COMPANY_SPECTATOR) {
@@ -946,13 +945,13 @@ CommandCost CmdCompanyCtrl(DoCommandFlag flags, CompanyCtrlAction cca, CompanyID
if (!(flags & DC_EXEC)) return CommandCost();
auto cni = std::make_unique<CompanyNewsInformation>(c);
CompanyNewsInformation *cni = new CompanyNewsInformation(c);
/* Show the bankrupt news */
SetDParam(0, STR_NEWS_COMPANY_BANKRUPT_TITLE);
SetDParam(1, STR_NEWS_COMPANY_BANKRUPT_DESCRIPTION);
SetDParamStr(2, cni->company_name);
AddCompanyNewsItem(STR_MESSAGE_NEWS_FORMAT, std::move(cni));
AddCompanyNewsItem(STR_MESSAGE_NEWS_FORMAT, cni);
/* Remove the company */
ChangeOwnershipOfCompanyItems(c->index, INVALID_OWNER);
@@ -1085,7 +1084,7 @@ CommandCost CmdSetCompanyColour(DoCommandFlag flags, LiveryScheme scheme, bool p
if (flags & DC_EXEC) {
if (primary) {
if (scheme != LS_DEFAULT) AssignBit(c->livery[scheme].in_use, 0, colour != INVALID_COLOUR);
if (scheme != LS_DEFAULT) SB(c->livery[scheme].in_use, 0, 1, colour != INVALID_COLOUR);
if (colour == INVALID_COLOUR) colour = c->livery[LS_DEFAULT].colour1;
c->livery[scheme].colour1 = colour;
@@ -1098,7 +1097,7 @@ CommandCost CmdSetCompanyColour(DoCommandFlag flags, LiveryScheme scheme, bool p
CompanyAdminUpdate(c);
}
} else {
if (scheme != LS_DEFAULT) AssignBit(c->livery[scheme].in_use, 1, colour != INVALID_COLOUR);
if (scheme != LS_DEFAULT) SB(c->livery[scheme].in_use, 1, 1, colour != INVALID_COLOUR);
if (colour == INVALID_COLOUR) colour = c->livery[LS_DEFAULT].colour2;
c->livery[scheme].colour2 = colour;
@@ -1172,7 +1171,7 @@ CommandCost CmdRenameCompany(DoCommandFlag flags, const std::string &text)
if (!reset) {
if (Utf8StringLength(text) >= MAX_LENGTH_COMPANY_NAME_CHARS) return CMD_ERROR;
if (!IsUniqueCompanyName(text)) return CommandCost(STR_ERROR_NAME_MUST_BE_UNIQUE);
if (!IsUniqueCompanyName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
}
if (flags & DC_EXEC) {
@@ -1215,7 +1214,7 @@ CommandCost CmdRenamePresident(DoCommandFlag flags, const std::string &text)
if (!reset) {
if (Utf8StringLength(text) >= MAX_LENGTH_PRESIDENT_NAME_CHARS) return CMD_ERROR;
if (!IsUniquePresidentName(text)) return CommandCost(STR_ERROR_NAME_MUST_BE_UNIQUE);
if (!IsUniquePresidentName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
}
if (flags & DC_EXEC) {
@@ -1301,7 +1300,7 @@ CommandCost CmdGiveMoney(DoCommandFlag flags, Money money, CompanyID dest_compan
CommandCost amount(EXPENSES_OTHER, std::min<Money>(money, 20000000LL));
/* You can only transfer funds that is in excess of your loan */
if (c->money - c->current_loan < amount.GetCost() || amount.GetCost() < 0) return CommandCost(STR_ERROR_INSUFFICIENT_FUNDS);
if (c->money - c->current_loan < amount.GetCost() || amount.GetCost() < 0) return_cmd_error(STR_ERROR_INSUFFICIENT_FUNDS);
if (!Company::IsValidID(dest_company)) return CMD_ERROR;
if (flags & DC_EXEC) {

View File

@@ -333,13 +333,10 @@ static constexpr NWidgetPart _nested_company_finances_widgets[] = {
/** Window class displaying the company finances. */
struct CompanyFinancesWindow : Window {
static constexpr int NUM_PERIODS = WID_CF_EXPS_PRICE3 - WID_CF_EXPS_PRICE1 + 1;
static Money max_money; ///< The maximum amount of money a company has had this 'run'
bool small; ///< Window is toggled to 'small'.
uint8_t first_visible = NUM_PERIODS - 1; ///< First visible expenses column. The last column (current) is always visible.
CompanyFinancesWindow(WindowDesc &desc, CompanyID company) : Window(desc)
CompanyFinancesWindow(WindowDesc *desc, CompanyID company) : Window(desc)
{
this->small = false;
this->CreateNestedTree();
@@ -347,7 +344,6 @@ struct CompanyFinancesWindow : Window {
this->FinishInitNested(company);
this->owner = (Owner)this->window_number;
this->InvalidateData();
}
void SetStringParameters(WidgetID widget) const override
@@ -430,12 +426,12 @@ struct CompanyFinancesWindow : Window {
case WID_CF_EXPS_PRICE1:
case WID_CF_EXPS_PRICE2:
case WID_CF_EXPS_PRICE3: {
int period = widget - WID_CF_EXPS_PRICE1;
if (period < this->first_visible) break;
const Company *c = Company::Get((CompanyID)this->window_number);
const auto &expenses = c->yearly_expenses[NUM_PERIODS - period - 1];
DrawYearColumn(r, TimerGameEconomy::year - (NUM_PERIODS - period - 1), expenses);
auto age = std::min(TimerGameEconomy::year - c->inaugurated_year, TimerGameEconomy::Year(2));
int wid_offset = widget - WID_CF_EXPS_PRICE1;
if (wid_offset <= age) {
DrawYearColumn(r, TimerGameEconomy::year - (age - wid_offset), c->yearly_expenses[(age - wid_offset).base()]);
}
break;
}
@@ -518,24 +514,6 @@ struct CompanyFinancesWindow : Window {
}
}
void RefreshVisibleColumns()
{
for (uint period = 0; period < this->first_visible; ++period) {
const Company *c = Company::Get((CompanyID)this->window_number);
const Expenses &expenses = c->yearly_expenses[NUM_PERIODS - period - 1];
/* Show expenses column if it has any non-zero value in it. */
if (std::ranges::any_of(expenses, [](const Money &value) { return value != 0; })) {
this->first_visible = period;
break;
}
}
}
void OnInvalidateData(int, bool) override
{
this->RefreshVisibleColumns();
}
/**
* Check on a regular interval if the maximum amount of money has changed.
* If it has, rescale the window to fit the new amount.
@@ -557,7 +535,7 @@ static WindowDesc _company_finances_desc(
WDP_AUTO, "company_finances", 0, 0,
WC_FINANCES, WC_NONE,
0,
_nested_company_finances_widgets
std::begin(_nested_company_finances_widgets), std::end(_nested_company_finances_widgets)
);
/**
@@ -570,7 +548,7 @@ void ShowCompanyFinances(CompanyID company)
if (!Company::IsValidID(company)) return;
if (BringWindowToFrontById(WC_FINANCES, company)) return;
new CompanyFinancesWindow(_company_finances_desc, company);
new CompanyFinancesWindow(&_company_finances_desc, company);
}
/* Association of liveries to livery classes */
@@ -692,7 +670,7 @@ private:
}
public:
SelectCompanyLiveryWindow(WindowDesc &desc, CompanyID company, GroupID group) : Window(desc)
SelectCompanyLiveryWindow(WindowDesc *desc, CompanyID company, GroupID group) : Window(desc)
{
this->CreateNestedTree();
this->vscroll = this->GetScrollbar(WID_SCL_MATRIX_SCROLLBAR);
@@ -1104,14 +1082,14 @@ static WindowDesc _select_company_livery_desc(
WDP_AUTO, "company_color_scheme", 0, 0,
WC_COMPANY_COLOUR, WC_NONE,
0,
_nested_select_company_livery_widgets
std::begin(_nested_select_company_livery_widgets), std::end(_nested_select_company_livery_widgets)
);
void ShowCompanyLiveryWindow(CompanyID company, GroupID group)
{
SelectCompanyLiveryWindow *w = (SelectCompanyLiveryWindow *)BringWindowToFrontById(WC_COMPANY_COLOUR, company);
if (w == nullptr) {
new SelectCompanyLiveryWindow(_select_company_livery_desc, company, group);
new SelectCompanyLiveryWindow(&_select_company_livery_desc, company, group);
} else if (group != INVALID_GROUP) {
w->SetSelectedGroup(company, group);
}
@@ -1371,7 +1349,7 @@ class SelectCompanyManagerFaceWindow : public Window
}
public:
SelectCompanyManagerFaceWindow(WindowDesc &desc, Window *parent) : Window(desc)
SelectCompanyManagerFaceWindow(WindowDesc *desc, Window *parent) : Window(desc)
{
this->advanced = false;
this->CreateNestedTree();
@@ -1708,12 +1686,12 @@ public:
}
}
void OnQueryTextFinished(std::optional<std::string> str) override
void OnQueryTextFinished(char *str) override
{
if (!str.has_value()) return;
if (str == nullptr) return;
/* Set a new company manager face number */
if (!str->empty()) {
this->face = std::strtoul(str->c_str(), nullptr, 10);
if (!StrEmpty(str)) {
this->face = std::strtoul(str, nullptr, 10);
ScaleAllCompanyManagerFaceBits(this->face);
ShowErrorMessage(STR_FACE_FACECODE_SET, INVALID_STRING_ID, WL_INFO);
this->UpdateData();
@@ -1729,7 +1707,7 @@ static WindowDesc _select_company_manager_face_desc(
WDP_AUTO, nullptr, 0, 0,
WC_COMPANY_MANAGER_FACE, WC_NONE,
WDF_CONSTRUCTION,
_nested_select_company_manager_face_widgets
std::begin(_nested_select_company_manager_face_widgets), std::end(_nested_select_company_manager_face_widgets)
);
/**
@@ -1742,7 +1720,7 @@ static void DoSelectCompanyManagerFace(Window *parent)
if (!Company::IsValidID((CompanyID)parent->window_number)) return;
if (BringWindowToFrontById(WC_COMPANY_MANAGER_FACE, parent->window_number)) return;
new SelectCompanyManagerFaceWindow(_select_company_manager_face_desc, parent);
new SelectCompanyManagerFaceWindow(&_select_company_manager_face_desc, parent);
}
static constexpr NWidgetPart _nested_company_infrastructure_widgets[] = {
@@ -1792,7 +1770,7 @@ struct CompanyInfrastructureWindow : Window
uint total_width; ///< String width of the total cost line.
CompanyInfrastructureWindow(WindowDesc &desc, WindowNumber window_number) : Window(desc)
CompanyInfrastructureWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
{
this->UpdateRailRoadTypes();
@@ -2106,7 +2084,7 @@ static WindowDesc _company_infrastructure_desc(
WDP_AUTO, "company_infrastructure", 0, 0,
WC_COMPANY_INFRASTRUCTURE, WC_NONE,
0,
_nested_company_infrastructure_widgets
std::begin(_nested_company_infrastructure_widgets), std::end(_nested_company_infrastructure_widgets)
);
/**
@@ -2116,7 +2094,7 @@ static WindowDesc _company_infrastructure_desc(
static void ShowCompanyInfrastructure(CompanyID company)
{
if (!Company::IsValidID(company)) return;
AllocateWindowDescFront<CompanyInfrastructureWindow>(_company_infrastructure_desc, company);
AllocateWindowDescFront<CompanyInfrastructureWindow>(&_company_infrastructure_desc, company);
}
static constexpr NWidgetPart _nested_company_widgets[] = {
@@ -2135,7 +2113,7 @@ static constexpr NWidgetPart _nested_company_widgets[] = {
NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0),
NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0),
NWidget(WWT_TEXT, COLOUR_GREY, WID_C_DESC_INAUGURATION), SetDataTip(STR_JUST_STRING2, STR_NULL), SetFill(1, 0),
NWidget(WWT_TEXT, COLOUR_GREY, WID_C_DESC_INAUGURATION), SetDataTip(STR_COMPANY_VIEW_INAUGURATED_TITLE, STR_NULL), SetFill(1, 0),
NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
NWidget(WWT_LABEL, COLOUR_GREY, WID_C_DESC_COLOUR_SCHEME), SetDataTip(STR_COMPANY_VIEW_COLOUR_SCHEME_TITLE, STR_NULL),
NWidget(WWT_EMPTY, INVALID_COLOUR, WID_C_DESC_COLOUR_SCHEME_EXAMPLE), SetMinimalSize(30, 0), SetFill(1, 1),
@@ -2218,7 +2196,7 @@ struct CompanyWindow : Window
CWP_RELOCATE_HIDE, ///< Hide the relocate HQ button.
};
CompanyWindow(WindowDesc &desc, WindowNumber window_number) : Window(desc)
CompanyWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
{
this->InitNested(window_number);
this->owner = (Owner)this->window_number;
@@ -2423,14 +2401,7 @@ struct CompanyWindow : Window
break;
case WID_C_DESC_INAUGURATION:
if (TimerGameEconomy::UsingWallclockUnits()) {
SetDParam(0, STR_COMPANY_VIEW_INAUGURATED_TITLE_WALLCLOCK);
SetDParam(1, Company::Get(static_cast<CompanyID>(this->window_number))->inaugurated_year_calendar);
SetDParam(2, Company::Get(static_cast<CompanyID>(this->window_number))->inaugurated_year);
} else {
SetDParam(0, STR_COMPANY_VIEW_INAUGURATED_TITLE);
SetDParam(1, Company::Get(static_cast<CompanyID>(this->window_number))->inaugurated_year);
}
SetDParam(0, Company::Get((CompanyID)this->window_number)->inaugurated_year);
break;
case WID_C_DESC_COMPANY_VALUE:
@@ -2549,25 +2520,25 @@ struct CompanyWindow : Window
this->RaiseButtons();
}
void OnQueryTextFinished(std::optional<std::string> str) override
void OnQueryTextFinished(char *str) override
{
if (!str.has_value()) return;
if (str == nullptr) return;
switch (this->query_widget) {
default: NOT_REACHED();
case WID_C_GIVE_MONEY: {
Money money = std::strtoull(str->c_str(), nullptr, 10) / GetCurrency().rate;
Money money = std::strtoull(str, nullptr, 10) / GetCurrency().rate;
Command<CMD_GIVE_MONEY>::Post(STR_ERROR_CAN_T_GIVE_MONEY, money, (CompanyID)this->window_number);
break;
}
case WID_C_PRESIDENT_NAME:
Command<CMD_RENAME_PRESIDENT>::Post(STR_ERROR_CAN_T_CHANGE_PRESIDENT, *str);
Command<CMD_RENAME_PRESIDENT>::Post(STR_ERROR_CAN_T_CHANGE_PRESIDENT, str);
break;
case WID_C_COMPANY_NAME:
Command<CMD_RENAME_COMPANY>::Post(STR_ERROR_CAN_T_CHANGE_COMPANY_NAME, *str);
Command<CMD_RENAME_COMPANY>::Post(STR_ERROR_CAN_T_CHANGE_COMPANY_NAME, str);
break;
}
}
@@ -2585,7 +2556,7 @@ static WindowDesc _company_desc(
WDP_AUTO, "company", 0, 0,
WC_COMPANY, WC_NONE,
0,
_nested_company_widgets
std::begin(_nested_company_widgets), std::end(_nested_company_widgets)
);
/**
@@ -2596,7 +2567,7 @@ void ShowCompany(CompanyID company)
{
if (!Company::IsValidID(company)) return;
AllocateWindowDescFront<CompanyWindow>(_company_desc, company);
AllocateWindowDescFront<CompanyWindow>(&_company_desc, company);
}
/**
@@ -2610,7 +2581,7 @@ void DirtyCompanyInfrastructureWindows(CompanyID company)
}
struct BuyCompanyWindow : Window {
BuyCompanyWindow(WindowDesc &desc, WindowNumber window_number, bool hostile_takeover) : Window(desc), hostile_takeover(hostile_takeover)
BuyCompanyWindow(WindowDesc *desc, WindowNumber window_number, bool hostile_takeover) : Window(desc), hostile_takeover(hostile_takeover)
{
this->InitNested(window_number);
@@ -2719,7 +2690,7 @@ static WindowDesc _buy_company_desc(
WDP_AUTO, nullptr, 0, 0,
WC_BUY_COMPANY, WC_NONE,
WDF_CONSTRUCTION,
_nested_buy_company_widgets
std::begin(_nested_buy_company_widgets), std::end(_nested_buy_company_widgets)
);
/**
@@ -2731,6 +2702,6 @@ void ShowBuyCompanyDialog(CompanyID company, bool hostile_takeover)
{
auto window = BringWindowToFrontById(WC_BUY_COMPANY, company);
if (window == nullptr) {
new BuyCompanyWindow(_buy_company_desc, company, hostile_takeover);
new BuyCompanyWindow(&_buy_company_desc, company, hostile_takeover);
}
}

View File

@@ -34,11 +34,11 @@ static const uint ICON_MAX_RECURSE = 10; ///< Maximum number of recursion
return aliases;
}
std::optional<FileHandle> _iconsole_output_file;
FILE *_iconsole_output_file;
void IConsoleInit()
{
_iconsole_output_file = std::nullopt;
_iconsole_output_file = nullptr;
_redirect_console_to_client = INVALID_CLIENT_ID;
_redirect_console_to_admin = INVALID_ADMIN_ID;
@@ -49,12 +49,13 @@ void IConsoleInit()
static void IConsoleWriteToLogFile(const std::string &string)
{
if (_iconsole_output_file.has_value()) {
if (_iconsole_output_file != nullptr) {
/* if there is an console output file ... also print it there */
try {
fmt::print(*_iconsole_output_file, "{}{}\n", GetLogPrefix(), string);
fmt::print(_iconsole_output_file, "{}{}\n", GetLogPrefix(), string);
} catch (const std::system_error &) {
_iconsole_output_file.reset();
fclose(_iconsole_output_file);
_iconsole_output_file = nullptr;
IConsolePrint(CC_ERROR, "Cannot write to console log file; closing the log file.");
}
}
@@ -62,9 +63,10 @@ static void IConsoleWriteToLogFile(const std::string &string)
bool CloseConsoleLogIfActive()
{
if (_iconsole_output_file.has_value()) {
if (_iconsole_output_file != nullptr) {
IConsolePrint(CC_INFO, "Console log file closed.");
_iconsole_output_file.reset();
fclose(_iconsole_output_file);
_iconsole_output_file = nullptr;
return true;
}

Some files were not shown because too many files have changed in this diff Show More