diff --git a/Makefile.lang.in b/Makefile.lang.in
index b4a276da3d..98d2250a32 100644
--- a/Makefile.lang.in
+++ b/Makefile.lang.in
@@ -7,7 +7,7 @@ LANG_DIR = !!LANG_DIR!!
BIN_DIR = !!BIN_DIR!!
LANGS_SRC = $(shell ls $(LANG_DIR)/*.txt)
LANGS = $(LANGS_SRC:$(LANG_DIR)/%.txt=%.lng)
-CC_BUILD = !!CC_BUILD!!
+CXX_BUILD = !!CXX_BUILD!!
CFLAGS_BUILD = !!CFLAGS_BUILD!!
STRGEN_FLAGS = !!STRGEN_FLAGS!!
STAGE = !!STAGE!!
@@ -36,13 +36,13 @@ RES := $(shell mkdir -p $(BIN_DIR)/lang )
all: table/strings.h $(LANGS)
-strgen.o: $(SRC_DIR)/strgen/strgen.c endian_host.h
- $(E) '$(STAGE) Compiling $(<:$(SRC_DIR)/%.c=%.c)'
- $(Q)$(CC_BUILD) $(CFLAGS_BUILD) -DSTRGEN -c -o $@ $<
+strgen.o: $(SRC_DIR)/strgen/strgen.cpp endian_host.h
+ $(E) '$(STAGE) Compiling $(<:$(SRC_DIR)/%.cpp=%.cpp)'
+ $(Q)$(CXX_BUILD) $(CFLAGS_BUILD) -DSTRGEN -c -o $@ $<
-string.o: $(SRC_DIR)/string.c endian_host.h
- $(E) '$(STAGE) Compiling $(<:$(SRC_DIR)/%.c=%.c)'
- $(Q)$(CC_BUILD) $(CFLAGS_BUILD) -DSTRGEN -c -o $@ $<
+string.o: $(SRC_DIR)/string.cpp endian_host.h
+ $(E) '$(STAGE) Compiling $(<:$(SRC_DIR)/%.cpp=%.cpp)'
+ $(Q)$(CXX_BUILD) $(CFLAGS_BUILD) -DSTRGEN -c -o $@ $<
lang/english.txt: $(LANG_DIR)/english.txt
$(Q)mkdir -p lang
@@ -50,7 +50,7 @@ lang/english.txt: $(LANG_DIR)/english.txt
$(STRGEN): string.o strgen.o
$(E) '$(STAGE) Compiling and Linking $@'
- $(Q)$(CC_BUILD) string.o strgen.o -o $@
+ $(Q)$(CXX_BUILD) string.o strgen.o -o $@
table/strings.h: lang/english.txt $(STRGEN)
$(E) '$(STAGE) Generating $@'
@@ -67,9 +67,9 @@ endian_host.h: $(ENDIAN_CHECK)
$(E) '$(STAGE) Testing endianness for host'
$(Q)./$(ENDIAN_CHECK) > $@
-$(ENDIAN_CHECK): $(SRC_DIR)/endian_check.c
+$(ENDIAN_CHECK): $(SRC_DIR)/endian_check.cpp
$(E) '$(STAGE) Compiling and Linking $@'
- $(Q)$(CC_BUILD) $(CFLAGS_BUILD) $< -o $@
+ $(Q)$(CXX_BUILD) $(CFLAGS_BUILD) $< -o $@
depend:
diff --git a/Makefile.src.in b/Makefile.src.in
index 62107f65b6..cc3b548888 100644
--- a/Makefile.src.in
+++ b/Makefile.src.in
@@ -3,6 +3,7 @@
CC_HOST = !!CC_HOST!!
CXX_HOST = !!CXX_HOST!!
CC_BUILD = !!CC_BUILD!!
+CXX_BUILD = !!CXX_BUILD!!
WINDRES = !!WINDRES!!
STRIP = !!STRIP!!
CC_CFLAGS = !!CC_CFLAGS!!
@@ -96,7 +97,7 @@ RES := $(shell if [ "`cat $(CONFIG_CACHE_ENDIAN) 2>/dev/null`" != "$(ENDIAN_FORC
# If there is a change in the source-file-list, make sure we recheck the deps
RES := $(shell if [ "`cat $(CONFIG_CACHE_SOURCE) 2>/dev/null`" != "$(SRCS)" ]; then echo "$(SRCS)" > $(CONFIG_CACHE_SOURCE); fi )
-# If there is a change in the revision, make sure we recompile rev.c
+# If there is a change in the revision, make sure we recompile rev.cpp
RES := $(shell if [ "`cat $(CONFIG_CACHE_VERSION) 2>/dev/null`" != "$(REV)" ]; then echo "$(REV)" > $(CONFIG_CACHE_VERSION); fi )
ifndef MAKEDEPEND
@@ -232,25 +233,25 @@ endian_target.h: $(ENDIAN_CHECK) $(CONFIG_CACHE_ENDIAN)
$(E) '$(STAGE) Testing endianness for target'
$(Q)./$(ENDIAN_CHECK) $(ENDIAN_FORCE) > $@
-$(ENDIAN_CHECK): $(SRC_DIR)/endian_check.c
+$(ENDIAN_CHECK): $(SRC_DIR)/endian_check.cpp
$(E) '$(STAGE) Compiling and Linking $@'
- $(Q)$(CC_BUILD) $(CFLAGS_BUILD) $< -o $@
+ $(Q)$(CXX_BUILD) $(CFLAGS_BUILD) $< -o $@
# Revision files
-rev.c: $(CONFIG_CACHE_VERSION)
+rev.cpp: $(CONFIG_CACHE_VERSION)
# setting the revision number in a place, there the binary can read it
- @echo 'const char _openttd_revision[] = "$(REV)";' > rev.c
+ @echo 'extern const char _openttd_revision[] = "$(REV)";' > rev.cpp
# Some additions for MorphOS versions tag
ifeq ($(OS),MORPHOS)
- @echo '#ifdef __MORPHOS__' >> rev.c
- @echo 'const char morphos_versions_tag[] = "\\0$$VER: OpenTTD $(REV) ('`date +%d.%m.%y`') (C) OpenTTD Team [MorphOS, PowerPC]";' >> rev.c
- @echo '#endif' >> rev.c
+ @echo '#ifdef __MORPHOS__' >> rev.cpp
+ @echo 'extern const char morphos_versions_tag[] = "\\0$$VER: OpenTTD $(REV) ('`date +%d.%m.%y`') (C) OpenTTD Team [MorphOS, PowerPC]";' >> rev.cpp
+ @echo '#endif' >> rev.cpp
endif
-rev.o: rev.c $(FILE_DEP)
- $(E) '$(STAGE) Compiling $(<:$(SRC_DIR)/%.c=%.c)'
- $(Q)$(CC_HOST) $(CC_CFLAGS) $(CFLAGS) -c -o $@ $<
+rev.o: rev.cpp $(FILE_DEP)
+ $(E) '$(STAGE) Compiling $(<:$(SRC_DIR)/%.cpp=%.cpp)'
+ $(Q)$(CXX_HOST) $(CFLAGS) -c -o $@ $<
FORCE:
@@ -261,7 +262,7 @@ clean:
$(Q)rm -f $(DEPS) $(OBJS) $(TTD) $(TTD:%=$(BIN_DIR)/%) $(CONFIG_CACHE_COMPILER) $(CONFIG_CACHE_LINKER) $(CONFIG_CACHE_ENDIAN) $(CONFIG_CACHE_SOURCE) $(ENDIAN_TARGETS) rev.o
mrproper: clean
- $(Q)rm -f rev.c
+ $(Q)rm -f rev.cpp
%.o:
@echo '$(STAGE) No such source-file: $(@:%.o=%).[c|cpp|m|rc]'
diff --git a/config.lib b/config.lib
index b7a4cb4e62..9583b4cd76 100644
--- a/config.lib
+++ b/config.lib
@@ -12,6 +12,7 @@ set_default() {
host=""
cc_build=""
cc_host=""
+ cxx_build=""
cxx_host=""
windres=""
strip=""
@@ -54,7 +55,7 @@ set_default() {
with_freetype="1"
with_fontconfig="1"
- save_params_array="build host cc_build cc_host cxx_host windres strip lipo os revision endian config_log prefix_dir binary_dir data_dir icon_dir personal_dir install_dir custom_lang_dir second_data_dir enable_install enable_debug enable_profiling enable_dedicated enable_network enable_static enable_translator enable_assert enable_strip with_osx_sysroot enable_universal enable_osx_g5 with_application_bundle with_sdl with_cocoa with_zlib with_png with_makedepend with_direct_music with_sort with_iconv with_midi with_midi_arg with_freetype with_fontconfig CC CXX CFLAGS LDFLAGS"
+ save_params_array="build host cc_build cc_host cxx_build cxx_host windres strip lipo os revision endian config_log prefix_dir binary_dir data_dir icon_dir personal_dir install_dir custom_lang_dir second_data_dir enable_install enable_debug enable_profiling enable_dedicated enable_network enable_static enable_translator enable_assert enable_strip with_osx_sysroot enable_universal enable_osx_g5 with_application_bundle with_sdl with_cocoa with_zlib with_png with_makedepend with_direct_music with_sort with_iconv with_midi with_midi_arg with_freetype with_fontconfig CC CXX CFLAGS LDFLAGS"
}
detect_params() {
@@ -90,6 +91,8 @@ detect_params() {
--cc-build=*) cc_build="$optarg";;
--cc-host) prevp_p="cc_host";;
--cc-host=*) cc_host="$optarg";;
+ --cxx-build) prevp_p="cxx_build";;
+ --cxx-build=*) cxx_build="$optarg";;
--cxx-host) prevp_p="cxx_host";;
--cxx-host=*) cxx_host="$optarg";;
--windres) prevp_p="windres";;
@@ -320,7 +323,8 @@ check_params() {
log 1 "checking for build gcc... $cc_build"
log 1 "checking for host gcc... $cc_host"
- check_cxx
+ check_cxx_build
+ check_cxx_host
check_windres
check_strip
check_lipo
@@ -535,7 +539,7 @@ check_params() {
native=`LC_ALL=C uname | tr [:upper:] [:lower:] | grep darwin`
# If $host doesn't match $build , we are cross-compiling
if [ -n "$native" ] && [ "$build" != "$host" ]; then
- $cc_build $SRC_DIR/os/macosx/G5_detector.c -o G5_detector
+ $cc_build $SRC_DIR/os/macosx/G5_detector.cpp -o G5_detector
res=`./G5_detector`
rm -f G5_detector
if [ -n "$res" ]; then
@@ -981,7 +985,13 @@ check_host() {
check_compiler "host system type" "cc_host" "$host" "$cc_host" "$CC" "gcc" "cc" "0" "-dumpmachine"
}
-check_cxx() {
+check_cxx_build() {
+ check_compiler "build g++" "cxx_build" "$build" "$cxx_build" "$CXX" "g++" "c++" 1 "-dumpmachine"
+}
+
+check_cxx_host() {
+ # By default the host is the build
+ if [ -z "$host" ]; then host="$build"; fi
check_compiler "host g++" "cxx_host" "$host" "$cxx_host" "$CXX" "g++" "c++" 1 "-dumpmachine"
}
@@ -1584,6 +1594,7 @@ make_sed() {
s#!!CC_HOST!!#$cc_host#g;
s#!!CXX_HOST!!#$cxx_host#g;
s#!!CC_BUILD!!#$cc_build#g;
+ s#!!CXX_BUILD!!#$cxx_build#g;
s#!!WINDRES!!#$windres#g;
s#!!STRIP!!#$strip $strip_arg#g;
s#!!LIPO!!#$lipo#g;
diff --git a/projects/openttd.vcproj b/projects/openttd.vcproj
index f4ffeff7ff..ded005ee13 100644
--- a/projects/openttd.vcproj
+++ b/projects/openttd.vcproj
@@ -161,220 +161,220 @@
Name="Source Files"
Filter="">
+ RelativePath=".\..\src\airport.cpp">
+ RelativePath=".\..\src\aystar.cpp">
+ RelativePath=".\..\src\bmp.cpp">
+ RelativePath=".\..\src\callback_table.cpp">
+ RelativePath=".\..\src\command.cpp">
+ RelativePath=".\..\src\console.cpp">
+ RelativePath=".\..\src\console_cmds.cpp">
+ RelativePath=".\..\src\currency.cpp">
+ RelativePath=".\..\src\date.cpp">
+ RelativePath=".\..\src\debug.cpp">
+ RelativePath=".\..\src\dedicated.cpp">
+ RelativePath=".\..\src\depot.cpp">
+ RelativePath=".\..\src\driver.cpp">
+ RelativePath=".\..\src\economy.cpp">
+ RelativePath=".\..\src\elrail.cpp">
+ RelativePath=".\..\src\engine.cpp">
+ RelativePath=".\..\src\fileio.cpp">
+ RelativePath=".\..\src\fios.cpp">
+ RelativePath=".\..\src\fontcache.cpp">
+ RelativePath=".\..\src\genworld.cpp">
+ RelativePath=".\..\src\gfx.cpp">
+ RelativePath=".\..\src\gfxinit.cpp">
+ RelativePath=".\..\src\heightmap.cpp">
+ RelativePath=".\..\src\landscape.cpp">
+ RelativePath=".\..\src\map.cpp">
+ RelativePath=".\..\src\md5.cpp">
+ RelativePath=".\..\src\mersenne.cpp">
+ RelativePath=".\..\src\minilzo.cpp">
+ RelativePath=".\..\src\misc.cpp">
+ RelativePath=".\..\src\mixer.cpp">
+ RelativePath=".\..\src\music.cpp">
+ RelativePath=".\..\src\namegen.cpp">
+ RelativePath=".\..\src\network\core\core.cpp">
+ RelativePath=".\..\src\network\core\packet.cpp">
+ RelativePath=".\..\src\network\core\tcp.cpp">
+ RelativePath=".\..\src\network\core\udp.cpp">
+ RelativePath=".\..\src\network\network.cpp">
+ RelativePath=".\..\src\network\network_client.cpp">
+ RelativePath=".\..\src\network\network_data.cpp">
+ RelativePath=".\..\src\network\network_gamelist.cpp">
+ RelativePath=".\..\src\network\network_server.cpp">
+ RelativePath=".\..\src\network\network_udp.cpp">
+ RelativePath=".\..\src\npf.cpp">
+ RelativePath=".\..\src\oldloader.cpp">
+ RelativePath=".\..\src\oldpool.cpp">
+ RelativePath=".\..\src\openttd.cpp">
+ RelativePath=".\..\src\os_timer.cpp">
+ RelativePath=".\..\src\pathfind.cpp">
+ RelativePath=".\..\src\players.cpp">
+ RelativePath=".\..\src\queue.cpp">
+ RelativePath=".\..\src\rail.cpp">
+ RelativePath=".\..\src\saveload.cpp">
+ RelativePath=".\..\src\screenshot.cpp">
+ RelativePath=".\..\src\sdl.cpp">
+ RelativePath=".\..\src\settings.cpp">
+ RelativePath=".\..\src\signs.cpp">
+ RelativePath=".\..\src\sound.cpp">
+ RelativePath=".\..\src\spritecache.cpp">
+ RelativePath=".\..\src\string.cpp">
+ RelativePath=".\..\src\strings.cpp">
+ RelativePath=".\..\src\texteff.cpp">
+ RelativePath=".\..\src\tgp.cpp">
+ RelativePath=".\..\src\thread.cpp">
+ RelativePath=".\..\src\tile.cpp">
+ RelativePath=".\..\src\vehicle.cpp">
+ RelativePath=".\..\src\viewport.cpp">
+ RelativePath=".\..\src\waypoint.cpp">
+ RelativePath=".\..\src\widget.cpp">
+ RelativePath=".\..\src\win32.cpp">
+ RelativePath=".\..\src\window.cpp">
+ RelativePath=".\..\src\aircraft_gui.cpp">
+ RelativePath=".\..\src\airport_gui.cpp">
+ RelativePath=".\..\src\bridge_gui.cpp">
+ RelativePath=".\..\src\build_vehicle_gui.cpp">
+ RelativePath=".\..\src\depot_gui.cpp">
+ RelativePath=".\..\src\dock_gui.cpp">
+ RelativePath=".\..\src\engine_gui.cpp">
+ RelativePath=".\..\src\genworld_gui.cpp">
+ RelativePath=".\..\src\graph_gui.cpp">
+ RelativePath=".\..\src\industry_gui.cpp">
+ RelativePath=".\..\src\intro_gui.cpp">
+ RelativePath=".\..\src\main_gui.cpp">
+ RelativePath=".\..\src\misc_gui.cpp">
+ RelativePath=".\..\src\music_gui.cpp">
+ RelativePath=".\..\src\network\network_gui.cpp">
+ RelativePath=".\..\src\newgrf_gui.cpp">
+ RelativePath=".\..\src\news_gui.cpp">
+ RelativePath=".\..\src\order_gui.cpp">
+ RelativePath=".\..\src\player_gui.cpp">
+ RelativePath=".\..\src\rail_gui.cpp">
+ RelativePath=".\..\src\road_gui.cpp">
+ RelativePath=".\..\src\roadveh_gui.cpp">
+ RelativePath=".\..\src\settings_gui.cpp">
+ RelativePath=".\..\src\ship_gui.cpp">
+ RelativePath=".\..\src\smallmap_gui.cpp">
+ RelativePath=".\..\src\station_gui.cpp">
+ RelativePath=".\..\src\subsidy_gui.cpp">
+ RelativePath=".\..\src\terraform_gui.cpp">
+ RelativePath=".\..\src\town_gui.cpp">
+ RelativePath=".\..\src\train_gui.cpp">
+ RelativePath=".\..\src\vehicle_gui.cpp">
+ RelativePath=".\..\src\aircraft_cmd.cpp">
+ RelativePath=".\..\src\clear_cmd.cpp">
+ RelativePath=".\..\src\disaster_cmd.cpp">
+ RelativePath=".\..\src\dummy_land.cpp">
+ RelativePath=".\..\src\industry_cmd.cpp">
+ RelativePath=".\..\src\misc_cmd.cpp">
+ RelativePath=".\..\src\order_cmd.cpp">
+ RelativePath=".\..\src\rail_cmd.cpp">
+ RelativePath=".\..\src\road_cmd.cpp">
+ RelativePath=".\..\src\roadveh_cmd.cpp">
+ RelativePath=".\..\src\ship_cmd.cpp">
+ RelativePath=".\..\src\station_cmd.cpp">
+ RelativePath=".\..\src\town_cmd.cpp">
+ RelativePath=".\..\src\train_cmd.cpp">
+ RelativePath=".\..\src\tree_cmd.cpp">
+ RelativePath=".\..\src\tunnelbridge_cmd.cpp">
+ RelativePath=".\..\src\unmovable_cmd.cpp">
+ RelativePath=".\..\src\water_cmd.cpp">
+ RelativePath=".\..\src\ai\ai.cpp">
+ RelativePath=".\..\src\ai\default\default.cpp">
+ RelativePath=".\..\src\ai\trolly\build.cpp">
+ RelativePath=".\..\src\ai\trolly\pathfinder.cpp">
+ RelativePath=".\..\src\ai\trolly\shared.cpp">
+ RelativePath=".\..\src\ai\trolly\trolly.cpp">
+ RelativePath=".\..\src\newgrf.cpp">
+ RelativePath=".\..\src\newgrf_cargo.cpp">
+ RelativePath=".\..\src\newgrf_config.cpp">
+ RelativePath=".\..\src\newgrf_engine.cpp">
+ RelativePath=".\..\src\newgrf_sound.cpp">
+ RelativePath=".\..\src\newgrf_spritegroup.cpp">
+ RelativePath=".\..\src\newgrf_station.cpp">
+ RelativePath=".\..\src\newgrf_text.cpp">
+ RelativePath=".\..\src\bridge_map.cpp">
@@ -966,13 +966,13 @@
RelativePath=".\..\src\rail_map.h">
+ RelativePath=".\..\src\road_map.cpp">
+ RelativePath=".\..\src\station_map.cpp">
@@ -984,7 +984,7 @@
RelativePath=".\..\src\tree_map.h">
+ RelativePath=".\..\src\tunnel_map.cpp">
@@ -1091,16 +1091,16 @@
Name="Video"
Filter="">
+ RelativePath=".\..\src\video\dedicated_v.cpp">
+ RelativePath=".\..\src\video\null_v.cpp">
+ RelativePath=".\..\src\video\sdl_v.cpp">
+ RelativePath=".\..\src\video\win32_v.cpp">
+ RelativePath=".\..\src\music\null_m.cpp">
+ RelativePath=".\..\src\music\win32_m.cpp">
+ RelativePath=".\..\src\sound\null_s.cpp">
+ RelativePath=".\..\src\sound\sdl_s.cpp">
+ RelativePath=".\..\src\sound\win32_s.cpp">
+ RelativePath=".\..\src\airport.cpp">
+ RelativePath=".\..\src\aystar.cpp">
+ RelativePath=".\..\src\bmp.cpp">
+ RelativePath=".\..\src\callback_table.cpp">
+ RelativePath=".\..\src\command.cpp">
+ RelativePath=".\..\src\console.cpp">
+ RelativePath=".\..\src\console_cmds.cpp">
+ RelativePath=".\..\src\currency.cpp">
+ RelativePath=".\..\src\date.cpp">
+ RelativePath=".\..\src\debug.cpp">
+ RelativePath=".\..\src\dedicated.cpp">
+ RelativePath=".\..\src\depot.cpp">
+ RelativePath=".\..\src\driver.cpp">
+ RelativePath=".\..\src\economy.cpp">
+ RelativePath=".\..\src\elrail.cpp">
+ RelativePath=".\..\src\engine.cpp">
+ RelativePath=".\..\src\fileio.cpp">
+ RelativePath=".\..\src\fios.cpp">
+ RelativePath=".\..\src\fontcache.cpp">
+ RelativePath=".\..\src\genworld.cpp">
+ RelativePath=".\..\src\gfx.cpp">
+ RelativePath=".\..\src\gfxinit.cpp">
+ RelativePath=".\..\src\heightmap.cpp">
+ RelativePath=".\..\src\landscape.cpp">
+ RelativePath=".\..\src\map.cpp">
+ RelativePath=".\..\src\md5.cpp">
+ RelativePath=".\..\src\mersenne.cpp">
+ RelativePath=".\..\src\minilzo.cpp">
+ RelativePath=".\..\src\misc.cpp">
+ RelativePath=".\..\src\mixer.cpp">
+ RelativePath=".\..\src\music.cpp">
+ RelativePath=".\..\src\namegen.cpp">
+ RelativePath=".\..\src\network\core\core.cpp">
+ RelativePath=".\..\src\network\core\packet.cpp">
+ RelativePath=".\..\src\network\core\tcp.cpp">
+ RelativePath=".\..\src\network\core\udp.cpp">
+ RelativePath=".\..\src\network\network.cpp">
+ RelativePath=".\..\src\network\network_client.cpp">
+ RelativePath=".\..\src\network\network_data.cpp">
+ RelativePath=".\..\src\network\network_gamelist.cpp">
+ RelativePath=".\..\src\network\network_server.cpp">
+ RelativePath=".\..\src\network\network_udp.cpp">
+ RelativePath=".\..\src\npf.cpp">
+ RelativePath=".\..\src\oldloader.cpp">
+ RelativePath=".\..\src\oldpool.cpp">
+ RelativePath=".\..\src\openttd.cpp">
+ RelativePath=".\..\src\os_timer.cpp">
+ RelativePath=".\..\src\pathfind.cpp">
+ RelativePath=".\..\src\players.cpp">
+ RelativePath=".\..\src\queue.cpp">
+ RelativePath=".\..\src\rail.cpp">
+ RelativePath=".\..\src\saveload.cpp">
+ RelativePath=".\..\src\screenshot.cpp">
+ RelativePath=".\..\src\sdl.cpp">
+ RelativePath=".\..\src\settings.cpp">
+ RelativePath=".\..\src\signs.cpp">
+ RelativePath=".\..\src\sound.cpp">
+ RelativePath=".\..\src\spritecache.cpp">
+ RelativePath=".\..\src\string.cpp">
+ RelativePath=".\..\src\strings.cpp">
+ RelativePath=".\..\src\texteff.cpp">
+ RelativePath=".\..\src\tgp.cpp">
+ RelativePath=".\..\src\thread.cpp">
+ RelativePath=".\..\src\tile.cpp">
+ RelativePath=".\..\src\vehicle.cpp">
+ RelativePath=".\..\src\viewport.cpp">
+ RelativePath=".\..\src\waypoint.cpp">
+ RelativePath=".\..\src\widget.cpp">
+ RelativePath=".\..\src\win32.cpp">
+ RelativePath=".\..\src\window.cpp">
+ RelativePath=".\..\src\aircraft_gui.cpp">
+ RelativePath=".\..\src\airport_gui.cpp">
+ RelativePath=".\..\src\bridge_gui.cpp">
+ RelativePath=".\..\src\build_vehicle_gui.cpp">
+ RelativePath=".\..\src\depot_gui.cpp">
+ RelativePath=".\..\src\dock_gui.cpp">
+ RelativePath=".\..\src\engine_gui.cpp">
+ RelativePath=".\..\src\genworld_gui.cpp">
+ RelativePath=".\..\src\graph_gui.cpp">
+ RelativePath=".\..\src\industry_gui.cpp">
+ RelativePath=".\..\src\intro_gui.cpp">
+ RelativePath=".\..\src\main_gui.cpp">
+ RelativePath=".\..\src\misc_gui.cpp">
+ RelativePath=".\..\src\music_gui.cpp">
+ RelativePath=".\..\src\network\network_gui.cpp">
+ RelativePath=".\..\src\newgrf_gui.cpp">
+ RelativePath=".\..\src\news_gui.cpp">
+ RelativePath=".\..\src\order_gui.cpp">
+ RelativePath=".\..\src\player_gui.cpp">
+ RelativePath=".\..\src\rail_gui.cpp">
+ RelativePath=".\..\src\road_gui.cpp">
+ RelativePath=".\..\src\roadveh_gui.cpp">
+ RelativePath=".\..\src\settings_gui.cpp">
+ RelativePath=".\..\src\ship_gui.cpp">
+ RelativePath=".\..\src\smallmap_gui.cpp">
+ RelativePath=".\..\src\station_gui.cpp">
+ RelativePath=".\..\src\subsidy_gui.cpp">
+ RelativePath=".\..\src\terraform_gui.cpp">
+ RelativePath=".\..\src\town_gui.cpp">
+ RelativePath=".\..\src\train_gui.cpp">
+ RelativePath=".\..\src\vehicle_gui.cpp">
+ RelativePath=".\..\src\aircraft_cmd.cpp">
+ RelativePath=".\..\src\clear_cmd.cpp">
+ RelativePath=".\..\src\disaster_cmd.cpp">
+ RelativePath=".\..\src\dummy_land.cpp">
+ RelativePath=".\..\src\industry_cmd.cpp">
+ RelativePath=".\..\src\misc_cmd.cpp">
+ RelativePath=".\..\src\order_cmd.cpp">
+ RelativePath=".\..\src\rail_cmd.cpp">
+ RelativePath=".\..\src\road_cmd.cpp">
+ RelativePath=".\..\src\roadveh_cmd.cpp">
+ RelativePath=".\..\src\ship_cmd.cpp">
+ RelativePath=".\..\src\station_cmd.cpp">
+ RelativePath=".\..\src\town_cmd.cpp">
+ RelativePath=".\..\src\train_cmd.cpp">
+ RelativePath=".\..\src\tree_cmd.cpp">
+ RelativePath=".\..\src\tunnelbridge_cmd.cpp">
+ RelativePath=".\..\src\unmovable_cmd.cpp">
+ RelativePath=".\..\src\water_cmd.cpp">
+ RelativePath=".\..\src\ai\ai.cpp">
+ RelativePath=".\..\src\ai\default\default.cpp">
+ RelativePath=".\..\src\ai\trolly\build.cpp">
+ RelativePath=".\..\src\ai\trolly\pathfinder.cpp">
+ RelativePath=".\..\src\ai\trolly\shared.cpp">
+ RelativePath=".\..\src\ai\trolly\trolly.cpp">
+ RelativePath=".\..\src\newgrf.cpp">
+ RelativePath=".\..\src\newgrf_cargo.cpp">
+ RelativePath=".\..\src\newgrf_config.cpp">
+ RelativePath=".\..\src\newgrf_engine.cpp">
+ RelativePath=".\..\src\newgrf_sound.cpp">
+ RelativePath=".\..\src\newgrf_spritegroup.cpp">
+ RelativePath=".\..\src\newgrf_station.cpp">
+ RelativePath=".\..\src\newgrf_text.cpp">
+ RelativePath=".\..\src\bridge_map.cpp">
@@ -1249,13 +1249,13 @@
RelativePath=".\..\src\rail_map.h">
+ RelativePath=".\..\src\road_map.cpp">
+ RelativePath=".\..\src\station_map.cpp">
@@ -1267,7 +1267,7 @@
RelativePath=".\..\src\tree_map.h">
+ RelativePath=".\..\src\tunnel_map.cpp">
@@ -1374,16 +1374,16 @@
Name="Video"
Filter="">
+ RelativePath=".\..\src\video\dedicated_v.cpp">
+ RelativePath=".\..\src\video\null_v.cpp">
+ RelativePath=".\..\src\video\sdl_v.cpp">
+ RelativePath=".\..\src\video\win32_v.cpp">
+ RelativePath=".\..\src\music\null_m.cpp">
+ RelativePath=".\..\src\music\win32_m.cpp">
+ RelativePath=".\..\src\sound\null_s.cpp">
+ RelativePath=".\..\src\sound\sdl_s.cpp">
+ RelativePath=".\..\src\sound\win32_s.cpp">
+ RelativePath="..\src\strgen\strgen.cpp">
+ RelativePath="..\src\string.cpp">
diff --git a/source.list b/source.list
index 1c98dbcbaa..db35bd4e0f 100644
--- a/source.list
+++ b/source.list
@@ -1,86 +1,86 @@
# Source Files
-airport.c
-aystar.c
-bmp.c
-callback_table.c
-command.c
-console.c
-console_cmds.c
-currency.c
-date.c
-debug.c
-dedicated.c
-depot.c
-driver.c
-economy.c
-elrail.c
-engine.c
-fileio.c
-fios.c
-fontcache.c
-genworld.c
-gfx.c
-gfxinit.c
-heightmap.c
+airport.cpp
+aystar.cpp
+bmp.cpp
+callback_table.cpp
+command.cpp
+console.cpp
+console_cmds.cpp
+currency.cpp
+date.cpp
+debug.cpp
+dedicated.cpp
+depot.cpp
+driver.cpp
+economy.cpp
+elrail.cpp
+engine.cpp
+fileio.cpp
+fios.cpp
+fontcache.cpp
+genworld.cpp
+gfx.cpp
+gfxinit.cpp
+heightmap.cpp
helpers.cpp
-landscape.c
-map.c
-md5.c
-mersenne.c
-minilzo.c
-misc.c
-mixer.c
-music.c
-namegen.c
-network/core/core.c
-network/core/packet.c
-network/core/tcp.c
-network/core/udp.c
-network/network.c
-network/network_client.c
-network/network_data.c
-network/network_gamelist.c
-network/network_server.c
-network/network_udp.c
-npf.c
-oldloader.c
-oldpool.c
-openttd.c
-os_timer.c
+landscape.cpp
+map.cpp
+md5.cpp
+mersenne.cpp
+minilzo.cpp
+misc.cpp
+mixer.cpp
+music.cpp
+namegen.cpp
+network/core/core.cpp
+network/core/packet.cpp
+network/core/tcp.cpp
+network/core/udp.cpp
+network/network.cpp
+network/network_client.cpp
+network/network_data.cpp
+network/network_gamelist.cpp
+network/network_server.cpp
+network/network_udp.cpp
+npf.cpp
+oldloader.cpp
+oldpool.cpp
+openttd.cpp
+os_timer.cpp
#if WIN32
ottdres.rc
#end
-pathfind.c
-players.c
-queue.c
-rail.c
-saveload.c
-screenshot.c
+pathfind.cpp
+players.cpp
+queue.cpp
+rail.cpp
+saveload.cpp
+screenshot.cpp
#if SDL
- sdl.c
+ sdl.cpp
#end
-settings.c
-signs.c
-sound.c
-spritecache.c
-string.c
-strings.c
-texteff.c
-tgp.c
-thread.c
-tile.c
+settings.cpp
+signs.cpp
+sound.cpp
+spritecache.cpp
+string.cpp
+strings.cpp
+texteff.cpp
+tgp.cpp
+thread.cpp
+tile.cpp
#if WIN32
#else
- unix.c
+ unix.cpp
#end
-vehicle.c
-viewport.c
-waypoint.c
-widget.c
+vehicle.cpp
+viewport.cpp
+waypoint.cpp
+widget.cpp
#if WIN32
- win32.c
+ win32.cpp
#end
-window.c
+window.cpp
# Header Files
airport.h
@@ -178,57 +178,57 @@ video/win32_v.h
window.h
# GUI Source Code
-aircraft_gui.c
-airport_gui.c
-bridge_gui.c
-build_vehicle_gui.c
-depot_gui.c
-dock_gui.c
-engine_gui.c
-genworld_gui.c
-graph_gui.c
-industry_gui.c
-intro_gui.c
-main_gui.c
-misc_gui.c
-music_gui.c
-network/network_gui.c
-newgrf_gui.c
-news_gui.c
-order_gui.c
-player_gui.c
-rail_gui.c
-road_gui.c
-roadveh_gui.c
-settings_gui.c
-ship_gui.c
-smallmap_gui.c
-station_gui.c
-subsidy_gui.c
-terraform_gui.c
-town_gui.c
-train_gui.c
-vehicle_gui.c
+aircraft_gui.cpp
+airport_gui.cpp
+bridge_gui.cpp
+build_vehicle_gui.cpp
+depot_gui.cpp
+dock_gui.cpp
+engine_gui.cpp
+genworld_gui.cpp
+graph_gui.cpp
+industry_gui.cpp
+intro_gui.cpp
+main_gui.cpp
+misc_gui.cpp
+music_gui.cpp
+network/network_gui.cpp
+newgrf_gui.cpp
+news_gui.cpp
+order_gui.cpp
+player_gui.cpp
+rail_gui.cpp
+road_gui.cpp
+roadveh_gui.cpp
+settings_gui.cpp
+ship_gui.cpp
+smallmap_gui.cpp
+station_gui.cpp
+subsidy_gui.cpp
+terraform_gui.cpp
+town_gui.cpp
+train_gui.cpp
+vehicle_gui.cpp
# Landscape
-aircraft_cmd.c
-clear_cmd.c
-disaster_cmd.c
-dummy_land.c
-industry_cmd.c
-misc_cmd.c
-order_cmd.c
-rail_cmd.c
-road_cmd.c
-roadveh_cmd.c
-ship_cmd.c
-station_cmd.c
-town_cmd.c
-train_cmd.c
-tree_cmd.c
-tunnelbridge_cmd.c
-unmovable_cmd.c
-water_cmd.c
+aircraft_cmd.cpp
+clear_cmd.cpp
+disaster_cmd.cpp
+dummy_land.cpp
+industry_cmd.cpp
+misc_cmd.cpp
+order_cmd.cpp
+rail_cmd.cpp
+road_cmd.cpp
+roadveh_cmd.cpp
+ship_cmd.cpp
+station_cmd.cpp
+town_cmd.cpp
+train_cmd.cpp
+tree_cmd.cpp
+tunnelbridge_cmd.cpp
+unmovable_cmd.cpp
+water_cmd.cpp
# Tables
table/ai_rail.h
@@ -259,36 +259,36 @@ table/unmovable_land.h
table/water_land.h
# AI Files
-ai/ai.c
-ai/default/default.c
-ai/trolly/build.c
-ai/trolly/pathfinder.c
-ai/trolly/shared.c
-ai/trolly/trolly.c
+ai/ai.cpp
+ai/default/default.cpp
+ai/trolly/build.cpp
+ai/trolly/pathfinder.cpp
+ai/trolly/shared.cpp
+ai/trolly/trolly.cpp
# NewGRF
-newgrf.c
-newgrf_cargo.c
-newgrf_config.c
-newgrf_engine.c
-newgrf_sound.c
-newgrf_spritegroup.c
-newgrf_station.c
-newgrf_text.c
+newgrf.cpp
+newgrf_cargo.cpp
+newgrf_config.cpp
+newgrf_engine.cpp
+newgrf_sound.cpp
+newgrf_spritegroup.cpp
+newgrf_station.cpp
+newgrf_text.cpp
# Map Accessors
-bridge_map.c
+bridge_map.cpp
bridge_map.h
clear_map.h
industry_map.h
rail_map.h
-road_map.c
+road_map.cpp
road_map.h
-station_map.c
+station_map.cpp
station_map.h
town_map.h
tree_map.h
-tunnel_map.c
+tunnel_map.cpp
tunnel_map.h
unmovable_map.h
void_map.h
@@ -325,36 +325,36 @@ yapf/yapf_settings.h
yapf/yapf_ship.cpp
# Video
-video/dedicated_v.c
-video/null_v.c
+video/dedicated_v.cpp
+video/null_v.cpp
#if SDL
- video/sdl_v.c
+ video/sdl_v.cpp
#end
#if WIN32
- video/win32_v.c
+ video/win32_v.cpp
#end
# Music
#if DIRECTMUSIC
music/dmusic.cpp
#end
-music/null_m.c
+music/null_m.cpp
#if WIN32
- music/win32_m.c
+ music/win32_m.cpp
#else
- music/extmidi.c
+ music/extmidi.cpp
#end
#if BEOS
music/bemidi.cpp
#end
# Sound
-sound/null_s.c
+sound/null_s.cpp
#if SDL
- sound/sdl_s.c
+ sound/sdl_s.cpp
#end
#if WIN32
- sound/win32_s.c
+ sound/win32_s.cpp
#end
#if OSX
@@ -363,12 +363,12 @@ sound/null_s.c
#if DEDICATED
#else
- music/qtmidi.c
+ music/qtmidi.cpp
#end
#if COCOA
video/cocoa_v.m
- sound/cocoa_s.c
- os/macosx/splash.c
+ sound/cocoa_s.cpp
+ os/macosx/splash.cpp
#end
#end
diff --git a/src/ai/ai.cpp b/src/ai/ai.cpp
index 58b97ad39c..5b2e5a8fc8 100644
--- a/src/ai/ai.cpp
+++ b/src/ai/ai.cpp
@@ -5,6 +5,7 @@
#include "../variables.h"
#include "../command.h"
#include "../network/network.h"
+#include "../helpers.hpp"
#include "ai.h"
#include "default/default.h"
@@ -50,11 +51,11 @@ static void AI_PutCommandInQueue(PlayerID player, TileIndex tile, uint32 p1, uin
if (_ai_player[player].queue_tail == NULL) {
/* There is no item in the queue yet, create the queue */
- _ai_player[player].queue = malloc(sizeof(AICommand));
+ MallocT(&_ai_player[player].queue, 1);
_ai_player[player].queue_tail = _ai_player[player].queue;
} else {
/* Add an item at the end */
- _ai_player[player].queue_tail->next = malloc(sizeof(AICommand));
+ MallocT(&_ai_player[player].queue_tail->next, 1);
_ai_player[player].queue_tail = _ai_player[player].queue_tail->next;
}
diff --git a/src/ai/default/default.cpp b/src/ai/default/default.cpp
index 143e724b96..5a328e9d08 100644
--- a/src/ai/default/default.cpp
+++ b/src/ai/default/default.cpp
@@ -26,6 +26,7 @@
#include "../../variables.h"
#include "../../bridge.h"
#include "../../date.h"
+#include "../../helpers.hpp"
#include "default.h"
// remove some day perhaps?
@@ -63,10 +64,10 @@ enum {
#include "../../table/ai_rail.h"
-static byte GetRailTrackStatus(TileIndex tile)
+static TrackBits GetRailTrackStatus(TileIndex tile)
{
uint32 r = GetTileTrackStatus(tile, TRANSPORT_RAIL);
- return (byte) (r | r >> 8);
+ return (TrackBits)(byte) (r | r >> 8);
}
@@ -644,8 +645,8 @@ static bool AiCheckIfRouteIsGood(Player *p, FoundRoute *fr, byte bitmask)
}
if (fr->cargo == CT_PASSENGERS || fr->cargo == CT_MAIL) {
- const Town* from = fr->from;
- const Town* to = fr->to;
+ const Town* from = (const Town*)fr->from;
+ const Town* to = (const Town*)fr->to;
if (from->pct_pass_transported > 0x99 ||
to->pct_pass_transported > 0x99) {
@@ -783,7 +784,7 @@ static void AiWantLongIndustryRoute(Player *p)
p->ai.order_list_blocks[2] = 255;
p->ai.state = AIS_BUILD_DEFAULT_RAIL_BLOCKS;
- p->ai.state_mode = -1;
+ p->ai.state_mode = UCHAR_MAX;
p->ai.state_counter = 0;
p->ai.timeout_counter = 0;
}
@@ -851,7 +852,7 @@ static void AiWantMediumIndustryRoute(Player *p)
p->ai.order_list_blocks[1] = 1;
p->ai.order_list_blocks[2] = 255;
p->ai.state = AIS_BUILD_DEFAULT_RAIL_BLOCKS;
- p->ai.state_mode = -1;
+ p->ai.state_mode = UCHAR_MAX;
p->ai.state_counter = 0;
p->ai.timeout_counter = 0;
}
@@ -919,7 +920,7 @@ static void AiWantShortIndustryRoute(Player *p)
p->ai.order_list_blocks[1] = 1;
p->ai.order_list_blocks[2] = 255;
p->ai.state = AIS_BUILD_DEFAULT_RAIL_BLOCKS;
- p->ai.state_mode = -1;
+ p->ai.state_mode = UCHAR_MAX;
p->ai.state_counter = 0;
p->ai.timeout_counter = 0;
}
@@ -1020,7 +1021,7 @@ static void AiWantMailRoute(Player *p)
p->ai.order_list_blocks[1] = 1;
p->ai.order_list_blocks[2] = 255;
p->ai.state = AIS_BUILD_DEFAULT_RAIL_BLOCKS;
- p->ai.state_mode = -1;
+ p->ai.state_mode = UCHAR_MAX;
p->ai.state_counter = 0;
p->ai.timeout_counter = 0;
}
@@ -1089,7 +1090,7 @@ static void AiWantPassengerRoute(Player *p)
p->ai.order_list_blocks[1] = 1;
p->ai.order_list_blocks[2] = 255;
p->ai.state = AIS_BUILD_DEFAULT_RAIL_BLOCKS;
- p->ai.state_mode = -1;
+ p->ai.state_mode = UCHAR_MAX;
p->ai.state_counter = 0;
p->ai.timeout_counter = 0;
}
@@ -1164,7 +1165,7 @@ static void AiWantLongRoadIndustryRoute(Player *p)
p->ai.order_list_blocks[2] = 255;
p->ai.state = AIS_BUILD_DEFAULT_ROAD_BLOCKS;
- p->ai.state_mode = -1;
+ p->ai.state_mode = UCHAR_MAX;
p->ai.state_counter = 0;
p->ai.timeout_counter = 0;
}
@@ -1220,7 +1221,7 @@ static void AiWantMediumRoadIndustryRoute(Player *p)
p->ai.order_list_blocks[2] = 255;
p->ai.state = AIS_BUILD_DEFAULT_ROAD_BLOCKS;
- p->ai.state_mode = -1;
+ p->ai.state_mode = UCHAR_MAX;
p->ai.state_counter = 0;
p->ai.timeout_counter = 0;
}
@@ -1278,7 +1279,7 @@ static void AiWantLongRoadPassengerRoute(Player *p)
p->ai.order_list_blocks[2] = 255;
p->ai.state = AIS_BUILD_DEFAULT_ROAD_BLOCKS;
- p->ai.state_mode = -1;
+ p->ai.state_mode = UCHAR_MAX;
p->ai.state_counter = 0;
p->ai.timeout_counter = 0;
}
@@ -1334,7 +1335,7 @@ static void AiWantPassengerRouteInsideTown(Player *p)
p->ai.order_list_blocks[2] = 255;
p->ai.state = AIS_BUILD_DEFAULT_ROAD_BLOCKS;
- p->ai.state_mode = -1;
+ p->ai.state_mode = UCHAR_MAX;
p->ai.state_counter = 0;
p->ai.timeout_counter = 0;
}
@@ -1852,7 +1853,7 @@ static bool AiDoFollowTrack(const Player* p)
arpfd.tile2 = p->ai.cur_tile_a;
arpfd.flag = false;
arpfd.count = 0;
- FollowTrack(p->ai.cur_tile_a + TileOffsByDiagDir(p->ai.cur_dir_a), 0x2000 | TRANSPORT_RAIL, p->ai.cur_dir_a^2,
+ FollowTrack(p->ai.cur_tile_a + TileOffsByDiagDir(p->ai.cur_dir_a), 0x2000 | TRANSPORT_RAIL, (DiagDirection)(p->ai.cur_dir_a^2),
(TPFEnumProc*)AiEnumFollowTrack, NULL, &arpfd);
return arpfd.count > 8;
}
@@ -1941,7 +1942,7 @@ static bool AiCheckRailPathBetter(AiRailFinder *arf, const byte *p)
}
}
arf->recursive_mode = 0;
- arf->cur_best_dist = (uint)-1;
+ arf->cur_best_dist = UINT_MAX;
arf->cur_best_depth = 0xff;
return better;
@@ -2185,7 +2186,7 @@ static bool AiRemoveTileAndGoForward(Player *p)
} else {
// Check if the bridge points in the right direction.
// This is not really needed the first place AiRemoveTileAndGoForward is called.
- if (DiagDirToAxis(GetBridgeRampDirection(tile)) != (p->ai.cur_dir_a & 1U)) return false;
+ if (DiagDirToAxis(GetBridgeRampDirection(tile)) != (p->ai.cur_dir_a & 1)) return false;
tile = GetOtherBridgeEnd(tile);
@@ -2820,7 +2821,7 @@ static bool AiCheckRoadFinished(Player *p)
are.best_dist = (uint)-1;
for_each_bit(i, bits) {
- FollowTrack(tile, 0x3000 | TRANSPORT_ROAD, _dir_by_track[i], (TPFEnumProc*)AiEnumFollowRoad, NULL, &are);
+ FollowTrack(tile, 0x3000 | TRANSPORT_ROAD, (DiagDirection)_dir_by_track[i], (TPFEnumProc*)AiEnumFollowRoad, NULL, &are);
}
if (DistanceManhattan(tile, are.dest) <= are.best_dist) return false;
@@ -3583,7 +3584,7 @@ static void AiStateRemoveStation(Player *p)
p->ai.state = AIS_1;
// Get a list of all stations that are in use by a vehicle
- in_use = malloc(GetMaxStationIndex() + 1);
+ MallocT(&in_use, GetMaxStationIndex() + 1);
memset(in_use, 0, GetMaxStationIndex() + 1);
FOR_ALL_ORDERS(ord) {
if (ord->type == OT_GOTO_STATION) in_use[ord->dest] = 1;
@@ -3705,7 +3706,7 @@ pos_3:
return;
}
- rails = 0;
+ rails = TRACK_BIT_NONE;
switch (GetBridgeRampDirection(tile)) {
default:
@@ -3798,7 +3799,6 @@ static void AiHandleTakeover(Player *p)
uint asked = p->bankrupt_asked;
Player *pp, *best_pl = NULL;
int32 best_val = -1;
- uint old_p;
// Ask the guy with the highest performance hist.
FOR_ALL_PLAYERS(pp) {
@@ -3830,7 +3830,7 @@ static void AiHandleTakeover(Player *p)
// Too little money for computer to buy it?
if (best_pl->player_money >> 1 >= p->bankrupt_value) {
// Computer wants to buy it.
- old_p = _current_player;
+ PlayerID old_p = _current_player;
_current_player = p->index;
DoCommand(0, old_p, 0, DC_EXEC, CMD_BUY_COMPANY);
_current_player = old_p;
diff --git a/src/ai/trolly/pathfinder.cpp b/src/ai/trolly/pathfinder.cpp
index 6ffdf1fec9..5ba50ca7f1 100644
--- a/src/ai/trolly/pathfinder.cpp
+++ b/src/ai/trolly/pathfinder.cpp
@@ -57,7 +57,7 @@ static bool IsRoad(TileIndex tile)
// Check if the current tile is in our end-area
static int32 AyStar_AiPathFinder_EndNodeCheck(AyStar *aystar, OpenListNode *current)
{
- const Ai_PathFinderInfo* PathFinderInfo = aystar->user_target;
+ const Ai_PathFinderInfo* PathFinderInfo = (Ai_PathFinderInfo*)aystar->user_target;
// It is not allowed to have a station on the end of a bridge or tunnel ;)
if (current->path.node.user_data[0] != 0) return AYSTAR_DONE;
@@ -82,7 +82,7 @@ static uint AiPathFinder_Hash(uint key1, uint key2)
static void AyStar_AiPathFinder_Free(AyStar *aystar)
{
AyStarMain_Free(aystar);
- free(aystar);
+ delete aystar;
}
@@ -99,7 +99,7 @@ AyStar *new_AyStar_AiPathFinder(int max_tiles_around, Ai_PathFinderInfo *PathFin
uint x;
uint y;
// Create AyStar
- AyStar *result = malloc(sizeof(AyStar));
+ AyStar *result = new AyStar();
init_AyStar(result, AiPathFinder_Hash, 1 << 10);
// Set the function pointers
result->CalculateG = AyStar_AiPathFinder_CalculateG;
@@ -170,7 +170,7 @@ void clean_AyStar_AiPathFinder(AyStar *aystar, Ai_PathFinderInfo *PathFinderInfo
// The h-value, simple calculation
static int32 AyStar_AiPathFinder_CalculateH(AyStar *aystar, AyStarNode *current, OpenListNode *parent)
{
- const Ai_PathFinderInfo* PathFinderInfo = aystar->user_target;
+ const Ai_PathFinderInfo* PathFinderInfo = (Ai_PathFinderInfo*)aystar->user_target;
int r, r2;
if (PathFinderInfo->end_direction != AI_PATHFINDER_NO_DIRECTION) {
@@ -214,7 +214,6 @@ static void AyStar_AiPathFinder_FoundEndNode(AyStar *aystar, OpenListNode *curre
// What tiles are around us.
static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *current)
{
- uint i;
int ret;
int dir;
@@ -223,7 +222,7 @@ static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *curr
aystar->num_neighbours = 0;
// Go through all surrounding tiles and check if they are within the limits
- for (i = 0; i < 4; i++) {
+ for (DiagDirection i = DIAGDIR_BEGIN; i < DIAGDIR_END; i++) {
TileIndex ctile = current->path.node.tile; // Current tile
TileIndex atile = ctile + TileOffsByDiagDir(i); // Adjacent tile
@@ -238,7 +237,7 @@ static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *curr
if (IsTunnel(atile)) {
if (GetTunnelDirection(atile) != i) continue;
} else {
- if ((_m[atile].m5 & 1U) != DiagDirToAxis(i)) continue;
+ if ((_m[atile].m5 & 1) != DiagDirToAxis(i)) continue;
}
}
}
@@ -246,7 +245,7 @@ static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *curr
if (!PathFinderInfo->rail_or_road && IsRoad(ctile)) {
if (IsTileType(ctile, MP_TUNNELBRIDGE)) {
// An existing bridge/tunnel... let's test the direction ;)
- if ((_m[ctile].m5 & 1U) != (i & 1)) continue;
+ if ((_m[ctile].m5 & 1) != (i & 1)) continue;
}
}
@@ -254,7 +253,7 @@ static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *curr
(AI_PATHFINDER_FLAG_TUNNEL & current->path.node.user_data[0]) != 0) {
// We are a bridge/tunnel, how cool!!
// This means we can only point forward.. get the direction from the user_data
- if (i != (current->path.node.user_data[0] >> 8)) continue;
+ if ((uint)i != (current->path.node.user_data[0] >> 8)) continue;
}
dir = 0;
@@ -371,7 +370,7 @@ static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *curr
extern uint GetRailFoundation(Slope tileh, TrackBits bits); // XXX function declaration in .c
-extern uint GetRoadFoundation(Slope tileh, uint bits); // XXX function declaration in .c
+extern uint GetRoadFoundation(Slope tileh, RoadBits bits); // XXX function declaration in .c
extern uint GetBridgeFoundation(Slope tileh, Axis); // XXX function declaration in .c
enum {
BRIDGE_NO_FOUNDATION = 1 << 0 | 1 << 3 | 1 << 6 | 1 << 9 | 1 << 12,
@@ -417,7 +416,7 @@ static int32 AyStar_AiPathFinder_CalculateG(AyStar *aystar, AyStarNode *current,
// Skip if the tile was from a bridge or tunnel
if (parent->path.node.user_data[0] == 0 && current->user_data[0] == 0) {
if (PathFinderInfo->rail_or_road) {
- r = GetRailFoundation(parent_tileh, 1 << AiNew_GetRailDirection(parent->path.parent->node.tile, parent->path.node.tile, current->tile));
+ r = GetRailFoundation(parent_tileh, (TrackBits)(1 << AiNew_GetRailDirection(parent->path.parent->node.tile, parent->path.node.tile, current->tile)));
// Maybe is BRIDGE_NO_FOUNDATION a bit strange here, but it contains just the right information..
if (r >= 15 || (r == 0 && HASBIT(BRIDGE_NO_FOUNDATION, tileh))) {
res += AI_PATHFINDER_TILE_GOES_UP_PENALTY;
@@ -426,7 +425,7 @@ static int32 AyStar_AiPathFinder_CalculateG(AyStar *aystar, AyStarNode *current,
}
} else {
if (!IsRoad(parent->path.node.tile) || !IsTileType(parent->path.node.tile, MP_TUNNELBRIDGE)) {
- r = GetRoadFoundation(parent_tileh, AiNew_GetRoadDirection(parent->path.parent->node.tile, parent->path.node.tile, current->tile));
+ r = GetRoadFoundation(parent_tileh, (RoadBits)AiNew_GetRoadDirection(parent->path.parent->node.tile, parent->path.node.tile, current->tile));
if (r >= 15 || r == 0) {
res += AI_PATHFINDER_TILE_GOES_UP_PENALTY;
} else {
@@ -452,13 +451,13 @@ static int32 AyStar_AiPathFinder_CalculateG(AyStar *aystar, AyStarNode *current,
// Check if we are going up or down, first for the starting point
// In user_data[0] is at the 8th bit the direction
if (!HASBIT(BRIDGE_NO_FOUNDATION, parent_tileh)) {
- if (GetBridgeFoundation(parent_tileh, (current->user_data[0] >> 8) & 1) < 15) {
+ if (GetBridgeFoundation(parent_tileh, (Axis)((current->user_data[0] >> 8) & 1)) < 15) {
res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY;
}
}
// Second for the end point
if (!HASBIT(BRIDGE_NO_FOUNDATION, tileh)) {
- if (GetBridgeFoundation(tileh, (current->user_data[0] >> 8) & 1) < 15) {
+ if (GetBridgeFoundation(tileh, (Axis)((current->user_data[0] >> 8) & 1)) < 15) {
res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY;
}
}
diff --git a/src/ai/trolly/trolly.cpp b/src/ai/trolly/trolly.cpp
index 35115a8808..855f74c8ff 100644
--- a/src/ai/trolly/trolly.cpp
+++ b/src/ai/trolly/trolly.cpp
@@ -794,7 +794,7 @@ static void AiNew_State_FindDepot(Player *p)
for (i=2;iainew.path_info.route_length-2;i++) {
tile = p->ainew.path_info.route[i];
- for (j = 0; j < 4; j++) {
+ for (j = DIAGDIR_BEGIN; j < DIAGDIR_END; j++) {
TileIndex t = tile + TileOffsByDiagDir(j);
if (IsTileType(t, MP_STREET) &&
@@ -825,7 +825,7 @@ static void AiNew_State_FindDepot(Player *p)
tile = p->ainew.path_info.route[i];
- for (j = 0; j < 4; j++) {
+ for (j = DIAGDIR_BEGIN; j < DIAGDIR_END; j++) {
TileIndex t = tile + TileOffsByDiagDir(j);
// It may not be placed on the road/rail itself
@@ -901,7 +901,8 @@ static int AiNew_HowManyVehicles(Player *p)
}
// This is because moving 60% is more than we can dream of!
- max_cargo *= 0.6;
+ max_cargo *= 6;
+ max_cargo /= 10;
// We want all the cargo to be gone in a month.. so, we know the cargo it delivers
// we know what the vehicle takes with him, and we know the time it takes him
// to get back here.. now let's do some math!
@@ -1051,7 +1052,7 @@ static void AiNew_State_BuildPath(Player *p)
dir3 = p->ainew.to_direction;
}
- ret = AI_DoCommand(tile, DiagDirToRoadBits(ReverseDiagDir(dir1)), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
+ ret = AI_DoCommand(tile, DiagDirToRoadBits(ReverseDiagDir((DiagDirection)dir1)), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
if (!CmdFailed(ret)) {
dir1 = TileOffsByDiagDir(dir1);
if (IsTileType(tile + dir1, MP_CLEAR) || IsTileType(tile + dir1, MP_TREES)) {
@@ -1063,7 +1064,7 @@ static void AiNew_State_BuildPath(Player *p)
}
}
- ret = AI_DoCommand(tile, DiagDirToRoadBits(ReverseDiagDir(dir2)), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
+ ret = AI_DoCommand(tile, DiagDirToRoadBits(ReverseDiagDir((DiagDirection)dir2)), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
if (!CmdFailed(ret)) {
dir2 = TileOffsByDiagDir(dir2);
if (IsTileType(tile + dir2, MP_CLEAR) || IsTileType(tile + dir2, MP_TREES)) {
@@ -1075,7 +1076,7 @@ static void AiNew_State_BuildPath(Player *p)
}
}
- ret = AI_DoCommand(tile, DiagDirToRoadBits(dir3), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
+ ret = AI_DoCommand(tile, DiagDirToRoadBits((DiagDirection)dir3), 0, DC_EXEC | DC_NO_WATER, CMD_BUILD_ROAD);
if (!CmdFailed(ret)) {
dir3 = TileOffsByDiagDir(dir3);
if (IsTileType(tile + dir3, MP_CLEAR) || IsTileType(tile + dir3, MP_TREES)) {
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp
index bbc3aa4dbb..16c4edfab9 100644
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -246,7 +246,7 @@ int32 CmdBuildAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
v->unitnumber = unit_num;
v->type = u->type = VEH_Aircraft;
- v->direction = 3;
+ v->direction = DIR_SE;
v->owner = u->owner = _current_player;
@@ -382,7 +382,7 @@ int32 CmdBuildAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
u->next = w;
w->type = VEH_Aircraft;
- w->direction = 0;
+ w->direction = DIR_N;
w->owner = _current_player;
w->x_pos = v->x_pos;
w->y_pos = v->y_pos;
@@ -907,7 +907,8 @@ static bool AircraftController(Vehicle *v)
Station *st;
const AirportMovingData *amd;
Vehicle *u;
- byte z,newdir,maxz,curz;
+ byte z, maxz, curz;
+ Direction newdir;
GetNewVehiclePosResult gp;
uint dist;
int x,y;
@@ -1419,7 +1420,7 @@ static void AircraftLeaveHangar(Vehicle *v)
v->cur_speed = 0;
v->subspeed = 0;
v->progress = 0;
- v->direction = 3;
+ v->direction = DIR_SE;
v->vehstatus &= ~VS_HIDDEN;
{
Vehicle *u = v->next;
diff --git a/src/airport.cpp b/src/airport.cpp
index 2135bd11b3..60df231bb3 100644
--- a/src/airport.cpp
+++ b/src/airport.cpp
@@ -9,6 +9,7 @@
#include "variables.h"
#include "airport_movement.h"
#include "date.h"
+#include "helpers.hpp"
/* Uncomment this to print out a full report of the airport-structure
* You should either use
@@ -30,7 +31,7 @@ static AirportFTAClass *HeliStation;
static void AirportFTAClass_Constructor(AirportFTAClass *apc,
const byte *terminals, const byte *helipads,
- const byte entry_point, const byte acc_planes,
+ const byte entry_point, const AcceptPlanes acc_planes,
const AirportFTAbuildup *apFA,
const TileIndexDiffC *depots, const byte nof_depots,
uint size_x, uint size_y
@@ -49,7 +50,7 @@ static void AirportPrintOut(const AirportFTAClass *apc, bool full_report);
void InitializeAirports(void)
{
// country airport
- CountryAirport = malloc(sizeof(AirportFTAClass));
+ MallocT(&CountryAirport, 1);
AirportFTAClass_Constructor(
CountryAirport,
@@ -64,7 +65,7 @@ void InitializeAirports(void)
);
// city airport
- CityAirport = malloc(sizeof(AirportFTAClass));
+ MallocT(&CityAirport, 1);
AirportFTAClass_Constructor(
CityAirport,
@@ -79,7 +80,7 @@ void InitializeAirports(void)
);
// metropolitan airport
- MetropolitanAirport = malloc(sizeof(AirportFTAClass));
+ MallocT(&MetropolitanAirport, 1);
AirportFTAClass_Constructor(
MetropolitanAirport,
@@ -94,7 +95,7 @@ void InitializeAirports(void)
);
// international airport
- InternationalAirport = (AirportFTAClass *)malloc(sizeof(AirportFTAClass));
+ MallocT(&InternationalAirport, 1);
AirportFTAClass_Constructor(
InternationalAirport,
@@ -109,7 +110,7 @@ void InitializeAirports(void)
);
// intercontintental airport
- IntercontinentalAirport = (AirportFTAClass *)malloc(sizeof(AirportFTAClass));
+ MallocT(&IntercontinentalAirport, 1);
AirportFTAClass_Constructor(
IntercontinentalAirport,
@@ -124,7 +125,7 @@ void InitializeAirports(void)
);
// heliport, oilrig
- Heliport = (AirportFTAClass *)malloc(sizeof(AirportFTAClass));
+ MallocT(&Heliport, 1);
AirportFTAClass_Constructor(
Heliport,
@@ -141,7 +142,7 @@ void InitializeAirports(void)
Oilrig = Heliport; // exactly the same structure for heliport/oilrig, so share state machine
// commuter airport
- CommuterAirport = malloc(sizeof(AirportFTAClass));
+ MallocT(&CommuterAirport, 1);
AirportFTAClass_Constructor(
CommuterAirport,
@@ -156,7 +157,7 @@ void InitializeAirports(void)
);
// helidepot airport
- HeliDepot = malloc(sizeof(AirportFTAClass));
+ MallocT(&HeliDepot, 1);
AirportFTAClass_Constructor(
HeliDepot,
@@ -171,7 +172,7 @@ void InitializeAirports(void)
);
// helistation airport
- HeliStation = malloc(sizeof(AirportFTAClass));
+ MallocT(&HeliStation, 1);
AirportFTAClass_Constructor(
HeliStation,
@@ -202,7 +203,7 @@ void UnInitializeAirports(void)
static void AirportFTAClass_Constructor(AirportFTAClass *apc,
const byte *terminals, const byte *helipads,
- const byte entry_point, const byte acc_planes,
+ const byte entry_point, const AcceptPlanes acc_planes,
const AirportFTAbuildup *apFA,
const TileIndexDiffC *depots, const byte nof_depots,
uint size_x, uint size_y
@@ -323,7 +324,8 @@ static byte AirportGetTerminalCount(const byte *terminals, byte *groups)
static void AirportBuildAutomata(AirportFTAClass *apc, const AirportFTAbuildup *apFA)
{
AirportFTA *current;
- AirportFTA *FAutomata = malloc(sizeof(AirportFTA) * apc->nofelements);
+ AirportFTA *FAutomata;
+ MallocT(&FAutomata, apc->nofelements);
uint16 internalcounter = 0;
uint16 i;
@@ -337,7 +339,8 @@ static void AirportBuildAutomata(AirportFTAClass *apc, const AirportFTAbuildup *
// outgoing nodes from the same position, create linked list
while (current->position == apFA[internalcounter + 1].position) {
- AirportFTA *newNode = malloc(sizeof(AirportFTA));
+ AirportFTA *newNode;
+ MallocT(&newNode, 1);
newNode->position = apFA[internalcounter + 1].position;
newNode->heading = apFA[internalcounter + 1].heading;
diff --git a/src/airport.h b/src/airport.h
index 2dcbd16608..207de84fa2 100644
--- a/src/airport.h
+++ b/src/airport.h
@@ -3,6 +3,8 @@
#ifndef AIRPORT_H
#define AIRPORT_H
+#include "direction.h"
+
enum {MAX_TERMINALS = 10};
enum {MAX_HELIPADS = 4};
enum {MAX_ELEMENTS = 255};
@@ -23,12 +25,18 @@ enum {
};
// do not change unless you change v->subtype too. This aligns perfectly with its current setting
-enum {
+enum AcceptPlanes {
+ ACC_BEGIN = 0,
AIRCRAFT_ONLY = 0,
ALL = 1,
HELICOPTERS_ONLY = 2,
+ ACC_END
};
+/** Define basic enum properties */
+template <> struct EnumPropsT : MakeEnumPropsT {};
+typedef TinyEnumT AcceptPlanesByte;
+
enum {
AMED_NOSPDCLAMP = 1 << 0,
AMED_TAKEOFF = 1 << 1,
@@ -122,7 +130,7 @@ enum {
typedef struct AirportMovingData {
int x,y;
byte flag;
- byte direction;
+ DirectionByte direction;
} AirportMovingData;
// Finite sTate mAchine --> FTA
@@ -131,7 +139,7 @@ typedef struct AirportFTAClass {
const byte *terminals;
const byte *helipads;
byte entry_point; // when an airplane arrives at this airport, enter it at position entry_point
- byte acc_planes; // accept airplanes or helicopters or both
+ AcceptPlanesByte acc_planes; // accept airplanes or helicopters or both
const TileIndexDiffC *airport_depots; // gives the position of the depots on the airports
byte nof_depots; // number of depots this airport has
struct AirportFTA *layout; // state machine for airport
diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp
index c049d50d5c..adfd6849c6 100644
--- a/src/airport_gui.cpp
+++ b/src/airport_gui.cpp
@@ -216,7 +216,7 @@ static void BuildAirportPickerWndProc(Window *w, WindowEvent *e)
SetWindowDirty(w);
break;
case 16: case 17:
- _station_show_coverage = e->we.click.widget - 16;
+ _station_show_coverage = (e->we.click.widget != 16);
SetWindowWidgetLoweredState(w, 16, !_station_show_coverage);
SetWindowWidgetLoweredState(w, 17, _station_show_coverage);
SndPlayFx(SND_15_BEEP);
diff --git a/src/airport_movement.h b/src/airport_movement.h
index 1ca00ed754..ac0937cc1a 100644
--- a/src/airport_movement.h
+++ b/src/airport_movement.h
@@ -17,354 +17,354 @@ typedef struct AirportFTAbuildup {
/////*********Movement Positions on Airports********************///////
// Country Airfield (small) 4x3
static const AirportMovingData _airport_moving_data_country[22] = {
- { 53, 3, AMED_EXACTPOS, 3 }, // 00 In Hangar
- { 53, 27, 0, 0 }, // 01 Taxi to right outside depot
- { 32, 23, AMED_EXACTPOS, 7 }, // 02 Terminal 1
- { 10, 23, AMED_EXACTPOS, 7 }, // 03 Terminal 2
- { 43, 37, 0, 0 }, // 04 Going towards terminal 2
- { 24, 37, 0, 0 }, // 05 Going towards terminal 2
- { 53, 37, 0, 0 }, // 06 Going for takeoff
- { 61, 40, AMED_EXACTPOS, 1 }, // 07 Taxi to start of runway (takeoff)
- { 3, 40, AMED_NOSPDCLAMP, 0 }, // 08 Accelerate to end of runway
- { -79, 40, AMED_NOSPDCLAMP | AMED_TAKEOFF, 0 }, // 09 Take off
- { 177, 40, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 10 Fly to landing position in air
- { 56, 40, AMED_NOSPDCLAMP | AMED_LAND, 0 }, // 11 Going down for land
- { 3, 40, AMED_NOSPDCLAMP | AMED_BRAKE, 0 }, // 12 Just landed, brake until end of runway
- { 7, 40, 0, 0 }, // 13 Just landed, turn around and taxi 1 square
- { 53, 40, 0, 0 }, // 14 Taxi from runway to crossing
- { -31, 193, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 15 Fly around waiting for a landing spot (north-east)
- { 1, 1, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 16 Fly around waiting for a landing spot (north-west)
- { 257, 1, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 17 Fly around waiting for a landing spot (south-west)
- { 273, 49, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 18 Fly around waiting for a landing spot (south)
- { 44, 37, AMED_HELI_RAISE, 0 }, // 19 Helicopter takeoff
- { 44, 40, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 20 In position above landing spot helicopter
- { 44, 40, AMED_HELI_LOWER, 0 }, // 21 Helicopter landing
+ { 53, 3, AMED_EXACTPOS, {DIR_SE} }, // 00 In Hangar
+ { 53, 27, 0, {DIR_N} }, // 01 Taxi to right outside depot
+ { 32, 23, AMED_EXACTPOS, {DIR_NW} }, // 02 Terminal 1
+ { 10, 23, AMED_EXACTPOS, {DIR_NW} }, // 03 Terminal 2
+ { 43, 37, 0, {DIR_N} }, // 04 Going towards terminal 2
+ { 24, 37, 0, {DIR_N} }, // 05 Going towards terminal 2
+ { 53, 37, 0, {DIR_N} }, // 06 Going for takeoff
+ { 61, 40, AMED_EXACTPOS, {DIR_NE} }, // 07 Taxi to start of runway (takeoff)
+ { 3, 40, AMED_NOSPDCLAMP, {DIR_N} }, // 08 Accelerate to end of runway
+ { -79, 40, AMED_NOSPDCLAMP | AMED_TAKEOFF, {DIR_N} }, // 09 Take off
+ { 177, 40, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 10 Fly to landing position in air
+ { 56, 40, AMED_NOSPDCLAMP | AMED_LAND, {DIR_N} }, // 11 Going down for land
+ { 3, 40, AMED_NOSPDCLAMP | AMED_BRAKE, {DIR_N} }, // 12 Just landed, brake until end of runway
+ { 7, 40, 0, {DIR_N} }, // 13 Just landed, turn around and taxi 1 square
+ { 53, 40, 0, {DIR_N} }, // 14 Taxi from runway to crossing
+ { -31, 193, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 15 Fly around waiting for a landing spot (north-east)
+ { 1, 1, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 16 Fly around waiting for a landing spot (north-west)
+ { 257, 1, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 17 Fly around waiting for a landing spot (south-west)
+ { 273, 49, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 18 Fly around waiting for a landing spot (south)
+ { 44, 37, AMED_HELI_RAISE, {DIR_N} }, // 19 Helicopter takeoff
+ { 44, 40, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 20 In position above landing spot helicopter
+ { 44, 40, AMED_HELI_LOWER, {DIR_N} }, // 21 Helicopter landing
};
// Commuter Airfield (small) 5x4
static const AirportMovingData _airport_moving_data_commuter[37] = {
- { 69, 3, AMED_EXACTPOS, 3 }, // 00 In Hangar
- { 72, 22, 0, 0 }, // 01 Taxi to right outside depot
- { 8, 22, AMED_EXACTPOS, 5 }, // 01 Taxi to right outside depot
- { 24, 36, AMED_EXACTPOS, 3 }, // 03 Terminal 1
- { 40, 36, AMED_EXACTPOS, 3 }, // 04 Terminal 2
- { 56, 36, AMED_EXACTPOS, 3 }, // 05 Terminal 3
- { 40, 8, AMED_EXACTPOS, 1 }, // 06 Helipad 1
- { 56, 8, AMED_EXACTPOS, 1 }, // 07 Helipad 2
- { 24, 22, 0, 5 }, // 08 Taxiing
- { 40, 22, 0, 5 }, // 09 Taxiing
- { 56, 22, 0, 5 }, // 10 Taxiing
- { 72, 40, 0, 3 }, // 11 Airport OUTWAY
- { 72, 54, AMED_EXACTPOS, 1 }, // 12 Accelerate to end of runway
- { 7, 54, AMED_NOSPDCLAMP, 0 }, // 13 Release control of runway, for smoother movement
- { 5, 54, AMED_NOSPDCLAMP, 0 }, // 14 End of runway
- { -79, 54, AMED_NOSPDCLAMP | AMED_TAKEOFF, 0 }, // 15 Take off
- { 145, 54, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 16 Fly to landing position in air
- { 73, 54, AMED_NOSPDCLAMP | AMED_LAND, 0 }, // 17 Going down for land
- { 3, 54, AMED_NOSPDCLAMP | AMED_BRAKE, 0 }, // 18 Just landed, brake until end of runway
- { 12, 54, 0, 7 }, // 19 Just landed, turn around and taxi
- { 8, 32, 0, 7 }, // 20 Taxi from runway to crossing
- { -31, 149, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 21 Fly around waiting for a landing spot (north-east)
- { 1, 6, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 22 Fly around waiting for a landing spot (north-west)
- { 193, 6, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 23 Fly around waiting for a landing spot (south-west)
- { 225, 81, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 24 Fly around waiting for a landing spot (south)
+ { 69, 3, AMED_EXACTPOS, {DIR_SE} }, // 00 In Hangar
+ { 72, 22, 0, {DIR_N} }, // 01 Taxi to right outside depot
+ { 8, 22, AMED_EXACTPOS, {DIR_SW} }, // 01 Taxi to right outside depot
+ { 24, 36, AMED_EXACTPOS, {DIR_SE} }, // 03 Terminal 1
+ { 40, 36, AMED_EXACTPOS, {DIR_SE} }, // 04 Terminal 2
+ { 56, 36, AMED_EXACTPOS, {DIR_SE} }, // 05 Terminal 3
+ { 40, 8, AMED_EXACTPOS, {DIR_NE} }, // 06 Helipad 1
+ { 56, 8, AMED_EXACTPOS, {DIR_NE} }, // 07 Helipad 2
+ { 24, 22, 0, {DIR_SW} }, // 08 Taxiing
+ { 40, 22, 0, {DIR_SW} }, // 09 Taxiing
+ { 56, 22, 0, {DIR_SW} }, // 10 Taxiing
+ { 72, 40, 0, {DIR_SE} }, // 11 Airport OUTWAY
+ { 72, 54, AMED_EXACTPOS, {DIR_NE} }, // 12 Accelerate to end of runway
+ { 7, 54, AMED_NOSPDCLAMP, {DIR_N} }, // 13 Release control of runway, for smoother movement
+ { 5, 54, AMED_NOSPDCLAMP, {DIR_N} }, // 14 End of runway
+ { -79, 54, AMED_NOSPDCLAMP | AMED_TAKEOFF, {DIR_N} }, // 15 Take off
+ { 145, 54, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 16 Fly to landing position in air
+ { 73, 54, AMED_NOSPDCLAMP | AMED_LAND, {DIR_N} }, // 17 Going down for land
+ { 3, 54, AMED_NOSPDCLAMP | AMED_BRAKE, {DIR_N} }, // 18 Just landed, brake until end of runway
+ { 12, 54, 0, {DIR_NW} }, // 19 Just landed, turn around and taxi
+ { 8, 32, 0, {DIR_NW} }, // 20 Taxi from runway to crossing
+ { -31, 149, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 21 Fly around waiting for a landing spot (north-east)
+ { 1, 6, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 22 Fly around waiting for a landing spot (north-west)
+ { 193, 6, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 23 Fly around waiting for a landing spot (south-west)
+ { 225, 81, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 24 Fly around waiting for a landing spot (south)
// Helicopter
- { 80, 0, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 25 Bufferspace before helipad
- { 80, 0, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 26 Bufferspace before helipad
- { 32, 8, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 27 Get in position for Helipad1
- { 48, 8, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 28 Get in position for Helipad2
- { 32, 8, AMED_HELI_LOWER, 0 }, // 29 Land at Helipad1
- { 48, 8, AMED_HELI_LOWER, 0 }, // 30 Land at Helipad2
- { 32, 8, AMED_HELI_RAISE, 0 }, // 31 Takeoff Helipad1
- { 48, 8, AMED_HELI_RAISE, 0 }, // 32 Takeoff Helipad2
- { 64, 22, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 33 Go to position for Hangarentrance in air
- { 64, 22, AMED_HELI_LOWER, 0 }, // 34 Land in front of hangar
- { 40, 8, AMED_EXACTPOS, 0 }, // pre-helitakeoff helipad 1
- { 56, 8, AMED_EXACTPOS, 0 }, // pre-helitakeoff helipad 2
+ { 80, 0, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 25 Bufferspace before helipad
+ { 80, 0, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 26 Bufferspace before helipad
+ { 32, 8, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 27 Get in position for Helipad1
+ { 48, 8, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 28 Get in position for Helipad2
+ { 32, 8, AMED_HELI_LOWER, {DIR_N} }, // 29 Land at Helipad1
+ { 48, 8, AMED_HELI_LOWER, {DIR_N} }, // 30 Land at Helipad2
+ { 32, 8, AMED_HELI_RAISE, {DIR_N} }, // 31 Takeoff Helipad1
+ { 48, 8, AMED_HELI_RAISE, {DIR_N} }, // 32 Takeoff Helipad2
+ { 64, 22, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 33 Go to position for Hangarentrance in air
+ { 64, 22, AMED_HELI_LOWER, {DIR_N} }, // 34 Land in front of hangar
+ { 40, 8, AMED_EXACTPOS, {DIR_N} }, // pre-helitakeoff helipad 1
+ { 56, 8, AMED_EXACTPOS, {DIR_N} }, // pre-helitakeoff helipad 2
};
// City Airport (large) 6x6
static const AirportMovingData _airport_moving_data_town[25] = {
- { 85, 3, AMED_EXACTPOS, 3 }, // 00 In Hangar
- { 85, 27, 0, 0 }, // 01 Taxi to right outside depot
- { 26, 41, AMED_EXACTPOS, 5 }, // 02 Terminal 1
- { 56, 20, AMED_EXACTPOS, 3 }, // 03 Terminal 2
- { 38, 8, AMED_EXACTPOS, 5 }, // 04 Terminal 3
- { 65, 6, 0, 0 }, // 05 Taxi to right in infront of terminal 2/3
- { 80, 27, 0, 0 }, // 06 Taxiway terminals 2-3
- { 44, 63, 0, 0 }, // 07 Taxi to Airport center
- { 58, 71, 0, 0 }, // 08 Towards takeoff
- { 72, 85, 0, 0 }, // 09 Taxi to runway (takeoff)
- { 89, 85, AMED_EXACTPOS, 1 }, // 10 Taxi to start of runway (takeoff)
- { 3, 85, AMED_NOSPDCLAMP, 0 }, // 11 Accelerate to end of runway
- { -79, 85, AMED_NOSPDCLAMP | AMED_TAKEOFF, 0 }, // 12 Take off
- { 177, 85, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 13 Fly to landing position in air
- { 89, 85, AMED_NOSPDCLAMP | AMED_LAND, 0 }, // 14 Going down for land
- { 3, 85, AMED_NOSPDCLAMP | AMED_BRAKE, 0 }, // 15 Just landed, brake until end of runway
- { 20, 87, 0, 0 }, // 16 Just landed, turn around and taxi 1 square
- { 36, 71, 0, 0 }, // 17 Taxi from runway to crossing
- { -31, 193, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 18 Fly around waiting for a landing spot (north-east)
- { 1, 1, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 19 Fly around waiting for a landing spot (north-west)
- { 257, 1, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 20 Fly around waiting for a landing spot (south-west)
- { 273, 49, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 21 Fly around waiting for a landing spot (south)
- { 44, 63, AMED_HELI_RAISE, 0 }, // 22 Helicopter takeoff
- { 28, 74, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 23 In position above landing spot helicopter
- { 28, 74, AMED_HELI_LOWER, 0 }, // 24 Helicopter landing
+ { 85, 3, AMED_EXACTPOS, {DIR_SE} }, // 00 In Hangar
+ { 85, 27, 0, {DIR_N} }, // 01 Taxi to right outside depot
+ { 26, 41, AMED_EXACTPOS, {DIR_SW} }, // 02 Terminal 1
+ { 56, 20, AMED_EXACTPOS, {DIR_SE} }, // 03 Terminal 2
+ { 38, 8, AMED_EXACTPOS, {DIR_SW} }, // 04 Terminal 3
+ { 65, 6, 0, {DIR_N} }, // 05 Taxi to right in infront of terminal 2/3
+ { 80, 27, 0, {DIR_N} }, // 06 Taxiway terminals 2-3
+ { 44, 63, 0, {DIR_N} }, // 07 Taxi to Airport center
+ { 58, 71, 0, {DIR_N} }, // 08 Towards takeoff
+ { 72, 85, 0, {DIR_N} }, // 09 Taxi to runway (takeoff)
+ { 89, 85, AMED_EXACTPOS, {DIR_NE} }, // 10 Taxi to start of runway (takeoff)
+ { 3, 85, AMED_NOSPDCLAMP, {DIR_N} }, // 11 Accelerate to end of runway
+ { -79, 85, AMED_NOSPDCLAMP | AMED_TAKEOFF, {DIR_N} }, // 12 Take off
+ { 177, 85, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 13 Fly to landing position in air
+ { 89, 85, AMED_NOSPDCLAMP | AMED_LAND, {DIR_N} }, // 14 Going down for land
+ { 3, 85, AMED_NOSPDCLAMP | AMED_BRAKE, {DIR_N} }, // 15 Just landed, brake until end of runway
+ { 20, 87, 0, {DIR_N} }, // 16 Just landed, turn around and taxi 1 square
+ { 36, 71, 0, {DIR_N} }, // 17 Taxi from runway to crossing
+ { -31, 193, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 18 Fly around waiting for a landing spot (north-east)
+ { 1, 1, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 19 Fly around waiting for a landing spot (north-west)
+ { 257, 1, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 20 Fly around waiting for a landing spot (south-west)
+ { 273, 49, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 21 Fly around waiting for a landing spot (south)
+ { 44, 63, AMED_HELI_RAISE, {DIR_N} }, // 22 Helicopter takeoff
+ { 28, 74, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 23 In position above landing spot helicopter
+ { 28, 74, AMED_HELI_LOWER, {DIR_N} }, // 24 Helicopter landing
};
// Metropolitan Airport (metropolitan) - 2 runways
static const AirportMovingData _airport_moving_data_metropolitan[27] = {
- { 85, 3, AMED_EXACTPOS, 3 }, // 00 In Hangar
- { 85, 27, 0, 0 }, // 01 Taxi to right outside depot
- { 26, 41, AMED_EXACTPOS, 5 }, // 02 Terminal 1
- { 56, 20, AMED_EXACTPOS, 3 }, // 03 Terminal 2
- { 38, 8, AMED_EXACTPOS, 5 }, // 04 Terminal 3
- { 65, 6, 0, 0 }, // 05 Taxi to right in infront of terminal 2/3
- { 70, 33, 0, 0 }, // 06 Taxiway terminals 2-3
- { 44, 58, 0, 0 }, // 07 Taxi to Airport center
- { 72, 58, 0, 0 }, // 08 Towards takeoff
- { 72, 69, 0, 0 }, // 09 Taxi to runway (takeoff)
- { 89, 69, AMED_EXACTPOS, 1 }, // 10 Taxi to start of runway (takeoff)
- { 3, 69, AMED_NOSPDCLAMP, 0 }, // 11 Accelerate to end of runway
- { -79, 69, AMED_NOSPDCLAMP | AMED_TAKEOFF, 0 }, // 12 Take off
- { 177, 85, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 13 Fly to landing position in air
- { 89, 85, AMED_NOSPDCLAMP | AMED_LAND, 0 }, // 14 Going down for land
- { 3, 85, AMED_NOSPDCLAMP | AMED_BRAKE, 0 }, // 15 Just landed, brake until end of runway
- { 21, 85, 0, 0 }, // 16 Just landed, turn around and taxi 1 square
- { 21, 69, 0, 0 }, // 17 On Runway-out taxiing to In-Way
- { 21, 54, AMED_EXACTPOS, 5 }, // 18 Taxi from runway to crossing
- { -31, 193, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 19 Fly around waiting for a landing spot (north-east)
- { 1, 1, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 20 Fly around waiting for a landing spot (north-west)
- { 257, 1, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 21 Fly around waiting for a landing spot (south-west)
- { 273, 49, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 22 Fly around waiting for a landing spot (south)
- { 44, 58, 0, 0 }, // 23 Helicopter takeoff spot on ground (to clear airport sooner)
- { 44, 63, AMED_HELI_RAISE, 0 }, // 24 Helicopter takeoff
- { 15, 54, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 25 Get in position above landing spot helicopter
- { 15, 54, AMED_HELI_LOWER, 0 }, // 26 Helicopter landing
+ { 85, 3, AMED_EXACTPOS, {DIR_SE} }, // 00 In Hangar
+ { 85, 27, 0, {DIR_N} }, // 01 Taxi to right outside depot
+ { 26, 41, AMED_EXACTPOS, {DIR_SW} }, // 02 Terminal 1
+ { 56, 20, AMED_EXACTPOS, {DIR_SE} }, // 03 Terminal 2
+ { 38, 8, AMED_EXACTPOS, {DIR_SW} }, // 04 Terminal 3
+ { 65, 6, 0, {DIR_N} }, // 05 Taxi to right in infront of terminal 2/3
+ { 70, 33, 0, {DIR_N} }, // 06 Taxiway terminals 2-3
+ { 44, 58, 0, {DIR_N} }, // 07 Taxi to Airport center
+ { 72, 58, 0, {DIR_N} }, // 08 Towards takeoff
+ { 72, 69, 0, {DIR_N} }, // 09 Taxi to runway (takeoff)
+ { 89, 69, AMED_EXACTPOS, {DIR_NE} }, // 10 Taxi to start of runway (takeoff)
+ { 3, 69, AMED_NOSPDCLAMP, {DIR_N} }, // 11 Accelerate to end of runway
+ { -79, 69, AMED_NOSPDCLAMP | AMED_TAKEOFF, {DIR_N} }, // 12 Take off
+ { 177, 85, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 13 Fly to landing position in air
+ { 89, 85, AMED_NOSPDCLAMP | AMED_LAND, {DIR_N} }, // 14 Going down for land
+ { 3, 85, AMED_NOSPDCLAMP | AMED_BRAKE, {DIR_N} }, // 15 Just landed, brake until end of runway
+ { 21, 85, 0, {DIR_N} }, // 16 Just landed, turn around and taxi 1 square
+ { 21, 69, 0, {DIR_N} }, // 17 On Runway-out taxiing to In-Way
+ { 21, 54, AMED_EXACTPOS, {DIR_SW} }, // 18 Taxi from runway to crossing
+ { -31, 193, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 19 Fly around waiting for a landing spot (north-east)
+ { 1, 1, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 20 Fly around waiting for a landing spot (north-west)
+ { 257, 1, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 21 Fly around waiting for a landing spot (south-west)
+ { 273, 49, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 22 Fly around waiting for a landing spot (south)
+ { 44, 58, 0, {DIR_N} }, // 23 Helicopter takeoff spot on ground (to clear airport sooner)
+ { 44, 63, AMED_HELI_RAISE, {DIR_N} }, // 24 Helicopter takeoff
+ { 15, 54, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 25 Get in position above landing spot helicopter
+ { 15, 54, AMED_HELI_LOWER, {DIR_N} }, // 26 Helicopter landing
};
// International Airport (international) - 2 runways, 6 terminals, dedicated helipod
static const AirportMovingData _airport_moving_data_international[51] = {
- { 7, 55, AMED_EXACTPOS, 3 }, // 00 In Hangar 1
- { 100, 21, AMED_EXACTPOS, 3 }, // 01 In Hangar 2
- { 7, 70, 0, 0 }, // 02 Taxi to right outside depot
- { 100, 36, 0, 0 }, // 03 Taxi to right outside depot
- { 38, 70, AMED_EXACTPOS, 5 }, // 04 Terminal 1
- { 38, 54, AMED_EXACTPOS, 5 }, // 05 Terminal 2
- { 38, 38, AMED_EXACTPOS, 5 }, // 06 Terminal 3
- { 70, 70, AMED_EXACTPOS, 1 }, // 07 Terminal 4
- { 70, 54, AMED_EXACTPOS, 1 }, // 08 Terminal 5
- { 70, 38, AMED_EXACTPOS, 1 }, // 09 Terminal 6
- { 104, 71, AMED_EXACTPOS, 1 }, // 10 Helipad 1
- { 104, 55, AMED_EXACTPOS, 1 }, // 11 Helipad 2
- { 22, 87, 0, 0 }, // 12 Towards Terminals 4/5/6, Helipad 1/2
- { 60, 87, 0, 0 }, // 13 Towards Terminals 4/5/6, Helipad 1/2
- { 66, 87, 0, 0 }, // 14 Towards Terminals 4/5/6, Helipad 1/2
- { 86, 87, AMED_EXACTPOS, 7 }, // 15 Towards Terminals 4/5/6, Helipad 1/2
- { 86, 70, 0, 0 }, // 16 In Front of Terminal 4 / Helipad 1
- { 86, 54, 0, 0 }, // 17 In Front of Terminal 5 / Helipad 2
- { 86, 38, 0, 0 }, // 18 In Front of Terminal 6
- { 86, 22, 0, 0 }, // 19 Towards Terminals Takeoff (Taxiway)
- { 66, 22, 0, 0 }, // 20 Towards Terminals Takeoff (Taxiway)
- { 60, 22, 0, 0 }, // 21 Towards Terminals Takeoff (Taxiway)
- { 38, 22, 0, 0 }, // 22 Towards Terminals Takeoff (Taxiway)
- { 22, 70, 0, 0 }, // 23 In Front of Terminal 1
- { 22, 58, 0, 0 }, // 24 In Front of Terminal 2
- { 22, 38, 0, 0 }, // 25 In Front of Terminal 3
- { 22, 22, AMED_EXACTPOS, 7 }, // 26 Going for Takeoff
- { 22, 6, 0, 0 }, // 27 On Runway-out, prepare for takeoff
- { 3, 6, AMED_EXACTPOS, 5 }, // 28 Accelerate to end of runway
- { 60, 6, AMED_NOSPDCLAMP, 0 }, // 29 Release control of runway, for smoother movement
- { 105, 6, AMED_NOSPDCLAMP, 0 }, // 30 End of runway
- { 190, 6, AMED_NOSPDCLAMP | AMED_TAKEOFF, 0 }, // 31 Take off
- { 193, 104, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 32 Fly to landing position in air
- { 105, 104, AMED_NOSPDCLAMP | AMED_LAND, 0 }, // 33 Going down for land
- { 3, 104, AMED_NOSPDCLAMP | AMED_BRAKE, 0 }, // 34 Just landed, brake until end of runway
- { 12, 104, 0, 0 }, // 35 Just landed, turn around and taxi 1 square
- { 7, 84, 0, 0 }, // 36 Taxi from runway to crossing
- { -31, 209, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 37 Fly around waiting for a landing spot (north-east)
- { 1, 6, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 38 Fly around waiting for a landing spot (north-west)
- { 273, 6, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 39 Fly around waiting for a landing spot (south-west)
- { 305, 81, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 40 Fly around waiting for a landing spot (south)
+ { 7, 55, AMED_EXACTPOS, {DIR_SE} }, // 00 In Hangar 1
+ { 100, 21, AMED_EXACTPOS, {DIR_SE} }, // 01 In Hangar 2
+ { 7, 70, 0, {DIR_N} }, // 02 Taxi to right outside depot
+ { 100, 36, 0, {DIR_N} }, // 03 Taxi to right outside depot
+ { 38, 70, AMED_EXACTPOS, {DIR_SW} }, // 04 Terminal 1
+ { 38, 54, AMED_EXACTPOS, {DIR_SW} }, // 05 Terminal 2
+ { 38, 38, AMED_EXACTPOS, {DIR_SW} }, // 06 Terminal 3
+ { 70, 70, AMED_EXACTPOS, {DIR_NE} }, // 07 Terminal 4
+ { 70, 54, AMED_EXACTPOS, {DIR_NE} }, // 08 Terminal 5
+ { 70, 38, AMED_EXACTPOS, {DIR_NE} }, // 09 Terminal 6
+ { 104, 71, AMED_EXACTPOS, {DIR_NE} }, // 10 Helipad 1
+ { 104, 55, AMED_EXACTPOS, {DIR_NE} }, // 11 Helipad 2
+ { 22, 87, 0, {DIR_N} }, // 12 Towards Terminals 4/5/6, Helipad 1/2
+ { 60, 87, 0, {DIR_N} }, // 13 Towards Terminals 4/5/6, Helipad 1/2
+ { 66, 87, 0, {DIR_N} }, // 14 Towards Terminals 4/5/6, Helipad 1/2
+ { 86, 87, AMED_EXACTPOS, {DIR_NW} }, // 15 Towards Terminals 4/5/6, Helipad 1/2
+ { 86, 70, 0, {DIR_N} }, // 16 In Front of Terminal 4 / Helipad 1
+ { 86, 54, 0, {DIR_N} }, // 17 In Front of Terminal 5 / Helipad 2
+ { 86, 38, 0, {DIR_N} }, // 18 In Front of Terminal 6
+ { 86, 22, 0, {DIR_N} }, // 19 Towards Terminals Takeoff (Taxiway)
+ { 66, 22, 0, {DIR_N} }, // 20 Towards Terminals Takeoff (Taxiway)
+ { 60, 22, 0, {DIR_N} }, // 21 Towards Terminals Takeoff (Taxiway)
+ { 38, 22, 0, {DIR_N} }, // 22 Towards Terminals Takeoff (Taxiway)
+ { 22, 70, 0, {DIR_N} }, // 23 In Front of Terminal 1
+ { 22, 58, 0, {DIR_N} }, // 24 In Front of Terminal 2
+ { 22, 38, 0, {DIR_N} }, // 25 In Front of Terminal 3
+ { 22, 22, AMED_EXACTPOS, {DIR_NW} }, // 26 Going for Takeoff
+ { 22, 6, 0, {DIR_N} }, // 27 On Runway-out, prepare for takeoff
+ { 3, 6, AMED_EXACTPOS, {DIR_SW} }, // 28 Accelerate to end of runway
+ { 60, 6, AMED_NOSPDCLAMP, {DIR_N} }, // 29 Release control of runway, for smoother movement
+ { 105, 6, AMED_NOSPDCLAMP, {DIR_N} }, // 30 End of runway
+ { 190, 6, AMED_NOSPDCLAMP | AMED_TAKEOFF, {DIR_N} }, // 31 Take off
+ { 193, 104, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 32 Fly to landing position in air
+ { 105, 104, AMED_NOSPDCLAMP | AMED_LAND, {DIR_N} }, // 33 Going down for land
+ { 3, 104, AMED_NOSPDCLAMP | AMED_BRAKE, {DIR_N} }, // 34 Just landed, brake until end of runway
+ { 12, 104, 0, {DIR_N} }, // 35 Just landed, turn around and taxi 1 square
+ { 7, 84, 0, {DIR_N} }, // 36 Taxi from runway to crossing
+ { -31, 209, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 37 Fly around waiting for a landing spot (north-east)
+ { 1, 6, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 38 Fly around waiting for a landing spot (north-west)
+ { 273, 6, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 39 Fly around waiting for a landing spot (south-west)
+ { 305, 81, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 40 Fly around waiting for a landing spot (south)
// Helicopter
- { 128, 80, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 41 Bufferspace before helipad
- { 128, 80, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 42 Bufferspace before helipad
- { 96, 71, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 43 Get in position for Helipad1
- { 96, 55, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 44 Get in position for Helipad2
- { 96, 71, AMED_HELI_LOWER, 0 }, // 45 Land at Helipad1
- { 96, 55, AMED_HELI_LOWER, 0 }, // 46 Land at Helipad2
- { 104, 71, AMED_HELI_RAISE, 0 }, // 47 Takeoff Helipad1
- { 104, 55, AMED_HELI_RAISE, 0 }, // 48 Takeoff Helipad2
- { 104, 32, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 49 Go to position for Hangarentrance in air
- { 104, 32, AMED_HELI_LOWER, 0} // 50 Land in HANGAR2_AREA to go to hangar
+ { 128, 80, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 41 Bufferspace before helipad
+ { 128, 80, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 42 Bufferspace before helipad
+ { 96, 71, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 43 Get in position for Helipad1
+ { 96, 55, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 44 Get in position for Helipad2
+ { 96, 71, AMED_HELI_LOWER, {DIR_N} }, // 45 Land at Helipad1
+ { 96, 55, AMED_HELI_LOWER, {DIR_N} }, // 46 Land at Helipad2
+ { 104, 71, AMED_HELI_RAISE, {DIR_N} }, // 47 Takeoff Helipad1
+ { 104, 55, AMED_HELI_RAISE, {DIR_N} }, // 48 Takeoff Helipad2
+ { 104, 32, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 49 Go to position for Hangarentrance in air
+ { 104, 32, AMED_HELI_LOWER, {DIR_N} }, // 50 Land in HANGAR2_AREA to go to hangar
};
// Intercontinental Airport - 4 runways, 8 terminals, 2 dedicated helipads
static const AirportMovingData _airport_moving_data_intercontinental[77] = {
- { 7, 87, AMED_EXACTPOS, 3 }, // 00 In Hangar 1
- { 135, 72, AMED_EXACTPOS, 3 }, // 01 In Hangar 2
- { 7, 104, 0, 0 }, // 02 Taxi to right outside depot 1
- { 135, 88, 0, 0 }, // 03 Taxi to right outside depot 2
- { 56, 120, AMED_EXACTPOS, 6 }, // 04 Terminal 1
- { 56, 104, AMED_EXACTPOS, 5 }, // 05 Terminal 2
- { 56, 88, AMED_EXACTPOS, 5 }, // 06 Terminal 3
- { 56, 72, AMED_EXACTPOS, 5 }, // 07 Terminal 4
- { 88, 120, AMED_EXACTPOS, 0 }, // 08 Terminal 5
- { 88, 104, AMED_EXACTPOS, 1 }, // 09 Terminal 6
- { 88, 88, AMED_EXACTPOS, 1 }, // 10 Terminal 7
- { 88, 72, AMED_EXACTPOS, 1 }, // 11 Terminal 8
- { 88, 56, AMED_EXACTPOS, 3 }, // 12 Helipad 1
- { 72, 56, AMED_EXACTPOS, 1 }, // 13 Helipad 2
- { 40, 136, 0, 0 }, // 14 Term group 2 enter 1 a
- { 56, 136, 0, 0 }, // 15 Term group 2 enter 1 b
- { 88, 136, 0, 0 }, // 16 Term group 2 enter 2 a
- { 104, 136, 0, 0 }, // 17 Term group 2 enter 2 b
- { 104, 120, 0, 0 }, // 18 Term group 2 - opp term 5
- { 104, 104, 0, 0 }, // 19 Term group 2 - opp term 6 & exit2
- { 104, 88, 0, 0 }, // 20 Term group 2 - opp term 7 & hangar area 2
- { 104, 72, 0, 0 }, // 21 Term group 2 - opp term 8
- { 104, 56, 0, 0 }, // 22 Taxi Term group 2 exit a
- { 104, 40, 0, 0 }, // 23 Taxi Term group 2 exit b
- { 56, 40, 0, 0 }, // 24 Term group 2 exit 2a
- { 40, 40, 0, 0 }, // 25 Term group 2 exit 2b
- { 40, 120, 0, 0 }, // 26 Term group 1 - opp term 1
- { 40, 104, 0, 0 }, // 27 Term group 1 - opp term 2 & hangar area 1
- { 40, 88, 0, 0 }, // 28 Term group 1 - opp term 3
- { 40, 72, 0, 0 }, // 29 Term group 1 - opp term 4
- { 18, 72, 0, 7 }, // 30 Outway 1
- { 8, 40, 0, 7 }, // 31 Airport OUTWAY
- { 8, 24, AMED_EXACTPOS, 5 }, // 32 Accelerate to end of runway
- { 119, 24, AMED_NOSPDCLAMP, 0 }, // 33 Release control of runway, for smoother movement
- { 117, 24, AMED_NOSPDCLAMP, 0 }, // 34 End of runway
- { 197, 24, AMED_NOSPDCLAMP | AMED_TAKEOFF, 0 }, // 35 Take off
- { 254, 84, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 36 Flying to landing position in air
- { 117, 168, AMED_NOSPDCLAMP | AMED_LAND, 0 }, // 37 Going down for land
- { 3, 168, AMED_NOSPDCLAMP | AMED_BRAKE, 0 }, // 38 Just landed, brake until end of runway
- { 8, 168, 0, 0 }, // 39 Just landed, turn around and taxi
- { 8, 144, 0, 7 }, // 40 Taxi from runway
- { 8, 128, 0, 7 }, // 41 Taxi from runway
- { 8, 120, AMED_EXACTPOS, 5 }, // 42 Airport entrance
- { 56, 344, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 43 Fly around waiting for a landing spot (north-east)
- { -200, 88, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 44 Fly around waiting for a landing spot (north-west)
- { 56, -168, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 45 Fly around waiting for a landing spot (south-west)
- { 312, 88, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 46 Fly around waiting for a landing spot (south)
+ { 7, 87, AMED_EXACTPOS, {DIR_SE} }, // 00 In Hangar 1
+ { 135, 72, AMED_EXACTPOS, {DIR_SE} }, // 01 In Hangar 2
+ { 7, 104, 0, {DIR_N} }, // 02 Taxi to right outside depot 1
+ { 135, 88, 0, {DIR_N} }, // 03 Taxi to right outside depot 2
+ { 56, 120, AMED_EXACTPOS, {DIR_W} }, // 04 Terminal 1
+ { 56, 104, AMED_EXACTPOS, {DIR_SW} }, // 05 Terminal 2
+ { 56, 88, AMED_EXACTPOS, {DIR_SW} }, // 06 Terminal 3
+ { 56, 72, AMED_EXACTPOS, {DIR_SW} }, // 07 Terminal 4
+ { 88, 120, AMED_EXACTPOS, {DIR_N} }, // 08 Terminal 5
+ { 88, 104, AMED_EXACTPOS, {DIR_NE} }, // 09 Terminal 6
+ { 88, 88, AMED_EXACTPOS, {DIR_NE} }, // 10 Terminal 7
+ { 88, 72, AMED_EXACTPOS, {DIR_NE} }, // 11 Terminal 8
+ { 88, 56, AMED_EXACTPOS, {DIR_SE} }, // 12 Helipad 1
+ { 72, 56, AMED_EXACTPOS, {DIR_NE} }, // 13 Helipad 2
+ { 40, 136, 0, {DIR_N} }, // 14 Term group 2 enter 1 a
+ { 56, 136, 0, {DIR_N} }, // 15 Term group 2 enter 1 b
+ { 88, 136, 0, {DIR_N} }, // 16 Term group 2 enter 2 a
+ { 104, 136, 0, {DIR_N} }, // 17 Term group 2 enter 2 b
+ { 104, 120, 0, {DIR_N} }, // 18 Term group 2 - opp term 5
+ { 104, 104, 0, {DIR_N} }, // 19 Term group 2 - opp term 6 & exit2
+ { 104, 88, 0, {DIR_N} }, // 20 Term group 2 - opp term 7 & hangar area 2
+ { 104, 72, 0, {DIR_N} }, // 21 Term group 2 - opp term 8
+ { 104, 56, 0, {DIR_N} }, // 22 Taxi Term group 2 exit a
+ { 104, 40, 0, {DIR_N} }, // 23 Taxi Term group 2 exit b
+ { 56, 40, 0, {DIR_N} }, // 24 Term group 2 exit 2a
+ { 40, 40, 0, {DIR_N} }, // 25 Term group 2 exit 2b
+ { 40, 120, 0, {DIR_N} }, // 26 Term group 1 - opp term 1
+ { 40, 104, 0, {DIR_N} }, // 27 Term group 1 - opp term 2 & hangar area 1
+ { 40, 88, 0, {DIR_N} }, // 28 Term group 1 - opp term 3
+ { 40, 72, 0, {DIR_N} }, // 29 Term group 1 - opp term 4
+ { 18, 72, 0, {DIR_NW} }, // 30 Outway 1
+ { 8, 40, 0, {DIR_NW} }, // 31 Airport OUTWAY
+ { 8, 24, AMED_EXACTPOS, {DIR_SW} }, // 32 Accelerate to end of runway
+ { 119, 24, AMED_NOSPDCLAMP, {DIR_N} }, // 33 Release control of runway, for smoother movement
+ { 117, 24, AMED_NOSPDCLAMP, {DIR_N} }, // 34 End of runway
+ { 197, 24, AMED_NOSPDCLAMP | AMED_TAKEOFF, {DIR_N} }, // 35 Take off
+ { 254, 84, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 36 Flying to landing position in air
+ { 117, 168, AMED_NOSPDCLAMP | AMED_LAND, {DIR_N} }, // 37 Going down for land
+ { 3, 168, AMED_NOSPDCLAMP | AMED_BRAKE, {DIR_N} }, // 38 Just landed, brake until end of runway
+ { 8, 168, 0, {DIR_N} }, // 39 Just landed, turn around and taxi
+ { 8, 144, 0, {DIR_NW} }, // 40 Taxi from runway
+ { 8, 128, 0, {DIR_NW} }, // 41 Taxi from runway
+ { 8, 120, AMED_EXACTPOS, {DIR_SW} }, // 42 Airport entrance
+ { 56, 344, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 43 Fly around waiting for a landing spot (north-east)
+ { -200, 88, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 44 Fly around waiting for a landing spot (north-west)
+ { 56, -168, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 45 Fly around waiting for a landing spot (south-west)
+ { 312, 88, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 46 Fly around waiting for a landing spot (south)
// Helicopter
- { 96, 40, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 47 Bufferspace before helipad
- { 96, 40, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 48 Bufferspace before helipad
- { 82, 54, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 49 Get in position for Helipad1
- { 64, 56, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 50 Get in position for Helipad2
- { 81, 55, AMED_HELI_LOWER, 0 }, // 51 Land at Helipad1
- { 64, 56, AMED_HELI_LOWER, 0 }, // 52 Land at Helipad2
- { 80, 56, AMED_HELI_RAISE, 0 }, // 53 Takeoff Helipad1
- { 64, 56, AMED_HELI_RAISE, 0 }, // 54 Takeoff Helipad2
- { 136, 96, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 55 Go to position for Hangarentrance in air
- { 136, 96, AMED_HELI_LOWER, 0 }, // 56 Land in front of hangar2
- { 126, 104, 0, 3 }, // 57 Outway 2
- { 136, 136, 0, 1 }, // 58 Airport OUTWAY 2
- { 136, 152, AMED_EXACTPOS, 5 }, // 59 Accelerate to end of runway2
- { 16, 152, AMED_NOSPDCLAMP, 0 }, // 60 Release control of runway2, for smoother movement
- { 20, 152, AMED_NOSPDCLAMP, 0 }, // 61 End of runway2
- { -56, 152, AMED_NOSPDCLAMP | AMED_TAKEOFF, 0 }, // 62 Take off2
- { 24, 8, AMED_NOSPDCLAMP | AMED_LAND, 0 }, // 63 Going down for land2
- { 136, 8, AMED_NOSPDCLAMP | AMED_BRAKE, 0 }, // 64 Just landed, brake until end of runway2in
- { 136, 8, 0, 0 }, // 65 Just landed, turn around and taxi
- { 136, 24, 0, 3 }, // 66 Taxi from runway 2in
- { 136, 40, 0, 3 }, // 67 Taxi from runway 2in
- { 136, 56, AMED_EXACTPOS, 1 }, // 68 Airport entrance2
- { -56, 8, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 69 Fly to landing position in air2
- { 88, 40, 0, 0 }, // 70 Taxi Term group 2 exit - opp heli1
- { 72, 40, 0, 0 }, // 71 Taxi Term group 2 exit - opp heli2
- { 88, 57, AMED_EXACTPOS, 3 }, // 72 pre-helitakeoff helipad 1
- { 71, 56, AMED_EXACTPOS, 1 }, // 73 pre-helitakeoff helipad 2
- { 8, 120, AMED_HELI_RAISE, 0 }, // 74 Helitakeoff outside depot 1
- { 136, 104, AMED_HELI_RAISE, 0 }, // 75 Helitakeoff outside depot 2
- { 197, 168, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0} // 76 Fly to landing position in air1
+ { 96, 40, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 47 Bufferspace before helipad
+ { 96, 40, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 48 Bufferspace before helipad
+ { 82, 54, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 49 Get in position for Helipad1
+ { 64, 56, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 50 Get in position for Helipad2
+ { 81, 55, AMED_HELI_LOWER, {DIR_N} }, // 51 Land at Helipad1
+ { 64, 56, AMED_HELI_LOWER, {DIR_N} }, // 52 Land at Helipad2
+ { 80, 56, AMED_HELI_RAISE, {DIR_N} }, // 53 Takeoff Helipad1
+ { 64, 56, AMED_HELI_RAISE, {DIR_N} }, // 54 Takeoff Helipad2
+ { 136, 96, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 55 Go to position for Hangarentrance in air
+ { 136, 96, AMED_HELI_LOWER, {DIR_N} }, // 56 Land in front of hangar2
+ { 126, 104, 0, {DIR_SE} }, // 57 Outway 2
+ { 136, 136, 0, {DIR_NE} }, // 58 Airport OUTWAY 2
+ { 136, 152, AMED_EXACTPOS, {DIR_SW} }, // 59 Accelerate to end of runway2
+ { 16, 152, AMED_NOSPDCLAMP, {DIR_N} }, // 60 Release control of runway2, for smoother movement
+ { 20, 152, AMED_NOSPDCLAMP, {DIR_N} }, // 61 End of runway2
+ { -56, 152, AMED_NOSPDCLAMP | AMED_TAKEOFF, {DIR_N} }, // 62 Take off2
+ { 24, 8, AMED_NOSPDCLAMP | AMED_LAND, {DIR_N} }, // 63 Going down for land2
+ { 136, 8, AMED_NOSPDCLAMP | AMED_BRAKE, {DIR_N} }, // 64 Just landed, brake until end of runway2in
+ { 136, 8, 0, {DIR_N} }, // 65 Just landed, turn around and taxi
+ { 136, 24, 0, {DIR_SE} }, // 66 Taxi from runway 2in
+ { 136, 40, 0, {DIR_SE} }, // 67 Taxi from runway 2in
+ { 136, 56, AMED_EXACTPOS, {DIR_NE} }, // 68 Airport entrance2
+ { -56, 8, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 69 Fly to landing position in air2
+ { 88, 40, 0, {DIR_N} }, // 70 Taxi Term group 2 exit - opp heli1
+ { 72, 40, 0, {DIR_N} }, // 71 Taxi Term group 2 exit - opp heli2
+ { 88, 57, AMED_EXACTPOS, {DIR_SE} }, // 72 pre-helitakeoff helipad 1
+ { 71, 56, AMED_EXACTPOS, {DIR_NE} }, // 73 pre-helitakeoff helipad 2
+ { 8, 120, AMED_HELI_RAISE, {DIR_N} }, // 74 Helitakeoff outside depot 1
+ { 136, 104, AMED_HELI_RAISE, {DIR_N} }, // 75 Helitakeoff outside depot 2
+ { 197, 168, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 76 Fly to landing position in air1
};
// Heliport (heliport)
static const AirportMovingData _airport_moving_data_heliport[9] = {
- { 5, 9, AMED_EXACTPOS, 1 }, // 0 - At heliport terminal
- { 2, 9, AMED_HELI_RAISE, 0 }, // 1 - Take off (play sound)
- { -3, 9, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 2 - In position above landing spot helicopter
- { -3, 9, AMED_HELI_LOWER, 0 }, // 3 - Land
- { 2, 9, 0, 0 }, // 4 - Goto terminal on ground
- { -31, 59, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 5 - Circle #1 (north-east)
- { -31, -49, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 6 - Circle #2 (north-west)
- { 49, -49, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 7 - Circle #3 (south-west)
- { 70, 9, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 8 - Circle #4 (south)
+ { 5, 9, AMED_EXACTPOS, {DIR_NE} }, // 0 - At heliport terminal
+ { 2, 9, AMED_HELI_RAISE, {DIR_N} }, // 1 - Take off (play sound)
+ { -3, 9, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 2 - In position above landing spot helicopter
+ { -3, 9, AMED_HELI_LOWER, {DIR_N} }, // 3 - Land
+ { 2, 9, 0, {DIR_N} }, // 4 - Goto terminal on ground
+ { -31, 59, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 5 - Circle #1 (north-east)
+ { -31, -49, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 6 - Circle #2 (north-west)
+ { 49, -49, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 7 - Circle #3 (south-west)
+ { 70, 9, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 8 - Circle #4 (south)
};
// HeliDepot 2x2 (heliport)
static const AirportMovingData _airport_moving_data_helidepot[18] = {
- { 24, 4, AMED_EXACTPOS, 1 }, // 0 - At depot
- { 24, 28, 0, 0 }, // 1 Taxi to right outside depot
- { 5, 38, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 2 Flying
- { -15, -15, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 3 - Circle #1 (north-east)
- { -15, -49, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 4 - Circle #2 (north-west)
- { 49, -49, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 5 - Circle #3 (south-west)
- { 49, -15, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 6 - Circle #4 (south-east)
- { 8, 32, AMED_NOSPDCLAMP | AMED_SLOWTURN, 7 }, // 7 - PreHelipad
- { 8, 32, AMED_NOSPDCLAMP | AMED_SLOWTURN, 7 }, // 8 - Helipad
- { 8, 16, AMED_NOSPDCLAMP | AMED_SLOWTURN, 7 }, // 9 - Land
- { 8, 16, AMED_HELI_LOWER, 7 }, // 10 - Land
- { 8, 24, AMED_HELI_RAISE, 0 }, // 11 - Take off (play sound)
- { 32, 24, AMED_NOSPDCLAMP | AMED_SLOWTURN, 7 }, // 12 Air to above hangar area
- { 32, 24, AMED_HELI_LOWER, 7 }, // 13 Taxi to right outside depot
- { 8, 24, AMED_EXACTPOS, 7 }, // 14 - on helipad1
- { 24, 28, AMED_HELI_RAISE, 0 }, // 15 Takeoff right outside depot
- { 8, 24, AMED_HELI_RAISE, 5 }, // 16 - Take off (play sound)
- { 8, 24, AMED_SLOWTURN | AMED_EXACTPOS, 2 }, // 17 - turn on helipad1 for takeoff
+ { 24, 4, AMED_EXACTPOS, {DIR_NE} }, // 0 - At depot
+ { 24, 28, 0, {DIR_N} }, // 1 Taxi to right outside depot
+ { 5, 38, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 2 Flying
+ { -15, -15, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 3 - Circle #1 (north-east)
+ { -15, -49, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 4 - Circle #2 (north-west)
+ { 49, -49, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 5 - Circle #3 (south-west)
+ { 49, -15, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 6 - Circle #4 (south-east)
+ { 8, 32, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_NW} }, // 7 - PreHelipad
+ { 8, 32, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_NW} }, // 8 - Helipad
+ { 8, 16, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_NW} }, // 9 - Land
+ { 8, 16, AMED_HELI_LOWER, {DIR_NW} }, // 10 - Land
+ { 8, 24, AMED_HELI_RAISE, {DIR_N} }, // 11 - Take off (play sound)
+ { 32, 24, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_NW} }, // 12 Air to above hangar area
+ { 32, 24, AMED_HELI_LOWER, {DIR_NW} }, // 13 Taxi to right outside depot
+ { 8, 24, AMED_EXACTPOS, {DIR_NW} }, // 14 - on helipad1
+ { 24, 28, AMED_HELI_RAISE, {DIR_N} }, // 15 Takeoff right outside depot
+ { 8, 24, AMED_HELI_RAISE, {DIR_SW} }, // 16 - Take off (play sound)
+ { 8, 24, AMED_SLOWTURN | AMED_EXACTPOS, {DIR_E} }, // 17 - turn on helipad1 for takeoff
};
// HeliDepot 2x2 (heliport)
static const AirportMovingData _airport_moving_data_helistation[33] = {
- { 8, 3, AMED_EXACTPOS, 3 }, // 00 In Hangar2
- { 8, 22, 0, 0 }, // 01 outside hangar 2
- { 116, 24, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 02 Fly to landing position in air
- { 14, 22, AMED_HELI_RAISE, 0 }, // 03 Helitakeoff outside hangar1(play sound)
- { 24, 22, 0, 0 }, // 04 taxiing
- { 40, 22, 0, 0 }, // 05 taxiing
- { 40, 8, AMED_EXACTPOS, 1 }, // 06 Helipad 1
- { 56, 8, AMED_EXACTPOS, 1 }, // 07 Helipad 2
- { 56, 24, AMED_EXACTPOS, 1 }, // 08 Helipad 3
- { 40, 8, AMED_EXACTPOS, 0 }, // 09 pre-helitakeoff helipad 1
- { 56, 8, AMED_EXACTPOS, 0 }, // 10 pre-helitakeoff helipad 2
- { 56, 24, AMED_EXACTPOS, 0 }, // 11 pre-helitakeoff helipad 3
- { 32, 8, AMED_HELI_RAISE, 0 }, // 12 Takeoff Helipad1
- { 48, 8, AMED_HELI_RAISE, 0 }, // 13 Takeoff Helipad2
- { 48, 24, AMED_HELI_RAISE, 0 }, // 14 Takeoff Helipad3
- { 84, 24, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 15 Bufferspace before helipad
- { 68, 24, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 16 Bufferspace before helipad
- { 32, 8, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 17 Get in position for Helipad1
- { 48, 8, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 18 Get in position for Helipad2
- { 48, 24, AMED_NOSPDCLAMP | AMED_SLOWTURN, 1 }, // 19 Get in position for Helipad3
- { 40, 8, AMED_HELI_LOWER, 0 }, // 20 Land at Helipad1
- { 48, 8, AMED_HELI_LOWER, 0 }, // 21 Land at Helipad2
- { 48, 24, AMED_HELI_LOWER, 0 }, // 22 Land at Helipad3
- { 0, 22, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 23 Go to position for Hangarentrance in air
- { 0, 22, AMED_HELI_LOWER, 0 }, // 24 Land in front of hangar
- { 148, -8, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 25 Fly around waiting for a landing spot (south-east)
- { 148, 8, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 26 Fly around waiting for a landing spot (south-west)
- { 132, 24, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 27 Fly around waiting for a landing spot (south-west)
- { 100, 24, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 28 Fly around waiting for a landing spot (north-east)
- { 84, 8, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 29 Fly around waiting for a landing spot (south-east)
- { 84, -8, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 30 Fly around waiting for a landing spot (south-west)
- { 100, -24, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 31 Fly around waiting for a landing spot (north-west)
- { 132, -24, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 32 Fly around waiting for a landing spot (north-east)
+ { 8, 3, AMED_EXACTPOS, {DIR_SE} }, // 00 In Hangar2
+ { 8, 22, 0, {DIR_N} }, // 01 outside hangar 2
+ { 116, 24, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 02 Fly to landing position in air
+ { 14, 22, AMED_HELI_RAISE, {DIR_N} }, // 03 Helitakeoff outside hangar1(play sound)
+ { 24, 22, 0, {DIR_N} }, // 04 taxiing
+ { 40, 22, 0, {DIR_N} }, // 05 taxiing
+ { 40, 8, AMED_EXACTPOS, {DIR_NE} }, // 06 Helipad 1
+ { 56, 8, AMED_EXACTPOS, {DIR_NE} }, // 07 Helipad 2
+ { 56, 24, AMED_EXACTPOS, {DIR_NE} }, // 08 Helipad 3
+ { 40, 8, AMED_EXACTPOS, {DIR_N} }, // 09 pre-helitakeoff helipad 1
+ { 56, 8, AMED_EXACTPOS, {DIR_N} }, // 10 pre-helitakeoff helipad 2
+ { 56, 24, AMED_EXACTPOS, {DIR_N} }, // 11 pre-helitakeoff helipad 3
+ { 32, 8, AMED_HELI_RAISE, {DIR_N} }, // 12 Takeoff Helipad1
+ { 48, 8, AMED_HELI_RAISE, {DIR_N} }, // 13 Takeoff Helipad2
+ { 48, 24, AMED_HELI_RAISE, {DIR_N} }, // 14 Takeoff Helipad3
+ { 84, 24, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 15 Bufferspace before helipad
+ { 68, 24, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 16 Bufferspace before helipad
+ { 32, 8, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 17 Get in position for Helipad1
+ { 48, 8, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 18 Get in position for Helipad2
+ { 48, 24, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_NE} }, // 19 Get in position for Helipad3
+ { 40, 8, AMED_HELI_LOWER, {DIR_N} }, // 20 Land at Helipad1
+ { 48, 8, AMED_HELI_LOWER, {DIR_N} }, // 21 Land at Helipad2
+ { 48, 24, AMED_HELI_LOWER, {DIR_N} }, // 22 Land at Helipad3
+ { 0, 22, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 23 Go to position for Hangarentrance in air
+ { 0, 22, AMED_HELI_LOWER, {DIR_N} }, // 24 Land in front of hangar
+ { 148, -8, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 25 Fly around waiting for a landing spot (south-east)
+ { 148, 8, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 26 Fly around waiting for a landing spot (south-west)
+ { 132, 24, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 27 Fly around waiting for a landing spot (south-west)
+ { 100, 24, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 28 Fly around waiting for a landing spot (north-east)
+ { 84, 8, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 29 Fly around waiting for a landing spot (south-east)
+ { 84, -8, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 30 Fly around waiting for a landing spot (south-west)
+ { 100, -24, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 31 Fly around waiting for a landing spot (north-west)
+ { 132, -24, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 32 Fly around waiting for a landing spot (north-east)
};
// Oilrig
static const AirportMovingData _airport_moving_data_oilrig[9] = {
- { 31, 9, AMED_EXACTPOS, 1 }, // 0 - At oilrig terminal
- { 28, 9, AMED_HELI_RAISE, 0 }, // 1 - Take off (play sound)
- { 23, 9, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 2 - In position above landing spot helicopter
- { 23, 9, AMED_HELI_LOWER, 0 }, // 3 - Land
- { 28, 9, 0, 0 }, // 4 - Goto terminal on ground
- { -31, 69, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 5 - circle #1 (north-east)
- { -31, -49, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 6 - circle #2 (north-west)
- { 69, -49, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 7 - circle #3 (south-west)
- { 70, 9, AMED_NOSPDCLAMP | AMED_SLOWTURN, 0 }, // 8 - circle #4 (south)
+ { 31, 9, AMED_EXACTPOS, {DIR_NE} }, // 0 - At oilrig terminal
+ { 28, 9, AMED_HELI_RAISE, {DIR_N} }, // 1 - Take off (play sound)
+ { 23, 9, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 2 - In position above landing spot helicopter
+ { 23, 9, AMED_HELI_LOWER, {DIR_N} }, // 3 - Land
+ { 28, 9, 0, {DIR_N} }, // 4 - Goto terminal on ground
+ { -31, 69, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 5 - circle #1 (north-east)
+ { -31, -49, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 6 - circle #2 (north-west)
+ { 69, -49, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 7 - circle #3 (south-west)
+ { 70, 9, AMED_NOSPDCLAMP | AMED_SLOWTURN, {DIR_N} }, // 8 - circle #4 (south)
};
///////////////////////////////////////////////////////////////////////
diff --git a/src/aystar.cpp b/src/aystar.cpp
index 0000d584ca..36260d4f36 100644
--- a/src/aystar.cpp
+++ b/src/aystar.cpp
@@ -19,6 +19,7 @@
#include "stdafx.h"
#include "openttd.h"
#include "aystar.h"
+#include "helpers.hpp"
int _aystar_stats_open_size;
int _aystar_stats_closed_size;
@@ -35,7 +36,8 @@ static PathNode* AyStarMain_ClosedList_IsInList(AyStar *aystar, const AyStarNode
static void AyStarMain_ClosedList_Add(AyStar *aystar, const PathNode *node)
{
// Add a node to the ClosedList
- PathNode *new_node = malloc(sizeof(*new_node));
+ PathNode *new_node;
+ MallocT(&new_node, 1);
*new_node = *node;
Hash_Set(&aystar->ClosedListHash, node->node.tile, node->node.direction, new_node);
}
@@ -66,7 +68,8 @@ static OpenListNode *AyStarMain_OpenList_Pop(AyStar *aystar)
static void AyStarMain_OpenList_Add(AyStar *aystar, PathNode *parent, const AyStarNode *node, int f, int g)
{
// Add a new Node to the OpenList
- OpenListNode *new_node = malloc(sizeof(*new_node));
+ OpenListNode *new_node;
+ MallocT(&new_node, 1);
new_node->g = g;
new_node->path.parent = parent;
new_node->path.node = *node;
diff --git a/src/aystar.h b/src/aystar.h
index 4920a37d4d..f00da20b16 100644
--- a/src/aystar.h
+++ b/src/aystar.h
@@ -30,7 +30,7 @@ enum{
typedef struct AyStarNode AyStarNode;
struct AyStarNode {
TileIndex tile;
- uint direction;
+ int direction;
uint user_data[2];
};
diff --git a/src/bmp.cpp b/src/bmp.cpp
index c2bd91270f..e9a882021f 100644
--- a/src/bmp.cpp
+++ b/src/bmp.cpp
@@ -5,6 +5,7 @@
#include "gfx.h"
#include "bmp.h"
#include "macros.h"
+#include "helpers.hpp"
void BmpInitializeBuffer(BmpBuffer *buffer, FILE *file) {
buffer->pos = -1;
@@ -328,7 +329,7 @@ bool BmpReadHeader(BmpBuffer *buffer, BmpInfo *info, BmpData *data)
}
if (info->palette_size == 0) info->palette_size = 1 << info->bpp;
- data->palette = calloc(info->palette_size, sizeof(*(data->palette)));
+ CallocT(&data->palette, info->palette_size);
if (data->palette == NULL) return false;
for (i = 0; i < info->palette_size; i++) {
@@ -350,7 +351,7 @@ bool BmpReadBitmap(BmpBuffer *buffer, BmpInfo *info, BmpData *data)
{
assert(info != NULL && data != NULL);
- data->bitmap = calloc(info->width * info->height, ((info->bpp == 24) ? 3 : 1) * sizeof(byte));
+ data->bitmap = (byte*)calloc(info->width * info->height, ((info->bpp == 24) ? 3 : 1) * sizeof(byte));
if (data->bitmap == NULL) return false;
/* Load image */
diff --git a/src/bridge_map.cpp b/src/bridge_map.cpp
index 8e2405ea34..416e603c54 100644
--- a/src/bridge_map.cpp
+++ b/src/bridge_map.cpp
@@ -40,7 +40,7 @@ TileIndex GetOtherBridgeEnd(TileIndex tile)
uint GetBridgeHeight(TileIndex t)
{
uint h;
- uint tileh = GetTileSlope(t, &h);
+ Slope tileh = GetTileSlope(t, &h);
uint f = GetBridgeFoundation(tileh, DiagDirToAxis(GetBridgeRampDirection(t)));
// one height level extra if the ramp is on a flat foundation
diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp
index b293b516cf..6c0632564a 100644
--- a/src/build_vehicle_gui.cpp
+++ b/src/build_vehicle_gui.cpp
@@ -302,6 +302,8 @@ static void GenerateBuildAircraftList(Window *w)
break;
case ALL: break;
+ default:
+ NOT_REACHED();
}
EngList_Add(&bv->eng_list, eid);
@@ -479,7 +481,7 @@ void ShowBuildVehicleWindow(TileIndex tile, byte type)
switch (type) {
case VEH_Aircraft: {
- byte acc_planes = (tile == 0) ? ALL : GetAirport(GetStationByTile(tile)->airport_type)->acc_planes;
+ AcceptPlanes acc_planes = (tile == 0) ? ALL : GetAirport(GetStationByTile(tile)->airport_type)->acc_planes;
bv->filter.acc_planes = acc_planes;
break;
}
diff --git a/src/clear_cmd.cpp b/src/clear_cmd.cpp
index 4d1a78ba97..08f5873b53 100644
--- a/src/clear_cmd.cpp
+++ b/src/clear_cmd.cpp
@@ -548,7 +548,7 @@ static void DrawTile_Clear(TileInfo *ti)
static uint GetSlopeZ_Clear(TileIndex tile, uint x, uint y)
{
uint z;
- uint tileh = GetTileSlope(tile, &z);
+ Slope tileh = GetTileSlope(tile, &z);
return z + GetPartialZ(x & 0xF, y & 0xF, tileh);
}
@@ -786,7 +786,7 @@ void InitializeClearLand(void)
_opt.snow_line = _patches.snow_line_height * TILE_HEIGHT;
}
-const TileTypeProcs _tile_type_clear_procs = {
+extern const TileTypeProcs _tile_type_clear_procs = {
DrawTile_Clear, /* draw_tile_proc */
GetSlopeZ_Clear, /* get_slope_z_proc */
ClearTile_Clear, /* clear_tile_proc */
diff --git a/src/clear_map.h b/src/clear_map.h
index 85c52a1a79..dd7a150618 100644
--- a/src/clear_map.h
+++ b/src/clear_map.h
@@ -23,7 +23,7 @@ typedef enum ClearGround {
static inline ClearGround GetClearGround(TileIndex t)
{
assert(IsTileType(t, MP_CLEAR));
- return GB(_m[t].m5, 2, 3);
+ return (ClearGround)GB(_m[t].m5, 2, 3);
}
static inline bool IsClearGround(TileIndex t, ClearGround ct)
diff --git a/src/command.cpp b/src/command.cpp
index ad93fc6430..942da930a0 100644
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -504,7 +504,7 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback,
*/
if (_networking && !(cmd & CMD_NETWORK_COMMAND)) {
PlayerID pbck = _local_player;
- if (_network_dedicated || (_network_server && pbck == PLAYER_SPECTATOR)) _local_player = 0;
+ if (_network_dedicated || (_network_server && pbck == PLAYER_SPECTATOR)) _local_player = PLAYER_FIRST;
NetworkSend_Command(tile, p1, p2, cmd, callback);
if (_network_dedicated || (_network_server && pbck == PLAYER_SPECTATOR)) _local_player = pbck;
_docommand_recursive = 0;
diff --git a/src/console.cpp b/src/console.cpp
index 07d2181306..cf192fb33a 100644
--- a/src/console.cpp
+++ b/src/console.cpp
@@ -13,6 +13,7 @@
#include
#include
#include "console.h"
+#include "helpers.hpp"
#include "network/network.h"
#include "network/network_data.h"
#include "network/network_server.h"
@@ -223,7 +224,7 @@ void IConsoleInit(void)
memset(_iconsole_history, 0, sizeof(_iconsole_history));
memset(_iconsole_buffer, 0, sizeof(_iconsole_buffer));
memset(_iconsole_cbuffer, 0, sizeof(_iconsole_cbuffer));
- _iconsole_cmdline.buf = calloc(ICON_CMDLN_SIZE, sizeof(*_iconsole_cmdline.buf)); // create buffer and zero it
+ CallocT(&_iconsole_cmdline.buf, ICON_CMDLN_SIZE); // create buffer and zero it
_iconsole_cmdline.maxlength = ICON_CMDLN_SIZE;
IConsolePrintF(13, "OpenTTD Game Console Revision 7 - %s", _openttd_revision);
@@ -612,7 +613,8 @@ void IConsoleVarHookAdd(const char *name, IConsoleHookTypes type, IConsoleHook *
void IConsoleCmdRegister(const char *name, IConsoleCmdProc *proc)
{
char *new_cmd = strdup(name);
- IConsoleCmd *item_new = malloc(sizeof(IConsoleCmd));
+ IConsoleCmd *item_new;
+ MallocT(&item_new, 1);
item_new->next = NULL;
item_new->proc = proc;
@@ -649,7 +651,8 @@ void IConsoleAliasRegister(const char *name, const char *cmd)
{
char *new_alias = strdup(name);
char *cmd_aliased = strdup(cmd);
- IConsoleAlias *item_new = malloc(sizeof(IConsoleAlias));
+ IConsoleAlias *item_new;
+ MallocT(&item_new, 1);
item_new->next = NULL;
item_new->cmdline = cmd_aliased;
@@ -784,7 +787,8 @@ void IConsoleVarStringRegister(const char *name, void *addr, uint32 size, const
void IConsoleVarRegister(const char *name, void *addr, IConsoleVarTypes type, const char *help)
{
char *new_cmd = strdup(name);
- IConsoleVar *item_new = malloc(sizeof(IConsoleVar));
+ IConsoleVar *item_new;
+ MallocT(&item_new, 1);
item_new->help = (help != NULL) ? strdup(help) : NULL;
@@ -861,7 +865,7 @@ static void IConsoleVarSetStringvalue(const IConsoleVar *var, const char *value)
if (var->type != ICONSOLE_VAR_STRING || var->addr == NULL) return;
IConsoleHookHandle(&var->hook, ICONSOLE_HOOK_PRE_ACTION);
- ttd_strlcpy(var->addr, value, var->size);
+ ttd_strlcpy((char*)var->addr, value, var->size);
IConsoleHookHandle(&var->hook, ICONSOLE_HOOK_POST_ACTION);
IConsoleVarPrintSetValue(var); // print out the new value, giving feedback
return;
diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp
index 46846af7d7..8f495e32b8 100644
--- a/src/console_cmds.cpp
+++ b/src/console_cmds.cpp
@@ -562,7 +562,7 @@ DEF_CONSOLE_CMD(ConStatus)
const NetworkClientInfo *ci = DEREF_CLIENT_INFO(cs);
const char* status;
- status = (cs->status < lengthof(stat_str) ? stat_str[cs->status] : "unknown");
+ status = (cs->status < (ptrdiff_t)lengthof(stat_str) ? stat_str[cs->status] : "unknown");
IConsolePrintF(8, "Client #%1d name: '%s' status: '%s' frame-lag: %3d company: %1d IP: %s unique-id: '%s'",
cs->index, ci->client_name, status, lag,
ci->client_playas + (IsValidPlayer(ci->client_playas) ? 1 : 0),
@@ -684,7 +684,7 @@ DEF_CONSOLE_CMD(ConResetCompany)
if (argc != 2) return false;
- index = atoi(argv[1]) - 1;
+ index = (PlayerID)(atoi(argv[1]) - 1);
/* Check valid range */
if (!IsValidPlayer(index)) {
@@ -770,7 +770,7 @@ DEF_CONSOLE_CMD(ConNetworkConnect)
IConsolePrintF(_icolour_def, "Connecting to %s...", ip);
if (player != NULL) {
- _network_playas = atoi(player);
+ _network_playas = (PlayerID)atoi(player);
IConsolePrintF(_icolour_def, " player-no: %d", _network_playas);
/* From a user pov 0 is a new player, internally it's different and all
diff --git a/src/debug.h b/src/debug.h
index c99795dddd..ff0761a8d5 100644
--- a/src/debug.h
+++ b/src/debug.h
@@ -3,6 +3,10 @@
#ifndef DEBUG_H
#define DEBUG_H
+#ifdef __cplusplus
+extern "C" {
+#endif //__cplusplus
+
/* Debugging messages policy:
* These should be the severities used for direct DEBUG() calls
* maximum debugging level should be 10 if really deep, deep
@@ -105,4 +109,8 @@ const char *GetDebugString(void);
}\
}
+#ifdef __cplusplus
+}
+#endif //__cplusplus
+
#endif /* DEBUG_H */
diff --git a/src/depot.cpp b/src/depot.cpp
index 49fdfa21cd..889d2a35c4 100644
--- a/src/depot.cpp
+++ b/src/depot.cpp
@@ -122,6 +122,6 @@ static void Load_DEPT(void)
}
}
-const ChunkHandler _depot_chunk_handlers[] = {
+extern const ChunkHandler _depot_chunk_handlers[] = {
{ 'DEPT', Save_DEPT, Load_DEPT, CH_ARRAY | CH_LAST},
};
diff --git a/src/direction.h b/src/direction.h
index 477c34046a..576d8e1bba 100644
--- a/src/direction.h
+++ b/src/direction.h
@@ -3,8 +3,11 @@
#ifndef DIRECTION_H
#define DIRECTION_H
+#include "helpers.hpp"
+
/* Direction as commonly used in v->direction, 8 way. */
typedef enum Direction {
+ DIR_BEGIN = 0,
DIR_N = 0,
DIR_NE = 1, /* Northeast, upper right on your monitor */
DIR_E = 2,
@@ -17,6 +20,10 @@ typedef enum Direction {
INVALID_DIR = 0xFF,
} Direction;
+/** Define basic enum properties */
+template <> struct EnumPropsT : MakeEnumPropsT {};
+typedef TinyEnumT DirectionByte;
+
static inline Direction ReverseDir(Direction d)
{
return (Direction)(4 ^ d);
@@ -51,6 +58,7 @@ static inline Direction ChangeDir(Direction d, DirDiff delta)
/* Direction commonly used as the direction of entering and leaving tiles, 4-way */
typedef enum DiagDirection {
+ DIAGDIR_BEGIN = 0,
DIAGDIR_NE = 0, /* Northeast, upper right on your monitor */
DIAGDIR_SE = 1,
DIAGDIR_SW = 2,
@@ -59,6 +67,12 @@ typedef enum DiagDirection {
INVALID_DIAGDIR = 0xFF,
} DiagDirection;
+DECLARE_POSTFIX_INCREMENT(DiagDirection);
+
+/** Define basic enum properties */
+template <> struct EnumPropsT : MakeEnumPropsT {};
+typedef TinyEnumT DiagDirectionByte;
+
static inline DiagDirection ReverseDiagDir(DiagDirection d)
{
return (DiagDirection)(2 ^ d);
diff --git a/src/disaster_cmd.cpp b/src/disaster_cmd.cpp
index 2d4579b525..f018149f2e 100644
--- a/src/disaster_cmd.cpp
+++ b/src/disaster_cmd.cpp
@@ -276,7 +276,7 @@ static void DisasterTick_UFO(Vehicle *v)
// fly around randomly
int x = TileX(v->dest_tile) * TILE_SIZE;
int y = TileY(v->dest_tile) * TILE_SIZE;
- if (abs(x - v->x_pos) + abs(y - v->y_pos) >= TILE_SIZE) {
+ if (delta(x, v->x_pos) + delta(y, v->y_pos) >= TILE_SIZE) {
v->direction = GetDirectionTowards(v, x, y);
GetNewVehiclePos(v, &gp);
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
@@ -305,7 +305,7 @@ static void DisasterTick_UFO(Vehicle *v)
return;
}
- dist = abs(v->x_pos - u->x_pos) + abs(v->y_pos - u->y_pos);
+ dist = delta(v->x_pos, u->x_pos) + delta(v->y_pos, u->y_pos);
if (dist < TILE_SIZE && !(u->vehstatus&VS_HIDDEN) && u->breakdown_ctr==0) {
u->breakdown_ctr = 3;
@@ -526,7 +526,7 @@ static void DisasterTick_4(Vehicle *v)
if (v->current_order.dest == 1) {
int x = TileX(v->dest_tile) * TILE_SIZE + TILE_SIZE / 2;
int y = TileY(v->dest_tile) * TILE_SIZE + TILE_SIZE / 2;
- if (abs(v->x_pos - x) + abs(v->y_pos - y) >= 8) {
+ if (delta(v->x_pos, x) + delta(v->y_pos, y) >= 8) {
v->direction = GetDirectionTowards(v, x, y);
GetNewVehiclePos(v, &gp);
@@ -544,7 +544,7 @@ static void DisasterTick_4(Vehicle *v)
FOR_ALL_VEHICLES(u) {
if (u->type == VEH_Train || u->type == VEH_Road) {
- if (abs(u->x_pos - v->x_pos) + abs(u->y_pos - v->y_pos) <= 12 * TILE_SIZE) {
+ if (delta(u->x_pos, v->x_pos) + delta(u->y_pos, v->y_pos) <= 12 * TILE_SIZE) {
u->breakdown_ctr = 5;
u->breakdown_delay = 0xF0;
}
@@ -578,7 +578,7 @@ static void DisasterTick_4(Vehicle *v)
int x = TileX(v->dest_tile) * TILE_SIZE;
int y = TileY(v->dest_tile) * TILE_SIZE;
- if (abs(x - v->x_pos) + abs(y - v->y_pos) >= TILE_SIZE) {
+ if (delta(x, v->x_pos) + delta(y, v->y_pos) >= TILE_SIZE) {
v->direction = GetDirectionTowards(v, x, y);
GetNewVehiclePos(v, &gp);
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
@@ -626,7 +626,7 @@ static void DisasterTick_4b(Vehicle *v)
if (v->current_order.dest == 0) {
u = GetVehicle(v->u.disaster.unk2);
- if (abs(v->x_pos - u->x_pos) > TILE_SIZE)
+ if (delta(v->x_pos, u->x_pos) > TILE_SIZE)
return;
v->current_order.dest = 1;
diff --git a/src/dock_gui.cpp b/src/dock_gui.cpp
index 8e550e9ece..89137396d9 100644
--- a/src/dock_gui.cpp
+++ b/src/dock_gui.cpp
@@ -254,7 +254,7 @@ static void BuildDockStationWndProc(Window *w, WindowEvent *e)
case 3:
case 4:
RaiseWindowWidget(w, _station_show_coverage + 3);
- _station_show_coverage = e->we.click.widget - 3;
+ _station_show_coverage = (e->we.click.widget != 3);
LowerWindowWidget(w, _station_show_coverage + 3);
SndPlayFx(SND_15_BEEP);
SetWindowDirty(w);
@@ -328,7 +328,7 @@ static void BuildDocksDepotWndProc(Window *w, WindowEvent *e)
case 3:
case 4:
RaiseWindowWidget(w, _ship_depot_direction + 3);
- _ship_depot_direction = e->we.click.widget - 3;
+ _ship_depot_direction = (e->we.click.widget == 3 ? AXIS_X : AXIS_Y);
LowerWindowWidget(w, _ship_depot_direction + 3);
SndPlayFx(SND_15_BEEP);
UpdateDocksDirection();
diff --git a/src/dummy_land.cpp b/src/dummy_land.cpp
index 10952fc00e..aa9a72d996 100644
--- a/src/dummy_land.cpp
+++ b/src/dummy_land.cpp
@@ -66,7 +66,7 @@ static uint32 GetTileTrackStatus_Dummy(TileIndex tile, TransportType mode)
return 0;
}
-const TileTypeProcs _tile_type_dummy_procs = {
+extern const TileTypeProcs _tile_type_dummy_procs = {
DrawTile_Dummy, /* draw_tile_proc */
GetSlopeZ_Dummy, /* get_slope_z_proc */
ClearTile_Dummy, /* clear_tile_proc */
diff --git a/src/economy.cpp b/src/economy.cpp
index a325a863c9..402fc9cec9 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -47,7 +47,7 @@ const ScoreInfo _score_info[] = {
{ SCORE_TOTAL, 0, 0 }
};
-int _score_part[MAX_PLAYERS][NUM_SCORE];
+int _score_part[MAX_PLAYERS][SCORE_END];
int64 CalculateCompanyValue(const Player* p)
{
@@ -209,11 +209,10 @@ int UpdateCompanyRatingAndValue(Player *p, bool update)
// Now we calculate the score for each item..
{
- int i;
int total_score = 0;
int s;
score = 0;
- for (i = 0; i < NUM_SCORE; i++) {
+ for (ScoreID i = SCORE_BEGIN; i < SCORE_END; i++) {
// Skip the total
if (i == SCORE_TOTAL) continue;
// Check the score
@@ -467,7 +466,7 @@ void DrawNewsBankrupcy(Window *w)
DrawNewsBorder(w);
- p = GetPlayer(GB(WP(w,news_d).ni->string_id, 0, 4));
+ p = GetPlayer((PlayerID)GB(WP(w,news_d).ni->string_id, 0, 4));
DrawPlayerFace(p->face, p->player_color, 2, 23);
GfxFillRect(3, 23, 3+91, 23+118, 0x323 | USE_COLORTABLE);
@@ -536,7 +535,7 @@ void DrawNewsBankrupcy(Window *w)
StringID GetNewsStringBankrupcy(const NewsItem *ni)
{
- const Player *p = GetPlayer(GB(ni->string_id, 0, 4));
+ const Player *p = GetPlayer((PlayerID)GB(ni->string_id, 0, 4));
switch (ni->string_id & 0xF0) {
case NB_BTROUBLE:
@@ -1562,7 +1561,7 @@ void PlayersMonthlyLoop(void)
static void DoAcquireCompany(Player *p)
{
Player *owner;
- int i,pi;
+ int i;
int64 value;
SetDParam(0, p->name_1);
@@ -1571,7 +1570,7 @@ static void DoAcquireCompany(Player *p)
AddNewsItem( (StringID)(_current_player | NB_BMERGER), NEWS_FLAGS(NM_CALLBACK, 0, NT_COMPANY_INFO, DNC_BANKRUPCY),0,0);
// original code does this a little bit differently
- pi = p->index;
+ PlayerID pi = p->index;
ChangeOwnershipOfPlayerItems(pi, _current_player);
if (p->bankrupt_value == 0) {
@@ -1595,7 +1594,7 @@ static void DoAcquireCompany(Player *p)
RebuildVehicleLists(); //Updates the open windows to add the newly acquired vehicles to the lists
}
-extern int GetAmountOwnedBy(Player *p, byte owner);
+extern int GetAmountOwnedBy(const Player *p, PlayerID owner);
/** Acquire shares in an opposing company.
* @param tile unused
@@ -1611,7 +1610,7 @@ int32 CmdBuyShareInCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
if (!IsValidPlayer((PlayerID)p1) || !_patches.allow_shares) return CMD_ERROR;
SET_EXPENSES_TYPE(EXPENSES_OTHER);
- p = GetPlayer(p1);
+ p = GetPlayer((PlayerID)p1);
/* Protect new companies from hostile takeovers */
if (_cur_year - p->inaugurated_year < 6) return_cmd_error(STR_7080_PROTECTED);
@@ -1624,7 +1623,7 @@ int32 CmdBuyShareInCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
cost = CalculateCompanyValue(p) >> 2;
if (flags & DC_EXEC) {
- PlayerID* b = p->share_owners;
+ PlayerByte* b = p->share_owners;
int i;
while (*b != PLAYER_SPECTATOR) b++; /* share owners is guaranteed to contain at least one PLAYER_SPECTATOR */
@@ -1656,7 +1655,7 @@ int32 CmdSellShareInCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
if (!IsValidPlayer((PlayerID)p1) || !_patches.allow_shares) return CMD_ERROR;
SET_EXPENSES_TYPE(EXPENSES_OTHER);
- p = GetPlayer(p1);
+ p = GetPlayer((PlayerID)p1);
/* Those lines are here for network-protection (clients can be slow) */
if (GetAmountOwnedBy(p, _current_player) == 0) return 0;
@@ -1666,7 +1665,7 @@ int32 CmdSellShareInCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
cost = -(cost - (cost >> 7));
if (flags & DC_EXEC) {
- PlayerID* b = p->share_owners;
+ PlayerByte* b = p->share_owners;
while (*b != _current_player) b++; /* share owners is guaranteed to contain player */
*b = PLAYER_SPECTATOR;
InvalidateWindow(WC_COMPANY, p1);
@@ -1690,7 +1689,7 @@ int32 CmdBuyCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
if (!IsValidPlayer((PlayerID)p1) || _networking) return CMD_ERROR;
SET_EXPENSES_TYPE(EXPENSES_OTHER);
- p = GetPlayer(p1);
+ p = GetPlayer((PlayerID)p1);
if (!p->is_ai) return CMD_ERROR;
@@ -1730,7 +1729,7 @@ static void SaveLoad_ECMY(void)
SlObject(&_economy, _economy_desc);
}
-const ChunkHandler _economy_chunk_handlers[] = {
+extern const ChunkHandler _economy_chunk_handlers[] = {
{ 'PRIC', SaveLoad_PRIC, SaveLoad_PRIC, CH_RIFF | CH_AUTO_LENGTH},
{ 'CAPR', SaveLoad_CAPR, SaveLoad_CAPR, CH_RIFF | CH_AUTO_LENGTH},
{ 'SUBS', Save_SUBS, Load_SUBS, CH_ARRAY},
diff --git a/src/economy.h b/src/economy.h
index 823e167c88..7737eefd91 100644
--- a/src/economy.h
+++ b/src/economy.h
@@ -29,7 +29,8 @@ typedef struct Subsidy {
} Subsidy;
-enum {
+enum ScoreID {
+ SCORE_BEGIN = 0,
SCORE_VEHICLES = 0,
SCORE_STATIONS = 1,
SCORE_MIN_PROFIT = 2,
@@ -40,13 +41,14 @@ enum {
SCORE_MONEY = 7,
SCORE_LOAN = 8,
SCORE_TOTAL = 9, // This must always be the last entry
-
- NUM_SCORE = 10, // How many scores are there..
+ SCORE_END = 10, // How many scores are there..
SCORE_MAX = 1000 // The max score that can be in the performance history
// the scores together of score_info is allowed to be more!
};
+DECLARE_POSTFIX_INCREMENT(ScoreID);
+
typedef struct ScoreInfo {
byte id; // Unique ID of the score
int needed; // How much you need to get the perfect score
@@ -54,7 +56,7 @@ typedef struct ScoreInfo {
} ScoreInfo;
extern const ScoreInfo _score_info[];
-extern int _score_part[MAX_PLAYERS][NUM_SCORE];
+extern int _score_part[MAX_PLAYERS][SCORE_END];
int UpdateCompanyRatingAndValue(Player *p, bool update);
diff --git a/src/elrail.cpp b/src/elrail.cpp
index da043b5828..97d4b15502 100644
--- a/src/elrail.cpp
+++ b/src/elrail.cpp
@@ -67,7 +67,7 @@
static inline TLG GetTLG(TileIndex t)
{
- return (HASBIT(TileX(t), 0) << 1) + HASBIT(TileY(t), 0);
+ return (TLG)((HASBIT(TileX(t), 0) << 1) + HASBIT(TileY(t), 0));
}
/** Finds which Rail Bits are present on a given tile. For bridge tiles,
@@ -77,24 +77,24 @@ static TrackBits GetRailTrackBitsUniversal(TileIndex t, byte *override)
{
switch (GetTileType(t)) {
case MP_RAILWAY:
- if (GetRailType(t) != RAILTYPE_ELECTRIC) return 0;
+ if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE;
switch (GetRailTileType(t)) {
case RAIL_TILE_NORMAL: case RAIL_TILE_SIGNALS:
return GetTrackBits(t);
case RAIL_TILE_DEPOT_WAYPOINT:
if (GetRailTileSubtype(t) == RAIL_SUBTYPE_WAYPOINT) return GetRailWaypointBits(t);
default:
- return 0;
+ return TRACK_BIT_NONE;
}
break;
case MP_TUNNELBRIDGE:
if (IsTunnel(t)) {
- if (GetRailType(t) != RAILTYPE_ELECTRIC) return 0;
+ if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE;
if (override != NULL) *override = 1 << GetTunnelDirection(t);
return AxisToTrackBits(DiagDirToAxis(GetTunnelDirection(t)));
} else {
- if (GetRailType(t) != RAILTYPE_ELECTRIC) return 0;
+ if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE;
if (override != NULL && DistanceMax(t, GetOtherBridgeEnd(t)) > 1) {
*override = 1 << GetBridgeRampDirection(t);
}
@@ -102,18 +102,18 @@ static TrackBits GetRailTrackBitsUniversal(TileIndex t, byte *override)
}
case MP_STREET:
- if (GetRoadTileType(t) != ROAD_TILE_CROSSING) return 0;
- if (GetRailTypeCrossing(t) != RAILTYPE_ELECTRIC) return 0;
+ if (GetRoadTileType(t) != ROAD_TILE_CROSSING) return TRACK_BIT_NONE;
+ if (GetRailTypeCrossing(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE;
return GetCrossingRailBits(t);
case MP_STATION:
- if (!IsRailwayStation(t)) return 0;
- if (GetRailType(t) != RAILTYPE_ELECTRIC) return 0;
- if (!IsStationTileElectrifiable(t)) return 0;
+ if (!IsRailwayStation(t)) return TRACK_BIT_NONE;
+ if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE;
+ if (!IsStationTileElectrifiable(t)) return TRACK_BIT_NONE;
return TrackToTrackBits(GetRailStationTrack(t));
default:
- return 0;
+ return TRACK_BIT_NONE;
}
}
@@ -171,7 +171,7 @@ static void DrawCatenaryRailway(const TileInfo *ti)
* which have no middle tiles */
trackconfig[TS_HOME] = GetRailTrackBitsUniversal(ti->tile, &OverridePCP);
/* If a track bit is present that is not in the main direction, the track is level */
- isflat[TS_HOME] = trackconfig[TS_HOME] & (TRACK_BIT_HORZ | TRACK_BIT_VERT);
+ isflat[TS_HOME] = ((trackconfig[TS_HOME] & (TRACK_BIT_HORZ | TRACK_BIT_VERT)) != 0);
AdjustTileh(ti->tile, &tileh[TS_HOME]);
@@ -184,8 +184,8 @@ static void DrawCatenaryRailway(const TileInfo *ti)
* existing foundataions, so we do have to do that manually later on.*/
tileh[TS_NEIGHBOUR] = GetTileSlope(neighbour, NULL);
trackconfig[TS_NEIGHBOUR] = GetRailTrackBitsUniversal(neighbour, NULL);
- if (IsTunnelTile(neighbour) && i != GetTunnelDirection(neighbour)) trackconfig[TS_NEIGHBOUR] = 0;
- isflat[TS_NEIGHBOUR] = trackconfig[TS_NEIGHBOUR] & (TRACK_BIT_HORZ | TRACK_BIT_VERT);
+ if (IsTunnelTile(neighbour) && i != GetTunnelDirection(neighbour)) trackconfig[TS_NEIGHBOUR] = TRACK_BIT_NONE;
+ isflat[TS_NEIGHBOUR] = ((trackconfig[TS_NEIGHBOUR] & (TRACK_BIT_HORZ | TRACK_BIT_VERT)) != 0);
PPPpreferred[i] = 0xFF; /* We start with preferring everything (end-of-line in any direction) */
PPPallowed[i] = AllowedPPPonPCP[i];
@@ -289,7 +289,7 @@ static void DrawCatenaryRailway(const TileInfo *ti)
}
/* Drawing of pylons is finished, now draw the wires */
- for (t = 0; t < TRACK_END; t++) {
+ for (t = TRACK_BEGIN; t < TRACK_END; t++) {
if (HASBIT(trackconfig[TS_HOME], t)) {
byte PCPconfig = HASBIT(PCPstatus, PCPpositions[t][0]) +
@@ -321,7 +321,7 @@ static void DrawCatenaryOnBridge(const TileInfo *ti)
Axis axis = GetBridgeAxis(ti->tile);
TLG tlg = GetTLG(ti->tile);
- CatenarySprite offset = axis == AXIS_X ? 0 : WIRE_Y_FLAT_BOTH - WIRE_X_FLAT_BOTH;
+ CatenarySprite offset = (CatenarySprite)(axis == AXIS_X ? 0 : WIRE_Y_FLAT_BOTH - WIRE_X_FLAT_BOTH);
if ((length % 2) && num == length) {
/* Draw the "short" wire on the southern end of the bridge
diff --git a/src/endian_check.cpp b/src/endian_check.cpp
index a302ea40bd..97773496f2 100644
--- a/src/endian_check.cpp
+++ b/src/endian_check.cpp
@@ -1,6 +1,7 @@
/* $Id$ */
#include
+#include
// This pretty simple file checks if the system is LITTLE_ENDIAN or BIG_ENDIAN
// it does that by putting a 1 and a 0 in an array, and read it out as one
diff --git a/src/engine.cpp b/src/engine.cpp
index 0a4b21c3dc..8c3779dc5c 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -129,7 +129,7 @@ void StartupEngines(void)
uint32 r;
e->age = 0;
- e->railtype = ei->railtype;
+ e->railtype = (RailType)ei->railtype;
e->flags = 0;
e->player_avail = 0;
@@ -189,7 +189,7 @@ static void AcceptEnginePreview(Engine *e, PlayerID player)
SETBIT(e->player_avail, player);
SETBIT(p->avail_railtypes, e->railtype);
- e->preview_player = 0xFF;
+ e->preview_player = INVALID_PLAYER;
if (player == _local_player) {
InvalidateWindowClassesData(WC_BUILD_VEHICLE);
InvalidateWindowClasses(WC_REPLACE_VEHICLE);
@@ -217,7 +217,7 @@ static PlayerID GetBestPlayer(PlayerID pp)
if (best_player == PLAYER_SPECTATOR) return PLAYER_SPECTATOR;
SETBIT(mask, best_player);
- } while (--pp != 0);
+ } while (pp--, pp != 0);
return best_player;
}
@@ -242,7 +242,7 @@ void EnginesDailyLoop(void)
PlayerID best_player = GetBestPlayer(e->preview_player);
if (best_player == PLAYER_SPECTATOR) {
- e->preview_player = 0xFF;
+ e->preview_player = INVALID_PLAYER;
continue;
}
@@ -364,7 +364,7 @@ void EnginesMonthlyLoop(void)
// Do not introduce new rail wagons
if (!IsWagon(e - _engines))
- e->preview_player = 1; // Give to the player with the highest rating.
+ e->preview_player = (PlayerID)1; // Give to the player with the highest rating.
}
}
}
@@ -636,7 +636,7 @@ static void LoadSave_ENGS(void)
SlArray(_engine_name_strings, lengthof(_engine_name_strings), SLE_STRINGID);
}
-const ChunkHandler _engine_chunk_handlers[] = {
+extern const ChunkHandler _engine_chunk_handlers[] = {
{ 'ENGN', Save_ENGN, Load_ENGN, CH_ARRAY },
{ 'ENGS', LoadSave_ENGS, LoadSave_ENGS, CH_RIFF },
{ 'ERNW', Save_ERNW, Load_ERNW, CH_ARRAY | CH_LAST},
diff --git a/src/engine.h b/src/engine.h
index 2fa6b9eb0b..c2dca0b9be 100644
--- a/src/engine.h
+++ b/src/engine.h
@@ -6,6 +6,8 @@
/** @file engine.h */
#include "oldpool.h"
+#include "rail.h"
+#include "sound.h"
typedef struct RailVehicleInfo {
byte image_index;
@@ -38,8 +40,8 @@ typedef struct ShipVehicleInfo {
CargoID cargo_type;
uint16 capacity;
byte running_cost;
- byte sfx;
- byte refittable;
+ SoundFxByte sfx;
+ bool refittable;
} ShipVehicleInfo;
// Aircraft subtypes
@@ -53,7 +55,7 @@ typedef struct AircraftVehicleInfo {
byte base_cost;
byte running_cost;
byte subtype;
- byte sfx;
+ SoundFxByte sfx;
byte acceleration;
byte max_speed;
byte mail_capacity;
@@ -64,7 +66,7 @@ typedef struct RoadVehicleInfo {
byte image_index;
byte base_cost;
byte running_cost;
- byte sfx;
+ SoundFxByte sfx;
byte max_speed;
byte capacity;
CargoID cargo_type;
@@ -96,9 +98,9 @@ typedef struct Engine {
uint16 duration_phase_1, duration_phase_2, duration_phase_3;
byte lifelength;
byte flags;
- byte preview_player;
+ PlayerByte preview_player;
byte preview_wait;
- byte railtype;
+ RailTypeByte railtype;
byte player_avail;
byte type; // type, ie VEH_Road, VEH_Train, etc. Same as in vehicle.h
} Engine;
@@ -122,9 +124,8 @@ enum {
NUM_VEHICLE_TYPES = 6
};
-enum {
- INVALID_ENGINE = 0xFFFF,
-};
+static const EngineID INVALID_ENGINE = 0xFFFF;
+
void AddTypeToEngines(void);
void StartupEngines(void);
diff --git a/src/engine_gui.cpp b/src/engine_gui.cpp
index 31f175cf14..91db313f61 100644
--- a/src/engine_gui.cpp
+++ b/src/engine_gui.cpp
@@ -24,6 +24,7 @@ static StringID GetEngineCategoryName(EngineID engine)
case RAILTYPE_ELECTRIC: return STR_8102_RAILROAD_LOCOMOTIVE;
case RAILTYPE_MONO: return STR_8106_MONORAIL_LOCOMOTIVE;
case RAILTYPE_MAGLEV: return STR_8107_MAGLEV_LOCOMOTIVE;
+ default: NOT_REACHED();
}
}
diff --git a/src/fios.cpp b/src/fios.cpp
index 950e26a23e..87e7ea93de 100644
--- a/src/fios.cpp
+++ b/src/fios.cpp
@@ -11,6 +11,7 @@
#include "variables.h"
#include "functions.h"
#include "heightmap.h"
+#include "helpers.hpp"
#include "table/strings.h"
#include "fios.h"
#include
@@ -47,7 +48,7 @@ FiosItem *FiosAlloc(void)
{
if (_fios_count == _fios_alloc) {
_fios_alloc += 256;
- _fios_items = realloc(_fios_items, _fios_alloc * sizeof(FiosItem));
+ ReallocT(&_fios_items, _fios_alloc);
}
return &_fios_items[_fios_count++];
}
@@ -323,7 +324,7 @@ FiosItem *FiosGetSavegameList(int mode)
static char *_fios_save_path = NULL;
if (_fios_save_path == NULL) {
- _fios_save_path = malloc(MAX_PATH);
+ MallocT(&_fios_save_path, MAX_PATH);
ttd_strlcpy(_fios_save_path, _paths.save_dir, MAX_PATH);
}
@@ -371,7 +372,7 @@ FiosItem *FiosGetScenarioList(int mode)
static char *_fios_scn_path = NULL;
if (_fios_scn_path == NULL) {
- _fios_scn_path = malloc(MAX_PATH);
+ MallocT(&_fios_scn_path, MAX_PATH);
ttd_strlcpy(_fios_scn_path, _paths.scenario_dir, MAX_PATH);
}
@@ -402,7 +403,7 @@ FiosItem *FiosGetHeightmapList(int mode)
static char *_fios_hmap_path = NULL;
if (_fios_hmap_path == NULL) {
- _fios_hmap_path = malloc(MAX_PATH);
+ MallocT(&_fios_hmap_path, MAX_PATH);
strcpy(_fios_hmap_path, _paths.heightmap_dir);
}
diff --git a/src/fontcache.cpp b/src/fontcache.cpp
index d555eea94a..e60fe8bc70 100644
--- a/src/fontcache.cpp
+++ b/src/fontcache.cpp
@@ -11,6 +11,7 @@
#include "gfx.h"
#include "string.h"
#include "fontcache.h"
+#include "helpers.hpp"
#ifdef WITH_FREETYPE
@@ -77,7 +78,7 @@ static FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
* normal char to match the data returned by RegEnumValue,
* otherwise just use parameter */
#if defined(UNICODE)
- font_namep = malloc(MAX_PATH * sizeof(TCHAR));
+ MallocT(&font_namep, MAX_PATH);
MB_TO_WIDE_BUFFER(font_name, font_namep, MAX_PATH * sizeof(TCHAR));
#else
font_namep = (char*)font_name; // only cast because in unicode pointer is not const
@@ -345,12 +346,12 @@ static void SetGlyphPtr(FontSize size, WChar key, const GlyphEntry *glyph)
{
if (_glyph_ptr[size] == NULL) {
DEBUG(freetype, 3, "Allocating root glyph cache for size %u", size);
- _glyph_ptr[size] = calloc(256, sizeof(**_glyph_ptr));
+ CallocT(&_glyph_ptr[size], 256);
}
if (_glyph_ptr[size][GB(key, 8, 8)] == NULL) {
DEBUG(freetype, 3, "Allocating glyph cache for range 0x%02X00, size %u", GB(key, 8, 8), size);
- _glyph_ptr[size][GB(key, 8, 8)] = calloc(256, sizeof(***_glyph_ptr));
+ CallocT(&_glyph_ptr[size][GB(key, 8, 8)], 256);
}
DEBUG(freetype, 4, "Set glyph for unicode character 0x%04X, size %u", key, size);
@@ -395,7 +396,7 @@ const Sprite *GetGlyph(FontSize size, WChar key)
height = max(1, slot->bitmap.rows + (size == FS_NORMAL));
/* FreeType has rendered the glyph, now we allocate a sprite and copy the image into it */
- sprite = calloc(width * height + 8, 1);
+ sprite = (Sprite*)calloc(width * height + 8, 1);
sprite->info = 1;
sprite->width = width;
sprite->height = height;
@@ -483,8 +484,8 @@ SpriteID GetUnicodeGlyph(FontSize size, uint32 key)
void SetUnicodeGlyph(FontSize size, uint32 key, SpriteID sprite)
{
- if (_unicode_glyph_map[size] == NULL) _unicode_glyph_map[size] = calloc(256, sizeof(*_unicode_glyph_map[size]));
- if (_unicode_glyph_map[size][GB(key, 8, 8)] == NULL) _unicode_glyph_map[size][GB(key, 8, 8)] = calloc(256, sizeof(**_unicode_glyph_map[size]));
+ if (_unicode_glyph_map[size] == NULL) CallocT(&_unicode_glyph_map[size], 256);
+ if (_unicode_glyph_map[size][GB(key, 8, 8)] == NULL) CallocT(&_unicode_glyph_map[size][GB(key, 8, 8)], 256);
_unicode_glyph_map[size][GB(key, 8, 8)][GB(key, 0, 8)] = sprite;
}
diff --git a/src/functions.h b/src/functions.h
index 12490b10d5..bba59f5ea5 100644
--- a/src/functions.h
+++ b/src/functions.h
@@ -10,7 +10,7 @@ uint GetPartialZ(int x, int y, Slope corners);
uint GetSlopeZ(int x, int y);
uint32 GetTileTrackStatus(TileIndex tile, TransportType mode);
void GetAcceptedCargo(TileIndex tile, AcceptedCargo ac);
-void ChangeTileOwner(TileIndex tile, byte old_player, byte new_player);
+void ChangeTileOwner(TileIndex tile, PlayerID old_player, PlayerID new_player);
void AnimateTile(TileIndex tile);
void ClickTile(TileIndex tile);
void GetTileDesc(TileIndex tile, TileDesc *td);
@@ -217,5 +217,4 @@ void HandleExitGameRequest(void);
void DeterminePaths(void);
-void CSleep(int milliseconds);
#endif /* FUNCTIONS_H */
diff --git a/src/genworld.cpp b/src/genworld.cpp
index ba9fe126f5..eef47eaeda 100644
--- a/src/genworld.cpp
+++ b/src/genworld.cpp
@@ -182,7 +182,7 @@ void WaitTillGeneratedWorld(void)
{
if (_gw.thread == NULL) return;
_gw.quit_thread = true;
- OTTDJoinThread(_gw.thread);
+ OTTDJoinThread((OTTDThread*)_gw.thread);
_gw.thread = NULL;
_gw.threaded = false;
}
diff --git a/src/genworld.h b/src/genworld.h
index 0cf67cbe64..10fb569a15 100644
--- a/src/genworld.h
+++ b/src/genworld.h
@@ -34,7 +34,7 @@ typedef struct gw_info {
bool quit_thread; //! Do we want to quit the active thread
bool threaded; //! Whether we run _GenerateWorld threaded
int mode; //! What mode are we making a world in
- byte lp; //! The local_player before generating
+ PlayerID lp; //! The local_player before generating
uint size_x; //! X-size of the map
uint size_y; //! Y-size of the map
gw_done_proc *proc; //! Proc that is called when done (can be NULL)
@@ -84,8 +84,8 @@ bool IsGeneratingWorldAborted(void);
void HandleGeneratingWorldAbortion(void);
/* genworld_gui.c */
-void SetGeneratingWorldProgress(gwp_class class, uint total);
-void IncreaseGeneratingWorldProgress(gwp_class class);
+void SetGeneratingWorldProgress(gwp_class cls, uint total);
+void IncreaseGeneratingWorldProgress(gwp_class cls);
void PrepareGenerateWorldProgress(void);
void ShowGenerateWorldProgress(void);
void StartNewGameWithoutGUI(uint seed);
diff --git a/src/genworld_gui.cpp b/src/genworld_gui.cpp
index 83d0f4cf1a..65cbbd6da9 100644
--- a/src/genworld_gui.cpp
+++ b/src/genworld_gui.cpp
@@ -196,7 +196,7 @@ void GenerateLandscapeWndProc(Window *w, WindowEvent *e)
static querystr_d _genseed_query;
static char _genseed_buffer[LEN_RND_SEED];
- uint mode = w->window_number;
+ glwp_modes mode = (glwp_modes)w->window_number;
uint y;
switch (e->event) {
@@ -714,7 +714,7 @@ static const Widget _show_terrain_progress_widgets[] = {
typedef struct tp_info {
uint percent;
- StringID class;
+ StringID cls;
uint current;
uint total;
int timer;
@@ -753,12 +753,12 @@ static void ShowTerrainProgressProc(Window* w, WindowEvent* e)
/* Draw the % complete with a bar and a text */
DrawFrameRect(19, 20, (w->width - 18), 37, 14, FR_BORDERONLY);
- DrawFrameRect(20, 21, (int)((w->width - 40) * _tp.percent / 100) + 20, 36, 10, 0);
+ DrawFrameRect(20, 21, (int)((w->width - 40) * _tp.percent / 100) + 20, 36, 10, FR_NONE);
SetDParam(0, _tp.percent);
DrawStringCentered(90, 25, STR_PROGRESS, 0);
/* Tell which class we are generating */
- DrawStringCentered(90, 46, _tp.class, 0);
+ DrawStringCentered(90, 46, _tp.cls, 0);
/* And say where we are in that class */
SetDParam(0, _tp.current);
@@ -783,7 +783,7 @@ static const WindowDesc _show_terrain_progress_desc = {
*/
void PrepareGenerateWorldProgress(void)
{
- _tp.class = STR_WORLD_GENERATION;
+ _tp.cls = STR_WORLD_GENERATION;
_tp.current = 0;
_tp.total = 0;
_tp.percent = 0;
@@ -798,7 +798,7 @@ void ShowGenerateWorldProgress(void)
AllocateWindowDescFront(&_show_terrain_progress_desc, 0);
}
-static void _SetGeneratingWorldProgress(gwp_class class, uint progress, uint total)
+static void _SetGeneratingWorldProgress(gwp_class cls, uint progress, uint total)
{
static const int percent_table[GWP_CLASS_COUNT + 1] = {0, 5, 15, 20, 40, 60, 65, 80, 85, 99, 100 };
static const StringID class_table[GWP_CLASS_COUNT] = {
@@ -814,7 +814,7 @@ static void _SetGeneratingWorldProgress(gwp_class class, uint progress, uint tot
STR_PREPARING_GAME
};
- assert(class < GWP_CLASS_COUNT);
+ assert(cls < GWP_CLASS_COUNT);
/* Do not run this function if we aren't in a thread */
if (!IsGenerateWorldThreaded() && !_network_dedicated) return;
@@ -822,13 +822,13 @@ static void _SetGeneratingWorldProgress(gwp_class class, uint progress, uint tot
if (IsGeneratingWorldAborted()) HandleGeneratingWorldAbortion();
if (total == 0) {
- assert(_tp.class == class_table[class]);
+ assert(_tp.cls == class_table[cls]);
_tp.current += progress;
} else {
- _tp.class = class_table[class];
+ _tp.cls = class_table[cls];
_tp.current = progress;
_tp.total = total;
- _tp.percent = percent_table[class];
+ _tp.percent = percent_table[cls];
}
/* Don't update the screen too often. So update it once in every 200ms.
@@ -837,7 +837,7 @@ static void _SetGeneratingWorldProgress(gwp_class class, uint progress, uint tot
if (!_network_dedicated && _tp.timer != 0 && _timer_counter - _tp.timer < (200 * 8 / 30)) return;
/* Percentage is about the number of completed tasks, so 'current - 1' */
- _tp.percent = percent_table[class] + (percent_table[class + 1] - percent_table[class]) * (_tp.current == 0 ? 0 : _tp.current - 1) / _tp.total;
+ _tp.percent = percent_table[cls] + (percent_table[cls + 1] - percent_table[cls]) * (_tp.current == 0 ? 0 : _tp.current - 1) / _tp.total;
_tp.timer = _timer_counter;
if (_network_dedicated) {
@@ -877,11 +877,11 @@ static void _SetGeneratingWorldProgress(gwp_class class, uint progress, uint tot
* Warning: this function isn't clever. Don't go from class 4 to 3. Go upwards, always.
* Also, progress works if total is zero, total works if progress is zero.
*/
-void SetGeneratingWorldProgress(gwp_class class, uint total)
+void SetGeneratingWorldProgress(gwp_class cls, uint total)
{
if (total == 0) return;
- _SetGeneratingWorldProgress(class, 0, total);
+ _SetGeneratingWorldProgress(cls, 0, total);
}
/**
@@ -891,8 +891,8 @@ void SetGeneratingWorldProgress(gwp_class class, uint total)
* Warning: this function isn't clever. Don't go from class 4 to 3. Go upwards, always.
* Also, progress works if total is zero, total works if progress is zero.
*/
-void IncreaseGeneratingWorldProgress(gwp_class class)
+void IncreaseGeneratingWorldProgress(gwp_class cls)
{
/* In fact the param 'class' isn't needed.. but for some security reasons, we want it around */
- _SetGeneratingWorldProgress(class, 1, 0);
+ _SetGeneratingWorldProgress(cls, 1, 0);
}
diff --git a/src/gfx.cpp b/src/gfx.cpp
index a78e20040b..de90ca461d 100644
--- a/src/gfx.cpp
+++ b/src/gfx.cpp
@@ -473,7 +473,7 @@ void DrawStringMultiCenter(int x, int y, StringID str, int maxw)
tmp = FormatStringLinebreaks(buffer, maxw);
num = GB(tmp, 0, 16);
- mt = GetCharacterHeight(GB(tmp, 16, 16));
+ mt = GetCharacterHeight((FontSize)GB(tmp, 16, 16));
y -= (mt >> 1) * num;
@@ -517,7 +517,7 @@ uint DrawStringMultiLine(int x, int y, StringID str, int maxw)
tmp = FormatStringLinebreaks(buffer, maxw);
num = GB(tmp, 0, 16);
- mt = GetCharacterHeight(GB(tmp, 16, 16));
+ mt = GetCharacterHeight((FontSize)GB(tmp, 16, 16));
total_height = (num + 1) * mt;
src = buffer;
diff --git a/src/gfx.h b/src/gfx.h
index 8636a36a61..a19ceaa459 100644
--- a/src/gfx.h
+++ b/src/gfx.h
@@ -3,31 +3,7 @@
#ifndef GFX_H
#define GFX_H
-typedef byte Pixel;
-
-struct DrawPixelInfo {
- Pixel *dst_ptr;
- int left, top, width, height;
- int pitch;
- uint16 zoom;
-};
-
-
-typedef struct CursorVars {
- Point pos, size, offs, delta; ///< position, size, offset from top-left, and movement
- Point draw_pos, draw_size; ///< position and size bounding-box for drawing
- CursorID sprite; ///< current image of cursor
-
- int wheel; ///< mouse wheel movement
- const CursorID *animate_list, *animate_cur; ///< in case of animated cursor, list of frames
- uint animate_timeout; ///< current frame in list of animated cursor
-
- bool visible; ///< cursor is visible
- bool dirty; ///< the rect occupied by the mouse is dirty (redraw)
- bool fix_at; ///< mouse is moving, but cursor is not (used for scrolling)
- bool in_window; ///< mouse inside this window, determines drawing logic
-} CursorVars;
-
+#include "helpers.hpp"
typedef enum FontSizes {
FS_NORMAL,
@@ -36,6 +12,7 @@ typedef enum FontSizes {
FS_END,
} FontSize;
+DECLARE_POSTFIX_INCREMENT(FontSize);
void RedrawScreenRect(int left, int top, int right, int bottom);
void GfxScroll(int left, int top, int width, int height, int xo, int yo);
@@ -83,7 +60,7 @@ bool FillDrawPixelInfo(DrawPixelInfo* n, int left, int top, int width, int heigh
/* window.c */
void DrawOverlappedWindowForAll(int left, int top, int right, int bottom);
-void SetMouseCursor(uint cursor);
+void SetMouseCursor(CursorID cursor);
void SetAnimatedMouseCursor(const CursorID *table);
void CursorTick(void);
void DrawMouseCursor(void);
@@ -91,7 +68,7 @@ void ScreenSizeChanged(void);
void UndrawMouseCursor(void);
bool ChangeResInGame(int w, int h);
void SortResolutions(int count);
-void ToggleFullScreen(bool fs);
+extern "C" void ToggleFullScreen(bool fs);
/* gfx.c */
#define ASCII_LETTERSTART 32
@@ -109,9 +86,7 @@ static inline byte GetCharacterHeight(FontSize size)
}
}
-VARDEF DrawPixelInfo _screen;
VARDEF DrawPixelInfo *_cur_dpi;
-VARDEF CursorVars _cursor;
enum {
COLOUR_DARK_BLUE,
@@ -138,20 +113,8 @@ enum {
*/
VARDEF byte _colour_gradient[16][8];
-VARDEF int _pal_first_dirty;
-VARDEF int _pal_last_dirty;
-
VARDEF bool _use_dos_palette;
-typedef struct Colour {
- byte r;
- byte g;
- byte b;
-} Colour;
-
-extern Colour _cur_palette[256];
-
-
typedef enum StringColorFlags {
IS_PALETTE_COLOR = 0x100, // color value is already a real palette color index, not an index of a StringColor
} StringColorFlags;
diff --git a/src/gfxinit.cpp b/src/gfxinit.cpp
index 4b55ec9049..6de300100e 100644
--- a/src/gfxinit.cpp
+++ b/src/gfxinit.cpp
@@ -17,13 +17,13 @@
#include
typedef struct MD5File {
- const char * const filename; // filename
- const md5_byte_t hash[16]; // md5 sum of the file
+ const char * filename; // filename
+ md5_byte_t hash[16]; // md5 sum of the file
} MD5File;
typedef struct FileList {
- const MD5File basic[4]; // grf files that always have to be loaded
- const MD5File landscape[3]; // landscape specific grf files
+ MD5File basic[4]; // grf files that always have to be loaded
+ MD5File landscape[3]; // landscape specific grf files
} FileList;
enum {
diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp
index c6a9b845b5..96d0f9f7ab 100644
--- a/src/graph_gui.cpp
+++ b/src/graph_gui.cpp
@@ -15,6 +15,7 @@
#include "debug.h"
#include "variables.h"
#include "date.h"
+#include "helpers.hpp"
const byte _cargo_colours[NUM_CARGO] = {152, 32, 15, 174, 208, 194, 191, 84, 184, 10, 202, 48};
@@ -65,7 +66,7 @@ static void DrawGraph(const GraphDrawer *gw)
/* the colors and cost array of GraphDrawer must accomodate
* both values for cargo and players. So if any are higher, quit */
- assert(GRAPH_NUM >= NUM_CARGO && GRAPH_NUM >= MAX_PLAYERS);
+ assert(GRAPH_NUM >= (int)NUM_CARGO && GRAPH_NUM >= (int)MAX_PLAYERS);
color = _colour_gradient[gw->bg_line_color][4];
@@ -118,7 +119,7 @@ static void DrawGraph(const GraphDrawer *gw)
col_ptr = row_ptr;
do {
if (*col_ptr != INVALID_VALUE) {
- mx = max64(mx, myabs64(*col_ptr));
+ mx = max64(mx, *col_ptr);
}
} while (col_ptr++, --num_x);
}
@@ -906,11 +907,10 @@ void ShowCompanyLeagueTable(void)
static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e)
{
- static PlayerID _performance_rating_detail_player = 0;
+ static PlayerID _performance_rating_detail_player = PLAYER_FIRST;
switch (e->event) {
case WE_PAINT: {
- int i;
byte x;
uint16 y = 14;
int total_score = 0;
@@ -920,7 +920,7 @@ static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e)
DrawWindowWidgets(w);
// Paint the player icons
- for (i = 0; i < MAX_PLAYERS; i++) {
+ for (PlayerID i = PLAYER_FIRST; i < MAX_PLAYERS; i++) {
if (!GetPlayer(i)->is_active) {
// Check if we have the player as an active player
if (!IsWindowWidgetDisabled(w, i + 13)) {
@@ -930,7 +930,7 @@ static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e)
if (IsWindowWidgetLowered(w, i + 13)) {
RaiseWindowWidget(w, i + 13);
LowerWindowWidget(w, 13);
- _performance_rating_detail_player = 0;
+ _performance_rating_detail_player = PLAYER_FIRST;
}
// We need a repaint
SetWindowDirty(w);
@@ -955,7 +955,7 @@ static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e)
color_notdone = _colour_gradient[COLOUR_RED][4];
// Draw all the score parts
- for (i = 0; i < NUM_SCORE; i++) {
+ for (ScoreID i = SCORE_BEGIN; i < SCORE_END; i++) {
int val = _score_part[_performance_rating_detail_player][i];
int needed = _score_info[i].needed;
int score = _score_info[i].score;
@@ -1030,7 +1030,7 @@ static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e)
// Is it no on disable?
if (!IsWindowWidgetDisabled(w, e->we.click.widget)) {
RaiseWindowWidget(w, _performance_rating_detail_player + 13);
- _performance_rating_detail_player = e->we.click.widget - 13;
+ _performance_rating_detail_player = (PlayerID)(e->we.click.widget - 13);
LowerWindowWidget(w, _performance_rating_detail_player + 13);
SetWindowDirty(w);
}
@@ -1038,11 +1038,11 @@ static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e)
break;
case WE_CREATE: {
- int i;
+ PlayerID i;
Player *p2;
/* Disable the players who are not active */
- for (i = 0; i < MAX_PLAYERS; i++) {
+ for (i = PLAYER_FIRST; i < MAX_PLAYERS; i++) {
SetWindowWidgetDisabledState(w, i + 13, !GetPlayer(i)->is_active);
}
/* Update all player stats with the current data
@@ -1054,7 +1054,7 @@ static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e)
w->custom[0] = DAY_TICKS;
w->custom[1] = 5;
- _performance_rating_detail_player = 0;
+ _performance_rating_detail_player = PLAYER_FIRST;
LowerWindowWidget(w, _performance_rating_detail_player + 13);
SetWindowDirty(w);
@@ -1151,7 +1151,7 @@ static void GlobalSortSignList(void)
uint n = 0;
/* Create array for sorting */
- _sign_sort = realloc((void *)_sign_sort, (GetMaxSignIndex() + 1)* sizeof(_sign_sort[0]));
+ ReallocT(&_sign_sort, GetMaxSignIndex() + 1);
if (_sign_sort == NULL) error("Could not allocate memory for the sign-sorting-list");
FOR_ALL_SIGNS(si) _sign_sort[n++] = si;
diff --git a/src/gui.h b/src/gui.h
index 8ca055f433..00ee301b4c 100644
--- a/src/gui.h
+++ b/src/gui.h
@@ -132,7 +132,7 @@ void ShowMusicWindow(void);
/* main_gui.c */
void HandleOnEditText(const char *str);
-VARDEF byte _station_show_coverage;
+VARDEF bool _station_show_coverage;
VARDEF PlaceProc *_place_proc;
/* vehicle_gui.c */
diff --git a/src/hal.h b/src/hal.h
index 1b239162b8..020df5f142 100644
--- a/src/hal.h
+++ b/src/hal.h
@@ -3,6 +3,85 @@
#ifndef HAL_H
#define HAL_H
+#ifdef __cplusplus
+extern "C" {
+#endif //__cplusplus
+
+enum WindowKeyCodes {
+ WKC_SHIFT = 0x8000,
+ WKC_CTRL = 0x4000,
+ WKC_ALT = 0x2000,
+ WKC_META = 0x1000,
+
+ // Special ones
+ WKC_NONE = 0,
+ WKC_ESC = 1,
+ WKC_BACKSPACE = 2,
+ WKC_INSERT = 3,
+ WKC_DELETE = 4,
+
+ WKC_PAGEUP = 5,
+ WKC_PAGEDOWN = 6,
+ WKC_END = 7,
+ WKC_HOME = 8,
+
+ // Arrow keys
+ WKC_LEFT = 9,
+ WKC_UP = 10,
+ WKC_RIGHT = 11,
+ WKC_DOWN = 12,
+
+ // Return & tab
+ WKC_RETURN = 13,
+ WKC_TAB = 14,
+
+ // Numerical keyboard
+ WKC_NUM_0 = 16,
+ WKC_NUM_1 = 17,
+ WKC_NUM_2 = 18,
+ WKC_NUM_3 = 19,
+ WKC_NUM_4 = 20,
+ WKC_NUM_5 = 21,
+ WKC_NUM_6 = 22,
+ WKC_NUM_7 = 23,
+ WKC_NUM_8 = 24,
+ WKC_NUM_9 = 25,
+ WKC_NUM_DIV = 26,
+ WKC_NUM_MUL = 27,
+ WKC_NUM_MINUS = 28,
+ WKC_NUM_PLUS = 29,
+ WKC_NUM_ENTER = 30,
+ WKC_NUM_DECIMAL = 31,
+
+ // Space
+ WKC_SPACE = 32,
+
+ // Function keys
+ WKC_F1 = 33,
+ WKC_F2 = 34,
+ WKC_F3 = 35,
+ WKC_F4 = 36,
+ WKC_F5 = 37,
+ WKC_F6 = 38,
+ WKC_F7 = 39,
+ WKC_F8 = 40,
+ WKC_F9 = 41,
+ WKC_F10 = 42,
+ WKC_F11 = 43,
+ WKC_F12 = 44,
+
+ // backquote is the key left of "1"
+ // we only store this key here, no matter what character is really mapped to it
+ // on a particular keyboard. (US keyboard: ` and ~ ; German keyboard: ^ and °)
+ WKC_BACKQUOTE = 45,
+ WKC_PAUSE = 46,
+
+ // 0-9 are mapped to 48-57
+ // A-Z are mapped to 65-90
+ // a-z are mapped to 97-122
+};
+
+
typedef struct {
const char *(*start)(const char * const *parm);
void (*stop)(void);
@@ -32,9 +111,9 @@ typedef struct {
void (*set_volume)(byte vol);
} HalMusicDriver;
-VARDEF HalMusicDriver *_music_driver;
-VARDEF HalSoundDriver *_sound_driver;
-VARDEF HalVideoDriver *_video_driver;
+extern HalMusicDriver *_music_driver;
+extern HalSoundDriver *_sound_driver;
+extern HalVideoDriver *_video_driver;
enum DriverType {
VIDEO_DRIVER = 0,
@@ -42,8 +121,99 @@ enum DriverType {
MUSIC_DRIVER = 2,
};
+enum GameModes {
+ GM_MENU,
+ GM_NORMAL,
+ GM_EDITOR
+};
+
void GameLoop(void);
void CreateConsole(void);
+typedef int32 CursorID;
+typedef byte Pixel;
+
+typedef struct Point {
+ int x,y;
+} Point;
+
+typedef struct Rect {
+ int left,top,right,bottom;
+} Rect;
+
+
+typedef struct CursorVars {
+ Point pos, size, offs, delta; ///< position, size, offset from top-left, and movement
+ Point draw_pos, draw_size; ///< position and size bounding-box for drawing
+ CursorID sprite; ///< current image of cursor
+
+ int wheel; ///< mouse wheel movement
+ const CursorID *animate_list, *animate_cur; ///< in case of animated cursor, list of frames
+ uint animate_timeout; ///< current frame in list of animated cursor
+
+ bool visible; ///< cursor is visible
+ bool dirty; ///< the rect occupied by the mouse is dirty (redraw)
+ bool fix_at; ///< mouse is moving, but cursor is not (used for scrolling)
+ bool in_window; ///< mouse inside this window, determines drawing logic
+} CursorVars;
+
+typedef struct DrawPixelInfo {
+ Pixel *dst_ptr;
+ int left, top, width, height;
+ int pitch;
+ uint16 zoom;
+} DrawPixelInfo;
+
+
+extern byte _dirkeys; // 1 = left, 2 = up, 4 = right, 8 = down
+extern bool _fullscreen;
+extern CursorVars _cursor;
+extern bool _ctrl_pressed; // Is Ctrl pressed?
+extern bool _shift_pressed; // Is Shift pressed?
+extern byte _fast_forward;
+
+extern bool _left_button_down;
+extern bool _left_button_clicked;
+extern bool _right_button_down;
+extern bool _right_button_clicked;
+
+extern DrawPixelInfo _screen;
+extern bool _exit_game;
+extern bool _networking; ///< are we in networking mode?
+extern byte _game_mode;
+extern byte _pause;
+
+
+void HandleKeypress(uint32 key);
+void HandleMouseEvents(void);
+void CSleep(int milliseconds);
+void UpdateWindows(void);
+
+uint32 InteractiveRandom(void); /* Used for random sequences that are not the same on the other end of the multiplayer link */
+uint InteractiveRandomRange(uint max);
+void DrawTextMessage(void);
+void DrawMouseCursor(void);
+void ScreenSizeChanged(void);
+void HandleExitGameRequest(void);
+void GameSizeChanged(void);
+void UndrawMouseCursor(void);
+
+extern int _pal_first_dirty;
+extern int _pal_last_dirty;
+extern int _num_resolutions;
+extern uint16 _resolutions[32][2];
+extern uint16 _cur_resolution[2];
+
+typedef struct Colour {
+ byte r;
+ byte g;
+ byte b;
+} Colour;
+extern Colour _cur_palette[256];
+
+#ifdef __cplusplus
+} // extern "C"
+#endif //__cplusplus
+
#endif /* HAL_H */
diff --git a/src/heightmap.cpp b/src/heightmap.cpp
index aeaa5c38e6..57f4c30b17 100644
--- a/src/heightmap.cpp
+++ b/src/heightmap.cpp
@@ -13,6 +13,7 @@
#include "gui.h"
#include "saveload.h"
#include "bmp.h"
+#include "helpers.hpp"
/**
* Convert RGB colors to Grayscale using 29.9% Red, 58.7% Green, 11.4% Blue
@@ -135,7 +136,7 @@ static bool ReadHeightmapPNG(char *filename, uint *x, uint *y, byte **map)
}
if (map != NULL) {
- *map = malloc(info_ptr->width * info_ptr->height * sizeof(byte));
+ MallocT(/* NO & */map, info_ptr->width * info_ptr->height);
if (*map == NULL) {
ShowErrorMessage(STR_PNGMAP_ERR_MISC, STR_PNGMAP_ERROR, 0, 0);
@@ -248,7 +249,7 @@ static bool ReadHeightmapBMP(char *filename, uint *x, uint *y, byte **map)
return false;
}
- *map = malloc(info.width * info.height * sizeof(byte));
+ MallocT(map, info.width * info.height);
if (*map == NULL) {
ShowErrorMessage(STR_PNGMAP_ERR_MISC, STR_BMPMAP_ERROR, 0, 0);
fclose(f);
diff --git a/src/helpers.cpp b/src/helpers.cpp
index b78df5de87..d40078683b 100644
--- a/src/helpers.cpp
+++ b/src/helpers.cpp
@@ -1,10 +1,8 @@
/* $Id$ */
#include "stdafx.h"
-EXTERN_C_BEGIN
#include "openttd.h"
#include "engine.h"
-EXTERN_C_END
#include
#include "yapf/blob.hpp"
diff --git a/src/helpers.hpp b/src/helpers.hpp
new file mode 100644
index 0000000000..b13fc25d44
--- /dev/null
+++ b/src/helpers.hpp
@@ -0,0 +1,178 @@
+/* $Id$ */
+
+#ifndef HELPERS_HPP
+#define HELPERS_HPP
+
+/** @file helpers.hpp */
+#include "macros.h"
+
+#ifdef __cplusplus
+
+/** When allocating using malloc/calloc in C++ it is usually needed to cast the return value
+* from void* to the proper pointer type. Another alternative would be MallocT<> as follows */
+template FORCEINLINE bool MallocT(T** t_ptr, size_t num_elements)
+{
+ *t_ptr = (T*)malloc(num_elements * sizeof(T));
+ return (*t_ptr != NULL);
+}
+/** When allocating using malloc/calloc in C++ it is usually needed to cast the return value
+* from void* to the proper pointer type. Another alternative would be MallocT<> as follows */
+template FORCEINLINE bool CallocT(T** t_ptr, size_t num_elements)
+{
+ *t_ptr = (T*)calloc(num_elements, sizeof(T));
+ return (*t_ptr != NULL);
+}
+/** When allocating using malloc/calloc in C++ it is usually needed to cast the return value
+* from void* to the proper pointer type. Another alternative would be MallocT<> as follows */
+template FORCEINLINE bool ReallocT(T** t_ptr, size_t num_elements)
+{
+ *t_ptr = (T*)realloc(*t_ptr, num_elements * sizeof(T));
+ return (*t_ptr != NULL);
+}
+
+/** type safe swap operation */
+template void SwapT(T *a, T *b);
+
+template FORCEINLINE void SwapT(T *a, T *b)
+{
+ T t = *a;
+ *a = *b;
+ *b = t;
+}
+
+
+/** returns the absolute value of (scalar) variable. @note assumes variable to be signed */
+template static inline T myabs(T a) { return a < (T)0 ? -a : a; }
+/** returns the (absolute) difference between two (scalar) variables */
+template static inline T delta(T a, T b) { return a < b ? b - a : a - b; }
+
+/** Some enums need to have allowed incrementing (i.e. StationClassID) */
+#define DECLARE_POSTFIX_INCREMENT(type) \
+ FORCEINLINE type operator ++(type& e, int) \
+ { \
+ type e_org = e; \
+ e = (type)((int)e + 1); \
+ return e_org; \
+ } \
+ FORCEINLINE type operator --(type& e, int) \
+ { \
+ type e_org = e; \
+ e = (type)((int)e - 1); \
+ return e_org; \
+ }
+
+
+
+/** Operators to allow to work with enum as with type safe bit set in C++ */
+# define DECLARE_ENUM_AS_BIT_SET(mask_t) \
+ FORCEINLINE mask_t operator | (mask_t m1, mask_t m2) {return (mask_t)((int)m1 | m2);} \
+ FORCEINLINE mask_t operator & (mask_t m1, mask_t m2) {return (mask_t)((int)m1 & m2);} \
+ FORCEINLINE mask_t operator ^ (mask_t m1, mask_t m2) {return (mask_t)((int)m1 ^ m2);} \
+ FORCEINLINE mask_t& operator |= (mask_t& m1, mask_t m2) {m1 = m1 | m2; return m1;} \
+ FORCEINLINE mask_t& operator &= (mask_t& m1, mask_t m2) {m1 = m1 & m2; return m1;} \
+ FORCEINLINE mask_t& operator ^= (mask_t& m1, mask_t m2) {m1 = m1 ^ m2; return m1;} \
+ FORCEINLINE mask_t operator ~(mask_t m) {return (mask_t)(~(int)m);}
+
+/** probably redundant enum combining operators (as we have conversion functions)
+ * but the old code is full of such arithmetics */
+# define DECLARE_ENUM_AS_BIT_INDEX(idx_t, mask_t) \
+ FORCEINLINE mask_t operator << (int m, idx_t i) {return (mask_t)(m << (int)i);} \
+ FORCEINLINE mask_t operator << (mask_t m, int i) {return (mask_t)(((int)m) << i);} \
+ FORCEINLINE mask_t operator >> (mask_t m, int i) {return (mask_t)(((int)m) >> i);}
+
+
+/** Informative template class exposing basic enumeration properties used by several
+ * other templates below. Here we have only forward declaration. For each enum type
+ * we will create specialization derived from MakeEnumPropsT<>. */
+template struct EnumPropsT;
+
+/** Helper template class that makes basic properties of given enumeration type visible
+ * from outsize. It is used as base class of several EnumPropsT specializations each
+ * dedicated to one of commonly used enumeration types. */
+template
+struct MakeEnumPropsT {
+ typedef Tenum_t type; ///< enum type (i.e. Trackdir)
+ typedef Tstorage_t storage; ///< storage type (i.e. byte)
+ static const Tenum_t begin = Tbegin; ///< lowest valid value (i.e. TRACKDIR_BEGIN)
+ static const Tenum_t end = Tend; ///< one after the last valid value (i.e. TRACKDIR_END)
+ static const Tenum_t invalid = Tinvalid; ///< what value is used as invalid value (i.e. INVALID_TRACKDIR)
+};
+
+
+
+/** In some cases we use byte or uint16 to store values that are defined as enum. It is
+ * necessary in order to control the sizeof() such values. Some compilers make enum
+ * the same size as int (4 or 8 bytes instead of 1 or 2). As a consequence the strict
+ * compiler type-checking causes errors like:
+ * 'HasPowerOnRail' : cannot convert parameter 1 from 'byte' to 'RailType' when
+ * u->u.rail.railtype is passed as argument or type RailType. In such cases it is better
+ * to teach the compiler that u->u.rail.railtype is to be treated as RailType. */
+template struct TinyEnumT;
+
+/** The general declaration of TinyEnumT<> (above) */
+template struct TinyEnumT
+{
+ typedef Tenum_t enum_type; ///< expose our enumeration type (i.e. Trackdir) to outside
+ typedef EnumPropsT Props; ///< make easier access to our enumeration propeties
+ typedef typename Props::storage storage_type; ///< small storage type
+ static const enum_type begin = Props::begin; ///< enum beginning (i.e. TRACKDIR_BEGIN)
+ static const enum_type end = Props::end; ///< enum end (i.e. TRACKDIR_END)
+ static const enum_type invalid = Props::invalid;///< invalid value (i.e. INVALID_TRACKDIR)
+
+ storage_type m_val; ///< here we hold the actual value in small (i.e. byte) form
+
+ /** Cast operator - invoked then the value is assigned to the Tenum_t type */
+ FORCEINLINE operator enum_type () const
+ {
+ return (enum_type)m_val;
+ }
+
+ /** Assignment operator (from Tenum_t type) */
+ FORCEINLINE TinyEnumT& operator = (enum_type e)
+ {
+ m_val = (storage_type)e; return *this;
+ }
+
+ /** postfix ++ operator on tiny type */
+ FORCEINLINE TinyEnumT& operator ++ (int)
+ {
+ if (++m_val >= end) m_val -= (storage_type)(end - begin);
+ return *this;
+ }
+};
+
+template FORCEINLINE void SwapT(TinyEnumT *a, TinyEnumT *b)
+{
+ SwapT(&a->m_val, &b->m_val);
+}
+
+template FORCEINLINE T ClrBitT(T t, int bit_index)
+{
+ int val = t;
+ CLRBIT(val, bit_index);
+ return (T)val;
+}
+
+template FORCEINLINE T SetBitT(T t, int bit_index)
+{
+ int val = t;
+ SETBIT(val, bit_index);
+ return (T)val;
+}
+
+template FORCEINLINE T ToggleBitT(T t, int bit_index)
+{
+ int val = t;
+ TOGGLEBIT(val, bit_index);
+ return (T)val;
+}
+
+#else // __cplusplus
+
+#define DECLARE_POSTFIX_INCREMENT(E)
+#define DECLARE_ENUM_AS_BIT_SET(E)
+#define DECLARE_ENUM_AS_BIT_INDEX(E1,E2)
+
+#endif // __cplusplus
+
+#endif /* HELPERS_HPP */
diff --git a/src/industry.h b/src/industry.h
index f8cf63c827..a7b5323817 100644
--- a/src/industry.h
+++ b/src/industry.h
@@ -36,7 +36,7 @@ struct Industry {
uint16 counter;
byte type;
- byte owner;
+ OwnerByte owner;
byte random_color;
Year last_prod_year;
byte was_cargo_delivered;
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
index 38e2c516b4..5b37939c0a 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -765,14 +765,14 @@ static void SetupFarmFieldFence(TileIndex tile, int size, byte type, Axis direct
tile = TILE_MASK(tile);
if (IsTileType(tile, MP_CLEAR) || IsTileType(tile, MP_TREES)) {
- byte or = type;
+ byte or_ = type;
- if (or == 1 && CHANCE16(1, 7)) or = 2;
+ if (or_ == 1 && CHANCE16(1, 7)) or_ = 2;
if (direction == AXIS_X) {
- SetFenceSE(tile, or);
+ SetFenceSE(tile, or_);
} else {
- SetFenceSW(tile, or);
+ SetFenceSW(tile, or_);
}
}
@@ -942,7 +942,7 @@ static void ProduceIndustryGoods(Industry *i)
if ((i->counter & 0x3F) == 0) {
if (CHANCE16R(1,14,r) && (num=_industry_sounds[i->type][0]) != 0) {
SndPlayTileFx(
- _industry_sounds[i->type][1] + (((r >> 16) * num) >> 16),
+ (SoundFx)(_industry_sounds[i->type][1] + (((r >> 16) * num) >> 16)),
i->xy);
}
}
@@ -1225,7 +1225,7 @@ static bool CheckCanTerraformSurroundingTiles(TileIndex tile, uint height, int i
return false;
/* Don't allow too big of a change if this is the sub-tile check */
- if (internal != 0 && myabs(curh - height) > 1) return false;
+ if (internal != 0 && delta(curh, height) > 1) return false;
/* Different height, so the surrounding tiles of this tile
* has to be correct too (in level, or almost in level)
@@ -1353,7 +1353,7 @@ static Industry *AllocateIndustry(void)
return AddBlockToPool(&_Industry_pool) ? AllocateIndustry() : NULL;
}
-static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const IndustryTileTable *it, const Town *t, byte owner)
+static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const IndustryTileTable *it, const Town *t, Owner owner)
{
const IndustrySpec *indspec = GetIndustrySpec(type);
uint32 r;
@@ -1595,25 +1595,25 @@ static void ExtChangeIndustryProduction(Industry *i)
default: /* INDUSTRY_PRODUCTION */
for (j = 0; j < 2 && i->produced_cargo[j] != CT_INVALID; j++){
uint32 r = Random();
- int old, new, percent;
+ int old_prod, new_prod, percent;
int mag;
- new = old = i->production_rate[j];
+ new_prod = old_prod = i->production_rate[j];
if (CHANCE16I(20, 1024, r))
- new -= ((RandomRange(50) + 10) * old) >> 8;
+ new_prod -= ((RandomRange(50) + 10) * old_prod) >> 8;
if (CHANCE16I(20 + (i->pct_transported[j] * 20 >> 8), 1024, r >> 16))
- new += ((RandomRange(50) + 10) * old) >> 8;
+ new_prod += ((RandomRange(50) + 10) * old_prod) >> 8;
- new = clamp(new, 0, 255);
- if (new == old) {
+ new_prod = clamp(new_prod, 0, 255);
+ if (new_prod == old_prod) {
closeit = false;
continue;
}
- percent = new * 100 / old - 100;
- i->production_rate[j] = new;
+ percent = new_prod * 100 / old_prod - 100;
+ i->production_rate[j] = new_prod;
- if (new >= indspec->production_rate[j] / 4)
+ if (new_prod >= indspec->production_rate[j] / 4)
closeit = false;
mag = abs(percent);
@@ -1827,7 +1827,7 @@ void InitializeIndustries(void)
_industry_sound_tile = 0;
}
-const TileTypeProcs _tile_type_industry_procs = {
+extern const TileTypeProcs _tile_type_industry_procs = {
DrawTile_Industry, /* draw_tile_proc */
GetSlopeZ_Industry, /* get_slope_z_proc */
ClearTile_Industry, /* clear_tile_proc */
@@ -1905,6 +1905,6 @@ static void Load_INDY(void)
}
}
-const ChunkHandler _industry_chunk_handlers[] = {
+extern const ChunkHandler _industry_chunk_handlers[] = {
{ 'INDY', Save_INDY, Load_INDY, CH_ARRAY | CH_LAST},
};
diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp
index 3e481ef886..7247036a4d 100644
--- a/src/industry_gui.cpp
+++ b/src/industry_gui.cpp
@@ -16,6 +16,7 @@
#include "industry.h"
#include "town.h"
#include "variables.h"
+#include "helpers.hpp"
const byte _build_industry_types[4][12] = {
{ 1, 2, 4, 6, 8, 0, 3, 5, 9, 11, 18 },
@@ -559,7 +560,7 @@ static void MakeSortedIndustryList(void)
if (GetNumIndustries() == 0) return;
/* Create array for sorting */
- _industry_sort = realloc((void *)_industry_sort, (GetMaxIndustryIndex() + 1) * sizeof(_industry_sort[0]));
+ ReallocT(&_industry_sort, GetMaxIndustryIndex() + 1);
if (_industry_sort == NULL) error("Could not allocate memory for the industry-sorting-list");
FOR_ALL_INDUSTRIES(i) _industry_sort[n++] = i;
diff --git a/src/landscape.cpp b/src/landscape.cpp
index 2d8b7205b1..2f05fc2ba3 100644
--- a/src/landscape.cpp
+++ b/src/landscape.cpp
@@ -55,7 +55,7 @@ const byte _tileh_to_sprite[32] = {
0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 17, 0, 15, 18, 0,
};
-const byte _inclined_tileh[] = {
+const Slope _inclined_tileh[] = {
SLOPE_SW, SLOPE_NW, SLOPE_SW, SLOPE_SE, SLOPE_NE, SLOPE_SE, SLOPE_NE, SLOPE_NW,
SLOPE_E, SLOPE_N, SLOPE_W, SLOPE_S,
SLOPE_NWS, SLOPE_WSE, SLOPE_SEN, SLOPE_ENW
@@ -276,7 +276,7 @@ uint32 GetTileTrackStatus(TileIndex tile, TransportType mode)
return _tile_type_procs[GetTileType(tile)]->get_tile_track_status_proc(tile, mode);
}
-void ChangeTileOwner(TileIndex tile, byte old_player, byte new_player)
+void ChangeTileOwner(TileIndex tile, PlayerID old_player, PlayerID new_player)
{
_tile_type_procs[GetTileType(tile)]->change_tile_owner_proc(tile, old_player, new_player);
}
@@ -468,13 +468,13 @@ static void GenerateTerrain(int type, int flag)
uint y;
uint w;
uint h;
- const Sprite* template;
+ const Sprite* templ;
const byte *p;
Tile* tile;
byte direction;
r = Random();
- template = GetSprite((((r >> 24) * _genterrain_tbl_1[type]) >> 8) + _genterrain_tbl_2[type] + 4845);
+ templ = GetSprite((((r >> 24) * _genterrain_tbl_1[type]) >> 8) + _genterrain_tbl_2[type] + 4845);
x = r & MapMaxX();
y = (r >> MapLogX()) & MapMaxY();
@@ -484,13 +484,13 @@ static void GenerateTerrain(int type, int flag)
direction = GB(r, 22, 2);
if (direction & 1) {
- w = template->height;
- h = template->width;
+ w = templ->height;
+ h = templ->width;
} else {
- w = template->width;
- h = template->height;
+ w = templ->width;
+ h = templ->height;
}
- p = template->data;
+ p = templ->data;
if (flag & 4) {
uint xw = x * MapSizeY();
diff --git a/src/livery.h b/src/livery.h
index 2655dcd48b..76b5c7e281 100644
--- a/src/livery.h
+++ b/src/livery.h
@@ -3,10 +3,12 @@
#ifndef LIVERY_H
#define LIVERY_H
+#include "helpers.hpp"
/* List of different livery schemes. */
typedef enum LiverySchemes {
- LS_DEFAULT,
+ LS_BEGIN = 0,
+ LS_DEFAULT = 0,
/* Rail vehicles */
LS_STEAM,
@@ -37,6 +39,7 @@ typedef enum LiverySchemes {
LS_END
} LiveryScheme;
+DECLARE_POSTFIX_INCREMENT(LiveryScheme);
/* List of different livery classes, used only by the livery GUI. */
typedef enum LiveryClasses {
diff --git a/src/macros.h b/src/macros.h
index 8e310c07e6..644f178af9 100644
--- a/src/macros.h
+++ b/src/macros.h
@@ -20,9 +20,10 @@
#undef max
#endif
-static inline int min(int a, int b) { if (a <= b) return a; return b; }
static inline int max(int a, int b) { if (a >= b) return a; return b; }
-static inline int64 max64(int64 a, int64 b) { if (a >= b) return a; return b; }
+static inline double dmax(double a, double b) { if (a >= b) return a; return b; }
+static inline uint64 max64(uint64 a, uint64 b) { if (a >= b) return a; return b; }
+static inline int min(int a, int b) { if (a <= b) return a; return b; }
static inline uint minu(uint a, uint b) { if (a <= b) return a; return b; }
static inline uint maxu(uint a, uint b) { if (a >= b) return a; return b; }
@@ -136,15 +137,11 @@ static inline int KillFirstBit2x64(int value)
#define abs myabs
-
static inline int intxchg_(int *a, int b) { int t = *a; *a = b; return t; }
#define intswap(a,b) ((b) = intxchg_(&(a), (b)))
static inline int uintxchg_(uint *a, uint b) { uint t = *a; *a = b; return t; }
#define uintswap(a,b) ((b) = uintxchg_(&(a), (b)))
-static inline int myabs(int a) { if (a<0) a = -a; return a; }
-static inline int64 myabs64(int64 a) { if (a<0) a = -a; return a; }
-
static inline void swap_byte(byte *a, byte *b) { byte t = *a; *a = *b; *b = t; }
static inline void swap_uint16(uint16 *a, uint16 *b) { uint16 t = *a; *a = *b; *b = t; }
static inline void swap_int16(int16 *a, int16 *b) { int16 t = *a; *a = *b; *b = t; }
diff --git a/src/main_gui.cpp b/src/main_gui.cpp
index e2b816e754..556a8feb4a 100644
--- a/src/main_gui.cpp
+++ b/src/main_gui.cpp
@@ -215,12 +215,12 @@ static void MenuClickSubsidies(int index)
static void MenuClickStations(int index)
{
- ShowPlayerStations(index);
+ ShowPlayerStations((PlayerID)index);
}
static void MenuClickFinances(int index)
{
- ShowPlayerFinances(index);
+ ShowPlayerFinances((PlayerID)index);
}
static void MenuClickCompany(int index)
@@ -229,7 +229,7 @@ static void MenuClickCompany(int index)
ShowClientList();
} else {
if (_networking) index--;
- ShowPlayerCompany(index);
+ ShowPlayerCompany((PlayerID)index);
}
}
@@ -263,27 +263,27 @@ static void MenuClickIndustry(int index)
static void MenuClickShowTrains(int index)
{
- ShowVehicleListWindow(index, INVALID_STATION, VEH_Train);
+ ShowVehicleListWindow((PlayerID)index, INVALID_STATION, VEH_Train);
}
static void MenuClickShowRoad(int index)
{
- ShowVehicleListWindow(index, INVALID_STATION, VEH_Road);
+ ShowVehicleListWindow((PlayerID)index, INVALID_STATION, VEH_Road);
}
static void MenuClickShowShips(int index)
{
- ShowVehicleListWindow(index, INVALID_STATION, VEH_Ship);
+ ShowVehicleListWindow((PlayerID)index, INVALID_STATION, VEH_Ship);
}
static void MenuClickShowAir(int index)
{
- ShowVehicleListWindow(index, INVALID_STATION, VEH_Aircraft);
+ ShowVehicleListWindow((PlayerID)index, INVALID_STATION, VEH_Aircraft);
}
static void MenuClickBuildRail(int index)
{
- _last_built_railtype = index;
+ _last_built_railtype = (RailType)index;
ShowBuildRailToolbar(_last_built_railtype, -1);
}
@@ -1564,7 +1564,7 @@ static bool AnyTownExists(void)
return false;
}
-extern Industry *CreateNewIndustry(TileIndex tile, int type);
+extern Industry *CreateNewIndustry(TileIndex tile, IndustryType type);
/**
* Search callback function for TryBuildIndustry
@@ -2283,7 +2283,7 @@ static void MainWindowWndProc(Window *w, WindowEvent *e)
case '1' | WKC_ALT: /* Gimme money */
/* Server can not cheat in advertise mode either! */
if (!_networking || !_network_server || !_network_advertise)
- DoCommandP(0, -10000000, 0, NULL, CMD_MONEY_CHEAT);
+ DoCommandP(0, 10000000, 0, NULL, CMD_MONEY_CHEAT);
break;
case '2' | WKC_ALT: /* Update the coordinates of all station signs */
@@ -2430,7 +2430,7 @@ void GameSizeChanged(void)
void InitializeMainGui(void)
{
/* Clean old GUI values */
- _last_built_railtype = 0;
+ _last_built_railtype = RAILTYPE_RAIL;
}
diff --git a/src/map.cpp b/src/map.cpp
index df16343c7d..05a51d8e82 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -7,10 +7,11 @@
#include "macros.h"
#include "map.h"
#include "direction.h"
+#include "helpers.hpp"
#if defined(_MSC_VER) && _MSC_VER >= 1400 /* VStudio 2005 is stupid! */
/* Why the hell is that not in all MSVC headers?? */
-_CRTIMP void __cdecl _assert(void *, void *, unsigned);
+extern "C" _CRTIMP void __cdecl _assert(void *, void *, unsigned);
#endif
uint _map_log_x;
@@ -41,7 +42,7 @@ void AllocateMap(uint size_x, uint size_y)
_map_tile_mask = _map_size - 1;
free(_m);
- _m = calloc(_map_size, sizeof(*_m));
+ CallocT(&_m, _map_size);
// XXX TODO handle memory shortage more gracefully
if (_m == NULL) error("Failed to allocate memory for the map");
@@ -121,14 +122,14 @@ uint TileAddWrap(TileIndex tile, int addx, int addy)
return INVALID_TILE;
}
-const TileIndexDiffC _tileoffs_by_diagdir[] = {
+extern const TileIndexDiffC _tileoffs_by_diagdir[] = {
{-1, 0}, // DIAGDIR_NE
{ 0, 1}, // DIAGDIR_SE
{ 1, 0}, // DIAGDIR_SW
{ 0, -1} // DIAGDIR_NW
};
-const TileIndexDiffC _tileoffs_by_dir[] = {
+extern const TileIndexDiffC _tileoffs_by_dir[] = {
{-1, -1}, // DIR_N
{-1, 0}, // DIR_NE
{-1, 1}, // DIR_E
@@ -141,8 +142,8 @@ const TileIndexDiffC _tileoffs_by_dir[] = {
uint DistanceManhattan(TileIndex t0, TileIndex t1)
{
- const uint dx = abs(TileX(t0) - TileX(t1));
- const uint dy = abs(TileY(t0) - TileY(t1));
+ const uint dx = delta(TileX(t0), TileX(t1));
+ const uint dy = delta(TileY(t0), TileY(t1));
return dx + dy;
}
@@ -157,16 +158,16 @@ uint DistanceSquare(TileIndex t0, TileIndex t1)
uint DistanceMax(TileIndex t0, TileIndex t1)
{
- const uint dx = abs(TileX(t0) - TileX(t1));
- const uint dy = abs(TileY(t0) - TileY(t1));
+ const uint dx = delta(TileX(t0), TileX(t1));
+ const uint dy = delta(TileY(t0), TileY(t1));
return dx > dy ? dx : dy;
}
uint DistanceMaxPlusManhattan(TileIndex t0, TileIndex t1)
{
- const uint dx = abs(TileX(t0) - TileX(t1));
- const uint dy = abs(TileY(t0) - TileY(t1));
+ const uint dx = delta(TileX(t0), TileX(t1));
+ const uint dy = delta(TileY(t0), TileY(t1));
return dx > dy ? 2 * dx + dy : 2 * dy + dx;
}
diff --git a/src/map.h b/src/map.h
index 25e29ef06d..fdc7525d01 100644
--- a/src/map.h
+++ b/src/map.h
@@ -67,13 +67,6 @@ static inline TileIndex TileVirtXY(uint x, uint y)
return (y >> 4 << MapLogX()) + (x >> 4);
}
-typedef byte Owner;
-enum Owners {
- OWNER_TOWN = 0x0F, // a town owns the tile
- OWNER_NONE = 0x10, // nobody owns the tile
- OWNER_WATER = 0x11, // "water" owns the tile
- OWNER_END = 0x12,
-};
enum {
INVALID_TILE = (TileIndex)-1
diff --git a/src/misc.cpp b/src/misc.cpp
index fd3a74b79b..d753445e94 100644
--- a/src/misc.cpp
+++ b/src/misc.cpp
@@ -611,13 +611,13 @@ static void Load_CHTS(void)
uint i;
for (i = 0; i < count; i++) {
- cht[i].been_used = SlReadByte();
- cht[i].value = SlReadByte();
+ cht[i].been_used = (SlReadByte() != 0);
+ cht[i].value = (SlReadByte() != 0);
}
}
-const ChunkHandler _misc_chunk_handlers[] = {
+extern const ChunkHandler _misc_chunk_handlers[] = {
{ 'MAPS', Save_MAPS, Load_MAPS, CH_RIFF },
{ 'MAPT', Save_MAPT, Load_MAPT, CH_RIFF },
{ 'MAPO', Save_MAP1, Load_MAP1, CH_RIFF },
diff --git a/src/misc_cmd.cpp b/src/misc_cmd.cpp
index 94b6755311..9eb9e66479 100644
--- a/src/misc_cmd.cpp
+++ b/src/misc_cmd.cpp
@@ -40,7 +40,7 @@ int32 CmdSetPlayerColor(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
{
Player *p, *pp;
byte colour;
- LiveryScheme scheme = GB(p1, 0, 8);
+ LiveryScheme scheme = (LiveryScheme)GB(p1, 0, 8);
byte state = GB(p1, 8, 2);
if (p2 >= 16) return CMD_ERROR; // max 16 colours
@@ -271,7 +271,7 @@ int32 CmdMoneyCheat(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
if (_networking) return CMD_ERROR;
#endif
SET_EXPENSES_TYPE(EXPENSES_OTHER);
- return (int32)p1;
+ return -(int32)p1;
}
/** Transfer funds (money) from one player to another.
@@ -296,7 +296,7 @@ int32 CmdGiveMoney(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
if (flags & DC_EXEC) {
/* Add money to player */
PlayerID old_cp = _current_player;
- _current_player = p2;
+ _current_player = (PlayerID)p2;
SubtractMoneyFromPlayer(-amount);
_current_player = old_cp;
}
diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp
index c80126f7af..0da96faf7d 100644
--- a/src/misc_gui.cpp
+++ b/src/misc_gui.cpp
@@ -95,7 +95,7 @@ static void Place_LandInfo(TileIndex tile)
w = AllocateWindowDesc(&_land_info_desc);
WP(w, void_d).data = &_landinfo_data;
- p = GetPlayer(IsValidPlayer(_local_player) ? _local_player : 0);
+ p = GetPlayer(IsValidPlayer(_local_player) ? _local_player : PLAYER_FIRST);
t = ClosestTownFromTile(tile, _patches.dist_local_authority);
old_money = p->money64;
@@ -166,7 +166,7 @@ static void Place_LandInfo(TileIndex tile)
if (td.build_date != 0) {
SetDParam(0, td.build_date);
- GetString(_landinfo_data[6], STR_BUILD_DATE, lastof(_landinfo_data[6]));
+ GetString(_landinfo_data[6], STR_BUILD_DATE, lastof(_landinfo_data[6]));
} else {
_landinfo_data[6][0] = '\0';
}
@@ -505,7 +505,7 @@ static void ErrmsgWndProc(Window *w, WindowEvent *e)
_errmsg_message_1,
238);
} else {
- const Player *p = GetPlayer(GetDParamX(_errmsg_decode_params,2));
+ const Player *p = GetPlayer((PlayerID)GetDParamX(_errmsg_decode_params,2));
DrawPlayerFace(p->face, p->player_color, 2, 16);
DrawStringMultiCenter(
@@ -1383,7 +1383,7 @@ static void GenerateFileName(void)
{
/* Check if we are not a specatator who wants to generate a name..
Let's use the name of player #0 for now. */
- const Player *p = GetPlayer(IsValidPlayer(_local_player) ? _local_player : 0);
+ const Player *p = GetPlayer(IsValidPlayer(_local_player) ? _local_player : PLAYER_FIRST);
SetDParam(0, p->name_1);
SetDParam(1, p->name_2);
@@ -1691,7 +1691,7 @@ void SetFiosType(const byte fiostype)
static int32 ClickMoneyCheat(int32 p1, int32 p2)
{
- DoCommandP(0, -10000000, 0, NULL, CMD_MONEY_CHEAT);
+ DoCommandP(0, 10000000, 0, NULL, CMD_MONEY_CHEAT);
return true;
}
@@ -1739,9 +1739,17 @@ static int32 ClickChangeDateCheat(int32 p1, int32 p2)
typedef int32 CheckButtonClick(int32, int32);
-enum ce_flags {CE_CLICK = 1 << 0};
+enum ce_flags_long
+{
+ CE_NONE = 0,
+ CE_CLICK = 1 << 0,
+ CE_END = 1 << 1,
+};
+
+/** Define basic enum properties */
+template <> struct EnumPropsT : MakeEnumPropsT {};
+typedef TinyEnumT ce_flags;
-typedef byte ce_flags;
typedef struct CheatEntry {
VarType type; // type of selector
@@ -1754,15 +1762,15 @@ typedef struct CheatEntry {
} CheatEntry;
static const CheatEntry _cheats_ui[] = {
- {SLE_BOOL,CE_CLICK, STR_CHEAT_MONEY, &_cheats.money.value, &_cheats.money.been_used, &ClickMoneyCheat, 0, 0},
- {SLE_UINT8, 0, STR_CHEAT_CHANGE_PLAYER, &_local_player, &_cheats.switch_player.been_used, &ClickChangePlayerCheat, 0, 11},
- {SLE_BOOL, 0, STR_CHEAT_EXTRA_DYNAMITE, &_cheats.magic_bulldozer.value, &_cheats.magic_bulldozer.been_used, NULL, 0, 0},
- {SLE_BOOL, 0, STR_CHEAT_CROSSINGTUNNELS,&_cheats.crossing_tunnels.value,&_cheats.crossing_tunnels.been_used,NULL, 0, 0},
- {SLE_BOOL, 0, STR_CHEAT_BUILD_IN_PAUSE, &_cheats.build_in_pause.value, &_cheats.build_in_pause.been_used, NULL, 0, 0},
- {SLE_BOOL, 0, STR_CHEAT_NO_JETCRASH, &_cheats.no_jetcrash.value, &_cheats.no_jetcrash.been_used, NULL, 0, 0},
- {SLE_BOOL, 0, STR_CHEAT_SETUP_PROD, &_cheats.setup_prod.value, &_cheats.setup_prod.been_used, NULL, 0, 0},
- {SLE_UINT8, 0, STR_CHEAT_SWITCH_CLIMATE, &_opt.landscape, &_cheats.switch_climate.been_used, &ClickChangeClimateCheat,-1, 4},
- {SLE_INT32, 0, STR_CHEAT_CHANGE_DATE, &_cur_year, &_cheats.change_date.been_used, &ClickChangeDateCheat, -1, 1},
+ {SLE_BOOL, {CE_CLICK}, STR_CHEAT_MONEY, &_cheats.money.value, &_cheats.money.been_used, &ClickMoneyCheat, 0, 0},
+ {SLE_UINT8, {CE_NONE}, STR_CHEAT_CHANGE_PLAYER, &_local_player, &_cheats.switch_player.been_used, &ClickChangePlayerCheat, 0, 11},
+ {SLE_BOOL, {CE_NONE}, STR_CHEAT_EXTRA_DYNAMITE, &_cheats.magic_bulldozer.value, &_cheats.magic_bulldozer.been_used, NULL, 0, 0},
+ {SLE_BOOL, {CE_NONE}, STR_CHEAT_CROSSINGTUNNELS,&_cheats.crossing_tunnels.value,&_cheats.crossing_tunnels.been_used,NULL, 0, 0},
+ {SLE_BOOL, {CE_NONE}, STR_CHEAT_BUILD_IN_PAUSE, &_cheats.build_in_pause.value, &_cheats.build_in_pause.been_used, NULL, 0, 0},
+ {SLE_BOOL, {CE_NONE}, STR_CHEAT_NO_JETCRASH, &_cheats.no_jetcrash.value, &_cheats.no_jetcrash.been_used, NULL, 0, 0},
+ {SLE_BOOL, {CE_NONE}, STR_CHEAT_SETUP_PROD, &_cheats.setup_prod.value, &_cheats.setup_prod.been_used, NULL, 0, 0},
+ {SLE_UINT8, {CE_NONE}, STR_CHEAT_SWITCH_CLIMATE, &_opt.landscape, &_cheats.switch_climate.been_used, &ClickChangeClimateCheat,-1, 4},
+ {SLE_INT32, {CE_NONE}, STR_CHEAT_CHANGE_DATE, &_cur_year, &_cheats.change_date.been_used, &ClickChangeDateCheat, -1, 1},
};
@@ -1801,14 +1809,14 @@ static void CheatsWndProc(Window *w, WindowEvent *e)
bool on = (*(bool*)ce->variable);
if (ce->flags & CE_CLICK) {
- DrawFrameRect(x + 20, y + 1, x + 30 + 9, y + 9, 0, (clk - (i * 2) == 1) ? FR_LOWERED : 0);
+ DrawFrameRect(x + 20, y + 1, x + 30 + 9, y + 9, 0, (clk - (i * 2) == 1) ? FR_LOWERED : FR_NONE);
if (i == 0) { // XXX - hack/hack for first element which is increase money. Told ya it's a mess
SetDParam64(0, 10000000);
} else {
SetDParam(0, false);
}
} else {
- DrawFrameRect(x + 20, y + 1, x + 30 + 9, y + 9, on ? 6 : 4, on ? FR_LOWERED : 0);
+ DrawFrameRect(x + 20, y + 1, x + 30 + 9, y + 9, on ? 6 : 4, on ? FR_LOWERED : FR_NONE);
SetDParam(0, on ? STR_CONFIG_PATCHES_ON : STR_CONFIG_PATCHES_OFF);
}
} break;
diff --git a/src/mixer.cpp b/src/mixer.cpp
index 5b97afbf9f..5037f771b3 100644
--- a/src/mixer.cpp
+++ b/src/mixer.cpp
@@ -85,7 +85,7 @@ void MxMixSamples(void *buffer, uint samples)
// Mix each channel
for (mc = _channels; mc != endof(_channels); mc++) {
if (mc->active) {
- mix_int8_to_int16(mc, buffer, samples);
+ mix_int8_to_int16(mc, (int16*)buffer, samples);
if (mc->samples_left == 0) MxCloseChannel(mc);
}
}
diff --git a/src/music/dmusic.cpp b/src/music/dmusic.cpp
index e20842d2e9..1c5b1d2003 100644
--- a/src/music/dmusic.cpp
+++ b/src/music/dmusic.cpp
@@ -4,12 +4,10 @@
#ifdef WIN32_ENABLE_DIRECTMUSIC_SUPPORT
-extern "C" {
- #include "../openttd.h"
- #include "../debug.h"
- #include "../win32.h"
- #include "dmusic.h"
-}
+#include "../openttd.h"
+#include "../debug.h"
+#include "../win32.h"
+#include "dmusic.h"
#include
#include
diff --git a/src/music_gui.cpp b/src/music_gui.cpp
index 37cd3fa798..620346e7e4 100644
--- a/src/music_gui.cpp
+++ b/src/music_gui.cpp
@@ -396,11 +396,11 @@ static void MusicWindowWndProc(Window *w, WindowEvent *e)
DrawFrameRect(214, 23, 280, 26, 14, FR_LOWERED);
DrawFrameRect(
- 108 + msf.music_vol / 2, 22, 111 + msf.music_vol / 2, 28, 14, 0
+ 108 + msf.music_vol / 2, 22, 111 + msf.music_vol / 2, 28, 14, FR_NONE
);
DrawFrameRect(
- 214 + msf.effect_vol / 2, 22, 217 + msf.effect_vol / 2, 28, 14, 0
+ 214 + msf.effect_vol / 2, 22, 217 + msf.effect_vol / 2, 28, 14, FR_NONE
);
} break;
diff --git a/src/network/core/packet.cpp b/src/network/core/packet.cpp
index d75d78c7e1..38d00d8c0c 100644
--- a/src/network/core/packet.cpp
+++ b/src/network/core/packet.cpp
@@ -5,6 +5,8 @@
#include "../../stdafx.h"
#include "../../macros.h"
#include "../../string.h"
+#include "../../helpers.hpp"
+#include "../network_data.h"
#include "packet.h"
@@ -24,7 +26,8 @@ extern void NORETURN CDECL error(const char *str, ...);
*/
Packet *NetworkSend_Init(const PacketType type)
{
- Packet *packet = malloc(sizeof(Packet));
+ Packet *packet;
+ MallocT(&packet, 1);
/* An error is inplace here, because it simply means we ran out of memory. */
if (packet == NULL) error("Failed to allocate Packet");
@@ -109,7 +112,7 @@ void NetworkSend_string(Packet *packet, const char* data)
*/
-extern uint CloseConnection(NetworkClientState *cs);
+extern NetworkRecvStatus CloseConnection(NetworkClientState *cs);
/** Is it safe to read from the packet, i.e. didn't we run over the buffer ? */
static inline bool CanReadFromPacket(NetworkClientState *cs, const Packet *packet, const uint bytes_to_read)
diff --git a/src/network/core/tcp.cpp b/src/network/core/tcp.cpp
index 9261ea0496..ce00335fea 100644
--- a/src/network/core/tcp.cpp
+++ b/src/network/core/tcp.cpp
@@ -12,6 +12,7 @@
#include "../network_data.h"
#include "packet.h"
#include "tcp.h"
+#include "../../helpers.hpp"
/**
* @file tcp.c Basic functions to receive and send TCP packets.
@@ -99,7 +100,7 @@ bool NetworkSend_Packets(NetworkClientState *cs)
p = cs->packet_queue;
while (p != NULL) {
- res = send(cs->socket, p->buffer + p->pos, p->size - p->pos, 0);
+ res = send(cs->socket, (const char*)p->buffer + p->pos, p->size - p->pos, 0);
if (res == -1) {
int err = GET_LAST_ERROR();
if (err != EWOULDBLOCK) {
@@ -148,7 +149,7 @@ Packet *NetworkRecv_Packet(NetworkClientState *cs, NetworkRecvStatus *status)
if (cs->socket == INVALID_SOCKET) return NULL;
if (cs->packet_recv == NULL) {
- cs->packet_recv = malloc(sizeof(Packet));
+ MallocT(&cs->packet_recv, 1);
if (cs->packet_recv == NULL) error("Failed to allocate packet");
/* Set pos to zero! */
cs->packet_recv->pos = 0;
@@ -161,7 +162,7 @@ Packet *NetworkRecv_Packet(NetworkClientState *cs, NetworkRecvStatus *status)
if (p->pos < sizeof(PacketSize)) {
while (p->pos < sizeof(PacketSize)) {
/* Read the size of the packet */
- res = recv(cs->socket, p->buffer + p->pos, sizeof(PacketSize) - p->pos, 0);
+ res = recv(cs->socket, (char*)p->buffer + p->pos, sizeof(PacketSize) - p->pos, 0);
if (res == -1) {
int err = GET_LAST_ERROR();
if (err != EWOULDBLOCK) {
@@ -191,7 +192,7 @@ Packet *NetworkRecv_Packet(NetworkClientState *cs, NetworkRecvStatus *status)
/* Read rest of packet */
while (p->pos < p->size) {
- res = recv(cs->socket, p->buffer + p->pos, p->size - p->pos, 0);
+ res = recv(cs->socket, (char*)p->buffer + p->pos, p->size - p->pos, 0);
if (res == -1) {
int err = GET_LAST_ERROR();
if (err != EWOULDBLOCK) {
diff --git a/src/network/core/udp.cpp b/src/network/core/udp.cpp
index 6699b4b872..91d751fd50 100644
--- a/src/network/core/udp.cpp
+++ b/src/network/core/udp.cpp
@@ -5,6 +5,7 @@
#include "../../stdafx.h"
#include "../../debug.h"
#include "../../macros.h"
+#include "../../helpers.hpp"
#include "packet.h"
#include "udp.h"
@@ -92,7 +93,7 @@ void NetworkSendUDP_Packet(const SOCKET udp, Packet *p, const struct sockaddr_in
NetworkSend_FillPacketSize(p);
/* Send the buffer */
- res = sendto(udp, p->buffer, p->size, 0, (struct sockaddr *)recv, sizeof(*recv));
+ res = sendto(udp, (const char*)p->buffer, p->size, 0, (struct sockaddr *)recv, sizeof(*recv));
/* Check for any errors, but ignore it otherwise */
if (res == -1) DEBUG(net, 1, "[udp] sendto failed with: %i", GET_LAST_ERROR());
@@ -114,7 +115,7 @@ void NetworkUDPReceive(const SOCKET udp)
client_len = sizeof(client_addr);
/* Try to receive anything */
- nbytes = recvfrom(udp, p.buffer, packet_len, 0, (struct sockaddr *)&client_addr, &client_len);
+ nbytes = recvfrom(udp, (char*)p.buffer, packet_len, 0, (struct sockaddr *)&client_addr, &client_len);
/* We got some bytes for the base header of the packet. */
if (nbytes > 2) {
@@ -256,7 +257,7 @@ void NetworkRecv_NetworkGameInfo(NetworkClientState *cs, Packet *p, NetworkGameI
uint num_grfs = NetworkRecv_uint8(cs, p);
for (i = 0; i < num_grfs; i++) {
- c = calloc(1, sizeof(*c));
+ CallocT(&c, 1);
NetworkRecv_GRFIdentifier(cs, p, c);
HandleIncomingNetworkGameInfoGRFConfig(c);
@@ -290,7 +291,7 @@ void NetworkRecv_NetworkGameInfo(NetworkClientState *cs, Packet *p, NetworkGameI
info->map_width = NetworkRecv_uint16(cs, p);
info->map_height = NetworkRecv_uint16(cs, p);
info->map_set = NetworkRecv_uint8 (cs, p);
- info->dedicated = NetworkRecv_uint8 (cs, p);
+ info->dedicated = (NetworkRecv_uint8 (cs, p) != 0);
}
}
diff --git a/src/network/network.cpp b/src/network/network.cpp
index ac8dd82b7f..443ee30666 100644
--- a/src/network/network.cpp
+++ b/src/network/network.cpp
@@ -7,9 +7,9 @@
extern const char _openttd_revision[];
#elif defined(WITH_REV_HACK)
#define WITH_REV
- const char _openttd_revision[] = WITH_REV_HACK;
+ extern const char _openttd_revision[] = WITH_REV_HACK;
#else
- const char _openttd_revision[] = NOREV_STRING;
+ extern const char _openttd_revision[] = NOREV_STRING;
#endif
@@ -38,6 +38,19 @@
#include /* va_list */
#include "../md5.h"
+// global variables (declared in network_data.h)
+CommandPacket *_local_command_queue;
+
+SOCKET _udp_client_socket; // udp client socket
+SOCKET _udp_server_socket; // udp server socket
+SOCKET _udp_master_socket; // udp master socket
+
+// Here we keep track of the clients
+// (and the client uses [0] for his own communication)
+NetworkClientState _clients[MAX_CLIENTS];
+
+
+
// The listen socket for the server
static SOCKET _listensocket;
@@ -277,7 +290,7 @@ char* GetNetworkErrorMsg(char* buf, NetworkErrorCode err, const char* last)
STR_NETWORK_ERR_CLIENT_SERVER_FULL
};
- if (err >= lengthof(network_error_strings)) err = 0;
+ if (err >= (ptrdiff_t)lengthof(network_error_strings)) err = NETWORK_ERROR_GENERAL;
return GetString(buf, network_error_strings[err], last);
}
@@ -729,7 +742,7 @@ static void NetworkAcceptClients(void)
p->buffer[0] = p->size & 0xFF;
p->buffer[1] = p->size >> 8;
- send(s, p->buffer, p->size, 0);
+ send(s, (const char*)p->buffer, p->size, 0);
closesocket(s);
free(p);
@@ -750,7 +763,7 @@ static void NetworkAcceptClients(void)
p->buffer[0] = p->size & 0xFF;
p->buffer[1] = p->size >> 8;
- send(s, p->buffer, p->size, 0);
+ send(s, (const char*)p->buffer, p->size, 0);
closesocket(s);
free(p);
@@ -1032,7 +1045,7 @@ bool NetworkServerStart(void)
_network_own_client_index = NETWORK_SERVER_INDEX;
/* Non-dedicated server will always be player #1 */
- if (!_network_dedicated) _network_playas = 0;
+ if (!_network_dedicated) _network_playas = PLAYER_FIRST;
_network_clients_connected = 0;
diff --git a/src/network/network.h b/src/network/network.h
index 0bd65c0b68..cc60ac96ee 100644
--- a/src/network/network.h
+++ b/src/network/network.h
@@ -59,7 +59,7 @@ typedef struct NetworkClientInfo {
uint16 client_index; // Index of the client (same as ClientState->index)
char client_name[NETWORK_CLIENT_NAME_LENGTH]; // Name of the client
byte client_lang; // The language of the client
- byte client_playas; // As which player is this client playing (PlayerID)
+ PlayerID client_playas; // As which player is this client playing (PlayerID)
uint32 client_ip; // IP-address of the client (so he can be banned)
Date join_date; // Gamedate the player has joined
char unique_id[NETWORK_NAME_LENGTH]; // Every play sends an unique id so we can indentify him
@@ -188,7 +188,6 @@ bool NetworkClientConnectGame(const char *host, uint16 port);
void NetworkReboot(void);
void NetworkDisconnect(void);
-VARDEF bool _networking; ///< are we in networking mode?
VARDEF bool _network_server; ///< network-server is active
VARDEF bool _network_available; ///< is network mode available?
diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp
index 6e27eec562..338d076e6c 100644
--- a/src/network/network_client.cpp
+++ b/src/network/network_client.cpp
@@ -20,7 +20,7 @@
#include "../console.h"
#include "../variables.h"
#include "../ai/ai.h"
-
+#include "../helpers.hpp"
// This file handles all the client-commands
@@ -286,14 +286,14 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_COMPANY_INFO)
if (!MY_CLIENT->has_quit && company_info_version == NETWORK_COMPANY_INFO_VERSION) {
byte total;
- byte current;
+ PlayerID current;
total = NetworkRecv_uint8(MY_CLIENT, p);
// There is no data at all..
if (total == 0) return NETWORK_RECV_STATUS_CLOSE_QUERY;
- current = NetworkRecv_uint8(MY_CLIENT, p);
+ current = (Owner)NetworkRecv_uint8(MY_CLIENT, p);
if (!IsValidPlayer(current)) return NETWORK_RECV_STATUS_CLOSE_QUERY;
NetworkRecv_string(MY_CLIENT, p, _network_player_info[current].company_name, sizeof(_network_player_info[current].company_name));
@@ -325,7 +325,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CLIENT_INFO)
{
NetworkClientInfo *ci;
uint16 index = NetworkRecv_uint16(MY_CLIENT, p);
- PlayerID playas = NetworkRecv_uint8(MY_CLIENT, p);
+ PlayerID playas = (Owner)NetworkRecv_uint8(MY_CLIENT, p);
char name[NETWORK_NAME_LENGTH];
char unique_id[NETWORK_NAME_LENGTH];
@@ -375,7 +375,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CLIENT_INFO)
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_ERROR)
{
- NetworkErrorCode error = NetworkRecv_uint8(MY_CLIENT, p);
+ NetworkErrorCode error = (NetworkErrorCode)NetworkRecv_uint8(MY_CLIENT, p);
switch (error) {
/* We made an error in the protocol, and our connection is closed.... */
@@ -410,7 +410,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_ERROR)
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_NEED_PASSWORD)
{
- NetworkPasswordType type = NetworkRecv_uint8(MY_CLIENT, p);
+ NetworkPasswordType type = (NetworkPasswordType)NetworkRecv_uint8(MY_CLIENT, p);
switch (type) {
case NETWORK_GAME_PASSWORD:
@@ -570,8 +570,9 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_SYNC)
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_COMMAND)
{
- CommandPacket *cp = malloc(sizeof(CommandPacket));
- cp->player = NetworkRecv_uint8(MY_CLIENT, p);
+ CommandPacket *cp;
+ MallocT(&cp, 1);
+ cp->player = (PlayerID)NetworkRecv_uint8(MY_CLIENT, p);
cp->cmd = NetworkRecv_uint32(MY_CLIENT, p);
cp->p1 = NetworkRecv_uint32(MY_CLIENT, p);
cp->p2 = NetworkRecv_uint32(MY_CLIENT, p);
@@ -601,9 +602,9 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CHAT)
char name[NETWORK_NAME_LENGTH], msg[MAX_TEXT_MSG_LEN];
const NetworkClientInfo *ci = NULL, *ci_to;
- NetworkAction action = NetworkRecv_uint8(MY_CLIENT, p);
+ NetworkAction action = (NetworkAction)NetworkRecv_uint8(MY_CLIENT, p);
uint16 index = NetworkRecv_uint16(MY_CLIENT, p);
- bool self_send = NetworkRecv_uint8(MY_CLIENT, p);
+ bool self_send = (NetworkRecv_uint8(MY_CLIENT, p) != 0);
NetworkRecv_string(MY_CLIENT, p, msg, MAX_TEXT_MSG_LEN);
ci_to = NetworkFindClientInfoFromIndex(index);
@@ -623,7 +624,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CHAT)
if (!IsValidPlayer(ci_to->client_playas)) return NETWORK_RECV_STATUS_OKAY;
/* fallthrough */
case NETWORK_ACTION_CHAT_COMPANY: {
- StringID str = IsValidPlayer(ci_to->client_playas) ? GetPlayer(ci_to->client_playas)->name_1 : STR_NETWORK_SPECTATORS;
+ StringID str = IsValidPlayer(ci_to->client_playas) ? GetPlayer(ci_to->client_playas)->name_1 : (uint16)STR_NETWORK_SPECTATORS;
GetString(name, str, lastof(name));
ci = NetworkFindClientInfoFromIndex(_network_own_client_index);
@@ -649,7 +650,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_ERROR_QUIT)
NetworkClientInfo *ci;
index = NetworkRecv_uint16(MY_CLIENT, p);
- GetNetworkErrorMsg(str, NetworkRecv_uint8(MY_CLIENT, p), lastof(str));
+ GetNetworkErrorMsg(str, (NetworkErrorCode)NetworkRecv_uint8(MY_CLIENT, p), lastof(str));
ci = NetworkFindClientInfoFromIndex(index);
if (ci != NULL) {
diff --git a/src/network/network_data.cpp b/src/network/network_data.cpp
index 9e5e6424d3..89011f18d3 100644
--- a/src/network/network_data.cpp
+++ b/src/network/network_data.cpp
@@ -9,11 +9,13 @@
#include "network_client.h"
#include "../command.h"
#include "../callback_table.h"
+#include "../helpers.hpp"
// Add a command to the local command queue
void NetworkAddCommandQueue(NetworkClientState *cs, CommandPacket *cp)
{
- CommandPacket* new_cp = malloc(sizeof(*new_cp));
+ CommandPacket* new_cp;
+ MallocT(&new_cp, 1);
*new_cp = *cp;
@@ -29,7 +31,8 @@ void NetworkAddCommandQueue(NetworkClientState *cs, CommandPacket *cp)
// Prepare a DoCommand to be send over the network
void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback)
{
- CommandPacket *c = malloc(sizeof(CommandPacket));
+ CommandPacket *c;
+ MallocT(&c, 1);
byte temp_callback;
c->player = _local_player;
diff --git a/src/network/network_data.h b/src/network/network_data.h
index 3e42e00cf1..2e44b8fcdb 100644
--- a/src/network/network_data.h
+++ b/src/network/network_data.h
@@ -20,7 +20,7 @@
typedef struct CommandPacket {
struct CommandPacket *next;
- PlayerID player; /// player that is executing the command
+ PlayerByte player; /// player that is executing the command
uint32 cmd; /// command being executed
uint32 p1; /// parameter p1
uint32 p2; /// parameter p2
@@ -120,15 +120,17 @@ typedef enum {
DESTTYPE_CLIENT, ///< Send message/notice to only a certain player (Private)
} DestType;
-CommandPacket *_local_command_queue;
+// following externs are instantiated at network.cpp
+extern CommandPacket *_local_command_queue;
-SOCKET _udp_client_socket; // udp client socket
-SOCKET _udp_server_socket; // udp server socket
-SOCKET _udp_master_socket; // udp master socket
+extern SOCKET _udp_client_socket; // udp client socket
+extern SOCKET _udp_server_socket; // udp server socket
+extern SOCKET _udp_master_socket; // udp master socket
// Here we keep track of the clients
// (and the client uses [0] for his own communication)
-NetworkClientState _clients[MAX_CLIENTS];
+extern NetworkClientState _clients[MAX_CLIENTS];
+
#define DEREF_CLIENT(i) (&_clients[i])
// This returns the NetworkClientInfo from a NetworkClientState
#define DEREF_CLIENT_INFO(cs) (&_network_client_info[cs - _clients])
diff --git a/src/network/network_gamelist.cpp b/src/network/network_gamelist.cpp
index a830073adb..b1b3993bb1 100644
--- a/src/network/network_gamelist.cpp
+++ b/src/network/network_gamelist.cpp
@@ -6,6 +6,7 @@
#include "../debug.h"
#include "network_data.h"
#include "../newgrf_config.h"
+#include "../helpers.hpp"
// This file handles the GameList
// Also, it handles the request to a server for data about the server
@@ -25,7 +26,7 @@ NetworkGameList *NetworkGameListAddItem(uint32 ip, uint16 port)
prev_item = item;
}
- item = malloc(sizeof(*item));
+ MallocT(&item, 1);
memset(item, 0, sizeof(*item));
item->next = NULL;
item->ip = ip;
diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp
index dd865118ee..7a6fc221bd 100644
--- a/src/network/network_gui.cpp
+++ b/src/network/network_gui.cpp
@@ -27,6 +27,7 @@
#include "../string.h"
#include "../town.h"
#include "../newgrf.h"
+#include "../helpers.hpp"
#define BGC 5
#define BTC 15
@@ -166,7 +167,7 @@ static void BuildNetworkGameList(network_ql_d *nqld)
/* Create temporary array of games to use for listing */
free(nqld->sort_list);
- nqld->sort_list = malloc(n * sizeof(nqld->sort_list[0]));
+ MallocT(&nqld->sort_list, n);
if (nqld->sort_list == NULL) error("Could not allocate memory for the network-game-sorting-list");
nqld->l.list_length = n;
@@ -221,7 +222,7 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
nd->server = NULL;
WP(w, network_ql_d).sort_list = NULL;
- ld->flags = VL_REBUILD | (_ng_sorting.order << (VL_DESC - 1));
+ ld->flags = VL_REBUILD | (_ng_sorting.order ? VL_DESC : VL_NONE);
ld->sort_type = _ng_sorting.criteria;
break;
@@ -787,19 +788,19 @@ static void ShowNetworkStartServerWindow(void)
InitializeTextBuffer(&WP(w, network_ql_d).q.text, _edit_str_buf, lengthof(_edit_str_buf), 160);
}
-static byte NetworkLobbyFindCompanyIndex(byte pos)
+static PlayerID NetworkLobbyFindCompanyIndex(byte pos)
{
- byte i;
+ PlayerID i;
/* Scroll through all _network_player_info and get the 'pos' item
that is not empty */
- for (i = 0; i < MAX_PLAYERS; i++) {
+ for (i = PLAYER_FIRST; i < MAX_PLAYERS; i++) {
if (_network_player_info[i].company_name[0] != '\0') {
if (pos-- == 0) return i;
}
}
- return 0;
+ return PLAYER_FIRST;
}
/* uses network_d WP macro */
@@ -809,7 +810,7 @@ static void NetworkLobbyWindowWndProc(Window *w, WindowEvent *e)
switch (e->event) {
case WE_CREATE:
- nd->company = (byte)-1;
+ nd->company = INVALID_PLAYER;
break;
case WE_PAINT: {
@@ -919,7 +920,7 @@ static void NetworkLobbyWindowWndProc(Window *w, WindowEvent *e)
if (id_v >= w->vscroll.cap) return;
id_v += w->vscroll.pos;
- nd->company = (id_v >= nd->server->info.companies_on) ? (byte)-1 : NetworkLobbyFindCompanyIndex(id_v);
+ nd->company = (id_v >= nd->server->info.companies_on) ? INVALID_PLAYER : NetworkLobbyFindCompanyIndex(id_v);
SetWindowDirty(w);
} break;
case 7: /* Join company */
@@ -1411,7 +1412,7 @@ static void NetworkJoinStatusWindowWndProc(Window *w, WindowEvent *e)
}
/* Draw nice progress bar :) */
- DrawFrameRect(20, 18, (int)((w->width - 20) * progress / 100), 28, 10, 0);
+ DrawFrameRect(20, 18, (int)((w->width - 20) * progress / 100), 28, 10, FR_NONE);
} break;
case WE_CLICK:
@@ -1465,9 +1466,9 @@ static void SendChat(const char *buf, DestType type, byte dest)
{
if (buf[0] == '\0') return;
if (!_network_server) {
- SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_CHAT + type, type, dest, buf);
+ SEND_COMMAND(PACKET_CLIENT_CHAT)((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf);
} else {
- NetworkServer_HandleChat(NETWORK_ACTION_CHAT + type, type, dest, buf, NETWORK_SERVER_INDEX);
+ NetworkServer_HandleChat((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf, NETWORK_SERVER_INDEX);
}
}
@@ -1635,7 +1636,7 @@ static void ChatWindowWndProc(Window *w, WindowEvent *e)
case WE_CLICK:
switch (e->we.click.widget) {
case 3: { /* Send */
- DestType type = GB(WP(w, querystr_d).caption, 0, 8);
+ DestType type = (DestType)GB(WP(w, querystr_d).caption, 0, 8);
byte dest = GB(WP(w, querystr_d).caption, 8, 8);
SendChat(WP(w, querystr_d).text.buf, type, dest);
} /* FALLTHROUGH */
@@ -1654,7 +1655,7 @@ static void ChatWindowWndProc(Window *w, WindowEvent *e)
_chat_tab_completion_active = false;
switch (HandleEditBoxKey(w, &WP(w, querystr_d), 2, e)) {
case 1: { /* Return */
- DestType type = GB(WP(w, querystr_d).caption, 0, 8);
+ DestType type = (DestType)GB(WP(w, querystr_d).caption, 0, 8);
byte dest = GB(WP(w, querystr_d).caption, 8, 8);
SendChat(WP(w, querystr_d).text.buf, type, dest);
} /* FALLTHROUGH */
diff --git a/src/network/network_gui.h b/src/network/network_gui.h
index aa4313eba8..650cf2554d 100644
--- a/src/network/network_gui.h
+++ b/src/network/network_gui.h
@@ -8,7 +8,7 @@
#include "network_data.h"
void ShowNetworkNeedPassword(NetworkPasswordType npt);
-void ShowNetworkGiveMoneyWindow(byte player); // PlayerID
+void ShowNetworkGiveMoneyWindow(PlayerID player); // PlayerID
void ShowNetworkChatQueryWindow(DestType type, byte dest);
void ShowJoinStatusWindow(void);
void ShowNetworkGameWindow(void);
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp
index 5a71091050..c7bc2069db 100644
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -22,6 +22,7 @@
#include "../station.h"
#include "../variables.h"
#include "../genworld.h"
+#include "../helpers.hpp"
// This file handles all the server-commands
@@ -571,7 +572,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_JOIN)
char name[NETWORK_CLIENT_NAME_LENGTH];
char unique_id[NETWORK_NAME_LENGTH];
NetworkClientInfo *ci;
- byte playas;
+ PlayerID playas;
NetworkLanguage client_lang;
char client_revision[NETWORK_REVISION_LENGTH];
@@ -588,8 +589,8 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_JOIN)
#endif
NetworkRecv_string(cs, p, name, sizeof(name));
- playas = NetworkRecv_uint8(cs, p);
- client_lang = NetworkRecv_uint8(cs, p);
+ playas = (Owner)NetworkRecv_uint8(cs, p);
+ client_lang = (NetworkLanguage)NetworkRecv_uint8(cs, p);
NetworkRecv_string(cs, p, unique_id, sizeof(unique_id));
if (cs->has_quit) return;
@@ -654,7 +655,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_PASSWORD)
char password[NETWORK_PASSWORD_LENGTH];
const NetworkClientInfo *ci;
- type = NetworkRecv_uint8(cs, p);
+ type = (NetworkPasswordType)NetworkRecv_uint8(cs, p);
NetworkRecv_string(cs, p, password, sizeof(password));
if (cs->status == STATUS_INACTIVE && type == NETWORK_GAME_PASSWORD) {
@@ -792,7 +793,8 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)
const NetworkClientInfo *ci;
byte callback;
- CommandPacket *cp = malloc(sizeof(CommandPacket));
+ CommandPacket *cp;
+ MallocT(&cp, 1);
// The client was never joined.. so this is impossible, right?
// Ignore the packet, give the client a warning, and close his connection
@@ -801,7 +803,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)
return;
}
- cp->player = NetworkRecv_uint8(cs, p);
+ cp->player = (Owner)NetworkRecv_uint8(cs, p);
cp->cmd = NetworkRecv_uint32(cs, p);
cp->p1 = NetworkRecv_uint32(cs, p);
cp->p2 = NetworkRecv_uint32(cs, p);
@@ -851,7 +853,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)
/* XXX - Execute the command as a valid player. Normally this would be done by a
* spectator, but that is not allowed any commands. So do an impersonation. The drawback
* of this is that the first company's last_built_tile is also updated... */
- cp->player = 0;
+ cp->player = OWNER_BEGIN;
cp->p2 = cs - _clients; // XXX - UGLY! p2 is mis-used to get the client-id in CmdPlayerCtrl
}
@@ -890,7 +892,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_ERROR)
NetworkClientState *new_cs;
char str[100];
char client_name[NETWORK_CLIENT_NAME_LENGTH];
- NetworkErrorCode errorno = NetworkRecv_uint8(cs, p);
+ NetworkErrorCode errorno = (NetworkErrorCode)NetworkRecv_uint8(cs, p);
// The client was never joined.. thank the client for the packet, but ignore it
if (cs->status < STATUS_DONE_MAP || cs->has_quit) {
@@ -1044,7 +1046,7 @@ void NetworkServer_HandleChat(NetworkAction action, DestType desttype, int dest,
if (ci != NULL && show_local) {
if (from_index == NETWORK_SERVER_INDEX) {
char name[NETWORK_NAME_LENGTH];
- StringID str = IsValidPlayer(ci_to->client_playas) ? GetPlayer(ci_to->client_playas)->name_1 : STR_NETWORK_SPECTATORS;
+ StringID str = IsValidPlayer(ci_to->client_playas) ? GetPlayer(ci_to->client_playas)->name_1 : (uint16)STR_NETWORK_SPECTATORS;
GetString(name, str, lastof(name));
NetworkTextMessage(action, GetDrawStringPlayerColor(ci_own->client_playas), true, name, "%s", msg);
} else {
@@ -1073,8 +1075,8 @@ void NetworkServer_HandleChat(NetworkAction action, DestType desttype, int dest,
DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_CHAT)
{
- NetworkAction action = NetworkRecv_uint8(cs, p);
- DestType desttype = NetworkRecv_uint8(cs, p);
+ NetworkAction action = (NetworkAction)NetworkRecv_uint8(cs, p);
+ DestType desttype = (DestType)NetworkRecv_uint8(cs, p);
int dest = NetworkRecv_uint8(cs, p);
char msg[MAX_TEXT_MSG_LEN];
diff --git a/src/network/network_udp.cpp b/src/network/network_udp.cpp
index 5caec3b423..b6bc2a9cea 100644
--- a/src/network/network_udp.cpp
+++ b/src/network/network_udp.cpp
@@ -335,7 +335,7 @@ DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_CLIENT_GET_NEWGRFS)
* the current list and do not send the other data.
* The name could be an empty string, if so take the filename. */
packet_len += sizeof(c.grfid) + sizeof(c.md5sum) +
- min(strlen((f->name != NULL && strlen(f->name) > 0) ? f->name : f->filename) + 1, NETWORK_GRF_NAME_LENGTH);
+ min(strlen((f->name != NULL && strlen(f->name) > 0) ? f->name : f->filename) + 1, (size_t)NETWORK_GRF_NAME_LENGTH);
if (packet_len > SEND_MTU - 4) { // 4 is 3 byte header + grf count in reply
break;
}
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index 5278ee6b46..48097fd822 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -30,6 +30,7 @@
#include "newgrf_config.h"
#include "newgrf_sound.h"
#include "newgrf_spritegroup.h"
+#include "helpers.hpp"
/* TTDPatch extended GRF format codec
* (c) Petr Baudis 2004 (GPL'd)
@@ -542,7 +543,7 @@ static bool RoadVehicleChangeInfo(uint engine, int numinfo, int prop, byte **buf
break;
case 0x12: /* SFX */
- FOR_EACH_OBJECT rvi[i].sfx = grf_load_byte(&buf);
+ FOR_EACH_OBJECT rvi[i].sfx = (SoundFx)grf_load_byte(&buf);
break;
case 0x13: /* Power in 10hp */
@@ -627,7 +628,7 @@ static bool ShipVehicleChangeInfo(uint engine, int numinfo, int prop, byte **buf
break;
case 0x09: /* Refittable */
- FOR_EACH_OBJECT svi[i].refittable = grf_load_byte(&buf);
+ FOR_EACH_OBJECT svi[i].refittable = (grf_load_byte(&buf) != 0);
break;
case 0x0A: /* Cost factor */
@@ -666,7 +667,7 @@ static bool ShipVehicleChangeInfo(uint engine, int numinfo, int prop, byte **buf
break;
case 0x10: /* SFX */
- FOR_EACH_OBJECT svi[i].sfx = grf_load_byte(&buf);
+ FOR_EACH_OBJECT svi[i].sfx = (SoundFx)grf_load_byte(&buf);
break;
case 0x11: /* Cargos available for refitting */
@@ -779,7 +780,7 @@ static bool AircraftVehicleChangeInfo(uint engine, int numinfo, int prop, byte *
break;
case 0x12: /* SFX */
- FOR_EACH_OBJECT avi[i].sfx = grf_load_byte(&buf);
+ FOR_EACH_OBJECT avi[i].sfx = (SoundFx)grf_load_byte(&buf);
break;
case 0x13: /* Cargos available for refitting */
@@ -841,7 +842,7 @@ static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int
}
/* Allocate station specs if necessary */
- if (_cur_grffile->stations == NULL) _cur_grffile->stations = calloc(MAX_STATIONS, sizeof(*_cur_grffile->stations));
+ if (_cur_grffile->stations == NULL) CallocT(&_cur_grffile->stations, MAX_STATIONS);
statspec = &_cur_grffile->stations[stid];
@@ -861,7 +862,7 @@ static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int
uint32 classid;
/* Property 0x08 is special; it is where the station is allocated */
- if (statspec[i] == NULL) statspec[i] = calloc(1, sizeof(*statspec[i]));
+ if (statspec[i] == NULL) CallocT(&statspec[i], 1);
/* Swap classid because we read it in BE meaning WAYP or DFLT */
classid = grf_load_dword(&buf);
@@ -875,7 +876,7 @@ static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int
uint t;
statspec->tiles = grf_load_extended(&buf);
- statspec->renderdata = calloc(statspec->tiles, sizeof(*statspec->renderdata));
+ CallocT(&statspec->renderdata, statspec->tiles);
statspec->copied_renderdata = false;
for (t = 0; t < statspec->tiles; t++) {
@@ -890,7 +891,7 @@ static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int
DrawTileSeqStruct *dtss;
// no relative bounding box support
- dts->seq = realloc((void*)dts->seq, ++seq_count * sizeof(DrawTileSeqStruct));
+ ReallocT((DrawTileSeqStruct**)&dts->seq, ++seq_count);
dtss = (DrawTileSeqStruct*) &dts->seq[seq_count - 1];
dtss->delta_x = grf_load_byte(&buf);
@@ -956,10 +957,10 @@ static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int
//debug("l %d > %d ?", length, stat->lengths);
if (length > statspec->lengths) {
- statspec->platforms = realloc(statspec->platforms, length);
+ ReallocT(&statspec->platforms, length);
memset(statspec->platforms + statspec->lengths, 0, length - statspec->lengths);
- statspec->layouts = realloc(statspec->layouts, length * sizeof(*statspec->layouts));
+ ReallocT(&statspec->layouts, length);
memset(statspec->layouts + statspec->lengths, 0,
(length - statspec->lengths) * sizeof(*statspec->layouts));
@@ -969,8 +970,7 @@ static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int
//debug("p %d > %d ?", number, stat->platforms[l]);
if (number > statspec->platforms[l]) {
- statspec->layouts[l] = realloc(statspec->layouts[l],
- number * sizeof(**statspec->layouts));
+ ReallocT(&statspec->layouts[l], number);
// We expect NULL being 0 here, but C99 guarantees that.
memset(statspec->layouts[l] + statspec->platforms[l], 0,
(number - statspec->platforms[l]) * sizeof(**statspec->layouts));
@@ -979,7 +979,7 @@ static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int
}
p = 0;
- layout = malloc(length * number);
+ MallocT(&layout, length * number);
for (l = 0; l < length; l++) {
for (p = 0; p < number; p++) {
layout[l * number + p] = grf_load_byte(&buf);
@@ -1075,7 +1075,7 @@ static bool BridgeChangeInfo(uint brid, int numinfo, int prop, byte **bufp, int
if (bridge->sprite_table == NULL) {
/* Allocate memory for sprite table pointers and zero out */
- bridge->sprite_table = calloc(7, sizeof(*bridge->sprite_table));
+ CallocT(bridge->sprite_table, 7);
}
for (; numtables-- != 0; tableid++) {
@@ -1088,7 +1088,7 @@ static bool BridgeChangeInfo(uint brid, int numinfo, int prop, byte **bufp, int
}
if (bridge->sprite_table[tableid] == NULL) {
- bridge->sprite_table[tableid] = malloc(32 * sizeof(**bridge->sprite_table));
+ MallocT(&bridge->sprite_table[tableid], 32);
}
for (sprite = 0; sprite < 32; sprite++)
@@ -1595,7 +1595,7 @@ static void NewSpriteGroup(byte *buf, int len)
if (setid >= _cur_grffile->spritegroups_count) {
// Allocate memory for new sprite group references.
- _cur_grffile->spritegroups = realloc(_cur_grffile->spritegroups, (setid + 1) * sizeof(*_cur_grffile->spritegroups));
+ ReallocT(&_cur_grffile->spritegroups, setid + 1);
// Initialise new space to NULL
for (; _cur_grffile->spritegroups_count < (setid + 1); _cur_grffile->spritegroups_count++)
_cur_grffile->spritegroups[_cur_grffile->spritegroups_count] = NULL;
@@ -1640,18 +1640,18 @@ static void NewSpriteGroup(byte *buf, int len)
}
group->g.determ.num_adjusts++;
- group->g.determ.adjusts = realloc(group->g.determ.adjusts, group->g.determ.num_adjusts * sizeof(*group->g.determ.adjusts));
+ ReallocT(&group->g.determ.adjusts, group->g.determ.num_adjusts);
adjust = &group->g.determ.adjusts[group->g.determ.num_adjusts - 1];
/* The first var adjust doesn't have an operation specified, so we set it to add. */
- adjust->operation = group->g.determ.num_adjusts == 1 ? DSGA_OP_ADD : grf_load_byte(&buf);
+ adjust->operation = group->g.determ.num_adjusts == 1 ? DSGA_OP_ADD : (DeterministicSpriteGroupAdjustOperation)grf_load_byte(&buf);
adjust->variable = grf_load_byte(&buf);
adjust->parameter = IS_BYTE_INSIDE(adjust->variable, 0x60, 0x80) ? grf_load_byte(&buf) : 0;
varadjust = grf_load_byte(&buf);
adjust->shift_num = GB(varadjust, 0, 5);
- adjust->type = GB(varadjust, 6, 2);
+ adjust->type = (DeterministicSpriteGroupAdjustType)GB(varadjust, 6, 2);
adjust->and_mask = grf_load_var(varsize, &buf);
if (adjust->type != DSGA_TYPE_NONE) {
@@ -1666,7 +1666,7 @@ static void NewSpriteGroup(byte *buf, int len)
} while (HASBIT(varadjust, 5));
group->g.determ.num_ranges = grf_load_byte(&buf);
- group->g.determ.ranges = calloc(group->g.determ.num_ranges, sizeof(*group->g.determ.ranges));
+ CallocT(&group->g.determ.ranges, group->g.determ.num_ranges);
check_length(bufend - buf, 2 + (2 + 2 * varsize) * group->g.determ.num_ranges, "NewSpriteGroup (Deterministic)");
@@ -1698,7 +1698,7 @@ static void NewSpriteGroup(byte *buf, int len)
group->g.random.cmp_mode = HASBIT(triggers, 7) ? RSG_CMP_ALL : RSG_CMP_ANY;
group->g.random.lowest_randbit = grf_load_byte(&buf);
group->g.random.num_groups = grf_load_byte(&buf);
- group->g.random.groups = calloc(group->g.random.num_groups, sizeof(*group->g.random.groups));
+ CallocT(&group->g.random.groups, group->g.random.num_groups);
check_length(bufend - buf, 2 * group->g.random.num_groups, "NewSpriteGroup (Randomized) (2)");
@@ -1738,8 +1738,8 @@ static void NewSpriteGroup(byte *buf, int len)
group->g.real.num_loaded = num_loaded;
group->g.real.num_loading = num_loading;
- if (num_loaded > 0) group->g.real.loaded = calloc(num_loaded, sizeof(*group->g.real.loaded));
- if (num_loading > 0) group->g.real.loading = calloc(num_loading, sizeof(*group->g.real.loading));
+ if (num_loaded > 0) CallocT(&group->g.real.loaded, num_loaded);
+ if (num_loading > 0) CallocT(&group->g.real.loading, num_loading);
grfmsg(6, "NewSpriteGroup: New SpriteGroup 0x%02X, %u views, %u loaded, %u loading",
setid, sprites, num_loaded, num_loading);
@@ -1884,7 +1884,7 @@ static void FeatureMapSpriteGroup(byte *buf, int len)
}
if (!wagover && last_engines_count != idcount) {
- last_engines = realloc(last_engines, idcount);
+ ReallocT(&last_engines, idcount);
last_engines_count = idcount;
}
@@ -2235,7 +2235,7 @@ static uint32 GetParamVal(byte param, uint32 *cond_val)
return _game_mode;
case 0x9A: /* Always -1 */
- return -1;
+ return UINT_MAX;
case 0x9D: /* TTD Platform, 00=TTDPatch, 01=OpenTTD */
return 1;
@@ -2249,7 +2249,7 @@ static uint32 GetParamVal(byte param, uint32 *cond_val)
/* In-game variable. */
grfmsg(1, "Unsupported in-game variable 0x%02X", param);
- return -1;
+ return UINT_MAX;
}
}
@@ -2274,7 +2274,7 @@ static void CfgApply(byte *buf, int len)
/* Check if the sprite is a pseudo sprite. We can't operate on real sprites. */
if (type == 0xFF) {
- _preload_sprite = malloc(num);
+ MallocT(&_preload_sprite, num);
FioReadBlock(_preload_sprite, num);
}
@@ -2788,7 +2788,7 @@ static void ParamSet(byte *buf, int len)
}
grfmsg(1, "GRM: Unable to allocate %d vehicles", count);
- src1 = -1;
+ src1 = UINT_MAX;
}
break;
}
@@ -3026,7 +3026,7 @@ static void DefineGotoLabel(byte *buf, int len)
check_length(len, 1, "DefineGotoLabel");
buf++; len--;
- label = malloc(sizeof(*label));
+ MallocT(&label, 1);
label->label = grf_load_byte(&buf);
label->nfo_line = _nfo_line;
label->pos = FioGetPos();
@@ -3198,7 +3198,7 @@ static void LoadFontGlyph(byte *buf, int len)
check_length(len, 1 + num_def * 4, "LoadFontGlyph");
for (i = 0; i < num_def; i++) {
- FontSize size = grf_load_byte(&buf);
+ FontSize size = (FontSize)grf_load_byte(&buf);
uint8 num_char = grf_load_byte(&buf);
uint16 base_char = grf_load_word(&buf);
uint c;
@@ -3489,7 +3489,7 @@ static void InitNewGRFFile(const GRFConfig *config, int sprite_offset)
return;
}
- newfile = calloc(1, sizeof(*newfile));
+ CallocT(&newfile, 1);
if (newfile == NULL) error ("Out of memory");
@@ -3617,7 +3617,7 @@ static void DecodeSpecialSprite(uint num, GrfLoadingStage stage)
if (_preload_sprite == NULL) {
/* No preloaded sprite to work with; allocate and read the
* pseudo sprite content. */
- buf = malloc(num);
+ MallocT(&buf, num);
if (buf == NULL) error("DecodeSpecialSprite: Could not allocate memory");
FioReadBlock(buf, num);
} else {
@@ -3770,3 +3770,4 @@ void LoadNewGRF(uint load_index, uint file_index)
}
+
diff --git a/src/newgrf.h b/src/newgrf.h
index 1d8c5a3659..697ef9fc02 100644
--- a/src/newgrf.h
+++ b/src/newgrf.h
@@ -5,6 +5,7 @@
#include "station.h"
#include "newgrf_config.h"
+#include "helpers.hpp"
typedef enum GrfLoadingStage {
GLS_FILESCAN,
@@ -15,6 +16,9 @@ typedef enum GrfLoadingStage {
GLS_END,
} GrfLoadingStage;
+DECLARE_POSTFIX_INCREMENT(GrfLoadingStage);
+
+
typedef struct GRFLabel {
byte label;
uint32 nfo_line;
diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp
index 977cb139e6..c624328dd1 100644
--- a/src/newgrf_config.cpp
+++ b/src/newgrf_config.cpp
@@ -12,6 +12,7 @@
#include "network/network_data.h"
#include "newgrf.h"
#include "newgrf_config.h"
+#include "helpers.hpp"
#include "fileio.h"
#include "fios.h"
@@ -123,7 +124,7 @@ GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src)
/* Clear destination as it will be overwritten */
ClearGRFConfigList(dst);
for (; src != NULL; src = src->next) {
- c = calloc(1, sizeof(*c));
+ CallocT(&c, 1);
*c = *src;
if (src->filename != NULL) c->filename = strdup(src->filename);
if (src->name != NULL) c->name = strdup(src->name);
@@ -269,7 +270,7 @@ static uint ScanPath(const char *path)
if (ext == NULL) continue;
if (strcasecmp(ext, ".grf") != 0) continue;
- c = calloc(1, sizeof(*c));
+ CallocT(&c, 1);
c->filename = strdup(file);
if (FillGRFDetails(c, false)) {
@@ -374,7 +375,7 @@ char *FindUnknownGRFName(uint32 grfid, uint8 *md5sum, bool create)
if (!create) return NULL;
- grf = calloc(1, sizeof(*grf));
+ CallocT(&grf, 1);
grf->grfid = grfid;
grf->next = unknown_grfs;
ttd_strlcpy(grf->name, UNKNOWN_GRF_NAME_PLACEHOLDER, sizeof(grf->name));
@@ -445,7 +446,8 @@ static void Load_NGRF(void)
GRFConfig **last = &first;
while (SlIterateArray() != -1) {
- GRFConfig *c = calloc(1, sizeof(*c));
+ GRFConfig *c;
+ CallocT(&c, 1);
SlObject(c, _grfconfig_desc);
/* Append our configuration to the list */
@@ -461,7 +463,7 @@ static void Load_NGRF(void)
AppendStaticGRFConfigs(&_grfconfig);
}
-const ChunkHandler _newgrf_chunk_handlers[] = {
+extern const ChunkHandler _newgrf_chunk_handlers[] = {
{ 'NGRF', Save_NGRF, Load_NGRF, CH_ARRAY | CH_LAST }
};
diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp
index 0662f3fc89..5b0fa51793 100644
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -17,6 +17,7 @@
#include "newgrf_spritegroup.h"
#include "newgrf_cargo.h"
#include "date.h"
+#include "helpers.hpp"
@@ -82,8 +83,7 @@ void SetWagonOverrideSprites(EngineID engine, CargoID cargo, const SpriteGroup *
wos = &_engine_wagon_overrides[engine];
wos->overrides_count++;
- wos->overrides = realloc(wos->overrides,
- wos->overrides_count * sizeof(*wos->overrides));
+ ReallocT(&wos->overrides, wos->overrides_count);
wo = &wos->overrides[wos->overrides_count - 1];
/* FIXME: If we are replacing an override, release original SpriteGroup
@@ -92,7 +92,7 @@ void SetWagonOverrideSprites(EngineID engine, CargoID cargo, const SpriteGroup *
wo->group = group;
wo->cargo = cargo;
wo->trains = trains;
- wo->train_id = malloc(trains);
+ MallocT(&wo->train_id, trains);
memcpy(wo->train_id, train_id, trains);
}
@@ -563,7 +563,7 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
}
*available = false;
- return -1;
+ return UINT_MAX;
}
/* Calculated vehicle parameters */
@@ -628,7 +628,7 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
return v->owner;
case 0x44: /* Aircraft information */
- if (v->type != VEH_Aircraft) return -1;
+ if (v->type != VEH_Aircraft) return UINT_MAX;
{
const Vehicle *w = v->next;
@@ -806,7 +806,7 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
DEBUG(grf, 1, "Unhandled vehicle property 0x%X, type 0x%X", variable, v->type);
*available = false;
- return -1;
+ return UINT_MAX;
}
diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp
index 4ae7342078..7eb63d7226 100644
--- a/src/newgrf_gui.cpp
+++ b/src/newgrf_gui.cpp
@@ -11,6 +11,7 @@
#include "table/sprites.h"
#include "newgrf.h"
#include "newgrf_config.h"
+#include "helpers.hpp"
/** Parse an integerlist string and set each found value
@@ -164,7 +165,7 @@ static void NewGRFAddDlgWndProc(Window *w, WindowEvent *e)
}
/* Copy GRF details from scanned list */
- c = calloc(1, sizeof(*c));
+ CallocT(&c, 1);
*c = *src;
c->filename = strdup(src->filename);
if (src->name != NULL) c->name = strdup(src->name);
diff --git a/src/newgrf_sound.cpp b/src/newgrf_sound.cpp
index e96934104e..16990faf56 100644
--- a/src/newgrf_sound.cpp
+++ b/src/newgrf_sound.cpp
@@ -63,6 +63,6 @@ bool PlayVehicleSound(const Vehicle *v, VehicleSoundEvent event)
if (callback == CALLBACK_FAILED) return false;
if (callback >= GetNumOriginalSounds()) callback += file->sound_offset - GetNumOriginalSounds();
- if (callback < GetNumSounds()) SndPlayVehicleFx(callback, v);
+ if (callback < GetNumSounds()) SndPlayVehicleFx((SoundFx)callback, v);
return true;
}
diff --git a/src/newgrf_spritegroup.cpp b/src/newgrf_spritegroup.cpp
index f97da9c90f..096ed21c53 100644
--- a/src/newgrf_spritegroup.cpp
+++ b/src/newgrf_spritegroup.cpp
@@ -81,7 +81,7 @@ static inline uint32 GetVariable(const ResolverObject *object, byte variable, by
case 0x10: return object->callback_param1;
case 0x11: return 0;
case 0x18: return object->callback_param2;
- case 0x1A: return -1;
+ case 0x1A: return (uint32)-1;
case 0x1B: return GB(_display_opt, 0, 6);
case 0x1C: return object->last_value;
case 0x20: return _opt.landscape == LT_HILLY ? _opt.snow_line : 0xFF;
diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp
index f36769a41b..0ef1ec84ed 100644
--- a/src/newgrf_station.cpp
+++ b/src/newgrf_station.cpp
@@ -17,6 +17,7 @@
#include "newgrf_station.h"
#include "newgrf_spritegroup.h"
#include "date.h"
+#include "helpers.hpp"
static StationClass station_classes[STAT_CLASS_MAX];
@@ -31,8 +32,7 @@ enum {
*/
void ResetStationClasses(void)
{
- StationClassID i;
- for (i = 0; i < STAT_CLASS_MAX; i++) {
+ for (StationClassID i = STAT_CLASS_BEGIN; i < STAT_CLASS_MAX; i++) {
station_classes[i].id = 0;
station_classes[i].name = STR_EMPTY;
station_classes[i].stations = 0;
@@ -45,13 +45,13 @@ void ResetStationClasses(void)
station_classes[0].id = 'DFLT';
station_classes[0].name = STR_STAT_CLASS_DFLT;
station_classes[0].stations = 1;
- station_classes[0].spec = malloc(sizeof(*station_classes[0].spec));
+ MallocT(&station_classes[0].spec, 1);
station_classes[0].spec[0] = NULL;
station_classes[1].id = 'WAYP';
station_classes[1].name = STR_STAT_CLASS_WAYP;
station_classes[1].stations = 1;
- station_classes[1].spec = malloc(sizeof(*station_classes[1].spec));
+ MallocT(&station_classes[1].spec, 1);
station_classes[1].spec[0] = NULL;
}
@@ -60,17 +60,15 @@ void ResetStationClasses(void)
* @param classid A 32 bit value identifying the class.
* @return Index into station_classes of allocated class.
*/
-StationClassID AllocateStationClass(uint32 class)
+StationClassID AllocateStationClass(uint32 cls)
{
- StationClassID i;
-
- for (i = 0; i < STAT_CLASS_MAX; i++) {
- if (station_classes[i].id == class) {
+ for (StationClassID i = STAT_CLASS_BEGIN; i < STAT_CLASS_MAX; i++) {
+ if (station_classes[i].id == cls) {
// ClassID is already allocated, so reuse it.
return i;
} else if (station_classes[i].id == 0) {
// This class is empty, so allocate it to the ClassID.
- station_classes[i].id = class;
+ station_classes[i].id = cls;
return i;
}
}
@@ -150,7 +148,7 @@ void SetCustomStationSpec(StationSpec *statspec)
station_class = &station_classes[statspec->sclass];
i = station_class->stations++;
- station_class->spec = realloc(station_class->spec, station_class->stations * sizeof(*station_class->spec));
+ ReallocT(&station_class->spec, station_class->stations);
station_class->spec[i] = statspec;
statspec->allocated = true;
@@ -176,10 +174,9 @@ const StationSpec *GetCustomStationSpec(StationClassID sclass, uint station)
const StationSpec *GetCustomStationSpecByGrf(uint32 grfid, byte localidx)
{
- StationClassID i;
uint j;
- for (i = STAT_CLASS_DFLT; i < STAT_CLASS_MAX; i++) {
+ for (StationClassID i = STAT_CLASS_BEGIN; i < STAT_CLASS_MAX; i++) {
for (j = 0; j < station_classes[i].stations; j++) {
const StationSpec *statspec = station_classes[i].spec[j];
if (statspec == NULL) continue;
@@ -364,7 +361,7 @@ static uint32 StationGetVariable(const ResolverObject *object, byte variable, by
}
*available = false;
- return -1;
+ return UINT_MAX;
}
switch (variable) {
@@ -430,7 +427,7 @@ static uint32 StationGetVariable(const ResolverObject *object, byte variable, by
DEBUG(grf, 1, "Unhandled station property 0x%X", variable);
*available = false;
- return -1;
+ return UINT_MAX;
}
@@ -610,7 +607,7 @@ int AllocateSpecToStation(const StationSpec *statspec, Station *st, bool exec)
if (exec) {
if (i >= st->num_specs) {
st->num_specs = i + 1;
- st->speclist = realloc(st->speclist, st->num_specs * sizeof(*st->speclist));
+ ReallocT(&st->speclist, st->num_specs);
if (st->num_specs == 2) {
/* Initial allocation */
@@ -656,7 +653,7 @@ void DeallocateSpecFromStation(Station* st, byte specindex)
for (; st->speclist[st->num_specs - 1].grfid == 0 && st->num_specs > 1; st->num_specs--);
if (st->num_specs > 1) {
- st->speclist = realloc(st->speclist, st->num_specs * sizeof(*st->speclist));
+ ReallocT(&st->speclist, st->num_specs);
} else {
free(st->speclist);
st->num_specs = 0;
@@ -696,7 +693,7 @@ bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID
if (statspec->renderdata == NULL) {
sprites = GetStationTileLayout(tile + axis);
} else {
- sprites = &statspec->renderdata[(tile < statspec->tiles) ? tile + axis : axis];
+ sprites = &statspec->renderdata[(tile < statspec->tiles) ? tile + axis : (uint)axis];
}
image = sprites->ground_sprite;
diff --git a/src/newgrf_station.h b/src/newgrf_station.h
index a133fb3d70..f504bdd2b6 100644
--- a/src/newgrf_station.h
+++ b/src/newgrf_station.h
@@ -7,13 +7,22 @@
#include "engine.h"
#include "newgrf_cargo.h"
+#include "helpers.hpp"
typedef enum {
- STAT_CLASS_DFLT, ///< Default station class.
- STAT_CLASS_WAYP, ///< Waypoint class.
- STAT_CLASS_MAX = 32, ///< Maximum number of classes.
+ STAT_CLASS_BEGIN = 0, ///< the lowest valid value
+ STAT_CLASS_DFLT = 0, ///< Default station class.
+ STAT_CLASS_WAYP, ///< Waypoint class.
+ STAT_CLASS_MAX = 32, ///< Maximum number of classes.
} StationClassID;
+/** Define basic enum properties */
+template <> struct EnumPropsT : MakeEnumPropsT {};
+typedef TinyEnumT StationClassIDByte;
+
+/** Allow incrementing of StationClassID variables */
+DECLARE_POSTFIX_INCREMENT(StationClassID);
+
/* Station layout for given dimensions - it is a two-dimensional array
* where index is computed as (x * platforms) + platform. */
typedef byte *StationLayout;
diff --git a/src/newgrf_text.cpp b/src/newgrf_text.cpp
index e859f6e6c5..af1dc688a4 100644
--- a/src/newgrf_text.cpp
+++ b/src/newgrf_text.cpp
@@ -20,6 +20,7 @@
#include "newgrf.h"
#include "newgrf_text.h"
#include "table/control_codes.h"
+#include "helpers.hpp"
#define GRFTAB 28
#define TABSIZE 11
@@ -157,7 +158,8 @@ static byte _currentLangID = GRFLX_ENGLISH; //by default, english is used.
char *TranslateTTDPatchCodes(const char *str)
{
- char *tmp = malloc(strlen(str) * 10 + 1); /* Allocate space to allow for expansion */
+ char *tmp;
+ MallocT(&tmp, strlen(str) * 10 + 1); /* Allocate space to allow for expansion */
char *d = tmp;
bool unicode = false;
WChar c;
@@ -253,7 +255,8 @@ char *TranslateTTDPatchCodes(const char *str)
}
*d = '\0';
- return realloc(tmp, strlen(tmp) + 1);
+ ReallocT(&tmp, strlen(tmp) + 1);
+ return tmp;
}
@@ -295,7 +298,7 @@ StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid_to_add, bool ne
translatedtext = TranslateTTDPatchCodes(text_to_add);
- newtext = malloc(sizeof(*newtext) + strlen(translatedtext) + 1);
+ newtext = (GRFText*)malloc(sizeof(*newtext) + strlen(translatedtext) + 1);
newtext->next = NULL;
newtext->langid = langid_to_add;
strcpy(newtext->text, translatedtext);
diff --git a/src/news_gui.cpp b/src/news_gui.cpp
index 677a87765d..df3936af14 100644
--- a/src/news_gui.cpp
+++ b/src/news_gui.cpp
@@ -74,6 +74,7 @@ static DrawNewsCallbackProc * const _draw_news_callback[] = {
DrawNewsBankrupcy, /* DNC_BANKRUPCY */
};
+extern GetNewsStringCallbackProc * const _get_news_string_callback[];
GetNewsStringCallbackProc * const _get_news_string_callback[] = {
GetNewsStringNewTrainAvail, /* DNC_TRAINAVAIL */
GetNewsStringNewRoadVehAvail, /* DNC_ROADAVAIL */
@@ -218,7 +219,7 @@ static void NewsWindowProc(Window *w, WindowEvent *e)
if (w->viewport != NULL)
w->viewport->top += y - w->top;
- diff = abs(w->top - y);
+ diff = delta(w->top, y);
w->top = y;
SetDirtyBlocks(w->left, w->top - diff, w->left + w->width, w->top + w->height);
@@ -367,14 +368,14 @@ static WindowDesc _news_type0_desc = {
static const SoundFx _news_sounds[] = {
SND_1D_APPLAUSE,
SND_1D_APPLAUSE,
- 0,
- 0,
- 0,
- 0,
+ SND_BEGIN,
+ SND_BEGIN,
+ SND_BEGIN,
+ SND_BEGIN,
SND_1E_OOOOH,
- 0,
- 0,
- 0
+ SND_BEGIN,
+ SND_BEGIN,
+ SND_BEGIN
};
/** Get the value of an item of the news-display settings. This is
@@ -752,7 +753,7 @@ static void MessageOptionsWndProc(Window *w, WindowEvent *e)
for (i = 0, y = 26; i != 10; i++, y += 12, click_state >>= 1, val >>= 2) {
bool clicked = !!(click_state & 1);
- DrawFrameRect(13, y, 89, 11 + y, 3, (clicked) ? FR_LOWERED : 0);
+ DrawFrameRect(13, y, 89, 11 + y, 3, (clicked) ? FR_LOWERED : FR_NONE);
DrawStringCentered(((13 + 89 + 1) >> 1) + clicked, ((y + 11 + y + 1) >> 1) - 5 + clicked, message_opt[val & 0x3], 0x10);
DrawString(103, y + 1, i + STR_0206_ARRIVAL_OF_FIRST_VEHICLE, 0);
}
diff --git a/src/npf.cpp b/src/npf.cpp
index 97b9bf367a..4e2cba0a40 100644
--- a/src/npf.cpp
+++ b/src/npf.cpp
@@ -37,8 +37,8 @@ static const uint _trackdir_length[TRACKDIR_END] = {
*/
static uint NPFDistanceTrack(TileIndex t0, TileIndex t1)
{
- const uint dx = abs(TileX(t0) - TileX(t1));
- const uint dy = abs(TileY(t0) - TileY(t1));
+ const uint dx = delta(TileX(t0), TileX(t1));
+ const uint dy = delta(TileY(t0), TileY(t1));
const uint straightTracks = 2 * min(dx, dy); /* The number of straight (not full length) tracks */
/* OPTIMISATION:
@@ -74,7 +74,7 @@ static uint NPFHash(uint key1, uint key2)
uint part1 = TileX(key1) & NPF_HASH_HALFMASK;
uint part2 = TileY(key1) & NPF_HASH_HALFMASK;
- assert(IsValidTrackdir(key2));
+ assert(IsValidTrackdir((Trackdir)key2));
assert(IsValidTile(key1));
return ((part1 << NPF_HASH_HALFBITS | part2) + (NPF_HASH_SIZE * key2 / TRACKDIR_END)) % NPF_HASH_SIZE;
}
@@ -137,7 +137,7 @@ static int32 NPFCalcStationOrTileHeuristic(AyStar* as, AyStarNode* current, Open
if (dist < ftd->best_bird_dist) {
ftd->best_bird_dist = dist;
- ftd->best_trackdir = current->user_data[NPF_TRACKDIR_CHOICE];
+ ftd->best_trackdir = (Trackdir)current->user_data[NPF_TRACKDIR_CHOICE];
}
return dist;
}
@@ -188,7 +188,7 @@ static inline uint NPFBridgeCost(AyStarNode *current)
static uint NPFSlopeCost(AyStarNode* current)
{
- TileIndex next = current->tile + TileOffsByDiagDir(TrackdirToExitdir(current->direction));
+ TileIndex next = current->tile + TileOffsByDiagDir(TrackdirToExitdir((Trackdir)current->direction));
int x,y;
int8 z1,z2;
@@ -290,7 +290,7 @@ static int32 NPFRoadPathCost(AyStar* as, AyStarNode* current, OpenListNode* pare
/* Check for turns. Road vehicles only really drive diagonal, turns are
* represented by non-diagonal tracks */
- if (!IsDiagonalTrackdir(current->direction))
+ if (!IsDiagonalTrackdir((Trackdir)current->direction))
cost += _patches.npf_road_curve_penalty;
NPFMarkTile(tile);
@@ -403,7 +403,7 @@ static int32 NPFFindDepot(AyStar* as, OpenListNode *current)
{
/* It's not worth caching the result with NPF_FLAG_IS_TARGET here as below,
* since checking the cache not that much faster than the actual check */
- return IsTileDepotType(current->path.node.tile, as->user_data[NPF_TYPE]) ?
+ return IsTileDepotType(current->path.node.tile, (TransportType)as->user_data[NPF_TYPE]) ?
AYSTAR_FOUND_END_NODE : AYSTAR_DONE;
}
@@ -511,8 +511,9 @@ static void NPFFollowTrack(AyStar* aystar, OpenListNode* current)
DiagDirection src_exitdir = TrackdirToExitdir(src_trackdir);
TileIndex dst_tile = INVALID_TILE;
int i;
- TrackdirBits trackdirbits, ts;
- TransportType type = aystar->user_data[NPF_TYPE];
+ uint32 ts;
+ TrackdirBits trackdirbits;
+ TransportType type = (TransportType)aystar->user_data[NPF_TYPE];
bool override_dst_check = false;
/* Initialize to 0, so we can jump out (return) somewhere an have no neighbours */
aystar->num_neighbours = 0;
@@ -587,13 +588,13 @@ static void NPFFollowTrack(AyStar* aystar, OpenListNode* current)
/* check correct rail type (mono, maglev, etc) */
if (type == TRANSPORT_RAIL) {
- RailType dst_type = GetTileRailType(dst_tile, src_trackdir);
+ RailType dst_type = GetTileRailType(dst_tile, TrackdirToTrack(src_trackdir));
if (!HASBIT(aystar->user_data[NPF_RAILTYPES], dst_type))
return;
}
/* Check the owner of the tile */
- if (!VehicleMayEnterTile(aystar->user_data[NPF_OWNER], dst_tile, TrackdirToExitdir(src_trackdir))) {
+ if (!VehicleMayEnterTile((Owner)aystar->user_data[NPF_OWNER], dst_tile, TrackdirToExitdir(src_trackdir))) {
return;
}
@@ -614,7 +615,7 @@ static void NPFFollowTrack(AyStar* aystar, OpenListNode* current)
} else {
ts = GetTileTrackStatus(dst_tile, type);
}
- trackdirbits = ts & TRACKDIR_BIT_MASK; /* Filter out signal status and the unused bits */
+ trackdirbits = (TrackdirBits)(ts & TRACKDIR_BIT_MASK); /* Filter out signal status and the unused bits */
DEBUG(npf, 4, "Next node: (%d, %d) [%d], possible trackdirs: 0x%X", TileX(dst_tile), TileY(dst_tile), dst_tile, trackdirbits);
/* Select only trackdirs we can reach from our current trackdir */
@@ -627,9 +628,7 @@ static void NPFFollowTrack(AyStar* aystar, OpenListNode* current)
i = 0;
/* Enumerate possible track */
while (trackdirbits != 0) {
- Trackdir dst_trackdir;
- dst_trackdir = FindFirstBit2x64(trackdirbits);
- trackdirbits = KillFirstBit2x64(trackdirbits);
+ Trackdir dst_trackdir = RemoveFirstTrackdir(trackdirbits);
DEBUG(npf, 5, "Expanded into trackdir: %d, remaining trackdirs: 0x%X", dst_trackdir, trackdirbits);
/* Check for oneway signal against us */
@@ -739,7 +738,7 @@ NPFFoundTargetData NPFRouteToStationOrTileTwoWay(TileIndex tile1, Trackdir track
NPFFoundTargetData NPFRouteToStationOrTile(TileIndex tile, Trackdir trackdir, NPFFindStationOrTileData* target, TransportType type, Owner owner, RailTypeMask railtypes)
{
- return NPFRouteToStationOrTileTwoWay(tile, trackdir, INVALID_TILE, 0, target, type, owner, railtypes);
+ return NPFRouteToStationOrTileTwoWay(tile, trackdir, INVALID_TILE, INVALID_TRACKDIR, target, type, owner, railtypes);
}
NPFFoundTargetData NPFRouteToDepotBreadthFirstTwoWay(TileIndex tile1, Trackdir trackdir1, TileIndex tile2, Trackdir trackdir2, TransportType type, Owner owner, RailTypeMask railtypes, uint reverse_penalty)
@@ -763,7 +762,7 @@ NPFFoundTargetData NPFRouteToDepotBreadthFirstTwoWay(TileIndex tile1, Trackdir t
NPFFoundTargetData NPFRouteToDepotBreadthFirst(TileIndex tile, Trackdir trackdir, TransportType type, Owner owner, RailTypeMask railtypes)
{
- return NPFRouteToDepotBreadthFirstTwoWay(tile, trackdir, INVALID_TILE, 0, type, owner, railtypes, 0);
+ return NPFRouteToDepotBreadthFirstTwoWay(tile, trackdir, INVALID_TILE, INVALID_TRACKDIR, type, owner, railtypes, 0);
}
NPFFoundTargetData NPFRouteToDepotTrialError(TileIndex tile, Trackdir trackdir, TransportType type, Owner owner, RailTypeMask railtypes)
@@ -827,7 +826,7 @@ NPFFoundTargetData NPFRouteToDepotTrialError(TileIndex tile, Trackdir trackdir,
best_result.best_bird_dist = (uint)-1;
/* Just iterate the depots in order of increasing distance */
- while ((current = depots.pop(&depots))) {
+ while ((current = (Depot*)depots.pop(&depots))) {
/* Check to see if we already have a path shorter than this
* depot's manhattan distance. HACK: We call DistanceManhattan
* again, we should probably modify the queue to give us that
diff --git a/src/oldloader.cpp b/src/oldloader.cpp
index f6a56fdd6a..98a1e9223d 100644
--- a/src/oldloader.cpp
+++ b/src/oldloader.cpp
@@ -80,6 +80,8 @@ typedef enum OldChunkTypes {
OC_END = 0 ///< End of the whole chunk, all 32bits set to zero
} OldChunkType;
+DECLARE_ENUM_AS_BIT_SET(OldChunkType);
+
typedef bool OldChunkProc(LoadgameState *ls, int num);
typedef struct OldChunks {
@@ -97,9 +99,9 @@ assert_compile(sizeof(TileIndex) == 4);
static uint32 _bump_assert_value;
static bool _read_ttdpatch_flags;
-static OldChunkType GetOldChunkType(OldChunkType type) {return GB(type, 0, 8);}
-static OldChunkType GetOldChunkVarType(OldChunkType type) {return GB(type, 8, 8) << 8;}
-static OldChunkType GetOldChunkFileType(OldChunkType type) {return GB(type, 16, 8) << 16;}
+static OldChunkType GetOldChunkType(OldChunkType type) {return (OldChunkType)GB(type, 0, 8);}
+static OldChunkType GetOldChunkVarType(OldChunkType type) {return (OldChunkType)(GB(type, 8, 8) << 8);}
+static OldChunkType GetOldChunkFileType(OldChunkType type) {return (OldChunkType)(GB(type, 16, 8) << 16);}
static inline byte CalcOldVarLen(OldChunkType type)
{
@@ -189,10 +191,10 @@ static inline uint32 ReadUint32(LoadgameState *ls)
static bool LoadChunk(LoadgameState *ls, void *base, const OldChunks *chunks)
{
const OldChunks *chunk = chunks;
- byte *base_ptr = base;
+ byte *base_ptr = (byte*)base;
while (chunk->type != OC_END) {
- byte* ptr = chunk->ptr;
+ byte* ptr = (byte*)chunk->ptr;
uint i;
for (i = 0; i < chunk->amount; i++) {
@@ -959,9 +961,9 @@ static const OldChunks player_chunk[] = {
static bool LoadOldPlayer(LoadgameState *ls, int num)
{
- Player *p = GetPlayer(num);
+ Player *p = GetPlayer((PlayerID)num);
- _current_player_id = num;
+ _current_player_id = (PlayerID)num;
if (!LoadChunk(ls, p, player_chunk)) return false;
@@ -996,7 +998,7 @@ static bool LoadOldPlayer(LoadgameState *ls, int num)
* really figured out as of now, p->ai.cur_veh; needed for 'sell vehicle'
* is NULL and the function will crash. To fix this, just change the state
* to some harmless state, like 'loop vehicle'; 1 */
- if (!IsHumanPlayer(num) && p->ai.state == 20) p->ai.state = 1;
+ if (!IsHumanPlayer((PlayerID)num) && p->ai.state == 20) p->ai.state = 1;
if (p->is_ai && (!_networking || _network_server) && _ai.enabled)
AI_StartNewAI(p->index);
diff --git a/src/oldpool.cpp b/src/oldpool.cpp
index 2b2d188e88..d19aa684ee 100644
--- a/src/oldpool.cpp
+++ b/src/oldpool.cpp
@@ -5,6 +5,7 @@
#include "debug.h"
#include "functions.h"
#include "oldpool.h"
+#include "helpers.hpp"
/**
* Clean a pool in a safe way (does free all blocks)
@@ -49,11 +50,11 @@ bool AddBlockToPool(OldMemoryPool *pool)
DEBUG(misc, 4, "[Pool] (%s) increasing size of pool to %d items (%d bytes)", pool->name, pool->total_items, pool->total_items * pool->item_size);
/* Increase the poolsize */
- pool->blocks = realloc(pool->blocks, sizeof(pool->blocks[0]) * (pool->current_blocks + 1));
+ ReallocT(&pool->blocks, pool->current_blocks + 1);
if (pool->blocks == NULL) error("Pool: (%s) could not allocate memory for blocks", pool->name);
/* Allocate memory to the new block item */
- pool->blocks[pool->current_blocks] = malloc(pool->item_size * (1 << pool->block_size_bits));
+ MallocT(&pool->blocks[pool->current_blocks], pool->item_size * (1 << pool->block_size_bits));
if (pool->blocks[pool->current_blocks] == NULL)
error("Pool: (%s) could not allocate memory for blocks", pool->name);
diff --git a/src/oldpool.h b/src/oldpool.h
index ba22e4ef4b..b6f5385daf 100644
--- a/src/oldpool.h
+++ b/src/oldpool.h
@@ -16,11 +16,11 @@ typedef void OldMemoryPoolCleanBlock(uint start_item, uint end_item);
* please try to avoid manual calls!
*/
struct OldMemoryPool {
- const char* const name; ///< Name of the pool (just for debugging)
+ const char* name; ///< Name of the pool (just for debugging)
- const uint max_blocks; ///< The max amount of blocks this pool can have
- const uint block_size_bits; ///< The size of each block in bits
- const uint item_size; ///< How many bytes one block is
+ uint max_blocks; ///< The max amount of blocks this pool can have
+ uint block_size_bits; ///< The size of each block in bits
+ uint item_size; ///< How many bytes one block is
/// Pointer to a function that is called after a new block is added
OldMemoryPoolNewBlock *new_block_proc;
diff --git a/src/openttd.cpp b/src/openttd.cpp
index a7604801ae..c1a66a555e 100644
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -1,6 +1,7 @@
/* $Id$ */
#include "stdafx.h"
+#define VARDEF
#include "string.h"
#include "table/strings.h"
#include "debug.h"
@@ -10,8 +11,8 @@
#include "map.h"
#include "tile.h"
#include "void_map.h"
+#include "helpers.hpp"
-#define VARDEF
#include "openttd.h"
#include "bridge_map.h"
#include "functions.h"
@@ -73,7 +74,7 @@ void InitializeStations(void);
void DeleteAllPlayerStations(void);
extern void SetDifficultyLevel(int mode, GameOptions *gm_opt);
-extern void DoStartupNewPlayer(bool is_ai);
+extern Player* DoStartupNewPlayer(bool is_ai);
extern void ShowOSErrorBox(const char *buf);
/* TODO: usrerror() for errors which are not of an internal nature but
@@ -119,7 +120,7 @@ void *ReadFileToMem(const char *filename, size_t *lenp, size_t maxsize)
fseek(in, 0, SEEK_END);
len = ftell(in);
fseek(in, 0, SEEK_SET);
- if (len > maxsize || (mem = malloc(len + 1)) == NULL) {
+ if (len > maxsize || !MallocT(&mem, len + 1)) {
fclose(in);
return NULL;
}
@@ -135,9 +136,9 @@ void *ReadFileToMem(const char *filename, size_t *lenp, size_t maxsize)
return mem;
}
+extern const char _openttd_revision[];
static void showhelp(void)
{
- extern const char _openttd_revision[];
char buf[4096], *p;
p = buf;
@@ -175,25 +176,26 @@ static void showhelp(void)
}
-typedef struct {
+struct MyGetOptData {
char *opt;
int numleft;
char **argv;
const char *options;
- char *cont;
-} MyGetOptData;
+ const char *cont;
-static void MyGetOptInit(MyGetOptData *md, int argc, char **argv, const char *options)
-{
- md->cont = NULL;
- md->numleft = argc;
- md->argv = argv;
- md->options = options;
-}
+ MyGetOptData(int argc, char **argv, const char *options)
+ {
+ opt = NULL;
+ numleft = argc;
+ this->argv = argv;
+ this->options = options;
+ cont = NULL;
+ }
+};
static int MyGetOpt(MyGetOptData *md)
{
- char *s,*r,*t;
+ const char *s,*r,*t;
s = md->cont;
if (s != NULL)
@@ -226,7 +228,7 @@ md_continue_here:;
md->argv++;
}
}
- md->opt = t;
+ md->opt = (char*)t;
md->cont = NULL;
return *s;
}
@@ -244,7 +246,7 @@ md_continue_here:;
static void ParseResolution(int res[2], const char *s)
{
- char *t = strchr(s, 'x');
+ const char *t = strchr(s, 'x');
if (t == NULL) {
ShowInfoF("Invalid resolution '%s'", s);
return;
@@ -308,7 +310,7 @@ static void LoadIntroGame(void)
}
_pause = 0;
- SetLocalPlayer(0);
+ SetLocalPlayer(PLAYER_FIRST);
/* Make sure you can't scroll in the menu */
_scrolling_viewport = 0;
_cursor.fix_at = false;
@@ -324,7 +326,6 @@ extern void DedicatedFork(void);
int ttd_main(int argc, char *argv[])
{
- MyGetOptData mgo;
int i;
const char *optformat;
char musicdriver[16], sounddriver[16], videodriver[16];
@@ -356,7 +357,8 @@ int ttd_main(int argc, char *argv[])
#endif
;
- MyGetOptInit(&mgo, argc-1, argv+1, optformat);
+ MyGetOptData mgo(argc-1, argv+1, optformat);
+
while ((i = MyGetOpt(&mgo)) != -1) {
switch (i) {
case 'm': ttd_strlcpy(musicdriver, mgo.opt, sizeof(musicdriver)); break;
@@ -512,7 +514,7 @@ int ttd_main(int argc, char *argv[])
ParseConnectionString(&player, &port, network_conn);
if (player != NULL) {
- _network_playas = atoi(player);
+ _network_playas = (PlayerID)atoi(player);
if (_network_playas != PLAYER_SPECTATOR) {
_network_playas--;
@@ -628,7 +630,7 @@ static void MakeNewGameDone(void)
/* Create a single player */
DoStartupNewPlayer(false);
- SetLocalPlayer(0);
+ SetLocalPlayer(PLAYER_FIRST);
_current_player = _local_player;
DoCommandP(0, (_patches.autorenew << 15 ) | (_patches.autorenew_months << 16) | 4, _patches.autorenew_money, NULL, CMD_SET_AUTOREPLACE);
@@ -708,7 +710,7 @@ static void StartScenario(void)
StartupEngines();
StartupDisasters();
- SetLocalPlayer(0);
+ SetLocalPlayer(PLAYER_FIRST);
_current_player = _local_player;
DoCommandP(0, (_patches.autorenew << 15 ) | (_patches.autorenew_months << 16) | 4, _patches.autorenew_money, NULL, CMD_SET_AUTOREPLACE);
@@ -799,7 +801,7 @@ void SwitchMode(int new_mode)
} else {
/* Update the local player for a loaded game. It is either always
* player #1 (eg 0) or in the case of a dedicated server a spectator */
- SetLocalPlayer(_network_dedicated ? PLAYER_SPECTATOR : 0);
+ SetLocalPlayer(_network_dedicated ? PLAYER_SPECTATOR : PLAYER_FIRST);
DoCommandP(0, 0, 0, NULL, CMD_PAUSE); // decrease pause counter (was increased from opening load dialog)
#ifdef ENABLE_NETWORK
if (_network_server) {
@@ -1096,7 +1098,7 @@ static void UpdateExclusiveRights(void)
Town *t;
FOR_ALL_TOWNS(t) {
- t->exclusivity = (byte)-1;
+ t->exclusivity = INVALID_PLAYER;
}
/* FIXME old exclusive rights status is not being imported (stored in s->blocked_months_obsolete)
@@ -1312,8 +1314,8 @@ bool AfterLoadGame(void)
* becomes player 0, unless we are in the scenario editor where all the
* players are 'invalid'.
*/
- if (!_network_dedicated && IsValidPlayer(0)) {
- p = GetPlayer(0);
+ if (!_network_dedicated && IsValidPlayer(PLAYER_FIRST)) {
+ p = GetPlayer(PLAYER_FIRST);
p->engine_renew = _patches.autorenew;
p->engine_renew_months = _patches.autorenew_months;
p->engine_renew_money = _patches.autorenew_money;
@@ -1387,7 +1389,7 @@ bool AfterLoadGame(void)
continue;
}
if (v->type == VEH_Train) {
- v->u.rail.track = 0x40;
+ v->u.rail.track = TRACK_BIT_WORMHOLE;
} else {
v->u.road.state = 0xFF;
}
@@ -1567,10 +1569,9 @@ bool AfterLoadGame(void)
{
/* Set up the engine count for all players */
Player *players[MAX_PLAYERS];
- int i;
const Vehicle *v;
- for (i = 0; i < MAX_PLAYERS; i++) players[i] = GetPlayer(i);
+ for (PlayerID i = PLAYER_FIRST; i < MAX_PLAYERS; i++) players[i] = GetPlayer(i);
FOR_ALL_VEHICLES(v) {
if (!IsEngineCountable(v)) continue;
@@ -1702,3 +1703,25 @@ void ReloadNewGRFData(void)
/* redraw the whole screen */
MarkWholeScreenDirty();
}
+
+HalMusicDriver *_music_driver;
+HalSoundDriver *_sound_driver;
+HalVideoDriver *_video_driver;
+
+byte _dirkeys; // 1 = left, 2 = up, 4 = right, 8 = down
+bool _fullscreen;
+CursorVars _cursor;
+bool _ctrl_pressed; // Is Ctrl pressed?
+bool _shift_pressed; // Is Shift pressed?
+byte _fast_forward;
+bool _left_button_down;
+bool _left_button_clicked;
+bool _right_button_down;
+bool _right_button_clicked;
+DrawPixelInfo _screen;
+bool _exit_game;
+bool _networking; ///< are we in networking mode?
+byte _game_mode;
+byte _pause;
+int _pal_first_dirty;
+int _pal_last_dirty;
diff --git a/src/openttd.h b/src/openttd.h
index 912ae4d8db..e87ad09a5d 100644
--- a/src/openttd.h
+++ b/src/openttd.h
@@ -8,9 +8,8 @@
#define VARDEF extern
#endif
-typedef struct Rect {
- int left,top,right,bottom;
-} Rect;
+#include "hal.h"
+#include "helpers.hpp"
typedef struct Oblong {
int x, y;
@@ -22,10 +21,6 @@ typedef struct BoundingRect {
int height;
} BoundingRect;
-typedef struct Point {
- int x,y;
-} Point;
-
typedef struct Pair {
int a;
int b;
@@ -45,13 +40,11 @@ typedef struct Town Town;
typedef struct NewsItem NewsItem;
typedef struct Industry Industry;
typedef struct DrawPixelInfo DrawPixelInfo;
-typedef byte PlayerID;
typedef byte VehicleOrderID; ///< The index of an order within its current vehicle (not pool related)
typedef byte CargoID;
typedef byte LandscapeID;
typedef uint32 SpriteID; ///< The number of a sprite, without mapping bits and colortables
typedef uint32 PalSpriteID; ///< The number of a sprite plus all the mapping bits and colortables
-typedef uint32 CursorID;
typedef uint16 EngineID;
typedef uint16 UnitID;
typedef uint16 StringID;
@@ -77,7 +70,7 @@ assert_compile(sizeof(DestinationID) == sizeof(DepotID));
assert_compile(sizeof(DestinationID) == sizeof(WaypointID));
assert_compile(sizeof(DestinationID) == sizeof(StationID));
-typedef uint32 WindowNumber;
+typedef int32 WindowNumber;
typedef byte WindowClass;
enum {
@@ -89,12 +82,6 @@ typedef int32 Year;
typedef int32 Date;
-enum GameModes {
- GM_MENU,
- GM_NORMAL,
- GM_EDITOR
-};
-
enum SwitchModes {
SM_NONE = 0,
SM_NEWGAME = 1,
@@ -124,6 +111,32 @@ enum InitializeGameModes {
IG_DATE_RESET = 1, /* Reset the date when initializing a game */
};
+enum Owner {
+ PLAYER_INACTIVE_CLIENT = 253,
+ PLAYER_NEW_COMPANY = 254,
+ PLAYER_SPECTATOR = 255,
+ OWNER_BEGIN = 0x00,
+ PLAYER_FIRST = 0x00,
+ MAX_PLAYERS = 8,
+ OWNER_TOWN = 0x0F, // a town owns the tile
+ OWNER_NONE = 0x10, // nobody owns the tile
+ OWNER_WATER = 0x11, // "water" owns the tile
+ OWNER_END = 0x12,
+ INVALID_OWNER = 0xFF,
+ INVALID_PLAYER = 0xFF,
+ /* Player identifiers All players below MAX_PLAYERS are playable
+ * players, above, they are special, computer controlled players */
+};
+
+typedef Owner PlayerID;
+
+DECLARE_POSTFIX_INCREMENT(Owner);
+
+/** Define basic enum properties */
+template <> struct EnumPropsT : MakeEnumPropsT {};
+typedef TinyEnumT OwnerByte;
+typedef OwnerByte PlayerByte;
+
typedef enum TransportTypes {
/* These constants are for now linked to the representation of bridges
@@ -132,6 +145,7 @@ typedef enum TransportTypes {
* accessing tunnels and bridges. For now, you should just not change
* the values for road and rail.
*/
+ TRANSPORT_BEGIN = 0,
TRANSPORT_RAIL = 0,
TRANSPORT_ROAD = 1,
TRANSPORT_WATER, // = 2
@@ -139,6 +153,11 @@ typedef enum TransportTypes {
INVALID_TRANSPORT = 0xff,
} TransportType;
+/** Define basic enum properties */
+template <> struct EnumPropsT : MakeEnumPropsT {};
+typedef TinyEnumT TransportTypeByte;
+
+
typedef struct TileInfo {
uint x;
uint y;
diff --git a/src/order.h b/src/order.h
index 7031f24553..ddc97481d8 100644
--- a/src/order.h
+++ b/src/order.h
@@ -10,11 +10,13 @@
enum {
INVALID_VEH_ORDER_ID = 0xFF,
- INVALID_ORDER = 0xFFFF,
};
+static const OrderID INVALID_ORDER = 0xFFFF;
+
/* Order types */
-enum OrderTypes {
+enum OrderType {
+ OT_BEGIN = 0,
OT_NOTHING = 0,
OT_GOTO_STATION = 1,
OT_GOTO_DEPOT = 2,
@@ -22,9 +24,14 @@ enum OrderTypes {
OT_LEAVESTATION = 4,
OT_DUMMY = 5,
OT_GOTO_WAYPOINT = 6,
+ OT_END
};
+
/* It needs to be 8bits, because we save and load it as such */
-typedef uint8 OrderType;
+/** Define basic enum properties */
+template <> struct EnumPropsT : MakeEnumPropsT {};
+typedef TinyEnumT OrderTypeByte;
+
/* Order flags -- please use OFB instead OF and use HASBIT/SETBIT/CLEARBIT */
@@ -82,7 +89,7 @@ enum {
* - REF_SHEDULE (all REFs are currently limited to 16 bits!!)
*/
typedef struct Order {
- OrderType type;
+ OrderTypeByte type;
uint8 flags;
DestinationID dest; ///< The destionation of the order.
diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp
index b510e84eaf..7b89e7b54c 100644
--- a/src/order_cmd.cpp
+++ b/src/order_cmd.cpp
@@ -38,7 +38,7 @@ DEFINE_OLD_POOL(Order, Order, OrderPoolNewBlock, NULL)
Order UnpackOldOrder(uint16 packed)
{
Order order;
- order.type = GB(packed, 0, 4);
+ order.type = (OrderType)GB(packed, 0, 4);
order.flags = GB(packed, 4, 4);
order.dest = GB(packed, 8, 8);
order.next = NULL;
@@ -65,7 +65,7 @@ Order UnpackOldOrder(uint16 packed)
static Order UnpackVersion4Order(uint16 packed)
{
Order order;
- order.type = GB(packed, 0, 4);
+ order.type = (OrderType)GB(packed, 0, 4);
order.flags = GB(packed, 4, 4);
order.dest = GB(packed, 8, 8);
order.next = NULL;
@@ -359,12 +359,12 @@ int32 CmdInsertOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
if (flags & DC_EXEC) {
Vehicle *u;
- Order *new = AllocateOrder();
- AssignOrder(new, new_order);
+ Order *new_o = AllocateOrder();
+ AssignOrder(new_o, new_order);
/* Create new order and link in list */
if (v->orders == NULL) {
- v->orders = new;
+ v->orders = new_o;
} else {
/* Try to get the previous item (we are inserting above the
selected) */
@@ -375,17 +375,17 @@ int32 CmdInsertOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
But because the orders can be shared, we copy the info over
the v->orders, so we don't have to change the pointers of
all vehicles */
- SwapOrders(v->orders, new);
+ SwapOrders(v->orders, new_o);
/* Now update the next pointers */
- v->orders->next = new;
+ v->orders->next = new_o;
} else if (order == NULL) {
/* 'sel' is a non-existing order, add him to the end */
order = GetLastVehicleOrder(v);
- order->next = new;
+ order->next = new_o;
} else {
/* Put the new order in between */
- new->next = order->next;
- order->next = new;
+ new_o->next = order->next;
+ order->next = new_o;
}
}
@@ -616,7 +616,7 @@ int32 CmdModifyOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
* whether we are not going to a depot as there are three
* cases where the full load flag can be active and only
* one case where the flag is used for depot orders. In the
- * other cases for the OrderType the flags are not used,
+ * other cases for the OrderTypeByte the flags are not used,
* so do not care and those orders should not be active
* when this function is called.
*/
@@ -1273,6 +1273,6 @@ static void Load_ORDR(void)
}
}
-const ChunkHandler _order_chunk_handlers[] = {
+extern const ChunkHandler _order_chunk_handlers[] = {
{ 'ORDR', Save_ORDR, Load_ORDR, CH_ARRAY | CH_LAST},
};
diff --git a/src/os/macosx/macos.h b/src/os/macosx/macos.h
index b8a6cd5110..ba33ce6028 100644
--- a/src/os/macosx/macos.h
+++ b/src/os/macosx/macos.h
@@ -11,9 +11,15 @@
* the function then adds text that tells the user to update and then report the bug if it's present in the newest version
* It also quits in a nice way since we call it when we know something happened that will crash OpenTTD (like a needed pointer turns out to be NULL or similar)
*/
-void ShowMacDialog ( const char *title, const char *message, const char *buttonLabel );
-void ShowMacAssertDialog ( const char *function, const char *file, const int line, const char *expression );
-void ShowMacErrorDialog(const char *error);
+#ifdef __cplusplus
+extern "C" {
+#endif //__cplusplus
+ void ShowMacDialog ( const char *title, const char *message, const char *buttonLabel );
+ void ShowMacAssertDialog ( const char *function, const char *file, const int line, const char *expression );
+ void ShowMacErrorDialog(const char *error);
+#ifdef __cplusplus
+}
+#endif //__cplusplus
// Since MacOS X users will never see an assert unless they started the game from a terminal
// we're using a custom assert(e) macro.
diff --git a/src/os/macosx/macos.m b/src/os/macosx/macos.m
index 59801fce00..33f296325d 100644
--- a/src/os/macosx/macos.m
+++ b/src/os/macosx/macos.m
@@ -8,11 +8,7 @@
#include
#include
#include "../../stdafx.h"
-#include "../../openttd.h"
-#include "../../newgrf.h"
-#include "../../gfx.h"
#include "../../macros.h"
-#include "../../string.h"
#ifndef CPU_SUBTYPE_POWERPC_970
#define CPU_SUBTYPE_POWERPC_970 ((cpu_subtype_t) 100)
@@ -26,6 +22,8 @@
* To insure that the crosscompiler still works, let him try any changes before they are committed
*/
+void ToggleFullScreen(bool fs);
+
static char *GetOSString(void)
{
static char buffer[175];
@@ -74,7 +72,7 @@ static char *GetOSString(void)
}
// make a list of used newgrf files
- if (_first_grffile != NULL) {
+/* if (_first_grffile != NULL) {
char* n = newgrf;
const GRFFile* file;
@@ -82,9 +80,9 @@ static char *GetOSString(void)
n = strecpy(n, " ", lastof(newgrf));
n = strecpy(n, file->filename, lastof(newgrf));
}
- } else {
+ } else {*/
sprintf(newgrf, "none");
- }
+// }
snprintf(
buffer, lengthof(buffer),
diff --git a/src/os/macosx/splash.h b/src/os/macosx/splash.h
index 39880562d4..1bc4fa53cd 100644
--- a/src/os/macosx/splash.h
+++ b/src/os/macosx/splash.h
@@ -5,6 +5,14 @@
#define SPLASH_IMAGE_FILE "splash.png"
-void DisplaySplashImage(void);
+#ifdef __cplusplus
+extern "C" {
+#endif //__cplusplus
+
+ void DisplaySplashImage(void);
+
+#ifdef __cplusplus
+}
+#endif //__cplusplus
#endif
diff --git a/src/pathfind.cpp b/src/pathfind.cpp
index 81ccc699cc..6fc4526475 100644
--- a/src/pathfind.cpp
+++ b/src/pathfind.cpp
@@ -114,16 +114,16 @@ static const byte _bits_mask[4] = {
0x2A,
};
-static const byte _tpf_new_direction[14] = {
- 0, 1, 0, 1, 2, 1,
- 0, 0,
- 2, 3, 3, 2, 3, 0,
+static const DiagDirection _tpf_new_direction[14] = {
+ DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_SW, DIAGDIR_SE,
+ INVALID_DIAGDIR, INVALID_DIAGDIR,
+ DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NW, DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NE,
};
-static const byte _tpf_prev_direction[14] = {
- 0, 1, 1, 0, 1, 2,
- 0, 0,
- 2, 3, 2, 3, 0, 3,
+static const DiagDirection _tpf_prev_direction[14] = {
+ DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_SE, DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_SW,
+ INVALID_DIAGDIR, INVALID_DIAGDIR,
+ DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NE, DIAGDIR_NW,
};
@@ -182,7 +182,7 @@ static void TPFMode2(TrackPathFinder* tpf, TileIndex tile, DiagDirection directi
}
continue_here:;
- tpf->the_dir = i + (HASBIT(_otherdir_mask[direction], i) ? 8 : 0);
+ tpf->the_dir = (Trackdir)(i + (HASBIT(_otherdir_mask[direction], i) ? 8 : 0));
if (!tpf->enum_proc(tile, tpf->userdata, tpf->the_dir, tpf->rd.cur_length, NULL)) {
TPFMode2(tpf, tile, _tpf_new_direction[tpf->the_dir]);
@@ -333,7 +333,7 @@ static void TPFMode1(TrackPathFinder* tpf, TileIndex tile, DiagDirection directi
i = FIND_FIRST_BIT(bits);
bits = KILL_FIRST_BIT(bits);
- tpf->the_dir = (_otherdir_mask[direction] & (byte)(1 << i)) ? (i+8) : i;
+ tpf->the_dir = (Trackdir)((_otherdir_mask[direction] & (byte)(1 << i)) ? (i+8) : i);
rd = tpf->rd;
if (TPFSetTileBit(tpf, tile, tpf->the_dir) &&
@@ -375,7 +375,7 @@ static void TPFMode1(TrackPathFinder* tpf, TileIndex tile, DiagDirection directi
i = FIND_FIRST_BIT(bits);
bits = KILL_FIRST_BIT(bits);
- tpf->the_dir = (_otherdir_mask[direction] & (byte)(1 << i)) ? (i+8) : i;
+ tpf->the_dir = (Trackdir)((_otherdir_mask[direction] & (byte)(1 << i)) ? (i+8) : i);
rd = tpf->rd;
if (TPFSetTileBit(tpf, tile, tpf->the_dir) &&
!tpf->enum_proc(tile, tpf->userdata, tpf->the_dir, tpf->rd.cur_length, &tpf->rd.pft_var6) ) {
@@ -407,11 +407,11 @@ void FollowTrack(TileIndex tile, uint16 flags, DiagDirection direction, TPFEnumP
tpf.hasbit_13 = HASBIT(flags, 13); /* 0x2000 */
- tpf.tracktype = (byte)flags;
+ tpf.tracktype = (TransportType)(flags & 0xFF);
if (HASBIT(flags, 11)) {
tpf.rd.pft_var6 = 0xFF;
- tpf.enum_proc(tile, data, 0, 0, 0);
+ tpf.enum_proc(tile, data, INVALID_TRACKDIR, 0, 0);
TPFMode2(&tpf, tile, direction);
} else {
/* clear the hash_heads */
@@ -427,19 +427,19 @@ typedef struct {
TileIndex tile;
uint16 cur_length; // This is the current length to this tile.
uint16 priority; // This is the current length + estimated length to the goal.
- byte track;
+ TrackdirByte track;
byte depth;
byte state;
byte first_track;
} StackedItem;
-static const byte _new_track[6][4] = {
-{0, 0xff, 8, 0xff,},
-{0xff, 1, 0xff, 9,},
-{0xff, 2, 10, 0xff,},
-{3, 0xff, 0xff, 11,},
-{12, 4, 0xff, 0xff,},
-{0xff, 0xff, 5, 13,},
+static const Trackdir _new_trackdir[6][4] = {
+{TRACKDIR_X_NE, INVALID_TRACKDIR, TRACKDIR_X_SW, INVALID_TRACKDIR,},
+{INVALID_TRACKDIR, TRACKDIR_Y_SE, INVALID_TRACKDIR, TRACKDIR_Y_NW,},
+{INVALID_TRACKDIR, TRACKDIR_UPPER_E, TRACKDIR_UPPER_W, INVALID_TRACKDIR,},
+{TRACKDIR_LOWER_E, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_LOWER_W,},
+{TRACKDIR_LEFT_N, TRACKDIR_LEFT_S, INVALID_TRACKDIR, INVALID_TRACKDIR,},
+{INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_RIGHT_S, TRACKDIR_RIGHT_N,},
};
typedef struct HashLink {
@@ -539,7 +539,7 @@ static bool NtpVisit(NewTrackPathFinder* tpf, TileIndex tile, DiagDirection dir,
}
if (head != 0xffff) {
- if (tile == tpf->hash_tile[hash] && (head & 0x3) == dir) {
+ if (tile == tpf->hash_tile[hash] && (head & 0x3) == (uint)dir) {
// longer length
if (length >= (head >> 2)) return false;
@@ -574,7 +574,7 @@ static bool NtpVisit(NewTrackPathFinder* tpf, TileIndex tile, DiagDirection dir,
uint offs = tpf->hash_tile[hash];
do {
link = NTP_GET_LINK_PTR(tpf, offs);
- if (tile == link->tile && (link->typelength & 0x3U) == dir) {
+ if (tile == link->tile && (link->typelength & 0x3U) == (uint)dir) {
if (length >= (uint)(link->typelength >> 2)) return false;
link->typelength = dir | (length << 2);
return true;
@@ -657,8 +657,8 @@ static const uint16 _is_upwards_slope[15] = {
static uint DistanceMoo(TileIndex t0, TileIndex t1)
{
- const uint dx = abs(TileX(t0) - TileX(t1));
- const uint dy = abs(TileY(t0) - TileY(t1));
+ const uint dx = delta(TileX(t0), TileX(t1));
+ const uint dy = delta(TileY(t0), TileY(t1));
const uint straightTracks = 2 * min(dx, dy); /* The number of straight (not full length) tracks */
/* OPTIMISATION:
@@ -685,7 +685,7 @@ static const byte _length_of_track[16] = {
static void NTPEnum(NewTrackPathFinder* tpf, TileIndex tile, DiagDirection direction)
{
TrackBits bits, allbits;
- uint track;
+ Trackdir track;
TileIndex tile_org;
StackedItem si;
int estimation;
@@ -737,7 +737,7 @@ start_at:
continue;
}
if (!HASBIT(tpf->railtypes, GetRailType(tile))) {
- bits = 0;
+ bits = TRACK_BIT_NONE;
break;
}
flotr = FindLengthOfTunnel(tile, direction);
@@ -771,7 +771,7 @@ start_at:
// too long search length? bail out.
if (si.cur_length >= tpf->maxlength) {
DEBUG(ntp, 1, "Cur_length too big");
- bits = 0;
+ bits = TRACK_BIT_NONE;
break;
}
@@ -780,14 +780,14 @@ start_at:
if (!IsTileType(tile, MP_RAILWAY) || !IsPlainRailTile(tile)) {
// We found a tile which is not a normal railway tile.
// Determine which tracks that exist on this tile.
- bits = GetTileTrackStatus(tile, TRANSPORT_RAIL) & _tpfmode1_and[direction];
- bits = (bits | (bits >> 8)) & 0x3F;
+ uint32 ts = GetTileTrackStatus(tile, TRANSPORT_RAIL) & _tpfmode1_and[direction];
+ bits = TrackdirBitsToTrackBits((TrackdirBits)(ts & TRACKDIR_BIT_MASK));
// Check that the tile contains exactly one track
if (bits == 0 || KILL_FIRST_BIT(bits) != 0) break;
if (!HASBIT(tpf->railtypes, IsTileType(tile, MP_STREET) ? GetRailTypeCrossing(tile) : GetRailType(tile))) {
- bits = 0;
+ bits = TRACK_BIT_NONE;
break;
}
@@ -797,7 +797,7 @@ start_at:
// bits - bitmask of which track that exist on the tile (exactly one bit is set)
// direction - which direction are we moving in?
///////////////////
- si.track = _new_track[FIND_FIRST_BIT(bits)][direction];
+ si.track = _new_trackdir[FIND_FIRST_BIT(bits)][direction];
si.cur_length += _length_of_track[si.track];
goto callback_and_continue;
}
@@ -810,18 +810,18 @@ start_at:
/* The tile has no reachable tracks => End of rail segment
* or Intersection => End of rail segment. We check this agains all the
* bits, not just reachable ones, to prevent infinite loops. */
- if (bits == 0 || TracksOverlap(allbits)) break;
+ if (bits == TRACK_BIT_NONE || TracksOverlap(allbits)) break;
if (!HASBIT(tpf->railtypes, GetRailType(tile))) {
- bits = 0;
+ bits = TRACK_BIT_NONE;
break;
}
/* If we reach here, the tile has exactly one track, and this
track is reachable => Rail segment continues */
- track = _new_track[FIND_FIRST_BIT(bits)][direction];
- assert(track != 0xff);
+ track = _new_trackdir[FIND_FIRST_BIT(bits)][direction];
+ assert(track != INVALID_TRACKDIR);
si.cur_length += _length_of_track[track];
@@ -837,7 +837,7 @@ start_at:
if (!HasSignalOnTrackdir(tile, track)) {
// if one way signal not pointing towards us, stop going in this direction => End of rail segment.
if (HasSignalOnTrackdir(tile, ReverseTrackdir(track))) {
- bits = 0;
+ bits = TRACK_BIT_NONE;
break;
}
} else if (GetSignalStateByTrackdir(tile, track) == SIGNAL_STATE_GREEN) {
@@ -850,7 +850,7 @@ start_at:
// stop going in this direction => End of rail segment.
// this is to prevent us from going into a full platform.
if (!(si.state&1)) {
- bits = 0;
+ bits = TRACK_BIT_NONE;
break;
}
}
@@ -874,14 +874,14 @@ start_at:
// safety check if we're running around chasing our tail... (infinite loop)
if (tile == tile_org) {
- bits = 0;
+ bits = TRACK_BIT_NONE;
break;
}
}
// There are no tracks to choose between.
// Stop searching in this direction
- if (bits == 0)
+ if (bits == TRACK_BIT_NONE)
continue;
////////////////
@@ -909,8 +909,9 @@ start_at:
if (si.depth == 0)
continue; /* We overflowed our depth. No more searching in this direction. */
si.tile = tile;
- do {
- si.track = _new_track[FIND_FIRST_BIT(bits)][direction];
+ while (bits != TRACK_BIT_NONE) {
+ Track track = RemoveFirstTrack(bits);
+ si.track = _new_trackdir[track][direction];
assert(si.track != 0xFF);
si.priority = si.cur_length + estimation;
@@ -922,7 +923,7 @@ start_at:
tpf->stack[tpf->nstack] = si;
HeapifyUp(tpf);
- } while ((bits = KILL_FIRST_BIT(bits)) != 0);
+ };
// If this is the first intersection, we need to fill the first_track member.
// so the code outside knows which path is better.
@@ -931,11 +932,11 @@ start_at:
assert(tpf->nstack == 1 || tpf->nstack == 2 || tpf->nstack == 3);
if (tpf->nstack != 1) {
uint32 r = Random();
- if (r&1) swap_byte(&tpf->stack[0].track, &tpf->stack[1].track);
+ if (r&1) SwapT(&tpf->stack[0].track, &tpf->stack[1].track);
if (tpf->nstack != 2) {
- byte t = tpf->stack[2].track;
- if (r&2) swap_byte(&tpf->stack[0].track, &t);
- if (r&4) swap_byte(&tpf->stack[1].track, &t);
+ TrackdirByte t = tpf->stack[2].track;
+ if (r&2) SwapT(&tpf->stack[0].track, &t);
+ if (r&4) SwapT(&tpf->stack[1].track, &t);
tpf->stack[2].first_track = tpf->stack[2].track = t;
}
tpf->stack[0].first_track = tpf->stack[0].track;
diff --git a/src/pathfind.h b/src/pathfind.h
index 432d7ea888..6c0dccad1d 100644
--- a/src/pathfind.h
+++ b/src/pathfind.h
@@ -4,6 +4,7 @@
#define PATHFIND_H
#include "direction.h"
+#include "openttd.h"
enum {
STR_FACTOR = 2,
@@ -14,7 +15,7 @@ enum {
//supported on all archs)
typedef struct TrackPathFinder TrackPathFinder;
-typedef bool TPFEnumProc(TileIndex tile, void *data, int track, uint length, byte *state);
+typedef bool TPFEnumProc(TileIndex tile, void *data, Trackdir trackdir, uint length, byte *state);
typedef void TPFAfterProc(TrackPathFinder *tpf);
typedef bool NTPEnumProc(TileIndex tile, void *data, int track, uint length);
@@ -51,9 +52,9 @@ struct TrackPathFinder {
RememberData rd;
- int the_dir;
+ TrackdirByte the_dir;
- byte tracktype;
+ TransportTypeByte tracktype;
byte var2;
bool disable_tile_hash;
bool hasbit_13;
diff --git a/src/player.h b/src/player.h
index df959c6e04..e3329c0d14 100644
--- a/src/player.h
+++ b/src/player.h
@@ -38,7 +38,7 @@ typedef struct PlayerAI {
byte state_mode;
byte banned_tile_count;
- byte railtype_to_use;
+ RailTypeByte railtype_to_use;
CargoID cargo_type;
byte num_wagons;
@@ -132,7 +132,7 @@ typedef struct PlayerAiNew {
bool to_deliver;
TileIndex depot_tile;
- byte depot_direction;
+ DiagDirectionByte depot_direction;
byte amount_veh; // How many vehicles we are going to build in this route
byte cur_veh; // How many vehicles did we bought?
@@ -166,14 +166,14 @@ typedef struct Player {
byte player_money_fraction;
byte avail_railtypes;
byte block_preview;
- PlayerID index;
+ PlayerByte index;
uint16 cargo_types; /* which cargo types were transported the last year */
TileIndex location_of_house;
TileIndex last_build_coordinate;
- PlayerID share_owners[4];
+ PlayerByte share_owners[4];
Year inaugurated_year;
byte num_valid_stat_ent;
@@ -212,15 +212,6 @@ void SetLocalPlayer(PlayerID new_player);
VARDEF PlayerID _local_player;
VARDEF PlayerID _current_player;
-/* Player identifiers All players below MAX_PLAYERS are playable
- * players, above, they are special, computer controlled players */
-enum Players {
- PLAYER_INACTIVE_CLIENT = 253,
- PLAYER_NEW_COMPANY = 254, ///< Command 'player' in Multiplayer to create a new company
- PLAYER_SPECTATOR = 255, ///< Spectator in Multiplayer or the player in the scenario editor
- MAX_PLAYERS = 8,
-};
-
VARDEF Player _players[MAX_PLAYERS];
// NOSAVE: can be determined from player structs
VARDEF byte _player_colors[MAX_PLAYERS];
@@ -239,7 +230,7 @@ static inline byte ActivePlayerCount(void)
static inline Player* GetPlayer(PlayerID i)
{
- assert(i < lengthof(_players));
+ assert(i < (PlayerID)lengthof(_players));
return &_players[i];
}
diff --git a/src/player_gui.cpp b/src/player_gui.cpp
index c4612f5dcd..1a2563d3bf 100644
--- a/src/player_gui.cpp
+++ b/src/player_gui.cpp
@@ -148,7 +148,7 @@ static void PlayerFinancesWndProc(Window *w, WindowEvent *e)
{
switch (e->event) {
case WE_PAINT: {
- PlayerID player = w->window_number;
+ PlayerID player = (PlayerID)w->window_number;
const Player *p = GetPlayer(player);
if (player == _local_player) {
@@ -170,7 +170,7 @@ static void PlayerFinancesWndProc(Window *w, WindowEvent *e)
case 2: {/* toggle size */
byte mode = (byte)WP(w,def_d).data_1;
bool stickied = !!(w->flags4 & WF_STICKY);
- PlayerID player = w->window_number;
+ PlayerID player = (PlayerID)w->window_number;
DeleteWindow(w);
DoShowPlayerFinances(player, !HASBIT(mode, 0), stickied);
} break;
@@ -305,11 +305,11 @@ static void ShowColourDropDownMenu(Window *w, uint32 widget)
}
/* Get the first selected livery to use as the default dropdown item */
- for (scheme = 0; scheme < LS_END; scheme++) {
+ for (scheme = LS_BEGIN; scheme < LS_END; scheme++) {
if (HASBIT(WP(w, livery_d).sel, scheme)) break;
}
if (scheme == LS_END) scheme = LS_DEFAULT;
- livery = &GetPlayer(w->window_number)->livery[scheme];
+ livery = &GetPlayer((PlayerID)w->window_number)->livery[scheme];
ShowDropDownMenu(w, _colour_dropdown, widget == 10 ? livery->colour1 : livery->colour2, widget, used_colours, 0);
}
@@ -326,7 +326,7 @@ static void SelectPlayerLiveryWndProc(Window *w, WindowEvent *e)
break;
case WE_PAINT: {
- const Player *p = GetPlayer(w->window_number);
+ const Player *p = GetPlayer((PlayerID)w->window_number);
LiveryScheme scheme = LS_DEFAULT;
int y = 51;
@@ -337,7 +337,7 @@ static void SelectPlayerLiveryWndProc(Window *w, WindowEvent *e)
SetWindowWidgetDisabledState(w, 12, (WP(w, livery_d).sel == 0));
if (!(WP(w, livery_d).sel == 0)) {
- for (scheme = 0; scheme < LS_END; scheme++) {
+ for (scheme = LS_BEGIN; scheme < LS_END; scheme++) {
if (HASBIT(WP(w, livery_d).sel, scheme)) break;
}
if (scheme == LS_END) scheme = LS_DEFAULT;
@@ -383,7 +383,7 @@ static void SelectPlayerLiveryWndProc(Window *w, WindowEvent *e)
LiveryScheme scheme;
RaiseWindowWidget(w, WP(w, livery_d).livery_class + 2);
- WP(w, livery_d).livery_class = e->we.click.widget - 2;
+ WP(w, livery_d).livery_class = (LiveryClass)(e->we.click.widget - 2);
WP(w, livery_d).sel = 0;
LowerWindowWidget(w, WP(w, livery_d).livery_class + 2);
@@ -413,9 +413,9 @@ static void SelectPlayerLiveryWndProc(Window *w, WindowEvent *e)
case 13: {
LiveryScheme scheme;
- LiveryScheme j = (e->we.click.pt.y - 48) / 14;
+ LiveryScheme j = (LiveryScheme)((e->we.click.pt.y - 48) / 14);
- for (scheme = 0; scheme <= j; scheme++) {
+ for (scheme = LS_BEGIN; scheme <= j; scheme++) {
if (livery_class[scheme] != WP(w, livery_d).livery_class) j++;
if (scheme >= LS_END) return;
}
@@ -423,7 +423,7 @@ static void SelectPlayerLiveryWndProc(Window *w, WindowEvent *e)
/* If clicking on the left edge, toggle using the livery */
if (e->we.click.pt.x < 10) {
- DoCommandP(0, j | (2 << 8), !GetPlayer(w->window_number)->livery[j].in_use, NULL, CMD_SET_PLAYER_COLOR);
+ DoCommandP(0, j | (2 << 8), !GetPlayer((PlayerID)w->window_number)->livery[j].in_use, NULL, CMD_SET_PLAYER_COLOR);
}
if (_ctrl_pressed) {
@@ -511,7 +511,7 @@ static void SelectPlayerFaceWndProc(Window *w, WindowEvent *e)
Player *p;
LowerWindowWidget(w, WP(w, facesel_d).gender + 5);
DrawWindowWidgets(w);
- p = GetPlayer(w->window_number);
+ p = GetPlayer((PlayerID)w->window_number);
DrawPlayerFace(WP(w,facesel_d).face, p->player_color, 2, 16);
} break;
@@ -675,7 +675,7 @@ static void PlayerCompanyWndProc(Window *w, WindowEvent *e)
{
switch (e->event) {
case WE_PAINT: {
- const Player *p = GetPlayer(w->window_number);
+ const Player *p = GetPlayer((PlayerID)w->window_number);
bool local = w->window_number == _local_player;
SetWindowWidgetHiddenState(w, PCW_WIDGET_NEW_FACE, !local);
@@ -711,14 +711,14 @@ static void PlayerCompanyWndProc(Window *w, WindowEvent *e)
SetDParam(0, p->name_1);
SetDParam(1, p->name_2);
- SetDParam(2, GetPlayerNameString((byte)w->window_number, 3));
+ SetDParam(2, GetPlayerNameString((PlayerID)w->window_number, 3));
DrawWindowWidgets(w);
SetDParam(0, p->inaugurated_year);
DrawString(110, 25, STR_7038_INAUGURATED, 0);
- DrawPlayerVehiclesAmount(w->window_number);
+ DrawPlayerVehiclesAmount((PlayerID)w->window_number);
DrawString(110,48, STR_7006_COLOR_SCHEME, 0);
// Draw company-colour bus
@@ -744,7 +744,7 @@ static void PlayerCompanyWndProc(Window *w, WindowEvent *e)
Window *wf = AllocateWindowDescFront(&_select_player_face_desc, w->window_number);
if (wf != NULL) {
wf->caption_color = w->window_number;
- WP(wf,facesel_d).face = GetPlayer(wf->window_number)->face;
+ WP(wf,facesel_d).face = GetPlayer((PlayerID)wf->window_number)->face;
WP(wf,facesel_d).gender = 0;
}
break;
@@ -762,7 +762,7 @@ static void PlayerCompanyWndProc(Window *w, WindowEvent *e)
}
case PCW_WIDGET_PRESIDENT_NAME: {
- const Player *p = GetPlayer(w->window_number);
+ const Player *p = GetPlayer((PlayerID)w->window_number);
WP(w, def_d).byte_1 = 0;
SetDParam(0, p->president_name_2);
ShowQueryString(p->president_name_1, STR_700B_PRESIDENT_S_NAME, 31, 94, w, CS_ALPHANUMERAL);
@@ -770,7 +770,7 @@ static void PlayerCompanyWndProc(Window *w, WindowEvent *e)
}
case PCW_WIDGET_COMPANY_NAME: {
- Player *p = GetPlayer(w->window_number);
+ Player *p = GetPlayer((PlayerID)w->window_number);
WP(w,def_d).byte_1 = 1;
SetDParam(0, p->name_2);
ShowQueryString(p->name_1, STR_700A_COMPANY_NAME, 31, 150, w, CS_ALPHANUMERAL);
@@ -778,7 +778,7 @@ static void PlayerCompanyWndProc(Window *w, WindowEvent *e)
}
case PCW_WIDGET_BUILD_VIEW_HQ: {
- TileIndex tile = GetPlayer(w->window_number)->location_of_house;
+ TileIndex tile = GetPlayer((PlayerID)w->window_number)->location_of_house;
if (tile == 0) {
if ((byte)w->window_number != _local_player)
return;
@@ -890,7 +890,7 @@ static void BuyCompanyWndProc(Window *w, WindowEvent *e)
{
switch (e->event) {
case WE_PAINT: {
- Player *p = GetPlayer(w->window_number);
+ Player *p = GetPlayer((PlayerID)w->window_number);
SetDParam(0, p->name_1);
SetDParam(1, p->name_2);
DrawWindowWidgets(w);
diff --git a/src/players.cpp b/src/players.cpp
index 4c2d1ed37e..6d295d87d0 100644
--- a/src/players.cpp
+++ b/src/players.cpp
@@ -483,7 +483,7 @@ static Player *AllocatePlayer(void)
// Find a free slot
FOR_ALL_PLAYERS(p) {
if (!p->is_active) {
- int i = p->index;
+ PlayerID i = p->index;
memset(p, 0, sizeof(Player));
p->index = i;
return p;
@@ -494,9 +494,7 @@ static Player *AllocatePlayer(void)
void ResetPlayerLivery(Player *p)
{
- LiveryScheme scheme;
-
- for (scheme = 0; scheme < LS_END; scheme++) {
+ for (LiveryScheme scheme = LS_BEGIN; scheme < LS_END; scheme++) {
p->livery[scheme].in_use = false;
p->livery[scheme].colour1 = p->player_color;
p->livery[scheme].colour2 = p->player_color;
@@ -583,10 +581,8 @@ static void MaybeStartNewPlayer(void)
void InitializePlayers(void)
{
- uint i;
-
memset(_players, 0, sizeof(_players));
- for (i = 0; i != MAX_PLAYERS; i++) _players[i].index = i;
+ for (PlayerID i = PLAYER_FIRST; i != MAX_PLAYERS; i++) _players[i].index = i;
_cur_player_tick_index = 0;
}
@@ -596,7 +592,7 @@ void OnTick_Players(void)
if (_game_mode == GM_EDITOR) return;
- p = GetPlayer(_cur_player_tick_index);
+ p = GetPlayer((PlayerID)_cur_player_tick_index);
_cur_player_tick_index = (_cur_player_tick_index + 1) % MAX_PLAYERS;
if (p->name_1 != 0) GenerateCompanyName(p);
@@ -614,7 +610,7 @@ StringID GetPlayerNameString(PlayerID player, uint index)
return STR_EMPTY;
}
-extern void ShowPlayerFinances(int player);
+extern void ShowPlayerFinances(PlayerID player);
void PlayersYearlyLoop(void)
{
@@ -928,11 +924,11 @@ int32 CmdPlayerCtrl(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
case 2: { /* Delete a player */
Player *p;
- if (!IsValidPlayer(p2)) return CMD_ERROR;
+ if (!IsValidPlayer((PlayerID)p2)) return CMD_ERROR;
if (!(flags & DC_EXEC)) return 0;
- p = GetPlayer(p2);
+ p = GetPlayer((PlayerID)p2);
/* Only allow removal of HUMAN companies */
if (IsHumanPlayer(p->index)) {
@@ -953,8 +949,8 @@ int32 CmdPlayerCtrl(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
} break;
case 3: { /* Merge a company (#1) into another company (#2), elimination company #1 */
- PlayerID pid_old = GB(p2, 0, 16);
- PlayerID pid_new = GB(p2, 16, 16);
+ PlayerID pid_old = (PlayerID)GB(p2, 0, 16);
+ PlayerID pid_new = (PlayerID)GB(p2, 16, 16);
if (!IsValidPlayer(pid_old) || !IsValidPlayer(pid_new)) return CMD_ERROR;
@@ -1323,7 +1319,7 @@ static void Load_PLYR(void)
{
int index;
while ((index = SlIterateArray()) != -1) {
- Player *p = GetPlayer(index);
+ Player *p = GetPlayer((PlayerID)index);
SaveLoad_PLYR(p);
_player_colors[index] = p->player_color;
UpdatePlayerMoney32(p);
@@ -1334,6 +1330,6 @@ static void Load_PLYR(void)
}
}
-const ChunkHandler _player_chunk_handlers[] = {
+extern const ChunkHandler _player_chunk_handlers[] = {
{ 'PLYR', Save_PLYR, Load_PLYR, CH_ARRAY | CH_LAST},
};
diff --git a/src/queue.cpp b/src/queue.cpp
index 9986442bfe..44ace52e5b 100644
--- a/src/queue.cpp
+++ b/src/queue.cpp
@@ -3,6 +3,7 @@
#include "stdafx.h"
#include "openttd.h"
#include "queue.h"
+#include "helpers.hpp"
static void Stack_Clear(Queue* q, bool free_values)
{
@@ -48,14 +49,15 @@ static Queue* init_stack(Queue* q, uint max_size)
q->free = Stack_Free;
q->data.stack.max_size = max_size;
q->data.stack.size = 0;
- q->data.stack.elements = malloc(max_size * sizeof(*q->data.stack.elements));
+ MallocT(&q->data.stack.elements, max_size);
q->freeq = false;
return q;
}
Queue* new_Stack(uint max_size)
{
- Queue* q = malloc(sizeof(*q));
+ Queue* q;
+ MallocT(&q, 1);
init_stack(q, max_size);
q->freeq = true;
@@ -125,14 +127,15 @@ static Queue* init_fifo(Queue* q, uint max_size)
q->data.fifo.max_size = max_size;
q->data.fifo.head = 0;
q->data.fifo.tail = 0;
- q->data.fifo.elements = malloc(max_size * sizeof(*q->data.fifo.elements));
+ MallocT(&q->data.fifo.elements, max_size);
q->freeq = false;
return q;
}
Queue* new_Fifo(uint max_size)
{
- Queue* q = malloc(sizeof(*q));
+ Queue* q;
+ MallocT(&q, 1);
init_fifo(q, max_size);
q->freeq = true;
@@ -166,7 +169,8 @@ static void InsSort_Free(Queue* q, bool free_values)
static bool InsSort_Push(Queue* q, void* item, int priority)
{
- InsSortNode* newnode = malloc(sizeof(*newnode));
+ InsSortNode* newnode;
+ MallocT(&newnode, 1);
if (newnode == NULL) return false;
newnode->item = item;
@@ -220,7 +224,8 @@ void init_InsSort(Queue* q)
Queue* new_InsSort(void)
{
- Queue* q = malloc(sizeof(*q));
+ Queue* q;
+ MallocT(&q, 1);
init_InsSort(q);
q->freeq = true;
@@ -299,7 +304,7 @@ static bool BinaryHeap_Push(Queue* q, void* item, int priority)
if (q->data.binaryheap.elements[q->data.binaryheap.size >> BINARY_HEAP_BLOCKSIZE_BITS] == NULL) {
/* The currently allocated blocks are full, allocate a new one */
assert((q->data.binaryheap.size & BINARY_HEAP_BLOCKSIZE_MASK) == 0);
- q->data.binaryheap.elements[q->data.binaryheap.size >> BINARY_HEAP_BLOCKSIZE_BITS] = malloc(BINARY_HEAP_BLOCKSIZE * sizeof(*q->data.binaryheap.elements[0]));
+ MallocT(&q->data.binaryheap.elements[q->data.binaryheap.size >> BINARY_HEAP_BLOCKSIZE_BITS], BINARY_HEAP_BLOCKSIZE);
q->data.binaryheap.blocks++;
#ifdef QUEUE_DEBUG
printf("[BinaryHeap] Increasing size of elements to %d nodes\n", q->data.binaryheap.blocks * BINARY_HEAP_BLOCKSIZE);
@@ -427,8 +432,8 @@ void init_BinaryHeap(Queue* q, uint max_size)
q->data.binaryheap.size = 0;
// We malloc memory in block of BINARY_HEAP_BLOCKSIZE
// It autosizes when it runs out of memory
- q->data.binaryheap.elements = calloc((max_size - 1) / BINARY_HEAP_BLOCKSIZE + 1, sizeof(*q->data.binaryheap.elements));
- q->data.binaryheap.elements[0] = malloc(BINARY_HEAP_BLOCKSIZE * sizeof(*q->data.binaryheap.elements[0]));
+ CallocT(&q->data.binaryheap.elements, (max_size - 1) / BINARY_HEAP_BLOCKSIZE + 1);
+ MallocT(&q->data.binaryheap.elements[0], BINARY_HEAP_BLOCKSIZE);
q->data.binaryheap.blocks = 1;
q->freeq = false;
#ifdef QUEUE_DEBUG
@@ -438,7 +443,8 @@ void init_BinaryHeap(Queue* q, uint max_size)
Queue* new_BinaryHeap(uint max_size)
{
- Queue* q = malloc(sizeof(*q));
+ Queue* q;
+ MallocT(&q, 1);
init_BinaryHeap(q, max_size);
q->freeq = true;
@@ -464,7 +470,7 @@ void init_Hash(Hash* h, Hash_HashProc* hash, uint num_buckets)
h->hash = hash;
h->size = 0;
h->num_buckets = num_buckets;
- h->buckets = malloc(num_buckets * (sizeof(*h->buckets) + sizeof(*h->buckets_in_use)));
+ h->buckets = (HashNode*)malloc(num_buckets * (sizeof(*h->buckets) + sizeof(*h->buckets_in_use)));
#ifdef HASH_DEBUG
debug("Buckets = %p", h->buckets);
#endif
@@ -475,7 +481,8 @@ void init_Hash(Hash* h, Hash_HashProc* hash, uint num_buckets)
Hash* new_Hash(Hash_HashProc* hash, int num_buckets)
{
- Hash* h = malloc(sizeof(*h));
+ Hash* h;
+ MallocT(&h, 1);
init_Hash(h, hash, num_buckets);
h->freeh = true;
@@ -709,7 +716,7 @@ void* Hash_Set(Hash* h, uint key1, uint key2, void* value)
node = h->buckets + hash;
} else {
/* Add it after prev */
- node = malloc(sizeof(*node));
+ MallocT(&node, 1);
prev->next = node;
}
node->next = NULL;
diff --git a/src/rail.cpp b/src/rail.cpp
index c4b20de271..2255b428b7 100644
--- a/src/rail.cpp
+++ b/src/rail.cpp
@@ -10,41 +10,41 @@
/* XXX: Below 3 tables store duplicate data. Maybe remove some? */
/* Maps a trackdir to the bit that stores its status in the map arrays, in the
* direction along with the trackdir */
-const byte _signal_along_trackdir[] = {
+extern const byte _signal_along_trackdir[] = {
0x80, 0x80, 0x80, 0x20, 0x40, 0x10, 0, 0,
0x40, 0x40, 0x40, 0x10, 0x80, 0x20
};
/* Maps a trackdir to the bit that stores its status in the map arrays, in the
* direction against the trackdir */
-const byte _signal_against_trackdir[] = {
+extern const byte _signal_against_trackdir[] = {
0x40, 0x40, 0x40, 0x10, 0x80, 0x20, 0, 0,
0x80, 0x80, 0x80, 0x20, 0x40, 0x10
};
/* Maps a Track to the bits that store the status of the two signals that can
* be present on the given track */
-const byte _signal_on_track[] = {
+extern const byte _signal_on_track[] = {
0xC0, 0xC0, 0xC0, 0x30, 0xC0, 0x30
};
/* Maps a diagonal direction to the all trackdirs that are connected to any
* track entering in this direction (including those making 90 degree turns)
*/
-const TrackdirBits _exitdir_reaches_trackdirs[] = {
+extern const TrackdirBits _exitdir_reaches_trackdirs[] = {
TRACKDIR_BIT_X_NE | TRACKDIR_BIT_LOWER_E | TRACKDIR_BIT_LEFT_N, /* DIAGDIR_NE */
TRACKDIR_BIT_Y_SE | TRACKDIR_BIT_LEFT_S | TRACKDIR_BIT_UPPER_E, /* DIAGDIR_SE */
TRACKDIR_BIT_X_SW | TRACKDIR_BIT_UPPER_W | TRACKDIR_BIT_RIGHT_S, /* DIAGDIR_SW */
TRACKDIR_BIT_Y_NW | TRACKDIR_BIT_RIGHT_N | TRACKDIR_BIT_LOWER_W /* DIAGDIR_NW */
};
-const Trackdir _next_trackdir[] = {
+extern const Trackdir _next_trackdir[] = {
TRACKDIR_X_NE, TRACKDIR_Y_SE, TRACKDIR_LOWER_E, TRACKDIR_UPPER_E, TRACKDIR_RIGHT_S, TRACKDIR_LEFT_S, INVALID_TRACKDIR, INVALID_TRACKDIR,
TRACKDIR_X_SW, TRACKDIR_Y_NW, TRACKDIR_LOWER_W, TRACKDIR_UPPER_W, TRACKDIR_RIGHT_N, TRACKDIR_LEFT_N
};
/* Maps a trackdir to all trackdirs that make 90 deg turns with it. */
-const TrackdirBits _track_crosses_trackdirs[] = {
+extern const TrackdirBits _track_crosses_trackdirs[] = {
TRACKDIR_BIT_Y_SE | TRACKDIR_BIT_Y_NW, /* TRACK_X */
TRACKDIR_BIT_X_NE | TRACKDIR_BIT_X_SW, /* TRACK_Y */
TRACKDIR_BIT_RIGHT_N | TRACKDIR_BIT_RIGHT_S | TRACKDIR_BIT_LEFT_N | TRACKDIR_BIT_LEFT_S, /* TRACK_UPPER */
@@ -54,7 +54,7 @@ const TrackdirBits _track_crosses_trackdirs[] = {
};
/* Maps a track to all tracks that make 90 deg turns with it. */
-const TrackBits _track_crosses_tracks[] = {
+extern const TrackBits _track_crosses_tracks[] = {
TRACK_BIT_Y, /* TRACK_X */
TRACK_BIT_X, /* TRACK_Y */
TRACK_BIT_VERT, /* TRACK_UPPER */
@@ -65,12 +65,12 @@ const TrackBits _track_crosses_tracks[] = {
/* Maps a trackdir to the (4-way) direction the tile is exited when following
* that trackdir */
-const DiagDirection _trackdir_to_exitdir[] = {
+extern const DiagDirection _trackdir_to_exitdir[] = {
DIAGDIR_NE,DIAGDIR_SE,DIAGDIR_NE,DIAGDIR_SE,DIAGDIR_SW,DIAGDIR_SE, DIAGDIR_NE,DIAGDIR_NE,
DIAGDIR_SW,DIAGDIR_NW,DIAGDIR_NW,DIAGDIR_SW,DIAGDIR_NW,DIAGDIR_NE,
};
-const Trackdir _track_exitdir_to_trackdir[][DIAGDIR_END] = {
+extern const Trackdir _track_exitdir_to_trackdir[][DIAGDIR_END] = {
{TRACKDIR_X_NE, INVALID_TRACKDIR, TRACKDIR_X_SW, INVALID_TRACKDIR},
{INVALID_TRACKDIR, TRACKDIR_Y_SE, INVALID_TRACKDIR, TRACKDIR_Y_NW},
{TRACKDIR_UPPER_E, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_UPPER_W},
@@ -79,7 +79,7 @@ const Trackdir _track_exitdir_to_trackdir[][DIAGDIR_END] = {
{TRACKDIR_RIGHT_N, TRACKDIR_RIGHT_S, INVALID_TRACKDIR, INVALID_TRACKDIR}
};
-const Trackdir _track_enterdir_to_trackdir[][DIAGDIR_END] = { // TODO: replace magic with enums
+extern const Trackdir _track_enterdir_to_trackdir[][DIAGDIR_END] = { // TODO: replace magic with enums
{TRACKDIR_X_NE, INVALID_TRACKDIR, TRACKDIR_X_SW, INVALID_TRACKDIR},
{INVALID_TRACKDIR, TRACKDIR_Y_SE, INVALID_TRACKDIR, TRACKDIR_Y_NW},
{INVALID_TRACKDIR, TRACKDIR_UPPER_E, TRACKDIR_UPPER_W, INVALID_TRACKDIR},
@@ -88,7 +88,7 @@ const Trackdir _track_enterdir_to_trackdir[][DIAGDIR_END] = { // TODO: replace m
{INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_RIGHT_S, TRACKDIR_RIGHT_N}
};
-const Trackdir _track_direction_to_trackdir[][DIR_END] = {
+extern const Trackdir _track_direction_to_trackdir[][DIR_END] = {
{INVALID_TRACKDIR, TRACKDIR_X_NE, INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_X_SW, INVALID_TRACKDIR, INVALID_TRACKDIR},
{INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_Y_SE, INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_Y_NW},
{INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_UPPER_E, INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_UPPER_W, INVALID_TRACKDIR},
@@ -97,12 +97,12 @@ const Trackdir _track_direction_to_trackdir[][DIR_END] = {
{TRACKDIR_RIGHT_N, INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_RIGHT_S, INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR}
};
-const Trackdir _dir_to_diag_trackdir[] = {
+extern const Trackdir _dir_to_diag_trackdir[] = {
TRACKDIR_X_NE, TRACKDIR_Y_SE, TRACKDIR_X_SW, TRACKDIR_Y_NW,
};
-RailType GetTileRailType(TileIndex tile, Trackdir trackdir)
+RailType GetTileRailType(TileIndex tile, Track track)
{
switch (GetTileType(tile)) {
case MP_RAILWAY:
diff --git a/src/rail.h b/src/rail.h
index 37270a1bf2..aaadc9060d 100644
--- a/src/rail.h
+++ b/src/rail.h
@@ -9,6 +9,7 @@
#include "tile.h"
typedef enum RailTypes {
+ RAILTYPE_BEGIN = 0,
RAILTYPE_RAIL = 0,
RAILTYPE_ELECTRIC = 1,
RAILTYPE_MONO = 2,
@@ -19,10 +20,17 @@ typedef enum RailTypes {
typedef byte RailTypeMask;
+/** Allow incrementing of Track variables */
+DECLARE_POSTFIX_INCREMENT(RailType);
+/** Define basic enum properties */
+template <> struct EnumPropsT : MakeEnumPropsT {};
+typedef TinyEnumT RailTypeByte;
+
/** These are used to specify a single track.
* Can be translated to a trackbit with TrackToTrackbit */
typedef enum Track {
+ TRACK_BEGIN = 0,
TRACK_X = 0,
TRACK_Y = 1,
TRACK_UPPER = 2,
@@ -33,6 +41,12 @@ typedef enum Track {
INVALID_TRACK = 0xFF
} Track;
+/** Allow incrementing of Track variables */
+DECLARE_POSTFIX_INCREMENT(Track);
+/** Define basic enum properties */
+template <> struct EnumPropsT