1
0
mirror of https://github.com/OpenTTD/OpenTTD.git synced 2025-08-15 18:49:10 +00:00

Compare commits

..

1 Commits

Author SHA1 Message Date
orudge
001b12b742 (svn r2355) Tagged 0.4.0.1 2005-05-21 19:42:12 +00:00
366 changed files with 41991 additions and 56328 deletions

233
Doxyfile
View File

@@ -1,233 +0,0 @@
#---------------------------------------------------------------------------
# Project related configuration options
#---------------------------------------------------------------------------
PROJECT_NAME = openttd
OUTPUT_DIRECTORY = docs/source/
CREATE_SUBDIRS = NO
OUTPUT_LANGUAGE = English
USE_WINDOWS_ENCODING = NO
BRIEF_MEMBER_DESC = YES
REPEAT_BRIEF = YES
ABBREVIATE_BRIEF = "The $name class" \
"The $name widget" \
"The $name file" \
is \
provides \
specifies \
contains \
represents \
a \
an \
the
ALWAYS_DETAILED_SEC = NO
INLINE_INHERITED_MEMB = NO
FULL_PATH_NAMES = YES
STRIP_FROM_PATH = ./
STRIP_FROM_INC_PATH =
SHORT_NAMES = NO
JAVADOC_AUTOBRIEF = YES
MULTILINE_CPP_IS_BRIEF = NO
DETAILS_AT_TOP = NO
INHERIT_DOCS = YES
DISTRIBUTE_GROUP_DOC = NO
TAB_SIZE = 2
ALIASES =
OPTIMIZE_OUTPUT_FOR_C = YES
OPTIMIZE_OUTPUT_JAVA = NO
SUBGROUPING = YES
#---------------------------------------------------------------------------
# Build related configuration options
#---------------------------------------------------------------------------
EXTRACT_ALL = NO
EXTRACT_PRIVATE = YES
EXTRACT_STATIC = YES
EXTRACT_LOCAL_CLASSES = YES
EXTRACT_LOCAL_METHODS = YES
HIDE_UNDOC_MEMBERS = NO
HIDE_UNDOC_CLASSES = NO
HIDE_FRIEND_COMPOUNDS = NO
HIDE_IN_BODY_DOCS = NO
INTERNAL_DOCS = NO
CASE_SENSE_NAMES = YES
HIDE_SCOPE_NAMES = NO
SHOW_INCLUDE_FILES = YES
INLINE_INFO = YES
SORT_MEMBER_DOCS = YES
SORT_BRIEF_DOCS = NO
SORT_BY_SCOPE_NAME = NO
GENERATE_TODOLIST = YES
GENERATE_TESTLIST = YES
GENERATE_BUGLIST = YES
GENERATE_DEPRECATEDLIST= YES
ENABLED_SECTIONS =
MAX_INITIALIZER_LINES = 30
SHOW_USED_FILES = YES
SHOW_DIRECTORIES = YES
FILE_VERSION_FILTER =
#---------------------------------------------------------------------------
# configuration options related to warning and progress messages
#---------------------------------------------------------------------------
QUIET = NO
WARNINGS = YES
WARN_IF_UNDOCUMENTED = YES
WARN_IF_DOC_ERROR = YES
WARN_NO_PARAMDOC = NO
WARN_FORMAT = "$file:$line: $text"
WARN_LOGFILE =
#---------------------------------------------------------------------------
# configuration options related to the input files
#---------------------------------------------------------------------------
INPUT = ./
FILE_PATTERNS = *.c \
*.cc \
*.cxx \
*.cpp \
*.c++ \
*.h \
table/*.h
RECURSIVE = YES
EXCLUDE =
EXCLUDE_SYMLINKS = NO
EXCLUDE_PATTERNS =
EXAMPLE_PATH =
EXAMPLE_PATTERNS = *
EXAMPLE_RECURSIVE = NO
IMAGE_PATH =
INPUT_FILTER =
FILTER_PATTERNS =
FILTER_SOURCE_FILES = NO
#---------------------------------------------------------------------------
# configuration options related to source browsing
#---------------------------------------------------------------------------
SOURCE_BROWSER = YES
INLINE_SOURCES = NO
STRIP_CODE_COMMENTS = YES
REFERENCED_BY_RELATION = YES
REFERENCES_RELATION = YES
VERBATIM_HEADERS = YES
#---------------------------------------------------------------------------
# configuration options related to the alphabetical class index
#---------------------------------------------------------------------------
ALPHABETICAL_INDEX = NO
COLS_IN_ALPHA_INDEX = 5
IGNORE_PREFIX =
#---------------------------------------------------------------------------
# configuration options related to the HTML output
#---------------------------------------------------------------------------
GENERATE_HTML = YES
HTML_OUTPUT = html
HTML_FILE_EXTENSION = .html
HTML_HEADER =
HTML_FOOTER =
HTML_STYLESHEET =
HTML_ALIGN_MEMBERS = YES
GENERATE_HTMLHELP = YES
CHM_FILE =
HHC_LOCATION =
GENERATE_CHI = NO
BINARY_TOC = NO
TOC_EXPAND = YES
DISABLE_INDEX = NO
ENUM_VALUES_PER_LINE = 4
GENERATE_TREEVIEW = YES
TREEVIEW_WIDTH = 250
#---------------------------------------------------------------------------
# configuration options related to the LaTeX output
#---------------------------------------------------------------------------
GENERATE_LATEX = NO
LATEX_OUTPUT = latex
LATEX_CMD_NAME = latex
MAKEINDEX_CMD_NAME = makeindex
COMPACT_LATEX = NO
PAPER_TYPE = a4wide
EXTRA_PACKAGES =
LATEX_HEADER =
PDF_HYPERLINKS = NO
USE_PDFLATEX = NO
LATEX_BATCHMODE = NO
LATEX_HIDE_INDICES = NO
#---------------------------------------------------------------------------
# configuration options related to the RTF output
#---------------------------------------------------------------------------
GENERATE_RTF = NO
RTF_OUTPUT = rtf
COMPACT_RTF = NO
RTF_HYPERLINKS = NO
RTF_STYLESHEET_FILE =
RTF_EXTENSIONS_FILE =
#---------------------------------------------------------------------------
# configuration options related to the man page output
#---------------------------------------------------------------------------
GENERATE_MAN = YES
MAN_OUTPUT = man
MAN_EXTENSION = .3
MAN_LINKS = NO
#---------------------------------------------------------------------------
# configuration options related to the XML output
#---------------------------------------------------------------------------
GENERATE_XML = NO
XML_OUTPUT = xml
XML_SCHEMA =
XML_DTD =
XML_PROGRAMLISTING = YES
#---------------------------------------------------------------------------
# configuration options for the AutoGen Definitions output
#---------------------------------------------------------------------------
GENERATE_AUTOGEN_DEF = NO
#---------------------------------------------------------------------------
# configuration options related to the Perl module output
#---------------------------------------------------------------------------
GENERATE_PERLMOD = NO
PERLMOD_LATEX = NO
PERLMOD_PRETTY = YES
PERLMOD_MAKEVAR_PREFIX =
#---------------------------------------------------------------------------
# Configuration options related to the preprocessor
#---------------------------------------------------------------------------
ENABLE_PREPROCESSING = YES
MACRO_EXPANSION = NO
EXPAND_ONLY_PREDEF = NO
SEARCH_INCLUDES = YES
INCLUDE_PATH =
INCLUDE_FILE_PATTERNS =
PREDEFINED =
EXPAND_AS_DEFINED =
SKIP_FUNCTION_MACROS = YES
#---------------------------------------------------------------------------
# Configuration::additions related to external references
#---------------------------------------------------------------------------
TAGFILES =
GENERATE_TAGFILE = openttd.tag
ALLEXTERNALS = NO
EXTERNAL_GROUPS = YES
PERL_PATH = /usr/bin/perl
#---------------------------------------------------------------------------
# Configuration options related to the dot tool
#---------------------------------------------------------------------------
CLASS_DIAGRAMS = YES
HIDE_UNDOC_RELATIONS = YES
HAVE_DOT = NO
CLASS_GRAPH = YES
COLLABORATION_GRAPH = YES
GROUP_GRAPHS = YES
UML_LOOK = NO
TEMPLATE_RELATIONS = NO
INCLUDE_GRAPH = YES
INCLUDED_BY_GRAPH = YES
CALL_GRAPH = NO
GRAPHICAL_HIERARCHY = YES
DIRECTORY_GRAPH = YES
DOT_IMAGE_FORMAT = png
DOT_PATH =
DOTFILE_DIRS =
MAX_DOT_GRAPH_WIDTH = 1024
MAX_DOT_GRAPH_HEIGHT = 1024
MAX_DOT_GRAPH_DEPTH = 1000
DOT_TRANSPARENT = NO
DOT_MULTI_TARGETS = NO
GENERATE_LEGEND = YES
DOT_CLEANUP = YES
#---------------------------------------------------------------------------
# Configuration::additions related to the search engine
#---------------------------------------------------------------------------
SEARCHENGINE = NO

700
Makefile
View File

@@ -1,4 +1,13 @@
# $Id$
# This Makefile is partially based on "a completely generic Makefile",
# originally created by Justin Husted <husted@cs>
#
# Rewrite and sane dependencies support by Petr Baudis <pasky@ucw.cz>
# Cygwin support and configuration by Jaen Saul <slowbyte@hot.ee>
# A lot of modifications by Bjarni Corfitzen <bjarni@openttd.com>
#
# Last modified by: $Author: strigeus $
# On: $Date: 2004/03/11 19:15:06 $
##############################################################################
#
@@ -43,9 +52,9 @@
# WITH_ZLIB: savegames using zlib
# WITH_PNG: screenshots using PNG
# WITH_SDL: SDL video driver support
# WITH_COCOA: Cocoa video driver support
#
# Summary of other defines:
# MANUAL_CONFIG: do not use Makefile.config, config options set manually
# DEBUG: build in debug mode
# PROFILE: build in profile mode, disables -s and -fomit-frame-pointer
# TRANSLATOR: build in translator mode (untranslated strings are prepended by
@@ -55,12 +64,8 @@
# MIDI: if set, it will use it as custom path to midi player.
# If unset, it will use the hardcoded path in the c code
# This can still be overriden by the music.extmidi openttd.cfg option.
# WITH_DIRECTMUSIC: enable DirectMusic MIDI support
# WITH_NETWORK: enable networking
# DEDICATED: allows compilation on UNIX without SDL. Useful for dedicated servers
# MAX_NUM_AUTOSAVES: sets the number of autosaves the games will make before starting
# to overwrite the old ones. If not set, the game will use 16.
# NOTE: assign a number, not a string of a number
#
# Paths:
# INSTALL: If not set, the game uses the directory of the binary to
@@ -78,12 +83,8 @@
# PREFIX: Normally /usr/local
# BINARY_DIR: The location of the binary, normally games. (Will be prefixed
# with $PREFIX)
# DATA_DIR: The location of the data (lang, data, gm and scenario), normally
# share/games/openttd. (Will be prefixed with $PREFIX) Note that scenarios
# are only put here if USE_HOMEDIR is true, otherwise they are placed in
# PERSONAL_DIR/scenario
# ICON_DIR: The location of the openttd icon. (Will be prefixed with
# $PREFIX).
# DATA_DIR: The location of the data (lang, data and gm), normally
# share/games/openttd. (Will be prefixed with $PREFIX)
# PERSONAL_DIR: The directory where openttd.cfg and the save folder will be
# stored. You cannot use ~ here, define USE_HOMEDIR for that.
# USE_HOMEDIR: If this variable is set, PERSONAL_DIR will be prefixed with
@@ -108,22 +109,14 @@
#
# Special for crosscompiling there are some commands available:
#
# UNIVERSAL_BINARY: builds a universal binary for OSX. Make sure you got both PPC and x86 libs. Only works with GCC 4 or newer
# TRIPLE_BINARY: builds a universal binary with the addition of code optimised for G5 (which means a total of 3 binaries in one file)
# OTTD_PPC, OTTD_PPC970, OTTD_i386: compile for target architecture.
# Multiple flags can be used so OTTD_PPC:=1 OTTD_i386:=1 produces the same result as UNIVERSAL_BINARY
#
# JAGUAR: Crosscompiling for OSX 1.2.8 (codenamed Jaguar). Only works if OSX is defined too. Only works with GCC 4 or newer
# This can be changed to any PPC version of OSX by changing the ppc flags in Makefile.config
#
# ENDIAN_FORCE: forces the endian-check to give a certain result. Can be BE, LE or PREPROCESSOR.
# PREPROCESSOR is always used on all OSX targets and will make the preprocessor pick the right endian.
# this means that you don't have to think about endianess when compiling for OSX.
# Very useful for universal binaries and crosscompilers. Not sure if it works on non OSX targets
# ENDIAN_FORCE: forces the endian-check to give a certain result. Can be either BE or LE.
# WINDRES: the location of your windres
# CC_HOST: the gcc of your localhost if you are making a target that produces incompatible executables
# CFLAGS_HOST: cflags used for CC_HOST. Make it something if you are getting errors when you try to compi
# windows executables on linux. (just: CFLAGS_HOST:='-I' or something)
#
# Experimental (does not work properly):
# WITH_DIRECTMUSIC: enable DirectMusic MIDI support
##############################################################################
@@ -134,8 +127,12 @@
# Makefile version tag
# it checks if the version tag in Makefile.config is the same and force update outdated config files
MAKEFILE_VERSION:=10
MAKEFILE_VERSION:=7
# CONFIG_WRITER has to be found even for manual configuration
CONFIG_WRITER=makefiledir/Makefile.config_writer
ifndef MANUAL_CONFIG
# Automatic configuration
MAKE_CONFIG:=Makefile.config
MAKEFILE:=Makefile
@@ -146,10 +143,26 @@ CONFIG_WRITER=makefiledir/Makefile.config_writer
# See target section for how this is built, suppress errors
# since first time it isn't found but make reads this twice
-include $(MAKE_CONFIG)
else
CONFIG_INCLUDED:=1
endif
# updates Makefile.config if it's outdated
ifneq ($(MAKEFILE_VERSION),$(CONFIG_VERSION))
ifndef MANUAL_CONFIG # manual config should not check this
UPDATECONFIG:=upgradeconf
CONFIG_INCLUDED:=
else
# this should define SDL-CONFIG for manual configuration
ifeq ($(shell uname),FreeBSD)
SDL-CONFIG:=sdl11-config
else
SDL-CONFIG:=sdl-config
endif
endif
endif
ifndef SDL-CONFIG
UPDATECONFIG:=upgradeconf
CONFIG_INCLUDED:=
endif
@@ -174,10 +187,6 @@ ifdef SUPRESS_LANG_ERRORS
LANG_ERRORS = >/dev/null 2>&1
endif
ifdef OSX
-include os/MacOSX/Makefile.setup
endif
ifdef STATIC
ifndef WIN32
ifndef OSX
@@ -190,14 +199,14 @@ endif
endif
endif
ifdef WITH_COCOA
ifdef WITH_SDL
$(error You can not use both the SDL video driver and the Cocoa video driver at the same time)
ifdef RELEASE
ifdef OSX
ifndef STATIC
$(error do not make dynamically linked releases. Most users can't use those)
endif
ifdef DEDICATED
$(error You can not use the Cocoa video driver in a dedicated server)
endif
else
endif
# Force SDL on UNIX platforms
ifndef WITH_SDL
ifdef UNIX
@@ -206,37 +215,12 @@ $(error You need to have SDL installed in order to run OpenTTD on UNIX. Use DEDI
endif
endif
endif
endif
# remove the dependancy for sdl if DEDICALTED is used
ifdef DEDICATED
WITH_SDL:=
WITH_SDL:=
endif
# add -lpthread to LDFLAGS
ifndef WIN32
ifndef MORPHOS
ifndef OSX
LDFLAGS+=-lpthread
endif
endif
endif
ifdef OSX
LDFLAGS+=-framework Cocoa
endif
ifdef WITH_SDL
ifndef SDL_CONFIG
$(error WITH_SDL can't be used when SDL_CONFIG is not set. Edit Makefile.config to correct this)
endif
endif
ifdef WITH_PNG
ifndef LIBPNG_CONFIG
$(error WITH_PNG can't be used when LIBPNG_CONFIG is not set. Edit Makefile.config to correct this)
endif
endif
##############################################################################
#
@@ -256,11 +240,33 @@ ENDIAN_CHECK=endian_check$(EXE)
STRGEN=strgen/strgen$(EXE)
OSXAPP="OpenTTD.app"
REV := 0.4.8-RC1
# What revision are we compiling, if we have an idea?
REV_NUMBER := $(shell if test -d .svn; then svnversion . | tr -dc 0-9; fi)
ifdef RELEASE
REV:=$(RELEASE)
else
REV := $(shell if test -d .svn; then svnversion . | awk '{ print "r"$$0 }'; fi)
tmp_test:=$(shell echo "$(REV)" | grep "M" )
ifdef tmp_test
REV_NUMBER:=1
endif
endif
ifndef REV_NUMBER
REV_NUMBER:=0
endif
# MorphOS needs builddate
BUILDDATE=`date +%d.%m.%y`
# AMD64 needs a little more settings to work
ifeq ($(shell uname -m), x86_64)
endwarnings:=endwarnings
64_bit_warnings:=64_bit_warnings
BASECFLAGS += -m64
endif
# Check if there is a windres override
ifndef WINDRES
WINDRES = windres
@@ -279,19 +285,27 @@ ifndef CFLAGS_HOST
CFLAGS_HOST = $(BASECFLAGS)
endif
# When calling the compiler, use these flags
# -g debugging symbols
# -Wall all warnings
# -s automatic strip
#
# You may also want:
# -O optimize or -O2 fully optimize (O's above 2 are not recommended)
# -pg profile - generate profiling data. See "man gprof" to use this.
CC_VERSION = $(shell $(CC) -dumpversion | cut -c 1,3)
# GNU make can only test for (in)equality
# this is a workaround to test for >=
ifeq ($(shell expr $(CC_VERSION) \>= 29), 1)
CFLAGS += -O -Wall -Wno-multichar -Wsign-compare -Wstrict-prototypes -Wundef
ifeq ($(shell if test $(CC_VERSION) -ge 29; then echo true; fi), true)
CFLAGS += -O -Wall -Wno-multichar -Wsign-compare -Wstrict-prototypes
CFLAGS += -Wwrite-strings -Wpointer-arith
endif
ifeq ($(shell expr $(CC_VERSION) \>= 30), 1)
ifeq ($(shell if test $(CC_VERSION) -ge 30; then echo true; fi), true)
CFLAGS += -W -Wno-unused-parameter
endif
ifeq ($(shell expr $(CC_VERSION) \>= 34), 1)
ifeq ($(shell if test $(CC_VERSION) -ge 34; then echo true; fi), true)
CFLAGS += -Wdeclaration-after-statement -Wold-style-definition
endif
@@ -328,10 +342,10 @@ endif
ifdef OSX
# these compilerflags makes the app run as fast as possible without making the app unstable. It works on G3 or newer
BASECFLAGS += -O3 -funroll-loops -fsched-interblock -falign-loops=16 -falign-jumps=16 -falign-functions=16 -falign-jumps-max-skip=15 -falign-loops-max-skip=15 -mdynamic-no-pic
BASECFLAGS += -O3 -funroll-loops -fsched-interblock -falign-loops=16 -falign-jumps=16 -falign-functions=16 -falign-jumps-max-skip=15 -falign-loops-max-skip=15 -mdynamic-no-pic -mpowerpc-gpopt -force_cpusubtype_ALL
else
ifdef MORPHOS
BASECFLAGS += -I/gg/os-include -O2 -noixemul -fstrict-aliasing -fexpensive-optimizations
BASECFLAGS += -O2 -noixemul -fstrict-aliasing -fexpensive-optimizations
BASECFLAGS += -mcpu=604 -fno-inline -mstring -mmultiple
else
BASECFLAGS += -O2
@@ -370,13 +384,12 @@ endif
ifdef BEOS
CDEFS += -DBEOS
LDFLAGS += -lmidi -lbe -lpthread
LDFLAGS += -lmidi -lbe
ifdef WITH_NETWORK
ifdef BEOS_NET_SERVER
CDEFS += -DBEOS_NET_SERVER
LDFLAGS += -lnet
else
# BONE needs a few more libraries than R5
# Zeta needs a few more libraries than R5
LDFLAGS += -lbind -lsocket
endif
endif
@@ -394,30 +407,46 @@ LDFLAGS += -lnsl -lsocket
endif
endif
# tell the source that we are building a dedicated server
ifdef DEDICATED
CDEFS += -DDEDICATED
endif
# SDL config
ifdef WITH_SDL
CDEFS += -DWITH_SDL
CFLAGS += $(shell $(SDL_CONFIG) --cflags)
CFLAGS += $(shell $(SDL-CONFIG) --cflags)
ifdef STATIC
LIBS += $(shell $(SDL_CONFIG) --static-libs)
LIBS += $(shell $(SDL-CONFIG) --static-libs)
else
LIBS += $(shell $(SDL_CONFIG) --libs)
LIBS += $(shell $(SDL-CONFIG) --libs)
endif
endif
# zlib config
ifdef WITH_ZLIB
CDEFS += -DWITH_ZLIB
CDEFS += -DWITH_ZLIB
ifdef STATIC
ifdef OSX
# OSX links dynamically to zlib, even in static builds since it's always present in the system
# zlib is default on OSX, so everybody have it. No need for static linking
LIBS += -lz
else
ifndef STATIC_ZLIB_PATH
ifndef MANUAL_CONFIG
# updates Makefile.config with the zlib path
UPDATECONFIG:=upgradeconf
endif
TEMP:=$(shell ls /lib 2>/dev/null | grep "zlib.a")$(shell ls /lib 2>/dev/null | grep "libz.a")
ifdef TEMP
STATIC_ZLIB_PATH:=/lib/$(TEMP)
else
TEMP:=$(shell ls /usr/lib 2>/dev/null | grep "zlib.a")$(shell ls /usr/lib 2>/dev/null | grep "libz.a")
ifdef TEMP
STATIC_ZLIB_PATH:=/usr/lib/$(TEMP)
else
TEMP:=$(shell ls /usr/local/lib 2>/dev/null | grep "zlib.a")$(shell ls /usr/local/lib 2>/dev/null | grep "libz.a")
ifdef TEMP
STATIC_ZLIB_PATH:=/usr/local/lib/$(TEMP)
endif
endif
endif
endif
LIBS += $(STATIC_ZLIB_PATH)
endif
else
@@ -428,25 +457,19 @@ endif
# libpng config
ifdef WITH_PNG
CDEFS += -DWITH_PNG
CFLAGS += $(shell $(LIBPNG_CONFIG) --cppflags --I_opts)
CFLAGS += $(shell libpng-config --cflags)
# seems like older libpng versions are broken and need this
PNGCONFIG_FLAGS = --ldflags --libs
ifdef STATIC
ifdef OSX
# Seems like we need a tiny hack for OSX static to work
LIBS += $(shell $(LIBPNG_CONFIG) --prefix)/lib/libpng.a
LIBS += $(shell libpng-config --prefix)/lib/libpng.a
else
LIBS += $(shell $(LIBPNG_CONFIG) --static $(PNGCONFIG_FLAGS))
LIBS += $(shell libpng-config --static $(PNGCONFIG_FLAGS))
endif
else
LIBS += $(shell $(LIBPNG_CONFIG) --L_opts $(PNGCONFIG_FLAGS))
endif
endif
ifdef OSX
ifndef JAGUAR
LIBS += -liconv
LIBS += $(shell libpng-config --L_opts $(PNGCONFIG_FLAGS))
endif
endif
@@ -468,30 +491,18 @@ else
STRGEN_FLAGS=
endif
# OSX specific setup
# MIDI setup
ifdef OSX
# set the endian flag for OSX, that can't fail
ENDIAN_FORCE:=PREPROCESSOR
ifndef DEDICATED
LIBS += -framework QuickTime
endif
ifdef WITH_COCOA
CDEFS += -DWITH_COCOA
LIBS += -F/System/Library/Frameworks -framework Cocoa -framework Carbon -framework AudioUnit
endif
# OSX path setup
ifndef SECOND_DATA_PATH
SECOND_DATA_PATH:="$(OSXAPP)/Contents/Data/"
endif
ifndef CUSTOM_LANG_DIR
ifndef DEDICATED
CUSTOM_LANG_DIR:="$(OSXAPP)/Contents/Lang/"
endif
endif
ifndef MIDI
MIDI:=$(OSXAPP)/Contents/macosx/track_starter
endif
ifndef SECOND_DATA_PATH
SECOND_DATA_PATH:="$(OSXAPP)/Contents/Data/"
endif
ifndef CUSTOM_LANG_DIR
CUSTOM_LANG_DIR:="$(OSXAPP)/Contents/Lang/"
endif
endif
ifdef MIDI
@@ -501,15 +512,20 @@ CDEFS += -DMIDI_ARG=\"$(MIDI_ARG)\"
endif
endif
ifdef MAX_NUM_AUTOSAVES
CDEFS += -DMAX_NUM_AUTOSAVES=$(MAX_NUM_AUTOSAVES)
endif
ifdef WITH_NETWORK
CDEFS += -DENABLE_NETWORK
ifdef QNX
LIBS += -lsocket
endif
ifdef UNIX
ifndef OSX
ifndef MORPHOS
# this have caused problems on many platforms and disabling it didn't break anything
# now we test if disabling it as a general breaks it for anybody
#LIBS += -lresolv
endif
endif
endif
endif
@@ -543,12 +559,10 @@ ifdef INSTALL
# the prefix is not prepended in the makefile config
BINARY_DIR_PREFIXED:=$(PREFIX)/$(BINARY_DIR)
DATA_DIR_PREFIXED:=$(PREFIX)/$(DATA_DIR)
ICON_DIR_PREFIXED:=$(PREFIX)/$(ICON_DIR)
# We use _INSTALL vars here, these vars are the locations where the files will
# be installed
DATA_DIR_INSTALL=$(DEST_DIR)/$(DATA_DIR_PREFIXED)
BINARY_DIR_INSTALL=$(DEST_DIR)/$(BINARY_DIR_PREFIXED)
ICON_DIR_INSTALL=$(DEST_DIR)/$(ICON_DIR_PREFIXED)
# Let the code know where to find stuff
ifdef DATA_DIR_PREFIXED
CDEFS += -DGAME_DATA_DIR=\"$(DATA_DIR_PREFIXED)/\"
@@ -572,167 +586,136 @@ endif
### Sources
# clean up C_SOURCES first. Needed since building universal binaries on OSX calls the makefile recursively (just one time)
SRCS :=
C_SOURCES += ai.c
C_SOURCES += ai_build.c
C_SOURCES += ai_new.c
C_SOURCES += ai_pathfinder.c
C_SOURCES += ai_shared.c
C_SOURCES += aircraft_cmd.c
C_SOURCES += aircraft_gui.c
C_SOURCES += airport.c
C_SOURCES += airport_gui.c
C_SOURCES += aystar.c
C_SOURCES += bridge_gui.c
C_SOURCES += callback_table.c
C_SOURCES += clear_cmd.c
C_SOURCES += command.c
C_SOURCES += console.c
C_SOURCES += console_cmds.c
C_SOURCES += debug.c
C_SOURCES += dedicated.c
C_SOURCES += depot.c
C_SOURCES += disaster_cmd.c
C_SOURCES += dock_gui.c
C_SOURCES += dummy_land.c
C_SOURCES += economy.c
C_SOURCES += engine.c
C_SOURCES += engine_gui.c
C_SOURCES += fileio.c
C_SOURCES += gfx.c
C_SOURCES += graph_gui.c
C_SOURCES += newgrf.c
C_SOURCES += industry_cmd.c
C_SOURCES += industry_gui.c
C_SOURCES += intro_gui.c
C_SOURCES += landscape.c
C_SOURCES += main_gui.c
C_SOURCES += map.c
C_SOURCES += md5.c
C_SOURCES += minilzo.c
C_SOURCES += misc.c
C_SOURCES += misc_cmd.c
C_SOURCES += misc_gui.c
C_SOURCES += mixer.c
C_SOURCES += music_gui.c
C_SOURCES += namegen.c
C_SOURCES += network.c
C_SOURCES += network_client.c
C_SOURCES += network_data.c
C_SOURCES += network_gamelist.c
C_SOURCES += network_gui.c
C_SOURCES += network_server.c
C_SOURCES += network_udp.c
C_SOURCES += news_gui.c
C_SOURCES += npf.c
C_SOURCES += oldloader.c
C_SOURCES += order_cmd.c
C_SOURCES += order_gui.c
C_SOURCES += pathfind.c
C_SOURCES += player_gui.c
C_SOURCES += players.c
C_SOURCES += pool.c
C_SOURCES += queue.c
C_SOURCES += rail_cmd.c
C_SOURCES += rail_gui.c
C_SOURCES += rev.c
C_SOURCES += road_cmd.c
C_SOURCES += road_gui.c
C_SOURCES += roadveh_cmd.c
C_SOURCES += roadveh_gui.c
C_SOURCES += saveload.c
C_SOURCES += screenshot.c
C_SOURCES += settings.c
C_SOURCES += settings_gui.c
C_SOURCES += ship_cmd.c
C_SOURCES += ship_gui.c
C_SOURCES += signs.c
C_SOURCES += smallmap_gui.c
C_SOURCES += sound.c
C_SOURCES += sprite.c
C_SOURCES += spritecache.c
C_SOURCES += station_cmd.c
C_SOURCES += station_gui.c
C_SOURCES += string.c
C_SOURCES += strings.c
C_SOURCES += subsidy_gui.c
C_SOURCES += terraform_gui.c
C_SOURCES += texteff.c
C_SOURCES += tile.c
C_SOURCES += town_cmd.c
C_SOURCES += town_gui.c
C_SOURCES += train_cmd.c
C_SOURCES += train_gui.c
C_SOURCES += tree_cmd.c
C_SOURCES += ttd.c
C_SOURCES += tunnelbridge_cmd.c
C_SOURCES += unmovable_cmd.c
C_SOURCES += vehicle.c
C_SOURCES += vehicle_gui.c
C_SOURCES += viewport.c
C_SOURCES += water_cmd.c
C_SOURCES += waypoint.c
C_SOURCES += widget.c
C_SOURCES += window.c
SRCS += aircraft_cmd.c
SRCS += aircraft_gui.c
SRCS += airport.c
SRCS += airport_gui.c
SRCS += aystar.c
SRCS += bridge_gui.c
SRCS += callback_table.c
SRCS += clear_cmd.c
SRCS += command.c
SRCS += console.c
SRCS += console_cmds.c
SRCS += currency.c
SRCS += debug.c
SRCS += dedicated.c
SRCS += depot.c
SRCS += disaster_cmd.c
SRCS += dock_gui.c
SRCS += driver.c
SRCS += dummy_land.c
SRCS += economy.c
SRCS += engine.c
SRCS += engine_gui.c
SRCS += fileio.c
SRCS += gfx.c
SRCS += gfxinit.c
SRCS += graph_gui.c
SRCS += industry_cmd.c
SRCS += industry_gui.c
SRCS += intro_gui.c
SRCS += landscape.c
SRCS += main_gui.c
SRCS += map.c
SRCS += md5.c
SRCS += mersenne.c
SRCS += minilzo.c
SRCS += misc.c
SRCS += misc_cmd.c
SRCS += misc_gui.c
SRCS += mixer.c
SRCS += music_gui.c
SRCS += namegen.c
SRCS += network.c
SRCS += network_client.c
SRCS += network_data.c
SRCS += network_gamelist.c
SRCS += network_gui.c
SRCS += network_server.c
SRCS += network_udp.c
SRCS += newgrf.c
SRCS += news_gui.c
SRCS += npf.c
SRCS += oldloader.c
SRCS += openttd.c
SRCS += order_cmd.c
SRCS += order_gui.c
SRCS += pathfind.c
SRCS += player_gui.c
SRCS += players.c
SRCS += pool.c
SRCS += queue.c
SRCS += rail.c
SRCS += rail_cmd.c
SRCS += rail_gui.c
SRCS += rev.c
SRCS += road_cmd.c
SRCS += road_gui.c
SRCS += roadveh_cmd.c
SRCS += roadveh_gui.c
SRCS += saveload.c
SRCS += screenshot.c
SRCS += settings.c
SRCS += settings_gui.c
SRCS += ship_cmd.c
SRCS += ship_gui.c
SRCS += signs.c
SRCS += smallmap_gui.c
SRCS += sound.c
SRCS += sprite.c
SRCS += spritecache.c
SRCS += station_cmd.c
SRCS += station_gui.c
SRCS += station_newgrf.c
SRCS += string.c
SRCS += strings.c
SRCS += subsidy_gui.c
SRCS += terraform_gui.c
SRCS += texteff.c
SRCS += thread.c
SRCS += tile.c
SRCS += town_cmd.c
SRCS += town_gui.c
SRCS += train_cmd.c
SRCS += train_gui.c
SRCS += tree_cmd.c
SRCS += tunnel_map.c
SRCS += tunnelbridge_cmd.c
SRCS += unmovable_cmd.c
SRCS += vehicle.c
SRCS += vehicle_gui.c
SRCS += viewport.c
SRCS += water_cmd.c
SRCS += waypoint.c
SRCS += widget.c
SRCS += window.c
SRCS += music/null_m.c
SRCS += sound/null_s.c
SRCS += video/dedicated_v.c
SRCS += video/null_v.c
# AI related files
SRCS += ai/ai.c
SRCS += ai/default/default.c
SRCS += ai/trolly/build.c
SRCS += ai/trolly/pathfinder.c
SRCS += ai/trolly/shared.c
SRCS += ai/trolly/trolly.c
CXX_SOURCES =
ifdef WITH_SDL
SRCS += sdl.c
SRCS += sound/sdl_s.c
SRCS += video/sdl_v.c
C_SOURCES += sdl.c
endif
ifdef WIN32
SRCS += win32.c
SRCS += music/win32_m.c
SRCS += sound/win32_s.c
SRCS += video/win32_v.c
C_SOURCES += win32.c w32dm.c
else
SRCS += unix.c
SRCS += music/extmidi.c
C_SOURCES += extmidi.c unix.c
endif
ifdef OSX
SRCS += os/macosx/macos.m
ifndef DEDICATED
SRCS += music/qtmidi.c
endif
ifdef WITH_COCOA
SRCS += video/cocoa_v.m
SRCS += sound/cocoa_s.c
SRCS += os/macosx/splash.c
endif
endif
OBJS = $(C_SOURCES:%.c=%.o) $(CXX_SOURCES:%.cpp=%.o)
ifdef BEOS
SRCS += music/bemidi.cpp
CXX_SOURCES += os/beos/bemidi.cpp
CFLAGS += -I.
endif
ifdef WIN32
SRCS += ottdres.rc
# Resource file
OBJS += winres.o
endif
ifdef WITH_DIRECTMUSIC
SRCS += music/dmusic.cpp
CXX_SOURCES += w32dm2.cpp
endif
OBJS += $(filter %.o, $(SRCS:%.cpp=%.o) $(SRCS:%.m=%.o) $(SRCS:%.c=%.o) $(SRCS:%.rc=%.o))
DEPS = $(OBJS:%.o=.deps/%.d)
LANG_TXT = $(filter-out %.unfinished.txt,$(wildcard lang/*.txt))
@@ -744,15 +727,40 @@ LANGS = $(LANG_TXT:%.txt=%.lng)
# Build commands
#
# If we are verbose, we will show commands prefixed by $(Q).
# The $(Q)s get replaced by @ in non-verbose mode.
# If we are verbose, we will show commands prefixed by $(Q) (which acts as
# @ in the non-verbose mode), and we will show the "real" cmds instead of
# their quiet versions (which are used in the non-verbose mode).
# Inspired by the Linux kernel build system.
ifdef VERBOSE
Q =
quiet =
else
Q = @
quiet = quiet_
endif
# Show the command (quiet or non-quiet version based on the assignment
# just above) and then execute it.
cmd = @$(if $($(quiet)cmd_$(1)),echo $($(quiet)cmd_$(1)) &&) $(cmd_$(1))
# The build commands themselves. Note that if you omit the quiet version,
# nothing will be shown in the non-verbose mode.
quiet_cmd_compile_link = '===> Compiling and Linking $@'
cmd_compile_link = $(CC_HOST) $(CFLAGS_HOST) $(CDEFS) $< -o $@
quiet_cmd_ttd_link = '===> Linking $@'
cmd_ttd_link = $(CC) $(LDFLAGS) $(TTDLDFLAGS) $(OBJS) $(LIBS) -o $@
COMPILE_PARAMS=$(CFLAGS) $(CDEFS) -MD -c $< -o $@
quiet_cmd_c_compile = '===> Compiling $<'
cmd_c_compile = $(CC) $(COMPILE_PARAMS)
quiet_cmd_cxx_compile = '===> Compiling $<'
cmd_cxx_compile = $(CXX) $(COMPILE_PARAMS)
##############################################################################
#
@@ -764,16 +772,12 @@ endif
ifdef OSX
# needs to be before all
OSX:=OSX
OSX_MIDI_PLAYER_FILE:=os/macos/OpenTTDMidi.class
endif
all: endian_target.h endian_host.h $(UPDATECONFIG) $(LANGS) $(TTD) $(OSX)
ifdef OSX
-include os/macosx/Makefile
endif
all: endian_target.h endian_host.h $(UPDATECONFIG) $(LANGS) $(TTD) $(OSX) $(endwarnings)
endian_host.h: $(ENDIAN_CHECK)
@echo '===> Testing endianness for host'
@@ -784,20 +788,37 @@ endian_target.h: $(ENDIAN_CHECK)
$(Q)./$(ENDIAN_CHECK) $(ENDIAN_FORCE) > $@
$(ENDIAN_CHECK): endian_check.c
@echo '===> Compiling and Linking $@'
$(Q)$(CC_HOST) $(CFLAGS_HOST) $(CDEFS) $< -o $@
$(call cmd,compile_link)
ifndef NATIVE_OSX
# OSX links in os/macosx/Makefile to handle universal binaries better
$(TTD): $(OBJS) $(MAKE_CONFIG)
@echo '===> Linking $@'
$(Q)$(CC) $(LDFLAGS) $(TTDLDFLAGS) $(OBJS) $(LIBS) -o $@
endif
$(TTD): table/strings.h $(OBJS) $(MAKE_CONFIG)
$(call cmd,ttd_link)
$(OSX): $(TTD)
$(Q)rm -fr "$(OSXAPP)"
$(Q)mkdir -p "$(OSXAPP)"/Contents/MacOS
$(Q)mkdir -p "$(OSXAPP)"/Contents/Resources
$(Q)mkdir -p "$(OSXAPP)"/Contents/Data
$(Q)mkdir -p "$(OSXAPP)"/Contents/Lang
$(Q)echo "APPL????" > "$(OSXAPP)"/Contents/PkgInfo
$(Q)cp os/macosx/openttd.icns "$(OSXAPP)"/Contents/Resources/openttd.icns
$(Q)os/macosx/plistgen.sh "$(OSXAPP)" "$(REV)"
$(Q)cp os/macosx/track_starter "$(OSXAPP)"/Contents/MacOS
$(Q)ls os/macosx | grep -q "\.class" || \
javac os/macosx/OpenTTDMidi.java
$(Q)cp os/macosx/OpenTTDMidi.class "$(OSXAPP)"/Contents/MacOS
$(Q)cp data/* "$(OSXAPP)"/Contents/Data/
$(Q)cp lang/*.lng "$(OSXAPP)"/Contents/Lang/
$(Q)cp $(TTD) "$(OSXAPP)"/Contents/MacOS/$(TTD)
$(endwarnings): $(64_bit_warnings)
$(64_bit_warnings):
$(warning 64 bit CPUs will get some 64 bit specific bugs!)
$(warning If you see any bugs, include in your bug report that you use a 64 bit CPU)
$(STRGEN): strgen/strgen.c endian_host.h
@echo '===> Compiling and Linking $@'
$(Q)$(CC_HOST) $(CFLAGS_HOST) $(CDEFS) $< -o $@
$(call cmd,compile_link)
table/strings.h: lang/english.txt $(STRGEN)
@echo '===> Generating $@'
@@ -805,7 +826,11 @@ table/strings.h: lang/english.txt $(STRGEN)
lang/%.lng: lang/%.txt $(STRGEN) lang/english.txt
@echo '===> Compiling language $(*F)'
$(Q)$(STRGEN) $(STRGEN_FLAGS) $< $(LANG_ERRORS) || rm -f $@
$(Q)$(STRGEN) $(STRGEN_FLAGS) $< $(LANG_ERRORS)
winres.o: ttd.rc
@echo '===> Compiling resource $<'
$(Q)$(WINDRES) -o $@ $<
ifdef MORPHOS
release: all
@@ -842,9 +867,47 @@ release: all
.PHONY: release
endif
ifdef OSX
release: all
$(Q)mkdir -p "OpenTTD $(RELEASE)"
$(Q)mkdir -p "OpenTTD $(RELEASE)"/docs
$(Q)mkdir -p "OpenTTD $(RELEASE)"/scenario
$(Q)cp -R $(OSXAPP) "OpenTTD $(RELEASE)"/
$(Q)cp docs/OSX_where_did_the_package_go.txt "OpenTTD $(RELEASE)"/Where\ did\ the\ package\ go.txt
$(Q)cp readme.txt "OpenTTD $(RELEASE)"/docs/
$(Q)cp docs/README_if_game_crashed_on_OSX.txt "OpenTTD $(RELEASE)"/docs/readme\ if\ crashed\ on\ OSX.txt
$(Q)cp docs/console.txt "OpenTTD $(RELEASE)"/docs/
$(Q)cp COPYING "OpenTTD $(RELEASE)"/docs/
$(Q)cp changelog.txt "OpenTTD $(RELEASE)"/docs/
$(Q)cp docs/README_if_game_crashed_on_OSX.txt "OpenTTD $(RELEASE)"/docs/
$(Q)cp os/macosx/*.webloc "OpenTTD $(RELEASE)"
$(Q)cp known-bugs.txt "OpenTTD $(RELEASE)"/known-bugs.txt
$(Q)cp scenario/* "OpenTTD $(RELEASE)"/scenario/
$(Q)/usr/bin/hdiutil create -ov -format UDZO -srcfolder "OpenTTD $(RELEASE)" openttd-"$(RELEASE)"-osx.dmg
$(Q)rm -fr "OpenTTD $(RELEASE)"
nightly_build: all
$(Q)mkdir -p "OpenTTD_nightly_$(DATE)"
$(Q)mkdir -p "OpenTTD_nightly_$(DATE)"/docs
$(Q)cp -R $(OSXAPP) "OpenTTD_nightly_$(DATE)"/
$(Q)cp docs/OSX_where_did_the_package_go.txt "OpenTTD_nightly_$(DATE)"/Where\ did\ the\ package\ go.txt
$(Q)cp readme.txt "OpenTTD_nightly_$(DATE)"/docs/
$(Q)cp docs/README_if_game_crashed_on_OSX.txt "OpenTTD_nightly_$(DATE)"/docs/readme\ if\ crashed\ on\ OSX.txt
$(Q)cp docs/console.txt "OpenTTD_nightly_$(DATE)"/docs/
$(Q)cp COPYING "OpenTTD_nightly_$(DATE)"/docs/
$(Q)cp revisionlog.txt "OpenTTD_nightly_$(DATE)"/revisionlog.txt
$(Q)cp docs/README_if_game_crashed_on_OSX.txt "OpenTTD_nightly_$(DATE)"/docs/
$(Q)cp os/macosx/*.webloc "OpenTTD_nightly_$(DATE)"/
$(Q)/usr/bin/hdiutil create -ov -format UDZO -srcfolder "OpenTTD_nightly_$(DATE)" openttd-nightly-"$(DATE)".dmg
$(Q)rm -fr "OpenTTD_nightly_$(DATE)"
.PHONY: release nightly_build
endif
rev.c: FORCE
@# setting the revision number in a place, there the binary can read it
@echo 'const char _openttd_revision[] = "$(REV)";' >>rev.c.new
@echo 'const int _revision_number = $(REV_NUMBER);' >>rev.c.new
@# some additions for MorphOS versions tag
@echo '#ifdef __MORPHOS__' >>rev.c.new
@echo 'const char morphos_versions_tag[] = "\\0$$VER: OpenTTD $(REV) ('${BUILDDATE}') <20> OpenTTD Team [MorphOS, PowerPC]";' >>rev.c.new
@@ -860,7 +923,7 @@ FORCE:
clean:
@echo '===> Cleaning up'
# endian.h is out-dated and no longer in use, so it can be removed soon
$(Q)rm -rf .deps *~ $(TTD) $(STRGEN) core table/strings.h $(LANGS) $(OBJS) $(OSX_MIDI_PLAYER_FILE) endian.h endian_host.h endian_target.h $(ENDIAN_CHECK) .OSX
$(Q)rm -rf .deps *~ $(TTD) $(STRGEN) core table/strings.h $(LANGS) $(OBJS) $(OSX_MIDI_PLAYER_FILE) endian.h endian_host.h endian_target.h $(ENDIAN_CHECK)
mrproper: clean
$(Q)rm -rf $(MAKE_CONFIG)
@@ -890,24 +953,14 @@ endif
install -d $(DATA_DIR_INSTALL)/lang \
$(DATA_DIR_INSTALL)/data \
$(DATA_DIR_INSTALL)/gm \
$(ICON_DIR_INSTALL) \
$(BINARY_DIR_INSTALL)
ifndef USE_HOMEDIR
mkdir -p $(PERSONAL_DIR)/scenario
else
mkdir -p $(DATA_DIR_INSTALL)/scenario
endif
mkdir -p $(PERSONAL_DIR)/scenario
install $(TTD) $(BINARY_DIR_INSTALL)
install -m 644 lang/*.lng $(DATA_DIR_INSTALL)/lang
install -m 644 data/*.grf $(DATA_DIR_INSTALL)/data
install -m 644 data/opntitle.dat $(DATA_DIR_INSTALL)/data
install -m 644 media/openttd.64.png $(ICON_DIR_INSTALL)
install -m 644 media/openttd.32.xpm $(ICON_DIR_INSTALL)
ifndef USE_HOMEDIR
install -m 644 media/openttd.64.png $(DATA_DIR_INSTALL)
cp scenario/* $(PERSONAL_DIR)/scenario/
else
cp scenario/* $(DATA_DIR_INSTALL)/scenario/
endif
else #MorphOS
install:
$(error make install is not supported on MorphOS)
@@ -921,7 +974,7 @@ endif
love:
@echo "YES! I thought you would never ask. We will have a great time. You can keep me turned on all night"
.PHONY: clean all $(OSX) install love
.PHONY: clean all $(OSX) install $(64_bit_warnings) $(endwarnings) love
### Automatic configuration
@@ -940,55 +993,30 @@ upgradeconf: $(MAKE_CONFIG)
### Internal build rules
# This makes sure the .deps dir is always around.
DEPS_MAGIC := $(shell mkdir -p $(sort $(dir $(DEPS))))
depend:
@true # The include handles this automagically
DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
# Introduce the dependencies
ifeq ($(findstring $(MAKECMDGOALS), clean info),)
-include $(DEPS)
endif
# Silence stale header dependency errors
# This compiles the object file as well as silently updating its dependencies
# list at the same time. It is not an issue that they aren't around during the
# first compilation round as we just build everything at that time anyway,
# therefore we do not need to watch deps.
%.o: %.c $(MAKE_CONFIG) endian_target.h table/strings.h
$(call cmd,c_compile)
@mv $(<:%.c=%.d) $(<:%.c=.deps/%.d)
%.o: %.cpp $(MAKE_CONFIG) endian_target.h table/strings.h
$(call cmd,cxx_compile)
@mv $(<:%.cpp=%.d) $(<:%.cpp=.deps/%.d)
# Silence stale header dependencies
%.h:
@true
.deps/%.d: %.c $(MAKE_CONFIG) table/strings.h endian_target.h
@echo '===> DEP $<'
$(Q)$(CC) $(CFLAGS) $(CDEFS) -MM $< | sed 's#^$(@F:%.d=%.o):#$@ $(@:.deps/%.d=%.o):#' > $@
.deps/%.d: %.cpp $(MAKE_CONFIG) table/strings.h endian_target.h
@echo '===> DEP $<'
$(Q)$(CXX) $(CFLAGS) $(CDEFS) -MM $< | sed 's#^$(@F:%.d=%.o):#$@ $(@:.deps/%.d=%.o):#' > $@
.deps/%.d: %.m $(MAKE_CONFIG) table/strings.h endian_target.h
@echo '===> DEP $<'
$(Q)$(CC) $(OBJCFLAGS) $(CDEFS) -MM $< | sed 's#^$(@F:%.d=%.o):#$@ $(@:.deps/%.d=%.o):#' > $@
ifndef NATIVE_OSX
# OSX uses os/macosx/Makefile to compile files
%.o: %.c $(MAKE_CONFIG)
@echo '===> Compiling $<'
$(Q)$(CC) $(CFLAGS) $(CDEFS) -c -o $@ $<
%.o: %.cpp $(MAKE_CONFIG)
@echo '===> Compiling $<'
$(Q)$(CXX) $(CFLAGS) $(CDEFS) -c -o $@ $<
%.o: %.m $(MAKE_CONFIG)
@echo '===> Compiling $<'
$(Q)$(CC) $(CFLAGS) $(CDEFS) -c -o $@ $<
endif
%.o: %.rc
@echo '===> Compiling resource $<'
$(Q)$(WINDRES) -o $@ $<
info:
@echo 'CFLAGS = $(CFLAGS)'
@echo 'LDFLAGS = $(LDFLAGS)'
@echo 'LIBS = $(LIBS)'
@echo 'CDEFS = $(CDEFS)'

View File

@@ -1,5 +1,3 @@
/* $Id$ */
// stdafx.cpp : source file that includes just the standard includes
// ttd.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information

File diff suppressed because it is too large Load Diff

View File

@@ -1,10 +1,7 @@
/* $Id$ */
#ifndef AI_H
#define AI_H
#ifndef AI_TROLLY_H
#define AI_TROLLY_H
#include "../../aystar.h"
#include "../../player.h"
#include "aystar.h"
/*
* These defines can be altered to change the behavoir of the AI
@@ -166,34 +163,33 @@
// This stops 90degrees curves
static const byte _illegal_curves[6] = {
255, 255, // Horz and vert, don't have the effect
5, // upleft and upright are not valid
4, // downright and downleft are not valid
2, // downleft and upleft are not valid
3, // upright and downright are not valid
255, 255, // Horz and vert, don't have the effect
5, // upleft and upright are not valid
4, // downright and downleft are not valid
2, // downleft and upleft are not valid
3, // upright and downright are not valid
};
enum {
AI_STATE_STARTUP = 0,
AI_STATE_FIRST_TIME,
AI_STATE_NOTHING,
AI_STATE_WAKE_UP,
AI_STATE_LOCATE_ROUTE,
AI_STATE_FIND_STATION,
AI_STATE_FIND_PATH,
AI_STATE_FIND_DEPOT,
AI_STATE_VERIFY_ROUTE,
AI_STATE_BUILD_STATION,
AI_STATE_BUILD_PATH,
AI_STATE_BUILD_DEPOT,
AI_STATE_BUILD_VEHICLE,
AI_STATE_WAIT_FOR_BUILD,
AI_STATE_GIVE_ORDERS,
AI_STATE_START_VEHICLE,
AI_STATE_REPAY_MONEY,
AI_STATE_STARTUP = 0,
AI_STATE_FIRST_TIME,
AI_STATE_NOTHING,
AI_STATE_WAKE_UP,
AI_STATE_LOCATE_ROUTE,
AI_STATE_FIND_STATION,
AI_STATE_FIND_PATH,
AI_STATE_FIND_DEPOT,
AI_STATE_VERIFY_ROUTE,
AI_STATE_BUILD_STATION,
AI_STATE_BUILD_PATH,
AI_STATE_BUILD_DEPOT,
AI_STATE_BUILD_VEHICLE,
AI_STATE_GIVE_ORDERS,
AI_STATE_START_VEHICLE,
AI_STATE_REPAY_MONEY,
AI_STATE_CHECK_ALL_VEHICLES,
AI_STATE_ACTION_DONE,
AI_STATE_STOP, // Temporary function to stop the AI
AI_STATE_ACTION_DONE,
AI_STATE_STOP, // Temporary function to stop the AI
};
// Used for tbt (train/bus/truck)
@@ -213,7 +209,7 @@ enum {
// Used for from_type/to_type
enum {
AI_NO_TYPE = 0,
AI_NO_TYPE = 0,
AI_CITY,
AI_INDUSTRY,
};
@@ -226,7 +222,7 @@ enum {
#define AI_NO_CARGO 0xFF // Means that there is no cargo defined yet (used for industry)
#define AI_NEED_CARGO 0xFE // Used when the AI needs to find out a cargo for the route
#define AI_STATION_RANGE TileXY(MapMaxX(), MapMaxY())
#define AI_STATION_RANGE TILE_XY(MapMaxX(), MapMaxY())
#define AI_PATHFINDER_NO_DIRECTION (byte)-1
@@ -244,19 +240,20 @@ AyStar *new_AyStar_AiPathFinder(int max_tiles_around, Ai_PathFinderInfo *PathFin
void clean_AyStar_AiPathFinder(AyStar *aystar, Ai_PathFinderInfo *PathFinderInfo);
// ai_shared.c
int AiNew_GetRailDirection(TileIndex tile_a, TileIndex tile_b, TileIndex tile_c);
int AiNew_GetRoadDirection(TileIndex tile_a, TileIndex tile_b, TileIndex tile_c);
int AiNew_GetDirection(TileIndex tile_a, TileIndex tile_b);
int AiNew_GetRailDirection(uint tile_a, uint tile_b, uint tile_c);
int AiNew_GetRoadDirection(uint tile_a, uint tile_b, uint tile_c);
int AiNew_GetDirection(uint tile_a, uint tile_b);
bool AiNew_SetSpecialVehicleFlag(Player *p, Vehicle *v, uint flag);
uint AiNew_GetSpecialVehicleFlag(Player *p, Vehicle *v);
// ai_build.c
bool AiNew_Build_CompanyHQ(Player *p, TileIndex tile);
int AiNew_Build_Station(Player *p, byte type, TileIndex tile, byte length, byte numtracks, byte direction, byte flag);
int AiNew_Build_Bridge(Player *p, TileIndex tile_a, TileIndex tile_b, byte flag);
bool AiNew_Build_CompanyHQ(Player *p, uint tile);
int AiNew_Build_Station(Player *p, byte type, uint tile, byte length, byte numtracks, byte direction, byte flag);
int AiNew_Build_Bridge(Player *p, uint tile_a, uint tile_b, byte flag);
int AiNew_Build_RoutePart(Player *p, Ai_PathFinderInfo *PathFinderInfo, byte flag);
int AiNew_PickVehicle(Player *p);
int AiNew_Build_Vehicle(Player *p, TileIndex tile, byte flag);
int AiNew_Build_Depot(Player *p, TileIndex tile, byte direction, byte flag);
int AiNew_Build_Vehicle(Player *p, uint tile, byte flag);
int AiNew_Build_Depot(Player *p, uint tile, byte direction, byte flag);
#endif /* AI_TROLLY_H */
#endif

271
ai/ai.c
View File

@@ -1,271 +0,0 @@
/* $Id$ */
#include "../stdafx.h"
#include "../openttd.h"
#include "../variables.h"
#include "../command.h"
#include "../network.h"
#include "ai.h"
#include "default/default.h"
/**
* Dequeues commands put in the queue via AI_PutCommandInQueue.
*/
static void AI_DequeueCommands(byte player)
{
AICommand *com, *entry_com;
entry_com = _ai_player[player].queue;
/* It happens that DoCommandP issues a new DoCommandAI which adds a new command
* to this very same queue (don't argue about this, if it currently doesn't
* happen I can tell you it will happen with AIScript -- TrueLight). If we
* do not make the queue NULL, that commands will be dequeued immediatly.
* Therefor we safe the entry-point to entry_com, and make the queue NULL, so
* the new queue can be safely built up. */
_ai_player[player].queue = NULL;
_ai_player[player].queue_tail = NULL;
/* Dequeue all commands */
while ((com = entry_com) != NULL) {
_current_player = player;
/* Copy the DP back in place */
_cmd_text = com->text;
DoCommandP(com->tile, com->p1, com->p2, com->callback, com->procc);
/* Free item */
entry_com = com->next;
if (com->text != NULL)
free(com->text);
free(com);
}
}
/**
* Needed for SP; we need to delay DoCommand with 1 tick, because else events
* will make infinite loops (AIScript).
*/
static void AI_PutCommandInQueue(PlayerID player, TileIndex tile, uint32 p1, uint32 p2, uint procc, CommandCallback* callback)
{
AICommand *com;
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));
_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));
_ai_player[player].queue_tail = _ai_player[player].queue_tail->next;
}
/* This is our new item */
com = _ai_player[player].queue_tail;
/* Assign the info */
com->tile = tile;
com->p1 = p1;
com->p2 = p2;
com->procc = procc;
com->callback = callback;
com->next = NULL;
com->text = NULL;
/* Copy the cmd_text, if needed */
if (_cmd_text != NULL) {
com->text = strdup(_cmd_text);
_cmd_text = NULL;
}
}
/**
* Executes a raw DoCommand for the AI.
*/
int32 AI_DoCommandCc(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc, CommandCallback* callback)
{
PlayerID old_lp;
int32 res = 0;
char *tmp_cmdtext = NULL;
/* If you enable DC_EXEC with DC_QUERY_COST you are a really strange
* person.. should we check for those funny jokes?
*/
/* The test already free _cmd_text in most cases, so let's backup the string, else we have a problem ;) */
if (_cmd_text != NULL)
tmp_cmdtext = strdup(_cmd_text);
/* First, do a test-run to see if we can do this */
res = DoCommandByTile(tile, p1, p2, flags & ~DC_EXEC, procc);
/* The command failed, or you didn't want to execute, or you are quering, return */
if ((CmdFailed(res)) || !(flags & DC_EXEC) || (flags & DC_QUERY_COST)) {
if (tmp_cmdtext != NULL)
free(tmp_cmdtext);
return res;
}
/* Recover _cmd_text */
if (tmp_cmdtext != NULL)
_cmd_text = tmp_cmdtext;
/* If we did a DC_EXEC, and the command did not return an error, execute it
over the network */
if (flags & DC_AUTO) procc |= CMD_AUTO;
if (flags & DC_NO_WATER) procc |= CMD_NO_WATER;
/* NetworkSend_Command needs _local_player to be set correctly, so
adjust it, and put it back right after the function */
old_lp = _local_player;
_local_player = _current_player;
#ifdef ENABLE_NETWORK
/* Send the command */
if (_networking)
/* Network is easy, send it to his handler */
NetworkSend_Command(tile, p1, p2, procc, callback);
else
#endif
/* If we execute BuildCommands directly in SP, we have a big problem with events
* so we need to delay is for 1 tick */
AI_PutCommandInQueue(_current_player, tile, p1, p2, procc, callback);
/* Set _local_player back */
_local_player = old_lp;
/* Free the temp _cmd_text var */
if (tmp_cmdtext != NULL)
free(tmp_cmdtext);
return res;
}
int32 AI_DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc)
{
return AI_DoCommandCc(tile, p1, p2, flags, procc, NULL);
}
/**
* Run 1 tick of the AI. Don't overdo it, keep it realistic.
*/
static void AI_RunTick(PlayerID player)
{
extern void AiNewDoGameLoop(Player *p);
Player *p = GetPlayer(player);
_current_player = player;
if (_patches.ainew_active) {
AiNewDoGameLoop(p);
} else {
/* Enable all kind of cheats the old AI needs in order to operate correctly... */
_is_old_ai_player = true;
AiDoGameLoop(p);
_is_old_ai_player = false;
}
}
/**
* The gameloop for AIs.
* Handles one tick for all the AIs.
*/
void AI_RunGameLoop(void)
{
/* Don't do anything if ai is disabled */
if (!_ai.enabled) return;
/* Don't do anything if we are a network-client
* (too bad when a client joins, he thinks the AIs are real, so it wants to control
* them.. this avoids that, while loading a network game in singleplayer, does make
* the AIs to continue ;))
*/
if (_networking && !_network_server && !_ai.network_client)
return;
/* New tick */
_ai.tick++;
/* Make sure the AI follows the difficulty rule.. */
assert(_opt.diff.competitor_speed <= 4);
if ((_ai.tick & ((1 << (4 - _opt.diff.competitor_speed)) - 1)) != 0)
return;
/* Check for AI-client (so joining a network with an AI) */
if (_ai.network_client && _ai_player[_ai.network_playas].active) {
/* Run the script */
AI_DequeueCommands(_ai.network_playas);
AI_RunTick(_ai.network_playas);
} else if (!_networking || _network_server) {
/* Check if we want to run AIs (server or SP only) */
Player *p;
FOR_ALL_PLAYERS(p) {
if (p->is_active && p->is_ai) {
/* This should always be true, else something went wrong... */
assert(_ai_player[p->index].active);
/* Run the script */
AI_DequeueCommands(p->index);
AI_RunTick(p->index);
}
}
}
_current_player = OWNER_NONE;
}
/**
* A new AI sees the day of light. You can do here what ever you think is needed.
*/
void AI_StartNewAI(PlayerID player)
{
assert(player < MAX_PLAYERS);
/* Called if a new AI is booted */
_ai_player[player].active = true;
}
/**
* This AI player died. Give it some chance to make a final puf.
*/
void AI_PlayerDied(PlayerID player)
{
if (_ai.network_client && _ai.network_playas == player)
_ai.network_playas = OWNER_SPECTATOR;
/* Called if this AI died */
_ai_player[player].active = false;
}
/**
* Initialize some AI-related stuff.
*/
void AI_Initialize(void)
{
bool ai_network_client = _ai.network_client;
/* First, make sure all AIs are DEAD! */
AI_Uninitialize();
memset(&_ai, 0, sizeof(_ai));
memset(&_ai_player, 0, sizeof(_ai_player));
_ai.network_client = ai_network_client;
_ai.network_playas = OWNER_SPECTATOR;
_ai.enabled = true;
}
/**
* Deinitializer for AI-related stuff.
*/
void AI_Uninitialize(void)
{
Player* p;
FOR_ALL_PLAYERS(p) {
if (p->is_active && p->is_ai) AI_PlayerDied(p->index);
}
}

114
ai/ai.h
View File

@@ -1,114 +0,0 @@
#ifndef AI_H
#define AI_H
#include "../functions.h"
#include "../network.h"
#include "../player.h"
/* How DoCommands look like for an AI */
typedef struct AICommand {
uint32 tile;
uint32 p1;
uint32 p2;
uint32 procc;
CommandCallback* callback;
char *text;
uint uid;
struct AICommand *next;
} AICommand;
/* The struct for an AIScript Player */
typedef struct AIPlayer {
bool active; //! Is this AI active?
AICommand *queue; //! The commands that he has in his queue
AICommand *queue_tail; //! The tail of this queue
} AIPlayer;
/* The struct to keep some data about the AI in general */
typedef struct AIStruct {
/* General */
bool enabled; //! Is AI enabled?
uint tick; //! The current tick (something like _frame_counter, only for AIs)
/* For network-clients (a OpenTTD client who acts as an AI connected to a server) */
bool network_client; //! Are we a network_client?
uint8 network_playas; //! The current network player we are connected as
} AIStruct;
VARDEF AIStruct _ai;
VARDEF AIPlayer _ai_player[MAX_PLAYERS];
// ai.c
void AI_StartNewAI(PlayerID player);
void AI_PlayerDied(PlayerID player);
void AI_RunGameLoop(void);
void AI_Initialize(void);
void AI_Uninitialize(void);
int32 AI_DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc);
int32 AI_DoCommandCc(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc, CommandCallback* callback);
/** Is it allowed to start a new AI.
* This function checks some boundries to see if we should launch a new AI.
* @return True if we can start a new AI.
*/
static inline bool AI_AllowNewAI(void)
{
/* If disabled, no AI */
if (!_ai.enabled)
return false;
/* If in network, but no server, no AI */
if (_networking && !_network_server)
return false;
/* If in network, and server, possible AI */
if (_networking && _network_server) {
/* Do we want AIs in multiplayer? */
if (!_patches.ai_in_multiplayer)
return false;
/* Only the NewAI is allowed... sadly enough the old AI just doesn't support this
* system, because all commands are delayed by at least 1 tick, which causes
* a big problem, because it uses variables that are only set AFTER the command
* is really executed... */
if (!_patches.ainew_active)
return false;
}
return true;
}
#define AI_CHANCE16(a,b) ((uint16) AI_Random() <= (uint16)((65536 * a) / b))
#define AI_CHANCE16R(a,b,r) ((uint16)(r = AI_Random()) <= (uint16)((65536 * a) / b))
/**
* The random-function that should be used by ALL AIs.
*/
static inline uint AI_RandomRange(uint max)
{
/* We pick RandomRange if we are in SP (so when saved, we do the same over and over)
* but we pick InteractiveRandomRange if we are a network_server or network-client.
*/
if (_networking)
return InteractiveRandomRange(max);
else
return RandomRange(max);
}
/**
* The random-function that should be used by ALL AIs.
*/
static inline uint32 AI_Random(void)
{
/* We pick RandomRange if we are in SP (so when saved, we do the same over and over)
* but we pick InteractiveRandomRange if we are a network_server or network-client.
*/
if (_networking)
return InteractiveRandom();
else
return Random();
}
#endif /* AI_H */

View File

@@ -1,8 +0,0 @@
/* $Id$ */
#ifndef DEFAULT_H
#define DEFAULT_H
void AiDoGameLoop(Player*);
#endif

View File

@@ -1,292 +0,0 @@
/* $Id$ */
#include "../../stdafx.h"
#include "../../openttd.h"
#include "../../debug.h"
#include "../../functions.h"
#include "../../map.h"
#include "../../tile.h"
#include "../../vehicle.h"
#include "../../command.h"
#include "trolly.h"
#include "../../engine.h"
#include "../../station.h"
#include "../../variables.h"
#include "../ai.h"
// Build HQ
// Params:
// tile : tile where HQ is going to be build
bool AiNew_Build_CompanyHQ(Player *p, TileIndex tile)
{
if (CmdFailed(AI_DoCommand(tile, 0, 0, DC_AUTO | DC_NO_WATER, CMD_BUILD_COMPANY_HQ)))
return false;
AI_DoCommand(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_BUILD_COMPANY_HQ);
return true;
}
// Build station
// Params:
// type : AI_TRAIN/AI_BUS/AI_TRUCK : indicates the type of station
// tile : tile where station is going to be build
// length : in case of AI_TRAIN: length of station
// numtracks : in case of AI_TRAIN: tracks of station
// direction : the direction of the station
// flag : flag passed to DoCommand (normally 0 to get the cost or DC_EXEC to build it)
int AiNew_Build_Station(Player *p, byte type, TileIndex tile, byte length, byte numtracks, byte direction, byte flag)
{
if (type == AI_TRAIN)
return AI_DoCommand(tile, direction + (numtracks << 8) + (length << 16), 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_RAILROAD_STATION);
if (type == AI_BUS)
return AI_DoCommand(tile, direction, RS_BUS, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD_STOP);
return AI_DoCommand(tile, direction, RS_TRUCK, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD_STOP);
}
// Builds a brdige. The second best out of the ones available for this player
// Params:
// tile_a : starting point
// tile_b : end point
// flag : flag passed to DoCommand
int AiNew_Build_Bridge(Player *p, TileIndex tile_a, TileIndex tile_b, byte flag)
{
int bridge_type, bridge_len, type, type2;
// Find a good bridgetype (the best money can buy)
bridge_len = GetBridgeLength(tile_a, tile_b);
type = type2 = 0;
for (bridge_type = MAX_BRIDGES-1; bridge_type >= 0; bridge_type--) {
if (CheckBridge_Stuff(bridge_type, bridge_len)) {
type2 = type;
type = bridge_type;
// We found two bridges, exit
if (type2 != 0) break;
}
}
// There is only one bridge that can be build..
if (type2 == 0 && type != 0) type2 = type;
// Now, simply, build the bridge!
if (p->ainew.tbt == AI_TRAIN)
return AI_DoCommand(tile_a, tile_b, (0<<8) + type2, flag | DC_AUTO, CMD_BUILD_BRIDGE);
return AI_DoCommand(tile_a, tile_b, (0x80 << 8) + type2, flag | DC_AUTO, CMD_BUILD_BRIDGE);
}
// Build the route part by part
// Basicly what this function do, is build that amount of parts of the route
// that go in the same direction. It sets 'part' to the last part of the route builded.
// The return value is the cost for the builded parts
//
// Params:
// PathFinderInfo : Pointer to the PathFinderInfo used for AiPathFinder
// part : Which part we need to build
//
// TODO: skip already builded road-pieces (e.g.: cityroad)
int AiNew_Build_RoutePart(Player *p, Ai_PathFinderInfo *PathFinderInfo, byte flag)
{
int part = PathFinderInfo->position;
byte *route_extra = PathFinderInfo->route_extra;
TileIndex *route = PathFinderInfo->route;
int dir;
int old_dir = -1;
int cost = 0;
int res;
// We need to calculate the direction with the parent of the parent.. so we skip
// the first pieces and the last piece
if (part < 1) part = 1;
// When we are done, stop it
if (part >= PathFinderInfo->route_length - 1) { PathFinderInfo->position = -2; return 0; }
if (PathFinderInfo->rail_or_road) {
// Tunnel code
if ((AI_PATHFINDER_FLAG_TUNNEL & route_extra[part]) != 0) {
cost += AI_DoCommand(route[part], 0, 0, flag, CMD_BUILD_TUNNEL);
PathFinderInfo->position++;
// TODO: problems!
if (CmdFailed(cost)) {
DEBUG(ai,0)("[AiNew - BuildPath] We have a serious problem: tunnel could not be build!");
return 0;
}
return cost;
}
// Bridge code
if ((AI_PATHFINDER_FLAG_BRIDGE & route_extra[part]) != 0) {
cost += AiNew_Build_Bridge(p, route[part], route[part-1], flag);
PathFinderInfo->position++;
// TODO: problems!
if (CmdFailed(cost)) {
DEBUG(ai,0)("[AiNew - BuildPath] We have a serious problem: bridge could not be build!");
return 0;
}
return cost;
}
// Build normal rail
// Keep it doing till we go an other way
if (route_extra[part-1] == 0 && route_extra[part] == 0) {
while (route_extra[part] == 0) {
// Get the current direction
dir = AiNew_GetRailDirection(route[part-1], route[part], route[part+1]);
// Is it the same as the last one?
if (old_dir != -1 && old_dir != dir) break;
old_dir = dir;
// Build the tile
res = AI_DoCommand(route[part], 0, dir, flag, CMD_BUILD_SINGLE_RAIL);
if (CmdFailed(res)) {
// Problem.. let's just abort it all!
p->ainew.state = AI_STATE_NOTHING;
return 0;
}
cost += res;
// Go to the next tile
part++;
// Check if it is still in range..
if (part >= PathFinderInfo->route_length - 1) break;
}
part--;
}
// We want to return the last position, so we go back one
PathFinderInfo->position = part;
} else {
// Tunnel code
if ((AI_PATHFINDER_FLAG_TUNNEL & route_extra[part]) != 0) {
cost += AI_DoCommand(route[part], 0x200, 0, flag, CMD_BUILD_TUNNEL);
PathFinderInfo->position++;
// TODO: problems!
if (CmdFailed(cost)) {
DEBUG(ai,0)("[AiNew - BuildPath] We have a serious problem: tunnel could not be build!");
return 0;
}
return cost;
}
// Bridge code
if ((AI_PATHFINDER_FLAG_BRIDGE & route_extra[part]) != 0) {
cost += AiNew_Build_Bridge(p, route[part], route[part+1], flag);
PathFinderInfo->position++;
// TODO: problems!
if (CmdFailed(cost)) {
DEBUG(ai,0)("[AiNew - BuildPath] We have a serious problem: bridge could not be build!");
return 0;
}
return cost;
}
// Build normal road
// Keep it doing till we go an other way
// EnsureNoVehicle makes sure we don't build on a tile where a vehicle is. This way
// it will wait till the vehicle is gone..
if (route_extra[part-1] == 0 && route_extra[part] == 0 && (flag != DC_EXEC || EnsureNoVehicle(route[part]))) {
while (route_extra[part] == 0 && (flag != DC_EXEC || EnsureNoVehicle(route[part]))) {
// Get the current direction
dir = AiNew_GetRoadDirection(route[part-1], route[part], route[part+1]);
// Is it the same as the last one?
if (old_dir != -1 && old_dir != dir) break;
old_dir = dir;
// There is already some road, and it is a bridge.. don't build!!!
if (!IsTileType(route[part], MP_TUNNELBRIDGE)) {
// Build the tile
res = AI_DoCommand(route[part], dir, 0, flag | DC_NO_WATER, CMD_BUILD_ROAD);
// Currently, we ignore CMD_ERRORs!
if (CmdFailed(res) && flag == DC_EXEC && !IsTileType(route[part], MP_STREET) && !EnsureNoVehicle(route[part])) {
// Problem.. let's just abort it all!
DEBUG(ai,0)("Darn, the route could not be builded.. aborting!");
p->ainew.state = AI_STATE_NOTHING;
return 0;
}
if (!CmdFailed(res)) cost += res;
}
// Go to the next tile
part++;
// Check if it is still in range..
if (part >= PathFinderInfo->route_length - 1) break;
}
part--;
// We want to return the last position, so we go back one
}
if (!EnsureNoVehicle(route[part]) && flag == DC_EXEC) part--;
PathFinderInfo->position = part;
}
return cost;
}
// This functions tries to find the best vehicle for this type of cargo
// It returns vehicle_id or -1 if not found
int AiNew_PickVehicle(Player *p)
{
if (p->ainew.tbt == AI_TRAIN) {
// Not supported yet
return -1;
} else {
int start, count, i, ret = CMD_ERROR;
start = _cargoc.ai_roadveh_start[p->ainew.cargo];
count = _cargoc.ai_roadveh_count[p->ainew.cargo];
// Let's check it backwards.. we simply want to best engine available..
for (i = start + count - 1; i >= start; i--) {
// Is it availiable?
// Also, check if the reliability of the vehicle is above the AI_VEHICLE_MIN_RELIABILTY
if (!HASBIT(GetEngine(i)->player_avail, _current_player) || GetEngine(i)->reliability * 100 < AI_VEHICLE_MIN_RELIABILTY << 16) continue;
// Can we build it?
ret = AI_DoCommand(0, i, 0, DC_QUERY_COST, CMD_BUILD_ROAD_VEH);
if (!CmdFailed(ret)) break;
}
// We did not find a vehicle :(
if (CmdFailed(ret)) return -1;
return i;
}
}
void CcAI(bool success, TileIndex tile, uint32 p1, uint32 p2)
{
Player* p = GetPlayer(_current_player);
if (success) {
p->ainew.state = AI_STATE_GIVE_ORDERS;
p->ainew.veh_id = _new_vehicle_id;
} else {
/* XXX this should be handled more gracefully */
p->ainew.state = AI_STATE_NOTHING;
}
}
// Builds the best vehicle possible
int AiNew_Build_Vehicle(Player *p, TileIndex tile, byte flag)
{
int i = AiNew_PickVehicle(p);
if (i == -1) return CMD_ERROR;
if (p->ainew.tbt == AI_TRAIN) return CMD_ERROR;
if (flag & DC_EXEC) {
return AI_DoCommandCc(tile, i, 0, flag, CMD_BUILD_ROAD_VEH, CcAI);
} else {
return AI_DoCommand(tile, i, 0, flag, CMD_BUILD_ROAD_VEH);
}
}
int AiNew_Build_Depot(Player *p, TileIndex tile, byte direction, byte flag)
{
static const byte _roadbits_by_dir[4] = {2,1,8,4};
int ret, ret2;
if (p->ainew.tbt == AI_TRAIN)
return AI_DoCommand(tile, 0, direction, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_TRAIN_DEPOT);
ret = AI_DoCommand(tile, direction, 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD_DEPOT);
if (CmdFailed(ret)) return ret;
// Try to build the road from the depot
ret2 = AI_DoCommand(tile + TileOffsByDir(direction), _roadbits_by_dir[direction], 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD);
// If it fails, ignore it..
if (CmdFailed(ret2)) return ret;
return ret + ret2;
}

File diff suppressed because it is too large Load Diff

260
ai_build.c Normal file
View File

@@ -0,0 +1,260 @@
#include "stdafx.h"
#include "ttd.h"
#include "debug.h"
#include "map.h"
#include "tile.h"
#include "command.h"
#include "ai.h"
#include "engine.h"
#include "station.h"
// Build HQ
// Params:
// tile : tile where HQ is going to be build
bool AiNew_Build_CompanyHQ(Player *p, uint tile) {
if (CmdFailed(DoCommandByTile(tile, 0, 0, DC_AUTO | DC_NO_WATER, CMD_BUILD_COMPANY_HQ)))
return false;
DoCommandByTile(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_BUILD_COMPANY_HQ);
return true;
}
// Build station
// Params:
// type : AI_TRAIN/AI_BUS/AI_TRUCK : indicates the type of station
// tile : tile where station is going to be build
// length : in case of AI_TRAIN: length of station
// numtracks : in case of AI_TRAIN: tracks of station
// direction : the direction of the station
// flag : flag passed to DoCommand (normally 0 to get the cost or DC_EXEC to build it)
int AiNew_Build_Station(Player *p, byte type, uint tile, byte length, byte numtracks, byte direction, byte flag) {
if (type == AI_TRAIN)
return DoCommandByTile(tile, direction + (numtracks << 8) + (length << 16), 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_RAILROAD_STATION);
if (type == AI_BUS)
return DoCommandByTile(tile, direction, RS_BUS, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD_STOP);
return DoCommandByTile(tile, direction, RS_TRUCK, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD_STOP);
}
// Builds a brdige. The second best out of the ones available for this player
// Params:
// tile_a : starting point
// tile_b : end point
// flag : flag passed to DoCommand
int AiNew_Build_Bridge(Player *p, uint tile_a, uint tile_b, byte flag) {
int bridge_type, bridge_len, type, type2;
// Find a good bridgetype (the best money can buy)
bridge_len = GetBridgeLength(tile_a, tile_b);
type = type2 = 0;
for (bridge_type = MAX_BRIDGES-1; bridge_type >= 0; bridge_type--) {
if (CheckBridge_Stuff(bridge_type, bridge_len)) {
type2 = type;
type = bridge_type;
// We found two bridges, exit
if (type2 != 0)
break;
}
}
// There is only one bridge that can be build..
if (type2 == 0 && type != 0) type2 = type;
// Now, simply, build the bridge!
if (p->ainew.tbt == AI_TRAIN)
return DoCommandByTile(tile_a, tile_b, (0<<8) + type2, flag | DC_AUTO, CMD_BUILD_BRIDGE);
return DoCommandByTile(tile_a, tile_b, (0x80 << 8) + type2, flag | DC_AUTO, CMD_BUILD_BRIDGE);
}
// Build the route part by part
// Basicly what this function do, is build that amount of parts of the route
// that go in the same direction. It sets 'part' to the last part of the route builded.
// The return value is the cost for the builded parts
//
// Params:
// PathFinderInfo : Pointer to the PathFinderInfo used for AiPathFinder
// part : Which part we need to build
//
// TODO: skip already builded road-pieces (e.g.: cityroad)
int AiNew_Build_RoutePart(Player *p, Ai_PathFinderInfo *PathFinderInfo, byte flag) {
int part = PathFinderInfo->position;
byte *route_extra = PathFinderInfo->route_extra;
TileIndex *route = PathFinderInfo->route;
int dir;
int old_dir = -1;
int cost = 0;
int res;
// We need to calculate the direction with the parent of the parent.. so we skip
// the first pieces and the last piece
if (part < 1) part = 1;
// When we are done, stop it
if (part >= PathFinderInfo->route_length - 1) { PathFinderInfo->position = -2; return 0; }
if (PathFinderInfo->rail_or_road) {
// Tunnel code
if ((AI_PATHFINDER_FLAG_TUNNEL & route_extra[part]) != 0) {
cost += DoCommandByTile(route[part], 0, 0, flag, CMD_BUILD_TUNNEL);
PathFinderInfo->position++;
// TODO: problems!
if (CmdFailed(cost)) {
DEBUG(ai,0)("[AiNew - BuildPath] We have a serious problem: tunnel could not be build!");
return 0;
}
return cost;
}
// Bridge code
if ((AI_PATHFINDER_FLAG_BRIDGE & route_extra[part]) != 0) {
cost += AiNew_Build_Bridge(p, route[part], route[part-1], flag);
PathFinderInfo->position++;
// TODO: problems!
if (CmdFailed(cost)) {
DEBUG(ai,0)("[AiNew - BuildPath] We have a serious problem: bridge could not be build!");
return 0;
}
return cost;
}
// Build normal rail
// Keep it doing till we go an other way
if (route_extra[part-1] == 0 && route_extra[part] == 0) {
while (route_extra[part] == 0) {
// Get the current direction
dir = AiNew_GetRailDirection(route[part-1], route[part], route[part+1]);
// Is it the same as the last one?
if (old_dir != -1 && old_dir != dir) break;
old_dir = dir;
// Build the tile
res = DoCommandByTile(route[part], 0, dir, flag, CMD_BUILD_SINGLE_RAIL);
if (CmdFailed(res)) {
// Problem.. let's just abort it all!
p->ainew.state = AI_STATE_NOTHING;
return 0;
}
cost += res;
// Go to the next tile
part++;
// Check if it is still in range..
if (part >= PathFinderInfo->route_length - 1) break;
}
part--;
}
// We want to return the last position, so we go back one
PathFinderInfo->position = part;
} else {
// Tunnel code
if ((AI_PATHFINDER_FLAG_TUNNEL & route_extra[part]) != 0) {
cost += DoCommandByTile(route[part], 0x200, 0, flag, CMD_BUILD_TUNNEL);
PathFinderInfo->position++;
// TODO: problems!
if (CmdFailed(cost)) {
DEBUG(ai,0)("[AiNew - BuildPath] We have a serious problem: tunnel could not be build!");
return 0;
}
return cost;
}
// Bridge code
if ((AI_PATHFINDER_FLAG_BRIDGE & route_extra[part]) != 0) {
cost += AiNew_Build_Bridge(p, route[part], route[part+1], flag);
PathFinderInfo->position++;
// TODO: problems!
if (CmdFailed(cost)) {
DEBUG(ai,0)("[AiNew - BuildPath] We have a serious problem: bridge could not be build!");
return 0;
}
return cost;
}
// Build normal road
// Keep it doing till we go an other way
// EnsureNoVehicle makes sure we don't build on a tile where a vehicle is. This way
// it will wait till the vehicle is gone..
if (route_extra[part-1] == 0 && route_extra[part] == 0 && (flag != DC_EXEC || EnsureNoVehicle(route[part]))) {
while (route_extra[part] == 0 && (flag != DC_EXEC || EnsureNoVehicle(route[part]))) {
// Get the current direction
dir = AiNew_GetRoadDirection(route[part-1], route[part], route[part+1]);
// Is it the same as the last one?
if (old_dir != -1 && old_dir != dir) break;
old_dir = dir;
// There is already some road, and it is a bridge.. don't build!!!
if (!IsTileType(route[part], MP_TUNNELBRIDGE)) {
// Build the tile
res = DoCommandByTile(route[part], dir, 0, flag | DC_NO_WATER, CMD_BUILD_ROAD);
// Currently, we ignore CMD_ERRORs!
if (CmdFailed(res) && flag == DC_EXEC && !IsTileType(route[part], MP_STREET) && !EnsureNoVehicle(route[part])) {
// Problem.. let's just abort it all!
DEBUG(ai,0)("Darn, the route could not be builded.. aborting!");
p->ainew.state = AI_STATE_NOTHING;
return 0;
}
if (!CmdFailed(res)) cost += res;
}
// Go to the next tile
part++;
// Check if it is still in range..
if (part >= PathFinderInfo->route_length - 1) break;
}
part--;
// We want to return the last position, so we go back one
}
if (!EnsureNoVehicle(route[part]) && flag == DC_EXEC) part--;
PathFinderInfo->position = part;
}
return cost;
}
// This functions tries to find the best vehicle for this type of cargo
// It returns vehicle_id or -1 if not found
int AiNew_PickVehicle(Player *p) {
if (p->ainew.tbt == AI_TRAIN) {
// Not supported yet
return -1;
} else {
int start, count, i, ret = CMD_ERROR;
start = _cargoc.ai_roadveh_start[p->ainew.cargo];
count = _cargoc.ai_roadveh_count[p->ainew.cargo];
// Let's check it backwards.. we simply want to best engine available..
for (i=start+count-1;i>=start;i--) {
// Is it availiable?
// Also, check if the reliability of the vehicle is above the AI_VEHICLE_MIN_RELIABILTY
if (!HASBIT(_engines[i].player_avail, _current_player) || _engines[i].reliability * 100 < AI_VEHICLE_MIN_RELIABILTY << 16) continue;
// Can we build it?
ret = DoCommandByTile(0, i, 0, DC_QUERY_COST, CMD_BUILD_ROAD_VEH);
if (!CmdFailed(ret)) break;
}
// We did not find a vehicle :(
if (CmdFailed(ret)) { return -1; }
return i;
}
}
// Builds the best vehicle possible
int AiNew_Build_Vehicle(Player *p, uint tile, byte flag) {
int i = AiNew_PickVehicle(p);
if (i == -1) return CMD_ERROR;
if (p->ainew.tbt == AI_TRAIN)
return CMD_ERROR;
return DoCommandByTile(tile, i, 0, flag, CMD_BUILD_ROAD_VEH);
}
int AiNew_Build_Depot(Player *p, uint tile, byte direction, byte flag)
{
static const byte _roadbits_by_dir[4] = {2,1,8,4};
int ret, ret2;
if (p->ainew.tbt == AI_TRAIN)
return DoCommandByTile(tile, 0, direction, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_TRAIN_DEPOT);
ret = DoCommandByTile(tile, direction, 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD_DEPOT);
if (CmdFailed(ret)) return ret;
// Try to build the road from the depot
ret2 = DoCommandByTile(tile + TileOffsByDir(direction), _roadbits_by_dir[direction], 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD);
// If it fails, ignore it..
if (CmdFailed(ret2)) return ret;
return ret + ret2;
}

1322
ai_new.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,24 +1,19 @@
/* $Id$ */
#include "../../stdafx.h"
#include "../../openttd.h"
#include "../../debug.h"
#include "../../functions.h"
#include "../../map.h"
#include "../../tile.h"
#include "../../command.h"
#include "trolly.h"
#include "../../depot.h"
#include "../../variables.h"
#include "../ai.h"
#include "stdafx.h"
#include "ttd.h"
#include "debug.h"
#include "map.h"
#include "tile.h"
#include "command.h"
#include "ai.h"
#include "depot.h"
#define TEST_STATION_NO_DIR 0xFF
// Tests if a station can be build on the given spot
// TODO: make it train compatible
static bool TestCanBuildStationHere(TileIndex tile, byte dir)
static bool TestCanBuildStationHere(uint tile, byte dir)
{
Player *p = GetPlayer(_current_player);
Player *p = DEREF_PLAYER(_current_player);
if (dir == TEST_STATION_NO_DIR) {
int32 ret;
@@ -43,9 +38,9 @@ static bool IsRoad(TileIndex tile)
(IsTileType(tile, MP_STREET) && !IsTileDepotType(tile, TRANSPORT_ROAD)) ||
(IsTileType(tile, MP_TUNNELBRIDGE) && (
// road tunnel?
((_m[tile].m5 & 0x80) == 0 && (_m[tile].m5 & 0x4) == 0x4) ||
((_map5[tile] & 0x80) == 0 && (_map5[tile] & 0x4) == 0x4) ||
// road bridge?
((_m[tile].m5 & 0x80) != 0 && (_m[tile].m5 & 0x2) == 0x2)
((_map5[tile] & 0x80) != 0 && (_map5[tile] & 0x2) == 0x2)
));
}
@@ -53,7 +48,6 @@ static bool IsRoad(TileIndex tile)
// Checks if a tile 'a' is between the tiles 'b' and 'c'
#define TILES_BETWEEN(a, b, c) (TileX(a) >= TileX(b) && TileX(a) <= TileX(c) && TileY(a) >= TileY(b) && TileY(a) <= TileY(c))
// Check if the current tile is in our end-area
static int32 AyStar_AiPathFinder_EndNodeCheck(AyStar *aystar, OpenListNode *current)
{
@@ -68,7 +62,6 @@ static int32 AyStar_AiPathFinder_EndNodeCheck(AyStar *aystar, OpenListNode *curr
return AYSTAR_DONE;
}
// Calculates the hash
// Currently it is a 10 bit hash, so the hash array has a max depth of 6 bits (so 64)
static uint AiPathFinder_Hash(uint key1, uint key2)
@@ -76,7 +69,6 @@ static uint AiPathFinder_Hash(uint key1, uint key2)
return (TileX(key1) & 0x1F) + ((TileY(key1) & 0x1F) << 5);
}
// Clear the memory of all the things
static void AyStar_AiPathFinder_Free(AyStar *aystar)
{
@@ -84,13 +76,11 @@ static void AyStar_AiPathFinder_Free(AyStar *aystar)
free(aystar);
}
static int32 AyStar_AiPathFinder_CalculateG(AyStar *aystar, AyStarNode *current, OpenListNode *parent);
static int32 AyStar_AiPathFinder_CalculateH(AyStar *aystar, AyStarNode *current, OpenListNode *parent);
static void AyStar_AiPathFinder_FoundEndNode(AyStar *aystar, OpenListNode *current);
static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *current);
// This creates the AiPathFinder
AyStar *new_AyStar_AiPathFinder(int max_tiles_around, Ai_PathFinderInfo *PathFinderInfo)
{
@@ -125,7 +115,7 @@ AyStar *new_AyStar_AiPathFinder(int max_tiles_around, Ai_PathFinderInfo *PathFin
// Now we add all the starting tiles
for (x = TileX(PathFinderInfo->start_tile_tl); x <= TileX(PathFinderInfo->start_tile_br); x++) {
for (y = TileY(PathFinderInfo->start_tile_tl); y <= TileY(PathFinderInfo->start_tile_br); y++) {
start_node.node.tile = TileXY(x, y);
start_node.node.tile = TILE_XY(x, y);
result->addstart(result, &start_node.node, 0);
}
}
@@ -133,7 +123,6 @@ AyStar *new_AyStar_AiPathFinder(int max_tiles_around, Ai_PathFinderInfo *PathFin
return result;
}
// To reuse AyStar we sometimes have to clean all the memory
void clean_AyStar_AiPathFinder(AyStar *aystar, Ai_PathFinderInfo *PathFinderInfo)
{
@@ -155,15 +144,14 @@ void clean_AyStar_AiPathFinder(AyStar *aystar, Ai_PathFinderInfo *PathFinderInfo
// Now we add all the starting tiles
for (x = TileX(PathFinderInfo->start_tile_tl); x <= TileX(PathFinderInfo->start_tile_br); x++) {
for (y = TileY(PathFinderInfo->start_tile_tl); y <= TileY(PathFinderInfo->start_tile_br); y++) {
if (!(IsTileType(TileXY(x, y), MP_CLEAR) || IsTileType(TileXY(x, y), MP_TREES))) continue;
if (!TestCanBuildStationHere(TileXY(x, y), TEST_STATION_NO_DIR)) continue;
start_node.node.tile = TileXY(x, y);
if (!(IsTileType(TILE_XY(x, y), MP_CLEAR) || IsTileType(TILE_XY(x, y), MP_TREES))) continue;
if (!TestCanBuildStationHere(TILE_XY(x, y), TEST_STATION_NO_DIR)) continue;
start_node.node.tile = TILE_XY(x, y);
aystar->addstart(aystar, &start_node.node, 0);
}
}
}
// The h-value, simple calculation
static int32 AyStar_AiPathFinder_CalculateH(AyStar *aystar, AyStarNode *current, OpenListNode *parent)
{
@@ -183,7 +171,6 @@ static int32 AyStar_AiPathFinder_CalculateH(AyStar *aystar, AyStarNode *current,
return r * AI_PATHFINDER_H_MULTIPLER;
}
// We found the end.. let's get the route back and put it in an array
static void AyStar_AiPathFinder_FoundEndNode(AyStar *aystar, OpenListNode *current)
{
@@ -206,7 +193,6 @@ static void AyStar_AiPathFinder_FoundEndNode(AyStar *aystar, OpenListNode *curre
DEBUG(ai, 1)("[Ai-PathFinding] Found route of %d nodes long in %d nodes of searching", i, Hash_Size(&aystar->ClosedListHash));
}
// What tiles are around us.
static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *current)
{
@@ -232,11 +218,11 @@ static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *curr
if (!PathFinderInfo->rail_or_road && IsRoad(atile)) {
if (IsTileType(atile, MP_TUNNELBRIDGE)) {
// An existing bridge... let's test the direction ;)
if ((_m[atile].m5 & 1U) != (i & 1)) continue;
if ((_map5[atile] & 1U) != (i & 1)) continue;
// This problem only is valid for tunnels:
// When the last tile was not yet a tunnel, check if we enter from the right side..
if ((_m[atile].m5 & 0x80) == 0) {
if (i != (_m[atile].m5 & 3U)) continue;
if ((_map5[atile] & 0x80) == 0) {
if (i != (_map5[atile] & 3U)) continue;
}
}
}
@@ -244,7 +230,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 ((_map5[ctile] & 1U) != (i & 1)) continue;
}
}
@@ -270,7 +256,7 @@ static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *curr
if (PathFinderInfo->rail_or_road) {
// Rail check
dir = AiNew_GetRailDirection(current->path.parent->node.tile, ctile, atile);
ret = AI_DoCommand(ctile, 0, dir, DC_AUTO | DC_NO_WATER, CMD_BUILD_SINGLE_RAIL);
ret = DoCommandByTile(ctile, 0, dir, DC_AUTO | DC_NO_WATER, CMD_BUILD_SINGLE_RAIL);
if (CmdFailed(ret)) continue;
#ifdef AI_PATHFINDER_NO_90DEGREES_TURN
if (current->path.parent->parent != NULL) {
@@ -290,9 +276,9 @@ static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *curr
dir = 0;
} else {
// It already has road.. check if we miss any bits!
if ((_m[ctile].m5 & dir) != dir) {
if ((_map5[ctile] & dir) != dir) {
// We do miss some pieces :(
dir &= ~_m[ctile].m5;
dir &= ~_map5[ctile];
} else {
dir = 0;
}
@@ -300,7 +286,7 @@ static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *curr
}
// Only destruct things if it is MP_CLEAR of MP_TREES
if (dir != 0) {
ret = AI_DoCommand(ctile, dir, 0, DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD);
ret = DoCommandByTile(ctile, dir, 0, DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD);
if (CmdFailed(ret)) continue;
}
}
@@ -329,6 +315,7 @@ static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *curr
if (ti.tileh != 0 ||
(PathFinderInfo->rail_or_road && IsTileType(tile + TileOffsByDir(dir), MP_STREET)) ||
(!PathFinderInfo->rail_or_road && IsTileType(tile + TileOffsByDir(dir), MP_RAILWAY))) {
for (;;) {
new_tile += TileOffsByDir(dir);
@@ -339,7 +326,7 @@ static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *curr
if (TILES_BETWEEN(new_tile, PathFinderInfo->end_tile_tl, PathFinderInfo->end_tile_br)) break;
// Try building the bridge..
ret = AI_DoCommand(tile, new_tile, (0 << 8) + (MAX_BRIDGES / 2), DC_AUTO, CMD_BUILD_BRIDGE);
ret = DoCommandByTile(tile, new_tile, (0 << 8) + (MAX_BRIDGES / 2), DC_AUTO, CMD_BUILD_BRIDGE);
if (CmdFailed(ret)) continue;
// We can build a bridge here.. add him to the neighbours
aystar->neighbours[aystar->num_neighbours].tile = new_tile;
@@ -358,7 +345,7 @@ static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *curr
(dir == 2 && ti.tileh == 3) ||
(dir == 3 && ti.tileh == 9)) {
// Now simply check if a tunnel can be build
ret = AI_DoCommand(tile, (PathFinderInfo->rail_or_road?0:0x200), 0, DC_AUTO, CMD_BUILD_TUNNEL);
ret = DoCommandByTile(tile, (PathFinderInfo->rail_or_road?0:0x200), 0, DC_AUTO, CMD_BUILD_TUNNEL);
FindLandscapeHeightByTile(&ti, _build_tunnel_endtile);
if (!CmdFailed(ret) && (ti.tileh == 3 || ti.tileh == 6 || ti.tileh == 9 || ti.tileh == 12)) {
aystar->neighbours[aystar->num_neighbours].tile = _build_tunnel_endtile;
@@ -369,7 +356,6 @@ static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *curr
}
}
extern uint GetRailFoundation(uint tileh, uint bits);
extern uint GetRoadFoundation(uint tileh, uint bits);
extern uint GetBridgeFoundation(uint tileh, byte direction);
@@ -391,10 +377,9 @@ static int32 AyStar_AiPathFinder_CalculateG(AyStar *aystar, AyStarNode *current,
// Check if we hit the end-tile
if (TILES_BETWEEN(current->tile, PathFinderInfo->end_tile_tl, PathFinderInfo->end_tile_br)) {
// We are at the end-tile, check if we had a direction or something...
if (PathFinderInfo->end_direction != AI_PATHFINDER_NO_DIRECTION && AiNew_GetDirection(current->tile, parent->path.node.tile) != PathFinderInfo->end_direction) {
if (PathFinderInfo->end_direction != AI_PATHFINDER_NO_DIRECTION && AiNew_GetDirection(current->tile, parent->path.node.tile) != PathFinderInfo->end_direction)
// We are not pointing the right way, invalid tile
return AYSTAR_INVALID_NODE;
}
// If it was valid, drop out.. we don't build on the endtile
return 0;
}
@@ -462,8 +447,10 @@ static int32 AyStar_AiPathFinder_CalculateG(AyStar *aystar, AyStarNode *current,
if (GetBridgeFoundation(ti.tileh, (current->user_data[0] >> 8) & 1) < 15)
res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY;
}
if (parent_ti.tileh == 0) res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY;
if (ti.tileh == 0) res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY;
if (parent_ti.tileh == 0)
res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY;
if (ti.tileh == 0)
res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY;
}
// To prevent the AI from taking the fastest way in tiles, but not the fastest way
@@ -471,7 +458,7 @@ static int32 AyStar_AiPathFinder_CalculateG(AyStar *aystar, AyStarNode *current,
// This way, we get almost the fastest way in tiles, and a very good speed on the track
if (!PathFinderInfo->rail_or_road) {
if (parent->path.parent != NULL &&
AiNew_GetDirection(current->tile, parent->path.node.tile) != AiNew_GetDirection(parent->path.node.tile, parent->path.parent->node.tile)) {
AiNew_GetDirection(current->tile, parent->path.node.tile) != AiNew_GetDirection(parent->path.node.tile, parent->path.parent->node.tile)) {
// When road exists, we don't like turning, but its free, so don't be to piggy about it
if (IsRoad(parent->path.node.tile))
res += AI_PATHFINDER_DIRECTION_CHANGE_ON_EXISTING_ROAD_PENALTY;
@@ -505,5 +492,9 @@ static int32 AyStar_AiPathFinder_CalculateG(AyStar *aystar, AyStarNode *current,
}
}
return (res < 0) ? 0 : res;
// Res should never be below zero.. if so, make it zero!
if (res < 0) { res = 0; }
// Return our value
return res;
}

View File

@@ -1,14 +1,11 @@
/* $Id$ */
#include "stdafx.h"
#include "ttd.h"
#include "debug.h"
#include "map.h"
#include "ai.h"
#include "vehicle.h"
#include "../../stdafx.h"
#include "../../openttd.h"
#include "../../debug.h"
#include "../../map.h"
#include "trolly.h"
#include "../../vehicle.h"
int AiNew_GetRailDirection(TileIndex tile_a, TileIndex tile_b, TileIndex tile_c)
{
int AiNew_GetRailDirection(uint tile_a, uint tile_b, uint tile_c) {
// 0 = vert
// 1 = horz
// 2 = dig up-left
@@ -49,8 +46,7 @@ int AiNew_GetRailDirection(TileIndex tile_a, TileIndex tile_b, TileIndex tile_c)
return 0;
}
int AiNew_GetRoadDirection(TileIndex tile_a, TileIndex tile_b, TileIndex tile_c)
{
int AiNew_GetRoadDirection(uint tile_a, uint tile_b, uint tile_c) {
int x1, x2, x3;
int y1, y2, y3;
int r;
@@ -79,8 +75,7 @@ int AiNew_GetRoadDirection(TileIndex tile_a, TileIndex tile_b, TileIndex tile_c)
}
// Get's the direction between 2 tiles seen from tile_a
int AiNew_GetDirection(TileIndex tile_a, TileIndex tile_b)
{
int AiNew_GetDirection(uint tile_a, uint tile_b) {
if (TileY(tile_a) < TileY(tile_b)) return 1;
if (TileY(tile_a) > TileY(tile_b)) return 3;
if (TileX(tile_a) < TileX(tile_b)) return 2;

View File

@@ -1,16 +0,0 @@
/* $Id$ */
#include "station_map.h"
#include "vehicle.h"
static inline bool IsAircraftInHangar(const Vehicle* v)
{
assert(v->type == VEH_Aircraft);
return v->vehstatus & VS_HIDDEN && IsHangarTile(v->tile);
}
static inline bool IsAircraftInHangarStopped(const Vehicle* v)
{
return IsAircraftInHangar(v) && v->vehstatus & VS_STOPPED;
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,11 +1,6 @@
/* $Id$ */
#include "stdafx.h"
#include "openttd.h"
#include "aircraft.h"
#include "ttd.h"
#include "debug.h"
#include "functions.h"
#include "table/sprites.h"
#include "table/strings.h"
#include "map.h"
#include "tile.h"
@@ -19,66 +14,47 @@
#include "viewport.h"
#include "player.h"
#include "depot.h"
#include "vehicle_gui.h"
/**
* Draw the purchase info details of an aircraft at a given location.
* @param x,y location where to draw the info
* @param engine_number the engine of which to draw the info of
*/
void DrawAircraftPurchaseInfo(int x, int y, EngineID engine_number)
void Set_DPARAM_Aircraft_Build_Window(uint16 engine_number)
{
const AircraftVehicleInfo *avi = AircraftVehInfo(engine_number);
const Engine* e = GetEngine(engine_number);
Engine *e;
YearMonthDay ymd;
ConvertDayToYMD(&ymd, e->intro_date);
/* Purchase cost - Max speed */
SetDParam(0, avi->base_cost * (_price.aircraft_base>>3)>>5);
SetDParam(1, avi->max_speed * 8);
DrawString(x, y, STR_PURCHASE_INFO_COST_SPEED, 0);
y += 10;
SetDParam(2, avi->passenger_capacity);
SetDParam(3, avi->mail_capacity);
SetDParam(4, avi->running_cost * _price.aircraft_running >> 8);
/* Cargo capacity */
SetDParam(0, avi->passenger_capacity);
SetDParam(1, avi->mail_capacity);
DrawString(x, y, STR_PURCHASE_INFO_AIRCRAFT_CAPACITY, 0);
y += 10;
e = &_engines[engine_number];
SetDParam(6, e->lifelength);
SetDParam(7, e->reliability * 100 >> 16);
ConvertDayToYMD(&ymd, e->intro_date);
SetDParam(5, ymd.year + 1920);
/* Running cost */
SetDParam(0, avi->running_cost * _price.aircraft_running >> 8);
DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
y += 10;
/* Design date - Life length */
SetDParam(0, ymd.year + 1920);
SetDParam(1, e->lifelength);
DrawString(x, y, STR_PURCHASE_INFO_DESIGNED_LIFE, 0);
y += 10;
/* Reliability */
SetDParam(0, e->reliability * 100 >> 16);
DrawString(x, y, STR_PURCHASE_INFO_RELIABILITY, 0);
y += 10;
}
static void DrawAircraftImage(const Vehicle *v, int x, int y, VehicleID selection)
{
int image = GetAircraftImage(v, 6);
uint32 ormod = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner));
if (v->vehstatus & VS_CRASHED) ormod = PALETTE_CRASH;
DrawSprite(image | ormod, x + 25, y + 10);
if (v->subtype == 0) DrawSprite(SPR_ROTOR_STOPPED, x + 25, y + 5);
if (v->vehstatus & VS_CRASHED) ormod = 0x3248000;
DrawSprite(image | ormod, x+25, y+10);
if (v->subtype == 0)
DrawSprite(0xF3D, x+25, y+5);
if (v->index == selection) {
DrawFrameRect(x - 1, y - 1, x + 58, y + 21, 0xF, FR_BORDERONLY);
DrawFrameRect(x-1, y-1, x+58, y+21, 0xF, 0x10);
}
}
void CcBuildAircraft(bool success, TileIndex tile, uint32 p1, uint32 p2)
void CcBuildAircraft(bool success, uint tile, uint32 p1, uint32 p2)
{
if (success) {
const Vehicle* v = GetVehicle(_new_aircraft_id);
Vehicle *v;
if (success) {
v = GetVehicle(_new_aircraft_id);
if (v->tile == _backup_orders_tile) {
_backup_orders_tile = 0;
RestoreVehicleOrders(v, _backup_orders_data);
@@ -87,24 +63,22 @@ void CcBuildAircraft(bool success, TileIndex tile, uint32 p1, uint32 p2)
}
}
void CcCloneAircraft(bool success, uint tile, uint32 p1, uint32 p2)
{
if (success) ShowAircraftViewWindow(GetVehicle(_new_aircraft_id));
}
static void NewAircraftWndProc(Window *w, WindowEvent *e)
{
switch (e->event) {
switch(e->event) {
case WE_PAINT: {
if (w->window_number == 0) SETBIT(w->disabled_state, 5);
if (w->window_number == 0)
SETBIT(w->disabled_state, 5);
{
int count = 0;
int num = NUM_AIRCRAFT_ENGINES;
const Engine* e = GetEngine(AIRCRAFT_ENGINES_INDEX);
Engine *e = &_engines[AIRCRAFT_ENGINES_INDEX];
do {
if (HASBIT(e->player_avail, _local_player)) count++;
if (HASBIT(e->player_avail, _local_player))
count++;
} while (++e,--num);
SetVScrollCount(w, count);
}
@@ -113,13 +87,13 @@ static void NewAircraftWndProc(Window *w, WindowEvent *e)
{
int num = NUM_AIRCRAFT_ENGINES;
const Engine* e = GetEngine(AIRCRAFT_ENGINES_INDEX);
Engine *e = &_engines[AIRCRAFT_ENGINES_INDEX];
int x = 2;
int y = 15;
int sel = WP(w,buildtrain_d).sel_index;
int pos = w->vscroll.pos;
EngineID engine_id = AIRCRAFT_ENGINES_INDEX;
EngineID selected_id = INVALID_ENGINE;
int engine_id = AIRCRAFT_ENGINES_INDEX;
int selected_id = -1;
do {
if (HASBIT(e->player_avail, _local_player)) {
@@ -135,8 +109,10 @@ static void NewAircraftWndProc(Window *w, WindowEvent *e)
WP(w,buildtrain_d).sel_engine = selected_id;
if (selected_id != INVALID_ENGINE) {
DrawAircraftPurchaseInfo(2, w->widget[4].top + 1, selected_id);
if (selected_id != -1) {
Set_DPARAM_Aircraft_Build_Window(selected_id);
DrawString(2, w->widget[4].top + 1, STR_A007_COST_SPEED_CAPACITY_PASSENGERS, 0);
}
}
} break;
@@ -152,14 +128,14 @@ static void NewAircraftWndProc(Window *w, WindowEvent *e)
} break;
case 5: { /* build */
EngineID sel_eng = WP(w,buildtrain_d).sel_engine;
if (sel_eng != INVALID_ENGINE)
int sel_eng = WP(w,buildtrain_d).sel_engine;
if (sel_eng != -1)
DoCommandP(w->window_number, sel_eng, 0, CcBuildAircraft, CMD_BUILD_AIRCRAFT | CMD_MSG(STR_A008_CAN_T_BUILD_AIRCRAFT));
} break;
case 6: { /* rename */
EngineID sel_eng = WP(w,buildtrain_d).sel_engine;
if (sel_eng != INVALID_ENGINE) {
int sel_eng = WP(w,buildtrain_d).sel_engine;
if (sel_eng != -1) {
WP(w,buildtrain_d).rename_engine = sel_eng;
ShowQueryString(GetCustomEngineName(sel_eng),
STR_A039_RENAME_AIRCRAFT_TYPE, 31, 160, w->window_class, w->window_number);
@@ -190,7 +166,7 @@ static void NewAircraftWndProc(Window *w, WindowEvent *e)
}
static const Widget _new_aircraft_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 239, 0, 13, STR_A005_NEW_AIRCRAFT, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_MATRIX, RESIZE_BOTTOM, 14, 0, 227, 14, 109, 0x401, STR_A025_AIRCRAFT_SELECTION_LIST},
{ WWT_SCROLLBAR, RESIZE_BOTTOM, 14, 228, 239, 14, 109, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
@@ -209,7 +185,7 @@ static const WindowDesc _new_aircraft_desc = {
NewAircraftWndProc
};
static void ShowBuildAircraftWindow(TileIndex tile)
static void ShowBuildAircraftWindow(uint tile)
{
Window *w;
@@ -223,7 +199,7 @@ static void ShowBuildAircraftWindow(TileIndex tile)
w->resize.step_height = 24;
if (tile != 0) {
w->caption_color = GetTileOwner(tile);
w->caption_color = _map_owner[tile];
} else {
w->caption_color = _local_player;
}
@@ -248,9 +224,9 @@ static void AircraftRefitWndProc(Window *w, WindowEvent *e)
int32 cost = DoCommandByTile(v->tile, v->index, WP(w,refit_d).cargo, DC_QUERY_COST, CMD_REFIT_AIRCRAFT);
if (!CmdFailed(cost)) {
SetDParam(2, cost);
SetDParam(0, _cargoc.names_long[WP(w,refit_d).cargo]);
SetDParam(0, _cargoc.names_long_p[WP(w,refit_d).cargo]);
SetDParam(1, _aircraft_refit_capacity);
DrawString(1, 147, STR_A041_NEW_CAPACITY_COST_OF_REFIT, 0);
DrawString(1, 137, STR_A041_NEW_CAPACITY_COST_OF_REFIT, 0);
}
}
} break;
@@ -277,23 +253,23 @@ static void AircraftRefitWndProc(Window *w, WindowEvent *e)
}
static const Widget _aircraft_refit_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 239, 0, 13, STR_A03C_REFIT, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 239, 14, 145, 0x0, STR_A03E_SELECT_TYPE_OF_CARGO_FOR},
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 239, 146, 167, 0x0, STR_NULL},
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 239, 168, 179, STR_A03D_REFIT_AIRCRAFT, STR_A03F_REFIT_AIRCRAFT_TO_CARRY},
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 239, 14, 135, 0x0, STR_A03E_SELECT_TYPE_OF_CARGO_FOR},
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 239, 136, 157, 0x0, STR_NULL},
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 239, 158, 169, STR_A03D_REFIT_AIRCRAFT, STR_A03F_REFIT_AIRCRAFT_TO_CARRY},
{ WIDGETS_END},
};
static const WindowDesc _aircraft_refit_desc = {
-1,-1, 240, 180,
-1,-1, 240, 170,
WC_VEHICLE_REFIT,WC_VEHICLE_VIEW,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
_aircraft_refit_widgets,
AircraftRefitWndProc
};
static void ShowAircraftRefitWindow(const Vehicle* v)
static void ShowAircraftRefitWindow(Vehicle *v)
{
Window *w;
@@ -323,10 +299,17 @@ static void AircraftDetailsWndProc(Window *w, WindowEvent *e)
/* Draw running cost */
{
int year = v->age / 366;
StringID str;
SetDParam(1, year);
SetDParam(0, (v->age + 365 < v->max_age) ? STR_AGE : STR_AGE_RED);
str = STR_0199_YEAR;
if (year != 1) {
str++;
if (v->max_age - 366 < v->age)
str++;
}
SetDParam(0, str);
SetDParam(2, v->max_age / 366);
SetDParam(3, _price.aircraft_running * AircraftVehInfo(v->engine_type)->running_cost >> 8);
DrawString(2, 15, STR_A00D_AGE_RUNNING_COST_YR, 0);
@@ -373,12 +356,12 @@ static void AircraftDetailsWndProc(Window *w, WindowEvent *e)
DrawString(60, y, STR_A011_BUILT_VALUE, 0);
y += 10;
SetDParam(0, _cargoc.names_long[v->cargo_type]);
SetDParam(0, _cargoc.names_long_p[v->cargo_type]);
SetDParam(1, v->cargo_cap);
u = v->next;
SetDParam(2, _cargoc.names_long[u->cargo_type]);
SetDParam(2, _cargoc.names_long_p[u->cargo_type]);
SetDParam(3, u->cargo_cap);
DrawString(60, y, (u->cargo_cap != 0) ? STR_A019_CAPACITY : STR_A01A_CAPACITY, 0);
DrawString(60, y, STR_A019_CAPACITY + (u->cargo_cap == 0), 0);
y += 14;
}
@@ -416,7 +399,7 @@ do_change_service_int:
mod = GetServiceIntervalClamped(mod + v->service_interval);
if (mod == v->service_interval) return;
DoCommandP(v->tile, v->index, mod, NULL, CMD_CHANGE_SERVICE_INT | CMD_MSG(STR_018A_CAN_T_CHANGE_SERVICING));
DoCommandP(v->tile, v->index, mod, NULL, CMD_CHANGE_AIRCRAFT_SERVICE_INT | CMD_MSG(STR_018A_CAN_T_CHANGE_SERVICING));
break;
}
} break;
@@ -426,19 +409,20 @@ do_change_service_int:
DeleteWindow(w);
break;
case WE_ON_EDIT_TEXT:
case WE_ON_EDIT_TEXT: {
if (e->edittext.str[0] != '\0') {
_cmd_text = e->edittext.str;
DoCommandP(0, w->window_number, 0, NULL,
CMD_NAME_VEHICLE | CMD_MSG(STR_A031_CAN_T_NAME_AIRCRAFT));
}
break;
} break;
}
}
static const Widget _aircraft_details_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 349, 0, 13, STR_A00C_DETAILS, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 350, 389, 0, 13, STR_01AA_NAME, STR_A032_NAME_AIRCRAFT},
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 389, 14, 55, 0x0, STR_NULL},
@@ -458,7 +442,7 @@ static const WindowDesc _aircraft_details_desc = {
};
static void ShowAircraftDetailsWindow(const Vehicle* v)
static void ShowAircraftDetailsWindow(Vehicle *v)
{
Window *w;
VehicleID veh = v->index;
@@ -476,7 +460,7 @@ static void ShowAircraftDetailsWindow(const Vehicle* v)
static const Widget _aircraft_view_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW },
{ WWT_TEXTBTN, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW },
{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 237, 0, 13, STR_A00A, STR_018C_WINDOW_TITLE_DRAG_THIS },
{ WWT_STICKYBOX, RESIZE_LR, 14, 238, 249, 0, 13, 0x0, STR_STICKY_BUTTON },
{ WWT_IMGBTN, RESIZE_RB, 14, 0, 231, 14, 103, 0x0, STR_NULL },
@@ -487,24 +471,29 @@ static const Widget _aircraft_view_widgets[] = {
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 50, 67, 0x2B4, STR_A03B_REFIT_AIRCRAFT_TO_CARRY },
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 68, 85, 0x2B2, STR_A028_SHOW_AIRCRAFT_S_ORDERS },
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 86, 103, 0x2B3, STR_A02B_SHOW_AIRCRAFT_DETAILS },
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 32, 49, SPR_CLONE_AIRCRAFT, STR_CLONE_AIRCRAFT_INFO },
{ WWT_PANEL, RESIZE_LRB, 14, 232, 249, 104, 103, 0x0, STR_NULL },
{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 238, 249, 104, 115, 0x0, STR_NULL },
{ WIDGETS_END }
};
static void AircraftViewWndProc(Window *w, WindowEvent *e)
{
switch(e->event) {
case WE_PAINT: {
const Vehicle* v = GetVehicle(w->window_number);
uint32 disabled = 1 << 8;
Vehicle *v = GetVehicle(w->window_number);
uint32 disabled = 1<<8;
StringID str;
if (IsAircraftInHangarStopped(v)) disabled = 0;
{
uint tile = v->tile;
if (IsTileType(tile, MP_STATION) &&
(_map5[tile] == 32 || _map5[tile] == 65) &&
v->vehstatus&VS_STOPPED)
disabled = 0;
}
if (v->owner != _local_player) disabled |= 1 << 8 | 1 << 7;
if (v->owner != _local_player)
disabled |= 1<<8 | 1<<7;
w->disabled_state = disabled;
/* draw widgets & caption */
@@ -512,6 +501,10 @@ static void AircraftViewWndProc(Window *w, WindowEvent *e)
SetDParam(1, v->unitnumber);
DrawWindowWidgets(w);
/* draw the flag */
DrawSprite(v->vehstatus & VS_STOPPED ? 0xC12 : 0xC13, 2,
w->widget[5].top + 1);
if (v->vehstatus & VS_CRASHED) {
str = STR_8863_CRASHED;
} else if (v->vehstatus & VS_STOPPED) {
@@ -538,23 +531,21 @@ static void AircraftViewWndProc(Window *w, WindowEvent *e)
if (v->num_orders == 0) {
str = STR_NO_ORDERS + _patches.vehicle_speed;
SetDParam(0, v->cur_speed * 8);
} else {
} else
str = STR_EMPTY;
}
break;
}
}
/* draw the flag plus orders */
DrawSprite(v->vehstatus & VS_STOPPED ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, 2, w->widget[5].top + 1);
DrawStringCenteredTruncated(w->widget[5].left + 8, w->widget[5].right, w->widget[5].top + 1, str, 0);
DrawStringCentered((w->widget[5].right - w->widget[5].left) / 2,
w->widget[5].top + 1, str, 0);
DrawWindowViewport(w);
} break;
case WE_CLICK: {
const Vehicle* v = GetVehicle(w->window_number);
Vehicle *v = GetVehicle(w->window_number);
switch (e->click.widget) {
switch(e->click.widget) {
case 5: /* start stop */
DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_AIRCRAFT | CMD_MSG(STR_A016_CAN_T_STOP_START_AIRCRAFT));
break;
@@ -573,10 +564,6 @@ static void AircraftViewWndProc(Window *w, WindowEvent *e)
case 10: /* show details */
ShowAircraftDetailsWindow(v);
break;
case 11:
/* clone vehicle */
DoCommandP(v->tile, v->index, _ctrl_pressed ? 1 : 0, CcCloneAircraft, CMD_CLONE_VEHICLE | CMD_MSG(STR_A008_CAN_T_BUILD_AIRCRAFT));
break;
}
} break;
@@ -592,16 +579,6 @@ static void AircraftViewWndProc(Window *w, WindowEvent *e)
DeleteWindowById(WC_VEHICLE_REFIT, w->window_number);
DeleteWindowById(WC_VEHICLE_DETAILS, w->window_number);
break;
case WE_MOUSELOOP: {
const Vehicle* v = GetVehicle(w->window_number);
uint32 h = IsAircraftInHangarStopped(v) ? 1 << 7 : 1 << 11;
if (h != w->hidden_state) {
w->hidden_state = h;
SetWindowDirty(w);
}
} break;
}
}
@@ -615,11 +592,12 @@ static const WindowDesc _aircraft_view_desc = {
};
void ShowAircraftViewWindow(const Vehicle* v)
void ShowAircraftViewWindow(Vehicle *v)
{
Window* w = AllocateWindowDescFront(&_aircraft_view_desc, v->index);
Window *w;
if (w != NULL) {
w = AllocateWindowDescFront(&_aircraft_view_desc, v->index);
if (w) {
w->caption_color = v->owner;
AssignWindowViewport(w, 3, 17, 0xE2, 0x54, w->window_number | (1 << 31), 0);
}
@@ -627,29 +605,25 @@ void ShowAircraftViewWindow(const Vehicle* v)
static void DrawAircraftDepotWindow(Window *w)
{
TileIndex tile;
uint tile;
Vehicle *v;
int num,x,y;
tile = w->window_number;
/* setup disabled buttons */
w->disabled_state =
IsTileOwner(tile, _local_player) ? 0 : ((1<<4) | (1<<7) | (1<<8));
w->disabled_state = (_map_owner[tile]==_local_player) ? 0 : ((1<<4)|(1<<7));
/* determine amount of items for scroller */
num = 0;
FOR_ALL_VEHICLES(v) {
if (v->type == VEH_Aircraft &&
v->subtype <= 2 &&
v->vehstatus & VS_HIDDEN &&
v->tile == tile) {
num++;
}
if (v->type == VEH_Aircraft && v->subtype <= 2 && v->vehstatus&VS_HIDDEN &&
v->tile == (TileIndex)tile)
num++;
}
SetVScrollCount(w, (num + w->hscroll.cap - 1) / w->hscroll.cap);
SetDParam(0, _m[tile].m2);
SetDParam(0, _map2[tile]);
DrawWindowWidgets(w);
x = 2;
@@ -660,7 +634,7 @@ static void DrawAircraftDepotWindow(Window *w)
if (v->type == VEH_Aircraft &&
v->subtype <= 2 &&
v->vehstatus&VS_HIDDEN &&
v->tile == tile &&
v->tile == (TileIndex)tile &&
--num < 0 && num >= -w->vscroll.cap * w->hscroll.cap) {
DrawAircraftImage(v, x+12, y, WP(w,traindepot_d).sel);
@@ -668,7 +642,7 @@ static void DrawAircraftDepotWindow(Window *w)
SetDParam(0, v->unitnumber);
DrawString(x, y+2, (uint16)(v->max_age-366) >= v->age ? STR_00E2 : STR_00E3, 0);
DrawSprite((v->vehstatus & VS_STOPPED) ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, x, y + 12);
DrawSprite( (v->vehstatus & VS_STOPPED) ? 0xC12 : 0xC13, x, y+12);
if ((x+=74) == 2 + 74 * w->hscroll.cap) {
x = 2;
@@ -678,10 +652,10 @@ static void DrawAircraftDepotWindow(Window *w)
}
}
static int GetVehicleFromAircraftDepotWndPt(const Window *w, int x, int y, Vehicle **veh) {
static int GetVehicleFromAircraftDepotWndPt(Window *w, int x, int y, Vehicle **veh) {
uint xt,row,xm,ym;
Vehicle *v;
TileIndex tile;
uint tile;
int pos;
xt = x / 74;
@@ -698,14 +672,20 @@ static int GetVehicleFromAircraftDepotWndPt(const Window *w, int x, int y, Vehic
tile = w->window_number;
FOR_ALL_VEHICLES(v) {
if (v->type == VEH_Aircraft && v->subtype <= 2 &&
v->vehstatus & VS_HIDDEN && v->tile == tile &&
if (v->type == VEH_Aircraft &&
v->subtype <= 2 &&
v->vehstatus&VS_HIDDEN &&
v->tile == (TileIndex)tile &&
--pos < 0) {
*veh = v;
if (xm >= 12) return 0;
if (ym <= 12) return -1; /* show window */
return -2; /* start stop */
}
*veh = v;
if (xm >= 12)
return 0;
if (ym <= 12)
return -1; /* show window */
return -2; /* start stop */
}
}
return 1; /* outside */
}
@@ -716,12 +696,9 @@ static void AircraftDepotClickAircraft(Window *w, int x, int y)
int mode = GetVehicleFromAircraftDepotWndPt(w, x, y, &v);
// share / copy orders
if (_thd.place_mode && mode <= 0) {
_place_clicked_vehicle = v;
return;
}
if (_thd.place_mode && mode <= 0) { _place_clicked_vehicle = v; return; }
switch (mode) {
switch(mode) {
case 1:
return;
@@ -746,30 +723,6 @@ static void AircraftDepotClickAircraft(Window *w, int x, int y)
}
}
/**
* Clones an aircraft
* @param *v is the original vehicle to clone
* @param *w is the window of the hangar where the clone is build
*/
static void HandleCloneVehClick(const Vehicle* v, const Window* w)
{
if (v == NULL || v->type != VEH_Aircraft) return;
DoCommandP(w->window_number, v->index, _ctrl_pressed ? 1 : 0,
CcCloneAircraft, CMD_CLONE_VEHICLE | CMD_MSG(STR_A008_CAN_T_BUILD_AIRCRAFT)
);
ResetObjectToPlace();
}
static void ClonePlaceObj(TileIndex tile, const Window* w)
{
const Vehicle* v = CheckMouseOverVehicle();
if (v != NULL) HandleCloneVehClick(v, w);
}
static void AircraftDepotWndProc(Window *w, WindowEvent *e)
{
switch(e->event) {
@@ -779,59 +732,23 @@ static void AircraftDepotWndProc(Window *w, WindowEvent *e)
case WE_CLICK:
switch(e->click.widget) {
case 5: /* click aircraft */
AircraftDepotClickAircraft(w, e->click.pt.x, e->click.pt.y);
break;
case 7: /* show build aircraft window */
ResetObjectToPlace();
ShowBuildAircraftWindow(w->window_number);
break;
case 8: /* clone button */
InvalidateWidget(w, 8);
TOGGLEBIT(w->click_state, 8);
if (HASBIT(w->click_state, 8)) {
_place_clicked_vehicle = NULL;
SetObjectToPlaceWnd(SPR_CURSOR_CLONE, VHM_RECT, w);
} else {
ResetObjectToPlace();
}
break;
case 9: /* scroll to tile */
ResetObjectToPlace();
ScrollMainWindowToTile(w->window_number);
break;
case 5: /* click aircraft */
AircraftDepotClickAircraft(w, e->click.pt.x, e->click.pt.y);
break;
case 7: /* show build aircraft window */
ShowBuildAircraftWindow(w->window_number);
break;
case 8: /* scroll to tile */
ScrollMainWindowToTile(w->window_number);
break;
}
break;
case WE_PLACE_OBJ: {
ClonePlaceObj(e->place.tile, w);
} break;
case WE_ABORT_PLACE_OBJ: {
CLRBIT(w->click_state, 8);
InvalidateWidget(w, 8);
} break;
// check if a vehicle in a depot was clicked..
case WE_MOUSELOOP: {
const Vehicle* v = _place_clicked_vehicle;
// since OTTD checks all open depot windows, we will make sure that it triggers the one with a clicked clone button
if (v != NULL && HASBIT(w->click_state, 8)) {
_place_clicked_vehicle = NULL;
HandleCloneVehClick(v, w);
}
} break;
case WE_DESTROY:
DeleteWindowById(WC_BUILD_VEHICLE, w->window_number);
break;
case WE_DRAGDROP:
case WE_DRAGDROP: {
switch(e->click.widget) {
case 5: {
Vehicle *v;
@@ -869,6 +786,8 @@ static void AircraftDepotWndProc(Window *w, WindowEvent *e)
SetWindowDirty(w);
}
break;
}
break;
case WE_RESIZE:
w->vscroll.cap += e->sizing.diff.y / 24;
@@ -879,7 +798,7 @@ static void AircraftDepotWndProc(Window *w, WindowEvent *e)
}
static const Widget _aircraft_depot_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 318, 0, 13, STR_A002_AIRCRAFT_HANGAR, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_STICKYBOX, RESIZE_LR, 14, 319, 330, 0, 13, 0x0, STR_STICKY_BUTTON},
{ WWT_PANEL, RESIZE_LRB, 14, 296, 318, 14, 13, 0x0, STR_NULL},
@@ -887,9 +806,8 @@ static const Widget _aircraft_depot_widgets[] = {
{ WWT_MATRIX, RESIZE_RB, 14, 0, 295, 14, 61, 0x204, STR_A021_AIRCRAFT_CLICK_ON_AIRCRAFT},
{ WWT_SCROLLBAR, RESIZE_LRB, 14, 319, 330, 14, 61, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 105, 62, 73, STR_A003_NEW_AIRCRAFT, STR_A022_BUILD_NEW_AIRCRAFT},
{WWT_NODISTXTBTN, RESIZE_TB, 14, 106, 212, 62, 73, STR_CLONE_AIRCRAFT, STR_CLONE_AIRCRAFT_INFO_HANGAR_WINDOW},
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 213, 318, 62, 73, STR_00E4_LOCATION, STR_A024_CENTER_MAIN_VIEW_ON_HANGAR},
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 159, 62, 73, STR_A003_NEW_AIRCRAFT, STR_A022_BUILD_NEW_AIRCRAFT},
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 160, 318, 62, 73, STR_00E4_LOCATION, STR_A024_CENTER_MAIN_VIEW_ON_HANGAR},
{ WWT_PANEL, RESIZE_RTB, 14, 319, 318, 62, 73, 0x0, STR_NULL},
{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 319, 330, 62, 73, 0x0, STR_RESIZE_BUTTON},
{ WIDGETS_END},
@@ -904,13 +822,13 @@ static const WindowDesc _aircraft_depot_desc = {
};
void ShowAircraftDepotWindow(TileIndex tile)
void ShowAircraftDepotWindow(uint tile)
{
Window *w;
w = AllocateWindowDescFront(&_aircraft_depot_desc, tile);
if (w != NULL) {
w->caption_color = GetTileOwner(tile);
if (w) {
w->caption_color = _map_owner[tile];
w->vscroll.cap = 2;
w->hscroll.cap = 4;
w->resize.step_width = 74;
@@ -920,7 +838,7 @@ void ShowAircraftDepotWindow(TileIndex tile)
}
}
static void DrawSmallOrderList(const Vehicle *v, int x, int y) {
static void DrawSmallOrderList(Vehicle *v, int x, int y) {
const Order *order;
int sel, i = 0;
@@ -939,7 +857,8 @@ static void DrawSmallOrderList(const Vehicle *v, int x, int y) {
DrawString(x, y, STR_A036, 0);
y += 6;
if (++i == 4) break;
if (++i == 4)
break;
}
}
}
@@ -949,9 +868,9 @@ static const Widget _player_aircraft_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 247, 0, 13, STR_A009_AIRCRAFT, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_STICKYBOX, RESIZE_LR, 14, 248, 259, 0, 13, 0x0, STR_STICKY_BUTTON},
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 80, 14, 25, STR_SORT_BY, STR_SORT_ORDER_TIP},
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 80, 14, 25, SRT_SORT_BY, STR_SORT_ORDER_TIP},
{ WWT_PANEL, RESIZE_NONE, 14, 81, 235, 14, 25, 0x0, STR_SORT_CRITERIA_TIP},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 236, 247, 14, 25, STR_0225, STR_SORT_CRITERIA_TIP},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 236, 247, 14, 25, STR_0225, STR_SORT_CRITERIA_TIP},
{ WWT_PANEL, RESIZE_RIGHT, 14, 248, 259, 14, 25, 0x0, STR_NULL},
{ WWT_MATRIX, RESIZE_RB, 14, 0, 247, 26, 169, 0x401, STR_A01F_AIRCRAFT_CLICK_ON_AIRCRAFT},
{ WWT_SCROLLBAR, RESIZE_LRB, 14, 248, 259, 26, 169, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
@@ -966,9 +885,9 @@ static const Widget _other_player_aircraft_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 247, 0, 13, STR_A009_AIRCRAFT, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_STICKYBOX, RESIZE_LR, 14, 248, 259, 0, 13, 0x0, STR_STICKY_BUTTON},
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 80, 14, 25, STR_SORT_BY, STR_SORT_ORDER_TIP},
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 80, 14, 25, SRT_SORT_BY, STR_SORT_ORDER_TIP},
{ WWT_PANEL, RESIZE_NONE, 14, 81, 235, 14, 25, 0x0, STR_SORT_CRITERIA_TIP},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 236, 247, 14, 25, STR_0225, STR_SORT_CRITERIA_TIP},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 236, 247, 14, 25, STR_0225, STR_SORT_CRITERIA_TIP},
{ WWT_PANEL, RESIZE_RIGHT, 14, 248, 259, 14, 25, 0x0, STR_NULL},
{ WWT_MATRIX, RESIZE_RB, 14, 0, 247, 26, 169, 0x401, STR_A01F_AIRCRAFT_CLICK_ON_AIRCRAFT},
{ WWT_SCROLLBAR, RESIZE_LRB, 14, 248, 259, 26, 169, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
@@ -979,8 +898,8 @@ static const Widget _other_player_aircraft_widgets[] = {
static void PlayerAircraftWndProc(Window *w, WindowEvent *e)
{
StationID station = GB(w->window_number, 16, 16);
PlayerID owner = GB(w->window_number, 0, 8);
int station = (int)w->window_number >> 16;
int owner = w->window_number & 0xff;
vehiclelist_d *vl = &WP(w, vehiclelist_d);
switch(e->event) {
@@ -996,12 +915,13 @@ static void PlayerAircraftWndProc(Window *w, WindowEvent *e)
SetVScrollCount(w, vl->list_length);
// disable 'Sort By' tooltip on Unsorted sorting criteria
if (vl->sort_type == SORT_BY_UNSORTED) w->disabled_state |= (1 << 3);
if (vl->sort_type == SORT_BY_UNSORTED)
w->disabled_state |= (1 << 3);
/* draw the widgets */
{
const Player *p = GetPlayer(owner);
if (station == INVALID_STATION) {
const Player *p = DEREF_PLAYER(owner);
if (station == -1) {
/* Company Name -- (###) Aircraft */
SetDParam(0, p->name_1);
SetDParam(1, p->name_2);
@@ -1018,7 +938,7 @@ static void PlayerAircraftWndProc(Window *w, WindowEvent *e)
/* draw sorting criteria string */
DrawString(85, 15, _vehicle_sort_listing[vl->sort_type], 0x10);
/* draw arrow pointing up/down for ascending/descending sorting */
DoDrawString(vl->flags & VL_DESC ? DOWNARROW : UPARROW, 69, 15, 0x10);
DoDrawString(vl->flags & VL_DESC ? "\xAA" : "\xA0", 69, 15, 0x10);
max = min(w->vscroll.pos + w->vscroll.cap, vl->list_length);
for (i = w->vscroll.pos; i < max; ++i) {
@@ -1031,11 +951,10 @@ static void PlayerAircraftWndProc(Window *w, WindowEvent *e)
DrawVehicleProfitButton(v, x, y + 13);
SetDParam(0, v->unitnumber);
if (IsAircraftInHangar(v)) {
if (IsAircraftHangarTile(v->tile) && (v->vehstatus & VS_HIDDEN))
str = STR_021F;
} else {
else
str = v->age > v->max_age - 366 ? STR_00E3 : STR_00E2;
}
DrawString(x, y + 2, str, 0);
SetDParam(0, v->profit_this_year);
@@ -1069,7 +988,7 @@ static void PlayerAircraftWndProc(Window *w, WindowEvent *e)
case 7: { /* Matrix to show vehicles */
uint32 id_v = (e->click.pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET) / PLY_WND_PRC__SIZE_OF_ROW_BIG;
if (id_v >= w->vscroll.cap) return; // click out of bounds
if (id_v >= w->vscroll.cap) { return;} // click out of bounds
id_v += w->vscroll.pos;
@@ -1087,14 +1006,14 @@ static void PlayerAircraftWndProc(Window *w, WindowEvent *e)
} break;
case 9: { /* Build new Vehicle */
TileIndex tile;
uint tile;
if (!IsWindowOfPrototype(w, _player_aircraft_widgets))
break;
tile = _last_built_aircraft_depot_tile;
do {
if (IsAircraftHangarTile(tile) && IsTileOwner(tile, _local_player)) {
if (_map_owner[tile] == _local_player && IsAircraftHangarTile(tile)) {
ShowAircraftDepotWindow(tile);
ShowBuildAircraftWindow(tile);
return;
@@ -1124,7 +1043,8 @@ static void PlayerAircraftWndProc(Window *w, WindowEvent *e)
_sorting.aircraft.criteria = vl->sort_type;
// enable 'Sort By' if a sorter criteria is chosen
if (vl->sort_type != SORT_BY_UNSORTED) CLRBIT(w->disabled_state, 3);
if (vl->sort_type != SORT_BY_UNSORTED)
CLRBIT(w->disabled_state, 3);
}
SetWindowDirty(w);
break;
@@ -1174,7 +1094,7 @@ static const WindowDesc _other_player_aircraft_desc = {
PlayerAircraftWndProc
};
void ShowPlayerAircraft(PlayerID player, StationID station)
void ShowPlayerAircraft(int player, int station)
{
Window *w;
@@ -1184,7 +1104,7 @@ void ShowPlayerAircraft(PlayerID player, StationID station)
w = AllocateWindowDescFront(&_other_player_aircraft_desc, (station << 16) | player);
}
if (w != NULL) {
if (w) {
w->caption_color = w->window_number;
w->vscroll.cap = 4;
w->widget[7].unkA = (w->vscroll.cap << 8) + 1;

View File

@@ -1,19 +1,14 @@
/* $Id$ */
#include "stdafx.h"
#include "openttd.h"
#include "ttd.h"
#include "debug.h"
#include "map.h"
#include "airport.h"
#include "macros.h"
#include "variables.h"
static AirportFTAClass* CountryAirport;
static AirportFTAClass* CityAirport;
static AirportFTAClass* Oilrig;
static AirportFTAClass* Heliport;
static AirportFTAClass* MetropolitanAirport;
static AirportFTAClass* InternationalAirport;
AirportFTAClass *CountryAirport;
AirportFTAClass *CityAirport;
AirportFTAClass *Heliport, *Oilrig;
AirportFTAClass *MetropolitanAirport;
AirportFTAClass *InternationalAirport;
static void AirportFTAClass_Constructor(AirportFTAClass *Airport,
const byte *terminals, const byte *helipads,
@@ -177,15 +172,14 @@ static void AirportFTAClass_Constructor(AirportFTAClass *Airport,
// build the state machine
AirportBuildAutomata(Airport, FA);
DEBUG(misc, 1) ("#Elements %2d; #Terminals %2d in %d group(s); #Helipads %2d in %d group(s); Entry Point %d",
Airport->nofelements, nofterminals, nofterminalgroups, nofhelipads, nofhelipadgroups, Airport->entry_point
);
DEBUG(misc, 1) ("#Elements %2d; #Terminals %2d in %d group(s); #Helipads %2d in %d group(s); Entry Point %d", Airport->nofelements,
nofterminals, nofterminalgroups, nofhelipads, nofhelipadgroups, Airport->entry_point);
{
byte ret = AirportTestFTA(Airport);
if (ret != MAX_ELEMENTS) printf("ERROR with element: %d\n", ret - 1);
assert(ret == MAX_ELEMENTS);
byte _retval = AirportTestFTA(Airport);
if (_retval != MAX_ELEMENTS) {printf("ERROR with element: %d\n", _retval-1);}
assert(_retval == MAX_ELEMENTS);
}
// print out full information
// true -- full info including heading, block, etc
@@ -215,13 +209,12 @@ static uint16 AirportGetNofElements(const AirportFTAbuildup *FA)
int i;
uint16 nofelements = 0;
int temp = FA[0].position;
for (i = 0; i < MAX_ELEMENTS; i++) {
if (temp != FA[i].position) {
nofelements++;
temp = FA[i].position;
}
if (FA[i].position == MAX_ELEMENTS) break;
if (FA[i].position == MAX_ELEMENTS) {break;}
}
return nofelements;
}
@@ -231,7 +224,7 @@ static void AirportBuildAutomata(AirportFTAClass *Airport, const AirportFTAbuild
AirportFTA *FAutomata;
AirportFTA *current;
uint16 internalcounter, i;
FAutomata = malloc(sizeof(AirportFTA) * Airport->nofelements);
FAutomata = (AirportFTA *)malloc(sizeof(AirportFTA) * Airport->nofelements);
Airport->layout = FAutomata;
internalcounter = 0;
@@ -243,13 +236,12 @@ static void AirportBuildAutomata(AirportFTAClass *Airport, const AirportFTAbuild
current->next_position = FA[internalcounter].next_in_chain;
// outgoing nodes from the same position, create linked list
while (current->position == FA[internalcounter + 1].position) {
AirportFTA* newNode = malloc(sizeof(AirportFTA));
newNode->position = FA[internalcounter + 1].position;
newNode->heading = FA[internalcounter + 1].heading;
newNode->block = FA[internalcounter + 1].block;
newNode->next_position = FA[internalcounter + 1].next_in_chain;
while (current->position == FA[internalcounter+1].position) {
AirportFTA *newNode = (AirportFTA *)malloc(sizeof(AirportFTA));
newNode->position = FA[internalcounter+1].position;
newNode->heading = FA[internalcounter+1].heading;
newNode->block = FA[internalcounter+1].block;
newNode->next_position = FA[internalcounter+1].next_in_chain;
// create link
current->next_in_chain = newNode;
current = current->next_in_chain;
@@ -268,14 +260,14 @@ static byte AirportTestFTA(const AirportFTAClass *Airport)
for (i = 0; i < Airport->nofelements; i++) {
position = Airport->layout[i].position;
if (position != next_element) return i;
if (position != next_element) {return i;}
temp = &Airport->layout[i];
do {
if (temp->heading > MAX_HEADINGS && temp->heading != 255) return i;
if (temp->heading == 0 && temp->next_in_chain != 0) return i;
if (position != temp->position) return i;
if (temp->next_position >= Airport->nofelements) return i;
if (temp->heading > MAX_HEADINGS && temp->heading != 255) {return i;}
if (temp->heading == 0 && temp->next_in_chain != 0) {return i;}
if (position != temp->position) {return i;}
if (temp->next_position >= Airport->nofelements) {return i;}
temp = temp->next_in_chain;
} while (temp != NULL);
next_element++;
@@ -283,8 +275,7 @@ static byte AirportTestFTA(const AirportFTAClass *Airport)
return MAX_ELEMENTS;
}
#if 0
static const char* const _airport_heading_strings[] = {
static const char* const _airport_heading_strings[MAX_HEADINGS+2] = {
"TO_ALL",
"HANGAR",
"TERM1",
@@ -307,6 +298,7 @@ static const char* const _airport_heading_strings[] = {
"DUMMY" // extra heading for 255
};
/*
static void AirportPrintOut(const AirportFTAClass *Airport, const bool full_report)
{
AirportFTA *temp;
@@ -320,18 +312,16 @@ static void AirportPrintOut(const AirportFTAClass *Airport, const bool full_repo
heading = (temp->heading == 255) ? MAX_HEADINGS+1 : temp->heading;
printf("Pos:%2d NPos:%2d Heading:%15s Block:%2d\n", temp->position, temp->next_position,
_airport_heading_strings[heading], AirportBlockToString(temp->block));
} else {
printf("P:%2d NP:%2d", temp->position, temp->next_position);
}
else { printf("P:%2d NP:%2d", temp->position, temp->next_position);}
while (temp->next_in_chain != NULL) {
temp = temp->next_in_chain;
if (full_report) {
heading = (temp->heading == 255) ? MAX_HEADINGS+1 : temp->heading;
printf("Pos:%2d NPos:%2d Heading:%15s Block:%2d\n", temp->position, temp->next_position,
_airport_heading_strings[heading], AirportBlockToString(temp->block));
} else {
printf("P:%2d NP:%2d", temp->position, temp->next_position);
}
else { printf("P:%2d NP:%2d", temp->position, temp->next_position);}
}
printf("\n");
}
@@ -347,8 +337,7 @@ static byte AirportBlockToString(uint32 block)
if (block & 0x0000000c) { block >>= 2; i += 2; }
if (block & 0x00000002) { i += 1; }
return i;
}
#endif
}*/
const AirportFTAClass* GetAirport(const byte airport_type)
{
@@ -370,14 +359,3 @@ const AirportFTAClass* GetAirport(const byte airport_type)
}
return Airport;
}
uint32 GetValidAirports(void)
{
uint32 bytemask = _avail_aircraft; /// sets the first 3 bytes, 0 - 2, @see AdjustAvailAircraft()
// 1980-1-1 is --> 21915
// 1990-1-1 is --> 25568
if (_date >= 21915) SETBIT(bytemask, 3); // metropilitan airport 1980
if (_date >= 25568) SETBIT(bytemask, 4); // international airport 1990
return bytemask;
}

View File

@@ -1,5 +1,3 @@
/* $Id$ */
#ifndef AIRPORT_H
#define AIRPORT_H
@@ -55,6 +53,15 @@ const AirportFTAClass* GetAirport(const byte airport_type);
* Bit 0 means the small airport is buildable, etc.
* @todo set availability of airports by year, instead of airplane
*/
uint32 GetValidAirports(void);
static inline uint32 GetValidAirports(void)
{
uint32 bytemask = _avail_aircraft; /// sets the first 3 bytes, 0 - 2, @see AdjustAvailAircraft()
// 1980-1-1 is --> 21915
// 1990-1-1 is --> 25568
if (_date >= 21915) {SETBIT(bytemask, 3);} // metropilitan airport 1980
if (_date >= 25568) {SETBIT(bytemask, 4);} // international airport 1990
return bytemask;
}
#endif /* AIRPORT_H */

View File

@@ -1,10 +1,7 @@
/* $Id$ */
#include "stdafx.h"
#include "openttd.h"
#include "ttd.h"
#include "table/sprites.h"
#include "table/strings.h"
#include "functions.h"
#include "map.h"
#include "window.h"
#include "gui.h"
@@ -22,7 +19,7 @@ static byte _selected_airport_type;
static void ShowBuildAirportPicker(void);
void CcBuildAirport(bool success, TileIndex tile, uint32 p1, uint32 p2)
void CcBuildAirport(bool success, uint tile, uint32 p1, uint32 p2)
{
if (success) {
SndPlayTileFx(SND_1F_SPLAT, tile);
@@ -30,12 +27,12 @@ void CcBuildAirport(bool success, TileIndex tile, uint32 p1, uint32 p2)
}
}
static void PlaceAirport(TileIndex tile)
static void PlaceAirport(uint tile)
{
DoCommandP(tile, _selected_airport_type, 0, CcBuildAirport, CMD_BUILD_AIRPORT | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_A001_CAN_T_BUILD_AIRPORT_HERE));
}
static void PlaceAir_DemolishArea(TileIndex tile)
static void PlaceAir_DemolishArea(uint tile)
{
VpStartPlaceSizing(tile, 4);
}
@@ -43,7 +40,7 @@ static void PlaceAir_DemolishArea(TileIndex tile)
static void BuildAirClick_Airport(Window *w)
{
if (HandlePlacePushButton(w, 3, SPR_CURSOR_AIRPORT, 1, PlaceAirport)) ShowBuildAirportPicker();
if (HandlePlacePushButton(w, 3, 0xAA4, 1, PlaceAirport)) ShowBuildAirportPicker();
}
static void BuildAirClick_Demolish(Window *w)
@@ -65,7 +62,7 @@ static OnButtonClick * const _build_air_button_proc[] = {
static void BuildAirToolbWndProc(Window *w, WindowEvent *e)
{
switch (e->event) {
switch(e->event) {
case WE_PAINT:
DrawWindowWidgets(w);
break;
@@ -80,7 +77,8 @@ static void BuildAirToolbWndProc(Window *w, WindowEvent *e)
case '1': BuildAirClick_Airport(w); break;
case '2': BuildAirClick_Demolish(w); break;
case 'l': BuildAirClick_Landscaping(w); break;
default: return;
default:
return;
}
} break;
@@ -106,10 +104,6 @@ static void BuildAirToolbWndProc(Window *w, WindowEvent *e)
if (w != 0)
WP(w,def_d).close = true;
break;
case WE_DESTROY:
if (_patches.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0);
break;
}
}
@@ -137,7 +131,6 @@ void ShowBuildAirToolbar(void)
if (_current_player == OWNER_SPECTATOR) return;
DeleteWindowById(WC_BUILD_TOOLBAR, 0);
AllocateWindowDescFront(&_air_toolbar_desc, 0);
if (_patches.link_terraform_toolbar) ShowTerraformToolbar();
}
static void BuildAirportPickerWndProc(Window *w, WindowEvent *e)
@@ -156,9 +149,9 @@ static void BuildAirportPickerWndProc(Window *w, WindowEvent *e)
if (!HASBIT(avail_airports, 0) && sel == AT_SMALL) sel = AT_LARGE;
if (!HASBIT(avail_airports, 1) && sel == AT_LARGE) sel = AT_SMALL;
/* 'Country Airport' starts at widget 3, and if its bit is set, it is
* available, so take its opposite value to set the disabled_state. There
* are only 5 available airports, so XOR with 0x1F (1 1111) */
/* 'Country Airport' starts at widget 3, and if its bit is set, it is available,
* so take its opposite value to set the disabled_state. There are only 5 available
* airports, so XOr with 0x1F (1 1111) */
w->disabled_state = (avail_airports ^ 0x1F) << 3;
_selected_airport_type = sel;
@@ -166,18 +159,18 @@ static void BuildAirportPickerWndProc(Window *w, WindowEvent *e)
w->click_state = ((1<<3) << sel) | ((1<<8) << _station_show_coverage);
SetTileSelectSize(_airport_size_x[sel],_airport_size_y[sel]);
if (_patches.modified_catchment) {
switch (sel) {
case AT_OILRIG: rad = CA_AIR_OILPAD; break;
case AT_HELIPORT: rad = CA_AIR_HELIPORT; break;
case AT_SMALL: rad = CA_AIR_SMALL; break;
case AT_LARGE: rad = CA_AIR_LARGE; break;
case AT_METROPOLITAN: rad = CA_AIR_METRO; break;
case AT_INTERNATIONAL: rad = CA_AIR_INTER; break;
}
}
if (_patches.modified_catchment) {
switch (sel) {
case AT_OILRIG: rad = CA_AIR_OILPAD; break;
case AT_HELIPORT: rad = CA_AIR_HELIPORT; break;
case AT_SMALL: rad = CA_AIR_SMALL; break;
case AT_LARGE: rad = CA_AIR_LARGE; break;
case AT_METROPOLITAN: rad = CA_AIR_METRO; break;
case AT_INTERNATIONAL: rad = CA_AIR_INTER; break;
}
}
if (_station_show_coverage) SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
if (_station_show_coverage) SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
DrawWindowWidgets(w);
// strings such as 'Size' and 'Coverage Area'
@@ -188,7 +181,7 @@ static void BuildAirportPickerWndProc(Window *w, WindowEvent *e)
}
case WE_CLICK: {
switch (e->click.widget) {
switch(e->click.widget) {
case 3: case 4: case 5: case 6: case 7:
_selected_airport_type = e->click.widget - 3;
SndPlayFx(SND_15_BEEP);
@@ -212,7 +205,8 @@ static void BuildAirportPickerWndProc(Window *w, WindowEvent *e)
} break;
case WE_DESTROY:
if (!WP(w,def_d).close) ResetObjectToPlace();
if (!WP(w,def_d).close)
ResetObjectToPlace();
break;
}
}
@@ -226,8 +220,8 @@ static const Widget _build_airport_picker_widgets[] = {
{WWT_NODISTXTBTN, RESIZE_NONE, 14, 2, 145, 63, 74, STR_306B_HELIPORT, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
{WWT_NODISTXTBTN, RESIZE_NONE, 14, 2, 145, 39, 50, STR_305AA_LARGE, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
{WWT_NODISTXTBTN, RESIZE_NONE, 14, 2, 145, 51, 62, STR_305AB_LARGE, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 14, 73, 88, 98, STR_02DB_OFF, STR_3065_DON_T_HIGHLIGHT_COVERAGE},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 74, 133, 88, 98, STR_02DA_ON, STR_3064_HIGHLIGHT_COVERAGE_AREA},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 14, 73, 88, 98, STR_02DB_OFF, STR_3065_DON_T_HIGHLIGHT_COVERAGE},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 74, 133, 88, 98, STR_02DA_ON, STR_3064_HIGHLIGHT_COVERAGE_AREA},
{ WIDGETS_END},
};

View File

@@ -1,9 +1,8 @@
/* $Id$ */
#ifndef AIRPORT_MOVEMENT_H
#define AIRPORT_MOVEMENT_H
#include "stdafx.h"
#include "macros.h"
typedef struct AirportMovingData {
int x,y;

View File

@@ -1,5 +1,3 @@
/* $Id$ */
/*
* This file has the core function for AyStar
* AyStar is a fast pathfinding routine and is used for things like
@@ -17,7 +15,7 @@
*/
#include "stdafx.h"
#include "openttd.h"
#include "ttd.h"
#include "aystar.h"
// This looks in the Hash if a node exists in ClosedList
// If so, it returns the PathNode, else NULL

View File

@@ -1,5 +1,3 @@
/* $Id$ */
/*
* This file has the header for AyStar
* AyStar is a fast pathfinding routine and is used for things like
@@ -29,7 +27,7 @@ enum{
typedef struct AyStarNode AyStarNode;
struct AyStarNode {
TileIndex tile;
uint tile;
uint direction;
uint user_data[2];
};
@@ -176,4 +174,4 @@ void AyStarMain_Clear(AyStar *aystar);
void init_AyStar(AyStar* aystar, Hash_HashProc hash, uint num_buckets);
#endif /* AYSTAR_H */
#endif

View File

@@ -1,25 +0,0 @@
/* $Id$ */
/** @file bridge.h Header file for bridges */
#ifndef BRIDGE_H
#define BRIDGE_H
/** Struct containing information about a single bridge type
*/
typedef struct Bridge {
byte avail_year; ///< the year in which the bridge becomes available
byte min_length; ///< the minimum length of the bridge (not counting start and end tile)
byte max_length; ///< the maximum length of the bridge (not counting start and end tile)
uint16 price; ///< the relative price of the bridge
uint16 speed; ///< maximum travel speed
PalSpriteID sprite; ///< the sprite which is used in the GUI (possibly with a recolor sprite)
StringID material; ///< the string that contains the bridge description
PalSpriteID **sprite_table; ///< table of sprites for drawing the bridge
byte flags; ///< bit 0 set: disable drawing of far pillars.
} Bridge;
extern const Bridge orig_bridge[MAX_BRIDGES];
extern Bridge _bridge[MAX_BRIDGES];
#endif /* BRIDGE_H */

View File

@@ -1,11 +1,6 @@
/* $Id$ */
/** @file bridge_gui.c Graphical user interface for bridge construction*/
#include "stdafx.h"
#include "openttd.h"
#include "ttd.h"
#include "table/strings.h"
#include "functions.h"
#include "map.h"
#include "window.h"
#include "gui.h"
@@ -13,19 +8,23 @@
#include "gfx.h"
#include "command.h"
#include "sound.h"
#include "variables.h"
#include "bridge.h"
static struct BridgeData {
uint count;
int count;
TileIndex start_tile;
TileIndex end_tile;
byte type;
byte indexes[MAX_BRIDGES];
int32 costs[MAX_BRIDGES];
} _bridgedata;
} _bridge;
void CcBuildBridge(bool success, TileIndex tile, uint32 p1, uint32 p2)
extern const uint16 _bridge_type_price_mod[MAX_BRIDGES];
extern const PalSpriteID _bridge_sprites[MAX_BRIDGES];
extern const uint16 _bridge_speeds[MAX_BRIDGES];
extern const StringID _bridge_material[MAX_BRIDGES];
void CcBuildBridge(bool success, uint tile, uint32 p1, uint32 p2)
{
if (success) SndPlayTileFx(SND_27_BLACKSMITH_ANVIL, tile);
}
@@ -33,8 +32,7 @@ void CcBuildBridge(bool success, TileIndex tile, uint32 p1, uint32 p2)
static void BuildBridge(Window *w, int i)
{
DeleteWindow(w);
DoCommandP(_bridgedata.end_tile, _bridgedata.start_tile,
_bridgedata.indexes[i] | (_bridgedata.type << 8), CcBuildBridge,
DoCommandP(_bridge.end_tile, _bridge.start_tile, _bridge.indexes[i] | (_bridge.type << 8), CcBuildBridge,
CMD_BUILD_BRIDGE | CMD_AUTO | CMD_MSG(STR_5015_CAN_T_BUILD_BRIDGE_HERE));
}
@@ -42,25 +40,25 @@ static void BuildBridgeWndProc(Window *w, WindowEvent *e)
{
switch(e->event) {
case WE_PAINT: {
uint i;
int i;
DrawWindowWidgets(w);
for (i = 0; i < 4 && i + w->vscroll.pos < _bridgedata.count; i++) {
const Bridge *b = &_bridge[_bridgedata.indexes[i + w->vscroll.pos]];
for(i=0; i < 4 && i + w->vscroll.pos < _bridge.count; i++) {
int ind = _bridge.indexes[i + w->vscroll.pos];
SetDParam(2, _bridgedata.costs[i + w->vscroll.pos]);
SetDParam(1, (b->speed >> 4) * 10);
SetDParam(0, b->material);
DrawSprite(b->sprite, 3, 15 + i * 22);
SetDParam(2, _bridge.costs[i + w->vscroll.pos]);
SetDParam(1, (_bridge_speeds[ind] >> 4) * 10);
SetDParam(0, _bridge_material[ind]);
DrawSprite(_bridge_sprites[ind], 3, 15 + i * 22);
DrawString(44, 15 + i * 22 , STR_500D, 0);
DrawString(44, 15 + i*22 , STR_500D, 0);
}
} break;
case WE_KEYPRESS: {
uint i = e->keypress.keycode - '1';
if (i < 9 && i < _bridgedata.count) {
if (i < 9 && i < (uint)_bridge.count) {
e->keypress.cont = false;
BuildBridge(w, i);
}
@@ -69,9 +67,9 @@ static void BuildBridgeWndProc(Window *w, WindowEvent *e)
}
case WE_CLICK:
if (e->click.widget == 2) {
if (e->click.widget == 2) {
uint ind = ((int)e->click.pt.y - 14) / 22;
if (ind < 4 && (ind += w->vscroll.pos) < _bridgedata.count)
if (ind < 4 && (ind += w->vscroll.pos) < (uint)_bridge.count)
BuildBridge(w, ind);
}
break;
@@ -112,53 +110,54 @@ static const WindowDesc _build_road_bridge_desc = {
};
void ShowBuildBridgeWindow(TileIndex start, TileIndex end, byte bridge_type)
void ShowBuildBridgeWindow(uint start, uint end, byte bridge_type)
{
uint j = 0;
int j = 0;
int32 ret;
StringID errmsg;
uint16 errmsg;
DeleteWindowById(WC_BUILD_BRIDGE, 0);
_bridgedata.type = bridge_type;
_bridgedata.start_tile = start;
_bridgedata.end_tile = end;
_bridge.type = bridge_type;
_bridge.start_tile = start;
_bridge.end_tile = end;
errmsg = INVALID_STRING_ID;
errmsg = 0xFFFF;
// only query bridge building possibility once, result is the same for all bridges!
// returns CMD_ERROR on failure, and price on success
// returns CMD_ERROR on failure, and priCe on success
ret = DoCommandByTile(end, start, (bridge_type << 8), DC_AUTO | DC_QUERY_COST, CMD_BUILD_BRIDGE);
if (CmdFailed(ret)) {
if (ret == CMD_ERROR) {
errmsg = _error_message;
} else {
// check which bridges can be built
}
// check which bridges can be built
else {
int bridge_len; // length of the middle parts of the bridge
int tot_bridgedata_len; // total length of bridge
int tot_bridge_len; // total length of bridge
// get absolute bridge length
bridge_len = GetBridgeLength(start, end);
tot_bridgedata_len = bridge_len + 2;
tot_bridge_len = bridge_len + 2;
tot_bridgedata_len = CalcBridgeLenCostFactor(tot_bridgedata_len);
tot_bridge_len = CalcBridgeLenCostFactor(tot_bridge_len);
for (bridge_type = 0; bridge_type != MAX_BRIDGES; bridge_type++) { // loop for all bridgetypes
if (CheckBridge_Stuff(bridge_type, bridge_len)) {
const Bridge *b = &_bridge[bridge_type];
// bridge is accepted, add to list
// add to terraforming & bulldozing costs the cost of the bridge itself (not computed with DC_QUERY_COST)
_bridgedata.costs[j] = ret + (((int64)tot_bridgedata_len * _price.build_bridge * b->price) >> 8);
_bridgedata.indexes[j] = bridge_type;
_bridge.costs[j] = ret + (((int64)tot_bridge_len * _price.build_bridge * _bridge_type_price_mod[bridge_type]) >> 8);
_bridge.indexes[j] = bridge_type;
j++;
}
}
}
_bridgedata.count = j;
_bridge.count = j;
if (j != 0) {
Window *w = AllocateWindowDesc((_bridgedata.type & 0x80) ? &_build_road_bridge_desc : &_build_bridge_desc);
Window *w = AllocateWindowDesc((_bridge.type & 0x80) ? &_build_road_bridge_desc : &_build_bridge_desc);
w->vscroll.cap = 4;
w->vscroll.count = (byte)j;
} else {

View File

@@ -1,64 +0,0 @@
/* $Id$ */
#ifndef BRIDGE_MAP_H
#define BRIDGE_MAP_H
#include "direction.h"
#include "macros.h"
#include "map.h"
#include "rail.h"
#include "tile.h"
static inline bool IsBridge(TileIndex t)
{
assert(IsTileType(t, MP_TUNNELBRIDGE));
return HASBIT(_m[t].m5, 7);
}
static inline bool IsBridgeTile(TileIndex t)
{
return IsTileType(t, MP_TUNNELBRIDGE) && IsBridge(t);
}
static inline bool IsBridgeRamp(TileIndex t)
{
assert(IsBridgeTile(t));
return !HASBIT(_m[t].m5, 6);
}
static inline bool IsBridgeMiddle(TileIndex t)
{
assert(IsBridgeTile(t));
return HASBIT(_m[t].m5, 6);
}
/**
* Get the direction pointing onto the bridge
*/
static inline DiagDirection GetBridgeRampDirection(TileIndex t)
{
assert(IsBridgeRamp(t));
/* Heavy wizardry to convert the X/Y (bit 0) + N/S (bit 5) encoding of
* bridges to a DiagDirection
*/
return (DiagDirection)((6 - (_m[t].m5 >> 4 & 2) - (_m[t].m5 & 1)) % 4);
}
static inline Axis GetBridgeAxis(TileIndex t)
{
assert(IsBridgeMiddle(t));
return (Axis)GB(_m[t].m5, 0, 1);
}
static inline bool IsTransportUnderBridge(TileIndex t)
{
assert(IsBridgeMiddle(t));
return HASBIT(_m[t].m5, 5);
}
#endif

View File

@@ -1,8 +1,5 @@
/* $Id$ */
#include "stdafx.h"
#include "openttd.h"
#include "callback_table.h"
#include "ttd.h"
#include "functions.h"
// If you add a callback for DoCommandP, also add the callback in here
@@ -11,7 +8,6 @@
/* aircraft_gui.c */
CommandCallback CcBuildAircraft;
CommandCallback CcCloneAircraft;
/* airport_gui.c */
CommandCallback CcBuildAirport;
@@ -27,6 +23,7 @@ CommandCallback CcBuildCanal;
CommandCallback CcPlaySound10;
CommandCallback CcPlaceSign;
CommandCallback CcTerraform;
//CommandCallback CcDemolish;
CommandCallback CcBuildTown;
/* rail_gui.c */
@@ -42,18 +39,13 @@ CommandCallback CcRoadDepot;
/* roadveh_gui.c */
CommandCallback CcBuildRoadVeh;
CommandCallback CcCloneRoadVeh;
/* ship_gui.c */
CommandCallback CcBuildShip;
CommandCallback CcCloneShip;
/* train_gui.c */
CommandCallback CcBuildWagon;
CommandCallback CcBuildLoco;
CommandCallback CcCloneTrain;
CommandCallback CcAI;
CommandCallback *_callback_table[] = {
/* 0x00 */ NULL,
@@ -76,12 +68,7 @@ CommandCallback *_callback_table[] = {
/* 0x11 */ CcPlaySound1D,
/* 0x12 */ CcPlaySound1E,
/* 0x13 */ CcStation,
/* 0x14 */ CcTerraform,
/* 0x15 */ CcCloneAircraft,
/* 0x16 */ CcCloneRoadVeh,
/* 0x17 */ CcCloneShip,
/* 0x18 */ CcCloneTrain,
/* 0x19 */ CcAI
/* 0x14 */ CcTerraform
};
const int _callback_table_count = lengthof(_callback_table);

View File

@@ -1,11 +1,7 @@
/* $Id$ */
#ifndef CALLBACK_TABLE_H
#define CALLBACK_TABLE_H
#include "functions.h"
extern CommandCallback *_callback_table[];
extern const int _callback_table_count;
#endif /* CALLBACK_TABLE_H */
#endif

View File

@@ -1,258 +1,3 @@
0.4.8-RC1 (2006-06-28)
------------------------------------------------------------------------
- Feature: Add Turkish town names as we have an official Turkish translation
- Feature: Add a fully optional configure script that is a wrapper around the cumbersome makefile.config
- Codechange: [NPF] Disable NPF totally for ships as it wholly kills performance (blathijs). Only for 0.4/ branch and 0.4.8.
- Fix: Redraw the screen when switching the signal side in the patches window
- Fix: It was possible to dig into a tunnel if certain rail combinations were ontop of it
- Fix: A HQ could only be flooded at its northern tile, the other 3 were immune to water
- Fix: Fix several glitches concerning foundations. Houses, property (rail/road/bridge/etc.) and cursor are now aligned properly
- Fix: Prohibit altering a road tile while road works are in progress. This fixes some glitches like "turning" the excavation by adding/removing road bits or removing the road piece
- Fix: Only advertise the server to your external IP/network (eg not to 127.0.0.1) and use proper broadcast addresses
- Fix: '-f' switch is not valid on windows, so don't show it in help
- Fix: [autoreplace] Autoreplaced trains can leave all wagons in depot under certain circumstances
- Fix: The wrong IP could get unbanned, e.g. 'unban 1.2.3.42' could result in unbanning 1.2.3.4
- Fix: It was possible to convert the railtype of a bridge while a train was on it
- Fix: It was possible to rename signs or waypoints with the chat box
- Fix: Be more strict what it means for an aircraft to be in a hangar: It's not just being stopped on a hangar tile
- Fix: If a road vehicle is on a road depot tile and stopped doesn't mean it's in the depot. Use the proper test for this
- Fix: [AI] The AI should send a plane into a hangar if it's not in a hangar _or_ not stopped, not when it's not in a hangar _and_ not stopped
- Fix: [AI] The trolly AI used information from the wrong industry when calculating the amount of to be transported goods
- Fix: [NTP] Fix NTP over bridges: don't check the rail type when on a bridge
- Fix: Truncate text in dropdown lists to stop text overflowing.
- Fix: "Erroneous train reversal on waypoints". When processing the next train order, do not even consider reversing the train if the last order was to a waypoint.
- Fix: Starting a new scenario did not adhere to local difficulty settings but took it from the scenario itself. That mode is for 'play scenario'
- Fix: Vehicles on a sloped tile under a bridge were affected by the bridge speed limit
- Fix: Issue with train pathfinding over level crossings.
- Fix: [AI] The AI no longer attempts to build signals under bridges.
- Fix: Refresh build vehicle window (if opened) when converting rail depot
- Fix: Crash when sorting an empty server list.
- Fix: The build-tree window button defaulted to a place-push-button on opening where no treetype is selected.
- Fix: Game crashes when cloning/autoreplace reaches train-limit
- Fix: [NTP] properly check for railtypes on non-plain-rail-tiles
- Fix: Trains could enter certain sloped rail tiles under bridges with incompatible rail type
- Fix: Ensure the map memory is cleared after it is allocated. This fixes random deserts that sometimes occurred.
- Fix: Some weird behaviour with tile selection near bridges
- Fix: Don't allow PF to enter train depot from the back (signal updates)
- Fix: Game no longer crashes when the last vehicle servicing a station has been deleted
- Fix: Reset the last built railtype when starting a new game
- Fix: Cloned vehicles get the same service interval as the original vehicle
- Fix: Game no longer errors out when "Many random towns" is selected in the scenario editor.
- Fix: Obscure road dragging bug. The road build command did not return the appropiate error message of invalid-slope when building road.
- Fix: Temperate bank will no longer appear (during game) in tropic landscape. This bug is from the original game.
- Fix: Specify the 'stopall' console command as a debug command.
- Fix: Fixed a problem that caused DeliverGoodsToIndustry to not work as intended
- Fix: Ships and aircraft can now be used as feeders as well
- Fix: When a multiheaded train is sold the pointers were not updated correctly causing sporadious crashes/disconnects.
- Fix: New plantations now cause the correct ".. being planted .." news item
- Fix: Danish town names were saved/loaded as Swiss
- Fix: Removing roads on crossings was done without a check for ownership
- Fix: [autoreplace] Fix drawing of train list for outdated engines
- Fix: Malicious clients/servers could crash the game
- Fix: [autoreplace] allow replacement of wagons even when the engine fails to be replaced
- Fix: Certain operations involving trains inside a depot could cause a crash
- Fix: [autoreplace] cost for refitting a new vehicle is added to the cost animation (player always paid for it, it just wasn't shown)
- Fix: [OSX] Save/Load issues solved for OSX 10.3.9 universal binaries
- Fix: Illegal servers in the master-server list could kick the client back to the main menu, effectively making Multiplayer impossible
- Fix: [NPF] Don't mark tiles when debugging in multiplayer, this will cause desyncs
- Fix: Several fixes to chatbox code, mainly plug a buffer overflow
0.4.7 (2006-03-26)
------------------------------------------------------------------------
- Feature: [OSX] Add support for triple-binaries (PPC, PPC970, i386) (r4102)
- Fix: [OSX] crash when going to fullscreen (r4100)
- Fix: Allow unused wagons to have their first cache set. Fixes faulty cache-warning message and noticably speeds up depot operations (r4094)
- Fix: [NPF] Trains & busses were unable to find a route when leaving a depot or bus stop. (r4072)
0.4.6 (2006-03-22)
------------------------------------------------------------------------
- Codechange: [win32] Show the revision in crash.txt and enable the button to show the crash text in the crash-window (r3965)
- Codechange: Add additional linker information to release builds to help figure out crashes more easily (r3526)
- Fix: [OSX 10.3 and newer] [ 1157244 ] Can't save game if name contains german umlauts (loading savegames with certain chars still look odd) (r4038)
- Fix: [OSX] major speedup for PPC fullscreen (r4034)
- Fix: [Makefile] Make sure the ICON_DIR gets created before copying files there. (r4032)
- Fix: [win32] Change compiler settings to use the multithreaded CRT. This prevents certain crashes on multi-threaded machines. (r4031)
- Fix: [ 1453646 NPF ] Road vehicles planning through the back of depots and stations. (r4029)
- Fix: Use the title of a savegame in the saveload dialog-editbox. (r4018)
- Fix: Improper resolution written to the configuration file when exiting from fullscreen. (r4017)
- Fix: When removing rail track from a tile where only X and Y pieces exist, explicitly update signals in both directions. (r4016)
- Fix: Default the patch-setting 'pause_on_join' to true. (r4015)
- Fix: Slope and height information returned for some tile types is wrong (r4014)
- Fix: Fixes a bug introduced by r3228 which allowed steep rail tiles resulting in ... unwanted effects such as display artifacts. (r4012)
- Fix: Update french translation (r3978)
- Fix: FS#56 - [Crash] Missing glyph(s) in big-font. Added several missing glyphs for the big font. (r3970)
- Fix: [ 1439907 ] Increase client list window width so at least most languages fit. (r3969)
- Fix: Update german and finnish languages. (r3968)
- Fix: Properly set back the owner of a crossing/road-under bridge after removing it. (r3967)
- Fix: [autoreplace]: (FS#67) autoreplacing trains now keep their tile length instead of their pixel length. (r3964)
- Fix: Mark the right tile as dirty. It's just a graphical glitch which happend in r1592. (r3962)
- Fix: Fix crash when resizing news history window. (r3961)
- Fix: Correctly implement minimum search, so road vehicles head twoards the closest station, not the last one in the list. (r3960)
- Fix: [FS#61] The tooltips for raising and lowering land buttons in the scenario editor are interchanged (r3959)
- Fix: Correctly restore the roadside after roadworks are finished. (r3957)
- Fix: [Multistop] Check the status of the destination road stop instead of a station's first road stop. This only has effect with road vehicle queuing disabled. (r3956)
- Fix: validate the setting of max_companies/spectators through the console. (r3955)
- Fix: Improve game-load times. (r3954)
- Fix: On loading a game, GetPlayerRailtypes() didn't account for the fact that vehicles are introduced a year after their introduction date. This will also relieve possible (rare) network desyncs. (r3952)
- Fix: Restore plural forms of cargo types for several languages. (r3951)
- Fix: [win32] Add directives to allow Visual Studio 2005 compilation. (r3950)
- Fix: [ 1415782 ] crash in string code with openbsd/zaurus; alignment issues (r3948)
0.4.5 (2006-01-31)
------------------------------------------------------------------------
- Feature: [newgrf] Implement varaction2 property 0x41 and 0xDA. (2361)
- Feature: giving server_ip a value of 'all' will make the server listen on any interface (2374)
- Feature: shortcut CTRL + U that clears the current input-box (2385)
- Feature: [newgrf] Implement the mechanism for handling newgrf callbacks (2389)
- Feature: [newgrf] Implement the 'refit capacity' callback (2389)
- Feature: saving games happen in a seperate thread (2391)
- Feature: [newgrf] Implement powered wagons, and the callback that goes with it (2414)
- Feature: [newgrf] Implement shorter train vehicles (2428)
- Feature: New display option: 'transparent station signs' (2438)
- Feature: You can now give transfer order to set up feeder systems (2441)
- Feature: Removing tracks with the 'remove' tool, automatically removes signals on the tracks (2469)
- Feature: [localisation] Allow changing the order of parameters in translated strings (2573)
- Feature: [localisation] New way to specify plural forms (2592)
- Feature: [localisation] Support genders (2594)
- Feature: [localisation] Support cases (2597)
- Feature: add support for truncating strings to a given (pixel) length (2607)
- Feature: Overhaul DirectMusic MIDI backend, remove "experimental" status (2712)
- Feature: Change the driver probing algorithm: Use the first music/sound/video which succeeds initialising instead of bailing out after the first. No need to specify -snull if no soundcard is present anymore (2728)
- Feature: The Main Toolbar Dropdown Menu can now display disabled items (2734)
- Feature: Clone vehicles (2764)
- Feature: When starting without a config file determine the language on basis of the current locale (2777)
- Feature: [NewGRF] Add support for "extended bytes" (2872)
- Feature: [localisation] Major step twoards ISO-8859-15: Implement missing characters (2879)
- Feature: Implement the console command rm to remove savegames (2941)
- Feature: Danish town names (2957)
- Feature: Menu option to toggle console (2958)
- Feature: Calculate proportions of non-square giant screenshot correctly (2963)
- Feature: [newgrf] Implement current set of action D (ParamSet) operations (2968)
- Feature: [newgrf] Show a wagon's speed limit in purchase list (2969)
- Feature: [newgrf] Support loading VarAction2 parameter for variables 0x60-0x7F (2971)
- Feature: [newgrf] Add patch option for wagon speed limits (2982)
- Feature: [newgrf] Support loading of bridge attributes and tables from GRF (3004)
- Feature: Native Support for Win64 (3008)
- Feature: OSX now uses quicktime to play midi files (3022)
- Feature: [OSX] Command+Q now works in main menu (3027)
- Feature: Allow unbanning players based on banlist-id (as well as IP) (3067)
- Feature: 'status' and 'clients' now show the IP of the players (3067)
- Feature: Make it possible to create a screenshot from the console that is both big and has no console, or any combination of (3068)
- Feature: [newgrf] Add support for rail vehicle weight greater than 255 tons (3071)
- Feature: 'HOME' icon to saveload dialogs that jumps to the default save/load directory based on the dialog (3096)
- Feature: Turkish translation (3120)
- Feature: [newgrf] Support positioning of rail vehicle visual effects (3132)
- Feature: [newgrf] Support for articulated rail vehicles (3139)
- Feature: [newgrf] Add support for cargo refitting specification by cargo classes (3148)
- Feature: [newgrf] Action 7/9 new value : is it TTDPatch or OpenTTD? (3152)
- Feature: Drag and drop rocky areas in scenario editor (3153)
- Feature: Added patch option to link the terraform toolbar to the rail, road, water and airport toolbars (3157)
- Feature: Right-Click-Scrolling optionally moves in the opposite direction (3222)
- Feature: Native cocoa sound and video drivers for OSX (3281)
- Feature: [newgrf] Allow train running cost class to differ from engine class (3388)
- Feature: Kick and ban now with IP numbers (3407)
- Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console (3427)
- Feature: Allow the network game list to be sorted (by name/clients/compatibility ascending/descending) (3441)
- Feature: Make it possible to ban offline clients (3469)
- Fix: The refit window now shows the correct refit options (2365)
- Fix: Refitting to a cargo which is already carried by some vehicles takes their capacities into account for display (2365)
- Fix: Add 'multihead' TTDPatch option to OpenTTD newgrf flags-emulation (2368)
- Fix: make install tried to install scenarios in the (non-existing) personal dir when USE_HOMEDIR is specified (2371)
- Fix: [console] update the example scripts in the scripts/ directory to reflect the new console functionality (2372)
- Fix: [console] any line starting with a '#' is a comment so ignore it (2372)
- Fix: [console] The special variables whose value can only be set by a custom process should, also print out their newly set value there (2372)
- Fix: [newgrf] Ignore action 0 prop 0x20 (air drag) (2377)
- Fix: [newgrf] Further property stubs, help prevents subsequent incorrect reading of newgrf data (2378)
- Fix: Build year for mail compartment of planes was not set correctly, affected station ratings (2380)
- Fix: Endgame window on easy difficulty resulted in infinite loop (2381)
- Fix: Check the airport type when building an airport (2382)
- Fix: Monkey-testing turned up some command crashes (2383)
- Fix: Check selling land and setting player colour. Also an extra map-bounds check for terraforming (2384)
- Fix: [realistic accel] Very slow trains no longer get an increase in maximum speed when part of them is in a depot (2388)
- Fix: [newgrf] Load power for dual-headed engines correctly (2400)
- Fix: [newgrf] When resolving callbacks, dont ignore wagon overrides (2410)
- Fix: Station ratings aren't affected by speed limits from realistic acceleration anymore (2411)
- Fix: building vehicles without depot crashed the game (2412)
- Fix: certain resolutions caused a crash when minimap was partly dragged outside the game window (2424)
- Fix: Deleting canals under bridges removed bridges first in certain configurations (2436)
- Fix: [NPF] Vehicles try to drive into a tunnel entrance from above (2471)
- Fix: [newgrf] Some road vehicle action 0 properties were loaded as the wrong type (int8,int16,int32) causing undefined results. (like cargo types being wrong) (2474)
- Fix: The console variable autoclean_unprotected was linked to the variable _network_autoclean_protected (2498)
- Fix: Old bug in the PCX writer: The first pixel column contained garbage, the picture was shifted one to the right, and the last column was dropped (2512)
- Fix: Using the mouse wheel could lead to a crash if mouse was not over a widget (2530)
- Fix: blinking 'lock' gfx in multiplayer games (2548)
- Fix: Remove original train pathfinder. Enhanced old pathfinder. (2553)
- Fix: Spaces in the path to the MIDI files caused the win32 MIDI player to fail (2563)
- Fix: set server map name to the loaded name of the game/scenario (2610)
- Fix: Improve the old pathfinder. Changed it to A* instead of Dijkstra. Benchmark shows that NTP is now around 10x faster than NPF (2635)
- Fix: Correctly save and load company_value, it's 64 bits wide, not 32 bits (2684)
- Fix: Volume control works now for the DirectMusic MIDI backend (2712)
- Fix: Change the fence algorithm so it removes fences when no farm tile is adjacent (2739)
- Fix: Tree tiles above the snow line got redrawn disproportionately often (2750)
- Fix: Depots could build trains of the wrong track type (2764)
- Fix: Sort the directories in the scenarion/savegame list (2860)
- Fix: On OS/2 show the trailing \ if the current directory is a root directory (2860)
- Fix: Return a proper version number, when testing the TTDPatch version in the SkipIf action (2862)
- Fix: Change the way NewGRFs are loaded, this saves quite some sprite slots - about 2000 for DBSetXL for example (2868)
- Fix: Several format string vulnerabilities and buffer overflows in the network code (2899)
- Fix: fixed issue where autorenewed vehicles didn't get all stats updated (2912)
- Fix: Exit the child of the extmidi backend with _exit() instead of exit(), because we don't want any atexit handlers - especially flushing output streams - to run, if exec() fails (2938)
- Fix: Server crash with "say"-command (2950)
- Fix: Fix win32 midi volume level control which didn't work (2960)
- Fix: [OSX] quitting the game no longer leaves a process behind that eats all the CPU power (3281)
- Fix: Fix for [ 1216203 ] UFO-broken waypoint (2961)
- Fix: [newgrf] Include missing grf feature canal
- Fix: [newgrf] Add bounds checking to VehicleChangeInfo for vehicles
- Fix: [newgrf] Wagon speed limits don't apply for wagons with livery overrides
- Fix: Align settings pool items to the size of void* to fix bus errors on 64bit architectures which require aligned variables (2976)
- Fix: restart_game_date is an UINT16, not a BYTE. Now setting the game restart year via the console should work (2987)
- Fix: [newgrf] Some GRF files don't specify a name or description, in which case the Action 8 is 8 bytes, not 9 (3005)
- Fix: The finnish markka was never abbreviated with capital letters (3021)
- Fix: Improve handling of non-existent sprite sets (3044)
- Fix: Don't attempt to map and empty sprite group to a vehicle (3045)
- Fix: Fixed typo and hang for BeOS Networking (3053)
- Fix: On Win98 and lower when you go to the root directory of a drive (eg. C:\) you were stuck there indefinitely and couldn't change any directories or see any files (3056)
- Fix: Complete rewrite of autoreplace; multiheaded train engines are replaced correctly (3081)
- Fix: A new train is now made if the front unit is an engine and the former front engine is moved away (3144)
- Fix: There are only 2 possible directions for ship depots, not 4 (3199)
- Fix: Allow bribing up to the maximum rating for bribing, don't disable this option at some arbitrary value early (3201)
- Fix: Don't lower land on tunnel, even with diag tracks on it (3228)
- Fix: Crash when making a screenshotin the main menu (3235)
- Fix: Crash when starting a scenarion via 'New Game' fails (3235)
- Fix: Determine clicked status of sticky icon from window flags rather than the widget click state (3247)
- Fix: Graphical glitch with autorail tool on a certain tile-types (3254)
- Fix: Center the X of the window close button (3302)
- Fix: [newgrf] Unload engine names before loading grf files (3316)
- Fix: Network window crash when it receives invalid information for example from the integrated nightly, so validate the network-input when it is received (3322)
- Fix: Build failed if SDL is built without pthread support (3326)
- Fix: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possib le network desyncs (3352)
- Fix: The default AI tried to change the service intervals of vehicles via the CMD_CHANGE_TRAIN_SERVICE_INT command - regardless of the type of the vehicle (3367)
- Fix: Out-of-bounds array access when road vehicles overtook in a curve caused desyncs (3371)
- Fix: Update signal states when building or removing rail station blocks (3372)
- Fix: Don't allow trains to get bigger than 100 via drag and drop (3374)
- Fix: Don't reset date in the scenario editor when pressing RandomLand (3376)
- Fix: [newgrf] Running cost should be halved for dual head vehicles (3384)
- Fix: No fence was placed when placing fences and the neighbouring tile is a rail configuration which permits a fence but has a signal (3389)
- Fix: [newgrf] Ignore non-climate dependent cargo types (3394)
- Fix: [newgrf] Only add a random number of days to an engine's base introduction date if that date is not 0 (3410)
- Fix: When changing the server password via the console, actually set the password as well as flag whether it is required (3411)
- Fix: Under certain conditions placing a road tile parallel under a bridge would, instead of failing, succeed and place a perpendicular piece (3413)
- Fix: Disable the Fund New Industry menu item and window when connected to a server as a spectator (3414)
- Fix: Disable the clone and refit buttons in the train view when viewing another player's vehicles, or as a spectator (3415)
- Fix: Disallow building an oil rig above sea level (3416)
- Fix: When removing a town-owned tunnel the player's rating was not reduced (3418)
- Fix: (Possible) game crash on removing track/road under bridge if a vehicle was on the track/road under the bridge and the track/road sloped (3419)
- Fix: [newgrf] Only power should decide whether a rail vehicle is an engine or a wagon. (fixes SHIKI 810 in jpsetw.grf) (3424)
- Fix: Incorrect validating of tree-planting command which can allow a buffer-overflow (3446)
- Fix: [newgrf] When changing the sprite ID of a vehicle, if it is not FD (custom graphics), the value needs to changed from a 16bit array offset to an array index. (fixes tropicstw.grf) (3449)
- Fix: You couldn't remove an item from a list-type of config ingame from the configuration file (3475)
- Fix: [newgrf] Always reinitialize the ttdpatch flags as patch settings may have changed (3486)
- Fix: Price for demolishing a bridge was dependent on orientation and map size (3487)
0.4.0.1 (2005-05-21)
------------------------------------------------------------------------

View File

@@ -1,17 +1,10 @@
/* $Id$ */
#include "stdafx.h"
#include "openttd.h"
#include "ttd.h"
#include "table/strings.h"
#include "functions.h"
#include "map.h"
#include "player.h"
#include "tile.h"
#include "viewport.h"
#include "command.h"
#include "tunnel_map.h"
#include "variables.h"
#include "table/sprites.h"
typedef struct TerraformerHeightMod {
TileIndex tile;
@@ -38,11 +31,13 @@ static int TerraformAllowTileProcess(TerraformerState *ts, TileIndex tile)
TileIndex *t;
int count;
if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) return -1;
if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY())
return -1;
t = ts->tile_table;
for (count = ts->tile_table_count; count != 0; count--, t++) {
if (*t == tile) return 0;
for(count = ts->tile_table_count; count != 0; count--,t++) {
if (*t == tile)
return 0;
}
return 1;
@@ -53,8 +48,9 @@ static int TerraformGetHeightOfTile(TerraformerState *ts, TileIndex tile)
TerraformerHeightMod *mod = ts->modheight;
int count;
for (count = ts->modheight_count; count != 0; count--, mod++) {
if (mod->tile == tile) return mod->height;
for(count = ts->modheight_count; count != 0; count--, mod++) {
if (mod->tile == tile)
return mod->height;
}
return TileHeight(tile);
@@ -67,10 +63,12 @@ static void TerraformAddDirtyTile(TerraformerState *ts, TileIndex tile)
count = ts->tile_table_count;
if (count >= 625) return;
if (count >= 625)
return;
for(t = ts->tile_table; count != 0; count--,t++) {
if (*t == tile) return;
if (*t == tile)
return;
}
ts->tile_table[ts->tile_table_count++] = tile;
@@ -78,35 +76,33 @@ static void TerraformAddDirtyTile(TerraformerState *ts, TileIndex tile)
static void TerraformAddDirtyTileAround(TerraformerState *ts, TileIndex tile)
{
TerraformAddDirtyTile(ts, tile + TileDiffXY( 0, -1));
TerraformAddDirtyTile(ts, tile + TileDiffXY(-1, -1));
TerraformAddDirtyTile(ts, tile + TileDiffXY(-1, 0));
TerraformAddDirtyTile(ts, tile+TILE_XY(0,-1));
TerraformAddDirtyTile(ts, tile+TILE_XY(-1,-1));
TerraformAddDirtyTile(ts, tile+TILE_XY(-1,0));
TerraformAddDirtyTile(ts, tile);
}
static int TerraformProc(TerraformerState *ts, TileIndex tile, int mode)
static int TerraformProc(TerraformerState *ts, uint tile, int mode)
{
int r;
int32 ret;
assert(tile < MapSize());
r = TerraformAllowTileProcess(ts, tile);
if (r <= 0) return r;
if ((r=TerraformAllowTileProcess(ts, tile)) <= 0)
return r;
if (IsTileType(tile, MP_RAILWAY)) {
static const TrackBits safe_track[] = { TRACK_BIT_LOWER, TRACK_BIT_LEFT, TRACK_BIT_UPPER, TRACK_BIT_RIGHT };
static const Slope unsafe_slope[] = { SLOPE_S, SLOPE_W, SLOPE_N, SLOPE_E };
Slope tileh;
uint z;
static const byte _railway_modes[4] = {8, 0x10, 4, 0x20};
static const byte _railway_dangslopes[4] = {0xd, 0xe, 7, 0xb};
static const byte _railway_dangslopes2[4] = {0x2, 0x1, 0x8, 0x4};
// Nothing could be built at the steep slope - this avoids a bug
// when you have a single diagonal track in one corner on a
// basement and then you raise/lower the other corner.
tileh = GetTileSlope(tile, &z);
if (tileh == unsafe_slope[mode] ||
tileh == ComplementSlope(unsafe_slope[mode])) {
int tileh = GetTileSlope(tile, NULL) & 0xF;
if (tileh == _railway_dangslopes[mode] ||
tileh == _railway_dangslopes2[mode]) {
_terraform_err_tile = tile;
_error_message = STR_1008_MUST_REMOVE_RAILROAD_TRACK;
return -1;
@@ -114,21 +110,8 @@ static int TerraformProc(TerraformerState *ts, TileIndex tile, int mode)
// If we have a single diagonal track there, the other side of
// tile can be terraformed.
if (IsPlainRailTile(tile) && GetTrackBits(tile) == safe_track[mode]) {
/* If terraforming downwards prevent damaging a potential tunnel below.
* This check is only necessary for flat tiles, because if the tile is
* non-flat, then the corner opposing the rail is raised. Only this corner
* can be lowered and this is a safe action
*/
if (tileh == SLOPE_FLAT &&
ts->direction == -1 &&
IsTunnelInWay(tile, z - TILE_HEIGHT)) {
_terraform_err_tile = tile;
_error_message = STR_1002_EXCAVATION_WOULD_DAMAGE;
return -1;
}
if ((_map5[tile]&~0x40) == _railway_modes[mode])
return 0;
}
}
ret = DoCommandByTile(tile, 0,0, ts->flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR);
@@ -140,13 +123,14 @@ static int TerraformProc(TerraformerState *ts, TileIndex tile, int mode)
ts->cost += ret;
if (ts->tile_table_count >= 625) return -1;
if (ts->tile_table_count >= 625)
return -1;
ts->tile_table[ts->tile_table_count++] = tile;
return 0;
}
static bool TerraformTileHeight(TerraformerState *ts, TileIndex tile, int height)
static bool TerraformTileHeight(TerraformerState *ts, uint tile, int height)
{
int nh;
TerraformerHeightMod *mod;
@@ -161,32 +145,42 @@ static bool TerraformTileHeight(TerraformerState *ts, TileIndex tile, int height
_error_message = STR_1004_TOO_HIGH;
if (height > 15) return false;
if (height > 0xF)
return false;
nh = TerraformGetHeightOfTile(ts, tile);
if (nh < 0 || height == nh) return false;
if (nh < 0 || height == nh)
return false;
if (TerraformProc(ts, tile, 0) < 0) return false;
if (TerraformProc(ts, tile + TileDiffXY( 0, -1), 1) < 0) return false;
if (TerraformProc(ts, tile + TileDiffXY(-1, -1), 2) < 0) return false;
if (TerraformProc(ts, tile + TileDiffXY(-1, 0), 3) < 0) return false;
if (TerraformProc(ts, tile, 0)<0)
return false;
if (TerraformProc(ts, tile + TILE_XY(0,-1), 1)<0)
return false;
if (TerraformProc(ts, tile + TILE_XY(-1,-1), 2)<0)
return false;
if (TerraformProc(ts, tile + TILE_XY(-1,0), 3)<0)
return false;
mod = ts->modheight;
count = ts->modheight_count;
for (;;) {
for(;;) {
if (count == 0) {
if (ts->modheight_count >= 576)
return false;
ts->modheight_count++;
break;
}
if (mod->tile == tile) break;
if (mod->tile == (TileIndex)tile)
break;
mod++;
count--;
}
mod->tile = tile;
mod->tile = (TileIndex)tile;
mod->height = (byte)height;
ts->cost += _price.terraform;
@@ -232,6 +226,7 @@ int32 CmdTerraformLand(int x, int y, uint32 flags, uint32 p1, uint32 p2)
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
_error_message = INVALID_STRING_ID;
_terraform_err_tile = 0;
ts.direction = direction = p2 ? 1 : -1;
@@ -241,32 +236,29 @@ int32 CmdTerraformLand(int x, int y, uint32 flags, uint32 p1, uint32 p2)
ts.modheight = modheight_data;
ts.tile_table = tile_table_data;
tile = TileVirtXY(x, y);
/* Make an extra check for map-bounds cause we add tiles to the originating tile */
if (tile + TileDiffXY(1, 1) >= MapSize()) return CMD_ERROR;
tile = TILE_FROM_XY(x,y);
if (p1 & 1) {
if (!TerraformTileHeight(&ts, tile + TileDiffXY(1, 0),
TileHeight(tile + TileDiffXY(1, 0)) + direction))
if (!TerraformTileHeight(&ts, tile+TILE_XY(1,0),
TileHeight(tile + TILE_XY(1, 0)) + direction))
return CMD_ERROR;
}
if (p1 & 2) {
if (!TerraformTileHeight(&ts, tile + TileDiffXY(1, 1),
TileHeight(tile + TileDiffXY(1, 1)) + direction))
if (!TerraformTileHeight(&ts, tile+TILE_XY(1,1),
TileHeight(tile + TILE_XY(1, 1)) + direction))
return CMD_ERROR;
}
if (p1 & 4) {
if (!TerraformTileHeight(&ts, tile + TileDiffXY(0, 1),
TileHeight(tile + TileDiffXY(0, 1)) + direction))
if (!TerraformTileHeight(&ts, tile+TILE_XY(0,1),
TileHeight(tile + TILE_XY(0, 1)) + direction))
return CMD_ERROR;
}
if (p1 & 8) {
if (!TerraformTileHeight(&ts, tile + TileDiffXY(0, 0),
TileHeight(tile + TileDiffXY(0, 0)) + direction))
if (!TerraformTileHeight(&ts, tile+TILE_XY(0,0),
TileHeight(tile + TILE_XY(0, 0)) + direction))
return CMD_ERROR;
}
@@ -277,19 +269,18 @@ int32 CmdTerraformLand(int x, int y, uint32 flags, uint32 p1, uint32 p2)
for (count = ts.tile_table_count; count != 0; count--, ti++) {
uint z, t;
TileIndex tile = *ti;
uint tile = *ti;
z = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 0));
t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 0));
z = TerraformGetHeightOfTile(&ts, tile + TILE_XY(0,0));
t = TerraformGetHeightOfTile(&ts, tile + TILE_XY(1,0));
if (t <= z) z = t;
t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 1));
t = TerraformGetHeightOfTile(&ts, tile + TILE_XY(1,1));
if (t <= z) z = t;
t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 1));
t = TerraformGetHeightOfTile(&ts, tile + TILE_XY(0,1));
if (t <= z) z = t;
if (IsTunnelInWay(tile, z * TILE_HEIGHT)) {
if (!CheckTunnelInWay(tile, z*8))
return_cmd_error(STR_1002_EXCAVATION_WOULD_DAMAGE);
}
}
}
@@ -307,10 +298,11 @@ int32 CmdTerraformLand(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
int count;
TerraformerHeightMod *mod;
uint til;
mod = ts.modheight;
for (count = ts.modheight_count; count != 0; count--, mod++) {
TileIndex til = mod->tile;
til = mod->tile;
SetTileHeight(til, mod->height);
TerraformAddDirtyTileAround(&ts, til);
@@ -343,7 +335,7 @@ int32 CmdLevelLand(int ex, int ey, uint32 flags, uint32 p1, uint32 p2)
TileIndex tile;
int32 ret, cost, money;
if (p1 >= MapSize()) return CMD_ERROR;
if (p1 > MapSize()) return CMD_ERROR;
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
@@ -357,7 +349,7 @@ int32 CmdLevelLand(int ex, int ey, uint32 flags, uint32 p1, uint32 p2)
sy = TileY(p1);
if (ex < sx) intswap(ex, sx);
if (ey < sy) intswap(ey, sy);
tile = TileXY(sx, sy);
tile = TILE_XY(sx,sy);
size_x = ex-sx+1;
size_y = ey-sy+1;
@@ -400,12 +392,11 @@ int32 CmdPurchaseLandArea(int x, int y, uint32 flags, uint32 p1, uint32 p2)
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
tile = TileVirtXY(x, y);
tile = TILE_FROM_XY(x,y);
if (!EnsureNoVehicle(tile)) return CMD_ERROR;
if (IsTileType(tile, MP_UNMOVABLE) && _m[tile].m5 == 3 &&
IsTileOwner(tile, _current_player))
if (IsTileType(tile, MP_UNMOVABLE) && _map5[tile] == 3 && _map_owner[tile] == _current_player)
return_cmd_error(STR_5807_YOU_ALREADY_OWN_IT);
cost = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
@@ -422,43 +413,25 @@ int32 CmdPurchaseLandArea(int x, int y, uint32 flags, uint32 p1, uint32 p2)
}
static int32 ClearTile_Clear(TileIndex tile, byte flags)
static int32 ClearTile_Clear(uint tile, byte flags)
{
static const int32 null = 0;
static const int32* clear_price_table[] = {
&null,
&_price.clear_1,
&_price.clear_1,
&_price.clear_1,
&_price.purchase_land,
&_price.purchase_land,
&_price.purchase_land,
&_price.purchase_land,
&_price.clear_2,
&_price.clear_2,
&_price.clear_2,
&_price.clear_2,
&_price.clear_3,
&_price.clear_3,
&_price.clear_3,
&_price.clear_3,
&_price.purchase_land,
&_price.purchase_land,
&_price.purchase_land,
&_price.purchase_land,
&_price.purchase_land,
&_price.purchase_land,
&_price.purchase_land,
&_price.purchase_land,
&_price.clear_2,
&_price.clear_2,
&_price.clear_2,
&_price.clear_2,
static const int32 * _clear_price_table[] = {
NULL,
&_price.clear_1, &_price.clear_1,&_price.clear_1,
&_price.purchase_land,&_price.purchase_land,&_price.purchase_land,&_price.purchase_land,
&_price.clear_2,&_price.clear_2,&_price.clear_2,&_price.clear_2,
&_price.clear_3,&_price.clear_3,&_price.clear_3,&_price.clear_3,
&_price.purchase_land,&_price.purchase_land,&_price.purchase_land,&_price.purchase_land,
&_price.purchase_land,&_price.purchase_land,&_price.purchase_land,&_price.purchase_land,
&_price.clear_2,&_price.clear_2,&_price.clear_2,&_price.clear_2,
};
const int32 *price = clear_price_table[GB(_m[tile].m5, 0, 5)];
const int32 *price = _clear_price_table[_map5[tile] & 0x1F];
if (flags & DC_EXEC) DoClearSquare(tile);
if (flags & DC_EXEC)
DoClearSquare(tile);
if (price == NULL)
return 0;
return *price;
}
@@ -474,11 +447,10 @@ int32 CmdSellLandArea(int x, int y, uint32 flags, uint32 p1, uint32 p2)
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
tile = TileVirtXY(x, y);
if (!IsTileType(tile, MP_UNMOVABLE) || _m[tile].m5 != 3) return CMD_ERROR;
if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER) return CMD_ERROR;
tile = TILE_FROM_XY(x,y);
if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER)
return CMD_ERROR;
if (!EnsureNoVehicle(tile)) return CMD_ERROR;
@@ -492,44 +464,45 @@ int32 CmdSellLandArea(int x, int y, uint32 flags, uint32 p1, uint32 p2)
#include "table/clear_land.h"
void DrawClearLandTile(const TileInfo *ti, byte set)
void DrawClearLandTile(TileInfo *ti, byte set)
{
DrawGroundSprite(SPR_FLAT_BARE_LAND + _tileh_to_sprite[ti->tileh] + set * 19);
DrawGroundSprite(0xF54 + _tileh_to_sprite[ti->tileh] + set * 19);
}
void DrawHillyLandTile(const TileInfo *ti)
void DrawHillyLandTile(TileInfo *ti)
{
if (ti->tileh != 0) {
DrawGroundSprite(SPR_FLAT_ROUGH_LAND + _tileh_to_sprite[ti->tileh]);
DrawGroundSprite(0xFA0 + _tileh_to_sprite[ti->tileh]);
} else {
DrawGroundSprite(_landscape_clear_sprites[GB(ti->x ^ ti->y, 4, 3)]);
DrawGroundSprite(_landscape_clear_sprites[((ti->x^ti->y) >> 4) & 0x7]);
}
}
void DrawClearLandFence(const TileInfo *ti)
void DrawClearLandFence(TileInfo *ti, byte img)
{
byte m4 = _m[ti->tile].m4;
byte z = ti->z;
if (ti->tileh & 2) {
z += 8;
if (ti->tileh == 0x17) z += 8;
if (ti->tileh == 0x17)
z += 8;
}
if (GB(m4, 5, 3) != 0) {
DrawGroundSpriteAt(_clear_land_fence_sprites_1[GB(m4, 5, 3) - 1] + _fence_mod_by_tileh[ti->tileh], ti->x, ti->y, z);
if (img & 0x38) {
DrawGroundSpriteAt(_clear_land_fence_sprites_1[((img >> 3) & 7) - 1] + _fence_mod_by_tileh[ti->tileh], ti->x, ti->y, z);
}
if (GB(m4, 2, 3) != 0) {
DrawGroundSpriteAt(_clear_land_fence_sprites_1[GB(m4, 2, 3) - 1] + _fence_mod_by_tileh_2[ti->tileh], ti->x, ti->y, z);
if (img & 0x7) {
DrawGroundSpriteAt(_clear_land_fence_sprites_1[(img & 7) - 1] + _fence_mod_by_tileh_2[ti->tileh], ti->x, ti->y, z);
}
}
static void DrawTile_Clear(TileInfo *ti)
{
switch (GB(ti->map5, 2, 3)) {
switch((ti->map5 & (7<<2)) >> 2) {
case 0:
DrawClearLandTile(ti, GB(ti->map5, 0, 2));
DrawClearLandTile(ti, (ti->map5 & 3));
break;
case 1:
@@ -537,111 +510,134 @@ static void DrawTile_Clear(TileInfo *ti)
break;
case 2:
DrawGroundSprite(SPR_FLAT_ROCKY_LAND_1 + _tileh_to_sprite[ti->tileh]);
DrawGroundSprite(0xFB7 + _tileh_to_sprite[ti->tileh]);
break;
case 3:
DrawGroundSprite(_clear_land_sprites_1[GB(_m[ti->tile].m3, 0, 4)] + _tileh_to_sprite[ti->tileh]);
DrawGroundSprite( _clear_land_sprites_1[_map3_lo[ti->tile]&0xF] + _tileh_to_sprite[ti->tileh]);
break;
case 4:
DrawGroundSprite(_clear_land_sprites_2[GB(ti->map5, 0, 2)] + _tileh_to_sprite[ti->tileh]);
DrawGroundSprite( _clear_land_sprites_2[ti->map5&3] + _tileh_to_sprite[ti->tileh]);
break;
case 5:
DrawGroundSprite(_clear_land_sprites_3[GB(ti->map5, 0, 2)] + _tileh_to_sprite[ti->tileh]);
DrawGroundSprite( _clear_land_sprites_3[ti->map5&3] + _tileh_to_sprite[ti->tileh]);
break;
}
DrawClearLandFence(ti);
DrawClearLandFence(ti, _map3_hi[ti->tile] >> 2);
}
static uint GetSlopeZ_Clear(const TileInfo* ti)
static uint GetSlopeZ_Clear(TileInfo *ti)
{
return GetPartialZ(ti->x & 0xF, ti->y & 0xF, ti->tileh) + ti->z;
}
static uint GetSlopeTileh_Clear(const TileInfo *ti)
static uint GetSlopeTileh_Clear(TileInfo *ti)
{
return ti->tileh;
}
static void GetAcceptedCargo_Clear(TileIndex tile, AcceptedCargo ac)
static void GetAcceptedCargo_Clear(uint tile, AcceptedCargo ac)
{
/* unused */
}
static void AnimateTile_Clear(TileIndex tile)
static void AnimateTile_Clear(uint tile)
{
/* unused */
}
void TileLoopClearHelper(TileIndex tile)
{
byte self;
byte neighbour;
byte img_1;
byte img_2;
static const byte img_by_map5[] = { 0, 0, 0, 2, 1, 1, 0, 0 };
TileIndex dirty = INVALID_TILE;
switch (GetTileType(tile)) {
case MP_CLEAR:
self = (GB(_m[tile].m5, 0, 5) == 15);
img_1 = img_by_map5[(_map5[tile] & 0x1C) >> 2];
break;
case MP_TREES:
if ((_map2[tile] & 0x30) == 0x20)
img_1 = 1;
else
img_1 = 0;
break;
default:
self = 0;
img_1 = 0;
break;
}
switch (GetTileType(TILE_ADDXY(tile, 1, 0))) {
case MP_CLEAR:
neighbour = (GB(_m[TILE_ADDXY(tile, 1, 0)].m5, 0, 5) == 15);
img_2 = img_by_map5[(_map5[TILE_ADDXY(tile, 1, 0)] & 0x1C) >> 2];
break;
case MP_TREES:
if ((_map2[TILE_ADDXY(tile, 1, 0)] & 0x30) == 0x20)
img_2 = 1;
else
img_2 = 0;
break;
default:
neighbour = 0;
img_2 = 0;
break;
}
if (GB(_m[tile].m4, 5, 3) == 0) {
if (self != neighbour) {
SB(_m[tile].m4, 5, 3, 3);
if ((_map3_hi[tile] & 0xE0) == 0) {
if ((img_1 & 2) != (img_2 & 2)) {
_map3_hi[tile] |= 3 << 5;
dirty = tile;
}
} else {
if (self == 0 && neighbour == 0) {
SB(_m[tile].m4, 5, 3, 0);
if (img_1 == 1 && img_2 == 1) {
_map3_hi[tile] &= ~(3 << 5);
dirty = tile;
}
}
switch (GetTileType(TILE_ADDXY(tile, 0, 1))) {
case MP_CLEAR:
neighbour = (GB(_m[TILE_ADDXY(tile, 0, 1)].m5, 0, 5) == 15);
img_2 = img_by_map5[(_map5[TILE_ADDXY(tile, 0, 1)] & 0x1C) >> 2];
break;
case MP_TREES:
if ((_map2[TILE_ADDXY(tile, 0, 1)] & 0x30) == 0x20)
img_2 = 1;
else
img_2 = 0;
break;
default:
neighbour = 0;
img_2 = 0;
break;
}
if (GB(_m[tile].m4, 2, 3) == 0) {
if (self != neighbour) {
SB(_m[tile].m4, 2, 3, 3);
if ((_map3_hi[tile] & 0x1C) == 0) {
if ((img_1 & 2) != (img_2 & 2)) {
_map3_hi[tile] |= 3 << 2;
dirty = tile;
}
} else {
if (self == 0 && neighbour == 0) {
SB(_m[tile].m4, 2, 3, 0);
if (img_1 == 1 && img_2 == 1) {
_map3_hi[tile] &= ~(3 << 2);
dirty = tile;
}
}
if (dirty != INVALID_TILE) MarkTileDirtyByTile(dirty);
if (dirty != INVALID_TILE)
MarkTileDirtyByTile(dirty);
}
/* convert into snowy tiles */
static void TileLoopClearAlps(TileIndex tile)
static void TileLoopClearAlps(uint tile)
{
int k;
byte m5,tmp;
@@ -649,8 +645,8 @@ static void TileLoopClearAlps(TileIndex tile)
/* distance from snow line, in steps of 8 */
k = GetTileZ(tile) - _opt.snow_line;
m5 = _m[tile].m5 & 0x1C;
tmp = _m[tile].m5 & 3;
m5 = _map5[tile] & 0x1C;
tmp = _map5[tile] & 3;
if (k < -8) {
/* snow_m2_down */
@@ -698,29 +694,30 @@ static void TileLoopClearAlps(TileIndex tile)
return;
}
_m[tile].m5 = m5;
_map5[tile] = m5;
MarkTileDirtyByTile(tile);
}
static void TileLoopClearDesert(TileIndex tile)
static void TileLoopClearDesert(uint tile)
{
if ((_m[tile].m5 & 0x1C) == 0x14) return;
if ( (_map5[tile] & 0x1C) == 0x14)
return;
if (GetMapExtraBits(tile) == 1) {
_m[tile].m5 = 0x17;
_map5[tile] = 0x17;
} else {
if (GetMapExtraBits(tile + TileDiffXY( 1, 0)) != 1 &&
GetMapExtraBits(tile + TileDiffXY(-1, 0)) != 1 &&
GetMapExtraBits(tile + TileDiffXY( 0, 1)) != 1 &&
GetMapExtraBits(tile + TileDiffXY( 0, -1)) != 1)
return;
_m[tile].m5 = 0x15;
if (GetMapExtraBits(tile+TILE_XY(1,0)) != 1 &&
GetMapExtraBits(tile+TILE_XY(-1,0)) != 1 &&
GetMapExtraBits(tile+TILE_XY(0,1)) != 1 &&
GetMapExtraBits(tile+TILE_XY(0,-1)) != 1)
return;
_map5[tile] = 0x15;
}
MarkTileDirtyByTile(tile);
}
static void TileLoop_Clear(TileIndex tile)
static void TileLoop_Clear(uint tile)
{
byte m5,m3;
@@ -732,22 +729,24 @@ static void TileLoop_Clear(TileIndex tile)
TileLoopClearAlps(tile);
}
m5 = _m[tile].m5;
if ((m5 & 0x1C) == 0x10 || (m5 & 0x1C) == 0x14) return;
m5 = _map5[tile];
if ( (m5 & 0x1C) == 0x10 || (m5 & 0x1C) == 0x14)
return;
if ((m5 & 0x1C) != 0xC) {
if ((m5 & 3) == 3) return;
if ( (m5 & 0x1C) != 0xC) {
if ( (m5 & 3) == 3)
return;
if (_game_mode != GM_EDITOR) {
m5 += 0x20;
if (m5 >= 0x20) {
// Didn't overflow
_m[tile].m5 = m5;
_map5[tile] = m5;
return;
}
/* did overflow, so continue */
} else {
m5 = (GB(Random(), 0, 8) > 21) ? 2 : 6;
m5 = ((byte)Random() > 21) ? (2) : (6);
}
m5++;
} else if (_game_mode != GM_EDITOR) {
@@ -755,47 +754,47 @@ static void TileLoop_Clear(TileIndex tile)
m5 += 0x20;
if (m5 >= 0x20) {
// Didn't overflow
_m[tile].m5 = m5;
_map5[tile] = m5;
return;
}
/* overflowed */
m3 = _m[tile].m3 + 1;
m3 = _map3_lo[tile] + 1;
assert( (m3 & 0xF) != 0);
if ( (m3 & 0xF) >= 9) /* NOTE: will not work properly if m3&0xF == 0xF */
m3 &= ~0xF;
_m[tile].m3 = m3;
_map3_lo[tile] = m3;
}
_m[tile].m5 = m5;
_map5[tile] = m5;
MarkTileDirtyByTile(tile);
}
void GenerateClearTile(void)
{
uint i;
TileIndex tile;
int i,j;
uint tile,tile_new;
uint32 r;
/* add hills */
i = ScaleByMapSize(GB(Random(), 0, 10) + 0x400);
i = ScaleByMapSize((Random() & 0x3FF) + 0x400);
do {
tile = RandomTile();
if (IsTileType(tile, MP_CLEAR)) SB(_m[tile].m5, 2, 2, 1);
tile = TILE_MASK(Random());
if (IsTileType(tile, MP_CLEAR))
_map5[tile] = (byte)((_map5[tile] & ~(3<<2)) | (1<<2));
} while (--i);
/* add grey squares */
i = ScaleByMapSize(GB(Random(), 0, 7) + 0x80);
i = ScaleByMapSize((Random() & 0x7F) + 0x80);
do {
uint32 r = Random();
tile = RandomTileSeed(r);
r = Random();
tile = TILE_MASK(r);
if (IsTileType(tile, MP_CLEAR)) {
uint j = GB(r, 16, 4) + 5;
j = ((r >> 16) & 0xF) + 5;
for(;;) {
TileIndex tile_new;
SB(_m[tile].m5, 2, 2, 2);
_map5[tile] = (byte)((_map5[tile] & ~(3<<2)) | (2<<2));
do {
if (--j == 0) goto get_out;
tile_new = tile + TileOffsByDir(GB(Random(), 0, 2));
tile_new = tile + TileOffsByDir(Random() & 3);
} while (!IsTileType(tile_new, MP_CLEAR));
tile = tile_new;
}
@@ -804,17 +803,17 @@ get_out:;
} while (--i);
}
static void ClickTile_Clear(TileIndex tile)
static void ClickTile_Clear(uint tile)
{
/* not used */
}
static uint32 GetTileTrackStatus_Clear(TileIndex tile, TransportType mode)
static uint32 GetTileTrackStatus_Clear(uint tile, TransportType mode)
{
return 0;
}
static const StringID _clear_land_str[] = {
static const StringID _clear_land_str[4+8-1] = {
STR_080B_ROUGH_LAND,
STR_080A_ROCKS,
STR_080E_FIELDS,
@@ -828,15 +827,16 @@ static const StringID _clear_land_str[] = {
STR_080D_GRASS,
};
static void GetTileDesc_Clear(TileIndex tile, TileDesc *td)
static void GetTileDesc_Clear(uint tile, TileDesc *td)
{
uint i = GB(_m[tile].m5, 2, 3);
if (i == 0) i = GB(_m[tile].m5, 0, 2) + 8;
int i = (_map5[tile]>>2) & 7;
if (i == 0)
i = (_map5[tile] & 3) + 8;
td->str = _clear_land_str[i - 1];
td->owner = GetTileOwner(tile);
td->owner = _map_owner[tile];
}
static void ChangeTileOwner_Clear(TileIndex tile, PlayerID old_player, PlayerID new_player)
static void ChangeTileOwner_Clear(uint tile, byte old_player, byte new_player)
{
return;
}

View File

@@ -1,15 +1,11 @@
/* $Id$ */
#include "stdafx.h"
#include "openttd.h"
#include "ttd.h"
#include "table/strings.h"
#include "functions.h"
#include "map.h"
#include "gui.h"
#include "command.h"
#include "player.h"
#include "network.h"
#include "variables.h"
const char* _cmd_text = NULL;
@@ -77,7 +73,7 @@ DEF_COMMAND(CmdModifyOrder);
DEF_COMMAND(CmdSkipOrder);
DEF_COMMAND(CmdDeleteOrder);
DEF_COMMAND(CmdInsertOrder);
DEF_COMMAND(CmdChangeServiceInt);
DEF_COMMAND(CmdChangeTrainServiceInt);
DEF_COMMAND(CmdRestoreOrderIndex);
DEF_COMMAND(CmdBuildIndustry);
@@ -103,6 +99,7 @@ DEF_COMMAND(CmdSellAircraft);
DEF_COMMAND(CmdStartStopAircraft);
DEF_COMMAND(CmdBuildAircraft);
DEF_COMMAND(CmdSendAircraftToHangar);
DEF_COMMAND(CmdChangeAircraftServiceInt);
DEF_COMMAND(CmdRefitAircraft);
DEF_COMMAND(CmdPlaceSign);
@@ -113,6 +110,7 @@ DEF_COMMAND(CmdStartStopRoadVeh);
DEF_COMMAND(CmdSellRoadVeh);
DEF_COMMAND(CmdSendRoadVehToDepot);
DEF_COMMAND(CmdTurnRoadVeh);
DEF_COMMAND(CmdChangeRoadVehServiceInt);
DEF_COMMAND(CmdPause);
@@ -134,6 +132,7 @@ DEF_COMMAND(CmdStartStopShip);
DEF_COMMAND(CmdSellShip);
DEF_COMMAND(CmdBuildShip);
DEF_COMMAND(CmdSendShipToDepot);
DEF_COMMAND(CmdChangeShipServiceInt);
DEF_COMMAND(CmdRefitShip);
DEF_COMMAND(CmdCloneOrder);
@@ -156,9 +155,6 @@ DEF_COMMAND(CmdRemoveSignalTrack);
DEF_COMMAND(CmdReplaceVehicle);
DEF_COMMAND(CmdCloneVehicle);
/* The master command table */
static const Command _command_proc_table[] = {
{CmdBuildRailroadTrack, 0}, /* 0 */
@@ -209,7 +205,7 @@ static const Command _command_proc_table[] = {
{CmdDeleteOrder, 0}, /* 44 */
{CmdInsertOrder, 0}, /* 45 */
{CmdChangeServiceInt, 0}, /* 46 */
{CmdChangeTrainServiceInt, 0}, /* 46 */
{CmdBuildIndustry, 0}, /* 47 */
{CmdBuildCompanyHQ, 0}, /* 48 */
@@ -234,7 +230,7 @@ static const Command _command_proc_table[] = {
{CmdBuildAircraft, 0}, /* 61 */
{CmdSendAircraftToHangar, 0}, /* 62 */
{NULL, 0}, /* 63 */
{CmdChangeAircraftServiceInt, 0}, /* 63 */
{CmdRefitAircraft, 0}, /* 64 */
{CmdPlaceSign, 0}, /* 65 */
@@ -245,7 +241,7 @@ static const Command _command_proc_table[] = {
{CmdSellRoadVeh, 0}, /* 69 */
{CmdSendRoadVehToDepot, 0}, /* 70 */
{CmdTurnRoadVeh, 0}, /* 71 */
{NULL, 0}, /* 72 */
{CmdChangeRoadVehServiceInt, 0}, /* 72 */
{CmdPause, CMD_SERVER}, /* 73 */
@@ -268,7 +264,7 @@ static const Command _command_proc_table[] = {
{CmdSellShip, 0}, /* 87 */
{CmdBuildShip, 0}, /* 88 */
{CmdSendShipToDepot, 0}, /* 89 */
{NULL, 0}, /* 90 */
{CmdChangeShipServiceInt, 0}, /* 90 */
{CmdRefitShip, 0}, /* 91 */
{NULL, 0}, /* 92 */
@@ -300,17 +296,17 @@ static const Command _command_proc_table[] = {
{CmdGiveMoney, 0}, /* 113 */
{CmdChangePatchSetting, CMD_SERVER}, /* 114 */
{CmdReplaceVehicle, 0}, /* 115 */
{CmdCloneVehicle, 0}, /* 116 */
};
/* This function range-checks a cmd, and checks if the cmd is not NULL */
bool IsValidCommand(uint cmd)
{
cmd &= 0xFF;
cmd = cmd & 0xFF;
return
cmd < lengthof(_command_proc_table) &&
_command_proc_table[cmd].proc != NULL;
if (cmd >= lengthof(_command_proc_table) || _command_proc_table[cmd].proc == NULL)
return false;
return true;
}
byte GetCommandFlags(uint cmd) {return _command_proc_table[cmd & 0xFF].flags;}
@@ -321,7 +317,7 @@ int32 DoCommandByTile(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint p
}
static int _docommand_recursive;
//extern void _stdcall Sleep(int s);
int32 DoCommand(int x, int y, uint32 p1, uint32 p2, uint32 flags, uint procc)
{
@@ -329,14 +325,20 @@ int32 DoCommand(int x, int y, uint32 p1, uint32 p2, uint32 flags, uint procc)
CommandProc *proc;
/* Do not even think about executing out-of-bounds tile-commands */
if (TileVirtXY(x, y) >= MapSize()) {
if (TILE_FROM_XY(x,y) > MapSize()) {
_cmd_text = NULL;
return CMD_ERROR;
}
proc = _command_proc_table[procc].proc;
if (_docommand_recursive == 0) _error_message = INVALID_STRING_ID;
if (_docommand_recursive == 0) {
_error_message = INVALID_STRING_ID;
// update last build coord of player
if ( (x|y) != 0 && _current_player < MAX_PLAYERS) {
DEREF_PLAYER(_current_player)->last_build_coordinate = TILE_FROM_XY(x,y);
}
}
_docommand_recursive++;
@@ -374,10 +376,6 @@ error:
// if toplevel, subtract the money.
if (--_docommand_recursive == 0) {
SubtractMoneyFromPlayer(res);
// XXX - Old AI hack which doesn't use DoCommandDP; update last build coord of player
if ( (x|y) != 0 && _current_player < MAX_PLAYERS) {
GetPlayer(_current_player)->last_build_coordinate = TileVirtXY(x, y);
}
}
_cmd_text = NULL;
@@ -388,7 +386,7 @@ int32 GetAvailableMoneyForCommand(void)
{
PlayerID pid = _current_player;
if (pid >= MAX_PLAYERS) return 0x7FFFFFFF; // max int
return GetPlayer(pid)->player_money;
return DEREF_PLAYER(pid)->player_money;
}
// toplevel network safe docommand function for the current player. must not be called recursively.
@@ -404,7 +402,7 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback,
int y = TileY(tile) * 16;
/* Do not even think about executing out-of-bounds tile-commands */
if (tile >= MapSize()) {
if (tile > MapSize()) {
_cmd_text = NULL;
return false;
}
@@ -430,10 +428,6 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback,
// get pointer to command handler
assert((cmd & 0xFF) < lengthof(_command_proc_table));
proc = _command_proc_table[cmd & 0xFF].proc;
if (proc == NULL) {
_cmd_text = NULL;
return false;
}
// Some commands have a different output in dryrun than the realrun
// e.g.: if you demolish a whole town, the dryrun would say okay.
@@ -454,7 +448,7 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback,
_docommand_recursive = 1;
// cost estimation only?
if (_shift_pressed && IsLocalPlayer() && !(cmd & (CMD_NETWORK_COMMAND | CMD_SHOW_NO_ERROR))) {
if (_shift_pressed && _current_player == _local_player && !(cmd & (CMD_NETWORK_COMMAND | CMD_SHOW_NO_ERROR))) {
// estimate the cost.
res = proc(x, y, flags, p1, p2);
if (CmdFailed(res)) {
@@ -499,7 +493,7 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback,
#endif /* ENABLE_NETWORK */
// update last build coordinate of player.
if ( tile != 0 && _current_player < MAX_PLAYERS) GetPlayer(_current_player)->last_build_coordinate = tile;
if ( tile != 0 && _current_player < MAX_PLAYERS) DEREF_PLAYER(_current_player)->last_build_coordinate = tile;
/* Actually try and execute the command. If no cost-type is given
* use the construction one */
@@ -519,7 +513,7 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback,
SubtractMoneyFromPlayer(res2);
if (IsLocalPlayer() && _game_mode != GM_EDITOR) {
if (_current_player == _local_player && _game_mode != GM_EDITOR) {
if (res2 != 0)
ShowCostOrIncomeAnimation(x, y, GetSlopeZ(x, y), res2);
if (_additional_cash_required) {
@@ -537,7 +531,7 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback,
show_error:
// show error message if the command fails?
if (IsLocalPlayer() && _error_message_2 != 0)
if (_current_player == _local_player && _error_message_2 != 0)
ShowErrorMessage(_error_message, _error_message_2, x,y);
callb_err:

View File

@@ -1,5 +1,3 @@
/* $Id$ */
#ifndef COMMAND_H
#define COMMAND_H
@@ -58,7 +56,7 @@ enum {
CMD_DELETE_ORDER = 44,
CMD_INSERT_ORDER = 45,
CMD_CHANGE_SERVICE_INT = 46,
CMD_CHANGE_TRAIN_SERVICE_INT = 46,
CMD_BUILD_INDUSTRY = 47,
@@ -81,6 +79,7 @@ enum {
CMD_START_STOP_AIRCRAFT = 60,
CMD_BUILD_AIRCRAFT = 61,
CMD_SEND_AIRCRAFT_TO_HANGAR = 62,
CMD_CHANGE_AIRCRAFT_SERVICE_INT = 63,
CMD_REFIT_AIRCRAFT = 64,
CMD_PLACE_SIGN = 65,
@@ -91,6 +90,7 @@ enum {
CMD_SELL_ROAD_VEH = 69,
CMD_SEND_ROADVEH_TO_DEPOT = 70,
CMD_TURN_ROADVEH = 71,
CMD_CHANGE_ROADVEH_SERVICE_INT = 72,
CMD_PAUSE = 73,
@@ -111,6 +111,7 @@ enum {
CMD_SELL_SHIP = 87,
CMD_BUILD_SHIP = 88,
CMD_SEND_SHIP_TO_DEPOT = 89,
CMD_CHANGE_SHIP_SERVICE_INT = 90,
CMD_REFIT_SHIP = 91,
CMD_CLONE_ORDER = 99,
@@ -133,9 +134,6 @@ enum {
CMD_CHANGE_PATCH_SETTING = 114,
CMD_REPLACE_VEHICLE = 115,
CMD_CLONE_VEHICLE = 116,
};
enum {

276
configure vendored
View File

@@ -1,276 +0,0 @@
#!/bin/sh
# This 'configure' script is a very easy wrapper around 'make updateconf'
# It allows cross-compilers to do their job much more easy.
function showhelp() {
echo "Configure for OpenTTD"
echo ""
echo "Usage:"
echo " $0 --your_options"
echo ""
echo "Params:"
echo " --debug Create debug-release [no]"
echo " --profile Create profile-release [no]"
echo " --dedicated Make a dedicated build [no]"
echo " --revision Set the revision of the compilation [detected]"
echo " --target-cc Sets the target-compiler [\$CC]"
echo " --target-cxx Sets the C++ target-compiler []"
echo " --host-cc Sets the host-compiler [\$CC]"
echo " --os Sets the OS. Listens to: [detected]"
echo " UNIX, OSX, FREEBSD, MORPHOS"
echo " BEOS, SUNOS, CYGWIN, MINGW"
echo " --windres Sets the windres (Windows) [windres]"
echo " --force-le Force LE platform [no]"
echo " --force-be Force BE platform [no]"
echo ""
echo "Params that can be used with --with or --without"
echo " (e.g.: --without-static disables static (default))"
echo " static Do you want a static build? [no]"
echo " directmusic Do you want direct-music? [no]"
echo " zlib Do you want zlib-support? [yes]"
echo " sdl Do you want SDL-support? [yes]"
echo " png Do you want PNG-support? [yes]"
echo " cocoa Do you want cocoa-support? (MacOSX) [no]"
echo ""
echo "Params used to configure external libs:"
echo " --static-zlib-path Set the path to your static zlib []"
echo " --sdl-config Where is your sdl-config [sdl-config]"
echo " --libpng-config Where is your libpng-config [libpng-config]"
echo " "
}
function handle() {
PARAM="$PARAM \"$1=`awk 'BEGIN { FS="="; $0="'"$2"'"; print $2;}'`\""
}
# The things you can use inside this case:
# handle NAME VALUE - Sets the value to give the 'make upgradeconf'
# Value is in form: tag=REAL_VALUE
# ITEM="NAME" - Will set the value as above, only with the next param
# SITEM="NAME" - Will set the var $NAME to the next param
for n in "$@"
do
case "$n" in
--help | -h)
showhelp
exit 0
;;
--debug)
DEBUG_SET=1
ITEM="DEBUG"
;;
--debug=*)
handle "DEBUG" "$n"
;;
--profile)
PARAM="$PARAM PROFILE=1"
;;
--dedicated)
PARAM="$PARAM DEDICATED=1"
;;
--revision=*)
RELEASE=`awk 'BEGIN { FS="="; $0="'"$n"'"; print $2;}'`
;;
--revision)
SITEM="RELEASE"
;;
--target-cc=*)
handle "CC_TARGET" "$n"
;;
--target-cc)
ITEM="CC_TARGET"
;;
--target-cxx=*)
TARGET_CXX=`awk 'BEGIN { FS="="; $0="'"$n"'"; print $2;}'`
;;
--target-cxx)
SITEM="TARGET_CXX"
;;
--host-cc=*)
handle CC_HOST "$n"
;;
--host-cc)
ITEM="CC_HOST"
;;
--host-cflags=*)
handle CFLAGS_HOST "$n"
;;
--host-cflags)
ITEM="CFLAGS_HOST"
;;
--os=*)
TARGET_OS=`awk 'BEGIN { FS="="; $0="'"$n"'"; print $2;}'`
;;
--os)
SITEM="TARGET_OS"
;;
--windres=*)
handle WINDRES "$n"
;;
--windres)
ITEM="WINDRES"
;;
--force-le)
PARAM="$PARAM ENDIAN_FORCE=LE"
;;
--force-be)
PARAM="$PARAM ENDIAN_FORCE=BE"
;;
--with-static)
PARAM="$PARAM STATIC=1"
;;
--without-static)
PARAM="$PARAM STATIC="
;;
--with-directmusic)
PARAM="$PARAM WITH_DIRECTMUSIC=1"
;;
--without-directmusic)
PARAM="$PARAM WITH_DIRECTMUSIC="
;;
--with-zlib)
PARAM="$PARAM WITH_ZLIB=1"
;;
--without-zlib)
PARAM="$PARAM WITH_ZLIB="
;;
--with-sdl)
PARAM="$PARAM WITH_SDL=1"
;;
--without-sdl)
PARAM="$PARAM WITH_SDL="
;;
--with-png)
PARAM="$PARAM WITH_PNG=1"
;;
--without-png)
PARAM="$PARAM WITH_PNG="
;;
--with-cocoa)
PARAM="$PARAM WITH_COCOA=1"
;;
--without-cocoa)
PARAM="$PARAM WITH_COCOA="
;;
--static-zlib-path=*)
handle STATIC_ZLIB_PATH "$n"
;;
--static-zlib-path)
ITEM="STATIC_ZLIB_PATH"
;;
--sdl-config=*)
handle SDL_CONFIG "$n"
;;
--sdl-config)
ITEM="SDL_CONFIG"
;;
--libpng-config=*)
handle LIBPNG_CONFIG "$n"
;;
--lib-png-config)
ITEM="LIBPNG_CONFIG"
;;
--*=*)
echo -n "Unknown switch "
echo `awk 'BEGIN { FS="="; $0="'"$n"'"; print $1;}'`
exit 1
;;
-*)
echo "Unknown switch $n"
exit 1
;;
*)
if ! test -z "$ITEM"
then
PARAM="$PARAM $ITEM=\"$n\""
ITEM="";
elif ! test -z "$SITEM"
then
export $SITEM="$n"
SITEM=""
else
echo "Unknown switch $n"
exit 1
fi
;;
esac
done
if ! test -z "$TARGET_OS"
then
TARGET_OS=`echo $TARGET_OS | tr '[:lower:]' '[:upper:]'`
case "$TARGET_OS" in
WIN32)
PARAM="$PARAM WIN32=1"
;;
UNIX)
PARAM="$PARAM UNIX=1"
;;
OSX)
PARAM="$PARAM OSX=1 UNIX=1"
;;
FREEBSD)
PARAM="$PARAM FREEBSD=1"
;;
MORPHOS)
PARAM="$PARAM MORPHOS=1 UNIX=1"
;;
BEOS)
PARAM="$PARAM BEOS=1 UNIX=1"
;;
SUNOS)
PARAM="$PARAM SUNOS=1 UNIX=1"
;;
CYGWIN)
PARAM="$PARAM CYGWIN=1 WIN32=1"
;;
MINGW)
PARAM="$PARAM MINGW=1 WIN32=1"
;;
*)
echo "Unknown OS: $TARGET_OS"
exit 1
;;
esac
PARAM="$PARAM BYPASS_OS_DETECT=1"
fi
if ! test -z "$DEBUG_SET"
then
if test -z "`echo $PARAM | grep "DEBUG="`"
then
# Someone did --debug, without assigning a value, assume 1
PARAM="$PARAM DEBUG=1"
fi
fi
# First remove the Makefile.config, else you can have double entries
if test -e "Makefile.config"
then
rm -f Makefile.config
fi
echo "make upgradeconf $PARAM" > Makefile.run
. Makefile.run
rm -f Makefile.run
# Makefile.config currently doesn't support custom CXX, so, we add the line
# ourself!
if ! test -z "$TARGET_CXX"
then
echo "CXX=$TARGET_CXX" >> Makefile.config
fi
# Same for RELEASE (read: REVISION)
if ! test -z "$RELEASE"
then
echo "RELEASE=$RELEASE" >> Makefile.config
fi

View File

@@ -1,15 +1,13 @@
/* $Id$ */
#include "stdafx.h"
#include "openttd.h"
#include "ttd.h"
#include "table/strings.h"
#include "functions.h"
#include "window.h"
#include "gui.h"
#include "gfx.h"
#include "player.h"
#include "variables.h"
#include "string.h"
#include "hal.h"
#include <stdarg.h>
#include <string.h>
#include "console.h"
@@ -58,10 +56,6 @@ static void IConsoleClearCommand(void)
static inline void IConsoleResetHistoryPos(void) {_iconsole_historypos = ICON_HISTORY_SIZE - 1;}
static void IConsoleHistoryAdd(const char* cmd);
static void IConsoleHistoryNavigate(int direction);
// ** console window ** //
static void IConsoleWndProc(Window* w, WindowEvent* e)
{
@@ -157,13 +151,9 @@ static void IConsoleWndProc(Window* w, WindowEvent* e)
SetWindowDirty(w);
}
break;
case (WKC_CTRL | 'L'):
case (WKC_CTRL | 'L'):
IConsoleCmdExec("clear");
break;
case (WKC_CTRL | 'U'):
DeleteTextBufferAll(&_iconsole_cmdline);
SetWindowDirty(w);
break;
case WKC_BACKSPACE: case WKC_DELETE:
if (DeleteTextBufferChar(&_iconsole_cmdline, e->keypress.keycode)) {
IConsoleResetHistoryPos();
@@ -224,7 +214,7 @@ void IConsoleInit(void)
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
_iconsole_cmdline.maxlength = ICON_CMDLN_SIZE;
_iconsole_cmdline.maxlength = ICON_CMDLN_SIZE - 1;
IConsolePrintF(13, "OpenTTD Game Console Revision 7 - %s", _openttd_revision);
IConsolePrint(12, "------------------------------------");
@@ -326,7 +316,7 @@ void IConsoleOpen(void) {if (_iconsole_mode == ICONSOLE_CLOSED) IConsoleSwitch(
* scroll, etc. Put it to the beginning as it is the latest text
* @param cmd Text to be entered into the 'history'
*/
static void IConsoleHistoryAdd(const char* cmd)
void IConsoleHistoryAdd(const char *cmd)
{
free(_iconsole_history[ICON_HISTORY_SIZE - 1]);
@@ -339,7 +329,7 @@ static void IConsoleHistoryAdd(const char* cmd)
* Navigate Up/Down in the history of typed commands
* @param direction Go further back in history (+1), go to recently typed commands (-1)
*/
static void IConsoleHistoryNavigate(int direction)
void IConsoleHistoryNavigate(signed char direction)
{
int i = _iconsole_historypos + direction;
@@ -479,7 +469,7 @@ bool GetArgumentInteger(uint32 *value, const char *arg)
}
*value = strtoul(arg, &endptr, 0);
return arg != endptr;
return (arg == endptr) ? false : true;
}
// * ************************* * //
@@ -505,7 +495,7 @@ static void IConsoleHookAdd(IConsoleHooks *hooks, IConsoleHookTypes type, IConso
case ICONSOLE_HOOK_POST_ACTION:
hooks->post = proc;
break;
default: NOT_REACHED();
default: NOT_REACHED();
}
}
@@ -532,7 +522,7 @@ static bool IConsoleHookHandle(const IConsoleHooks *hooks, IConsoleHookTypes typ
case ICONSOLE_HOOK_POST_ACTION:
proc = hooks->post;
break;
default: NOT_REACHED();
default: NOT_REACHED();
}
return (proc == NULL) ? true : proc();
@@ -691,7 +681,7 @@ static inline int IConsoleCopyInParams(char *dst, const char *src, uint bufpos)
* @param tokencount the number of parameters passed
* @param *tokens are the parameters given to the original command (0 is the first param)
*/
static void IConsoleAliasExec(const IConsoleAlias* alias, byte tokencount, char* tokens[ICON_TOKEN_COUNT])
void IConsoleAliasExec(const IConsoleAlias *alias, byte tokencount, char *tokens[ICON_TOKEN_COUNT])
{
const char *cmdptr;
char *aliases[ICON_MAX_ALIAS_LINES], aliasstream[ICON_MAX_STREAMSIZE];
@@ -701,9 +691,6 @@ static void IConsoleAliasExec(const IConsoleAlias* alias, byte tokencount, char*
memset(&aliases, 0, sizeof(aliases));
memset(&aliasstream, 0, sizeof(aliasstream));
if (_stdlib_con_developer)
IConsolePrintF(_icolour_dbg, "condbg: requested command is an alias; parsing...");
aliases[0] = aliasstream;
for (cmdptr = alias->cmdline, a_index = 0, astream_i = 0; *cmdptr != '\0'; cmdptr++) {
if (a_index >= lengthof(aliases) || astream_i >= lengthof(aliasstream)) break;
@@ -833,7 +820,7 @@ static void IConsoleVarSetValue(const IConsoleVar *var, uint32 value)
*(byte*)var->addr = (byte)value;
break;
case ICONSOLE_VAR_UINT16:
*(uint16*)var->addr = (uint16)value;
*(uint16*)var->addr = (byte)value;
break;
case ICONSOLE_VAR_INT16:
*(int16*)var->addr = (int16)value;
@@ -931,7 +918,6 @@ static char *IConsoleVarGetStringValue(const IConsoleVar *var)
break;
case ICONSOLE_VAR_STRING:
value = (char*)var->addr;
break;
default: NOT_REACHED();
}
@@ -978,9 +964,6 @@ void IConsoleVarExec(const IConsoleVar *var, byte tokencount, char *token[ICON_T
byte t_index = tokencount;
uint32 value;
if (_stdlib_con_developer)
IConsolePrintF(_icolour_dbg, "condbg: requested command is a variable");
if (tokencount == 0) { /* Just print out value */
IConsoleVarPrintGetValue(var);
return;
@@ -993,6 +976,7 @@ void IConsoleVarExec(const IConsoleVar *var, byte tokencount, char *token[ICON_T
/* Some variables need really special handling, handle it in their callback procedure */
if (var->proc != NULL) {
var->proc(tokencount, &token[t_index - tokencount]); // set the new value
var->proc(0, NULL); // print out new value
return;
}
/* Strings need special processing. No need to convert the argument to
@@ -1051,8 +1035,6 @@ void IConsoleCmdExec(const char *cmdstr)
bool longtoken = false;
bool foundtoken = false;
if (cmdstr[0] == '#') return; // comments
for (cmdptr = cmdstr; *cmdptr != '\0'; cmdptr++) {
if (!IsValidAsciiChar(*cmdptr)) {
IConsoleError("command contains malformed characters, aborting");

View File

@@ -1,5 +1,3 @@
/* $Id$ */
#ifndef CONSOLE_H
#define CONSOLE_H
@@ -123,6 +121,10 @@ void IConsoleSwitch(void);
void IConsoleClose(void);
void IConsoleOpen(void);
// ** console cmd buffer ** //
void IConsoleHistoryAdd(const char *cmd);
void IConsoleHistoryNavigate(signed char direction);
// ** console output ** //
void IConsolePrint(uint16 color_code, const char *string);
void CDECL IConsolePrintF(uint16 color_code, const char *s, ...);
@@ -146,6 +148,7 @@ void IConsoleVarPrintSetValue(const IConsoleVar *var);
// *** Parser *** //
void IConsoleCmdExec(const char *cmdstr);
void IConsoleVarExec(const IConsoleVar *var, byte tokencount, char *token[]);
void IConsoleAliasExec(const IConsoleAlias *alias, byte tokencount, char *tokens[]);
// ** console std lib (register ingame commands/aliases/variables) ** //
void IConsoleStdLibRegister(void);

View File

@@ -1,12 +1,9 @@
/* $Id$ */
#include "stdafx.h"
#include "openttd.h"
#include "ttd.h"
#include "console.h"
#include "debug.h"
#include "engine.h"
#include "functions.h"
#include "saveload.h"
#include "string.h"
#include "variables.h"
#include "network_data.h"
@@ -16,7 +13,6 @@
#include "command.h"
#include "settings.h"
#include "hal.h" /* for file list */
#include "vehicle.h"
// ** scriptfile handling ** //
static FILE *_script_file;
@@ -121,28 +117,6 @@ DEF_CONSOLE_CMD(ConResetTile)
return false;
}
DEF_CONSOLE_CMD(ConStopAllVehicles)
{
Vehicle* v;
if (argc == 0) {
IConsoleHelp("Stops all vehicles in the game. For debugging only! Use at your own risk... Usage: 'stopall'");
return true;
}
FOR_ALL_VEHICLES(v) {
if (IsValidVehicle(v)) {
/* Code ripped from CmdStartStopTrain. Can't call it, because of
* ownership problems, so we'll duplicate some code, for now */
if (v->type == VEH_Train)
v->u.rail.days_since_order_progr = 0;
v->vehstatus |= VS_STOPPED;
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
}
}
return true;
}
#endif /* _DEBUG */
DEF_CONSOLE_CMD(ConScrollToTile)
@@ -201,7 +175,6 @@ static const FiosItem* GetFiosItem(const char* file)
for (i = 0; i < _fios_num; i++) {
if (strcmp(file, _fios_list[i].name) == 0) break;
if (strcmp(file, _fios_list[i].title) == 0) break;
}
if (i == _fios_num) { /* If no name matches, try to parse it as number */
@@ -221,7 +194,7 @@ DEF_CONSOLE_CMD(ConLoad)
const char *file;
if (argc == 0) {
IConsoleHelp("Load a game by name or index. Usage: 'load <file | number>'");
IConsoleHelp("Load a game by name or index. Usage: 'load <file \\ number>'");
return true;
}
@@ -231,13 +204,11 @@ DEF_CONSOLE_CMD(ConLoad)
item = GetFiosItem(file);
if (item != NULL) {
switch (item->type) {
case FIOS_TYPE_FILE: case FIOS_TYPE_OLDFILE: {
case FIOS_TYPE_FILE: case FIOS_TYPE_OLDFILE:
_switch_mode = SM_LOAD;
SetFiosType(item->type);
ttd_strlcpy(_file_to_saveload.name, FiosBrowseTo(item), sizeof(_file_to_saveload.name));
ttd_strlcpy(_file_to_saveload.title, item->title, sizeof(_file_to_saveload.title));
} break;
strcpy(_file_to_saveload.name, FiosBrowseTo(item));
break;
default: IConsolePrintF(_icolour_err, "%s: Not a savegame.", file);
}
} else
@@ -247,39 +218,13 @@ DEF_CONSOLE_CMD(ConLoad)
return true;
}
DEF_CONSOLE_CMD(ConRemove)
{
const FiosItem* item;
const char* file;
if (argc == 0) {
IConsoleHelp("Remove a savegame by name or index. Usage: 'rm <file | number>'");
return true;
}
if (argc != 2) return false;
file = argv[1];
item = GetFiosItem(file);
if (item != NULL) {
if (!FiosDelete(item->name))
IConsolePrintF(_icolour_err, "%s: Failed to delete file", file);
} else
IConsolePrintF(_icolour_err, "%s: No such file or directory.", file);
FiosFreeSavegameList();
return true;
}
/* List all the files in the current dir via console */
DEF_CONSOLE_CMD(ConListFiles)
{
int i;
if (argc == 0) {
IConsoleHelp("List all loadable savegames and directories in the current dir via console. Usage: 'ls | dir'");
IConsoleHelp("List all loadable savegames and directories in the current dir via console. Usage: 'ls \\ dir'");
return true;
}
@@ -287,7 +232,7 @@ DEF_CONSOLE_CMD(ConListFiles)
for (i = 0; i < _fios_num; i++) {
const FiosItem *item = &_fios_list[i];
IConsolePrintF(_icolour_def, "%d) %s", i, item->title);
IConsolePrintF(_icolour_def, "%d) %s", i, (item->title[0] != '\0') ? item->title : item->name);
}
FiosFreeSavegameList();
@@ -301,7 +246,7 @@ DEF_CONSOLE_CMD(ConChangeDirectory)
const char *file;
if (argc == 0) {
IConsoleHelp("Change the dir via console. Usage: 'cd <directory | number>'");
IConsoleHelp("Change the dir via console. Usage: 'cd <directory \\ number>'");
return true;
}
@@ -362,80 +307,63 @@ DEF_CONSOLE_CMD(ConClearBuffer)
DEF_CONSOLE_CMD(ConBan)
{
NetworkClientInfo *ci;
const char *banip = NULL;
uint32 index;
if (argc == 0) {
IConsoleHelp("Ban a player from a network game. Usage: 'ban <ip | client-id>'");
IConsoleHelp("Ban a player from a network game. Usage: 'ban <client-id>'");
IConsoleHelp("For client-id's, see the command 'clients'");
IConsoleHelp("If the client is no longer online, you can still ban his/her IP");
return true;
}
if (argc != 2) return false;
if (strchr(argv[1], '.') == NULL) { // banning with ID
index = atoi(argv[1]);
ci = NetworkFindClientInfoFromIndex(index);
} else { // banning IP
ci = NetworkFindClientInfoFromIP(argv[1]);
if (ci == NULL) {
banip = argv[1];
index = (uint32)-1;
} else {
index = ci->client_index;
}
}
index = atoi(argv[1]);
if (index == NETWORK_SERVER_INDEX) {
IConsoleError("Silly boy, you can not ban yourself!");
IConsolePrint(_icolour_def, "Silly boy, you can not ban yourself!");
return true;
}
if (index == 0) {
IConsoleError("Invalid Client-ID");
return true;
}
if (index == 0 || (ci == NULL && index != (uint32)-1)) {
IConsoleError("Invalid client");
return true;
}
ci = NetworkFindClientInfoFromIndex(index);
if (ci != NULL) {
banip = inet_ntoa(*(struct in_addr *)&ci->client_ip);
SEND_COMMAND(PACKET_SERVER_ERROR)(NetworkFindClientStateFromIndex(index), NETWORK_ERROR_KICKED);
IConsolePrint(_icolour_def, "Client banned");
} else
IConsolePrint(_icolour_def, "Client not online, banned IP");
/* Add user to ban-list */
for (index = 0; index < lengthof(_network_ban_list); index++) {
if (_network_ban_list[index] == NULL) {
_network_ban_list[index] = strdup(banip);
break;
uint i;
/* Add user to ban-list */
for (i = 0; i < lengthof(_network_ban_list); i++) {
if (_network_ban_list[i] == NULL || _network_ban_list[i][0] == '\0') {
_network_ban_list[i] = strdup(inet_ntoa(*(struct in_addr *)&ci->client_ip));
break;
}
}
}
SEND_COMMAND(PACKET_SERVER_ERROR)(NetworkFindClientStateFromIndex(index), NETWORK_ERROR_KICKED);
} else
IConsoleError("Client-ID not found");
return true;
}
DEF_CONSOLE_CMD(ConUnBan)
{
uint i, index;
uint i;
if (argc == 0) {
IConsoleHelp("Unban a player from a network game. Usage: 'unban <ip | client-id>'");
IConsoleHelp("For a list of banned IP's, see the command 'banlist'");
IConsoleHelp("Unban a player from a network game. Usage: 'unban <ip>'");
return true;
}
if (argc != 2) return false;
index = (strchr(argv[1], '.') == NULL) ? atoi(argv[1]) : 0;
index--;
for (i = 0; i < lengthof(_network_ban_list); i++) {
if (_network_ban_list[i] == NULL) continue;
if (_network_ban_list[i] == NULL || _network_ban_list[i][0] == '\0')
continue;
if (strcmp(_network_ban_list[i], argv[1]) == 0 || index == i) {
free(_network_ban_list[i]);
_network_ban_list[i] = NULL;
if (strncmp(_network_ban_list[i], argv[1], strlen(_network_ban_list[i])) == 0) {
_network_ban_list[i][0] = '\0';
IConsolePrint(_icolour_def, "IP unbanned.");
return true;
}
@@ -457,8 +385,10 @@ DEF_CONSOLE_CMD(ConBanList)
IConsolePrint(_icolour_def, "Banlist: ");
for (i = 0; i < lengthof(_network_ban_list); i++) {
if (_network_ban_list[i] != NULL)
IConsolePrintF(_icolour_def, " %d) %s", i + 1, _network_ban_list[i]);
if (_network_ban_list[i] == NULL || _network_ban_list[i][0] == '\0')
continue;
IConsolePrintF(_icolour_def, " %d) %s", i + 1, _network_ban_list[i]);
}
return true;
@@ -517,7 +447,7 @@ DEF_CONSOLE_CMD(ConStatus)
const NetworkClientState *cs;
if (argc == 0) {
IConsoleHelp("List the status of all clients connected to the server. Usage 'status'");
IConsoleHelp("List the status of all clients connected to the server: Usage 'status'");
return true;
}
@@ -526,56 +456,8 @@ DEF_CONSOLE_CMD(ConStatus)
const NetworkClientInfo *ci = DEREF_CLIENT_INFO(cs);
status = (cs->status <= STATUS_ACTIVE) ? 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, GetPlayerIP(ci), ci->unique_id);
}
return true;
}
DEF_CONSOLE_CMD(ConServerInfo)
{
const NetworkGameInfo *gi;
if (argc == 0) {
IConsoleHelp("List current and maximum client/player limits. Usage 'server_info'");
IConsoleHelp("You can change these values by setting the variables 'max_clients', 'max_companies' and 'max_spectators'");
return true;
}
gi = &_network_game_info;
IConsolePrintF(_icolour_def, "Current/maximum clients: %2d/%2d", gi->clients_on, gi->clients_max);
IConsolePrintF(_icolour_def, "Current/maximum companies: %2d/%2d", ActivePlayerCount(), gi->companies_max);
IConsolePrintF(_icolour_def, "Current/maximum spectators: %2d/%2d", NetworkSpectatorCount(), gi->spectators_max);
return true;
}
DEF_CONSOLE_HOOK(ConHookValidateMaxClientsCount) {
/* XXX - hardcoded, string limiation -- TrueLight
* XXX - also see network.c:NetworkStartup ~1356 */
if (_network_game_info.clients_max > 10) {
_network_game_info.clients_max = 10;
IConsoleError("Maximum clients out of bounds, truncating to limit.");
}
return true;
}
DEF_CONSOLE_HOOK(ConHookValidateMaxCompaniesCount) {
if (_network_game_info.companies_max > MAX_PLAYERS) {
_network_game_info.companies_max = MAX_PLAYERS;
IConsoleError("Maximum companies out of bounds, truncating to limit.");
}
return true;
}
DEF_CONSOLE_HOOK(ConHookValidateMaxSpectatorsCount) {
/* XXX @see ConHookValidateMaxClientsCount */
if (_network_game_info.spectators_max > 10) {
_network_game_info.spectators_max = 10;
IConsoleError("Maximum spectators out of bounds, truncating to limit.");
IConsolePrintF(8, "Client #%d/%s status: %s frame-lag: %d play-as: %d unique-id: %s",
cs->index, ci->client_name, status, lag, ci->client_playas, ci->unique_id);
}
return true;
@@ -587,35 +469,29 @@ DEF_CONSOLE_CMD(ConKick)
uint32 index;
if (argc == 0) {
IConsoleHelp("Kick a player from a network game. Usage: 'kick <ip | client-id>'");
IConsoleHelp("Kick a player from a network game. Usage: 'kick <client-id>'");
IConsoleHelp("For client-id's, see the command 'clients'");
return true;
}
if (argc != 2) return false;
if (strchr(argv[1], '.') == NULL) {
index = atoi(argv[1]);
ci = NetworkFindClientInfoFromIndex(index);
} else {
ci = NetworkFindClientInfoFromIP(argv[1]);
index = (ci == NULL) ? 0 : ci->client_index;
}
index = atoi(argv[1]);
if (index == NETWORK_SERVER_INDEX) {
IConsoleError("Silly boy, you can not kick yourself!");
IConsolePrint(_icolour_def, "Silly boy, you can not kick yourself!");
return true;
}
if (index == 0) {
IConsoleError("Invalid client-id");
return true;
}
if (index == 0) {
IConsoleError("Invalid client");
return true;
}
ci = NetworkFindClientInfoFromIndex(index);
if (ci != NULL) {
SEND_COMMAND(PACKET_SERVER_ERROR)(NetworkFindClientStateFromIndex(index), NETWORK_ERROR_KICKED);
} else
IConsoleError("Client not found");
IConsoleError("Client-id not found");
return true;
}
@@ -645,7 +521,7 @@ DEF_CONSOLE_CMD(ConResetCompany)
/* Check if company does exist */
index--;
p = GetPlayer(index);
p = DEREF_PLAYER(index);
if (!p->is_active) {
IConsoleError("Company does not exist.");
return true;
@@ -682,14 +558,13 @@ DEF_CONSOLE_CMD(ConNetworkClients)
NetworkClientInfo *ci;
if (argc == 0) {
IConsoleHelp("Get a list of connected clients including their ID, name, company-id, and IP. Usage: 'clients'");
IConsoleHelp("Get a list of connected clients including their ID, name, and company-id. Usage: 'clients'");
return true;
}
for (ci = _network_client_info; ci != &_network_client_info[MAX_CLIENT_INFO]; ci++) {
if (ci->client_index != NETWORK_EMPTY_INDEX) {
IConsolePrintF(8, "Client #%1d name: '%s' company: %1d IP: %s",
ci->client_index, ci->client_name, ci->client_playas, GetPlayerIP(ci));
IConsolePrintF(8, "Client #%d name: %s play-as company: %d", ci->client_index, ci->client_name, ci->client_playas);
}
}
@@ -809,7 +684,7 @@ DEF_CONSOLE_CMD(ConScript)
if (!CloseConsoleLogIfActive()) {
if (argc < 2) return false;
IConsolePrintF(_icolour_def, "file output started to: %s", argv[1]);
IConsolePrintF(_icolour_def, "file output started to: %s", argv[1]);
_iconsole_output_file = fopen(argv[1], "ab");
if (_iconsole_output_file == NULL) IConsoleError("could not open file");
}
@@ -880,22 +755,22 @@ DEF_CONSOLE_CMD(ConAlias)
DEF_CONSOLE_CMD(ConScreenShot)
{
if (argc == 0) {
IConsoleHelp("Create a screenshot of the game. Usage: 'screenshot [big | no_con]'");
IConsoleHelp("Create a screenshot of the game. Usage: 'screenshot [big\\no_con]'");
IConsoleHelp("'big' makes a screenshot of the whole map, 'no_con' hides the console to create the screenshot");
return true;
}
if (argc > 3) return false;
_make_screenshot = 1;
if (argc > 1) {
if (strcmp(argv[1], "big") == 0 || (argc == 3 && strcmp(argv[2], "big") == 0))
if (argc < 2) {
_make_screenshot = 1;
} else {
if (strcmp(argv[1], "big") == 0)
_make_screenshot = 2;
if (strcmp(argv[1], "no_con") == 0 || (argc == 3 && strcmp(argv[2], "no_con") == 0))
if (strcmp(argv[1], "no_con") == 0) {
IConsoleClose();
_make_screenshot = 1;
}
}
return true;
}
@@ -1004,31 +879,31 @@ DEF_CONSOLE_CMD(ConHelp)
const IConsoleAlias *alias;
cmd = IConsoleCmdGet(argv[1]);
if (cmd != NULL) {
cmd->proc(0, NULL);
return true;
}
if (cmd != NULL) {
cmd->proc(0, NULL);
return true;
}
alias = IConsoleAliasGet(argv[1]);
if (alias != NULL) {
cmd = IConsoleCmdGet(alias->cmdline);
if (cmd != NULL) {
cmd->proc(0, NULL);
return true;
}
IConsolePrintF(_icolour_err, "ERROR: alias is of special type, please see its execution-line: '%s'", alias->cmdline);
return true;
}
alias = IConsoleAliasGet(argv[1]);
if (alias != NULL) {
cmd = IConsoleCmdGet(alias->cmdline);
if (cmd != NULL) {
cmd->proc(0, NULL);
return true;
}
IConsolePrintF(_icolour_err, "ERROR: alias is of special type, please see its execution-line: '%s'", alias->cmdline);
return true;
}
var = IConsoleVarGet(argv[1]);
if (var != NULL && var->help != NULL) {
IConsoleHelp(var->help);
return true;
}
var = IConsoleVarGet(argv[1]);
if (var != NULL && var->help != NULL) {
IConsoleHelp(var->help);
return true;
}
IConsoleError("command or variable not found");
return true;
}
IConsoleError("command or variable not found");
return true;
}
IConsolePrint(13, " ---- OpenTTD Console Help ---- ");
IConsolePrint( 1, " - variables: [command to list all variables: list_vars]");
@@ -1038,9 +913,9 @@ DEF_CONSOLE_CMD(ConHelp)
IConsolePrint( 1, " call commands with '<command> <arg2> <arg3>...'");
IConsolePrint( 1, " - to assign strings, or use them as arguments, enclose it within quotes");
IConsolePrint( 1, " like this: '<command> \"string argument with spaces\"'");
IConsolePrint( 1, " - use 'help <command> | <variable>' to get specific information");
IConsolePrint( 1, " - scroll console output with shift + (up | down) | (pageup | pagedown))");
IConsolePrint( 1, " - scroll console input history with the up | down arrows");
IConsolePrint( 1, " - use 'help <command>\\<variable>' to get specific information");
IConsolePrint( 1, " - scroll console output with shift + (up\\down)\\(pageup\\pagedown))");
IConsolePrint( 1, " - scroll console input history with the up\\down arrows");
IConsolePrint( 1, "");
return true;
}
@@ -1152,7 +1027,7 @@ DEF_CONSOLE_CMD(ConSayClient)
{
if (argc == 0) {
IConsoleHelp("Chat to a certain player in a multiplayer game. Usage: 'say_client <client-no> \"<msg>\"'");
IConsoleHelp("For client-id's, see the command 'clients'");
IConsoleHelp("For client-id's, see the command 'clients'");
return true;
}
@@ -1171,10 +1046,8 @@ DEF_CONSOLE_HOOK(ConHookServerPW)
if (strncmp(_network_server_password, "*", NETWORK_PASSWORD_LENGTH) == 0) {
_network_server_password[0] = '\0';
_network_game_info.use_password = 0;
} else {
ttd_strlcpy(_network_game_info.server_password, _network_server_password, sizeof(_network_server_password));
} else
_network_game_info.use_password = 1;
}
return true;
}
@@ -1213,8 +1086,6 @@ bool NetworkChangeCompanyPassword(byte argc, char *argv[])
if (!_network_server)
SEND_COMMAND(PACKET_CLIENT_SET_PASSWORD)(_network_player_info[_local_player].password);
IConsolePrintF(_icolour_warn, "'company_pw' changed to: %s", _network_player_info[_local_player].password);
return true;
}
@@ -1230,7 +1101,7 @@ DEF_CONSOLE_HOOK(ConProcPlayerName)
SEND_COMMAND(PACKET_CLIENT_SET_NAME)(_network_player_name);
} else {
if (NetworkFindName(_network_player_name)) {
NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, 1, false, ci->client_name, "%s", _network_player_name);
NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, 1, false, ci->client_name, _network_player_name);
ttd_strlcpy(ci->client_name, _network_player_name, sizeof(ci->client_name));
NetworkUpdateClientInfo(NETWORK_SERVER_INDEX);
}
@@ -1263,9 +1134,8 @@ DEF_CONSOLE_CMD(ConProcServerIP)
if (argc != 1) return false;
_network_server_bind_ip = (strcmp(argv[0], "all") == 0) ? inet_addr("0.0.0.0") : inet_addr(argv[0]);
_network_server_bind_ip = inet_addr(argv[0]);
snprintf(_network_server_bind_ip_host, sizeof(_network_server_bind_ip_host), "%s", inet_ntoa(*(struct in_addr *)&_network_server_bind_ip));
IConsolePrintF(_icolour_warn, "'server_ip' changed to: %s", inet_ntoa(*(struct in_addr *)&_network_server_bind_ip));
return true;
}
@@ -1321,7 +1191,6 @@ static void IConsoleDebugLibRegister(void)
IConsoleVarRegister("con_developer", &_stdlib_con_developer, ICONSOLE_VAR_BOOLEAN, "Enable/disable console debugging information (internal)");
IConsoleCmdRegister("resettile", ConResetTile);
IConsoleCmdRegister("stopall", ConStopAllVehicles);
IConsoleAliasRegister("dbg_echo", "echo %A; echo %B");
IConsoleAliasRegister("dbg_echo2", "echo %!");
}
@@ -1357,17 +1226,15 @@ void IConsoleStdLibRegister(void)
IConsoleCmdRegister("screenshot", ConScreenShot);
IConsoleCmdRegister("script", ConScript);
IConsoleCmdRegister("scrollto", ConScrollToTile);
IConsoleCmdRegister("alias", ConAlias);
IConsoleCmdRegister("load", ConLoad);
IConsoleCmdRegister("rm", ConRemove);
IConsoleCmdRegister("save", ConSave);
IConsoleCmdRegister("alias", ConAlias);
IConsoleCmdRegister("load", ConLoad);
IConsoleCmdRegister("save", ConSave);
IConsoleCmdRegister("ls", ConListFiles);
IConsoleCmdRegister("cd", ConChangeDirectory);
IConsoleCmdRegister("pwd", ConPrintWorkingDirectory);
IConsoleCmdRegister("clear", ConClearBuffer);
IConsoleAliasRegister("dir", "ls");
IConsoleAliasRegister("del", "rm %+");
IConsoleAliasRegister("newmap", "newgame");
IConsoleAliasRegister("new_map", "newgame");
IConsoleAliasRegister("new_game", "newgame");
@@ -1377,9 +1244,6 @@ void IConsoleStdLibRegister(void)
/* networking variables and functions */
#ifdef ENABLE_NETWORK
/* Network hooks; only active in network */
IConsoleCmdHookAdd ("resetengines", ICONSOLE_HOOK_ACCESS, ConHookNoNetwork);
/*** Networking commands ***/
IConsoleCmdRegister("say", ConSay);
IConsoleCmdHookAdd("say", ICONSOLE_HOOK_ACCESS, ConHookNeedNetwork);
@@ -1387,32 +1251,29 @@ void IConsoleStdLibRegister(void)
IConsoleCmdHookAdd("say_player", ICONSOLE_HOOK_ACCESS, ConHookNeedNetwork);
IConsoleCmdRegister("say_client", ConSayClient);
IConsoleCmdHookAdd("say_client", ICONSOLE_HOOK_ACCESS, ConHookNeedNetwork);
IConsoleCmdRegister("kick", ConKick);
IConsoleCmdHookAdd("kick", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
IConsoleCmdRegister("reset_company", ConResetCompany);
IConsoleCmdHookAdd("reset_company", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
IConsoleAliasRegister("clean_company", "reset_company %A");
IConsoleCmdRegister("connect", ConNetworkConnect);
IConsoleCmdHookAdd("connect", ICONSOLE_HOOK_ACCESS, ConHookClientOnly);
IConsoleAliasRegister("join", "connect %A");
IConsoleCmdHookAdd("connect", ICONSOLE_HOOK_ACCESS, ConHookClientOnly);
IConsoleCmdRegister("clients", ConNetworkClients);
IConsoleCmdHookAdd("clients", ICONSOLE_HOOK_ACCESS, ConHookNeedNetwork);
IConsoleCmdRegister("status", ConStatus);
IConsoleCmdHookAdd("status", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
IConsoleCmdRegister("server_info", ConServerInfo);
IConsoleCmdHookAdd("server_info", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
IConsoleAliasRegister("info", "server_info");
IConsoleCmdHookAdd("resetengines", ICONSOLE_HOOK_ACCESS, ConHookNoNetwork);
IConsoleCmdRegister("rcon", ConRcon);
IConsoleCmdHookAdd("rcon", ICONSOLE_HOOK_ACCESS, ConHookNeedNetwork);
IConsoleCmdRegister("reset_company", ConResetCompany);
IConsoleCmdHookAdd("reset_company", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
IConsoleAliasRegister("clean_company", "reset_company %A");
IConsoleCmdRegister("kick", ConKick);
IConsoleCmdHookAdd("kick", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
IConsoleCmdRegister("ban", ConBan);
IConsoleCmdHookAdd("ban", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
IConsoleCmdRegister("unban", ConUnBan);
IConsoleCmdHookAdd("unban", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
IConsoleCmdRegister("banlist", ConBanList);
IConsoleCmdHookAdd("banlist", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
IConsoleCmdRegister("pause", ConPauseGame);
IConsoleCmdHookAdd("pause", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
IConsoleCmdRegister("unpause", ConUnPauseGame);
@@ -1431,10 +1292,12 @@ void IConsoleStdLibRegister(void)
IConsoleVarHookAdd("server_pw", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
IConsoleVarHookAdd("server_pw", ICONSOLE_HOOK_POST_ACTION, ConHookServerPW);
IConsoleAliasRegister("server_password", "server_pw %+");
IConsoleVarStringRegister("rcon_pw", &_network_rcon_password, sizeof(_network_rcon_password), "Set the rcon-password to change server behaviour. Use '*' to disable rcon");
IConsoleVarHookAdd("rcon_pw", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
IConsoleVarHookAdd("rcon_pw", ICONSOLE_HOOK_POST_ACTION, ConHookRconPW);
IConsoleAliasRegister("rcon_password", "rcon_pw %+");
IConsoleVarStringRegister("company_pw", NULL, 0, "Set a password for your company, so no one without the correct password can join. Use '*' to clear the password");
IConsoleVarHookAdd("company_pw", ICONSOLE_HOOK_ACCESS, ConHookNeedNetwork);
IConsoleVarProcAdd("company_pw", NetworkChangeCompanyPassword);
@@ -1443,42 +1306,38 @@ void IConsoleStdLibRegister(void)
IConsoleVarStringRegister("name", &_network_player_name, sizeof(_network_player_name), "Set your name for multiplayer");
IConsoleVarHookAdd("name", ICONSOLE_HOOK_ACCESS, ConHookNeedNetwork);
IConsoleVarHookAdd("name", ICONSOLE_HOOK_POST_ACTION, ConProcPlayerName);
IConsoleVarStringRegister("server_name", &_network_server_name, sizeof(_network_server_name), "Set the name of the server for multiplayer");
IConsoleVarHookAdd("server_name", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
IConsoleVarHookAdd("server_name", ICONSOLE_HOOK_POST_ACTION, ConHookServerName);
IConsoleVarRegister("server_port", &_network_server_port, ICONSOLE_VAR_UINT32, "Set the server port. Changes take effect the next time you start a server");
IConsoleVarRegister("server_ip", &_network_server_bind_ip, ICONSOLE_VAR_UINT32, "Set the IP the server binds to. Changes take effect the next time you start a server. Use 'all' to bind to any IP.");
IConsoleVarRegister("server_ip", &_network_server_bind_ip, ICONSOLE_VAR_UINT32, "Set the IP the server binds to. Changes take effect the next time you start a server");
IConsoleVarProcAdd("server_ip", ConProcServerIP);
IConsoleAliasRegister("server_bind_ip", "server_ip %+");
IConsoleAliasRegister("server_ip_bind", "server_ip %+");
IConsoleAliasRegister("server_bind", "server_ip %+");
IConsoleVarRegister("max_join_time", &_network_max_join_time, ICONSOLE_VAR_UINT16, "Set the maximum amount of time (ticks) a client is allowed to join. Default value: 500");
IConsoleVarRegister("server_advertise", &_network_advertise, ICONSOLE_VAR_BOOLEAN, "Set if the server will advertise to the master server and show up there");
IConsoleVarHookAdd("server_advertise", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
IConsoleVarHookAdd("server_advertise", ICONSOLE_HOOK_POST_ACTION, ConHookServerAdvertise);
IConsoleVarRegister("max_clients", &_network_game_info.clients_max, ICONSOLE_VAR_BYTE, "Control the maximum amount of connected players during runtime. Default value: 10");
IConsoleVarHookAdd("max_clients", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
IConsoleVarHookAdd("max_clients", ICONSOLE_HOOK_POST_ACTION, ConHookValidateMaxClientsCount);
IConsoleVarRegister("max_companies", &_network_game_info.companies_max, ICONSOLE_VAR_BYTE, "Control the maximum amount of active companies during runtime. Default value: 8");
IConsoleVarHookAdd("max_companies", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
IConsoleVarHookAdd("max_companies", ICONSOLE_HOOK_POST_ACTION, ConHookValidateMaxCompaniesCount);
IConsoleVarRegister("max_spectators", &_network_game_info.spectators_max, ICONSOLE_VAR_BYTE, "Control the maximum amount of active spectators during runtime. Default value: 9");
IConsoleVarHookAdd("max_spectators", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
IConsoleVarHookAdd("max_spectators", ICONSOLE_HOOK_POST_ACTION, ConHookValidateMaxSpectatorsCount);
IConsoleVarRegister("max_join_time", &_network_max_join_time, ICONSOLE_VAR_UINT16, "Set the maximum amount of time (ticks) a client is allowed to join. Default value: 500");
IConsoleVarRegister("pause_on_join", &_network_pause_on_join, ICONSOLE_VAR_BOOLEAN, "Set if the server should pause gameplay while a client is joining. This might help slow users");
IConsoleVarHookAdd("pause_on_join", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
IConsoleVarRegister("autoclean_companies", &_network_autoclean_companies, ICONSOLE_VAR_BOOLEAN, "Automatically shut down inactive companies to free them up for other players. Customize with 'autoclean_(un)protected'");
IConsoleVarHookAdd("autoclean_companies", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
IConsoleVarRegister("autoclean_protected", &_network_autoclean_protected, ICONSOLE_VAR_BYTE, "Automatically remove the password from an inactive company after the given amount of months");
IConsoleVarHookAdd("autoclean_protected", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
IConsoleVarRegister("autoclean_unprotected", &_network_autoclean_unprotected, ICONSOLE_VAR_BYTE, "Automatically shut down inactive companies after the given amount of months");
IConsoleVarRegister("autoclean_unprotected", &_network_autoclean_protected, ICONSOLE_VAR_BYTE, "Automatically shut down inactive companies after the given amount of months");
IConsoleVarHookAdd("autoclean_unprotected", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
IConsoleVarRegister("restart_game_date", &_network_restart_game_date, ICONSOLE_VAR_UINT16, "Auto-restart the server when Jan 1st of the set year is reached. Use '0' to disable this");
IConsoleVarRegister("restart_game_date", &_network_restart_game_date, ICONSOLE_VAR_BYTE, "Auto-restart the server when Jan 1st of the set year is reached. Use '0' to disable this");
IConsoleVarHookAdd("restart_game_date", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
#endif /* ENABLE_NETWORK */

View File

@@ -1,100 +0,0 @@
/* $Id$ */
#include "stdafx.h"
#include "openttd.h"
#include "currency.h"
#include "news.h"
#include "variables.h"
#include "table/strings.h"
// exchange rate prefix
// | separator | postfix
// | | Euro year | |
// | | | | |
CurrencySpec _currency_specs[] = {
{ 1, ',', CF_NOEURO, "\xA3", "" }, // british pounds
{ 2, ',', CF_NOEURO, "$", "" }, // us dollars
{ 2, ',', CF_ISEURO, "<EFBFBD>", "" }, // Euro
{ 200, ',', CF_NOEURO, "\xA5", "" }, // yen
{ 19, ',', 2002, "", " S." }, // austrian schilling
{ 57, ',', 2002, "BEF ", "" }, // belgian franc
{ 2, ',', CF_NOEURO, "CHF ", "" }, // swiss franc
{ 50, ',', CF_NOEURO, "", " Kc" }, // czech koruna // TODO: Should use the "c" with an upside down "^"
{ 4, '.', 2002, "DM ", "" }, // deutsche mark
{ 10, '.', CF_NOEURO, "", " kr" }, // danish krone
{ 200, '.', 2002, "Pts ", "" }, // spanish pesetas
{ 8, ',', 2002, "", " mk" }, // finnish markka
{ 10, '.', 2002, "FF ", "" }, // french francs
{ 480, ',', 2002, "", "Dr." }, // greek drachma
{ 376, ',', 2002, "", " Ft" }, // hungarian forint
{ 130, '.', CF_NOEURO, "", " Kr" }, // icelandic krona
{ 2730, ',', 2002, "", " L." }, // italian lira
{ 3, ',', 2002, "NLG ", "" }, // dutch gulden
{ 11, '.', CF_NOEURO, "", " Kr" }, // norwegian krone
{ 6, ' ', CF_NOEURO, "", " zl" }, // polish zloty
{ 6, '.', CF_NOEURO, "", " Lei" }, // romanian Lei
{ 5, ' ', CF_NOEURO, "", " p" }, // russian rouble
{ 13, '.', CF_NOEURO, "", " Kr" }, // swedish krona
{ 1, ' ', CF_NOEURO, "", "" }, // custom currency
};
const StringID _currency_string_list[] = {
STR_CURR_GBP,
STR_CURR_USD,
STR_CURR_EUR,
STR_CURR_YEN,
STR_CURR_ATS,
STR_CURR_BEF,
STR_CURR_CHF,
STR_CURR_CZK,
STR_CURR_DEM,
STR_CURR_DKK,
STR_CURR_ESP,
STR_CURR_FIM,
STR_CURR_FRF,
STR_CURR_GRD,
STR_CURR_HUF,
STR_CURR_ISK,
STR_CURR_ITL,
STR_CURR_NLG,
STR_CURR_NOK,
STR_CURR_PLN,
STR_CURR_ROL,
STR_CURR_RUR,
STR_CURR_SEK,
STR_CURR_CUSTOM,
INVALID_STRING_ID
};
// NOTE: Make sure both lists are in the same order
// + 1 string list terminator
assert_compile(lengthof(_currency_specs) + 1 == lengthof(_currency_string_list));
// get a mask of the allowed currencies depending on the year
uint GetMaskOfAllowedCurrencies(void)
{
uint mask = 0;
uint i;
for (i = 0; i != lengthof(_currency_specs); i++) {
uint16 to_euro = _currency_specs[i].to_euro;
if (to_euro != CF_NOEURO && to_euro != CF_ISEURO && _cur_year >= to_euro - MAX_YEAR_BEGIN_REAL) continue;
if (to_euro == CF_ISEURO && _cur_year < 2000 - MAX_YEAR_BEGIN_REAL) continue;
mask |= (1 << i);
}
mask |= (1 << 23); // always allow custom currency
return mask;
}
void CheckSwitchToEuro(void)
{
if (_currency_specs[_opt.currency].to_euro != CF_NOEURO &&
_currency_specs[_opt.currency].to_euro != CF_ISEURO &&
MAX_YEAR_BEGIN_REAL + _cur_year >= _currency_specs[_opt.currency].to_euro) {
_opt.currency = 2; // this is the index of euro above.
AddNewsItem(STR_EURO_INTRODUCE, NEWS_FLAGS(NM_NORMAL, 0, NT_ECONOMY, 0), 0, 0);
}
}

View File

@@ -1,29 +0,0 @@
/* $Id$ */
#ifndef CURRENCY_H
#define CURRENCY_H
enum {
CF_NOEURO = 0,
CF_ISEURO = 1,
};
typedef struct {
uint16 rate;
char separator;
uint16 to_euro;
char prefix[16];
char suffix[16];
} CurrencySpec;
extern CurrencySpec _currency_specs[];
extern const StringID _currency_string_list[];
// XXX small hack, but makes the rest of the code a bit nicer to read
#define _custom_currency (_currency_specs[23])
#define _currency ((const CurrencySpec*)&_currency_specs[_opt_ptr->currency])
uint GetMaskOfAllowedCurrencies(void);
void CheckSwitchToEuro(void);
#endif /* CURRENCY_H */

Binary file not shown.

Binary file not shown.

BIN
data/signalsw.grf Normal file

Binary file not shown.

18
debug.c
View File

@@ -1,16 +1,12 @@
/* $Id$ */
#include "stdafx.h"
#include <stdio.h>
#include <stdarg.h>
#include "openttd.h"
#include "ttd.h"
#include "console.h"
#include "debug.h"
#include "functions.h"
#include "string.h"
int _debug_ai_level;
int _debug_driver_level;
int _debug_grf_level;
int _debug_map_level;
int _debug_misc_level;
@@ -18,7 +14,6 @@ int _debug_ms_level;
int _debug_net_level;
int _debug_spritecache_level;
int _debug_oldloader_level;
int _debug_ntp_level;
int _debug_npf_level;
@@ -42,7 +37,6 @@ typedef struct DebugLevel {
#define DEBUG_LEVEL(x) { #x, &_debug_##x##_level }
static const DebugLevel debug_level[] = {
DEBUG_LEVEL(ai),
DEBUG_LEVEL(driver),
DEBUG_LEVEL(grf),
DEBUG_LEVEL(map),
DEBUG_LEVEL(misc),
@@ -50,7 +44,6 @@ typedef struct DebugLevel {
DEBUG_LEVEL(net),
DEBUG_LEVEL(spritecache),
DEBUG_LEVEL(oldloader),
DEBUG_LEVEL(ntp),
DEBUG_LEVEL(npf)
};
#undef DEBUG_LEVEL
@@ -68,11 +61,12 @@ void SetDebugString(const char *s)
v = strtoul(s, &end, 0);
s = end;
for (i = debug_level; i != endof(debug_level); ++i) *i->level = v;
for (i = debug_level; i != endof(debug_level); ++i)
*i->level = v;
}
// individual levels
for (;;) {
for(;;) {
const DebugLevel *i;
int *p;
@@ -94,9 +88,9 @@ void SetDebugString(const char *s)
if (*s == '=') s++;
v = strtoul(s, &end, 0);
s = end;
if (p != NULL) {
if (p != NULL)
*p = v;
} else {
else {
ShowInfoF("Unknown debug level '%.*s'", s - t, t);
return;
}

View File

@@ -1,5 +1,3 @@
/* $Id$ */
#ifndef DEBUG_H
#define DEBUG_H
@@ -9,7 +7,6 @@
#define DEBUG(name, level) if (level == 0 || _debug_ ## name ## _level >= level) debug
extern int _debug_ai_level;
extern int _debug_driver_level;
extern int _debug_grf_level;
extern int _debug_map_level;
extern int _debug_misc_level;
@@ -17,7 +14,6 @@
extern int _debug_net_level;
extern int _debug_spritecache_level;
extern int _debug_oldloader_level;
extern int _debug_ntp_level;
extern int _debug_npf_level;
#endif
@@ -26,4 +22,4 @@ void CDECL debug(const char *s, ...);
void SetDebugString(const char *s);
const char *GetDebugString(void);
#endif /* DEBUG_H */
#endif

View File

@@ -1,17 +1,54 @@
/* $Id$ */
#include "stdafx.h"
#include "ttd.h"
#include "debug.h"
#include "network.h"
#include "hal.h"
#ifdef ENABLE_NETWORK
#if defined(UNIX) && !defined(__MORPHOS__)
#include "gfx.h"
#include "window.h"
#include "command.h"
#include "console.h"
#ifdef WIN32
# include <windows.h> /* GetTickCount */
# include <conio.h>
#endif
#include "openttd.h"
#include "variables.h"
#ifdef __OS2__
# include <sys/time.h> /* gettimeofday */
# include <sys/types.h>
# include <unistd.h>
# include <conio.h>
# define STDIN 0 /* file descriptor for standard input */
#include <sys/types.h>
#include <unistd.h>
extern void OS2_SwitchToConsoleMode();
#endif
#ifdef UNIX
# include <sys/time.h> /* gettimeofday */
# include <sys/types.h>
# include <unistd.h>
# include <signal.h>
# define STDIN 0 /* file descriptor for standard input */
#endif
#ifdef __MORPHOS__
/* Voids the fork, option will be disabled for MorphOS build anyway, because
* MorphOS doesn't support forking (could only implemented with lots of code
* changes here). */
int fork(void) { return -1; }
int dup2(int oldd, int newd) { return -1; }
#endif
// This file handles all dedicated-server in- and outputs
static void *_dedicated_video_mem;
extern bool SafeSaveOrLoad(const char *filename, int mode, int newgm);
extern void SwitchMode(int new_mode);
#ifdef UNIX
/* We want to fork our dedicated server */
void DedicatedFork(void)
{
/* Fork the program */
@@ -20,28 +57,25 @@ void DedicatedFork(void)
case -1:
perror("Unable to fork");
exit(1);
case 0: { // We're the child
FILE* f;
case 0:
// We're the child
/* Open the log-file to log all stuff too */
f = fopen(_log_file, "a");
if (f == NULL) {
_log_file_fd = fopen(_log_file, "a");
if (!_log_file_fd) {
perror("Unable to open logfile");
exit(1);
}
/* Redirect stdout and stderr to log-file */
if (dup2(fileno(f), fileno(stdout)) == -1) {
if (dup2(fileno(_log_file_fd), fileno(stdout)) == -1) {
perror("Rerouting stdout");
exit(1);
}
if (dup2(fileno(f), fileno(stderr)) == -1) {
if (dup2(fileno(_log_file_fd), fileno(stderr)) == -1) {
perror("Rerouting stderr");
exit(1);
}
break;
}
default:
// We're the parent
printf("Loading dedicated server...\n");
@@ -49,10 +83,274 @@ void DedicatedFork(void)
exit(0);
}
}
/* Signal handlers */
static void DedicatedSignalHandler(int sig)
{
_exit_game = true;
signal(sig, DedicatedSignalHandler);
}
#endif
#ifdef WIN32
#include <time.h>
HANDLE hEvent;
static HANDLE hThread; // Thread to close
static char _win_console_thread_buffer[200];
/* Windows Console thread. Just loop and signal when input has been received */
void WINAPI CheckForConsoleInput(void)
{
while (true) {
fgets(_win_console_thread_buffer, lengthof(_win_console_thread_buffer), stdin);
SetEvent(hEvent); // signal input waiting that the line is ready
}
}
void CreateWindowsConsoleThread(void)
{
static char tbuffer[9];
DWORD dwThreadId;
/* Create event to signal when console input is ready */
hEvent = CreateEvent(NULL, false, false, _strtime(tbuffer));
if (hEvent == NULL)
error("Cannot create console event!");
hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)CheckForConsoleInput, NULL, 0, &dwThreadId);
if (hThread == NULL)
error("Cannot create console thread!");
DEBUG(misc, 0) ("Windows console thread started...");
}
void CloseWindowsConsoleThread(void)
{
CloseHandle(hThread);
CloseHandle(hEvent);
DEBUG(misc, 0) ("Windows console thread shut down...");
}
#endif
static const char *DedicatedVideoStart(const char * const *parm)
{
_screen.width = _screen.pitch = _cur_resolution[0];
_screen.height = _cur_resolution[1];
_dedicated_video_mem = malloc(_cur_resolution[0]*_cur_resolution[1]);
_debug_net_level = 6;
_debug_misc_level = 0;
#ifdef WIN32
// For win32 we need to allocate an console (debug mode does the same)
CreateConsole();
CreateWindowsConsoleThread();
SetConsoleTitle("OpenTTD Dedicated Server");
#endif
#ifdef __OS2__
// For OS/2 we also need to switch to console mode instead of PM mode
OS2_SwitchToConsoleMode();
#endif
DEBUG(misc,0)("Loading dedicated server...");
return NULL;
}
static void DedicatedVideoStop(void)
{
#ifdef WIN32
CloseWindowsConsoleThread();
#endif
free(_dedicated_video_mem);
}
static void DedicatedVideoMakeDirty(int left, int top, int width, int height) {}
static bool DedicatedVideoChangeRes(int w, int h) { return false; }
static void DedicatedVideoFullScreen(bool fs) {}
#if defined(UNIX) || defined(__OS2__)
static bool InputWaiting(void)
{
struct timeval tv;
fd_set readfds;
byte ret;
tv.tv_sec = 0;
tv.tv_usec = 1;
FD_ZERO(&readfds);
FD_SET(STDIN, &readfds);
/* don't care about writefds and exceptfds: */
ret = select(STDIN + 1, &readfds, NULL, NULL, &tv);
if (ret > 0)
return true;
return false;
}
#else
static bool InputWaiting(void)
{
if (WaitForSingleObject(hEvent, 1) == WAIT_OBJECT_0)
return true;
return false;
}
#endif
static void DedicatedHandleKeyInput(void)
{
static char input_line[200] = "";
if (!InputWaiting())
return;
if (_exit_game)
return;
#if defined(UNIX) || defined(__OS2__)
fgets(input_line, lengthof(input_line), stdin);
#else
strncpy(input_line, _win_console_thread_buffer, lengthof(input_line));
#endif
/* XXX - strtok() does not 'forget' \n\r if it is the first character! */
strtok(input_line, "\r\n"); // Forget about the final \n (or \r)
{ /* Remove any special control characters */
uint i;
for (i = 0; i < lengthof(input_line); i++) {
if (input_line[i] == '\n' || input_line[i] == '\r') // cut missed beginning '\0'
input_line[i] = '\0';
if (input_line[i] == '\0')
break;
if (!IS_INT_INSIDE(input_line[i], ' ', 256))
input_line[i] = ' ';
}
}
IConsoleCmdExec(input_line); // execute command
}
static int DedicatedVideoMainLoop(void)
{
#ifndef WIN32
struct timeval tim;
#endif
uint32 next_tick;
uint32 cur_ticks;
#ifdef WIN32
next_tick = GetTickCount() + 30;
#else
gettimeofday(&tim, NULL);
next_tick = (tim.tv_usec / 1000) + 30 + (tim.tv_sec * 1000);
#endif
/* Signal handlers */
#ifdef UNIX
signal(SIGTERM, DedicatedSignalHandler);
signal(SIGINT, DedicatedSignalHandler);
signal(SIGQUIT, DedicatedSignalHandler);
#endif
// Load the dedicated server stuff
_is_network_server = true;
_network_dedicated = true;
_network_playas = OWNER_SPECTATOR;
_local_player = OWNER_SPECTATOR;
/* If SwitchMode is SM_LOAD, it means that the user used the '-g' options */
if (_switch_mode != SM_LOAD) {
_switch_mode = SM_NONE;
GenRandomNewGame(Random(), InteractiveRandom());
} else {
_switch_mode = SM_NONE;
/* First we need to test if the savegame can be loaded, else we will end up playing the
* intro game... */
if (!SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_NORMAL)) {
/* Loading failed, pop out.. */
DEBUG(net, 0)("Loading requested map failed. Aborting.");
_networking = false;
} else {
/* We can load this game, so go ahead */
SwitchMode(SM_LOAD);
}
}
// Done loading, start game!
if (!_networking) {
DEBUG(net, 1)("Dedicated server could not be launched. Aborting.");
return ML_QUIT;
}
while (true) {
InteractiveRandom(); // randomness
if (_exit_game) return ML_QUIT;
if (!_dedicated_forks)
DedicatedHandleKeyInput();
#ifdef WIN32
cur_ticks = GetTickCount();
#else
gettimeofday(&tim, NULL);
cur_ticks = (tim.tv_usec / 1000) + (tim.tv_sec * 1000);
#endif
if (cur_ticks >= next_tick) {
next_tick += 30;
GameLoop();
_screen.dst_ptr = _dedicated_video_mem;
UpdateWindows();
}
CSleep(1);
}
return ML_QUIT;
}
const HalVideoDriver _dedicated_video_driver = {
DedicatedVideoStart,
DedicatedVideoStop,
DedicatedVideoMakeDirty,
DedicatedVideoMainLoop,
DedicatedVideoChangeRes,
DedicatedVideoFullScreen,
};
#else
static void *_dedicated_video_mem;
static const char *DedicatedVideoStart(const char * const *parm)
{
DEBUG(misc, 0) ("OpenTTD compiled without network support, exiting.");
return NULL;
}
void DedicatedFork(void) {}
static void DedicatedVideoStop(void) { free(_dedicated_video_mem); }
static void DedicatedVideoMakeDirty(int left, int top, int width, int height) {}
static bool DedicatedVideoChangeRes(int w, int h) { return false; }
static void DedicatedVideoFullScreen(bool fs) {}
static int DedicatedVideoMainLoop(void) { return ML_QUIT; }
const HalVideoDriver _dedicated_video_driver = {
DedicatedVideoStart,
DedicatedVideoStop,
DedicatedVideoMakeDirty,
DedicatedVideoMainLoop,
DedicatedVideoChangeRes,
DedicatedVideoFullScreen,
};
#endif /* ENABLE_NETWORK */

11
depot.c
View File

@@ -1,9 +1,6 @@
/* $Id$ */
#include "stdafx.h"
#include "openttd.h"
#include "ttd.h"
#include "depot.h"
#include "functions.h"
#include "tile.h"
#include "map.h"
#include "table/strings.h"
@@ -36,7 +33,7 @@ MemoryPool _depot_pool = { "Depots", DEPOT_POOL_MAX_BLOCKS, DEPOT_POOL_BLOCK_SIZ
*
* @return Returns the depot if the tile had a depot, else it returns NULL
*/
Depot *GetDepotByTile(TileIndex tile)
Depot *GetDepotByTile(uint tile)
{
Depot *depot;
@@ -76,7 +73,7 @@ Depot *AllocateDepot(void)
/**
* Delete a depot
*/
void DoDeleteDepot(TileIndex tile)
void DoDeleteDepot(uint tile)
{
Order order;
Depot *depot;
@@ -106,7 +103,7 @@ void InitializeDepot(void)
}
static const SaveLoad _depot_desc[] = {
static const byte _depot_desc[] = {
SLE_CONDVAR(Depot, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
SLE_CONDVAR(Depot, xy, SLE_UINT32, 6, 255),
SLE_VAR(Depot,town_index, SLE_UINT16),

60
depot.h
View File

@@ -1,14 +1,8 @@
/* $Id$ */
#ifndef DEPOT_H
#define DEPOT_H
/** @file depot.h Header files for depots (not hangars)
* @see depot.c */
#include "pool.h"
#include "tile.h"
#include "variables.h"
struct Depot {
TileIndex xy;
@@ -78,14 +72,14 @@ static inline bool IsTileDepotType(TileIndex tile, TransportType type)
switch(type)
{
case TRANSPORT_RAIL:
return IsTileType(tile, MP_RAILWAY) && (_m[tile].m5 & 0xFC) == 0xC0;
return IsTileType(tile, MP_RAILWAY) && (_map5[tile] & 0xFC) == 0xC0;
break;
case TRANSPORT_ROAD:
return IsTileType(tile, MP_STREET) && (_m[tile].m5 & 0xF0) == 0x20;
return IsTileType(tile, MP_STREET) && (_map5[tile] & 0xF0) == 0x20;
break;
case TRANSPORT_WATER:
return IsTileType(tile, MP_WATER) && (_m[tile].m5 & ~3) == 0x80;
return IsTileType(tile, MP_WATER) && (_map5[tile] & ~3) == 0x80;
break;
default:
assert(0);
return false;
@@ -95,7 +89,7 @@ static inline bool IsTileDepotType(TileIndex tile, TransportType type)
/**
* Returns the direction the exit of the depot on the given tile is facing.
*/
static inline DiagDirection GetDepotDirection(TileIndex tile, TransportType type)
static inline uint GetDepotDirection(TileIndex tile, TransportType type)
{
assert(IsTileDepotType(tile, type));
@@ -104,45 +98,23 @@ static inline DiagDirection GetDepotDirection(TileIndex tile, TransportType type
case TRANSPORT_RAIL:
case TRANSPORT_ROAD:
/* Rail and road store a diagonal direction in bits 0 and 1 */
return (DiagDirection)GB(_m[tile].m5, 0, 2);
return _map5[tile] & 3;
case TRANSPORT_WATER:
/* Water is stubborn, it stores the directions in a different order. */
switch (GB(_m[tile].m5, 0, 2)) {
case 0: return DIAGDIR_NE;
case 1: return DIAGDIR_SW;
case 2: return DIAGDIR_NW;
case 3: return DIAGDIR_SE;
switch (_map5[tile] & 3) {
case 0: return 0;
case 1: return 2;
case 2: return 3;
case 3: return 1;
}
default:
return INVALID_DIAGDIR; /* Not reached */
return 0; /* Not reached */
}
}
/**
Find out if the slope of the tile is suitable to build a depot of given direction
@param direction The direction in which the depot's exit points. Starts with 0 as NE and goes Clockwise
@param tileh The slope of the tile in question
@return true if the construction is possible
This is checked by the ugly 0x4C >> direction magic, which does the following:
0x4C is 0100 1100 and tileh has only bits 0..3 set (steep tiles are ruled out)
So: for direction (only the significant bits are shown)<p>
00 (exit towards NE) we need either bit 2 or 3 set in tileh: 0x4C >> 0 = 1100<p>
01 (exit towards SE) we need either bit 1 or 2 set in tileh: 0x4C >> 1 = 0110<p>
02 (exit towards SW) we need either bit 0 or 1 set in tileh: 0x4C >> 2 = 0011<p>
03 (exit towards NW) we need either bit 0 or 4 set in tileh: 0x4C >> 3 = 1001<p>
So ((0x4C >> p2) & tileh) determines whether the depot can be built on the current tileh
*/
static inline bool CanBuildDepotByTileh(uint32 direction, uint tileh)
{
return (0x4C >> direction) & tileh;
}
Depot *GetDepotByTile(TileIndex tile);
Depot *GetDepotByTile(uint tile);
void InitializeDepot(void);
Depot *AllocateDepot(void);
void DoDeleteDepot(TileIndex tile);
void DoDeleteDepot(uint tile);
#endif /* DEPOT_H */

View File

@@ -1,30 +0,0 @@
/* $Id$ */
#ifndef DIRECTION_H
#define DIRECTION_H
/* the 2 axis */
typedef enum Axis {
AXIS_X = 0,
AXIS_Y = 1,
AXIS_END
} Axis;
static inline Axis DiagDirToAxis(uint d)
{
return (Axis)(d & 1);
}
/*
* Converts an Axis to a DiagDirection
* Points always in the positive direction, i.e. S[EW]
*/
static inline uint AxisToDiagDir(Axis a)
{
return (uint)(2 - a);
}
#endif

View File

@@ -1,35 +1,31 @@
/* $Id$ */
#include "stdafx.h"
#include "openttd.h"
#include "ttd.h"
#include "table/strings.h"
#include "functions.h"
#include "map.h"
#include "tile.h"
#include "vehicle.h"
#include "command.h"
#include "news.h"
#include "gfx.h"
#include "station.h"
#include "waypoint.h"
#include "town.h"
#include "industry.h"
#include "player.h"
#include "airport_movement.h"
#include "sound.h"
#include "variables.h"
#include "table/sprites.h"
static void DisasterClearSquare(TileIndex tile)
{
if (!EnsureNoVehicle(tile)) return;
if (!EnsureNoVehicle(tile))
return;
switch (GetTileType(tile)) {
case MP_RAILWAY:
if (IS_HUMAN_PLAYER(GetTileOwner(tile)) && !IsRailWaypoint(tile)) DoClearSquare(tile);
if (IS_HUMAN_PLAYER(_map_owner[tile])) DoClearSquare(tile);
break;
case MP_HOUSE: {
PlayerID p = _current_player;
byte p = _current_player;
_current_player = OWNER_NONE;
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
_current_player = p;
@@ -80,7 +76,7 @@ static void InitializeDisasterVehicle(Vehicle *v, int x, int y, byte z, byte dir
v->x_pos = x;
v->y_pos = y;
v->z_pos = z;
v->tile = TileVirtXY(x, y);
v->tile = TILE_FROM_XY(x,y);
v->direction = direction;
v->subtype = subtype;
v->x_offs = -1;
@@ -115,7 +111,7 @@ static void SetDisasterVehiclePos(Vehicle *v, int x, int y, byte z)
v->x_pos = x;
v->y_pos = y;
v->z_pos = z;
v->tile = TileVirtXY(x, y);
v->tile = TILE_FROM_XY(x,y);
DisasterVehicleUpdateImage(v);
VehiclePositionChanged(v);
@@ -151,7 +147,7 @@ static void DisasterTick_Zeppeliner(Vehicle *v)
Station *st;
int x,y;
byte z;
TileIndex tile;
uint tile;
++v->tick_counter;
@@ -177,12 +173,13 @@ static void DisasterTick_Zeppeliner(Vehicle *v)
if (IsValidTile(tile) &&
IsTileType(tile, MP_STATION) &&
IS_BYTE_INSIDE(_m[tile].m5, 8, 0x43) &&
IS_HUMAN_PLAYER(GetTileOwner(tile))) {
IS_BYTE_INSIDE(_map5[tile], 8, 0x43) &&
IS_HUMAN_PLAYER(_map_owner[tile])) {
v->current_order.station = 1;
v->age = 0;
SetDParam(0, _m[tile].m2);
SetDParam(0, _map2[tile]);
AddNewsItem(STR_B000_ZEPPELIN_DISASTER_AT,
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ACCIDENT, 0),
v->index,
@@ -202,9 +199,10 @@ static void DisasterTick_Zeppeliner(Vehicle *v)
if (IsValidTile(tile) &&
IsTileType(tile, MP_STATION) &&
IS_BYTE_INSIDE(_m[tile].m5, 8, 0x43) &&
IS_HUMAN_PLAYER(GetTileOwner(tile))) {
st = GetStation(_m[tile].m2);
IS_BYTE_INSIDE(_map5[tile], 8, 0x43) &&
IS_HUMAN_PLAYER(_map_owner[tile])) {
st = GetStation(_map2[tile]);
CLRBITS(st->airport_flags, RUNWAY_IN_block);
}
@@ -223,17 +221,17 @@ static void DisasterTick_Zeppeliner(Vehicle *v)
if (++v->age == 1) {
CreateEffectVehicleRel(v, 0, 7, 8, EV_EXPLOSION_LARGE);
SndPlayVehicleFx(SND_12_EXPLOSION, v);
v->u.disaster.image_override = SPR_BLIMP_CRASHING;
v->u.disaster.image_override = 0xF42;
} else if (v->age == 70) {
v->u.disaster.image_override = SPR_BLIMP_CRASHED;
v->u.disaster.image_override = 0xF43;
} else if (v->age <= 300) {
if (!(v->tick_counter&7)) {
uint32 r = Random();
CreateEffectVehicleRel(v,
GB(r, 0, 4) - 7,
GB(r, 4, 4) - 7,
GB(r, 8, 3) + 5,
-7 + (r&0xF),
-7 + (r>>4&0xF),
5 + (r>>8&0x7),
EV_EXPLOSION_SMALL);
}
} else if (v->age == 350) {
@@ -244,10 +242,10 @@ static void DisasterTick_Zeppeliner(Vehicle *v)
tile = v->tile;/**/
if (IsValidTile(tile) &&
IsTileType(tile, MP_STATION) &&
IS_BYTE_INSIDE(_m[tile].m5, 8, 0x43) &&
IS_HUMAN_PLAYER(GetTileOwner(tile))) {
IS_BYTE_INSIDE(_map5[tile], 8, 0x43) &&
IS_HUMAN_PLAYER(_map_owner[tile])) {
st = GetStation(_m[tile].m2);
st = GetStation(_map2[tile]);
SETBITS(st->airport_flags, RUNWAY_IN_block);
}
}
@@ -261,20 +259,20 @@ static void DisasterTick_UFO(Vehicle *v)
uint dist;
byte z;
v->u.disaster.image_override = (++v->tick_counter & 8) ? SPR_UFO_SMALL_SCOUT_DARKER : SPR_UFO_SMALL_SCOUT;
v->u.disaster.image_override = (++v->tick_counter & 8) ? 0xF45 : 0xF44;
if (v->current_order.station == 0) {
// fly around randomly
int x = TileX(v->dest_tile) * 16;
int y = TileY(v->dest_tile) * 16;
if (abs(x - v->x_pos) + abs(y - v->y_pos) >= 16) {
if (abs(x - v->x_pos) + abs(y - v->y_pos) >= 16) {
v->direction = GetDirectionTowards(v, x, y);
GetNewVehiclePos(v, &gp);
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
return;
}
if (++v->age < 6) {
v->dest_tile = RandomTile();
v->dest_tile = TILE_MASK(Random());
return;
}
v->current_order.station = 1;
@@ -334,11 +332,11 @@ static void DisasterTick_UFO(Vehicle *v)
static void DestructIndustry(Industry *i)
{
TileIndex tile;
uint tile;
for (tile = 0; tile != MapSize(); tile++) {
if (IsTileType(tile, MP_INDUSTRY) && _m[tile].m2 == i->index) {
_m[tile].m1 = 0;
for(tile=0; tile != MapSize(); tile++) {
if (IsTileType(tile, MP_INDUSTRY) && _map2[tile] == i->index) {
_map_owner[tile] = 0;
MarkTileDirtyByTile(tile);
}
}
@@ -351,7 +349,7 @@ static void DisasterTick_2(Vehicle *v)
v->tick_counter++;
v->u.disaster.image_override =
(v->current_order.station == 1 && v->tick_counter & 4) ? SPR_F_15_FIRING : 0;
(v->current_order.station == 1 && v->tick_counter&4) ? 0xF4F : 0;
GetNewVehiclePos(v, &gp);
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
@@ -369,9 +367,9 @@ static void DisasterTick_2(Vehicle *v)
uint32 r = Random();
CreateEffectVehicleAbove(
GB(r, 0, 6) + x,
GB(r, 6, 6) + y,
GB(r, 12, 4),
x + (r & 0x3F),
y + (r >> 6 & 0x3F),
(r >> 12 & 0xF),
EV_EXPLOSION_SMALL);
if (++v->age >= 55)
@@ -393,7 +391,7 @@ static void DisasterTick_2(Vehicle *v)
}
} else if (v->current_order.station == 0) {
int x,y;
TileIndex tile;
uint tile;
int ind;
x = v->x_pos - 15*16;
@@ -402,11 +400,11 @@ static void DisasterTick_2(Vehicle *v)
if ( (uint)x > MapMaxX() * 16-1)
return;
tile = TileVirtXY(x, y);
tile = TILE_FROM_XY(x,y);
if (!IsTileType(tile, MP_INDUSTRY))
return;
v->dest_tile = ind = _m[tile].m2;
v->dest_tile = ind = _map2[tile];
if (GetIndustry(ind)->type == IT_OIL_REFINERY) {
v->current_order.station = 1;
@@ -422,7 +420,7 @@ static void DisasterTick_3(Vehicle *v)
v->tick_counter++;
v->u.disaster.image_override =
(v->current_order.station == 1 && v->tick_counter & 4) ? SPR_AH_64A_FIRING : 0;
(v->current_order.station == 1 && v->tick_counter&4) ? 0xF53 : 0;
GetNewVehiclePos(v, &gp);
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
@@ -440,9 +438,9 @@ static void DisasterTick_3(Vehicle *v)
uint32 r = Random();
CreateEffectVehicleAbove(
GB(r, 0, 6) + x,
GB(r, 6, 6) + y,
GB(r, 12, 4),
x + (r & 0x3F),
y + (r >> 6 & 0x3F),
(r >> 12 & 0xF),
EV_EXPLOSION_SMALL);
if (++v->age >= 55)
@@ -464,7 +462,7 @@ static void DisasterTick_3(Vehicle *v)
}
} else if (v->current_order.station == 0) {
int x,y;
TileIndex tile;
uint tile;
int ind;
x = v->x_pos - 15*16;
@@ -473,11 +471,11 @@ static void DisasterTick_3(Vehicle *v)
if ( (uint)x > MapMaxX() * 16-1)
return;
tile = TileVirtXY(x, y);
tile = TILE_FROM_XY(x,y);
if (!IsTileType(tile, MP_INDUSTRY))
return;
v->dest_tile = ind = _m[tile].m2;
v->dest_tile = ind = _map2[tile];
if (GetIndustry(ind)->type == IT_FACTORY) {
v->current_order.station = 1;
@@ -492,7 +490,8 @@ static void DisasterTick_3b(Vehicle *v)
if (++v->tick_counter & 1)
return;
if (++v->cur_image > SPR_ROTOR_MOVING_3) v->cur_image = SPR_ROTOR_MOVING_1;
if (++v->cur_image == 0xF40 + 1)
v->cur_image = 0xF3E;
VehiclePositionChanged(v);
BeginVehicleMove(v);
@@ -507,8 +506,7 @@ static void DisasterTick_4(Vehicle *v)
byte z;
Vehicle *u,*w;
Town *t;
TileIndex tile;
TileIndex tile_org;
uint tile,tile_org;
v->tick_counter++;
@@ -567,7 +565,7 @@ static void DisasterTick_4(Vehicle *v)
int x = TileX(v->dest_tile) * 16;
int y = TileY(v->dest_tile) * 16;
if (abs(x - v->x_pos) + abs(y - v->y_pos) >= 16) {
if (abs(x - v->x_pos) + abs(y - v->y_pos) >= 16) {
v->direction = GetDirectionTowards(v, x, y);
GetNewVehiclePos(v, &gp);
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
@@ -575,16 +573,16 @@ static void DisasterTick_4(Vehicle *v)
}
if (++v->age < 6) {
v->dest_tile = RandomTile();
v->dest_tile = TILE_MASK(Random());
return;
}
v->current_order.station = 1;
tile_org = tile = RandomTile();
tile_org = tile = TILE_MASK(Random());
do {
if (IsTileType(tile, MP_RAILWAY) &&
(_m[tile].m5 & ~3) != 0xC0 && IS_HUMAN_PLAYER(GetTileOwner(tile)))
break;
(_map5[tile]&~3)!=0xC0 && IS_HUMAN_PLAYER(_map_owner[tile]))
break;
tile = TILE_MASK(tile+1);
} while (tile != tile_org);
v->dest_tile = tile;
@@ -624,16 +622,16 @@ static void DisasterTick_4b(Vehicle *v)
for(i=0; i!=80; i++) {
uint32 r = Random();
CreateEffectVehicleAbove(
GB(r, 0, 6) + v->x_pos - 32,
GB(r, 5, 6) + v->y_pos - 32,
v->x_pos-32+(r&0x3F),
v->y_pos-32+(r>>5&0x3F),
0,
EV_EXPLOSION_SMALL);
}
BEGIN_TILE_LOOP(tile, 6, 6, v->tile - TileDiffXY(3, 3))
BEGIN_TILE_LOOP(tile,6,6,v->tile - TILE_XY(3,3))
tile = TILE_MASK(tile);
DisasterClearSquare(tile);
END_TILE_LOOP(tile, 6, 6, v->tile - TileDiffXY(3, 3))
END_TILE_LOOP(tile,6,6,v->tile - TILE_XY(3,3))
}
}
@@ -642,7 +640,7 @@ static void DisasterTick_5_and_6(Vehicle *v)
{
uint32 r;
GetNewVehiclePosResult gp;
TileIndex tile;
uint tile;
v->tick_counter++;
@@ -666,7 +664,7 @@ static void DisasterTick_5_and_6(Vehicle *v)
return;
}
v->direction = (v->direction + (GB(Random(), 0, 1) ? 2 : -2)) & 7;
v->direction = (v->direction + ((Random()&1)?2:-2))&7;
}
@@ -690,6 +688,10 @@ void DisasterVehicle_Tick(Vehicle *v)
_disastervehicle_tick_procs[v->subtype](v);
}
void HandleClickOnDisasterVeh(Vehicle *v)
{
// not used
}
void OnNewDay_DisasterVehicle(Vehicle *v)
{
@@ -743,7 +745,7 @@ static void Disaster1_Init(void)
x = TileX(Random()) * 16 + 8;
InitializeDisasterVehicle(v, x, 0, 135, 3, 2);
v->dest_tile = TileXY(MapSizeX() / 2, MapSizeY() / 2);
v->dest_tile = TILE_XY(MapSizeX() / 2, MapSizeY() / 2);
v->age = 0;
// Allocate shadow too?
@@ -838,13 +840,14 @@ static void Disaster4_Init(void)
Vehicle *v = ForceAllocateSpecialVehicle(), *u;
int x,y;
if (v == NULL) return;
if (v == NULL)
return;
x = TileX(Random()) * 16 + 8;
y = MapMaxX() * 16 - 1;
InitializeDisasterVehicle(v, x, y, 135, 7, 9);
v->dest_tile = TileXY(MapSizeX() / 2, MapSizeY() / 2);
v->dest_tile = TILE_XY(MapSizeX() / 2, MapSizeY() / 2);
v->age = 0;
// Allocate shadow too?
@@ -864,7 +867,8 @@ static void Disaster5_Init(void)
byte dir;
uint32 r;
if (v == NULL) return;
if (v == NULL)
return;
r = Random();
x = TileX(r) * 16 + 8;
@@ -884,7 +888,8 @@ static void Disaster6_Init(void)
byte dir;
uint32 r;
if (v == NULL) return;
if (v == NULL)
return;
r = Random();
x = TileX(r) * 16 + 8;
@@ -898,32 +903,31 @@ static void Disaster6_Init(void)
static void Disaster7_Init(void)
{
int index = GB(Random(), 0, 4);
Industry *i;
uint m;
int maxloop = 15;
int index = Random() & 0xF;
for (m = 0; m < 15; m++) {
do {
FOR_ALL_INDUSTRIES(i) {
if (i->xy != 0 && i->type == IT_COAL_MINE && --index < 0) {
if (i->xy != 0 && i->type == IT_COAL_MINE && --index < 0) {
SetDParam(0, i->town->index);
AddNewsItem(STR_B005_COAL_MINE_SUBSIDENCE_LEAVES,
NEWS_FLAGS(NM_THIN,NF_VIEWPORT|NF_TILE,NT_ACCIDENT,0), i->xy + TileDiffXY(1, 1), 0);
NEWS_FLAGS(NM_THIN,NF_VIEWPORT|NF_TILE,NT_ACCIDENT,0), i->xy + TILE_XY(1,1), 0);
{
TileIndex tile = i->xy;
TileIndexDiff step = TileOffsByDir(GB(Random(), 0, 2));
uint n;
for (n = 0; n < 30; n++) {
uint tile = i->xy;
TileIndexDiff step = TileOffsByDir(Random() & 3);
int count = 30;
do {
DisasterClearSquare(tile);
tile = TILE_MASK(tile + step);
}
} while (--count);
}
return;
}
}
}
} while (--maxloop != 0);
}
static DisasterInitProc * const _disaster_initprocs[] = {
@@ -937,56 +941,60 @@ static DisasterInitProc * const _disaster_initprocs[] = {
Disaster7_Init,
};
#define MK(a, b) { (a) - MAX_YEAR_BEGIN_REAL, (b) - MAX_YEAR_BEGIN_REAL }
static const struct {
byte min;
byte max;
} _dis_years[] = {
MK(1930, 1955),
MK(1940, 1970),
MK(1960, 1990),
MK(1970, 2000),
MK(2000, 2100),
MK(1940, 1965),
MK(1975, 2010),
MK(1950, 1985)
typedef struct {
byte min,max;
} DisasterYears;
#define MK(a,b) {a-20,b-20}
static const DisasterYears _dis_years[8] = {
MK(30,55),
MK(40,70),
MK(60,90),
MK(70,100),
MK(100,200),
MK(40,65),
MK(75,110),
MK(50,85),
};
#undef MK
static void DoDisaster(void)
{
byte buf[lengthof(_dis_years)];
byte buf[8];
byte year = _cur_year;
uint i;
uint j;
int i,j;
j = 0;
for (i = 0; i != lengthof(_dis_years); i++) {
if (year >= _dis_years[i].min && year < _dis_years[i].max) buf[j++] = i;
for(i=j=0; i!=lengthof(_dis_years); i++) {
if (year >= _dis_years[i].min &&
year < _dis_years[i].max)
buf[j++] = i;
}
if (j == 0) return;
if (j == 0)
return;
_disaster_initprocs[buf[RandomRange(j)]]();
_disaster_initprocs[buf[(uint16)Random() * j >> 16]]();
}
static void ResetDisasterDelay(void)
{
_disaster_delay = GB(Random(), 0, 9) + 730;
_disaster_delay = (int)(Random() & 0x1FF) + 730;
}
void DisasterDailyLoop(void)
{
if (--_disaster_delay != 0) return;
if (--_disaster_delay != 0)
return;
ResetDisasterDelay();
if (_opt.diff.disasters != 0) DoDisaster();
if (_opt.diff.disasters != 0)
DoDisaster();
}
void StartupDisasters(void)
{
ResetDisasterDelay();
}

View File

@@ -1,10 +1,7 @@
/* $Id$ */
#include "stdafx.h"
#include "openttd.h"
#include "ttd.h"
#include "table/sprites.h"
#include "table/strings.h"
#include "functions.h"
#include "map.h"
#include "window.h"
#include "station.h"
@@ -13,14 +10,13 @@
#include "gfx.h"
#include "sound.h"
#include "command.h"
#include "variables.h"
static void ShowBuildDockStationPicker(void);
static void ShowBuildDocksDepotPicker(void);
static byte _ship_depot_direction;
void CcBuildDocks(bool success, TileIndex tile, uint32 p1, uint32 p2)
void CcBuildDocks(bool success, uint tile, uint32 p1, uint32 p2)
{
if (success) {
SndPlayTileFx(SND_02_SPLAT, tile);
@@ -28,38 +24,38 @@ void CcBuildDocks(bool success, TileIndex tile, uint32 p1, uint32 p2)
}
}
void CcBuildCanal(bool success, TileIndex tile, uint32 p1, uint32 p2)
void CcBuildCanal(bool success, uint tile, uint32 p1, uint32 p2)
{
if (success) SndPlayTileFx(SND_02_SPLAT, tile);
}
static void PlaceDocks_Dock(TileIndex tile)
static void PlaceDocks_Dock(uint tile)
{
DoCommandP(tile, 0, 0, CcBuildDocks, CMD_BUILD_DOCK | CMD_AUTO | CMD_MSG(STR_9802_CAN_T_BUILD_DOCK_HERE));
}
static void PlaceDocks_Depot(TileIndex tile)
static void PlaceDocks_Depot(uint tile)
{
DoCommandP(tile, _ship_depot_direction, 0, CcBuildDocks, CMD_BUILD_SHIP_DEPOT | CMD_AUTO | CMD_MSG(STR_3802_CAN_T_BUILD_SHIP_DEPOT));
}
static void PlaceDocks_Buoy(TileIndex tile)
static void PlaceDocks_Buoy(uint tile)
{
DoCommandP(tile, 0, 0, CcBuildDocks, CMD_BUILD_BUOY | CMD_AUTO | CMD_MSG(STR_9835_CAN_T_POSITION_BUOY_HERE));
}
static void PlaceDocks_DemolishArea(TileIndex tile)
static void PlaceDocks_DemolishArea(uint tile)
{
VpStartPlaceSizing(tile, VPM_X_AND_Y | GUI_PlaceProc_DemolishArea);
}
static void PlaceDocks_BuildCanal(TileIndex tile)
static void PlaceDocks_BuildCanal(uint tile)
{
VpStartPlaceSizing(tile, VPM_X_OR_Y);
}
static void PlaceDocks_BuildLock(TileIndex tile)
static void PlaceDocks_BuildLock(uint tile)
{
DoCommandP(tile, 0, 0, CcBuildDocks, CMD_BUILD_LOCK | CMD_AUTO | CMD_MSG(STR_CANT_BUILD_LOCKS));
}
@@ -67,12 +63,12 @@ static void PlaceDocks_BuildLock(TileIndex tile)
static void BuildDocksClick_Canal(Window *w)
{
HandlePlacePushButton(w, 3, SPR_CURSOR_CANAL, 1, PlaceDocks_BuildCanal);
HandlePlacePushButton(w, 3, SPR_OPENTTD_BASE + 11, 1, PlaceDocks_BuildCanal);
}
static void BuildDocksClick_Lock(Window *w)
{
HandlePlacePushButton(w, 4, SPR_CURSOR_LOCK, 1, PlaceDocks_BuildLock);
HandlePlacePushButton(w, 4, SPR_OPENTTD_BASE + 64, 1, PlaceDocks_BuildLock);
}
static void BuildDocksClick_Demolish(Window *w)
@@ -82,18 +78,18 @@ static void BuildDocksClick_Demolish(Window *w)
static void BuildDocksClick_Depot(Window *w)
{
if (HandlePlacePushButton(w, 7, SPR_CURSOR_SHIP_DEPOT, 1, PlaceDocks_Depot)) ShowBuildDocksDepotPicker();
if (HandlePlacePushButton(w, 7, 0x2D1, 1, PlaceDocks_Depot)) ShowBuildDocksDepotPicker();
}
static void BuildDocksClick_Dock(Window *w)
{
if (HandlePlacePushButton(w, 8, SPR_CURSOR_DOCK, 3, PlaceDocks_Dock)) ShowBuildDockStationPicker();
if (HandlePlacePushButton(w, 8, 0xE54, 3, PlaceDocks_Dock)) ShowBuildDockStationPicker();
}
static void BuildDocksClick_Buoy(Window *w)
{
HandlePlacePushButton(w, 9, SPR_CURSOR_BOUY, 1, PlaceDocks_Buoy);
HandlePlacePushButton(w, 9, 0x2BE, 1, PlaceDocks_Buoy);
}
static void BuildDocksClick_Landscaping(Window *w)
@@ -105,7 +101,7 @@ typedef void OnButtonClick(Window *w);
static OnButtonClick * const _build_docks_button_proc[] = {
BuildDocksClick_Canal,
BuildDocksClick_Lock,
NULL,
0,
BuildDocksClick_Demolish,
BuildDocksClick_Depot,
BuildDocksClick_Dock,
@@ -120,12 +116,12 @@ static void BuildDocksToolbWndProc(Window *w, WindowEvent *e)
DrawWindowWidgets(w);
break;
case WE_CLICK:
case WE_CLICK: {
if (e->click.widget - 3 >= 0 && e->click.widget != 5) _build_docks_button_proc[e->click.widget - 3](w);
break;
} break;
case WE_KEYPRESS:
switch (e->keypress.keycode) {
case WE_KEYPRESS: {
switch(e->keypress.keycode) {
case '1': BuildDocksClick_Canal(w); break;
case '2': BuildDocksClick_Lock(w); break;
case '3': BuildDocksClick_Demolish(w); break;
@@ -133,9 +129,10 @@ static void BuildDocksToolbWndProc(Window *w, WindowEvent *e)
case '5': BuildDocksClick_Dock(w); break;
case '6': BuildDocksClick_Buoy(w); break;
case 'l': BuildDocksClick_Landscaping(w); break;
default: return;
default:
return;
}
break;
} break;
case WE_PLACE_OBJ:
_place_proc(e->place.tile);
@@ -150,9 +147,8 @@ static void BuildDocksToolbWndProc(Window *w, WindowEvent *e)
if (e->click.pt.x != -1) {
if ((e->place.userdata & 0xF) == VPM_X_AND_Y) { // dragged actions
GUIPlaceProcDragXY(e);
} else if (e->place.userdata == VPM_X_OR_Y) {
} else if(e->place.userdata == VPM_X_OR_Y)
DoCommandP(e->place.tile, e->place.starttile, 0, CcBuildCanal, CMD_BUILD_CANAL | CMD_AUTO | CMD_MSG(STR_CANT_BUILD_CANALS));
}
}
break;
@@ -161,29 +157,24 @@ static void BuildDocksToolbWndProc(Window *w, WindowEvent *e)
SetWindowDirty(w);
w = FindWindowById(WC_BUILD_STATION, 0);
if (w != NULL) WP(w,def_d).close = true;
if (w != NULL) WP(w,def_d).close=true;
w = FindWindowById(WC_BUILD_DEPOT, 0);
if (w != NULL) WP(w,def_d).close = true;
if (w != NULL) WP(w,def_d).close=true;
break;
case WE_PLACE_PRESIZE: {
TileIndex tile_from;
TileIndex tile_to;
uint tile_from, tile_to;
tile_from = tile_to = e->place.tile;
switch (GetTileSlope(tile_from, NULL)) {
case 3: tile_to += TileDiffXY(-1, 0); break;
case 6: tile_to += TileDiffXY( 0, -1); break;
case 9: tile_to += TileDiffXY( 0, 1); break;
case 12: tile_to += TileDiffXY( 1, 0); break;
switch(GetTileSlope(tile_from, NULL)) {
case 3: tile_to += TILE_XY(-1,0); break;
case 6: tile_to += TILE_XY(0,-1); break;
case 9: tile_to += TILE_XY(0,1); break;
case 12:tile_to += TILE_XY(1,0); break;
}
VpSetPresizeRange(tile_from, tile_to);
} break;
case WE_DESTROY:
if (_patches.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0);
break;
}
}
@@ -217,44 +208,42 @@ void ShowBuildDocksToolbar(void)
if (_current_player == OWNER_SPECTATOR) return;
DeleteWindowById(WC_BUILD_TOOLBAR, 0);
AllocateWindowDesc(&_build_docks_toolbar_desc);
if (_patches.link_terraform_toolbar) ShowTerraformToolbar();
}
static void BuildDockStationWndProc(Window *w, WindowEvent *e)
{
switch (e->event) {
case WE_PAINT: {
int rad;
int rad;
if (WP(w,def_d).close) return;
switch(e->event) {
case WE_PAINT: {
if (WP(w,def_d).close)
return;
w->click_state = (1<<3) << _station_show_coverage;
DrawWindowWidgets(w);
rad = (_patches.modified_catchment) ? CA_DOCK : 4;
if (_station_show_coverage) {
SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
if (_patches.modified_catchment) {
rad = CA_DOCK;
} else {
SetTileSelectBigSize(0, 0, 0, 0);
rad = 4;
}
if (_station_show_coverage) SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
else SetTileSelectBigSize(0, 0, 0, 0);
DrawStringCentered(74, 17, STR_3066_COVERAGE_AREA_HIGHLIGHT, 0);
DrawStationCoverageAreaText(4, 50, (uint)-1, rad);
break;
}
} break;
case WE_CLICK:
switch (e->click.widget) {
case 3:
case 4:
_station_show_coverage = e->click.widget - 3;
SndPlayFx(SND_15_BEEP);
SetWindowDirty(w);
break;
case WE_CLICK: {
switch(e->click.widget) {
case 3: case 4:
_station_show_coverage = e->click.widget - 3;
SndPlayFx(SND_15_BEEP);
SetWindowDirty(w);
break;
}
break;
} break;
case WE_MOUSELOOP:
case WE_MOUSELOOP: {
if (WP(w,def_d).close) {
DeleteWindow(w);
return;
@@ -262,9 +251,11 @@ static void BuildDockStationWndProc(Window *w, WindowEvent *e)
CheckRedrawStationCoverage(w);
break;
}
case WE_DESTROY:
if (!WP(w,def_d).close) ResetObjectToPlace();
if (!WP(w,def_d).close)
ResetObjectToPlace();
break;
}
}
@@ -273,8 +264,8 @@ static const Widget _build_dock_station_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 147, 0, 13, STR_3068_DOCK, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_PANEL, RESIZE_NONE, 7, 0, 147, 14, 74, 0x0, STR_NULL},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 14, 73, 30, 40, STR_02DB_OFF, STR_3065_DON_T_HIGHLIGHT_COVERAGE},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 74, 133, 30, 40, STR_02DA_ON, STR_3064_HIGHLIGHT_COVERAGE_AREA},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 14, 73, 30, 40, STR_02DB_OFF, STR_3065_DON_T_HIGHLIGHT_COVERAGE},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 74, 133, 30, 40, STR_02DA_ON, STR_3064_HIGHLIGHT_COVERAGE_AREA},
{ WIDGETS_END},
};
@@ -302,7 +293,7 @@ static void UpdateDocksDirection(void)
static void BuildDocksDepotWndProc(Window *w, WindowEvent *e)
{
switch (e->event) {
switch(e->event) {
case WE_PAINT:
w->click_state = (1<<3) << _ship_depot_direction;
DrawWindowWidgets(w);
@@ -314,7 +305,7 @@ static void BuildDocksDepotWndProc(Window *w, WindowEvent *e)
return;
case WE_CLICK: {
switch (e->click.widget) {
switch(e->click.widget) {
case 3:
case 4:
_ship_depot_direction = e->click.widget - 3;
@@ -326,11 +317,13 @@ static void BuildDocksDepotWndProc(Window *w, WindowEvent *e)
} break;
case WE_MOUSELOOP:
if (WP(w,def_d).close) DeleteWindow(w);
if (WP(w,def_d).close)
DeleteWindow(w);
break;
case WE_DESTROY:
if (!WP(w,def_d).close) ResetObjectToPlace();
if (!WP(w,def_d).close)
ResetObjectToPlace();
break;
}
}

View File

@@ -1,23 +0,0 @@
To install OpenTTD, you should drag the game to any location you want and in that folder, you should create a folder called "data". It should contain:
sample.cat
trg1r.grf
trgcr.grf
trghr.grf
trgir.grf
trgtr.grf
(Alternatively you can use the TTD GRF files from the DOS version: TRG1.GRF, TRGC.GRF, TRGH.GRF, TRGI.GRF, TRGT.GRF. A few minor graphical glitches with the DOS graphics remain. E.g. the autorail button in the rail toolbar doesn't look as nice as with the Windows graphics.)
You should also use the data folder to add any custom grf files if you like
if you want music, you can add a GM folder and add all .gm files from TTD inside it
If you want to use the scenarios, you can copy the scenario folder as well. If you already have one, just copy the content so you don't overwrite old ones that have been removed.
In the end, you should have a folder containing:
OpenTTD (the actual game)
data (containing the grf files)
GM (optional for music)
scenario (optional pregenerated maps)
The game adds some items by itself when it runs, like a save folder and a setting file

View File

@@ -0,0 +1,24 @@
It's gone
The main goal with the package system was to make it as simple as possible to update. The problem was that some files inside the data folder should be updated and not others. Now the data files have been moved inside OpenTTD itself and to make it even easier, the same goes for the lang dir. There will no longer be an issue where people have different versions of grf files, language files and OpenTTD.
To install simply copy OpenTTD into the folder you want
If it is your current folder with outdated grf files, you should remove
canalsw.grf
openttd.grf
opntitle.dat
signalsw.grf
trkfoundw.grf
THE TTD GRF FILES ARE STILL NEEDED!
They need to be inside a folder called "data" in the same folder as OpenTTD. Create it if you have none. It should contain:
sample.cat
trg1r.grf
trgcr.grf
trghr.grf
trgir.grf
trgtr.grf
(Alternatively you can use the TTD GRF files from the DOS version: TRG1.GRF, TRGC.GRF, TRGH.GRF, TRGI.GRF, TRGT.GRF. A few minor graphical glitches with the DOS graphics remain. E.g. the autorail button in the rail toolbar doesn't look as nice as with the Windows graphics.)
You should also use the data folder to add any custom grf files if you like

View File

@@ -1,10 +0,0 @@
There are currently two different downloads for OSX, one is named osx, while the other one is named osx-jaguar
The reason for this is that Apple added more functionality to 10.3 and to make use of that, it will no longer run on OSX 10.2 (codenamed Jaguar). To make the game useable on Jaguar, then a special download is available, but it will miss the bugfixes/features, that relies on newer functionality.
The general download is a universal binary and should work great on all macs using 10.3.9 or newer, no matter what processor it got. You should at all time avoid the Jaguar Build if possible.
Technically the universal binary is a triple binary because it contains code for 3 CPUs and the CPUs in question are PPC (G3+G4), G5 and Intel. The Jaguar build is only optimised for PPC and other (newer) CPUs will not benefit so much from their advanced features. This is another reason to avoid the Jaguar build. It's generally slower on modern CPUs.
Current list of missing features in the Jaguar build:
-Can't save screenshots or savegames if certain chars are in the filename. This mainly applies to European chars and hits German hard as the month Mär (Mar) can't be saved

View File

@@ -0,0 +1,36 @@
Since you are reading this, OpenTTD have crashed. This file tells you how
to fix the most common problems or make to make a bug report, that the
developers can use to track down the problem
If it is an assert, OpenTTD will open the console for you, if it is truly a crash, you have to do it yourself. The Console is located at /Applications/Utilities/Console.
The problem is near the button of the page
The problems are as follows:
NOTE: build from source means to download the source and compile
yourself. If you get one of the build from source error with the version
that is downloaded on a dmg file, you should make a bug report
--Didn't find a needed file:
you just give it the file it asks for. It even tells you what
folder it wants it in
most common version of this problem is "Error: Cannot open file
'data/sample.cat'"
if you get that one, that means that you haven't got all the
needed files from the WINDOWS version of TTD
or if you build from source,
--Error: No available language packs
you need at least one .lng file in your lang folder. This applies
only to people who build from source
--spritecache.c:237: failed assertion `b'
you got an outdated grf file. Update from the data folder in the
source. This applies only to people, who build from source
--assertion error that are not triggered by one of the errors listed in
this file:
you most likely found a bug. Write down the assertion and try to
see if you can reproduce it. If you can, make a
savegame from just before it happens (autosaves are useful here)
and post a bugreport with it on sourceforge
Write what you did to trigger the bug and what assertion it made

View File

@@ -15,13 +15,15 @@ LIBRARIES REQUIRED FOR END USERS
SDL.DLL (SDL 1.2.7) and FSLib.dll are required to use this program:
these can be downloaded from the Files section at
http://sourceforge.net/projects/openttd/ - see "os2-useful-v1.1.zip".
Version 20051222 of SDL or later is required. This can be found at
http://sdl.netlabs.org/.
http://sourceforge.net/projects/openttd/ - see "os2-useful.zip".
(Note that a newer version of SDL is now available at
ftp://ftp.netlabs.org/pub/sdl/sdl-dev-os2-2004-12-22.zip which may
help solve some problems).
Please note that earlier SDL releases will probably NOT work with
OpenTTD. If you experience problems with OpenTTD, please check
your SDL and FSLib.dll versions (both must match).
Please note that SDL release 2005-03-30 does NOT work with OpenTTD,
at least in my experience and the experience of a couple of other
users. If you experience problems with OpenTTD, please try downgrading
to SDL 2004-12-22.
Note that to actually play the game, I have found in my own
experience that a version of the Scitech Display Drivers or its later
@@ -94,12 +96,13 @@ provided, they are not designed for Watcom (apart from SDL):
http://www.libpng.org/ - contains an EMX/gcc makefile, ignore this
- SDL for OS/2
ftp://ftp.netlabs.org/pub/sdl/sdl-1.2.7-src-20051222.zip used for
0.4.7
For 0.3.5, I used ftp://ftp.netlabs.org/pub/sdl/SDL-1.2.7-src-20040908a.zip -
take SDL.dll and SDL.lib from the src/ directory. Note that 20041222 is
out now, which is recommended for stability updates.
If you do not wish to build the libraries yourself, pre-built versions
can be downloaded from the Files section at
http://sourceforge.net/projects/openttd/ - see "os2-useful-v1.1.zip".
http://sourceforge.net/projects/openttd/ - see "os2-useful.zip".
A Note About Subversion Revision Numbers
----------------------------------------

View File

@@ -1,50 +1,54 @@
Compiling OpenTTD using Microsoft Visual C++ 6.0
Step 1: Ingredients
---Step 1
Download the following files:
* Openttd-useful.zip (http://sourceforge.net/project/showfiles.php?group_id=103924&amp;package_id=114307&amp;release_id=228633)
* DirectX 8.1 SDK (http://neuron.tuke.sk/~mizanin/eng/Dx81sdk-include-lib.rar) (or alternatively the latest DirectX SDK from Microsoft)
* The February 2003 Microsoft Platform SDK (http://www.microsoft.com/msdownload/platformsdk/sdkupdate/XPSP2FULLInstall.htm) (newer SDK's do not work with MSVC6)
* afxres.h (http://www-d0.fnal.gov/d0dist/dist/packages/d0ve/devel/windows/AFXRES.H) (maybe you not need this)
* Useful.zip (http://sourceforge.net/project/showfiles.php?group_id=103924&package_id=114307&release_id=228633)
* SDL-1.2.8-VC6.zip (http://www.libsdl.org/release/SDL-devel-1.2.8-VC6.zip)
* DirectX7.0 SDK (http://www.tt-forums.net/download.php?id=15989) (or alternatively the latest DirectX SDK from Microsoft)
* afxres.h (http://www-d0.fnal.gov/d0dist/dist/packages/d0ve/devel/windows/AFXRES.H)
...and of course the newest source from svn://svn.openttd.org/trunk
...and of course the newest source from svn://svn.openttd.com/trunk
You have to have a SVN-client to download the source:
(The alpha version of the new map array can be found at svn://svn.openttd.com/branch/map)
* Command line version (Subversion 1.2.3 Win32 binaries) (http://subversion.tigris.org/servlets/ProjectDocumentList?folderID=91)
* GUI TortoiseSVN (http://tortoisesvn.tigris.org/download.html)
You have to have and SVN-client to download the source:
Step 2: Includes and Libraries
* Command line version (http://subversion.tigris.org/servlets/ProjectDocumentList?folderID=91)
* TortoiseSVN (http://tortoisesvn.tigris.org/download.html)
Put the newly downloaded files in the VC lib and include directories (Where "C:\Program Files\Microsoft Visual Studio\VC98" is your local location of VC)
---Step 2
Put the newly downloaded files in the VC lib and include directories (Where C:\program files\ is your local location of VC)
* zconf.h [useful.zip]
* zlib.h [useful.zip]
* png.h [useful.zip]
* pngconf.h [useful.zip]
* afxres.h
* afxres.h
in
C:\Program Files\Microsoft Visual Studio\VC98\Include
C:\Program Files\Microsoft Visual Studio\VC98\Include
and
* zlibstat.lib [useful.zip]
* libpng.lib [useful.zip]
* SDL.lib [SDL.zip]
* libpng.lib [useful.zip]
in
C:\Program Files\Microsoft Visual Studio\VC98\Lib
C:\Program Files\Microsoft Visual Studio\VC98\Lib
Step 3: DirectX SDK
---Step 3: DirectX SDK
(This should work with the latest DirectX SDK as well.)
(This should work with the latest DirectX SDK as well.) The installation with DirectX 7 was odd, so you'd better use the version available via the forum, see also the download link on top.
There are 2 folder in the compressed file: Include and Lib
@@ -58,17 +62,16 @@ C:\Program Files\Microsoft Visual Studio\VC98\Lib
You can also make custom directories, which is recommended so you don't overwrite VS6 files, for libraries (.lib) and includes/header files (.h) and add it to the VC paths via:
You can also make custom directories, for libraries (.lib) and includes/header files (.h) and add it to the VC paths via:
Tools -> Options -> Directories -> show directories for:
a) include files (the include dir: C:\Program Files\Microsoft Visual Studio\VC98\DirectX 8.1 SDK\include )
a) include files (the include dir: C:\Program Files\Microsoft Visual Studio\VC98\DirectX 7 SDK\include )
b) library files (the lib dir, C:\Program Files\Microsoft Visual Studio\VC98\DirectX 8.1 SDK\lib )
b) library files (the lib dir, C:\Program Files\Microsoft Visual Studio\VC98\DirectX 7 SDK\lib )
NOTE: make sure that the directory for the DirectX SDK is the first one in the list, above all others, otherwise compilation will most likely fail!!
Step 4: TTD Graphics files
---Step 4
Copy the following files from Transport Tycoon Deluxe to the data folder
@@ -77,14 +80,14 @@ Copy the following files from Transport Tycoon Deluxe to the data folder
* trgcr.grf
* trghr.grf
* trgir.grf
* trgtr.grf
* trgtr.grf
Step 5: Compiling
---Step 5
Open trunk/openttd.dsw
Open trunk/ttd.dsw
Build menu > Set active configuration > Select: "openttd - Win32 Release"
Build menu > Set active configuration > Select: "ttd - Win32 Release with PNG"
Compile...
@@ -93,12 +96,10 @@ Now it should work, it worked for me :)
From r1319 you can compile branch/map in Debug mode (by Bociusz)
For compiling branch/cargo-packets you have to add cargo.c and .h to this tree's openttd.dsp
If it's not working, and you checked that you using the newest SVN (!) report to Bociusz on IRC (irc://irc.freenode.net/openttd)
If it's not working, and you checked that you using the newest SVN (!) report to Bociusz on IRC (irc://irc.freenode.net/#openttd)
Go ahead and make that patch! Happy Hacking! :)
Originally written by Dribbel
Project file updating by Bociusz
Project file updating by Bociusz

View File

@@ -11,17 +11,7 @@
<h3><a name="Landscape">Landscape</a></h3>
<p>
Five attributes hold the information about a tile.
These attributes are referred to as
"<span style="font-weight: bold;">type_height</span>",
"<span style="font-weight: bold;">m1</span>",
"<span style="font-weight: bold;">m2</span>",
"<span style="font-weight: bold;">m3</span>",
"<span style="font-weight: bold;">m4</span>" and
"<span style="font-weight: bold;">m5</span>".
The most important value is the class of a tile, stored in the upper 4 bits of the type_height array.
The lower 4 bits are used to encode the height and slope data.
For a graphical represenation of the tile-layout have a look at <a href="landscape_grid.html">Landscape grid</a> page.
Five arrays are used to encode the information of the contents of each tile. These arrays are referred to as "<span style="font-weight: bold;">map_owner</span>", "<span style="font-weight: bold;">map2</span>", "<span style="font-weight: bold;">map3_lo|_hi</span>", "<span style="font-weight: bold;">map_type_and_height</span>" and "<span style="font-weight: bold;">map5</span>". The known encodings are listed in the table below. The most important value is the class of a tile, stored in the upper 4 bits of the type_and_height array. The lower 4 bits are used to encode the height and slope data. For a graphical represenation of the tile-layout have a look at <a href="landscape_grid.html">Landscape grid</a> page.
</p>
<p>
OTTD's class-specific periodic tile processing routine is called once every +256 ticks for each tile.
@@ -32,7 +22,7 @@ OTTD's class-specific periodic tile processing routine is called once every +256
<tr><td valign=top nowrap><a name="Class0"><tt> 0 </tt></a></td><td>
<ul>
<li>m5 bits 4..0: tile type:
<li>map5 bits 4..0: tile type:
<table>
<tr><td nowrap valign=top><tt>00</tt>&nbsp; </td><td align=left>bare land</td></tr>
<tr><td nowrap valign=top><tt>01</tt>&nbsp; </td><td align=left>1/3 grass</td></tr>
@@ -40,7 +30,7 @@ OTTD's class-specific periodic tile processing routine is called once every +256
<tr><td nowrap valign=top><tt>03</tt>&nbsp; </td><td align=left>full grass</td></tr>
<tr><td nowrap valign=top><tt>07</tt>&nbsp; </td><td align=left>rough land</td></tr>
<tr><td nowrap valign=top><tt>0B</tt>&nbsp; </td><td align=left>rocks</td></tr>
<tr><td nowrap valign=top><tt>0F</tt>&nbsp; </td><td align=left>fields; type of fields in m3 bits 3..0 (legal values: 0 through 9)</td></tr>
<tr><td nowrap valign=top><tt>0F</tt>&nbsp; </td><td align=left>fields; type of fields in map3_lo bits 3..0 (legal values: 0 through 9)</td></tr>
<tr><td nowrap valign=top><tt>10</tt>&nbsp; </td><td align=left>1/4 snow</td></tr>
<tr><td nowrap valign=top><tt>11</tt>&nbsp; </td><td align=left>2/4 snow</td></tr>
<tr><td nowrap valign=top><tt>12</tt>&nbsp; </td><td align=left>3/4 snow</td></tr>
@@ -49,20 +39,20 @@ OTTD's class-specific periodic tile processing routine is called once every +256
<tr><td nowrap valign=top><tt>17</tt>&nbsp; </td><td align=left>full desert</td></tr>
</table>
</li>
<li>m5 bits 7..5: update counter, incremented on every periodic processing for tile types other than <tt>03</tt>, <tt>07</tt>, <tt>0B</tt> and <tt>10</tt> and above, on wraparound the tile is updated (for fields, the type of fields in m3 is increased, for other types the tile type in m5 is increased)
<li>map5 bits 7..6: update counter, incremented on every periodic processing for tile types other than <tt>03</tt>, <tt>07</tt>, <tt>0B</tt> and <tt>10</tt> and above, on wraparound the tile is updated (for fields, the type of fields in map3_lo is increased, for other types the tile type in map5 is increased)
<br>(for snow and desert, these bits are not used, tile is updated on every periodic processing)
</li>
<li>m1: <a href="#OwnershipInfo">owner</a> of the tile (normally <tt>10</tt>)
<li>map_owner: <a href="#OwnershipInfo">owner</a> of the tile (normally <tt>10</tt>)
</li>
<li>m4 bits 7..5: type of hedge on the SW border of the tile (1 through 6, or 0=none); bits 4..2: same for the SE border
<li>map3_hi bits 7..5: type of hedge on the SW border of the tile (1 through 6, or 0=none); bits 4..2: same for the SE border
</li>
</ul>
</td></tr>
<tr><td valign=top nowrap><a name="Class1"><tt> 1 </tt></a></td><td>
m5 bit 7 clear: railway track
map5 bit 7 clear: railway track
<ul>
<li>m5 bits 0..5: track layout: bit set = track present:
<li>map5 bits 0..5: track layout: bit set = track present:
<table>
<tr><td nowrap valign=top>bit 0: </td><td align=left>in the X direction</td></tr>
<tr><td nowrap valign=top>bit 1: </td><td align=left>in the Y direction</td></tr>
@@ -71,9 +61,9 @@ m5 bit 7 clear: railway track
<tr><td nowrap valign=top>bit 4: </td><td align=left>in the west corner (direction N-S)</td></tr>
<tr><td nowrap valign=top>bit 5: </td><td align=left>in the east corner (direction N-S)</td></tr>
</table></li>
<li>m5 bit 6 set = with signals:
<li>map5 bit 6 set = with signals:
<ul>
<li>m3 bits 7..4: bit set = signal present:
<li>map3_lo bits 7..4: bit set = signal present:
<ul>
<li>For track in the X direction:
<table>
@@ -100,8 +90,8 @@ m5 bit 7 clear: railway track
<tr><td nowrap valign=top>bit 7: </td><td align=left>signal in the N direction on the track in the W corner</td></tr>
</table></li>
</ul></li>
<li>m2 bits 7..4: bit clear = signal shows red; same bits as in m3</li>
<li>OpenTTD bits in m4:
<li>map2 bits 7..4: bit clear = signal shows red; same bits as in map3_lo</li>
<li>OpenTTD bits in map3_hi:
<table>
<tr><td nowrap valign=top>bits 1..0: </td><td align=left>type of signal:</td></tr>
<tr><td nowrap valign=top><tt>00</tt>: </td><td align=left>normal signals</td></tr>
@@ -111,9 +101,9 @@ m5 bit 7 clear: railway track
<tr><td nowrap valign=top>bit 2: </td><td align=left>set = semaphore signals, clear = light signals</td></tr>
</table></li>
</ul></li>
<li>m1: <a href="#OwnershipInfo">owner</a> of the track
<li>map_owner: <a href="#OwnershipInfo">owner</a> of the track
</li>
<li>m2 bits 0..3:
<li>map2 bits 0..3:
<table>
<tr><td nowrap valign=top><tt>0</tt>&nbsp; </td><td align=left>on bare land</td></tr>
<tr><td nowrap valign=top><tt>1</tt>&nbsp; </td><td align=left>on grass, no fences</td></tr>
@@ -129,64 +119,64 @@ m5 bit 7 clear: railway track
<tr><td nowrap valign=top><tt>B</tt>&nbsp; </td><td align=left>fence on the N side (track in the S corner)</td></tr>
<tr><td nowrap valign=top><tt>C</tt>&nbsp; </td><td align=left>on snow or desert</td></tr>
</table></li>
<li>m3 bits 0..3 = <a name="TrackType">track type</a>: <tt>0</tt> - conventional railway, <tt>1</tt> - monorail, <tt>2</tt> - maglev
<li>map3_lo bits 0..3 = <a name="TrackType">track type</a>: <tt>0</tt> - conventional railway, <tt>1</tt> - monorail, <tt>2</tt> - maglev
</li>
</ul>
m5 bits 7 and 6 set: railway depot / checkpoints
map5 bits 7 and 6 set: railway depot / checkpoints
<ul>
<li>m5 value C0..C3: railway depot
<br>m5 bits 1..0 - direction: exit towards: <tt>00</tt> = NE, <tt>01</tt> = SE, <tt>02</tt> = SW, <tt>03</tt> = NW</li>
<li>m5 value C4..C5: checkpoint
<li>map5 value C0..C3: railway depot
<br>map5 bits 1..0 - direction: exit towards: <tt>00</tt> = NE, <tt>01</tt> = SE, <tt>02</tt> = SW, <tt>03</tt> = NW</li>
<li>map5 value C4..C5: checkpoint
<br>bit 0: clear = in X direction, set = in Y direction
<br>
<br>
<li>m1: <a href="#OwnershipInfo">owner</a> of the depot / checkpoint</li>
<li>m2: For waypoints, index into the array of waypoints.</li>
<li>m3 bits 0..3 = <a href="#TrackType">track type</a></li>
<li>m3 bit 4 = use custom sprite (valid only for the checkpoint)</li>
<li>m4 bits 0..3 = ground type, as per m2 bits 0..3 for railway tiles.</li>
<li>map_owner: <a href="#OwnershipInfo">owner</a> of the depot / checkpoint</li>
<li>map3_lo bits 0..3 = <a href="#TrackType">track type</a></li>
<li>map3_lo bit 4 = use custom sprite (valid only for the checkpoint)</li>
<li>map3_hi = custom station id</li>
</ul>
</td></tr>
<tr><td valign=top nowrap><a name="Class2"><tt> 2 </tt></a></td><td>
m5 bits 7..4 clear: road
map5 bits 7..4 clear: road
<ul>
<li>m5 bits 3..0: road layout: bit set = road piece present:
<li>map5 bits 3..0: road layout: bit set = road piece present:
<table>
<tr><td nowrap valign=top>bit 0: </td><td align=left>NW piece</td></tr>
<tr><td nowrap valign=top>bit 1: </td><td align=left>SW piece</td></tr>
<tr><td nowrap valign=top>bit 2: </td><td align=left>SE piece</td></tr>
<tr><td nowrap valign=top>bit 3: </td><td align=left>NE piece</td></tr>
</table></li>
<li>m1: <a href="#OwnershipInfo">owner</a> of the road</li>
<li>m2: Index into the array of towns, 0 for non-town roads</li>
<li>m4 bits 0..3: counter for the roadworks</li>
<li>m4 bits 4..6: <tt>0</tt> - on bare land, <tt>1</tt> - on grass, <tt>2</tt> - paved, <tt>3</tt> - with streetlights, <tt>5</tt> - tree-lined, <tt>6</tt> - on grass with road works, <tt>7</tt> - paved with road works</li>
<li>m4 bit 7 set = on snow or desert</li>
<li>map_owner: <a href="#OwnershipInfo">owner</a> of the road</li>
<li>map2: Index into the array of towns, 0 for non-town roads</li>
<li>map3_hi bits 0..3: counter for the roadworks</li>
<li>map3_hi bits 4..6: <tt>0</tt> - on bare land, <tt>1</tt> - on grass, <tt>2</tt> - paved, <tt>3</tt> - with streetlights, <tt>5</tt> - tree-lined, <tt>6</tt> - on grass with road works, <tt>7</tt> - paved with road works</li>
<li>map3_hi bit 7 set = on snow or desert</li>
</ul>
m5 bit 4 set, bits 7..5 clear: level crossing
map5 bit 4 set, bits 7..5 clear: level crossing
<ul>
<li>m5 bit 3: clear - road in the X direction, set - road in the Y direction (railway track always perpendicular)</li>
<li>m5 bit 2: set if crossing lights are on</li>
<li>m1: <a href="#OwnershipInfo">owner</a> of the railway track</li>
<li>m2: Index into the array of towns, 0 for non-town roads</li>
<li>m3 bits 0..7: <a href="#OwnershipInfo">owner</a> of the road</li>
<li>m4 bits 3..0: <a href="#TrackType">track type</a></li>
<li>m4 bits 4..6: <tt>0</tt> - on bare land, <tt>1</tt> - on grass, <tt>2</tt> or higher - paved</li>
<li>m4 bit 7 set = on snow or desert</li>
<li>map5 bit 3: clear - road in the X direction, set - road in the Y direction (railway track always perpendicular)</li>
<li>map5 bit 2: set if crossing lights are on</li>
<li>map_owner: <a href="#OwnershipInfo">owner</a> of the railway track</li>
<li>map2: Index into the array of towns, 0 for non-town roads</li>
<li>map3_lo bits 0..7: <a href="#OwnershipInfo">owner</a> of the road</li>
<li>map3_hi bits 3..0: <a href="#TrackType">track type</a></li>
<li>map3_hi bits 4..6: <tt>0</tt> - on bare land, <tt>1</tt> - on grass, <tt>2</tt> or higher - paved</li>
<li>map3_hi bit 7 set = on snow or desert</li>
</ul>
m5 bit 5 set: road depot
map5 bit 5 set: road depot
<ul>
<li>m5 bits 3..0 - direction: exit towards: <tt>0</tt> = NE, <tt>1</tt> = SE, <tt>2</tt> = SW, <tt>3</tt> = NW</li>
<li>m1: <a href="#OwnershipInfo">owner</a> of the depot</li>
<li>m4 bit 7 set = on snow or desert (not displayed, but set internally)</li>
<li>map5 bits 3..0 - direction: exit towards: <tt>0</tt> = NE, <tt>1</tt> = SE, <tt>2</tt> = SW, <tt>3</tt> = NW</li>
<li>map_owner: <a href="#OwnershipInfo">owner</a> of the depot</li>
<li>map3_hi bit 7 set = on snow or desert (not displayed, but set internally)</li>
</ul>
</td></tr>
<tr><td valign=top nowrap><a name="Class3"><tt> 3 </tt></a></td><td>
Town building
<ul>
<li>m2: Index into the array of towns</li>
<li>m4: <a name="HouseTypes">town building type</a>:
<li>map2: Index into the array of towns</li>
<li>map3_hi: <a name="HouseTypes">town building type</a>:
<p><small>Note: In the climate list, 'sub-arctic' means below the <a href="#_snowline">snow line</a>, and 'snow' means above the snow line in the sub-arctic climate.</small></p>
<table>
<tr><th align=left>Type&nbsp;</th><th align=left>Size&nbsp;</th><th align=left>Climates&nbsp;</th><th align=left>Description</th></tr>
@@ -276,13 +266,13 @@ Town building
<tr><td nowrap valign=top><tt>6D</tt>&nbsp; </td><td>1&times;1</td><td>toyland</td><td align=left>piggy-bank</td></tr>
<tr><td colspan=2></td></tr> <!-- spacer -- -- (and I don't mean a walk) -->
</table></li>
<li>m3 bits 7..6: stage of construction (<tt>3</tt> = completed)</li>
<li>m5 bits 2..0: construction counter, for buildings under construction incremented on every periodic tile processing, on wraparound the stage of construction in m3 is increased</li>
<li>map3_lo bits 7..6: stage of construction (<tt>3</tt> = completed)</li>
<li>map5 bits 2..0: construction counter, for buildings under construction incremented on every periodic tile processing, on wraparound the stage of construction in map3_lo is increased</li>
<li>for large office blocks (types <tt>04</tt> and <tt>05</tt>):
<ul>
<li>m1 bits 6..0: position of the lift</li>
<li>m1 bit 7: if set the lift is moving</li>
<li>m5 bit 7: if set then m5 bits 5..0 hold the destination floor of the lift, which could be 0..6, except 1, so the building has 6 effective floors. This due to the fact that the first floor is 2 'normal' floors high. One 'normal' floor has a height of 6 lift positions.</li>
<li>map_owner bits 6..0: position of the lift</li>
<li>map_owner bit 7: if set the lift is moving</li>
<li>map5 bit 7: if set then map5 bits 5..0 hold the final position of the lift divided by 6 (valid values 0..6 except 1)</li>
</ul></li>
</ul>
</td></tr>
@@ -290,9 +280,9 @@ Town building
<tr><td valign=top nowrap><a name="Class4"><tt> 4 </tt></a></td><td>
Trees
<ul>
<li>m5 bits 7..6: number of trees minus one</li>
<li>m5 bits 2..0: growth status: <tt>0</tt>..<tt>2</tt> - one of trees is growing, <tt>3</tt> - all trees are fully grown, <tt>4</tt>..<tt>6</tt> - one of trees is withering</li>
<li>m3 bits 7..0: type of trees:
<li>map5 bits 7..6: number of trees minus one</li>
<li>map5 bits 2..0: growth status: <tt>0</tt>..<tt>2</tt> - one of trees is growing, <tt>3</tt> - all trees are fully grown, <tt>4</tt>..<tt>6</tt> - one of trees is withering</li>
<li>map3_lo bits 7..0: type of trees:
<table>
<tr><td nowrap valign=top><tt>00</tt>..<tt>0B</tt>&nbsp; </td><td align=left>temperate climate trees</td></tr>
<tr><td nowrap valign=top><tt>0C</tt>..<tt>13</tt>&nbsp; </td><td align=left>sub-arctic climate trees</td></tr>
@@ -303,24 +293,24 @@ Trees
</table>
(note: the actually displayed set of trees depends on both type and number of trees)
</li>
<li>m4 bits 7..5: type of hedge on the SW border of the tile (1 through 6, or 0=none)</li>
<li>m4 bits 4..2: type of hedge on the SE border of the tile (1 through 6, or 0=none)</li>
<li>m2 bits 5..4:
<li>map3_hi bits 7..5: type of hedge on the SW border of the tile (1 through 6, or 0=none)</li>
<li>map3_hi bits 4..2: type of hedge on the SE border of the tile (1 through 6, or 0=none)</li>
<li>map2 bits 5..4:
<table>
<tr><td nowrap valign=top><tt>0</tt>&nbsp; </td><td align=left>on grass</td></tr>
<tr><td nowrap valign=top><tt>1</tt>&nbsp; </td><td align=left>on rough land</td></tr>
<tr><td nowrap valign=top><tt>2</tt>&nbsp; </td><td align=left>on snow or desert; m2 bits 7..6 - amount of snow or desert (for desert always set to 3 in TTD)
<tr><td nowrap valign=top><tt>2</tt>&nbsp; </td><td align=left>on snow or desert; map2 bits 7..6 - amount of snow or desert (for desert always set to 3 in TTD)
</td></tr>
</table></li>
<li>m2 bits 3..0: update counter, incremented on every periodic processing, on wraparound the growth status is updated (or, if it's <tt>3</tt>, a random action is taken)</li>
<li>m1: <a href="#OwnershipInfo">owner</a> (normally <tt>10</tt>)</li>
<li>map2 bits 3..0: update counter, incremented on every periodic processing, on wraparound the growth status is updated (or, if it's <tt>3</tt>, a random action is taken)</li>
<li>map_owner: <a href="#OwnershipInfo">owner</a> (normally <tt>10</tt>)</li>
</ul>
</td></tr>
<tr><td valign=top nowrap><a name="Class5"><tt> 5 </tt></a></td><td>
Station tile
<ul>
<li>m5: tile type:
<li>map5: tile type:
<table>
<tr><td nowrap valign=top><tt>00</tt>..<tt>07</tt>&nbsp; </td><td align=left>railway station
<br><tt>00</tt>..<tt>01</tt> - open platform, <tt>02</tt>..<tt>03</tt> - open platform with station building, <tt>04</tt>....<tt>07</tt> - roofed platform
@@ -378,17 +368,17 @@ exit towards: <tt>47</tt> - NE, <tt>48</tt> - SE, <tt>49</tt> - SW, <tt>4A</tt>
<tr><td colspan=2></td></tr> <!-- spacer -->
</table>
</li>
<li>m1: <a href="#OwnershipInfo">owner</a> of the station</li>
<li>m2: index into the <a href="#_StationArray">array of stations</a></li>
<li>m3 bits 0..3: <a href="#TrackType">track type</a> for railway stations, must be 0 for all the other stations</li>
<li>m3 bit 4 = use custom sprite (valid only railway stations FOR NOW)</li>
<li>m4 = custom station id</li>
<li>map_owner: <a href="#OwnershipInfo">owner</a> of the station</li>
<li>map2: index into the <a href="#_StationArray">array of stations</a></li>
<li>map3_lo bits 0..3: <a href="#TrackType">track type</a> for railway stations, must be 0 for all the other stations</li>
<li>map3_lo bit 4 = use custom sprite (valid only railway stations FOR NOW)</li>
<li>map3_hi = custom station id</li>
</ul>
</td></tr>
<tr><td valign=top nowrap><a name="Class6"><tt> 6 </tt></a></td><td>
<ul>
<li>m5: tile type:
<li>map5: tile type:
<table>
<tr><td nowrap valign=top><tt>00</tt>&nbsp; </td><td align=left>water</td></tr>
<tr><td nowrap valign=top><tt>01</tt>&nbsp; </td><td align=left>coast or riverbank</td></tr>
@@ -419,7 +409,7 @@ exit towards: <tt>47</tt> - NE, <tt>48</tt> - SE, <tt>49</tt> - SW, <tt>4A</tt>
</table>
</td></tr>
</table></li>
<li>m1: <a href="#OwnershipInfo">owner</a> (for water and coasts normally <tt>11</tt>)</li>
<li>map_owner: <a href="#OwnershipInfo">owner</a> (for water and coasts normally <tt>11</tt>)</li>
</ul>
</td></tr>
@@ -433,19 +423,19 @@ Tiles of this class form an invisible, one tile wide border at the south (bottom
<tr><td valign=top nowrap><a name="Class8"><tt> 8 </tt></a></td><td>
Industry tile
<ul>
<li>m5: type:
<li>map5: type:
<br><small>(note: this is not the same as the <a href="#industry.type">industry type</a> stored in the <a href="#_IndustryArray">array of industries</a>)</small>
<table>
<tr><td nowrap valign=top><tt>00</tt>..<tt>06</tt>&nbsp; </td><td align=left>coal mine
<table>
<tr><td nowrap valign=top><tt>00</tt>&nbsp; </td><td align=left>wheel tower when not animated</td></tr>
<tr><td nowrap valign=top><tt>01</tt>&nbsp; </td><td align=left>wheel tower when animated; animation state in m1 bits 5..0; m1 bit 6 set = sound already generated</td></tr>
<tr><td nowrap valign=top><tt>01</tt>&nbsp; </td><td align=left>wheel tower when animated; animation state in map_owner bits 5..0; map_owner bit 6 set = sound already generated</td></tr>
</table>
</td></tr>
<tr><td nowrap valign=top><tt>07</tt>..<tt>0A</tt>&nbsp; </td><td align=left>power station
<table>
<tr><td nowrap valign=top><tt>08</tt>&nbsp; </td><td align=left>chimney</td></tr>
<tr><td nowrap valign=top><tt>0A</tt>&nbsp; </td><td align=left>transformer; animation progress in m1 bits 5..2 (valid range <tt>0</tt>..<tt>7</tt>)</td></tr>
<tr><td nowrap valign=top><tt>0A</tt>&nbsp; </td><td align=left>transformer; animation progress in map_owner bits 5..2 (valid range <tt>0</tt>..<tt>7</tt>)</td></tr>
</table>
</td></tr>
<tr><td nowrap valign=top><tt>0B</tt>..<tt>0F</tt>&nbsp; </td><td align=left>sawmill</td></tr>
@@ -459,7 +449,7 @@ Industry tile
<tr><td nowrap valign=top><tt>1D</tt>..<tt>20</tt>&nbsp; </td><td align=left>oil wells
<table>
<tr><td nowrap valign=top><tt>1D</tt>&nbsp; </td><td align=left>not animated</td></tr>
<tr><td nowrap valign=top><tt>1E</tt>..<tt>20</tt>&nbsp; </td><td align=left>various stages of animation; progress of animation in m1 bits 1..0</td></tr>
<tr><td nowrap valign=top><tt>1E</tt>..<tt>20</tt>&nbsp; </td><td align=left>various stages of animation; progress of animation in map_owner bits 1..0</td></tr>
</table>
</td></tr>
<tr><td nowrap valign=top><tt>21</tt>..<tt>26</tt>&nbsp; </td><td align=left>farm</td></tr>
@@ -468,7 +458,7 @@ Industry tile
<tr><td nowrap valign=top><tt>2F</tt>..<tt>33</tt>&nbsp; </td><td align=left>copper ore mine
<table>
<tr><td nowrap valign=top><tt>2F</tt>&nbsp; </td><td align=left>wheel tower when not animated</td></tr>
<tr><td nowrap valign=top><tt>30</tt>&nbsp; </td><td align=left>wheel tower when animated; animation state in m1 bits 5..0; m1 bit 6 set = sound already generated</td></tr>
<tr><td nowrap valign=top><tt>30</tt>&nbsp; </td><td align=left>wheel tower when animated; animation state in map_owner bits 5..0; map_owner bit 6 set = sound already generated</td></tr>
<tr><td nowrap valign=top><tt>31</tt>&nbsp; </td><td align=left>chimney</td></tr>
</table>
</td></tr>
@@ -479,7 +469,7 @@ Industry tile
<tr><td nowrap valign=top><tt>48</tt>..<tt>58</tt>&nbsp; </td><td align=left>gold mine
<table>
<tr><td nowrap valign=top><tt>4F</tt>&nbsp; </td><td align=left>wheel tower when not animated</td></tr>
<tr><td nowrap valign=top><tt>58</tt>&nbsp; </td><td align=left>wheel tower when animated; animation state in m1 bits 5..0; m1 bit 6 set = sound already generated</td></tr>
<tr><td nowrap valign=top><tt>58</tt>&nbsp; </td><td align=left>wheel tower when animated; animation state in map_owner bits 5..0; map_owner bit 6 set = sound already generated</td></tr>
</table>
</td></tr>
<tr><td nowrap valign=top><tt>59</tt>..<tt>5A</tt>&nbsp; </td><td align=left>bank (sub-arctic or sub-tropical climate)</td></tr>
@@ -506,9 +496,9 @@ Industry tile
<tr><td nowrap valign=top><tt>8A</tt>..<tt>8D</tt>&nbsp; </td><td align=left>toy shop</td></tr>
<tr><td nowrap valign=top><tt>8E</tt>..<tt>93</tt>&nbsp; </td><td align=left>toy factory
<table>
<tr><td nowrap valign=top><tt>8F</tt>&nbsp; </td><td align=left>animated part; animation state in m3 (valid range <tt>00</tt>..<tt>31</tt>)<br>
tile animation is started (m4 zeroed) on the periodic processing if <a href="#industry.didtransform">field <tt>2C</tt></a> in the corresponding industry array entry is nonzero<br>
while the animation is in progress (see the <a href="#_AnimatedTilesList">array at <tt>04328</tt></a>) m4 holds the number of animation cycles that have already taken place; when this number reaches 8 the animation is stopped</td></tr>
<tr><td nowrap valign=top><tt>8F</tt>&nbsp; </td><td align=left>animated part; animation state in map3_lo (valid range <tt>00</tt>..<tt>31</tt>)<br>
tile animation is started (map3_hi zeroed) on the periodic processing if <a href="#industry.didtransform">field <tt>2C</tt></a> in the corresponding industry array entry is nonzero<br>
while the animation is in progress (see the <a href="#_AnimatedTilesList">array at <tt>04328</tt></a>) map3_hi holds the number of animation cycles that have already taken place; when this number reaches 8 the animation is stopped</td></tr>
</table>
</td></tr>
<tr><td nowrap valign=top><tt>94</tt>..<tt>9B</tt>&nbsp; </td><td align=left>plastic fountains (various stages of cyclic animation)</td></tr>
@@ -516,69 +506,69 @@ while the animation is in progress (see the <a href="#_AnimatedTilesList">array
<tr><td nowrap valign=top><tt>A0</tt>..<tt>A3</tt>&nbsp; </td><td align=left>bubble generator
<table>
<tr><td nowrap valign=top><tt>A1</tt>&nbsp; </td><td align=left>generators</td></tr>
<tr><td nowrap valign=top><tt>A2</tt>&nbsp; </td><td align=left>bubble capture facility; animation state in m3 (valid range <tt>00</tt>..<tt>27</tt>)</td></tr>
<tr><td nowrap valign=top><tt>A2</tt>&nbsp; </td><td align=left>bubble capture facility; animation state in map3_lo (valid range <tt>00</tt>..<tt>27</tt>)</td></tr>
</table>
</td></tr>
<tr><td nowrap valign=top><tt>A4</tt>..<tt>A6</tt>&nbsp; </td><td align=left>toffee quarry
<table>
<tr><td nowrap valign=top><tt>A5</tt>&nbsp; </td><td align=left>animated part; animation state in m3 (valid range <tt>00</tt>..<tt>45</tt>)</td></tr>
<tr><td nowrap valign=top><tt>A5</tt>&nbsp; </td><td align=left>animated part; animation state in map3_lo (valid range <tt>00</tt>..<tt>45</tt>)</td></tr>
</table>
</td></tr>
<tr><td nowrap valign=top><tt>A7</tt>..<tt>AE</tt>&nbsp; </td><td align=left>sugar mine
<table>
<tr><td nowrap valign=top><tt>AE</tt>&nbsp; </td><td align=left>animated part; animation state in m3 (valid range <tt>00</tt>..<tt>5F</tt>)</td></tr>
<tr><td nowrap valign=top><tt>AE</tt>&nbsp; </td><td align=left>animated part; animation state in map3_lo (valid range <tt>00</tt>..<tt>5F</tt>)</td></tr>
</table>
</td></tr>
<tr><td colspan=2></td></tr> <!-- spacer -->
</table></li>
<li>m2: index into the <a href="#_IndustryArray">array of industries</a>
<li>map2: index into the <a href="#_IndustryArray">array of industries</a>
</li>
<li>m1 bit 7: clear = under construction
<li>map_owner bit 7: clear = under construction
<ul>
<li>m1 bits 4..2: construction counter, for buildings under construction incremented on every periodic tile processing
<li>map_owner bits 4..2: construction counter, for buildings under construction incremented on every periodic tile processing
</li>
</ul></li>
<li>m1 bits 1..0: stage of construction (<tt>3</tt> = completed), incremented when the construction counter wraps around
<li>map_owner bits 1..0: stage of construction (<tt>3</tt> = completed), incremented when the construction counter wraps around
<br>the meaning is different for some animated tiles which are never under construction (types <tt>01</tt>, <tt>1E</tt>..<tt>20</tt>, <tt>30</tt>, <tt>58</tt>; see above)
</li>
</ul>
</td></tr>
<tr><td valign=top nowrap><a name="Class9"><tt> 9 </tt></a></td><td>
m5 bits 7..4 clear: tunnel entrance/exit
map5 bits 7..4 clear: tunnel entrance/exit
<ul>
<li>m5 bits 3..2: <tt>0</tt> - railway tunnel, <tt>1</tt> - road tunnel</li>
<li>m5 bits 1..0 - direction: entrance towards: <tt>0</tt> = NE, <tt>1</tt> = SE, <tt>2</tt> = SW, <tt>3</tt> = NW</li>
<li>m1: <a href="#OwnershipInfo">owner</a> of the tunnel</li>
<li>m3 bits 3..0 = <a href="#TrackType">track type</a> for railway tunnel, must be 0 for road tunnel</li>
<li>m4 bit 7 set = on snow or desert</li>
<li>map5 bits 3..2: <tt>0</tt> - railway tunnel, <tt>1</tt> - road tunnel</li>
<li>map5 bits 1..0 - direction: entrance towards: <tt>0</tt> = NE, <tt>1</tt> = SE, <tt>2</tt> = SW, <tt>3</tt> = NW</li>
<li>map_owner: <a href="#OwnershipInfo">owner</a> of the tunnel</li>
<li>map3_lo bits 3..0 = <a href="#TrackType">track type</a> for railway tunnel, must be 0 for road tunnel</li>
<li>map3_hi bit 7 set = on snow or desert</li>
</ul>
m5 bit 7 set: bridge
map5 bit 7 set: bridge
<ul><li>
m5 bit 6 clear: bridge ending
map5 bit 6 clear: bridge ending
<ul>
<li>m5 bit 5: clear - northern, set - southern ending</li>
<li>m3 bits 3..0 = <a href="#TrackType">type of track</a> on the bridge, must be 0 for road bridge</li>
<li>m1: <a href="#OwnershipInfo">owner</a> of the bridge</li>
<li>map5 bit 5: clear - northern, set - southern ending</li>
<li>map3_lo bits 3..0 = <a href="#TrackType">type of track</a> on the bridge, must be 0 for road bridge</li>
<li>map_owner: <a href="#OwnershipInfo">owner</a> of the bridge</li>
</ul>
m5 bit 6 set: bridge middle part
map5 bit 6 set: bridge middle part
<ul>
<li>m5 bit 5 clear:
<li>map5 bit 5 clear:
<ul>
<li>m5 bits 4..3: land under bridge: <tt>0</tt> - grass, snow or desert, <tt>1</tt> - water</li>
<li>map5 bits 4..3: land under bridge: <tt>0</tt> - grass, snow or desert, <tt>1</tt> - water</li>
</ul>
m5 bit 5 set:
map5 bit 5 set:
<ul>
<li>m5 bits 4..3: transport route under bridge: <tt>0</tt> - railway, <tt>1</tt> - road</li>
<li>map5 bits 4..3: transport route under bridge: <tt>0</tt> - railway, <tt>1</tt> - road</li>
</ul>
<li>m3 bits 7..4 = <a href="#TrackType">type of track</a> on the bridge, must be 0 for road bridge</li>
<li>m3 bits 3..0 = <a href="#TrackType">type of track</a> under the bridge, if any</li>
<li>m2 bits 3..0: bridge piece (<tt>0</tt>..<tt>5</tt>)
<li>m1: <a href="#OwnershipInfo">owner</a> of the land under bridge</li>
<li>map3_lo bits 7..4 = <a href="#TrackType">type of track</a> on the bridge, must be 0 for road bridge</li>
<li>map3_lo bits 3..0 = <a href="#TrackType">type of track</a> under the bridge, if any</li>
<li>map2 bits 3..0: bridge piece (<tt>0</tt>..<tt>5</tt>)
<li>map_owner: <a href="#OwnershipInfo">owner</a> of the land under bridge</li>
</ul></li>
<li>m5 bits 2..1: <tt>0</tt> - railway bridge, <tt>1</tt> - road bridge</li>
<li>m5 bit 0: clear - bridge in the X direction, set - bridge in the Y direction</li>
<li>m2 bits 7..4: <a name="BridgeType">bridge type</a>:
<li>map5 bits 2..1: <tt>0</tt> - railway bridge, <tt>1</tt> - road bridge</li>
<li>map5 bit 0: clear - bridge in the X direction, set - bridge in the Y direction</li>
<li>map2 bits 7..4: <a name="BridgeType">bridge type</a>:
<table>
<tr><th align=left>Type&nbsp;</th><th align=left>Max. speed (mph)&nbsp;</th><th align=left>Description</th></tr>
<tr><td nowrap valign=top><tt>0</tt>&nbsp; </td><td align=center>20</td><td align=left>wooden</td></tr>
@@ -593,13 +583,13 @@ m5 bit 5 set:
<tr><td nowrap valign=top><tt>9</tt>&nbsp; </td><td align=center>160</td><td align=left>girder, steel</td></tr>
<tr><td nowrap valign=top><tt>A</tt>&nbsp; </td><td align=center>200</td><td align=left>tubular, steel</td></tr>
</table></li>
<li>m4 bit 7 set = on snow or desert</li>
<li>map3_hi bit 7 set = on snow or desert</li>
</ul>
</td></tr>
<tr><td valign=top nowrap><a name="ClassA"><tt> A </tt></a></td><td>
<ul>
<li>m5: tile type:
<li>map5: tile type:
<table>
<tr><td nowrap valign=top><tt>00</tt>&nbsp; </td><td align=left>transmitter</td></tr>
<tr><td nowrap valign=top><tt>01</tt>&nbsp; </td><td align=left>lighthouse</td></tr>
@@ -608,7 +598,7 @@ m5 bit 5 set:
<tr><td nowrap valign=top><tt>80</tt>..<tt>93</tt>&nbsp; </td><td align=left>company headquarters (5 sets of 4 tiles each, updated quarterly depending on the company performance)</td></tr>
</table>
</li>
<li>m1: <a href="#OwnershipInfo">owner</a> of the object (for lighthouses and transmitters normally <tt>10</tt>)</li>
<li>map_owner: <a href="#OwnershipInfo">owner</a> of the object (for lighthouses and transmitters normally <tt>10</tt>)</li>
</ul>
</td></tr>

View File

@@ -5,244 +5,232 @@
<meta name="Description" content="Structure of OpenTTD (OTTD) landscape arrays #2">
<title>OpenTTD Landscape Internals - #2</title>
<style type="text/css">
span.abuse { font-family: "Courier New", Courier, mono; background-color: rgb(255, 58, 31); }
span.free { font-family: "Courier New", Courier, mono; background-color: rgb(30, 178, 54); }
span.used { font-family: "Courier New", Courier, mono; }
td.bits { white-space: nowrap; text-align: center; font-family: "Courier New", Courier, mono; }
td.caption { white-space: nowrap; text-align: left; }
td li { white-space: nowrap; text-align: left; }
th { white-space: nowrap; text-align: center; }
.freebits { background-color: rgb(30, 178, 54);}
.abuse { background-color: rgb(255, 58, 31);}
</style>
</head>
<body style="direction: ltr;">
<h3 style="font-weight: bold;">Landscape</h3>
<span style="font-weight: bold;"></span>Five attributes hold the information about a tile.
<span style="font-weight: bold;"></span>Five arrays are used to encode the information of the contents of the tile.
This can be seen in the <a href="landscape.html">Landscape</a> document. This page tries to give an overview of used and free bits of
the array so you can quickly see what is used and what is not.
<ul>
<li><span style="font-weight: bold;"><span class="free">O</span></span> - bit is free</li>
<li><span style="font-weight: bold;"><span class="used">X</span></span> - bit is used</li>
<li><span style="font-weight: bold;"><span class="abuse">&nbsp;</span></span> - bit of attribute is abused for different purposes</li>
<li><span style="font-weight: bold;"><span class="freebits">O</span></span> - bit is free</li>
<li><span style="font-weight: bold;">X</span> - bit is used</li>
<li><span style="font-weight: bold;"><span class="abuse">&nbsp;&nbsp;&nbsp;</span></span> - bit of _map_* is abused for different purposes</li>
</ul>
<p>
<ul>
<li><span style="font-weight: bold;">type_height</span> - 8 bits in size, stores tile height (lower 4 bits) and tile class (upper 4 bits)</li>
<li><span style="font-weight: bold;">m1</span> - 8 bits in size, used to identify the owner of that tile (eg piece of rail, bridge, etc.)</li>
<li><span style="font-weight: bold;">m2</span> - 16 bits in size, used to identify the index of the given tile (object) in the (object-)array</li>
<li><span style="font-weight: bold;">m3</span> - 8 bits in size, is used for general storage</li>
<li><span style="font-weight: bold;">m4</span> - 8 bits in size, is used for general storage</li>
<li><span style="font-weight: bold;">m5</span> - 8 bits in size, is used for general storage</li>
<li><span style="font-weight: bold;">_map_owner[]</span> - 8 bits in size, used to identify the owner of that tile (eg piece of rail, bridge, etc.).</li>
<li><span style="font-weight: bold;">_map2[]</span> - 16 bits in size, used to identify the index of the given tile (object) in the (object-)array.</li>
<li><span style="font-weight: bold;">_map3[]</span> - 16 bits in size, which is split up into _map3lo[] and _map3hi[] is used for general storage.</li>
<li><span style="font-weight: bold;">_map_type_and_height[]</span> - 8 bits in size, stores tile height (lower 4 bits) and tile class (upper 4 bits).</li>
<li><span style="font-weight: bold;">_map5[]</span> - 8 bits in size, is used for general storage.</li>
</ul>
<table align=center border="1" cellpadding="2" cellspacing="2">
<table style="text-align: left;" border="1" cellpadding="2"
cellspacing="2" width="100%">
<tbody>
<tr>
<th colspan=2>class</th>
<th>m1 (8)</th>
<th>m2 (16)</th>
<th>m3 (8)</th>
<th>m4 (8)</th>
<th>type_height (8)</th>
<th>m5 (8)</th>
<th style="white-space: nowrap; text-align: left;">class</th>
<th style="white-space: nowrap; text-align: center;">_map_owner[L1] (8)</th>
<th style="white-space: nowrap; text-align: center;">_map2[L2] (16)</th>
<th style="white-space: nowrap; text-align: center;">_map3[lo&amp; hi,L3] (16)</th>
<th style="white-space: nowrap; text-align: center;">_map_type_and_height[L4] (8)</th>
<th style="white-space: nowrap; text-align: center;">_map5[L5] (8)</th>
</tr>
<tr>
<td colspan=2 class="caption">bits</td>
<td class="bits">7654 3210</td>
<td class="bits">FEDC BA98 7654 3210</td>
<td class="bits">7654 3210</td>
<td class="bits">7654 3210</td>
<td class="bits">7654 3210</td>
<td class="bits">7654 3210</td>
<td style="white-space: nowrap; text-align: left;">(0) ground</td>
<td style="white-space: nowrap; text-align: center;">XXXX XXXX</td>
<td style="white-space: nowrap; text-align: center;"><span class="freebits">OOOO OOOO OOOO OOOO</span></td>
<td style="white-space: nowrap; text-align: center;">XXXX <span class="freebits">OOOO OO</span>XX XXXX</td>
<td style="white-space: nowrap; text-align: center;">XXXX&nbsp;&nbsp;&nbsp;&nbsp;XXXX</td>
<td style="white-space: nowrap; text-align: center;">XXXX X<span class="freebits">O</span>XX</td>
</tr>
<tr>
<td>0</td>
<td class="caption">ground</td>
<td class="bits">XXXX XXXX</td>
<td class="bits"><span class="free">OOOO OOOO OOOO OOOO</span></td>
<td class="bits"><span class="free">OOOO</span> XXXX</td>
<td class="bits">XXXX XX<span class="free">OO</span></td>
<td class="bits">XXXX XXXX</td>
<td class="bits">XXXX XXXX</td>
<td style="white-space: nowrap; text-align: left;">(1) rail</td>
<td style="white-space: nowrap; text-align: center;"><span class="abuse">XXXX XXXX</span></td>
<td style="white-space: nowrap; text-align: center;">XXXX XXXX <span class="freebits">OOOO OOOO</span><br>
</td>
<td style="white-space: nowrap; text-align: center;">XXXX XXXX XXX<span class="freebits">O OOOO</span><br>
</td>
<td style="white-space: nowrap; text-align: center;">XXXX&nbsp;&nbsp;&nbsp;&nbsp;XXXX</td>
<td style="white-space: nowrap; text-align: center;">XXXX XXXX<br>
</td>
</tr>
<tr>
<td rowspan=3>1</td>
<td class="caption">rail</td>
<td class="bits">XXXX XXXX</td>
<td class="bits"><span class="free">OOOO OOOO</span> XXXX XXXX</td>
<td class="bits">XXXX XXXX</td>
<td class="bits"><span class="free">OOOO O</span>XXX</td>
<td class="bits">XXXX XXXX</td>
<td class="bits">XXXX XXXX</td>
<td>
<ul>
<li style="white-space: nowrap; text-align: left;">depot/checkpoint</li>
</ul>
</td>
<td style="text-align: center;">-inherit-</td>
<td style="text-align: center;"><span class="freebits">OOOO OOOO OOOO OOOO</span></td>
<td style="text-align: center;">XXXX X<span class="freebits">OOO</span> XXXX XXXX</td>
<td style="text-align: center;">-inherit-</td>
<td style="white-space: nowrap; text-align: center;">XXX<span class="freebits">O OO</span>XX</td>
</tr>
<tr>
<td class="caption">depot</td>
<td class="bits">-inherit-</td>
<td class="bits"><span class="free">OOOO OOOO OOOO OOOO</span></td>
<td class="bits"><span class="free">OOOO</span> XXXX</td>
<td class="bits"><span class="free">OOOO</span> XXXX</td>
<td class="bits">-inherit-</td>
<td class="bits">XX<span class="free">OO O</span>XXX</td>
<td style="white-space: nowrap; text-align: left;">(2) road</td>
<td style="text-align: center;">XXXX XXXX</td>
<td style="text-align: center;"><span class="abuse">XXXX XXXX XXXX XXXX</span></td>
<td style="text-align: center;"><span class="freebits">OOOO OOOO</span> XXXX XXXX</td>
<td style="text-align: center;">XXXX&nbsp;&nbsp;&nbsp;&nbsp;XXXX</td>
<td style="text-align: center;">XXXX XXXX</td>
</tr>
<tr>
<td class="caption">waypoint</td>
<td class="bits">-inherit-</td>
<td class="bits">XXXX XXXX XXXX XXXX</td>
<td class="bits"><span class="free">OOO</span>X XXXX</td>
<td class="bits"><span class="free">OOOO</span> XXXX</td>
<td class="bits">-inherit-</td>
<td class="bits">XX<span class="free">OO O</span>XXX</td>
<td>
<ul>
<li style="white-space: nowrap; text-align: left;">level crossing</li>
</ul>
</td>
<td style="text-align: center;">-inherit-</td>
<td style="text-align: center;"><span class="abuse">XXXX XXXX XXXX XXXX</span></td>
<td style="text-align: center;">XXXX XXXX XXXX XXXX</td>
<td style="text-align: center;">-inherit-</td>
<td style="text-align: center;"><span class="freebits">OO</span>XX XXXX</td>
</tr>
<tr>
<td rowspan=3>2</td>
<td class="caption">road</td>
<td class="bits">XXXX XXXX</td>
<td class="bits">XXXX XXXX XXXX XXXX</td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
<td class="bits">XXXX XXXX</td>
<td class="bits">XXXX XXXX</td>
<td class="bits">XXXX XXXX</td>
<td>
<ul>
<li style="white-space: nowrap; text-align: left;">road depot</li>
</ul>
</td>
<td style="text-align: center;">-inherit-</td>
<td style="text-align: center;"><span class="freebits">OOOO OOOO OOOO OOOO</span></td>
<td style="text-align: center;"><span class="freebits">OOOO OOOO OOOO OOO</span>X</td>
<td style="text-align: center;">-inherit-</td>
<td style="text-align: center;">XXXX XXXX</td>
</tr>
<tr>
<td class="caption">level crossing</td>
<td class="bits">-inherit-</td>
<td class="bits">-inherit-</td>
<td class="bits">XXXX XXXX</td>
<td class="bits">XXXX XXXX</td>
<td class="bits">-inherit-</td>
<td class="bits">XXXX XX<span class="free">OO</span></td>
<td style="white-space: nowrap; text-align: left;">(3) town</td>
<td style="white-space: nowrap; text-align: center;"><span class="abuse">XXXX XXXX</span></td>
<td style="white-space: nowrap; text-align: center;">XXXX XXXX XXXX XXXX<br>
</td>
<td style="white-space: nowrap; text-align: center;">XXXX XXXX XXXX XXXX<br>
</td>
<td style="white-space: nowrap; text-align: center;">XXXX&nbsp;&nbsp;&nbsp;&nbsp;XXXX</td>
<td style="white-space: nowrap; text-align: center;">XXXX XX<span class="freebits">O</span>X</td>
</tr>
<tr>
<td class="caption">road depot</td>
<td class="bits">-inherit-</td>
<td class="bits"><span class="free">OOOO OOOO OOOO OOOO</span></td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
<td class="bits">X<span class="free">OOO OOOO</span></td>
<td class="bits">-inherit-</td>
<td class="bits">XXXX XXXX</td>
<td style="white-space: nowrap; text-align: left;">(4) trees</td>
<td style="white-space: nowrap; text-align: center;"><span class="abuse">XXXX XXXX</span></td>
<td style="white-space: nowrap; text-align: center;">XXXX XX<span class="freebits">OO OOOO OOOO</span></td>
<td style="white-space: nowrap; text-align: center;">XXXX XXXX <span class="freebits">OO</span>XX XXXX</td>
<td style="white-space: nowrap; text-align: center;">XXXX&nbsp;&nbsp;&nbsp;&nbsp;XXXX</td>
<td style="white-space: nowrap; text-align: center;">XXX<span class="freebits">O OO</span>XX</td>
</tr>
<tr>
<td>3</td>
<td class="caption">town</td>
<td class="bits"><span class="abuse">XXXX XXXX</span></td>
<td class="bits">XXXX XXXX XXXX XXXX</td>
<td class="bits">XX<span class="free">OO OOOO</span></td>
<td class="bits">XXXX XXXX</td>
<td class="bits">XXXX XXXX</td>
<td class="bits">X<span class="free">O</span>XX XXXX</td>
<td style="white-space: nowrap; text-align: left;">(5) station</td>
<td style="white-space: nowrap; text-align: center;">XXXX XXXX</td>
<td style="white-space: nowrap; text-align: center;">XXXX XXXX XXXX XXXX</td>
<td style="white-space: nowrap; text-align: center;">XXXX X<span class="freebits">OOO</span> XXXX XXXX</td>
<td style="white-space: nowrap; text-align: center;">XXXX&nbsp;&nbsp;&nbsp;&nbsp;XXXX</td>
<td style="white-space: nowrap; text-align: center;">XXXX XXXX</td>
</tr>
<tr>
<td>4</td>
<td class="caption">trees</td>
<td class="bits">XXXX XXXX</td>
<td class="bits"><span class="free">OOOO OOOO</span> XXXX XXXX</td>
<td class="bits">XXXX XXXX</td>
<td class="bits">XXXX XX<span class="free">OO</span></td>
<td class="bits">XXXX XXXX</td>
<td class="bits">XX<span class="free">OO O</span>XXX</td>
<td style="white-space: nowrap; text-align: left;">(6) water</td>
<td style="white-space: nowrap; text-align: center;">XXXX XXXX</td>
<td style="white-space: nowrap; text-align: center;"><span class="freebits">OOOO OOOO OOOO OOOO</span></td>
<td style="white-space: nowrap; text-align: center;"><span class="freebits">OOOO OOOO OOOO OOOO</span></td>
<td style="white-space: nowrap; text-align: center;">XXXX&nbsp;&nbsp;&nbsp;&nbsp;XXXX</td>
<td style="white-space: nowrap; text-align: center;">XXXX XXXX</td>
</tr>
<tr>
<td>5</td>
<td class="caption">station</td>
<td class="bits">XXXX XXXX</td>
<td class="bits">XXXX XXXX XXXX XXXX</td>
<td class="bits"><span class="free">OOO</span>X XXXX</td>
<td class="bits">XXXX XXXX</td>
<td class="bits">XXXX XXXX</td>
<td class="bits">XXXX XXXX</td>
<td style="white-space: nowrap; text-align: left;">(8) industry</td>
<td style="white-space: nowrap; text-align: center;"><span class="abuse">XXXX X</span><span class="freebits">OO</span><span class="abuse">X</span></td>
<td style="white-space: nowrap; text-align: center;">XXXX XXXX XXXX XXXX</td>
<td style="white-space: nowrap; text-align: center;"><span class="freebits">OOOO OOOO OOOO OOOO</span></td>
<td style="white-space: nowrap; text-align: center;">XXXX&nbsp;&nbsp;&nbsp;&nbsp;XXXX</td>
<td style="white-space: nowrap; text-align: center;">XXXX XXXX</td>
</tr>
<tr>
<td>6</td>
<td class="caption">water</td>
<td class="bits">XXXX XXXX</td>
<td class="bits"><span class="free">OOOO OOOO OOOO OOOO</span></td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
<td class="bits">XXXX XXXX</td>
<td class="bits">XXXX XXXX</td>
<td>
<ul>
<li style="white-space: nowrap; text-align: left;">bubble/sugar/toffee</li>
</ul>
</td>
<td style="text-align: center;">-inherit-</td>
<td style="text-align: center;">-inherit-</td>
<td style="text-align: center;">XXXX XXXX <span class="freebits">OOOO OOOO</span></td>
<td style="text-align: center;">-inherit-</td>
<td style="text-align: center;">-inherit-</td>
</tr>
<tr>
<td rowspan=6>8</td>
<td class="caption">industry</td>
<td class="bits"><span class="abuse">X</span><span class="free">OO</span><span class="abuse">X XXXX</span></td>
<td class="bits">XXXX XXXX XXXX XXXX</td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
<td class="bits">XXXX XXXX</td>
<td class="bits">XXXX XXXX</td>
<td>
<ul>
<li style="white-space: nowrap; text-align: left;">toy factory</li>
</ul>
</td>
<td style="text-align: center;">-inherit-</td>
<td style="text-align: center;">-inherit-</td>
<td style="text-align: center;">XXXX XXXX XXXX XXXX</td>
<td style="text-align: center;">-inherit-</td>
<td style="text-align: center;">-inherit-</td>
</tr>
<tr>
<td>bubble/sugar/toffee</td>
<td class="bits"><span class="abuse">X</span><span class="free">OOO OOOO</span></td>
<td class="bits">-inherit-</td>
<td class="bits">XXXX XXXX</td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
<td class="bits">-inherit-</td>
<td class="bits">-inherit-</td>
<td>
<ul>
<li style="white-space: nowrap; text-align: left;">gold/copper/coal</li>
</ul>
</td>
<td style="text-align: center;">XXXX XXXX</td>
<td style="text-align: center;">-inherit-</td>
<td style="text-align: center;">-inherit-</td>
<td style="text-align: center;">-inherit-</td>
<td style="text-align: center;">-inherit-</td>
</tr>
<tr>
<td>toy factory</td>
<td class="bits"><span class="abuse">X</span><span class="free">OOO OOOO</span></td>
<td class="bits">-inherit-</td>
<td class="bits">XXXX XXXX</td>
<td class="bits">XXXX XXXX</td>
<td class="bits">-inherit-</td>
<td class="bits">-inherit-</td>
<td>
<ul>
<li style="white-space: nowrap; text-align: left;">oil wells</li>
</ul>
</td>
<td style="text-align: center;">-inherit-</td>
<td style="text-align: center;">-inherit-</td>
<td style="text-align: center;">-inherit-</td>
<td style="text-align: center;">-inherit-</td>
<td style="text-align: center;">-inherit-</td>
</tr>
<tr>
<td>gold/copper/coal</td>
<td class="bits"><span class="abuse">XX</span><span class="free">OO OO</span><span class="abuse">XX</span></td>
<td class="bits">-inherit-</td>
<td class="bits">-inherit-</td>
<td class="bits">-inherit-</td>
<td class="bits">-inherit-</td>
<td class="bits">-inherit-</td>
<td>
<ul>
<li style="white-space: nowrap; text-align: left;">power station</li>
</ul>
</td>
<td style="text-align: center;">XXXX XX<span class="freebits">O</span>X</td>
<td style="text-align: center;">-inherit-</td>
<td style="text-align: center;">-inherit-</td>
<td style="text-align: center;">-inherit-</td>
<td style="text-align: center;">-inherit-</td>
</tr>
<tr>
<td>oil wells</td>
<td class="bits"><span class="abuse">X</span><span class="free">OOO OO</span><span class="abuse">XX</span></td>
<td class="bits">-inherit-</td>
<td class="bits">-inherit-</td>
<td class="bits">-inherit-</td>
<td class="bits">-inherit-</td>
<td class="bits">-inherit-</td>
<td style="white-space: nowrap; text-align: left;">(9) tunnel</td>
<td style="white-space: nowrap; text-align: center;">XXXX XXXX</td>
<td style="white-space: nowrap; text-align: center;"><span class="freebits">OOOO OOOO OOOO OOOO</span></td>
<td style="white-space: nowrap; text-align: center;">XXXX <span class="freebits">OOOO OOOO OOO</span>X</td>
<td style="white-space: nowrap; text-align: center;">XXXX&nbsp;&nbsp;&nbsp;&nbsp;XXXX</td>
<td style="white-space: nowrap; text-align: center;">XXXX XXXX</td>
</tr>
<tr>
<td>power station</td>
<td class="bits"><span class="abuse">X</span><span class="free">O</span><span class="abuse">XX XX</span><span class="free">OO</span></td>
<td class="bits">-inherit-</td>
<td class="bits">-inherit-</td>
<td class="bits">-inherit-</td>
<td class="bits">-inherit-</td>
<td class="bits">-inherit-</td>
<td>
<ul>
<li style="white-space: nowrap; text-align: left;">bridge</li>
</ul>
</td>
<td style="text-align: center;">XXXX XXXX</td>
<td style="text-align: center;"><span class="abuse">XXXX XXXX</span> <span class="freebits">OOOO OOOO</span></td>
<td style="text-align: center;">XXXX XXXX <span class="freebits">OOOO OOO</span>X</td>
<td style="text-align: center;">XXXX&nbsp;&nbsp;&nbsp;&nbsp;XXXX</td>
<td style="text-align: center;">XXXX XXXX</td>
</tr>
<tr>
<td rowspan=2>9</td>
<td class="caption">tunnel</td>
<td class="bits">XXXX XXXX</td>
<td class="bits"><span class="free">OOOO OOOO OOOO OOOO</span></td>
<td class="bits"><span class="free">OOOO</span> XXXX</td>
<td class="bits">X<span class="free">OOO OOOO</span></td>
<td class="bits">XXXX XXXX</td>
<td class="bits">XXXX XXXX</td>
</tr>
<tr>
<td>bridge</td>
<td class="bits">XXXX XXXX</td>
<td class="bits"><span class="free">OOOO OOOO</span> <span class="abuse">XXXX XXXX</span></td>
<td class="bits">XXXX XXXX</td>
<td class="bits">X<span class="free">OOO OOOO</span></td>
<td class="bits">XXXX XXXX</td>
<td class="bits">XXXX XXXX</td>
</tr>
<tr>
<td>A</td>
<td class="caption">various (HQ)</td>
<td class="bits">XXXX XXXX</td>
<td class="bits"><span class="free">OOOO OOOO OOOO OOOO</span></td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
<td class="bits">XXXX XXXX</td>
<td class="bits">XXXX XXXX</td>
<td style="white-space: nowrap; text-align: left;">(10) various (HQ)</td>
<td style="white-space: nowrap; text-align: center;">XXXX XXXX</td>
<td style="white-space: nowrap; text-align: center;"><span class="freebits">OOOO OOOO OOOO OOOO</span></td>
<td style="white-space: nowrap; text-align: center;"><span class="freebits">OOOO OOOO OOOO OOOO</span></td>
<td style="white-space: nowrap; text-align: center;">XXXX&nbsp;&nbsp;&nbsp;&nbsp;XXXX</td>
<td style="white-space: nowrap; text-align: center;">XXXX XXXX</td>
</tr>
</tbody>
</table>

View File

@@ -1,68 +1,50 @@
.\" Hey, EMACS: -*- nroff -*-
.\" First parameter, NAME, should be all caps
.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
.\" other parameters are allowed: see man(7), man(1)
.TH OPENTTD 6 "September 16, 2004"
.\" Please adjust this date whenever revising the manpage.
.Dd March June 28, 2006
.Dt OPENTTD 6
.Sh NAME
.Nm openttd
.Nd An open source clone of the Microprose game "Transport Tycoon Deluxe"
.Sh SYNOPSIS
.Nm
.Op Fl Defhi
.Op Fl G Ar seed
.Op Fl d Ar [level | cat=lvl[, ...]]
.Op Fl g Ar [savegame]
.Op Fl n Ar [host[#player][:port]]
.Op Fl r Ar widthxheight
.Op Fl t Ar date
.Op Fl m Ar driver
.Op Fl s Ar driver
.Op Fl v Ar driver
.Sh OPTIONS
.Bl -tag -width ".Fl n Ar host[#player][:port]"
.It Fl D
Start a dedicated server
.It Fl G Ar seed
Seed the pseudo random number generator
.It Fl d Ar [level]
Set debug verbosity for all categories to
.Ar level
or 1 if omitted
.It Fl d Ar cat=level[, ...]
Set debug verbosity for a specific category
.It Fl e
Start in world editor mode
.It Fl f
Fork into background (dedicated only, see
.Fl D )
.It Fl g Ar [savegame]
Load
.Ar savegame
at start or start a new game if omitted
.It Fl h
Display a summary of all options and available drivers
.It Fl i
Force to use the DOS palette (use this if you see a lot of magenta)
.It Fl m Ar driver
Set the music driver, see
.Fl h
.It Fl n
Start a network server
.It Fl n Ar host[#player][:port]
Join a network game, optionally specify player to play as and port to connect to
.It Fl r Ar widthxheight
Set the resolution
.It Fl s Ar driver
Set the sound driver, see
.Fl h
.It Fl t Ar date
Set the starting date
.It Fl v Ar driver
Set the video driver, see
.Fl h
.El
.Sh SEE ALSO
http://wiki.openttd.org/
.Sh HISTORY
Transport Tycoon Deluxe was written by Chris Sawyer and published by Microprose.
.Nm
is a free reimplementation.
.\"
.\" Some roff macros, for reference:
.\" .nh disable hyphenation
.\" .hy enable hyphenation
.\" .ad l left justify
.\" .ad b justify to both left and right margins
.\" .nf disable filling
.\" .fi enable filling
.\" .br insert line break
.\" .sp <n> insert n+1 empty lines
.\" for manpage-specific macros, see man(7)
.SH NAME
openttd \- An open source clone of the Microprose game "Transport Tycoon Deluxe"
.SH SYNOPSIS
.B openttd
.RI [ options ]
.br
.SH DESCRIPTION
Unfortunately, there is no real manpage for openttd yet. Hopefully someone
will write one soon. For now you should use
.B openttd -h
for more information, or check our Wiki manual: http://wiki.openttd.org/
.PP
.\" TeX users may be more comfortable with the \fB<whatever>\fP and
.\" \fI<whatever>\fP escape sequences to invoke bold face and italics,
.\" respectively.
.\" \fBopenttd\fP is a program that...
.SH OPTIONS
Wouldn't we like to have something here?
.\" below are commented out, to serve as layout examples for when somebody
.\" does actually fill this page
.\" .TP
.\" .B \-h, \-\-help
.\" Show summary of options.
.\" .TP
.\" .B \-v, \-\-version
.\" Show version of program.
.\" .SH SEE ALSO
.\" .BR bar (1),
.\" .BR baz (1).
.br
.SH AUTHOR
This manual page was written by Matthijs Kooijman <matthijs@katherina.student.utwente.nl>,
for the Debian project (but may be used by others).

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

38
docs/textcolor.txt Normal file
View File

@@ -0,0 +1,38 @@
0,9,10,2,3,13,9,9,0,10,4,15,6,11,14,1
dark blue=0 =0
pale_green=1 =9
pink=2 =10
yellow=3 =2
red=4 =3
light blue=5 =13
green=6 =9
dark green=7 =9
blue=8 =0
cream=9 =10
mauve=10 =4
purple=11 =15
orange=12 =6
brown=13 =11
grey=14 =14
white=15 =1
=blue=0
=white=1
=yellow=2
=red=3
=blue=4
=grey=5
=orange=6
=green=7
=light yellow=8
=light green=9
=cream=10
=brown=11
=white=12
=light blue=13
=dark grey=14
=purple=15
=black=16
=dark green=17=not good
=dark grey=21

224
driver.c
View File

@@ -1,224 +0,0 @@
/* $Id$ */
#include "stdafx.h"
#include "openttd.h"
#include "debug.h"
#include "driver.h"
#include "functions.h"
#include "hal.h"
#include "string.h"
#include "music/bemidi.h"
#include "music/dmusic.h"
#include "music/extmidi.h"
#include "music/null_m.h"
#include "music/os2_m.h"
#include "music/win32_m.h"
#include "music/qtmidi.h"
#include "sound/null_s.h"
#include "sound/sdl_s.h"
#include "sound/cocoa_s.h"
#include "sound/win32_s.h"
#include "video/dedicated_v.h"
#include "video/null_v.h"
#include "video/sdl_v.h"
#include "video/cocoa_v.h"
#include "video/win32_v.h"
typedef struct DriverDesc {
const char* name;
const char* longname;
const HalCommonDriver* drv;
} DriverDesc;
typedef struct DriverClass {
const DriverDesc *descs;
const char *name;
const HalCommonDriver** drv;
} DriverClass;
#define M(x, y, z) { x, y, (const HalCommonDriver *)(void *)z }
static const DriverDesc _music_driver_descs[] = {
#ifdef __BEOS__
M("bemidi", "BeOS MIDI Driver", &_bemidi_music_driver),
#endif
#ifdef __OS2__
M("os2", "OS/2 Music Driver", &_os2_music_driver),
#endif
#ifdef WIN32_ENABLE_DIRECTMUSIC_SUPPORT
M("dmusic", "DirectMusic MIDI Driver", &_dmusic_midi_driver),
#endif
#ifdef WIN32
M("win32", "Win32 MIDI Driver", &_win32_music_driver),
#endif
#if defined(__APPLE__) && !defined(DEDICATED)
M("qt", "QuickTime MIDI Driver", &_qtime_music_driver),
#endif
#ifdef UNIX
#if !defined(__MORPHOS__) && !defined(__AMIGA__)
M("extmidi", "External MIDI Driver", &_extmidi_music_driver),
#endif
#endif
M("null", "Null Music Driver", &_null_music_driver),
M(NULL, NULL, NULL)
};
static const DriverDesc _sound_driver_descs[] = {
#ifdef WIN32
M("win32", "Win32 WaveOut Driver", &_win32_sound_driver),
#endif
#ifdef WITH_SDL
M("sdl", "SDL Sound Driver", &_sdl_sound_driver),
#endif
#ifdef WITH_COCOA
M("cocoa", "Cocoa Sound Driver", &_cocoa_sound_driver),
#endif
M("null", "Null Sound Driver", &_null_sound_driver),
M(NULL, NULL, NULL)
};
static const DriverDesc _video_driver_descs[] = {
#ifdef WIN32
M("win32", "Win32 GDI Video Driver", &_win32_video_driver),
#endif
#ifdef WITH_SDL
M("sdl", "SDL Video Driver", &_sdl_video_driver),
#endif
#ifdef WITH_COCOA
M("cocoa", "Cocoa Video Driver", &_cocoa_video_driver),
#endif
M("null", "Null Video Driver", &_null_video_driver),
#ifdef ENABLE_NETWORK
M("dedicated", "Dedicated Video Driver", &_dedicated_video_driver),
#endif
M(NULL, NULL, NULL)
};
#undef M
#define M(x, y, z) { x, y, (const HalCommonDriver **)(void *)z }
static const DriverClass _driver_classes[] = {
M(_video_driver_descs, "video", &_video_driver),
M(_sound_driver_descs, "sound", &_sound_driver),
M(_music_driver_descs, "music", &_music_driver)
};
#undef M
static const DriverDesc* GetDriverByName(const DriverDesc* dd, const char* name)
{
for (; dd->name != NULL; dd++) {
if (strcmp(dd->name, name) == 0) return dd;
}
return NULL;
}
void LoadDriver(int driver, const char *name)
{
const DriverClass *dc = &_driver_classes[driver];
const DriverDesc *dd;
const char *err;
if (*name == '\0') {
for (dd = dc->descs; dd->name != NULL; dd++) {
err = dd->drv->start(NULL);
if (err == NULL) break;
DEBUG(driver, 1) ("Probing %s driver \"%s\" failed with error: %s",
dc->name, dd->name, err
);
}
if (dd->name == NULL) {
error("Couldn't find any suitable %s driver", dc->name);
}
DEBUG(driver, 1)
("Successfully probed %s driver \"%s\"", dc->name, dd->name);
*dc->drv = dd->drv;
} else {
char* parm;
char buffer[256];
const char* parms[32];
// Extract the driver name and put parameter list in parm
ttd_strlcpy(buffer, name, sizeof(buffer));
parm = strchr(buffer, ':');
parms[0] = NULL;
if (parm != NULL) {
uint np = 0;
// Tokenize the parm.
do {
*parm++ = '\0';
if (np < lengthof(parms) - 1)
parms[np++] = parm;
while (*parm != '\0' && *parm != ',')
parm++;
} while (*parm == ',');
parms[np] = NULL;
}
dd = GetDriverByName(dc->descs, buffer);
if (dd == NULL)
error("No such %s driver: %s\n", dc->name, buffer);
if (*dc->drv != NULL) (*dc->drv)->stop();
*dc->drv = NULL;
err = dd->drv->start(parms);
if (err != NULL) {
error("Unable to load driver %s(%s). The error was: %s\n",
dd->name, dd->longname, err
);
}
*dc->drv = dd->drv;
}
}
static const char* GetDriverParam(const char* const* parm, const char* name)
{
size_t len;
if (parm == NULL) return NULL;
len = strlen(name);
for (; *parm != NULL; parm++) {
const char* p = *parm;
if (strncmp(p, name, len) == 0) {
if (p[len] == '=') return p + len + 1;
if (p[len] == '\0') return p + len;
}
}
return NULL;
}
bool GetDriverParamBool(const char* const* parm, const char* name)
{
return GetDriverParam(parm, name) != NULL;
}
int GetDriverParamInt(const char* const* parm, const char* name, int def)
{
const char* p = GetDriverParam(parm, name);
return p != NULL ? atoi(p) : def;
}
char *GetDriverList(char* p)
{
const DriverClass* dc;
for (dc = _driver_classes; dc != endof(_driver_classes); dc++) {
const DriverDesc* dd;
p += sprintf(p, "List of %s drivers:\n", dc->name);
for (dd = dc->descs; dd->name != NULL; dd++) {
p += sprintf(p, "%10s: %s\n", dd->name, dd->longname);
}
p += sprintf(p, "\n");
}
return p;
}

View File

@@ -1,13 +0,0 @@
/* $Id$ */
#ifndef DRIVER_H
#define DRIVER_H
void LoadDriver(int driver, const char *name);
bool GetDriverParamBool(const char* const* parm, const char* name);
int GetDriverParamInt(const char* const* parm, const char* name, int def);
char *GetDriverList(char* p);
#endif /* DRIVER_H */

View File

@@ -1,67 +1,60 @@
/* $Id$ */
#include "stdafx.h"
#include "openttd.h"
#include "ttd.h"
#include "table/strings.h"
#include "functions.h"
#include "viewport.h"
#include "command.h"
#include "table/sprites.h"
static void DrawTile_Dummy(TileInfo *ti)
{
DrawGroundSpriteAt(SPR_SHADOW_CELL, ti->x, ti->y, ti->z);
DrawGroundSpriteAt(0x3EC, ti->x, ti->y, ti->z);
}
static uint GetSlopeZ_Dummy(const TileInfo* ti)
{
return 0;
static uint GetSlopeZ_Dummy(TileInfo *ti) {
return GetPartialZ(ti->x&0xF, ti->y&0xF, ti->tileh) + ti->z;
}
static uint GetSlopeTileh_Dummy(const TileInfo* ti)
{
return 0;
static uint GetSlopeTileh_Dummy(TileInfo *ti) {
return ti->tileh;
}
static int32 ClearTile_Dummy(TileIndex tile, byte flags)
{
static int32 ClearTile_Dummy(uint tile, byte flags) {
return_cmd_error(STR_0001_OFF_EDGE_OF_MAP);
}
static void GetAcceptedCargo_Dummy(TileIndex tile, AcceptedCargo ac)
static void GetAcceptedCargo_Dummy(uint tile, AcceptedCargo ac)
{
/* not used */
}
static void GetTileDesc_Dummy(TileIndex tile, TileDesc *td)
static void GetTileDesc_Dummy(uint tile, TileDesc *td)
{
td->str = STR_EMPTY;
td->owner = OWNER_NONE;
}
static void AnimateTile_Dummy(TileIndex tile)
static void AnimateTile_Dummy(uint tile)
{
/* not used */
}
static void TileLoop_Dummy(TileIndex tile)
static void TileLoop_Dummy(uint tile)
{
/* not used */
}
static void ClickTile_Dummy(TileIndex tile)
static void ClickTile_Dummy(uint tile)
{
/* not used */
}
static void ChangeTileOwner_Dummy(TileIndex tile, PlayerID old_player, PlayerID new_player)
static void ChangeTileOwner_Dummy(uint tile, byte old_player, byte new_player)
{
/* not used */
}
static uint32 GetTileTrackStatus_Dummy(TileIndex tile, TransportType mode)
static uint32 GetTileTrackStatus_Dummy(uint tile, TransportType mode)
{
return 0;
}
@@ -82,3 +75,4 @@ const TileTypeProcs _tile_type_dummy_procs = {
NULL, /* vehicle_leave_tile_proc */
GetSlopeTileh_Dummy, /* get_slope_tileh_proc */
};

417
economy.c
View File

@@ -1,12 +1,7 @@
/* $Id$ */
#include "stdafx.h"
#include "openttd.h"
#include "currency.h"
#include "functions.h"
#include "ttd.h"
#include "strings.h" // XXX InjectDParam()
#include "table/strings.h"
#include "table/sprites.h"
#include "map.h"
#include "news.h"
#include "player.h"
@@ -23,31 +18,36 @@
#include "sound.h"
#include "engine.h"
#include "network_data.h"
#include "variables.h"
#include "vehicle_gui.h"
#include "ai/ai.h"
#include "train.h"
// Score info
const ScoreInfo _score_info[] = {
{SCORE_VEHICLES, 120, 100},
{SCORE_STATIONS, 80, 100},
{SCORE_MIN_PROFIT, 10000, 100},
{SCORE_MIN_INCOME, 50000, 50},
{SCORE_MAX_INCOME, 100000, 100},
{SCORE_DELIVERED, 40000, 400},
{SCORE_CARGO, 8, 50},
{SCORE_MONEY, 10000000, 50},
{SCORE_LOAN, 250000, 50},
{SCORE_TOTAL, 0, 0}
};
// get a mask of the allowed currencies depending on the year
uint GetMaskOfAllowedCurrencies(void)
{
int i;
uint mask = 0;
for (i = 0; i != lengthof(_currency_specs); i++) {
uint16 to_euro = _currency_specs[i].to_euro;
if (i == 23) mask |= (1 << 23); // always allow custom currency
if (to_euro != CF_NOEURO && to_euro != CF_ISEURO && _cur_year >= (to_euro-MAX_YEAR_BEGIN_REAL)) continue;
if (_cur_year < (2000-MAX_YEAR_BEGIN_REAL) && (to_euro == CF_ISEURO)) continue;
mask |= (1 << i);
}
return mask;
}
int _score_part[MAX_PLAYERS][NUM_SCORE];
void CheckSwitchToEuro(void)
{
if (_currency_specs[_opt.currency].to_euro != CF_NOEURO &&
_currency_specs[_opt.currency].to_euro != CF_ISEURO &&
_cur_year >= (_currency_specs[_opt.currency].to_euro-MAX_YEAR_BEGIN_REAL)) {
_opt.currency = 2; // this is the index of euro above.
AddNewsItem(STR_EURO_INTRODUCE, NEWS_FLAGS(NM_NORMAL,0,NT_ECONOMY,0), 0, 0);
}
}
void UpdatePlayerHouse(Player *p, uint score)
{
byte val;
TileIndex tile = p->location_of_house;
uint tile = p->location_of_house;
if (tile == 0)
return;
@@ -59,23 +59,22 @@ void UpdatePlayerHouse(Player *p, uint score)
(val+= 4, true);
/* house is already big enough */
if (val <= _m[tile].m5)
if (val <= _map5[tile])
return;
_m[tile + TileDiffXY(0, 0)].m5 = val;
_m[tile + TileDiffXY(0, 1)].m5 = ++val;
_m[tile + TileDiffXY(1, 0)].m5 = ++val;
_m[tile + TileDiffXY(1, 1)].m5 = ++val;
_map5[tile + TILE_XY(0,0)] = val;
_map5[tile + TILE_XY(0,1)] = ++val;
_map5[tile + TILE_XY(1,0)] = ++val;
_map5[tile + TILE_XY(1,1)] = ++val;
MarkTileDirtyByTile(tile + TileDiffXY(0, 0));
MarkTileDirtyByTile(tile + TileDiffXY(0, 1));
MarkTileDirtyByTile(tile + TileDiffXY(1, 0));
MarkTileDirtyByTile(tile + TileDiffXY(1, 1));
MarkTileDirtyByTile(tile + TILE_XY(0,0));
MarkTileDirtyByTile(tile + TILE_XY(0,1));
MarkTileDirtyByTile(tile + TILE_XY(1,0));
MarkTileDirtyByTile(tile + TILE_XY(1,1));
}
int64 CalculateCompanyValue(const Player* p)
{
PlayerID owner = p->index;
int64 CalculateCompanyValue(Player *p) {
byte owner = p->index;
int64 value;
{
@@ -124,31 +123,25 @@ int UpdateCompanyRatingAndValue(Player *p, bool update)
/* Count vehicles */
{
Vehicle *v;
int32 min_profit = 0;
bool min_profit_first = true;
int32 min_profit = score_info[SCORE_MIN_PROFIT].needed;
uint num = 0;
FOR_ALL_VEHICLES(v) {
if (v->owner != owner)
continue;
if ((v->type == VEH_Train && IsFrontEngine(v)) ||
v->type == VEH_Road ||
(v->type == VEH_Aircraft && v->subtype <= 2) ||
v->type == VEH_Ship) {
if ((v->type == VEH_Train && v->subtype == TS_Front_Engine) ||
v->type == VEH_Road ||
(v->type == VEH_Aircraft && v->subtype<=2) ||
v->type == VEH_Ship) {
num++;
if (v->age > 730) {
/* Find the vehicle with the lowest amount of profit */
if (min_profit_first == true) {
min_profit = v->profit_last_year;
min_profit_first = false;
} else if (min_profit > v->profit_last_year)
if (min_profit > v->profit_last_year)
min_profit = v->profit_last_year;
}
}
}
_score_part[owner][SCORE_VEHICLES] = num;
/* Don't allow negative min_profit to show */
if (min_profit > 0)
_score_part[owner][SCORE_MIN_PROFIT] = min_profit;
}
@@ -229,7 +222,7 @@ int UpdateCompanyRatingAndValue(Player *p, bool update)
/* Generate score for loan */
{
_score_part[owner][SCORE_LOAN] = _score_info[SCORE_LOAN].needed - p->current_loan;
_score_part[owner][SCORE_LOAN] = score_info[SCORE_LOAN].needed - p->current_loan;
}
// Now we calculate the score for each item..
@@ -242,12 +235,10 @@ int UpdateCompanyRatingAndValue(Player *p, bool update)
// Skip the total
if (i == SCORE_TOTAL) continue;
// Check the score
s = (_score_part[owner][i] >= _score_info[i].needed) ?
_score_info[i].score :
((_score_part[owner][i] * _score_info[i].score) / _score_info[i].needed);
s = (_score_part[owner][i] >= score_info[i].needed) ? score_info[i].score : ((_score_part[owner][i] * score_info[i].score) / score_info[i].needed);
if (s < 0) s = 0;
score += s;
total_score += _score_info[i].score;
total_score += score_info[i].score;
}
_score_part[owner][SCORE_TOTAL] = score;
@@ -267,7 +258,7 @@ int UpdateCompanyRatingAndValue(Player *p, bool update)
return score;
}
// use OWNER_SPECTATOR as new_player to delete the player.
// use 255 as new_player to delete the player.
void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_player)
{
PlayerID old = _current_player;
@@ -277,9 +268,9 @@ void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_player)
Subsidy *s;
for (s = _subsidies; s != endof(_subsidies); s++) {
if (s->cargo_type != CT_INVALID && s->age >= 12) {
if (s->cargo_type != 0xff && s->age >= 12) {
if (GetStation(s->to)->owner == old_player)
s->cargo_type = CT_INVALID;
s->cargo_type = 0xff;
}
}
}
@@ -320,7 +311,7 @@ void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_player)
if (v->owner == new_player) {
switch (v->type) {
case VEH_Train:
if (IsFrontEngine(v)) num_train++;
if (v->subtype == TS_Front_Engine) num_train++;
break;
case VEH_Road:
num_road++;
@@ -345,7 +336,7 @@ void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_player)
DeleteVehicle(v);
} else {
v->owner = new_player;
if (v->type == VEH_Train && IsFrontEngine(v))
if (v->type == VEH_Train && v->subtype == TS_Front_Engine)
v->unitnumber = ++num_train;
else if (v->type == VEH_Road)
v->unitnumber = ++num_road;
@@ -384,13 +375,13 @@ void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_player)
for (i = 0; i < 4; i++) {
/* 'Sell' the share if this player has any */
if (p->share_owners[i] == _current_player)
p->share_owners[i] = OWNER_SPECTATOR;
p->share_owners[i] = 0xFF;
}
}
p = GetPlayer(_current_player);
p = DEREF_PLAYER(_current_player);
/* Sell all the shares that people have on this company */
for (i = 0; i < 4; i++)
p->share_owners[i] = OWNER_SPECTATOR;
p->share_owners[i] = 0xFF;
}
_current_player = old;
@@ -398,9 +389,11 @@ void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_player)
MarkWholeScreenDirty();
}
extern void DeletePlayerWindows(int pi);
static void PlayersCheckBankrupt(Player *p)
{
PlayerID owner;
int owner;
int64 val;
// If the player has money again, it does not go bankrupt
@@ -477,14 +470,9 @@ static void PlayersCheckBankrupt(Player *p)
// Convert everything the player owns to NO_OWNER
p->money64 = p->player_money = 100000000;
ChangeOwnershipOfPlayerItems(owner, OWNER_SPECTATOR);
ChangeOwnershipOfPlayerItems(owner, 0xFF); // 255 is no owner
// Register the player as not-active
p->is_active = false;
if (!IS_HUMAN_PLAYER(owner) && (!_networking || _network_server) && _ai.enabled)
AI_PlayerDied(owner);
if (IS_HUMAN_PLAYER(owner) && owner == _local_player && _ai.network_client)
AI_PlayerDied(owner);
}
}
}
@@ -496,9 +484,9 @@ void DrawNewsBankrupcy(Window *w)
DrawNewsBorder(w);
p = GetPlayer(WP(w,news_d).ni->string_id & 15);
p = DEREF_PLAYER(WP(w,news_d).ni->string_id & 15);
DrawPlayerFace(p->face, p->player_color, 2, 23);
GfxFillRect(3, 23, 3+91, 23+118, 0x323 | USE_COLORTABLE);
GfxFillRect(3, 23, 3+91, 23+118, 0x4323);
SetDParam(0, p->president_name_1);
SetDParam(1, p->president_name_2);
@@ -563,11 +551,11 @@ void DrawNewsBankrupcy(Window *w)
}
}
StringID GetNewsStringBankrupcy(const NewsItem *ni)
StringID GetNewsStringBankrupcy(NewsItem *ni)
{
const Player *p = GetPlayer(ni->string_id & 0xF);
Player *p = DEREF_PLAYER(ni->string_id & 0xF);
switch (ni->string_id >> 4) {
switch(ni->string_id >> 4) {
case 1:
SetDParam(0, STR_7056_TRANSPORT_COMPANY_IN_TROUBLE);
SetDParam(1, STR_7057_WILL_BE_SOLD_OFF_OR_DECLARED);
@@ -656,8 +644,8 @@ static void AddInflation(void)
int i;
int32 inf = _economy.infl_amount * 54;
for (i = 0; i != NUM_PRICES; i++) {
AddSingleInflation((int32*)&_price + i, _price_frac + i, inf);
for(i=0; i!=NUM_PRICES; i++) {
AddSingleInflation( (int32*)&_price + i, _price_frac + i, inf );
}
_economy.max_loan_unround += BIGMULUS(_economy.max_loan_unround, inf, 16);
@@ -666,9 +654,9 @@ static void AddInflation(void)
_economy.max_loan += 50000;
inf = _economy.infl_amount_pr * 54;
for (i = 0; i != NUM_CARGO; i++) {
for(i=0; i!=NUM_CARGO; i++) {
AddSingleInflation(
(int32*)_cargo_payment_rates + i,
_cargo_payment_rates + i,
_cargo_payment_rates_frac + i,
inf
);
@@ -682,11 +670,12 @@ static void AddInflation(void)
static void PlayersPayInterest(void)
{
const Player* p;
Player *p;
int interest = _economy.interest_rate * 54;
FOR_ALL_PLAYERS(p) {
if (!p->is_active) continue;
if (!p->is_active)
continue;
_current_player = p->index;
SET_EXPENSES_TYPE(EXPENSES_LOAN_INT);
@@ -700,13 +689,14 @@ static void PlayersPayInterest(void)
static void HandleEconomyFluctuations(void)
{
if (_opt.diff.economy == 0) return;
if (_opt.diff.economy == 0)
return;
if (--_economy.fluct == 0) {
_economy.fluct = -(int)GB(Random(), 0, 2);
_economy.fluct = - (int)(Random()&3);
AddNewsItem(STR_7073_WORLD_RECESSION_FINANCIAL, NEWS_FLAGS(NM_NORMAL,0,NT_ECONOMY,0), 0, 0);
} else if (_economy.fluct == -12) {
_economy.fluct = GB(Random(), 0, 8) + 312;
_economy.fluct = (Random()&255) + 312;
AddNewsItem(STR_7074_RECESSION_OVER_UPTURN_IN, NEWS_FLAGS(NM_NORMAL,0,NT_ECONOMY,0), 0, 0);
}
}
@@ -773,33 +763,6 @@ static const int32 _price_base[NUM_PRICES] = {
1000000, // build_industry
};
static byte price_base_multiplier[NUM_PRICES];
/**
* Reset changes to the price base multipliers.
*/
void ResetPriceBaseMultipliers(void)
{
uint i;
// 8 means no multiplier.
for (i = 0; i < NUM_PRICES; i++)
price_base_multiplier[i] = 8;
}
/**
* Change a price base by the given factor.
* The price base is altered by factors of two, with an offset of 8.
* NewBaseCost = OldBaseCost * 2^(n-8)
* @param price Index of price base to change.
* @param factor Amount to change by.
*/
void SetPriceBaseMultiplier(uint price, byte factor)
{
assert(price < NUM_PRICES);
price_base_multiplier[price] = factor;
}
void StartupEconomy(void)
{
int i;
@@ -816,11 +779,6 @@ void StartupEconomy(void)
price = price * 9 >> 3;
}
}
if (price_base_multiplier[i] > 8) {
price <<= price_base_multiplier[i] - 8;
} else {
price >>= 8 - price_base_multiplier[i];
}
((int32*)&_price)[i] = price;
_price_frac[i] = 0;
}
@@ -829,48 +787,62 @@ void StartupEconomy(void)
_economy.infl_amount = _opt.diff.initial_interest;
_economy.infl_amount_pr = max(0, _opt.diff.initial_interest - 1);
_economy.max_loan_unround = _economy.max_loan = _opt.diff.max_loan * 1000;
_economy.fluct = GB(Random(), 0, 8) + 168;
_economy.fluct = (byte)(Random()) + 168;
}
Pair SetupSubsidyDecodeParam(const Subsidy* s, bool mode)
Pair SetupSubsidyDecodeParam(Subsidy *s, bool mode)
{
TileIndex tile;
TileIndex tile2;
int tile, tile2;
Industry *i;
Town *t;
Station *st;
Pair tp;
/* if mode is false, use the singular form */
SetDParam(0, _cargoc.names_s[s->cargo_type] + (mode ? 0 : 32));
/* if mode is false, convert into plural */
SetDParam(0, _cargoc.names_s[s->cargo_type] + (mode?0:32));
if (s->age < 12) {
if (s->cargo_type != CT_PASSENGERS && s->cargo_type != CT_MAIL) {
SetDParam(1, STR_INDUSTRY);
SetDParam(2, s->from);
tile = GetIndustry(s->from)->xy;
if (!(s->cargo_type == CT_PASSENGERS || s->cargo_type == CT_MAIL)) {
SetDParam(1, STR_2029);
i = GetIndustry(s->from);
tile = i->xy;
SetDParam(2, i->town->townnametype);
SetDParam(3, i->town->townnameparts);
SetDParam(4, i->type + STR_4802_COAL_MINE);
if (s->cargo_type != CT_GOODS && s->cargo_type != CT_FOOD) {
SetDParam(4, STR_INDUSTRY);
SetDParam(5, s->to);
tile2 = GetIndustry(s->to)->xy;
SetDParam(5, STR_2029);
i = GetIndustry(s->to);
tile2 = i->xy;
SetDParam(8, i->type + STR_4802_COAL_MINE);
SetDParam(6, i->town->townnametype);
SetDParam(7, i->town->townnameparts);
} else {
SetDParam(4, STR_TOWN);
SetDParam(5, s->to);
tile2 = GetTown(s->to)->xy;
t = GetTown(s->to);
tile2 = t->xy;
SetDParam(5, t->townnametype);
SetDParam(6, t->townnameparts);
}
} else {
SetDParam(1, STR_TOWN);
SetDParam(2, s->from);
tile = GetTown(s->from)->xy;
t = GetTown(s->from);
tile = t->xy;
SetDParam(1, t->townnametype);
SetDParam(2, t->townnameparts);
SetDParam(4, STR_TOWN);
SetDParam(5, s->to);
tile2 = GetTown(s->to)->xy;
t = GetTown(s->to);
tile2 = t->xy;
SetDParam(3, t->townnametype);
SetDParam(4, t->townnameparts);
}
} else {
SetDParam(1, s->from);
tile = GetStation(s->from)->xy;
st = GetStation(s->from);
tile = st->xy;
SetDParam(1, st->index);
SetDParam(2, s->to);
tile2 = GetStation(s->to)->xy;
st = GetStation(s->to);
tile2 = st->xy;
SetDParam(2, st->index);
}
tp.a = tile;
@@ -884,10 +856,10 @@ void DeleteSubsidyWithIndustry(uint16 index)
Subsidy *s;
for(s=_subsidies; s != endof(_subsidies); s++) {
if (s->cargo_type != CT_INVALID && s->age < 12 &&
if (s->cargo_type != 0xFF && s->age < 12 &&
s->cargo_type != CT_PASSENGERS && s->cargo_type != CT_MAIL &&
(index == s->from || (s->cargo_type!=CT_GOODS && s->cargo_type!=CT_FOOD && index==s->to))) {
s->cargo_type = CT_INVALID;
s->cargo_type = 0xFF;
}
}
}
@@ -898,9 +870,9 @@ void DeleteSubsidyWithStation(uint16 index)
bool dirty = false;
for(s=_subsidies; s != endof(_subsidies); s++) {
if (s->cargo_type != CT_INVALID && s->age >= 12 &&
if (s->cargo_type != 0xFF && s->age >= 12 &&
(s->from == index || s->to == index)) {
s->cargo_type = CT_INVALID;
s->cargo_type = 0xFF;
dirty = true;
}
}
@@ -946,7 +918,7 @@ static void FindSubsidyCargoRoute(FoundRoute *fr)
return;
// Randomize cargo type
if (Random()&1 && i->produced_cargo[1] != CT_INVALID) {
if (Random()&1 && i->produced_cargo[1] != 0xFF) {
cargo = i->produced_cargo[1];
trans = i->pct_transported[1];
total = i->total_production[1];
@@ -959,7 +931,7 @@ static void FindSubsidyCargoRoute(FoundRoute *fr)
// Quit if no production in this industry
// or if the cargo type is passengers
// or if the pct transported is already large enough
if (total == 0 || trans > 42 || cargo == CT_INVALID || cargo == CT_PASSENGERS)
if (total == 0 || trans > 42 || cargo == 0xFF || cargo == CT_PASSENGERS)
return;
fr->cargo = cargo;
@@ -990,20 +962,38 @@ static void FindSubsidyCargoRoute(FoundRoute *fr)
static bool CheckSubsidyDuplicate(Subsidy *s)
{
const Subsidy* ss;
Subsidy *ss;
for (ss = _subsidies; ss != endof(_subsidies); ss++) {
for(ss=_subsidies; ss != endof(_subsidies); ss++) {
if (s != ss &&
// ss->age < 12 &&
ss->from == s->from &&
ss->to == s->to &&
ss->cargo_type == s->cargo_type) {
s->cargo_type = CT_INVALID;
s->cargo_type = 0xFF;
return true;
}
}
return false;
}
void RemoteSubsidyAdd(Subsidy *s_new)
{
Subsidy *s;
Pair pair;
// search the first free subsidy
for(s=_subsidies; s != endof(_subsidies); s++)
if (s->cargo_type == 0xFF)
break;
memcpy(s,s_new,sizeof(Subsidy));
pair = SetupSubsidyDecodeParam(s, 0);
AddNewsItem(STR_2030_SERVICE_SUBSIDY_OFFERED, NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_SUBSIDIES, 0), pair.a, pair.b);
InvalidateWindow(WC_SUBSIDIES_LIST, 0);
}
static void SubsidyMonthlyHandler(void)
{
@@ -1015,13 +1005,13 @@ static void SubsidyMonthlyHandler(void)
bool modified = false;
for(s=_subsidies; s != endof(_subsidies); s++) {
if (s->cargo_type == CT_INVALID)
if (s->cargo_type == 0xFF)
continue;
if (s->age == 12-1) {
pair = SetupSubsidyDecodeParam(s, 1);
AddNewsItem(STR_202E_OFFER_OF_SUBSIDY_EXPIRED, NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_SUBSIDIES, 0), pair.a, pair.b);
s->cargo_type = CT_INVALID;
s->cargo_type = 0xFF;
modified = true;
} else if (s->age == 2*12-1) {
st = GetStation(s->to);
@@ -1029,7 +1019,7 @@ static void SubsidyMonthlyHandler(void)
pair = SetupSubsidyDecodeParam(s, 1);
AddNewsItem(STR_202F_SUBSIDY_WITHDRAWN_SERVICE, NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_SUBSIDIES, 0), pair.a, pair.b);
}
s->cargo_type = CT_INVALID;
s->cargo_type = 0xFF;
modified = true;
} else {
s->age++;
@@ -1040,7 +1030,7 @@ static void SubsidyMonthlyHandler(void)
if (CHANCE16(1,4)) {
// Find a free slot
s = _subsidies;
while (s->cargo_type != CT_INVALID) {
while (s->cargo_type != 0xFF) {
if (++s == endof(_subsidies))
goto no_add;
}
@@ -1075,7 +1065,7 @@ no_add:;
InvalidateWindow(WC_SUBSIDIES_LIST, 0);
}
static const SaveLoad _subsidies_desc[] = {
static const byte _subsidies_desc[] = {
SLE_VAR(Subsidy,cargo_type, SLE_UINT8),
SLE_VAR(Subsidy,age, SLE_UINT8),
SLE_CONDVAR(Subsidy,from, SLE_FILE_U8 | SLE_VAR_U16, 0, 4),
@@ -1092,7 +1082,7 @@ static void Save_SUBS(void)
for(i=0; i!=lengthof(_subsidies); i++) {
s = &_subsidies[i];
if (s->cargo_type != CT_INVALID) {
if (s->cargo_type != 0xFF) {
SlSetArrayIndex(i);
SlObject(s, _subsidies_desc);
}
@@ -1142,13 +1132,13 @@ static void DeliverGoodsToIndustry(TileIndex xy, byte cargo_type, int num_pieces
/* Check if there's an industry close to the station that accepts
* the cargo */
best = NULL;
u = (_patches.station_spread + 8) * 2;
u = _patches.station_spread + 8;
FOR_ALL_INDUSTRIES(ind) {
if (ind->xy != 0 && (cargo_type == ind->accepts_cargo[0] || cargo_type
== ind->accepts_cargo[1] || cargo_type == ind->accepts_cargo[2]) &&
ind->produced_cargo[0] != CT_INVALID &&
ind->produced_cargo[0] != 0xFF &&
ind->produced_cargo[0] != cargo_type &&
(t = DistanceManhattan(ind->xy, xy)) < 2) {
(t = DistanceManhattan(ind->xy, xy)) < 2 * u) {
u = t;
best = ind;
}
@@ -1209,7 +1199,7 @@ static bool CheckSubsidised(Station *from, Station *to, byte cargo_type)
pair = SetupSubsidyDecodeParam(s, 0);
InjectDParam(2);
p = GetPlayer(_current_player);
p = DEREF_PLAYER(_current_player);
SetDParam(0, p->name_1);
SetDParam(1, p->name_2);
AddNewsItem(
@@ -1234,7 +1224,7 @@ static int32 DeliverGoods(int num_pieces, byte cargo_type, uint16 source, uint16
// Update player statistics
{
Player *p = GetPlayer(_current_player);
Player *p = DEREF_PLAYER(_current_player);
p->cur_economy.delivered_cargo += num_pieces;
SETBIT(p->cargo_types, cargo_type);
}
@@ -1247,14 +1237,26 @@ static int32 DeliverGoods(int num_pieces, byte cargo_type, uint16 source, uint16
subsidised = CheckSubsidised(s_from, s_to, cargo_type);
// Increase town's counter for some special goods types
if (cargo_type == CT_FOOD) s_to->town->new_act_food += num_pieces;
if (cargo_type == CT_WATER) s_to->town->new_act_water += num_pieces;
{
Town *t = s_to->town;
if (cargo_type == CT_FOOD) t->new_act_food += num_pieces;
if (cargo_type == CT_WATER) t->new_act_water += num_pieces;
}
// Give the goods to the industry.
DeliverGoodsToIndustry(s_to->xy, cargo_type, num_pieces);
// Determine profit
profit = GetTransportedGoodsIncome(num_pieces, DistanceManhattan(s_from->xy, s_to->xy), days_in_transit, cargo_type);
{
int t = DistanceManhattan(s_from->xy, s_to->xy);
int r = num_pieces;
profit = 0;
do {
int u = min(r, 255);
r -= u;
profit += GetTransportedGoodsIncome(u, t, days_in_transit, cargo_type);
} while (r != 0);
}
// Modify profit if a subsidy is in effect
if (subsidised) {
@@ -1273,6 +1275,10 @@ static int32 DeliverGoods(int num_pieces, byte cargo_type, uint16 source, uint16
}
}
// Computers get 25% extra profit if they're intelligent.
if (_opt.diff.competitor_intelligence>=1 && !IS_HUMAN_PLAYER(_current_player))
profit += profit >> 2;
return profit;
}
@@ -1298,7 +1304,7 @@ static bool LoadWait(const Vehicle *v, const Vehicle *u) {
}
FOR_ALL_VEHICLES(x) {
if ((x->type != VEH_Train || IsFrontEngine(x)) && // for all locs
if ((x->type != VEH_Train || x->subtype == TS_Front_Engine) && // for all locs
u->last_station_visited == x->last_station_visited && // at the same station
!(x->vehstatus & VS_STOPPED) && // not stopped
x->current_order.type == OT_LOADING && // loading
@@ -1332,16 +1338,15 @@ static bool LoadWait(const Vehicle *v, const Vehicle *u) {
int LoadUnloadVehicle(Vehicle *v)
{
int profit = 0;
int v_profit; //virtual profit for feeder systems
int v_profit_total = 0;
int unloading_time = 20;
Vehicle *u = v;
int result = 0;
uint16 last_visited;
Station *st;
GoodsEntry *ge;
int t;
uint count, cap;
PlayerID old_player;
byte old_player;
bool completely_empty = true;
assert(v->current_order.type == OT_LOADING);
@@ -1354,15 +1359,13 @@ int LoadUnloadVehicle(Vehicle *v)
st = GetStation(last_visited = v->last_station_visited);
for (; v != NULL; v = v->next) {
GoodsEntry* ge;
if (v->cargo_cap == 0) continue;
ge = &st->goods[v->cargo_type];
/* unload? */
if (v->cargo_count != 0) {
if (v->cargo_source != last_visited && ge->waiting_acceptance & 0x8000 && !(u->current_order.flags & OF_TRANSFER)) {
if (v->cargo_source != last_visited && ge->waiting_acceptance & 0x8000) {
// deliver goods to the station
st->time_since_unload = 0;
@@ -1370,22 +1373,11 @@ int LoadUnloadVehicle(Vehicle *v)
profit += DeliverGoods(v->cargo_count, v->cargo_type, v->cargo_source, last_visited, v->cargo_days);
result |= 1;
v->cargo_count = 0;
} else if (u->current_order.flags & (OF_UNLOAD | OF_TRANSFER)) {
} else if (u->current_order.flags & OF_UNLOAD) {
/* unload goods and let it wait at the station */
st->time_since_unload = 0;
v_profit = GetTransportedGoodsIncome(
v->cargo_count,
DistanceManhattan(GetStation(v->cargo_source)->xy, GetStation(last_visited)->xy),
v->cargo_days,
v->cargo_type) * 3 / 2;
v_profit_total += v_profit;
unloading_time += v->cargo_count;
t = GB(ge->waiting_acceptance, 0, 12);
if (t == 0) {
if ((t=ge->waiting_acceptance & 0xFFF) == 0) {
// No goods waiting at station
ge->enroute_time = v->cargo_days;
ge->enroute_from = v->cargo_source;
@@ -1397,9 +1389,7 @@ int LoadUnloadVehicle(Vehicle *v)
ge->enroute_from = v->cargo_source;
}
// Update amount of waiting cargo
SB(ge->waiting_acceptance, 0, 12, min(v->cargo_count + t, 0xFFF));
ge->feeder_profit += v_profit;
u->profit_this_year += v_profit;
ge->waiting_acceptance = (ge->waiting_acceptance &~0xFFF) | min(v->cargo_count + t, 0xFFF);
result |= 2;
v->cargo_count = 0;
}
@@ -1415,7 +1405,6 @@ int LoadUnloadVehicle(Vehicle *v)
ge->days_since_pickup = 0;
t = u->max_speed;
if (u->type == VEH_Road) t >>=1;
if (u->type == VEH_Train) t = u->u.rail.cached_max_speed;
// if last speed is 0, we treat that as if no vehicle has ever visited the station.
ge->last_speed = t < 255 ? t : 255;
@@ -1423,12 +1412,8 @@ int LoadUnloadVehicle(Vehicle *v)
// If there's goods waiting at the station, and the vehicle
// has capacity for it, load it on the vehicle.
count = GB(ge->waiting_acceptance, 0, 12);
if (count != 0 &&
if ((count=ge->waiting_acceptance & 0xFFF) != 0 &&
(cap = v->cargo_cap - v->cargo_count) != 0) {
int cargoshare;
int feeder_profit_share;
if (v->cargo_count == 0)
TriggerVehicle(v, VEHICLE_TRIGGER_NEW_CARGO);
@@ -1446,12 +1431,8 @@ int LoadUnloadVehicle(Vehicle *v)
completely_empty = false;
if (cap > count) cap = count;
cargoshare = cap * 10000 / ge->waiting_acceptance;
feeder_profit_share = ge->feeder_profit * cargoshare / 10000;
v->cargo_count += cap;
ge->waiting_acceptance -= cap;
v->profit_this_year -= feeder_profit_share;
ge->feeder_profit -= feeder_profit_share;
unloading_time += cap;
st->time_since_load = 0;
@@ -1463,19 +1444,16 @@ int LoadUnloadVehicle(Vehicle *v)
}
}
v = u;
if (v_profit_total > 0)
ShowFeederIncomeAnimation(v->x_pos, v->y_pos, v->z_pos, v_profit_total);
if (v->type == VEH_Train) {
// Each platform tile is worth 2 rail vehicles.
int overhang = v->u.rail.cached_total_length - GetStationPlatforms(st, v->tile) * 16;
if (overhang > 0) {
unloading_time <<= 1;
unloading_time += (overhang * unloading_time) / 8;
int num = - (int)GetStationPlatforms(st, v->tile) * 2;
do num++; while ( (v=v->next) != NULL);
if (num > 0) {
unloading_time <<=1;
unloading_time += num * unloading_time;
}
v = u;
}
v->load_unload_time_rem = unloading_time;
@@ -1494,7 +1472,8 @@ int LoadUnloadVehicle(Vehicle *v)
v->profit_this_year += profit;
SubtractMoneyFromPlayer(-profit);
if (IsLocalPlayer()) SndPlayVehicleFx(SND_14_CASHTILL, v);
if (_current_player == _local_player)
SndPlayVehicleFx(SND_14_CASHTILL, v);
ShowCostOrIncomeAnimation(v->x_pos, v->y_pos, v->z_pos, -profit);
}
@@ -1532,14 +1511,14 @@ static void DoAcquireCompany(Player *p)
ChangeOwnershipOfPlayerItems(pi, _current_player);
if (p->bankrupt_value == 0) {
owner = GetPlayer(_current_player);
owner = DEREF_PLAYER(_current_player);
owner->current_loan += p->current_loan;
}
value = CalculateCompanyValue(p) >> 2;
for(i=0; i!=4; i++) {
if (p->share_owners[i] != OWNER_SPECTATOR) {
owner = GetPlayer(p->share_owners[i]);
if (p->share_owners[i] != 0xFF) {
owner = DEREF_PLAYER(p->share_owners[i]);
owner->money64 += value;
owner->yearly_expenses[0][EXPENSES_OTHER] += value;
UpdatePlayerMoney32(owner);
@@ -1568,7 +1547,7 @@ int32 CmdBuyShareInCompany(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (p1 >= MAX_PLAYERS || !_patches.allow_shares) return CMD_ERROR;
SET_EXPENSES_TYPE(EXPENSES_OTHER);
p = GetPlayer(p1);
p = DEREF_PLAYER(p1);
/* Protect new companies from hostile takeovers */
if (_cur_year - p->inaugurated_year < 6) return_cmd_error(STR_7080_PROTECTED);
@@ -1581,10 +1560,10 @@ int32 CmdBuyShareInCompany(int x, int y, uint32 flags, uint32 p1, uint32 p2)
cost = CalculateCompanyValue(p) >> 2;
if (flags & DC_EXEC) {
PlayerID* b = p->share_owners;
int i;
byte *b = p->share_owners;
while (*b != OWNER_SPECTATOR) b++; /* share owners is guaranteed to contain at least one OWNER_SPECTATOR */
while (*b != 0xFF) b++; /* share owners is guaranteed to contain at least one 0xFF */
*b = _current_player;
for (i = 0; p->share_owners[i] == _current_player;) {
@@ -1613,7 +1592,7 @@ int32 CmdSellShareInCompany(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (p1 >= MAX_PLAYERS || !_patches.allow_shares) return CMD_ERROR;
SET_EXPENSES_TYPE(EXPENSES_OTHER);
p = GetPlayer(p1);
p = DEREF_PLAYER(p1);
/* Those lines are here for network-protection (clients can be slow) */
if (GetAmountOwnedBy(p, _current_player) == 0) return 0;
@@ -1623,9 +1602,9 @@ int32 CmdSellShareInCompany(int x, int y, uint32 flags, uint32 p1, uint32 p2)
cost = -(cost - (cost >> 7));
if (flags & DC_EXEC) {
PlayerID* b = p->share_owners;
byte *b = p->share_owners;
while (*b != _current_player) b++; /* share owners is guaranteed to contain player */
*b = OWNER_SPECTATOR;
*b = 0xFF;
InvalidateWindow(WC_COMPANY, (int)p1);
}
return cost;
@@ -1647,7 +1626,7 @@ int32 CmdBuyCompany(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (p1 >= MAX_PLAYERS || _networking) return CMD_ERROR;
SET_EXPENSES_TYPE(EXPENSES_OTHER);
p = GetPlayer(p1);
p = DEREF_PLAYER(p1);
if (!p->is_ai) return CMD_ERROR;
@@ -1671,7 +1650,7 @@ static void SaveLoad_CAPR(void)
SlArray(&_cargo_payment_rates_frac, NUM_CARGO, SLE_UINT16);
}
static const SaveLoad _economy_desc[] = {
static const byte _economy_desc[] = {
SLE_VAR(Economy,max_loan, SLE_INT32),
SLE_VAR(Economy,max_loan_unround, SLE_INT32),
SLE_VAR(Economy,fluct, SLE_FILE_I16 | SLE_VAR_I32),
@@ -1684,7 +1663,7 @@ static const SaveLoad _economy_desc[] = {
// Economy variables
static void SaveLoad_ECMY(void)
{
SlObject(&_economy, _economy_desc);
SlObject(&_economy, &_economy_desc);
}
const ChunkHandler _economy_chunk_handlers[] = {

View File

@@ -1,11 +1,6 @@
/* $Id$ */
#ifndef ECONOMY_H
#define ECONOMY_H
void ResetPriceBaseMultipliers(void);
void SetPriceBaseMultiplier(uint price, byte factor);
typedef struct {
// Maximum possible loan
int32 max_loan;
@@ -52,19 +47,32 @@ typedef struct ScoreInfo {
int score; // How much score it will give
} ScoreInfo;
extern const ScoreInfo _score_info[];
extern int _score_part[MAX_PLAYERS][NUM_SCORE];
static const ScoreInfo score_info[] = {
{SCORE_VEHICLES, 120, 100},
{SCORE_STATIONS, 80, 100},
{SCORE_MIN_PROFIT, 10000, 100},
{SCORE_MIN_INCOME, 50000, 50},
{SCORE_MAX_INCOME, 100000, 100},
{SCORE_DELIVERED, 40000, 400},
{SCORE_CARGO, 8, 50},
{SCORE_MONEY, 10000000, 50},
{SCORE_LOAN, 250000, 50},
{SCORE_TOTAL, 0, 0}
};
int _score_part[MAX_PLAYERS][NUM_SCORE];
int UpdateCompanyRatingAndValue(Player *p, bool update);
void UpdatePlayerHouse(Player *p, uint score);
VARDEF Subsidy _subsidies[MAX_PLAYERS];
Pair SetupSubsidyDecodeParam(const Subsidy* s, bool mode);
Pair SetupSubsidyDecodeParam(Subsidy *s, bool mode);
void DeleteSubsidyWithIndustry(uint16 index);
void DeleteSubsidyWithStation(uint16 index);
void RemoteSubsidyAdd(Subsidy *s_new);
int32 GetTransportedGoodsIncome(uint num_pieces, uint dist, byte transit_days, byte cargo_type);
uint MoveGoodsToStation(TileIndex tile, int w, int h, int type, uint amount);
uint MoveGoodsToStation(uint tile, int w, int h, int type, uint amount);
#endif /* ECONOMY_H */

View File

@@ -1,5 +1,3 @@
/* $Id$ */
#include <stdio.h>
// This pretty simple file checks if the system is LITTLE_ENDIAN or BIG_ENDIAN
@@ -11,42 +9,22 @@
// care of the real writing to the file.
int main (int argc, char *argv[]) {
unsigned char EndianTest[2] = { 1, 0 };
int force_BE = 0, force_LE = 0, force_PREPROCESSOR = 0;
unsigned char EndianTest[2] = { 1, 0 };
int force_BE = 0, force_LE = 0;
if (argc > 1 && strcmp(argv[1], "BE") == 0)
force_BE = 1;
if (argc > 1 && strcmp(argv[1], "LE") == 0)
force_LE = 1;
if (argc > 1 && strcmp(argv[1], "PREPROCESSOR") == 0)
force_PREPROCESSOR = 1;
if (argc > 1 && strcmp(argv[1], "BE") == 0)
force_BE = 1;
if (argc > 1 && strcmp(argv[1], "LE") == 0)
force_LE = 1;
printf("#ifndef ENDIAN_H\n#define ENDIAN_H\n");
printf("#ifndef ENDIAN_H\n#define ENDIAN_H\n");
if (force_LE == 1) {
printf("#define TTD_LITTLE_ENDIAN\n");
} else {
if (force_BE == 1) {
printf("#define TTD_BIG_ENDIAN\n");
} else {
if (force_PREPROCESSOR == 1) {
// adding support for universal binaries on OSX
// Universal binaries supports both PPC and x86
// If a compiler for OSX gets this setting, it will always pick the correct endian and no test is needed
printf("#ifdef __BIG_ENDIAN__\n");
printf("#define TTD_BIG_ENDIAN\n");
printf("#else\n");
printf("#define TTD_LITTLE_ENDIAN\n");
printf("#endif\n");
} else {
if ( *(short *) EndianTest == 1 )
printf("#define TTD_LITTLE_ENDIAN\n");
else
printf("#define TTD_BIG_ENDIAN\n");
}
}
}
printf("#endif\n");
if ( (*(short *) EndianTest == 1 && force_BE != 1) || force_LE == 1)
printf("#define TTD_LITTLE_ENDIAN\n");
else
printf("#define TTD_BIG_ENDIAN\n");
return 0;
printf("#endif\n");
return 0;
}

653
engine.c

File diff suppressed because it is too large Load Diff

202
engine.h
View File

@@ -1,13 +1,7 @@
/* $Id$ */
#ifndef ENGINE_H
#define ENGINE_H
/** @file engine.h
*/
#include "sprite.h"
#include "pool.h"
typedef struct RailVehicleInfo {
byte image_index;
@@ -15,20 +9,11 @@ typedef struct RailVehicleInfo {
byte base_cost;
uint16 max_speed;
uint16 power;
uint16 weight;
byte weight;
byte running_cost_base;
byte running_cost_class;
byte engclass; // 0: steam, 1: diesel, 2: electric
byte capacity;
byte cargo_type;
byte callbackmask; // see CallbackMask enum
uint16 pow_wag_power;
byte pow_wag_weight;
byte visual_effect; // NOTE: this is not 100% implemented yet, at the moment it is only used as a 'fallback' value
// for when the 'powered wagon' callback fails. But it should really also determine what
// kind of visual effect to generate for a vehicle (default, steam, diesel, electric).
// Same goes for the callback result, which atm is only used to check if a wagon is powered.
byte shorten_factor; // length on main map for this type is 8 - shorten_factor
} RailVehicleInfo;
typedef struct ShipVehicleInfo {
@@ -64,17 +49,12 @@ typedef struct RoadVehicleInfo {
byte cargo_type;
} RoadVehicleInfo;
/** Information about a vehicle
* @see table/engines.h
*/
typedef struct EngineInfo {
uint16 base_intro;
byte unk2; ///< Carriages have the highest bit set in this one
byte unk2;
byte lifelength;
byte base_life;
byte railtype:4;
byte climates:4;
uint32 refit_mask;
byte railtype_climates;
} EngineInfo;
typedef struct Engine {
@@ -86,10 +66,10 @@ typedef struct Engine {
uint16 duration_phase_1, duration_phase_2, duration_phase_3;
byte lifelength;
byte flags;
byte preview_player;
PlayerID preview_player;
byte preview_wait;
byte railtype;
byte player_avail;
PlayerID player_avail;
byte type; // type, ie VEH_Road, VEH_Train, etc. Same as in vehicle.h
} Engine;
@@ -103,10 +83,6 @@ enum {
NUM_VEHICLE_TYPES = 6
};
enum {
INVALID_ENGINE = 0xFFFF,
};
void AddTypeToEngines(void);
void StartupEngines(void);
@@ -146,49 +122,17 @@ enum GlobalCargo {
NUM_GLOBAL_CID = 31
};
// This enum lists the implemented callbacks
// Use as argument for the GetCallBackResult function (see comments there)
enum CallbackID {
// Powered wagons, if the result is lower as 0x40 then the wagon is powered
// TODO: interpret the rest of the result, aka "visual effects"
CBID_WAGON_POWER = 0x10,
// Vehicle length, returns the amount of 1/8's the vehicle is shorter
// only for train vehicles
CBID_VEH_LENGTH = 0x11,
// Refit capacity, the passed vehicle needs to have its ->cargo_type set to
// the cargo we are refitting to, returns the new cargo capacity
CBID_REFIT_CAP = 0x15,
CBID_ARTIC_ENGINE = 0x16,
};
// bit positions for rvi->callbackmask, indicates which callbacks are used by an engine
// (some callbacks are always used, and dont appear here)
enum CallbackMask {
CBM_WAGON_POWER = 0,
CBM_VEH_LENGTH = 1,
CBM_REFIT_CAP = 3,
CBM_ARTIC_ENGINE = 4,
};
enum {
CALLBACK_FAILED = 0xFFFF
};
VARDEF const uint32 _default_refitmasks[NUM_VEHICLE_TYPES];
VARDEF const CargoID _global_cargo_id[NUM_LANDSCAPE][NUM_CARGO];
VARDEF const uint32 _landscape_global_cargo_mask[NUM_LANDSCAPE];
VARDEF const CargoID _local_cargo_id_ctype[NUM_GLOBAL_CID];
VARDEF const uint32 cargo_classes[16];
void SetWagonOverrideSprites(EngineID engine, struct SpriteGroup *group, byte *train_id, int trains);
void SetCustomEngineSprites(EngineID engine, byte cargo, struct SpriteGroup *group);
VARDEF uint32 _engine_refit_masks[256];
VARDEF byte _engine_original_sprites[256];
void SetWagonOverrideSprites(byte engine, struct SpriteGroup *group, byte *train_id, int trains);
void SetCustomEngineSprites(byte engine, byte cargo, struct SpriteGroup *group);
// loaded is in percents, overriding_engine 0xffff is none
int GetCustomEngineSprite(EngineID engine, const Vehicle *v, byte direction);
uint16 GetCallBackResult(uint16 callback_info, EngineID engine, const Vehicle *v);
bool UsesWagonOverride(const Vehicle *v);
int GetCustomEngineSprite(byte engine, const Vehicle *v, byte direction);
#define GetCustomVehicleSprite(v, direction) GetCustomEngineSprite(v->engine_type, v, direction)
#define GetCustomVehicleIcon(et, direction) GetCustomEngineSprite(et, NULL, direction)
@@ -203,19 +147,27 @@ typedef enum VehicleTrigger {
} VehicleTrigger;
void TriggerVehicle(Vehicle *veh, VehicleTrigger trigger);
void SetCustomEngineName(EngineID engine, const char *name);
StringID GetCustomEngineName(EngineID engine);
void SetCustomEngineName(int engine, const char *name);
StringID GetCustomEngineName(int engine);
void DrawTrainEngine(int x, int y, EngineID engine, uint32 image_ormod);
void DrawRoadVehEngine(int x, int y, EngineID engine, uint32 image_ormod);
void DrawShipEngine(int x, int y, EngineID engine, uint32 image_ormod);
void DrawAircraftEngine(int x, int y, EngineID engine, uint32 image_ormod);
void DrawTrainEngine(int x, int y, int engine, uint32 image_ormod);
void DrawRoadVehEngine(int x, int y, int engine, uint32 image_ormod);
void DrawShipEngine(int x, int y, int engine, uint32 image_ormod);
void DrawAircraftEngine(int x, int y, int engine, uint32 image_ormod);
void DrawTrainEngineInfo(int engine, int x, int y, int maxw);
void DrawRoadVehEngineInfo(int engine, int x, int y, int maxw);
void DrawShipEngineInfo(int engine, int x, int y, int maxw);
void DrawAircraftEngineInfo(int engine, int x, int y, int maxw);
void AcceptEnginePreview(Engine *e, PlayerID player);
void LoadCustomEngineNames(void);
void DeleteCustomEngineNames(void);
bool IsEngineBuildable(uint engine, byte type);
void UnInitNewgrEngines(void);
enum {
NUM_NORMAL_RAIL_ENGINES = 54,
@@ -232,8 +184,8 @@ enum {
};
VARDEF Engine _engines[TOTAL_NUM_ENGINES];
#define FOR_ALL_ENGINES(e) for (e = _engines; e != endof(_engines); e++)
static inline Engine* GetEngine(EngineID i)
#define DEREF_ENGINE(i) (GetEngine(i))
static inline Engine* GetEngine(uint i)
{
assert(i < lengthof(_engines));
return &_engines[i];
@@ -248,120 +200,34 @@ static inline bool IsEngineIndex(uint index)
/* Access Vehicle Data */
//#include "table/engines.h"
extern const EngineInfo orig_engine_info[TOTAL_NUM_ENGINES];
extern const RailVehicleInfo orig_rail_vehicle_info[NUM_TRAIN_ENGINES];
extern const ShipVehicleInfo orig_ship_vehicle_info[NUM_SHIP_ENGINES];
extern const AircraftVehicleInfo orig_aircraft_vehicle_info[NUM_AIRCRAFT_ENGINES];
extern const RoadVehicleInfo orig_road_vehicle_info[NUM_ROAD_ENGINES];
extern EngineInfo _engine_info[TOTAL_NUM_ENGINES];
extern RailVehicleInfo _rail_vehicle_info[NUM_TRAIN_ENGINES];
extern ShipVehicleInfo _ship_vehicle_info[NUM_SHIP_ENGINES];
extern AircraftVehicleInfo _aircraft_vehicle_info[NUM_AIRCRAFT_ENGINES];
extern RoadVehicleInfo _road_vehicle_info[NUM_ROAD_ENGINES];
static inline const RailVehicleInfo* RailVehInfo(EngineID e)
static inline RailVehicleInfo *RailVehInfo(uint e)
{
assert(e < lengthof(_rail_vehicle_info));
return &_rail_vehicle_info[e];
}
static inline const ShipVehicleInfo* ShipVehInfo(EngineID e)
static inline ShipVehicleInfo *ShipVehInfo(uint e)
{
assert(e >= SHIP_ENGINES_INDEX && e < SHIP_ENGINES_INDEX + lengthof(_ship_vehicle_info));
assert(e - SHIP_ENGINES_INDEX < lengthof(_ship_vehicle_info));
return &_ship_vehicle_info[e - SHIP_ENGINES_INDEX];
}
static inline const AircraftVehicleInfo* AircraftVehInfo(EngineID e)
static inline AircraftVehicleInfo *AircraftVehInfo(uint e)
{
assert(e >= AIRCRAFT_ENGINES_INDEX && e < AIRCRAFT_ENGINES_INDEX + lengthof(_aircraft_vehicle_info));
assert(e - AIRCRAFT_ENGINES_INDEX < lengthof(_aircraft_vehicle_info));
return &_aircraft_vehicle_info[e - AIRCRAFT_ENGINES_INDEX];
}
static inline const RoadVehicleInfo* RoadVehInfo(EngineID e)
static inline RoadVehicleInfo *RoadVehInfo(uint e)
{
assert(e >= ROAD_ENGINES_INDEX && e < ROAD_ENGINES_INDEX + lengthof(_road_vehicle_info));
assert(e - ROAD_ENGINES_INDEX < lengthof(_road_vehicle_info));
return &_road_vehicle_info[e - ROAD_ENGINES_INDEX];
}
void UnloadWagonOverrides(void);
void UnloadCustomEngineSprites(void);
void UnloadCustomEngineNames(void);
/************************************************************************
* Engine Replacement stuff
************************************************************************/
/**
* Struct to store engine replacements. DO NOT USE outside of engine.c. Is
* placed here so the only exception to this rule, the saveload code, can use
* it.
*/
struct EngineRenew {
uint16 index;
EngineID from;
EngineID to;
struct EngineRenew *next;
};
typedef struct EngineRenew EngineRenew;
/**
* Memory pool for engine renew elements. DO NOT USE outside of engine.c. Is
* placed here so the only exception to this rule, the saveload code, can use
* it.
*/
extern MemoryPool _engine_renew_pool;
/**
* DO NOT USE outside of engine.c. Is
* placed here so the only exception to this rule, the saveload code, can use
* it.
*/
static inline EngineRenew *GetEngineRenew(uint16 index)
{
return (EngineRenew*)GetItemFromPool(&_engine_renew_pool, index);
}
/**
* A list to group EngineRenew directives together (such as per-player).
*/
typedef EngineRenew* EngineRenewList;
/**
* Remove all engine replacement settings for the player.
* @param er The renewlist for a given player.
* @return The new renewlist for the player.
*/
void RemoveAllEngineReplacement(EngineRenewList* erl);
/**
* Retrieve the engine replacement in a given renewlist for an original engine type.
* @param erl The renewlist to search in.
* @param engine Engine type to be replaced.
* @return The engine type to replace with, or INVALID_ENGINE if no
* replacement is in the list.
*/
EngineID EngineReplacement(EngineRenewList erl, EngineID engine);
/**
* Add an engine replacement to the given renewlist.
* @param erl The renewlist to add to.
* @param old_engine The original engine type.
* @param new_engine The replacement engine type.
* @param flags The calling command flags.
* @return 0 on success, CMD_ERROR on failure.
*/
int32 AddEngineReplacement(EngineRenewList* erl, EngineID old_engine, EngineID new_engine, uint32 flags);
/**
* Remove an engine replacement from a given renewlist.
* @param erl The renewlist from which to remove the replacement
* @param engine The original engine type.
* @param flags The calling command flags.
* @return 0 on success, CMD_ERROR on failure.
*/
int32 RemoveEngineReplacement(EngineRenewList* erl, EngineID engine, uint32 flags);
#endif /* ENGINE_H */
#endif

View File

@@ -1,10 +1,6 @@
/* $Id$ */
#include "stdafx.h"
#include "openttd.h"
#include "ttd.h"
#include "table/strings.h"
#include "table/sprites.h"
#include "functions.h"
#include "window.h"
#include "gui.h"
#include "viewport.h"
@@ -12,16 +8,18 @@
#include "engine.h"
#include "command.h"
#include "news.h"
#include "variables.h"
static StringID GetEngineCategoryName(EngineID engine)
static StringID GetEngineCategoryName(byte engine)
{
if (engine < NUM_TRAIN_ENGINES) {
switch (GetEngine(engine)->railtype) {
case RAILTYPE_RAIL: return STR_8102_RAILROAD_LOCOMOTIVE;
case RAILTYPE_MONO: return STR_8106_MONORAIL_LOCOMOTIVE;
case RAILTYPE_MAGLEV: return STR_8107_MAGLEV_LOCOMOTIVE;
switch (_engines[engine].railtype) {
case 0:
return STR_8102_RAILROAD_LOCOMOTIVE;
case 1:
return STR_8106_MONORAIL_LOCOMOTIVE;
case 2:
return STR_8107_MAGLEV_LOCOMOTIVE;
}
}
@@ -35,7 +33,7 @@ static StringID GetEngineCategoryName(EngineID engine)
}
static const Widget _engine_preview_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 5, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_TEXTBTN, RESIZE_NONE, 5, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, RESIZE_NONE, 5, 11, 299, 0, 13, STR_8100_MESSAGE_FROM_VEHICLE_MANUFACTURE, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_IMGBTN, RESIZE_NONE, 5, 0, 299, 14, 191, 0x0, STR_NULL},
{ WWT_PUSHTXTBTN, RESIZE_NONE, 5, 85, 144, 172, 183, STR_00C9_NO, STR_NULL},
@@ -43,19 +41,14 @@ static const Widget _engine_preview_widgets[] = {
{ WIDGETS_END},
};
typedef void DrawEngineProc(int x, int y, EngineID engine, uint32 image_ormod);
typedef void DrawEngineInfoProc(EngineID, int x, int y, int maxw);
typedef void DrawEngineProc(int x, int y, int engine, uint32 image_ormod);
typedef void DrawEngineInfoProc(int x, int y, int engine, int maxw);
typedef struct DrawEngineInfo {
DrawEngineProc *engine_proc;
DrawEngineInfoProc *info_proc;
} DrawEngineInfo;
static void DrawTrainEngineInfo(EngineID engine, int x, int y, int maxw);
static void DrawRoadVehEngineInfo(EngineID engine, int x, int y, int maxw);
static void DrawShipEngineInfo(EngineID engine, int x, int y, int maxw);
static void DrawAircraftEngineInfo(EngineID engine, int x, int y, int maxw);
static const DrawEngineInfo _draw_engine_list[4] = {
{DrawTrainEngine,DrawTrainEngineInfo},
{DrawRoadVehEngine,DrawRoadVehEngineInfo},
@@ -65,40 +58,39 @@ static const DrawEngineInfo _draw_engine_list[4] = {
static void EnginePreviewWndProc(Window *w, WindowEvent *e)
{
switch (e->event) {
case WE_PAINT: {
EngineID engine = w->window_number;
const DrawEngineInfo* dei;
int width;
byte eng;
int engine;
const DrawEngineInfo *dei;
int width;
switch(e->event) {
case WE_PAINT:
DrawWindowWidgets(w);
engine = w->window_number;
SetDParam(0, GetEngineCategoryName(engine));
DrawStringMultiCenter(150, 44, STR_8101_WE_HAVE_JUST_DESIGNED_A, 296);
DrawStringCentered(w->width >> 1, 80, GetCustomEngineName(engine), 0x10);
(dei = _draw_engine_list,engine < NUM_TRAIN_ENGINES) ||
(dei++,engine < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES) ||
(dei++,engine < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES) ||
eng = (byte)engine;
(dei = _draw_engine_list,eng < NUM_TRAIN_ENGINES) ||
(dei++,eng < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES) ||
(dei++,eng < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES) ||
(dei++, true);
width = w->width;
dei->engine_proc(width >> 1, 100, engine, 0);
dei->info_proc(engine, width >> 1, 130, width - 52);
break;
}
case WE_CLICK:
switch (e->click.widget) {
case 3:
DeleteWindow(w);
break;
case 4:
DoCommandP(0, w->window_number, 0, NULL, CMD_WANT_ENGINE_PREVIEW);
DeleteWindow(w);
break;
switch(e->click.widget) {
case 3: DeleteWindow(w); break;
case 4:
DoCommandP(0, w->window_number, 0, NULL, CMD_WANT_ENGINE_PREVIEW);
DeleteWindow(w);
break;
}
break;
}
@@ -113,7 +105,7 @@ static const WindowDesc _engine_preview_desc = {
};
void ShowEnginePreviewWindow(EngineID engine)
void ShowEnginePreviewWindow(int engine)
{
Window *w;
@@ -121,30 +113,9 @@ void ShowEnginePreviewWindow(EngineID engine)
w->window_number = engine;
}
static void DrawTrainEngineInfo(EngineID engine, int x, int y, int maxw)
{
const RailVehicleInfo *rvi = RailVehInfo(engine);
uint multihead = (rvi->flags & RVI_MULTIHEAD) ? 1 : 0;
SetDParam(0, (_price.build_railvehicle >> 3) * rvi->base_cost >> 5);
SetDParam(2, rvi->max_speed * 10 >> 4);
SetDParam(3, rvi->power << multihead);
SetDParam(1, rvi->weight << multihead);
SetDParam(4, rvi->running_cost_base * _price.running_rail[rvi->running_cost_class] >> 8 << multihead);
if (rvi->capacity != 0) {
SetDParam(5, _cargoc.names_long[rvi->cargo_type]);
SetDParam(6, rvi->capacity << multihead);
} else {
SetDParam(5, STR_8838_N_A);
}
DrawStringMultiCenter(x, y, STR_885B_COST_WEIGHT_T_SPEED_POWER, maxw);
}
void DrawNewsNewTrainAvail(Window *w)
{
EngineID engine;
int engine;
DrawNewsBorder(w);
@@ -158,34 +129,22 @@ void DrawNewsNewTrainAvail(Window *w)
DrawStringMultiCenter(w->width >> 1, 57, STR_885A, w->width - 2);
DrawTrainEngine(w->width >> 1, 88, engine, 0);
GfxFillRect(25, 56, w->width - 56, 112, 0x323 | USE_COLORTABLE);
GfxFillRect(25, 56, w->width - 56, 112, 0x4323);
DrawTrainEngineInfo(engine, w->width >> 1, 129, w->width - 52);
}
StringID GetNewsStringNewTrainAvail(const NewsItem *ni)
StringID GetNewsStringNewTrainAvail(NewsItem *ni)
{
EngineID engine = ni->string_id;
int engine = ni->string_id;
SetDParam(0, STR_8859_NEW_NOW_AVAILABLE);
SetDParam(1, GetEngineCategoryName(engine));
SetDParam(2, GetCustomEngineName(engine));
return STR_02B6;
}
static void DrawAircraftEngineInfo(EngineID engine, int x, int y, int maxw)
{
const AircraftVehicleInfo *avi = AircraftVehInfo(engine);
SetDParam(0, (_price.aircraft_base >> 3) * avi->base_cost >> 5);
SetDParam(1, avi->max_speed << 3);
SetDParam(2, avi->passenger_capacity);
SetDParam(3, avi->mail_capacity);
SetDParam(4, avi->running_cost * _price.aircraft_running >> 8);
DrawStringMultiCenter(x, y, STR_A02E_COST_MAX_SPEED_CAPACITY, maxw);
}
void DrawNewsNewAircraftAvail(Window *w)
{
EngineID engine;
int engine;
DrawNewsBorder(w);
@@ -198,35 +157,21 @@ void DrawNewsNewAircraftAvail(Window *w)
DrawStringMultiCenter(w->width >> 1, 57, STR_A02D, w->width - 2);
DrawAircraftEngine(w->width >> 1, 93, engine, 0);
GfxFillRect(25, 56, w->width - 56, 110, 0x323 | USE_COLORTABLE);
GfxFillRect(25, 56, w->width - 56, 110, 0x4323);
DrawAircraftEngineInfo(engine, w->width >> 1, 131, w->width - 52);
}
StringID GetNewsStringNewAircraftAvail(const NewsItem *ni)
StringID GetNewsStringNewAircraftAvail(NewsItem *ni)
{
EngineID engine = ni->string_id;
int engine = ni->string_id;
SetDParam(0, STR_A02C_NEW_AIRCRAFT_NOW_AVAILABLE);
SetDParam(1, GetCustomEngineName(engine));
return STR_02B6;
}
static void DrawRoadVehEngineInfo(EngineID engine, int x, int y, int maxw)
{
const RoadVehicleInfo *rvi = RoadVehInfo(engine);
SetDParam(0, (_price.roadveh_base >> 3) * rvi->base_cost >> 5);
SetDParam(1, rvi->max_speed * 10 >> 5);
SetDParam(2, rvi->running_cost * _price.roadveh_running >> 8);
SetDParam(4, rvi->capacity);
SetDParam(3, _cargoc.names_long[rvi->cargo_type]);
DrawStringMultiCenter(x, y, STR_902A_COST_SPEED_RUNNING_COST, maxw);
}
void DrawNewsNewRoadVehAvail(Window *w)
{
EngineID engine;
int engine;
DrawNewsBorder(w);
@@ -238,32 +183,21 @@ void DrawNewsNewRoadVehAvail(Window *w)
DrawStringMultiCenter(w->width >> 1, 57, STR_9029, w->width - 2);
DrawRoadVehEngine(w->width >> 1, 88, engine, 0);
GfxFillRect(25, 56, w->width - 56, 112, 0x323 | USE_COLORTABLE);
GfxFillRect(25, 56, w->width - 56, 112, 0x4323);
DrawRoadVehEngineInfo(engine, w->width >> 1, 129, w->width - 52);
}
StringID GetNewsStringNewRoadVehAvail(const NewsItem *ni)
StringID GetNewsStringNewRoadVehAvail(NewsItem *ni)
{
EngineID engine = ni->string_id;
int engine = ni->string_id;
SetDParam(0, STR_9028_NEW_ROAD_VEHICLE_NOW_AVAILABLE);
SetDParam(1, GetCustomEngineName(engine));
return STR_02B6;
}
static void DrawShipEngineInfo(EngineID engine, int x, int y, int maxw)
{
const ShipVehicleInfo *svi = ShipVehInfo(engine);
SetDParam(0, svi->base_cost * (_price.ship_base >> 3) >> 5);
SetDParam(1, svi->max_speed * 10 >> 5);
SetDParam(2, _cargoc.names_long[svi->cargo_type]);
SetDParam(3, svi->capacity);
SetDParam(4, svi->running_cost * _price.ship_running >> 8);
DrawStringMultiCenter(x, y, STR_982E_COST_MAX_SPEED_CAPACITY, maxw);
}
void DrawNewsNewShipAvail(Window *w)
{
EngineID engine;
int engine;
DrawNewsBorder(w);
@@ -276,13 +210,13 @@ void DrawNewsNewShipAvail(Window *w)
DrawStringMultiCenter(w->width >> 1, 57, STR_982D, w->width - 2);
DrawShipEngine(w->width >> 1, 93, engine, 0);
GfxFillRect(25, 56, w->width - 56, 110, 0x323 | USE_COLORTABLE);
GfxFillRect(25, 56, w->width - 56, 110, 0x4323);
DrawShipEngineInfo(engine, w->width >> 1, 131, w->width - 52);
}
StringID GetNewsStringNewShipAvail(const NewsItem *ni)
StringID GetNewsStringNewShipAvail(NewsItem *ni)
{
EngineID engine = ni->string_id;
int engine = ni->string_id;
SetDParam(0, STR_982C_NEW_SHIP_NOW_AVAILABLE);
SetDParam(1, GetCustomEngineName(engine));
return STR_02B6;

View File

@@ -1,12 +1,11 @@
/* $Id$ */
#ifndef __BEOS__
#ifndef __MORPHOS__
#include "../stdafx.h"
#include "../openttd.h"
#include "../sound.h"
#include "../string.h"
#include "../variables.h"
#include "extmidi.h"
#include "stdafx.h"
#include "ttd.h"
#include "hal.h"
#include "sound.h"
#include "string.h"
#include <fcntl.h>
#include <sys/types.h>
#include <sys/wait.h>
@@ -17,7 +16,7 @@
static struct {
char song[MAX_PATH];
pid_t pid;
int pid;
} _midi;
static void DoPlay(void);
@@ -69,15 +68,19 @@ static void DoPlay(void)
int d;
close(0);
close(1);
close(2);
d = open("/dev/null", O_RDONLY);
if (d != -1 && dup2(d, 1) != -1 && dup2(d, 2) != -1) {
#if defined(MIDI_ARG)
execlp(msf.extmidi, "extmidi", MIDI_ARG, _midi.song, (char*)0);
#else
execlp(msf.extmidi, "extmidi", _midi.song, (char*)0);
#endif
if (d != -1) {
if (dup2(d, 1) != -1 && dup2(d, 2) != -1) {
#if defined(MIDI_ARG)
execlp(msf.extmidi, "extmidi", MIDI_ARG, _midi.song, NULL);
#else
execlp(msf.extmidi, "extmidi", _midi.song, NULL);
#endif
}
}
_exit(1);
exit(1);
}
case -1:
@@ -105,3 +108,4 @@ const HalMusicDriver _extmidi_music_driver = {
};
#endif /* __MORPHOS__ */
#endif /* __BEOS__ */

View File

@@ -1,11 +1,6 @@
/* $Id$ */
#include "stdafx.h"
#include "openttd.h"
#include "ttd.h"
#include "fileio.h"
#include "functions.h"
#include "macros.h"
#include "variables.h"
#if defined(UNIX) || defined(__OS2__)
#include <ctype.h> // required for tolower()
#endif
@@ -141,37 +136,6 @@ bool FiosCheckFileExists(const char *filename)
}
}
FILE *FioFOpenFile(const char *filename)
{
FILE *f;
char buf[MAX_PATH];
sprintf(buf, "%s%s", _path.data_dir, filename);
f = fopen(buf, "rb");
#if !defined(WIN32)
if (f == NULL) {
char *s;
// Make lower case and try again
for(s=buf + strlen(_path.data_dir) - 1; *s != 0; s++)
*s = tolower(*s);
f = fopen(buf, "rb");
#if defined SECOND_DATA_DIR
// tries in the 2nd data directory
if (f == NULL) {
sprintf(buf, "%s%s", _path.second_data_dir, filename);
for(s=buf + strlen(_path.second_data_dir) - 1; *s != 0; s++)
*s = tolower(*s);
f = fopen(buf, "rb");
}
#endif
}
#endif
return f;
}
void FioOpenFile(int slot, const char *filename)
{
FILE *f;
@@ -196,10 +160,6 @@ void FioOpenFile(int slot, const char *filename)
*s = tolower(*s);
f = fopen(buf, "rb");
}
if (f == NULL)
sprintf(buf, "%s%s", _path.data_dir, filename); //makes it print the primary datadir path instead of the secundary one
#endif
}
#endif
@@ -211,3 +171,5 @@ void FioOpenFile(int slot, const char *filename)
_fio.handles[slot] = f;
FioSeekToFile(slot << 24);
}

View File

@@ -1,5 +1,3 @@
/* $Id$ */
#ifndef FILEIO_H
#define FILEIO_H
@@ -10,7 +8,6 @@ byte FioReadByte(void);
uint16 FioReadWord(void);
uint32 FioReadDword(void);
void FioCloseAll(void);
FILE *FioFOpenFile(const char *filename);
void FioOpenFile(int slot, const char *filename);
void FioReadBlock(void *ptr, uint size);
void FioSkipBytes(int n);

View File

@@ -1,8 +1,11 @@
/* $Id$ */
#ifndef FUNCTIONS_H
#define FUNCTIONS_H
/* vehicle.c */
/* window.c */
/* landscape.c */
void FindLandscapeHeight(TileInfo *ti, uint x, uint y);
void FindLandscapeHeightByTile(TileInfo *ti, TileIndex tile);
@@ -45,32 +48,38 @@ static inline Point RemapCoords2(int x, int y)
/* clear_land.c */
void DrawHillyLandTile(const TileInfo *ti);
void DrawClearLandTile(const TileInfo *ti, byte set);
void DrawClearLandFence(const TileInfo *ti);
void DrawHillyLandTile(TileInfo *ti);
void DrawClearLandTile(TileInfo *ti, byte set);
void DrawClearLandFence(TileInfo *ti, byte img);
void TileLoopClearHelper(TileIndex tile);
/* station_land.c */
void StationPickerDrawSprite(int x, int y, int railtype, int image);
/* track_land.c */
void DrawTrainDepotSprite(int x, int y, int image, int railtype);
/* road_land.c */
void DrawRoadDepotSprite(int x, int y, int image);
/* water_land.c */
void DrawShipDepotSprite(int x, int y, int image);
void TileLoop_Water(TileIndex tile);
void TileLoop_Water(uint tile);
/* players.c */
bool CheckPlayerHasMoney(int32 cost);
void SubtractMoneyFromPlayer(int32 cost);
void SubtractMoneyFromPlayerFract(PlayerID player, int32 cost);
bool CheckOwnership(PlayerID owner);
bool CheckTileOwnership(TileIndex tile);
StringID GetPlayerNameString(PlayerID player, uint index);
void SubtractMoneyFromPlayerFract(byte player, int32 cost);
bool CheckOwnership(byte owner);
bool CheckTileOwnership(uint tile);
StringID GetPlayerNameString(byte player, byte index);
/* standard */
void ShowInfo(const char *str);
void CDECL ShowInfoF(const char *str, ...);
void NORETURN CDECL error(const char *str, ...);
/* openttd.c */
/* ttd.c */
// **************
// * Warning: DO NOT enable this unless you understand what it does
@@ -84,21 +93,6 @@ void NORETURN CDECL error(const char *str, ...);
//#define RANDOM_DEBUG
// Enable this to produce higher quality random numbers.
// Doesn't work with network yet.
//#define MERSENNE_TWISTER
// Mersenne twister functions
void SeedMT(uint32 seed);
uint32 RandomMT(void);
#ifdef MERSENNE_TWISTER
static inline uint32 Random(void) { return RandomMT(); }
uint RandomRange(uint max);
#else
#ifdef RANDOM_DEBUG
#define Random() DoRandom(__LINE__, __FILE__)
uint32 DoRandom(int line, const char *file);
@@ -108,21 +102,12 @@ uint32 RandomMT(void);
uint32 Random(void);
uint RandomRange(uint max);
#endif
#endif // MERSENNE_TWISTER
static inline TileIndex RandomTileSeed(uint32 r) { return TILE_MASK(r); }
static inline TileIndex RandomTile(void) { return TILE_MASK(Random()); }
void InitPlayerRandoms(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);
// Used for profiling
#define TIC() { extern uint32 _rdtsc(void); uint32 _xxx_ = _rdtsc(); static float __avg__;
#define TOC(s) _xxx_ = _rdtsc() - _xxx_; __avg__=__avg__*0.99+_xxx_*0.01; printf("%s: %8d %f\n", s, _xxx_,__avg__); }
void SetDate(uint date);
/* facedraw.c */
void DrawPlayerFace(uint32 face, int color, int x, int y);
@@ -139,18 +124,18 @@ void CDECL AddTextMessage(uint16 color, uint8 duration, const char *message, ...
void UndrawTextMessage(void);
void TextMessageDailyLoop(void);
bool AddAnimatedTile(TileIndex tile);
void DeleteAnimatedTile(TileIndex tile);
bool AddAnimatedTile(uint tile);
void DeleteAnimatedTile(uint tile);
void AnimateAnimatedTiles(void);
void InitializeAnimatedTiles(void);
/* tunnelbridge_cmd.c */
bool CheckTunnelInWay(TileIndex tile, int z);
bool CheckBridge_Stuff(byte bridge_type, uint bridge_len);
bool CheckTunnelInWay(uint tile, int z);
bool CheckBridge_Stuff(byte bridge_type, int bridge_len);
uint32 GetBridgeLength(TileIndex begin, TileIndex end);
int CalcBridgeLenCostFactor(int x);
typedef void CommandCallback(bool success, TileIndex tile, uint32 p1, uint32 p2);
typedef void CommandCallback(bool success, uint tile, uint32 p1, uint32 p2);
bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback, uint32 cmd);
/* network.c */
@@ -163,7 +148,7 @@ bool NetworkServerStart(void);
bool NetworkClientConnectGame(const char* host, unsigned short port);
void NetworkReboot(void);
void NetworkDisconnect(void);
void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback);
void NetworkSend_Command(uint32 tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback);
/* misc_cmd.c */
void PlaceTreesRandomly(void);
@@ -186,17 +171,18 @@ uint ConvertIntDate(uint date);
/* misc functions */
void MarkTileDirty(int x, int y);
void MarkTileDirtyByTile(TileIndex tile);
void InvalidateWindow(WindowClass cls, WindowNumber number);
void InvalidateWindowWidget(WindowClass cls, WindowNumber number, byte widget_index);
void InvalidateWindowClasses(WindowClass cls);
void InvalidateWindow(byte cls, WindowNumber number);
void InvalidateWindowWidget(byte cls, WindowNumber number, byte widget_index);
void InvalidateWindowClasses(byte cls);
void DeleteWindowById(WindowClass cls, WindowNumber number);
void DeleteWindowByClass(WindowClass cls);
void SetObjectToPlaceWnd(CursorID icon, byte mode, Window *w);
void SetObjectToPlace(CursorID icon, byte mode, WindowClass window_class, WindowNumber window_num);
void SetObjectToPlaceWnd(int icon, byte mode, Window *w);
void SetObjectToPlace(int icon, byte mode, WindowClass window_class, WindowNumber window_num);
void ResetObjectToPlace(void);
bool ScrollWindowToTile(TileIndex tile, Window * w);
bool ScrollWindowTo(int x, int y, Window * w);
bool ScrollMainWindowToTile(TileIndex tile);
@@ -207,16 +193,15 @@ bool EnsureNoVehicle(TileIndex tile);
bool EnsureNoVehicleZ(TileIndex tile, byte z);
void MarkAllViewportsDirty(int left, int top, int right, int bottom);
void ShowCostOrIncomeAnimation(int x, int y, int z, int32 cost);
void ShowFeederIncomeAnimation(int x, int y, int z, int32 cost);
void DrawFoundation(TileInfo *ti, uint f);
bool CheckIfAuthorityAllows(TileIndex tile);
Town *ClosestTownFromTile(TileIndex tile, uint threshold);
bool CheckIfAuthorityAllows(uint tile);
Town *ClosestTownFromTile(uint tile, uint threshold);
void ChangeTownRating(Town *t, int add, int max);
uint GetRoadBitsByTile(TileIndex tile);
int GetTownRadiusGroup(const Town *t, TileIndex tile);
int GetTownRadiusGroup(Town *t, uint tile);
void ShowNetworkChatQueryWindow(byte desttype, byte dest);
void ShowNetworkGiveMoneyWindow(byte player);
void ShowNetworkNeedGamePassword(void);
@@ -226,6 +211,20 @@ void ShowHighscoreTable(int difficulty, int8 rank);
void ShowEndGameChart(void);
TileIndex AdjustTileCoordRandomly(TileIndex a, byte rng);
enum SaveOrLoadResult {
SL_OK = 0, // completed successfully
SL_ERROR = 1, // error that was caught before internal structures were modified
SL_REINIT = 2, // error that was caught in the middle of updating game state, need to clear it. (can only happen during load)
};
enum SaveOrLoadMode {
SL_INVALID = -1,
SL_LOAD = 0,
SL_SAVE = 1,
SL_OLD_LOAD = 2,
};
int SaveOrLoad(const char *filename, int mode);
void AfterLoadTown(void);
void GenRandomNewGame(uint32 rnd1, uint32 rnd2);
void StartScenarioEditor(uint32 rnd1, uint32 rnd2);
@@ -255,13 +254,16 @@ void InitializeLanguagePacks(void);
void *ReadFileToMem(const char *filename, size_t *lenp, size_t maxsize);
int GetLanguageList(char **languages, int max);
void CheckSwitchToEuro(void);
void LoadFromConfig(void);
void SaveToConfig(void);
void CheckConfig(void);
int ttd_main(int argc, char* argv[]);
byte GetOSVersion(void);
void DeterminePaths(void);
char * CDECL str_fmt(const char *str, ...);
void bubblesort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *));
void CSleep(int milliseconds);
#endif /* FUNCTIONS_H */

1121
gfx.c

File diff suppressed because it is too large Load Diff

63
gfx.h
View File

@@ -1,9 +1,6 @@
/* $Id$ */
#ifndef GFX_H
#define GFX_H
typedef byte Pixel;
typedef struct ColorList {
byte unk0, unk1, unk2;
@@ -13,7 +10,7 @@ typedef struct ColorList {
} ColorList;
struct DrawPixelInfo {
Pixel *dst_ptr;
byte *dst_ptr;
int left, top, width, height;
int pitch;
uint16 zoom;
@@ -23,10 +20,10 @@ struct DrawPixelInfo {
typedef struct CursorVars {
Point pos, size, offs, delta;
Point draw_pos, draw_size;
CursorID sprite;
uint32 sprite;
int wheel; // mouse wheel movement
const CursorID *animate_list, *animate_cur;
const uint16 *animate_list, *animate_cur;
uint animate_timeout;
bool visible;
@@ -37,52 +34,33 @@ typedef struct CursorVars {
void RedrawScreenRect(int left, int top, int right, int bottom);
void GfxScroll(int left, int top, int width, int height, int xo, int yo);
// XXX doesn't really belong here, but the only
// consumers always use it in conjunction with DoDrawString()
#define UPARROW "\x80"
#define DOWNARROW "\xAA"
int DrawStringCentered(int x, int y, StringID str, uint16 color);
int DrawStringCenteredTruncated(int xl, int xr, int y, StringID str, uint16 color);
int DoDrawStringCentered(int x, int y, const char *str, uint16 color);
int DrawString(int x, int y, StringID str, uint16 color);
int DrawStringTruncated(int x, int y, StringID str, uint16 color, uint maxw);
int DrawStringCentered(int x, int y, uint16 str, uint16 color);
int DrawString(int x, int y, uint16 str, uint16 color);
void DrawStringCenterUnderline(int x, int y, uint16 str, uint16 color);
int DoDrawString(const char *string, int x, int y, uint16 color);
int DoDrawStringTruncated(const char *str, int x, int y, uint16 color, uint maxw);
void DrawStringCenterUnderline(int x, int y, StringID str, uint16 color);
void DrawStringCenterUnderlineTruncated(int xl, int xr, int y, StringID str, uint16 color);
void DrawStringRightAligned(int x, int y, StringID str, uint16 color);
void DrawStringRightAlignedTruncated(int x, int y, StringID str, uint16 color, uint maxw);
void DrawStringRightAligned(int x, int y, uint16 str, uint16 color);
void GfxFillRect(int left, int top, int right, int bottom, int color);
void GfxDrawLine(int left, int top, int right, int bottom, int color);
void DrawFrameRect(int left, int top, int right, int bottom, int color, int flags);
uint16 GetDrawStringPlayerColor(PlayerID player);
uint16 GetDrawStringPlayerColor(byte player);
int GetStringWidth(const char *str);
void LoadStringWidthTable(void);
void DrawStringMultiCenter(int x, int y, StringID str, int maxw);
void DrawStringMultiLine(int x, int y, StringID str, int maxw);
void DrawStringMultiCenter(int x, int y, uint16 str, int maxw);
void DrawStringMultiLine(int x, int y, uint16 str, int maxw);
void DrawDirtyBlocks(void);
void SetDirtyBlocks(int left, int top, int right, int bottom);
void MarkWholeScreenDirty(void);
void GfxInitPalettes(void);
bool FillDrawPixelInfo(DrawPixelInfo* n, const DrawPixelInfo* o, int left, int top, int width, int height);
bool FillDrawPixelInfo(DrawPixelInfo *n, DrawPixelInfo *o, int left, int top, int width, int height);
/* window.c */
void DrawOverlappedWindowForAll(int left, int top, int right, int bottom);
void SetMouseCursor(uint cursor);
void SetAnimatedMouseCursor(const CursorID *table);
void SetAnimatedMouseCursor(const uint16 *table);
void CursorTick(void);
void DrawMouseCursor(void);
void ScreenSizeChanged(void);
@@ -111,21 +89,18 @@ VARDEF int _pal_last_dirty;
VARDEF bool _use_dos_palette;
typedef struct Colour {
byte r;
byte g;
byte b;
} Colour;
/* spritecache.c */
//enum { NUM_SPRITES = 0x1320 };
//enum { NUM_SPRITES = 0x1500 };
enum { NUM_SPRITES = 0x3500 }; // 1500 + space for custom GRF sets
extern Colour _cur_palette[256];
/* tables.h */
extern byte _palettes[4][256 * 3];
VARDEF byte _cur_palette[768];
typedef enum StringColorFlags {
IS_PALETTE_COLOR = 0x100, // color value is already a real palette color index, not an index of a StringColor
} StringColorFlags;
#ifdef _DEBUG
extern bool _dbg_screen_rect;
#endif
#endif /* GFX_H */

382
gfxinit.c
View File

@@ -1,382 +0,0 @@
/* $Id$ */
#include "stdafx.h"
#include "openttd.h"
#include "debug.h"
#include "functions.h"
#include "gfx.h"
#include "gfxinit.h"
#include "spritecache.h"
#include "table/sprites.h"
#include "fileio.h"
#include "newgrf.h"
#include "md5.h"
#include "variables.h"
#include <ctype.h>
typedef struct MD5File {
const char * const filename; // filename
const md5_byte_t hash[16]; // md5 sum of the file
} MD5File;
typedef struct FileList {
const MD5File basic[5]; // grf files that always have to be loaded
const MD5File landscape[3]; // landscape specific grf files
} FileList;
enum {
SKIP = 0xFFFE,
END = 0xFFFF
};
#include "table/files.h"
#include "table/landscape_sprite.h"
static const SpriteID * const _landscape_spriteindexes[] = {
_landscape_spriteindexes_1,
_landscape_spriteindexes_2,
_landscape_spriteindexes_3,
};
static const SpriteID * const _slopes_spriteindexes[] = {
_slopes_spriteindexes_0,
_slopes_spriteindexes_1,
_slopes_spriteindexes_2,
_slopes_spriteindexes_3,
};
static uint LoadGrfFile(const char* filename, uint load_index, int file_index)
{
uint load_index_org = load_index;
FioOpenFile(file_index, filename);
DEBUG(spritecache, 2) ("Reading grf-file ``%s''", filename);
while (LoadNextSprite(load_index, file_index)) {
load_index++;
if (load_index >= MAX_SPRITES) {
error("Too many sprites. Recompile with higher MAX_SPRITES value or remove some custom GRF files.");
}
}
DEBUG(spritecache, 2) ("Currently %i sprites are loaded", load_index);
return load_index - load_index_org;
}
static void LoadGrfIndexed(const char* filename, const SpriteID* index_tbl, int file_index)
{
uint start;
FioOpenFile(file_index, filename);
DEBUG(spritecache, 2) ("Reading indexed grf-file ``%s''", filename);
while ((start = *index_tbl++) != END) {
uint end = *index_tbl++;
if (start == SKIP) { // skip sprites (amount in second var)
SkipSprites(end);
} else { // load sprites and use indexes from start to end
do {
#ifdef NDEBUG
LoadNextSprite(start, file_index);
#else
bool b = LoadNextSprite(start, file_index);
assert(b);
#endif
} while (++start <= end);
}
}
}
/* Check that the supplied MD5 hash matches that stored for the supplied filename */
static bool CheckMD5Digest(const MD5File file, md5_byte_t *digest, bool warn)
{
uint i;
/* Loop through each byte of the file MD5 and the stored MD5... */
for (i = 0; i < 16; i++) if (file.hash[i] != digest[i]) break;
/* If all bytes of the MD5's match (i.e. the MD5's match)... */
if (i == 16) {
return true;
} else {
if (warn) fprintf(stderr, "MD5 of %s is ****INCORRECT**** - File Corrupt.\n", file.filename);
return false;
};
}
/* Calculate and check the MD5 hash of the supplied filename.
* returns true if the checksum is correct */
static bool FileMD5(const MD5File file, bool warn)
{
FILE *f;
char buf[MAX_PATH];
// open file
sprintf(buf, "%s%s", _path.data_dir, file.filename);
f = fopen(buf, "rb");
#if !defined(WIN32)
if (f == NULL) {
char *s;
// make lower case and check again
for (s = buf + strlen(_path.data_dir) - 1; *s != '\0'; s++)
*s = tolower(*s);
f = fopen(buf, "rb");
}
#endif
if (f != NULL) {
md5_state_t filemd5state;
md5_byte_t buffer[1024];
md5_byte_t digest[16];
size_t len;
md5_init(&filemd5state);
while ((len = fread(buffer, 1, sizeof(buffer), f)) != 0)
md5_append(&filemd5state, buffer, len);
if (ferror(f) && warn) fprintf(stderr, "Error Reading from %s \n", buf);
fclose(f);
md5_finish(&filemd5state, digest);
return CheckMD5Digest(file, digest, warn);
} else { // file not found
return false;
}
}
/* Checks, if either the Windows files exist (TRG1R.GRF) or the DOS files (TRG1.GRF)
* by comparing the MD5 checksums of the files. _use_dos_palette is set accordingly.
* If neither are found, Windows palette is assumed.
*
* (Note: Also checks sample.cat for corruption) */
void CheckExternalFiles(void)
{
uint i;
// count of files from this version
uint dos = 0;
uint win = 0;
for (i = 0; i < 2; i++) if (FileMD5(files_dos.basic[i], true)) dos++;
for (i = 0; i < 3; i++) if (FileMD5(files_dos.landscape[i], true)) dos++;
for (i = 0; i < 2; i++) if (FileMD5(files_win.basic[i], true)) win++;
for (i = 0; i < 3; i++) if (FileMD5(files_win.landscape[i], true)) win++;
if (!FileMD5(sample_cat_win, false) && !FileMD5(sample_cat_dos, false))
fprintf(stderr, "Your sample.cat file is corrupted or missing!\n");
/*
* forced DOS palette via command line -> leave it that way
* all Windows files present -> Windows palette
* all DOS files present -> DOS palette
* no Windows files present and any DOS file present -> DOS palette
* otherwise -> Windows palette
*/
if (_use_dos_palette) {
return;
} else if (win == 5) {
_use_dos_palette = false;
} else if (dos == 5 || (win == 0 && dos > 0)) {
_use_dos_palette = true;
} else {
_use_dos_palette = false;
}
}
static const SpriteID trg1idx[] = {
0, 1, // Mouse cursor, ZZZ
/* Medium font */
2, 92, // ' ' till 'z'
SKIP, 36,
160, 160, // Move <20> to the correct position
98, 98, // Up arrow
131, 133,
SKIP, 1, // skip currency sign
135, 135,
SKIP, 1,
137, 137,
SKIP, 1,
139, 139,
140, 140, // TODO Down arrow
141, 141,
142, 142, // TODO Check mark
143, 143, // TODO Cross
144, 144,
145, 145, // TODO Right arrow
146, 149,
118, 122, // Transport markers
SKIP, 2,
157, 157,
114, 115, // Small up/down arrows
SKIP, 1,
161, 225,
/* Small font */
226, 316, // ' ' till 'z'
SKIP, 36,
384, 384, // Move <20> to the correct position
322, 322, // Up arrow
355, 357,
SKIP, 1, // skip currency sign
359, 359,
SKIP, 1,
361, 361,
SKIP, 1,
363, 363,
364, 364, // TODO Down arrow
365, 366,
SKIP, 1,
368, 368,
369, 369, // TODO Right arrow
370, 373,
SKIP, 7,
381, 381,
SKIP, 3,
385, 449,
/* Big font */
450, 540, // ' ' till 'z'
SKIP, 36,
608, 608, // Move <20> to the correct position
SKIP, 1,
579, 581,
SKIP, 1,
583, 583,
SKIP, 5,
589, 589,
SKIP, 15,
605, 605,
SKIP, 3,
609, 625,
SKIP, 1,
627, 632,
SKIP, 1,
634, 639,
SKIP, 1,
641, 657,
SKIP, 1,
659, 664,
SKIP, 2,
667, 671,
SKIP, 1,
673, 673,
/* Graphics */
674, 4792,
END
};
/* NOTE: When adding a normal sprite, increase OPENTTD_SPRITES_COUNT with the
* amount of sprites and add them to the end of the list, with the index of
* the old sprite-count offset from SPR_OPENTTD_BASE. With this there is no
* correspondence of any kind with the ID's in the grf file, but results in
* a maximum use of sprite slots. */
#define OPENTTD_SPRITES_COUNT 95
static const SpriteID _openttd_grf_indexes[] = {
SPR_IMG_AUTORAIL, SPR_CURSOR_WAYPOINT, // icons etc
134, 134, // euro symbol medium size
582, 582, // euro symbol large size
358, 358, // euro symbol tiny
SPR_CURSOR_CANAL, SPR_IMG_FASTFORWARD, // more icons
648, 648, // nordic char: <20>
616, 616, // nordic char: <20>
666, 666, // nordic char: <20>
634, 634, // nordic char: <20>
SPR_PIN_UP, SPR_CURSOR_CLONE, // more icons
382, 383, // <20> <20> tiny
158, 159, // <20> <20> medium
606, 607, // <20> <20> large
360, 360, // <20> tiny
362, 362, // <20> tiny
136, 136, // <20> medium
138, 138, // <20> medium
584, 584, // <20> large
586, 586, // <20> large
626, 626, // <20> large
658, 658, // <20> large
374, 374, // <20> tiny
378, 378, // <20> tiny
150, 150, // <20> medium
154, 154, // <20> medium
598, 598, // <20> large
602, 602, // <20> large
640, 640, // <20> large
672, 672, // <20> large
380, 380, // <20> tiny
156, 156, // <20> medium
604, 604, // <20> large
317, 320, // { | } ~ tiny
93, 96, // { | } ~ medium
541, 544, // { | } ~ large
SPR_HOUSE_ICON, SPR_HOUSE_ICON,
585, 585, // <20> large
587, 587, // <20> large
592, 592, // <20> large
594, 597, // <20> <20> <20> <20> large
633, 633, // <20> large
665, 665, // <20> large
END
};
static byte _sprite_page_to_load = 0xFF;
static void LoadSpriteTables(void)
{
const FileList* files = _use_dos_palette ? &files_dos : &files_win;
uint load_index;
uint i;
LoadGrfIndexed(files->basic[0].filename, trg1idx, 0);
DupSprite( 2, 130); // non-breaking space medium
DupSprite(226, 354); // non-breaking space tiny
DupSprite(450, 578); // non-breaking space large
load_index = 4793;
for (i = 1; files->basic[i].filename != NULL; i++) {
load_index += LoadGrfFile(files->basic[i].filename, load_index, i);
}
if (_sprite_page_to_load != 0) {
LoadGrfIndexed(
files->landscape[_sprite_page_to_load - 1].filename,
_landscape_spriteindexes[_sprite_page_to_load - 1],
i++
);
}
assert(load_index == SPR_CANALS_BASE);
load_index += LoadGrfFile("canalsw.grf", load_index, i++);
assert(load_index == SPR_SLOPES_BASE);
LoadGrfIndexed("trkfoundw.grf", _slopes_spriteindexes[_opt.landscape], i++);
load_index = SPR_AUTORAIL_BASE;
load_index += LoadGrfFile("autorail.grf", load_index, i++);
assert(load_index == SPR_OPENTTD_BASE);
LoadGrfIndexed("openttd.grf", _openttd_grf_indexes, i++);
load_index = SPR_OPENTTD_BASE + OPENTTD_SPRITES_COUNT;
LoadNewGRF(load_index, i);
}
void GfxLoadSprites(void)
{
// Need to reload the sprites only if the landscape changed
if (_sprite_page_to_load != _opt.landscape) {
_sprite_page_to_load = _opt.landscape;
// Sprite cache
DEBUG(spritecache, 1) ("Loading sprite set %d.", _sprite_page_to_load);
GfxInitSpriteMem();
LoadSpriteTables();
GfxInitPalettes();
}
}

View File

@@ -1,9 +0,0 @@
/* $Id$ */
#ifndef GFXINIT_H
#define GFXINIT_H
void CheckExternalFiles(void);
void GfxLoadSprites(void);
#endif /* GFXINIT_H */

View File

@@ -1,10 +1,6 @@
/* $Id$ */
#include "stdafx.h"
#include "openttd.h"
#include "ttd.h"
#include "table/strings.h"
#include "table/sprites.h"
#include "functions.h"
#include "window.h"
#include "gui.h"
#include "gfx.h"
@@ -13,7 +9,6 @@
#include "signs.h"
#include "strings.h"
#include "debug.h"
#include "variables.h"
static uint _legend_excludebits;
static uint _legend_cargobits;
@@ -44,7 +39,7 @@ typedef struct GraphDrawer {
#define INVALID_VALUE 0x80000000
static void DrawGraph(const GraphDrawer *gw)
static void DrawGraph(GraphDrawer *gw)
{
int i,j,k;
@@ -52,7 +47,7 @@ static void DrawGraph(const GraphDrawer *gw)
int color;
int right, bottom;
int num_x, num_dataset;
const uint64 *row_ptr, *col_ptr;
uint64 *row_ptr, *col_ptr;
int64 mx;
int adj_height;
uint64 y_scaling, tmp;
@@ -219,18 +214,20 @@ void DrawPlayerIcon(int p, int x, int y)
static void GraphLegendWndProc(Window *w, WindowEvent *e)
{
const Player* p;
Player *p;
switch(e->event) {
case WE_PAINT:
FOR_ALL_PLAYERS(p) {
if (!p->is_active) SETBIT(_legend_excludebits, p->index);
if (!p->is_active)
SETBIT(_legend_excludebits, p->index);
}
w->click_state = (~_legend_excludebits) << 3;
w->click_state = ((~_legend_excludebits) << 3);
DrawWindowWidgets(w);
FOR_ALL_PLAYERS(p) {
if (!p->is_active) continue;
if (!p->is_active)
continue;
DrawPlayerIcon(p->index, 4, 18+p->index*12);
@@ -243,7 +240,7 @@ static void GraphLegendWndProc(Window *w, WindowEvent *e)
case WE_CLICK:
if (IS_INT_INSIDE(e->click.widget, 3, 11)) {
_legend_excludebits ^= (1 << (e->click.widget - 3));
_legend_excludebits ^= (1 << (e->click.widget-3));
SetWindowDirty(w);
InvalidateWindow(WC_INCOME_GRAPH, 0);
InvalidateWindow(WC_OPERATING_PROFIT, 0);
@@ -256,7 +253,7 @@ static void GraphLegendWndProc(Window *w, WindowEvent *e)
}
static const Widget _graph_legend_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 249, 0, 13, STR_704E_KEY_TO_COMPANY_GRAPHS, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 249, 14, 113, 0x0,STR_NULL},
{ WWT_IMGBTN, RESIZE_NONE, 14, 2, 247, 16, 27, 0x0,STR_704F_CLICK_HERE_TO_TOGGLE_COMPANY},
@@ -289,7 +286,7 @@ static void ShowGraphLegend(void)
static void SetupGraphDrawerForPlayers(GraphDrawer *gd)
{
const Player* p;
Player *p;
uint excludebits = _legend_excludebits;
int nums;
int mo,yr;
@@ -323,7 +320,7 @@ static void OperatingProfitWndProc(Window *w, WindowEvent *e)
switch(e->event) {
case WE_PAINT: {
GraphDrawer gd;
const Player* p;
Player *p;
int i,j;
int numd;
@@ -333,7 +330,7 @@ static void OperatingProfitWndProc(Window *w, WindowEvent *e)
gd.top = 18;
gd.height = 136;
gd.include_neg = true;
gd.format_str_y_axis = STR_CURRCOMPACT;
gd.format_str_y_axis = STR_CURRCOMPACT32;
gd.color_3 = 0x10;
gd.color_2 = 0xD7;
gd.bg_line_color = 0xE;
@@ -364,7 +361,7 @@ static void OperatingProfitWndProc(Window *w, WindowEvent *e)
}
static const Widget _operating_profit_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 525, 0, 13, STR_7025_OPERATING_PROFIT_GRAPH, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 526, 575, 0, 13, STR_704C_KEY, STR_704D_SHOW_KEY_TO_GRAPHS},
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 575, 14, 173, 0x0, STR_NULL},
@@ -397,7 +394,7 @@ static void IncomeGraphWndProc(Window *w, WindowEvent *e)
switch(e->event) {
case WE_PAINT: {
GraphDrawer gd;
const Player* p;
Player *p;
int i,j;
int numd;
@@ -407,7 +404,7 @@ static void IncomeGraphWndProc(Window *w, WindowEvent *e)
gd.top = 18;
gd.height = 104;
gd.include_neg = false;
gd.format_str_y_axis = STR_CURRCOMPACT;
gd.format_str_y_axis = STR_CURRCOMPACT32;
gd.color_3 = 0x10;
gd.color_2 = 0xD7;
gd.bg_line_color = 0xE;
@@ -439,7 +436,7 @@ static void IncomeGraphWndProc(Window *w, WindowEvent *e)
}
static const Widget _income_graph_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 525, 0, 13, STR_7022_INCOME_GRAPH, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 526, 575, 0, 13, STR_704C_KEY, STR_704D_SHOW_KEY_TO_GRAPHS},
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 575, 14, 141, 0x0, STR_NULL},
@@ -470,7 +467,7 @@ static void DeliveredCargoGraphWndProc(Window *w, WindowEvent *e)
switch(e->event) {
case WE_PAINT: {
GraphDrawer gd;
const Player* p;
Player *p;
int i,j;
int numd;
@@ -512,7 +509,7 @@ static void DeliveredCargoGraphWndProc(Window *w, WindowEvent *e)
}
static const Widget _delivered_cargo_graph_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 525, 0, 13, STR_7050_UNITS_OF_CARGO_DELIVERED, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 526, 575, 0, 13, STR_704C_KEY, STR_704D_SHOW_KEY_TO_GRAPHS},
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 575, 14, 141, 0x0, STR_NULL},
@@ -543,7 +540,7 @@ static void PerformanceHistoryWndProc(Window *w, WindowEvent *e)
switch(e->event) {
case WE_PAINT: {
GraphDrawer gd;
const Player* p;
Player *p;
int i,j;
int numd;
@@ -587,7 +584,7 @@ static void PerformanceHistoryWndProc(Window *w, WindowEvent *e)
}
static const Widget _performance_history_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 475, 0, 13, STR_7051_COMPANY_PERFORMANCE_RATINGS, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 526, 575, 0, 13, STR_704C_KEY, STR_704D_SHOW_KEY_TO_GRAPHS},
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 476, 525, 0, 13, STR_PERFORMANCE_DETAIL_KEY, STR_704D_SHOW_KEY_TO_GRAPHS},
@@ -619,7 +616,7 @@ static void CompanyValueGraphWndProc(Window *w, WindowEvent *e)
switch(e->event) {
case WE_PAINT: {
GraphDrawer gd;
const Player* p;
Player *p;
int i,j;
int numd;
@@ -629,7 +626,7 @@ static void CompanyValueGraphWndProc(Window *w, WindowEvent *e)
gd.top = 18;
gd.height = 200;
gd.include_neg = false;
gd.format_str_y_axis = STR_CURRCOMPACT;
gd.format_str_y_axis = STR_CURRCOMPACT64;
gd.color_3 = 0x10;
gd.color_2 = 0xD7;
gd.bg_line_color = 0xE;
@@ -661,7 +658,7 @@ static void CompanyValueGraphWndProc(Window *w, WindowEvent *e)
}
static const Widget _company_value_graph_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 525, 0, 13, STR_7052_COMPANY_VALUES, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 526, 575, 0, 13, STR_704C_KEY, STR_704D_SHOW_KEY_TO_GRAPHS},
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 575, 14, 237, 0x0, STR_NULL},
@@ -715,7 +712,7 @@ static void CargoPaymentRatesWndProc(Window *w, WindowEvent *e)
gd.top = 24;
gd.height = 104;
gd.include_neg = false;
gd.format_str_y_axis = STR_CURRCOMPACT;
gd.format_str_y_axis = STR_CURRCOMPACT32;
gd.color_3 = 16;
gd.color_2 = 215;
gd.bg_line_color = 14;
@@ -813,60 +810,69 @@ static inline StringID GetPerformanceTitleFromValue(uint value)
return _performance_titles[minu(value, 1000) >> 6];
}
static int CDECL PerfHistComp(const void* elem1, const void* elem2)
{
const Player* p1 = *(const Player* const*)elem1;
const Player* p2 = *(const Player* const*)elem2;
return p2->old_economy[1].performance_history - p1->old_economy[1].performance_history;
static int CDECL _perf_hist_comp(const void *elem1, const void *elem2 ) {
const Player *p1 = *(const Player* const *)elem1;
const Player *p2 = *(const Player* const *)elem2;
int32 v = p2->old_economy[1].performance_history - p1->old_economy[1].performance_history;
return (v!=0) | (v >> (sizeof(int32)*8-1));
}
static void CompanyLeagueWndProc(Window *w, WindowEvent *e)
{
switch (e->event) {
case WE_PAINT: {
const Player* plist[MAX_PLAYERS];
const Player* p;
uint pl_num;
uint i;
switch(e->event) {
case WE_PAINT: {
Player *p;
Player *plist[MAX_PLAYERS];
size_t pl_num, i;
DrawWindowWidgets(w);
DrawWindowWidgets(w);
pl_num = 0;
FOR_ALL_PLAYERS(p) if (p->is_active) plist[pl_num++] = p;
qsort((void*)plist, pl_num, sizeof(*plist), PerfHistComp);
for (i = 0; i != pl_num; i++) {
p = plist[i];
SetDParam(0, i + STR_01AC_1ST);
SetDParam(1, p->name_1);
SetDParam(2, p->name_2);
SetDParam(3, GetPlayerNameString(p->index, 4));
SetDParam(5, GetPerformanceTitleFromValue(p->old_economy[1].performance_history));
DrawString(2, 15 + i * 10, i == 0 ? STR_7054 : STR_7055, 0);
DrawPlayerIcon(p->index, 27, 16 + i * 10);
}
break;
pl_num=0;
FOR_ALL_PLAYERS(p) {
if (p->is_active)
plist[pl_num++] = p;
}
assert(pl_num > 0);
qsort(plist, pl_num, sizeof(Player*), _perf_hist_comp);
i = 0;
do {
SetDParam(0, i + 1 + STR_01AB);
p = plist[i];
SetDParam(1, p->name_1);
SetDParam(2, p->name_2);
SetDParam(3, GetPlayerNameString(p->index, 4));
/* WARNING ugly hack!
GetPlayerNameString sets up (Player #) if the player is human in an extra DPARAM16
It seems that if player is non-human, nothing is set up, so param is 0. GetString doesn't like
that because there is another param after it.
So we'll just shift the rating one back if player is AI and all is fine
*/
SetDParam((IS_HUMAN_PLAYER(p->index) ? 5 : 4), GetPerformanceTitleFromValue(p->old_economy[1].performance_history));
DrawString(2, 15 + i * 10, i == 0 ? STR_7054 : STR_7055, 0);
DrawPlayerIcon(p->index, 27, 16 + i * 10);
} while (++i != pl_num);
break;
}
}
}
static const Widget _company_league_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 387, 0, 13, STR_7053_COMPANY_LEAGUE_TABLE, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_STICKYBOX, RESIZE_NONE, 14, 388, 399, 0, 13, STR_NULL, STR_STICKY_BUTTON},
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 399, 14, 96, 0x0, STR_NULL},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 399, 0, 13, STR_7053_COMPANY_LEAGUE_TABLE, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 399, 14, 96, 0x0, STR_NULL},
{ WIDGETS_END},
};
static const WindowDesc _company_league_desc = {
-1, -1, 400, 97,
WC_COMPANY_LEAGUE,0,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
_company_league_widgets,
CompanyLeagueWndProc
};
@@ -898,7 +904,7 @@ static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e)
// Paint the player icons
for (i=0;i<MAX_PLAYERS;i++) {
if (!GetPlayer(i)->is_active) {
if (!DEREF_PLAYER(i)->is_active) {
// Check if we have the player as an active player
if (!(w->disabled_state & (1 << (i+13)))) {
// Bah, player gone :(
@@ -932,8 +938,8 @@ static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e)
for (i=0;i<NUM_SCORE;i++) {
y += 20;
val = _score_part[owner][i];
needed = _score_info[i].needed;
score = _score_info[i].score;
needed = score_info[i].needed;
score = score_info[i].score;
// SCORE_TOTAL has his own rulez ;)
if (i == SCORE_TOTAL) {
needed = total_score;
@@ -1018,7 +1024,7 @@ static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e)
// Hide the player who are not active
for (i=0;i<MAX_PLAYERS;i++) {
if (!GetPlayer(i)->is_active) {
if (!DEREF_PLAYER(i)->is_active) {
w->disabled_state += 1 << (i+13);
}
}
@@ -1057,7 +1063,7 @@ static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e)
}
static const Widget _performance_rating_detail_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 298, 0, 13, STR_PERFORMANCE_DETAIL, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 298, 14, 27, 0x0, STR_NULL},
@@ -1151,6 +1157,7 @@ static void SignListWndProc(Window *w, WindowEvent *e)
{
switch (e->event) {
case WE_PAINT: {
uint32 i;
int y = 16; // offset from top of widget
if (_sign_sort_dirty)
@@ -1167,11 +1174,12 @@ static void SignListWndProc(Window *w, WindowEvent *e)
return;
}
{ const SignStruct *ss;
uint16 i;
{
SignStruct *ss;
/* Start drawing the signs */
for (i = w->vscroll.pos; i < w->vscroll.cap + w->vscroll.pos && i < w->vscroll.count; i++) {
i = 0;
for (i = w->vscroll.pos; i < (uint)w->vscroll.cap + w->vscroll.pos && i < w->vscroll.count; i++) {
ss = GetSign(_sign_sort[i]);
if (ss->owner != OWNER_NONE)
@@ -1198,7 +1206,7 @@ static void SignListWndProc(Window *w, WindowEvent *e)
return;
ss = GetSign(_sign_sort[id_v]);
ScrollMainWindowToTile(TileVirtXY(ss->x, ss->y));
ScrollMainWindowToTile(TILE_FROM_XY(ss->x, ss->y));
} break;
}
} break;

63
gui.h
View File

@@ -1,22 +1,20 @@
/* $Id$ */
#ifndef GUI_H
#define GUI_H
#include "station.h"
#include "window.h"
/* main_gui.c */
void SetupColorsAndInitialWindow(void);
void CcPlaySound10(bool success, TileIndex tile, uint32 p1, uint32 p2);
void CcBuildCanal(bool success, TileIndex tile, uint32 p1, uint32 p2);
void CcTerraform(bool success, TileIndex tile, uint32 p1, uint32 p2);
void CcPlaySound10(bool success, uint tile, uint32 p1, uint32 p2);
void CcBuildCanal(bool success, uint tile, uint32 p1, uint32 p2);
void CcTerraform(bool success, uint tile, uint32 p1, uint32 p2);
/* settings_gui.c */
void ShowGameOptions(void);
void ShowGameDifficulty(void);
void ShowPatchesSelection(void);
void ShowNewgrf(void);
void ShowCustCurrency(void);
/* graph_gui.c */
void ShowOperatingProfitGraph(void);
@@ -34,36 +32,39 @@ void ShowMessageOptions(void);
void ShowMessageHistory(void);
/* traintoolb_gui.c */
void ShowBuildRailToolbar(RailType railtype, int button);
void PlaceProc_BuyLand(TileIndex tile);
void ShowBuildRailToolbar(int index, int button);
void PlaceProc_BuyLand(uint tile);
/* train_gui.c */
void ShowPlayerTrains(PlayerID player, StationID station);
void ShowTrainViewWindow(const Vehicle *v);
void ShowOrdersWindow(const Vehicle* v);
void ShowPlayerTrains(int player, int station);
void ShowTrainViewWindow(Vehicle *v);
void ShowTrainDetailsWindow(Vehicle *v);
void ShowOrdersWindow(Vehicle *v);
void ShowRoadVehViewWindow(const Vehicle* v);
void ShowRoadVehViewWindow(Vehicle *v);
/* road_gui.c */
void ShowBuildRoadToolbar(void);
void ShowBuildRoadScenToolbar(void);
void ShowPlayerRoadVehicles(PlayerID player, StationID station);
void ShowPlayerRoadVehicles(int player, int station);
/* dock_gui.c */
void ShowBuildDocksToolbar(void);
void ShowPlayerShips(PlayerID player, StationID station);
void ShowPlayerShips(int player, int station);
void ShowShipViewWindow(const Vehicle* v);
void ShowShipViewWindow(Vehicle *v);
/* aircraft_gui.c */
void ShowBuildAirToolbar(void);
void ShowPlayerAircraft(PlayerID player, StationID station);
void ShowPlayerAircraft(int player, int station);
/* terraform_gui.c */
void ShowTerraformToolbar(void);
void PlaceProc_DemolishArea(TileIndex tile);
void PlaceProc_LevelLand(TileIndex tile);
void PlaceProc_DemolishArea(uint tile);
void PlaceProc_LowerLand(uint tile);
void PlaceProc_RaiseLand(uint tile);
void PlaceProc_LevelLand(uint tile);
bool GUIPlaceProcDragXY(const WindowEvent *we);
enum { // max 32 - 4 = 28 types
@@ -71,8 +72,7 @@ enum { // max 32 - 4 = 28 types
GUI_PlaceProc_LevelArea = 1 << 4,
GUI_PlaceProc_DesertArea = 2 << 4,
GUI_PlaceProc_WaterArea = 3 << 4,
GUI_PlaceProc_ConvertRailArea = 4 << 4,
GUI_PlaceProc_RockyArea = 5 << 4,
GUI_PlaceProc_ConvertRailArea = 4 << 4
};
/* misc_gui.c */
@@ -83,16 +83,16 @@ void ShowBuildTreesScenToolbar(void);
void ShowTownDirectory(void);
void ShowIndustryDirectory(void);
void ShowSubsidiesList(void);
void ShowPlayerStations(PlayerID player);
void ShowPlayerFinances(PlayerID player);
void ShowPlayerCompany(PlayerID player);
void ShowPlayerStations(int player);
void ShowPlayerFinances(int player);
void ShowPlayerCompany(int player);
void ShowSignList(void);
void ShowEstimatedCostOrIncome(int32 cost, int x, int y);
void ShowErrorMessage(StringID msg_1, StringID msg_2, int x, int y);
void DrawStationCoverageAreaText(int sx, int sy, uint mask,int rad);
void CheckRedrawStationCoverage(const Window* w);
void CheckRedrawStationCoverage(Window *w);
void ShowSmallMap(void);
void ShowExtraViewPortWindow(void);
@@ -103,26 +103,29 @@ void SetHScrollCount(Window *w, int num);
void ShowCheatWindow(void);
void AskForNewGameToStart(void);
void DrawEditBox(Window *w, querystr_d *string, int wid);
void HandleEditBox(Window *w, querystr_d *string, int wid);
int HandleEditBoxKey(Window *w, querystr_d *string, int wid, WindowEvent *we);
void DrawEditBox(Window *w, int wid);
void HandleEditBox(Window *w, int wid);
int HandleEditBoxKey(Window *w, int wid, WindowEvent *we);
bool HandleCaret(Textbuf *tb);
void DeleteTextBufferAll(Textbuf *tb);
bool DeleteTextBufferChar(Textbuf *tb, int delmode);
bool InsertTextBufferChar(Textbuf *tb, byte key);
bool InsertTextBufferClipboard(Textbuf *tb);
bool MoveTextBufferPos(Textbuf *tb, int navmode);
void UpdateTextBufferSize(Textbuf *tb);
/* IS_INT_INSIDE = filter for ascii-function codes like BELL and so on [we need an special filter here later] */
static inline bool IsValidAsciiChar(byte key) {return IS_INT_INSIDE(key, ' ', 256);}
void BuildFileList(void);
void SetFiosType(const byte fiostype);
/* FIOS_TYPE_FILE, FIOS_TYPE_OLDFILE etc. different colours */
extern const byte _fios_colors[];
static const byte _fios_colors[] = {13, 9, 9, 6, 5, 6, 5};
/* network gui */
void ShowNetworkGameWindow(void);
void ShowChatWindow(StringID str, StringID caption, int maxlen, int maxwidth, byte window_class, uint16 window_number);
/* bridge_gui.c */
void ShowBuildBridgeWindow(uint start, uint end, byte type);
@@ -139,8 +142,10 @@ void ShowQueryString(StringID str, StringID caption, uint maxlen, uint maxwidth,
void ShowMusicWindow(void);
/* main_gui.c */
VARDEF byte _construct_mode;
VARDEF byte _station_show_coverage;
VARDEF PlaceProc *_place_proc;
VARDEF bool _no_button_sound;
/* vehicle_gui.c */
void InitializeGUI(void);

62
hal.h
View File

@@ -1,5 +1,3 @@
/* $Id$ */
#ifndef HAL_H
#define HAL_H
@@ -12,11 +10,16 @@ typedef struct {
const char *(*start)(const char * const *parm);
void (*stop)(void);
void (*make_dirty)(int left, int top, int width, int height);
void (*main_loop)(void);
int (*main_loop)(void);
bool (*change_resolution)(int w, int h);
void (*toggle_fullscreen)(bool fullscreen);
} HalVideoDriver;
enum {
ML_QUIT = 0,
ML_SWITCHDRIVER = 1,
};
typedef struct {
const char *(*start)(const char * const *parm);
void (*stop)(void);
@@ -32,10 +35,49 @@ typedef struct {
void (*set_volume)(byte vol);
} HalMusicDriver;
typedef struct {
const char *name;
const char *longname;
const void *drv;
uint32 flags;
} DriverDesc;
enum {
HALERR_OK = 0,
HALERR_ERROR = 1,
};
extern const HalMusicDriver _null_music_driver;
extern const HalVideoDriver _null_video_driver;
extern const HalSoundDriver _null_sound_driver;
VARDEF HalMusicDriver *_music_driver;
VARDEF HalSoundDriver *_sound_driver;
VARDEF HalVideoDriver *_video_driver;
extern const DriverDesc _video_driver_descs[];
extern const DriverDesc _sound_driver_descs[];
extern const DriverDesc _music_driver_descs[];
#if defined(WITH_SDL)
extern const HalSoundDriver _sdl_sound_driver;
extern const HalVideoDriver _sdl_video_driver;
#endif
#if defined(UNIX)
extern const HalMusicDriver _extmidi_music_driver;
#endif
#if defined(__BEOS__)
extern const HalMusicDriver _bemidi_music_driver;
#endif
#if defined(__OS2__)
extern const HalMusicDriver _os2_music_driver;
#endif
extern const HalVideoDriver _dedicated_video_driver;
enum DriverType {
VIDEO_DRIVER = 0,
SOUND_DRIVER = 1,
@@ -43,10 +85,19 @@ enum DriverType {
};
extern void GameLoop(void);
extern bool _dbg_screen_rect;
void LoadDriver(int driver, const char *name);
const char *GetDriverParam(const char * const *parm, const char *name);
bool GetDriverParamBool(const char * const *parm, const char *name);
int GetDriverParamInt(const char * const *parm, const char *name, int def);
// Deals with finding savegames
typedef struct {
uint16 id;
byte type;
uint64 mtime;
char title[64];
@@ -61,7 +112,6 @@ enum {
FIOS_TYPE_OLDFILE = 4,
FIOS_TYPE_SCENARIO = 5,
FIOS_TYPE_OLD_SCENARIO = 6,
FIOS_TYPE_DIRECT = 7,
};
@@ -86,9 +136,9 @@ char *FiosBrowseTo(const FiosItem *item);
// Return path, free space and stringID
StringID FiosGetDescText(const char **path, uint32 *tot);
// Delete a name
bool FiosDelete(const char *name);
void FiosDelete(const char *name);
// Make a filename from a name
void FiosMakeSavegameName(char *buf, const char *name, size_t size);
void FiosMakeSavegameName(char *buf, const char *name);
int CDECL compare_FiosItems(const void *a, const void *b);

View File

@@ -1,5 +1,3 @@
/* $Id$ */
#ifndef INDUSTRY_H
#define INDUSTRY_H
@@ -9,7 +7,7 @@ struct Industry {
TileIndex xy;
byte width; /* swapped order of w/h with town */
byte height;
const Town* town;
Town *town;
byte produced_cargo[2];
uint16 cargo_waiting[2];
byte production_rate[2];
@@ -107,4 +105,4 @@ enum {
IT_SUGAR_MINE = 36,
};
#endif /* INDUSTRY_H */
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,12 +1,8 @@
/* $Id$ */
#include "stdafx.h"
#include "openttd.h"
#include "ttd.h"
#include "debug.h"
#include "functions.h"
#include "strings.h"
#include "table/strings.h"
#include "table/sprites.h"
#include "map.h"
#include "gui.h"
#include "window.h"
@@ -15,7 +11,6 @@
#include "viewport.h"
#include "industry.h"
#include "town.h"
#include "variables.h"
/* Present in table/build_industry.h" */
extern const byte _build_industry_types[4][12];
@@ -40,7 +35,7 @@ static void BuildIndustryWndProc(Window *w, WindowEvent *e)
case WE_CLICK: {
int wid = e->click.widget;
if (wid >= 3) {
if (HandlePlacePushButton(w, wid, SPR_CURSOR_INDUSTRY, 1, NULL))
if (HandlePlacePushButton(w, wid, 0xFF1, 1, NULL))
WP(w,def_d).data_1 = wid - 3;
}
} break;
@@ -61,11 +56,11 @@ static const Widget _build_industry_land0_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_PANEL, RESIZE_NONE, 7, 0, 169, 14, 115, 0x0, STR_NULL},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 16, 27, STR_0241_POWER_STATION, STR_0263_CONSTRUCT_POWER_STATION},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 29, 40, STR_0242_SAWMILL, STR_0264_CONSTRUCT_SAWMILL},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 42, 53, STR_0244_OIL_REFINERY, STR_0266_CONSTRUCT_OIL_REFINERY},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 55, 66, STR_0246_FACTORY, STR_0268_CONSTRUCT_FACTORY},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 68, 79, STR_0247_STEEL_MILL, STR_0269_CONSTRUCT_STEEL_MILL},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 16, 27, STR_0241_POWER_STATION, STR_0263_CONSTRUCT_POWER_STATION},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 29, 40, STR_0242_SAWMILL, STR_0264_CONSTRUCT_SAWMILL},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 42, 53, STR_0244_OIL_REFINERY, STR_0266_CONSTRUCT_OIL_REFINERY},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 55, 66, STR_0246_FACTORY, STR_0268_CONSTRUCT_FACTORY},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 68, 79, STR_0247_STEEL_MILL, STR_0269_CONSTRUCT_STEEL_MILL},
{ WIDGETS_END},
};
@@ -73,11 +68,11 @@ static const Widget _build_industry_land1_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_PANEL, RESIZE_NONE, 7, 0, 169, 14, 115, 0x0, STR_NULL},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 16, 27, STR_0241_POWER_STATION, STR_0263_CONSTRUCT_POWER_STATION},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 29, 40, STR_024C_PAPER_MILL, STR_026E_CONSTRUCT_PAPER_MILL},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 42, 53, STR_0244_OIL_REFINERY, STR_0266_CONSTRUCT_OIL_REFINERY},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 55, 66, STR_024D_FOOD_PROCESSING_PLANT,STR_026F_CONSTRUCT_FOOD_PROCESSING},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 68, 79, STR_024E_PRINTING_WORKS, STR_0270_CONSTRUCT_PRINTING_WORKS},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 16, 27, STR_0241_POWER_STATION, STR_0263_CONSTRUCT_POWER_STATION},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 29, 40, STR_024C_PAPER_MILL, STR_026E_CONSTRUCT_PAPER_MILL},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 42, 53, STR_0244_OIL_REFINERY, STR_0266_CONSTRUCT_OIL_REFINERY},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 55, 66, STR_024D_FOOD_PROCESSING_PLANT,STR_026F_CONSTRUCT_FOOD_PROCESSING},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 68, 79, STR_024E_PRINTING_WORKS, STR_0270_CONSTRUCT_PRINTING_WORKS},
{ WIDGETS_END},
};
@@ -85,11 +80,11 @@ static const Widget _build_industry_land2_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_PANEL, RESIZE_NONE, 7, 0, 169, 14, 115, 0x0, STR_NULL},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 16, 27, STR_0250_LUMBER_MILL, STR_0273_CONSTRUCT_LUMBER_MILL_TO},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 29, 40, STR_024D_FOOD_PROCESSING_PLANT,STR_026F_CONSTRUCT_FOOD_PROCESSING},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 42, 53, STR_0244_OIL_REFINERY, STR_0266_CONSTRUCT_OIL_REFINERY},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 55, 66, STR_0246_FACTORY, STR_0268_CONSTRUCT_FACTORY},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 68, 79, STR_0254_WATER_TOWER, STR_0277_CONSTRUCT_WATER_TOWER_CAN},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 16, 27, STR_0250_LUMBER_MILL, STR_0273_CONSTRUCT_LUMBER_MILL_TO},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 29, 40, STR_024D_FOOD_PROCESSING_PLANT,STR_026F_CONSTRUCT_FOOD_PROCESSING},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 42, 53, STR_0244_OIL_REFINERY, STR_0266_CONSTRUCT_OIL_REFINERY},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 55, 66, STR_0246_FACTORY, STR_0268_CONSTRUCT_FACTORY},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 68, 79, STR_0254_WATER_TOWER, STR_0277_CONSTRUCT_WATER_TOWER_CAN},
{ WIDGETS_END},
};
@@ -97,10 +92,10 @@ static const Widget _build_industry_land3_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_PANEL, RESIZE_NONE, 7, 0, 169, 14, 115, 0x0, STR_NULL},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 16, 27, STR_0258_CANDY_FACTORY, STR_027B_CONSTRUCT_CANDY_FACTORY},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 29, 40, STR_025B_TOY_SHOP, STR_027E_CONSTRUCT_TOY_SHOP},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 42, 53, STR_025C_TOY_FACTORY, STR_027F_CONSTRUCT_TOY_FACTORY},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 55, 66, STR_025E_FIZZY_DRINK_FACTORY, STR_0281_CONSTRUCT_FIZZY_DRINK_FACTORY},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 16, 27, STR_0258_CANDY_FACTORY, STR_027B_CONSTRUCT_CANDY_FACTORY},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 29, 40, STR_025B_TOY_SHOP, STR_027E_CONSTRUCT_TOY_SHOP},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 42, 53, STR_025C_TOY_FACTORY, STR_027F_CONSTRUCT_TOY_FACTORY},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 55, 66, STR_025E_FIZZY_DRINK_FACTORY, STR_0281_CONSTRUCT_FIZZY_DRINK_FACTORY},
{ WIDGETS_END},
};
@@ -109,18 +104,18 @@ static const Widget _build_industry_land0_widgets_extra[] = {
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY,STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_PANEL, RESIZE_NONE, 7, 0, 169, 14, 187, 0x0, STR_NULL},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 16, 27, STR_0241_POWER_STATION,STR_0263_CONSTRUCT_POWER_STATION},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 29, 40, STR_0242_SAWMILL, STR_0264_CONSTRUCT_SAWMILL},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 42, 53, STR_0244_OIL_REFINERY, STR_0266_CONSTRUCT_OIL_REFINERY},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 55, 66, STR_0246_FACTORY, STR_0268_CONSTRUCT_FACTORY},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 68, 79, STR_0247_STEEL_MILL, STR_0269_CONSTRUCT_STEEL_MILL},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 16, 27, STR_0241_POWER_STATION,STR_0263_CONSTRUCT_POWER_STATION},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 29, 40, STR_0242_SAWMILL, STR_0264_CONSTRUCT_SAWMILL},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 42, 53, STR_0244_OIL_REFINERY, STR_0266_CONSTRUCT_OIL_REFINERY},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 55, 66, STR_0246_FACTORY, STR_0268_CONSTRUCT_FACTORY},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 68, 79, STR_0247_STEEL_MILL, STR_0269_CONSTRUCT_STEEL_MILL},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 84, 95, STR_0240_COAL_MINE, STR_CONSTRUCT_COAL_MINE_TIP},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 97, 108, STR_0243_FOREST, STR_CONSTRUCT_FOREST_TIP},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 110, 121, STR_0245_OIL_RIG, STR_CONSTRUCT_OIL_RIG_TIP},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 123, 134, STR_0248_FARM, STR_CONSTRUCT_FARM_TIP},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 136, 147, STR_024A_OIL_WELLS, STR_CONSTRUCT_OIL_WELLS_TIP},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 149, 160, STR_0249_IRON_ORE_MINE, STR_CONSTRUCT_IRON_ORE_MINE_TIP},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 84, 95, STR_0240_COAL_MINE, STR_CONSTRUCT_COAL_MINE_TIP},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 97, 108, STR_0243_FOREST, STR_CONSTRUCT_FOREST_TIP},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 110, 121, STR_0245_OIL_RIG, STR_CONSTRUCT_OIL_RIG_TIP},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 123, 134, STR_0248_FARM, STR_CONSTRUCT_FARM_TIP},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 136, 147, STR_024A_OIL_WELLS, STR_CONSTRUCT_OIL_WELLS_TIP},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 149, 160, STR_0249_IRON_ORE_MINE, STR_CONSTRUCT_IRON_ORE_MINE_TIP},
{ WIDGETS_END},
};
@@ -130,17 +125,17 @@ static const Widget _build_industry_land1_widgets_extra[] = {
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_PANEL, RESIZE_NONE, 7, 0, 169, 14, 174, 0x0, STR_NULL},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 16, 27, STR_0241_POWER_STATION, STR_0263_CONSTRUCT_POWER_STATION},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 29, 40, STR_024C_PAPER_MILL, STR_026E_CONSTRUCT_PAPER_MILL},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 42, 53, STR_0244_OIL_REFINERY, STR_0266_CONSTRUCT_OIL_REFINERY},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 55, 66, STR_024D_FOOD_PROCESSING_PLANT,STR_026F_CONSTRUCT_FOOD_PROCESSING},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 68, 79, STR_024E_PRINTING_WORKS, STR_0270_CONSTRUCT_PRINTING_WORKS},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 16, 27, STR_0241_POWER_STATION, STR_0263_CONSTRUCT_POWER_STATION},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 29, 40, STR_024C_PAPER_MILL, STR_026E_CONSTRUCT_PAPER_MILL},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 42, 53, STR_0244_OIL_REFINERY, STR_0266_CONSTRUCT_OIL_REFINERY},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 55, 66, STR_024D_FOOD_PROCESSING_PLANT,STR_026F_CONSTRUCT_FOOD_PROCESSING},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 68, 79, STR_024E_PRINTING_WORKS, STR_0270_CONSTRUCT_PRINTING_WORKS},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 81+3, 92+3, STR_0240_COAL_MINE, STR_CONSTRUCT_COAL_MINE_TIP},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 94+3, 105+3, STR_0243_FOREST, STR_CONSTRUCT_FOREST_TIP},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 107+3, 118+3, STR_0248_FARM, STR_CONSTRUCT_FARM_TIP},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 120+3, 131+3, STR_024A_OIL_WELLS, STR_CONSTRUCT_OIL_WELLS_TIP},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 133+3, 144+3, STR_024F_GOLD_MINE, STR_CONSTRUCT_GOLD_MINE_TIP},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 81+3, 92+3, STR_0240_COAL_MINE, STR_CONSTRUCT_COAL_MINE_TIP},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 94+3, 105+3, STR_0243_FOREST, STR_CONSTRUCT_FOREST_TIP},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 107+3, 118+3, STR_0248_FARM, STR_CONSTRUCT_FARM_TIP},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 120+3, 131+3, STR_024A_OIL_WELLS, STR_CONSTRUCT_OIL_WELLS_TIP},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 133+3, 144+3, STR_024F_GOLD_MINE, STR_CONSTRUCT_GOLD_MINE_TIP},
{ WIDGETS_END},
};
@@ -149,19 +144,19 @@ static const Widget _build_industry_land2_widgets_extra[] = {
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_PANEL, RESIZE_NONE, 7, 0, 169, 14, 200, 0x0, STR_NULL},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 16, 27, STR_0250_LUMBER_MILL, STR_0273_CONSTRUCT_LUMBER_MILL_TO},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 29, 40, STR_024D_FOOD_PROCESSING_PLANT,STR_026F_CONSTRUCT_FOOD_PROCESSING},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 42, 53, STR_0244_OIL_REFINERY, STR_0266_CONSTRUCT_OIL_REFINERY},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 55, 66, STR_0246_FACTORY, STR_0268_CONSTRUCT_FACTORY},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 68, 79, STR_0254_WATER_TOWER, STR_0277_CONSTRUCT_WATER_TOWER_CAN},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 16, 27, STR_0250_LUMBER_MILL, STR_0273_CONSTRUCT_LUMBER_MILL_TO},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 29, 40, STR_024D_FOOD_PROCESSING_PLANT,STR_026F_CONSTRUCT_FOOD_PROCESSING},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 42, 53, STR_0244_OIL_REFINERY, STR_0266_CONSTRUCT_OIL_REFINERY},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 55, 66, STR_0246_FACTORY, STR_0268_CONSTRUCT_FACTORY},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 68, 79, STR_0254_WATER_TOWER, STR_0277_CONSTRUCT_WATER_TOWER_CAN},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 81+3, 92+3, STR_024A_OIL_WELLS,STR_CONSTRUCT_OIL_WELLS_TIP},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 94+3, 105+3, STR_0255_DIAMOND_MINE, STR_CONSTRUCT_DIAMOND_MINE_TIP},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 107+3, 118+3, STR_0256_COPPER_ORE_MINE, STR_CONSTRUCT_COPPER_ORE_MINE_TIP},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 120+3, 131+3, STR_0248_FARM, STR_CONSTRUCT_FARM_TIP},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 133+3, 144+3, STR_0251_FRUIT_PLANTATION, STR_CONSTRUCT_FRUIT_PLANTATION_TIP},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 146+3, 157+3, STR_0252_RUBBER_PLANTATION,STR_CONSTRUCT_RUBBER_PLANTATION_TIP},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 159+3, 170+3, STR_0253_WATER_SUPPLY, STR_CONSTRUCT_WATER_SUPPLY_TIP},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 81+3, 92+3, STR_024A_OIL_WELLS,STR_CONSTRUCT_OIL_WELLS_TIP},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 94+3, 105+3, STR_0255_DIAMOND_MINE, STR_CONSTRUCT_DIAMOND_MINE_TIP},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 107+3, 118+3, STR_0256_COPPER_ORE_MINE, STR_CONSTRUCT_COPPER_ORE_MINE_TIP},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 120+3, 131+3, STR_0248_FARM, STR_CONSTRUCT_FARM_TIP},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 133+3, 144+3, STR_0251_FRUIT_PLANTATION, STR_CONSTRUCT_FRUIT_PLANTATION_TIP},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 146+3, 157+3, STR_0252_RUBBER_PLANTATION,STR_CONSTRUCT_RUBBER_PLANTATION_TIP},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 159+3, 170+3, STR_0253_WATER_SUPPLY, STR_CONSTRUCT_WATER_SUPPLY_TIP},
{ WIDGETS_END},
};
@@ -170,18 +165,18 @@ static const Widget _build_industry_land3_widgets_extra[] = {
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_PANEL, RESIZE_NONE, 7, 0, 169, 14, 187, 0x0, STR_NULL},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 16, 27, STR_0258_CANDY_FACTORY, STR_027B_CONSTRUCT_CANDY_FACTORY},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 29, 40, STR_025B_TOY_SHOP, STR_027E_CONSTRUCT_TOY_SHOP},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 42, 53, STR_025C_TOY_FACTORY, STR_027F_CONSTRUCT_TOY_FACTORY},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 55, 66, STR_025E_FIZZY_DRINK_FACTORY, STR_0281_CONSTRUCT_FIZZY_DRINK_FACTORY},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 16, 27, STR_0258_CANDY_FACTORY, STR_027B_CONSTRUCT_CANDY_FACTORY},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 29, 40, STR_025B_TOY_SHOP, STR_027E_CONSTRUCT_TOY_SHOP},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 42, 53, STR_025C_TOY_FACTORY, STR_027F_CONSTRUCT_TOY_FACTORY},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 55, 66, STR_025E_FIZZY_DRINK_FACTORY, STR_0281_CONSTRUCT_FIZZY_DRINK_FACTORY},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 68+3, 79+3, STR_0257_COTTON_CANDY_FOREST,STR_CONSTRUCT_COTTON_CANDY_TIP},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 81+3, 92+3, STR_0259_BATTERY_FARM, STR_CONSTRUCT_BATTERY_FARM_TIP},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 94+3, 105+3, STR_025A_COLA_WELLS, STR_CONSTRUCT_COLA_WELLS_TIP},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 107+3, 118+3, STR_025D_PLASTIC_FOUNTAINS,STR_CONSTRUCT_PLASTIC_FOUNTAINS_TIP},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 120+3, 131+3, STR_025F_BUBBLE_GENERATOR, STR_CONSTRUCT_BUBBLE_GENERATOR_TIP},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 133+3, 144+3, STR_0260_TOFFEE_QUARRY, STR_CONSTRUCT_TOFFEE_QUARRY_TIP},
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 167, 146+3, 157+3, STR_0261_SUGAR_MINE, STR_CONSTRUCT_SUGAR_MINE_TIP},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 68+3, 79+3, STR_0257_COTTON_CANDY_FOREST,STR_CONSTRUCT_COTTON_CANDY_TIP},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 81+3, 92+3, STR_0259_BATTERY_FARM, STR_CONSTRUCT_BATTERY_FARM_TIP},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 94+3, 105+3, STR_025A_COLA_WELLS, STR_CONSTRUCT_COLA_WELLS_TIP},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 107+3, 118+3, STR_025D_PLASTIC_FOUNTAINS,STR_CONSTRUCT_PLASTIC_FOUNTAINS_TIP},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 120+3, 131+3, STR_025F_BUBBLE_GENERATOR, STR_CONSTRUCT_BUBBLE_GENERATOR_TIP},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 133+3, 144+3, STR_0260_TOFFEE_QUARRY, STR_CONSTRUCT_TOFFEE_QUARRY_TIP},
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 2, 167, 146+3, 157+3, STR_0261_SUGAR_MINE, STR_CONSTRUCT_SUGAR_MINE_TIP},
{ WIDGETS_END},
};
@@ -267,7 +262,6 @@ static const WindowDesc * const _industry_window_desc[2][4] = {
void ShowBuildIndustryWindow(void)
{
if (_current_player == OWNER_SPECTATOR) return;
AllocateWindowDescFront(_industry_window_desc[_patches.build_rawmaterial_ind][_opt_ptr->landscape],0);
}
@@ -282,9 +276,12 @@ static void IndustryViewWndProc(Window *w, WindowEvent *e)
case WE_PAINT: {
const Industry *i;
StringID str;
// in editor, use bulldoze to destroy industry
// Destroy Industry button costing money removed per request of dominik
//w->disabled_state = (_patches.extra_dynamite && !_networking && _game_mode != GM_EDITOR) ? 0 : (1 << 6);
i = GetIndustry(w->window_number);
SetDParam(0, w->window_number);
SetDParam(0, i->town->index);
SetDParam(1, i->type + STR_4802_COAL_MINE);
DrawWindowWidgets(w);
if (i->accepts_cargo[0] != CT_INVALID) {
@@ -304,9 +301,8 @@ static void IndustryViewWndProc(Window *w, WindowEvent *e)
if (i->produced_cargo[0] != CT_INVALID) {
DrawString(2, 117, STR_482A_PRODUCTION_LAST_MONTH, 0);
SetDParam(0, _cargoc.names_long[i->produced_cargo[0]]);
SetDParam(1, i->total_production[0]);
SetDParam(0, _cargoc.names_long_s[i->produced_cargo[0]] + ((i->total_production[0]!=1)<<5));
SetDParam(2, i->pct_transported[0] * 100 >> 8);
DrawString(4 + (NEED_ALTERB ? 30 : 0), 127, STR_482B_TRANSPORTED, 0);
// Let's put out those buttons..
@@ -314,8 +310,8 @@ static void IndustryViewWndProc(Window *w, WindowEvent *e)
DrawArrowButtons(5, 127, (WP(w,vp2_d).data_2 == 1 ? WP(w,vp2_d).data_3 : 0));
if (i->produced_cargo[1] != CT_INVALID) {
SetDParam(0, _cargoc.names_long[i->produced_cargo[1]]);
SetDParam(1, i->total_production[1]);
SetDParam(0, _cargoc.names_long_s[i->produced_cargo[1]] + ((i->total_production[1]!=1)<<5));
SetDParam(2, i->pct_transported[1] * 100 >> 8);
DrawString(4 + (NEED_ALTERB ? 30 : 0), 137, STR_482B_TRANSPORTED, 0);
// Let's put out those buttons..
@@ -379,7 +375,7 @@ static void IndustryViewWndProc(Window *w, WindowEvent *e)
break;
case 6:
i = GetIndustry(w->window_number);
ScrollMainWindowToTile(i->xy + TileDiffXY(1, 1));
ScrollMainWindowToTile(i->xy + TILE_XY(1,1));
break;
}
}
@@ -420,7 +416,7 @@ static void UpdateIndustryProduction(Industry *i)
}
static const Widget _industry_view_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 9, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_TEXTBTN, RESIZE_NONE, 9, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, RESIZE_NONE, 9, 11, 247, 0, 13, STR_4801, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_STICKYBOX, RESIZE_NONE, 9, 248, 259, 0, 13, 0x0, STR_STICKY_BUTTON},
{ WWT_IMGBTN, RESIZE_NONE, 9, 0, 259, 14, 105, 0x0, STR_NULL},
@@ -428,6 +424,8 @@ static const Widget _industry_view_widgets[] = {
{ WWT_IMGBTN, RESIZE_NONE, 9, 0, 259, 106, 147, 0x0, STR_NULL},
{ WWT_PUSHTXTBTN, RESIZE_NONE, 9, 0, 129, 148, 159, STR_00E4_LOCATION, STR_482C_CENTER_THE_MAIN_VIEW_ON},
{ WWT_IMGBTN, RESIZE_NONE, 9, 130, 259, 148, 159, 0x0, STR_NULL},
// Destroy Industry button costing money removed per request of dominik
//{ WWT_PUSHTXTBTN, RESIZE_NONE, 9, 130, 259, 148, 159, STR_INDUSTRYDIR_DESTROY, STR_482C_DESTROY_INDUSTRY},
{ WIDGETS_END},
};
@@ -451,12 +449,12 @@ void ShowIndustryViewWindow(int industry)
WP(w,vp2_d).data_2 = 0;
WP(w,vp2_d).data_3 = 0;
i = GetIndustry(w->window_number);
AssignWindowViewport(w, 3, 17, 0xFE, 0x56, i->xy + TileDiffXY(1, 1), 1);
AssignWindowViewport(w, 3, 17, 0xFE, 0x56, i->xy + TILE_XY(1,1), 1);
}
}
static const Widget _industry_directory_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_TEXTBTN, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, RESIZE_NONE, 13, 11, 495, 0, 13, STR_INDUSTRYDIR_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_STICKYBOX, RESIZE_NONE, 13, 496, 507, 0, 13, 0x0, STR_STICKY_BUTTON},
{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 0, 100, 14, 25, STR_SORT_BY_NAME, STR_SORT_ORDER_TIP},
@@ -493,28 +491,28 @@ static int CDECL GeneralIndustrySorter(const void *a, const void *b)
// FIXME - Production & Transported sort need to be inversed...but, WTF it does not wanna!
// FIXME - And no simple --> "if (!(_industry_sort_order & 1)) r = -r;" hack at the bottom!!
case 2: { /* Sort by Production */
if (i->produced_cargo[0] != CT_INVALID && j->produced_cargo[0] != CT_INVALID) { // both industries produce cargo?
if (i->produced_cargo[1] == CT_INVALID) // producing one or two things?
if (i->produced_cargo[0] != 0xFF && j->produced_cargo[0] != 0xFF) { // both industries produce cargo?
if (i->produced_cargo[1] == 0xFF) // producing one or two things?
r = j->total_production[0] - i->total_production[0];
else
r = (j->total_production[0] + j->total_production[1]) / 2 - (i->total_production[0] + i->total_production[1]) / 2;
} else if (i->produced_cargo[0] == CT_INVALID && j->produced_cargo[0] == CT_INVALID) // none of them producing anything, let them go to the name-sorting
} else if (i->produced_cargo[0] == 0xFF && j->produced_cargo[0] == 0xFF) // none of them producing anything, let them go to the name-sorting
r = 0;
else if (i->produced_cargo[0] == CT_INVALID) // end up the non-producer industry first/last in list
else if (i->produced_cargo[0] == 0xFF) // end up the non-producer industry first/last in list
r = 1;
else
r = -1;
break;
}
case 3: /* Sort by Transported amount */
if (i->produced_cargo[0] != CT_INVALID && j->produced_cargo[0] != CT_INVALID) { // both industries produce cargo?
if (i->produced_cargo[1] == CT_INVALID) // producing one or two things?
if (i->produced_cargo[0] != 0xFF && j->produced_cargo[0] != 0xFF) { // both industries produce cargo?
if (i->produced_cargo[1] == 0xFF) // producing one or two things?
r = (j->pct_transported[0] * 100 >> 8) - (i->pct_transported[0] * 100 >> 8);
else
r = ((j->pct_transported[0] * 100 >> 8) + (j->pct_transported[1] * 100 >> 8)) / 2 - ((i->pct_transported[0] * 100 >> 8) + (i->pct_transported[1] * 100 >> 8)) / 2;
} else if (i->produced_cargo[0] == CT_INVALID && j->produced_cargo[0] == CT_INVALID) // none of them producing anything, let them go to the name-sorting
} else if (i->produced_cargo[0] == 0xFF && j->produced_cargo[0] == 0xFF) // none of them producing anything, let them go to the name-sorting
r = 0;
else if (i->produced_cargo[0] == CT_INVALID) // end up the non-producer industry first/last in list
else if (i->produced_cargo[0] == 0xFF) // end up the non-producer industry first/last in list
r = 1;
else
r = -1;
@@ -523,13 +521,13 @@ static int CDECL GeneralIndustrySorter(const void *a, const void *b)
// default to string sorting if they are otherwise equal
if (r == 0) {
SetDParam(0, i->town->index);
GetString(buf1, STR_TOWN);
SetDParam(0, i->town->townnameparts);
GetString(buf1, i->town->townnametype);
if ( (val=*(const uint16*)b) != _last_industry_idx) {
_last_industry_idx = val;
SetDParam(0, j->town->index);
GetString(_bufcache, STR_TOWN);
SetDParam(0, j->town->townnameparts);
GetString(_bufcache, j->town->townnametype);
}
r = strcmp(buf1, _bufcache);
}
@@ -578,26 +576,27 @@ static void IndustryDirectoryWndProc(Window *w, WindowEvent *e)
SetVScrollCount(w, _num_industry_sort);
DrawWindowWidgets(w);
DoDrawString(_industry_sort_order & 1 ? DOWNARROW : UPARROW, _indicator_positions[_industry_sort_order>>1], 15, 0x10);
DoDrawString(_industry_sort_order & 1 ? "\xAA" : "\xA0", _indicator_positions[_industry_sort_order>>1], 15, 0x10);
p = w->vscroll.pos;
n = 0;
while (p < _num_industry_sort) {
i = GetIndustry(_industry_sort[p]);
SetDParam(0, i->index);
if (i->produced_cargo[0] != CT_INVALID) {
SetDParam(1, _cargoc.names_long[i->produced_cargo[0]]);
SetDParam(2, i->total_production[0]);
SetDParam(0, i->town->index);
SetDParam(1, i->type + STR_4802_COAL_MINE);
if (i->produced_cargo[0] != 0xFF) {
SetDParam(3, i->total_production[0]);
SetDParam(2, _cargoc.names_long_s[i->produced_cargo[0]] + ((i->total_production[0]!=1)<<5));
if (i->produced_cargo[1] != CT_INVALID) {
SetDParam(3, _cargoc.names_long[i->produced_cargo[1]]);
SetDParam(4, i->total_production[1]);
SetDParam(5, i->pct_transported[0] * 100 >> 8);
SetDParam(6, i->pct_transported[1] * 100 >> 8);
if (i->produced_cargo[1] != 0xFF) {
SetDParam(5, i->total_production[1]);
SetDParam(4, _cargoc.names_long_s[i->produced_cargo[1]] + ((i->total_production[1]!=1)<<5));
SetDParam(6, i->pct_transported[0] * 100 >> 8);
SetDParam(7, i->pct_transported[1] * 100 >> 8);
DrawString(4, 28+n*10, STR_INDUSTRYDIR_ITEM_TWO, 0);
} else {
SetDParam(3, i->pct_transported[0] * 100 >> 8);
SetDParam(4, i->pct_transported[0] * 100 >> 8);
DrawString(4, 28+n*10, STR_INDUSTRYDIR_ITEM, 0);
}
} else {

View File

@@ -1,18 +1,21 @@
/* $Id$ */
#include "stdafx.h"
#include "openttd.h"
#include "ttd.h"
#include "table/strings.h"
#include "functions.h"
#include "window.h"
#include "gui.h"
#include "viewport.h"
#include "gfx.h"
#include "player.h"
#include "command.h"
#include "console.h"
#include "network.h"
#include "variables.h"
extern void SwitchMode(int new_mode);
#if 0
static void ShowSelectTutorialWindow() {}
#endif
static const Widget _select_game_widgets[] = {
{ WWT_CAPTION, RESIZE_NONE, 13, 0, 335, 0, 13, STR_0307_OPENTTD, STR_NULL},
{ WWT_IMGBTN, RESIZE_NONE, 13, 0, 335, 14, 196, STR_NULL, STR_NULL},
@@ -26,9 +29,9 @@ static const Widget _select_game_widgets[] = {
{ WWT_PANEL_2, RESIZE_NONE, 12, 250, 326, 59, 113, 0x1318, STR_0311_SELECT_TOYLAND_LANDSCAPE},
{ WWT_PANEL, RESIZE_NONE, 12, 219, 254, 120, 131, STR_NULL, STR_NULL},
{ WWT_TEXTBTN, RESIZE_NONE, 12, 255, 266, 120, 131, STR_0225, STR_NULL},
{ WWT_CLOSEBOX, RESIZE_NONE, 12, 255, 266, 120, 131, STR_0225, STR_NULL},
{ WWT_PANEL, RESIZE_NONE, 12, 279, 314, 120, 131, STR_NULL, STR_NULL},
{ WWT_TEXTBTN, RESIZE_NONE, 12, 315, 326, 120, 131, STR_0225, STR_NULL},
{ WWT_CLOSEBOX, RESIZE_NONE, 12, 315, 326, 120, 131, STR_0225, STR_NULL},
{ WWT_PUSHTXTBTN, RESIZE_NONE, 12, 10, 167, 138, 149, STR_SINGLE_PLAYER, STR_02FF_SELECT_SINGLE_PLAYER_GAME},
{ WWT_PUSHTXTBTN, RESIZE_NONE, 12, 168, 325, 138, 149, STR_MULTIPLAYER, STR_0300_SELECT_MULTIPLAYER_GAME},
@@ -85,11 +88,11 @@ static void SelectGameWndProc(Window *w, WindowEvent *e)
case 15:
#ifdef ENABLE_NETWORK
if (!_network_available) {
ShowErrorMessage(INVALID_STRING_ID, STR_NETWORK_ERR_NOTAVAILABLE, 0, 0);
ShowErrorMessage(-1, STR_NETWORK_ERR_NOTAVAILABLE, 0, 0);
} else
ShowNetworkGameWindow();
#else
ShowErrorMessage(INVALID_STRING_ID ,STR_NETWORK_ERR_NOTAVAILABLE, 0, 0);
ShowErrorMessage(-1 ,STR_NETWORK_ERR_NOTAVAILABLE, 0, 0);
#endif
break;
case 16: ShowGameOptions(); break;
@@ -104,8 +107,8 @@ static void SelectGameWndProc(Window *w, WindowEvent *e)
case WE_DROPDOWN_SELECT: /* Mapsize selection */
switch (e->dropdown.button) {
case 11: _patches.map_x = e->dropdown.index + 6; break;
case 13: _patches.map_y = e->dropdown.index + 6; break;
case 11: _patches.map_x = e->dropdown.index + 6; break;
case 13: _patches.map_y = e->dropdown.index + 6; break;
}
SetWindowDirty(w);
break;
@@ -143,7 +146,7 @@ void StartScenarioEditor(uint32 rnd1, uint32 rnd2)
}
static const Widget _ask_abandon_game_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 4, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_TEXTBTN, RESIZE_NONE, 4, 0, 10, 0, 13, STR_00C5, STR_NULL},
{ WWT_CAPTION, RESIZE_NONE, 4, 11, 179, 0, 13, STR_00C7_QUIT, STR_NULL},
{ WWT_IMGBTN, RESIZE_NONE, 4, 0, 179, 14, 91, 0x0, STR_NULL},
{ WWT_TEXTBTN, RESIZE_NONE, 12, 25, 84, 72, 83, STR_00C9_NO, STR_NULL},
@@ -151,9 +154,8 @@ static const Widget _ask_abandon_game_widgets[] = {
{ WIDGETS_END },
};
static void AskAbandonGameWndProc(Window* w, WindowEvent* e)
{
switch (e->event) {
static void AskAbandonGameWndProc(Window *w, WindowEvent *e) {
switch(e->event) {
case WE_PAINT:
DrawWindowWidgets(w);
#if defined(_WIN32)
@@ -171,23 +173,22 @@ static void AskAbandonGameWndProc(Window* w, WindowEvent* e)
#else
SetDParam(0, STR_0134_UNIX);
#endif
DrawStringMultiCenter(90, 38, STR_00CA_ARE_YOU_SURE_YOU_WANT_TO, 178);
DrawStringMultiCenter(0x5A, 0x26, STR_00CA_ARE_YOU_SURE_YOU_WANT_TO, 178);
return;
case WE_CLICK:
switch (e->click.widget) {
case 3: DeleteWindow(w); break;
case 4: _exit_game = true; break;
switch(e->click.widget) {
case 3:
DeleteWindow(w);
break;
case 4:
_exit_game = true;
break;
}
break;
case WE_KEYPRESS: /* Exit game on pressing 'Enter' */
switch (e->keypress.keycode) {
case WKC_RETURN:
case WKC_NUM_ENTER:
_exit_game = true;
break;
}
if (e->keypress.keycode == WKC_RETURN || e->keypress.keycode == WKC_NUM_ENTER)
_exit_game = true;
break;
}
}
@@ -207,7 +208,7 @@ void AskExitGame(void)
static const Widget _ask_quit_game_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 4, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_TEXTBTN, RESIZE_NONE, 4, 0, 10, 0, 13, STR_00C5, STR_NULL},
{ WWT_CAPTION, RESIZE_NONE, 4, 11, 179, 0, 13, STR_0161_QUIT_GAME, STR_NULL},
{ WWT_IMGBTN, RESIZE_NONE, 4, 0, 179, 14, 91, 0x0, STR_NULL},
{ WWT_TEXTBTN, RESIZE_NONE, 12, 25, 84, 72, 83, STR_00C9_NO, STR_NULL},
@@ -215,29 +216,32 @@ static const Widget _ask_quit_game_widgets[] = {
{ WIDGETS_END },
};
static void AskQuitGameWndProc(Window* w, WindowEvent* e)
{
switch (e->event) {
case WE_PAINT:
DrawWindowWidgets(w);
DrawStringMultiCenter(
90, 38,
_game_mode != GM_EDITOR ?
STR_0160_ARE_YOU_SURE_YOU_WANT_TO : STR_029B_ARE_YOU_SURE_YOU_WANT_TO,
178
);
break;
static void AskQuitGameWndProc(Window *w, WindowEvent *e) {
switch(e->event) {
case WE_PAINT:
DrawWindowWidgets(w);
DrawStringMultiCenter(0x5A, 0x26,
_game_mode != GM_EDITOR ? STR_0160_ARE_YOU_SURE_YOU_WANT_TO :
STR_029B_ARE_YOU_SURE_YOU_WANT_TO,
178);
return;
case WE_CLICK:
switch (e->click.widget) {
case 3: DeleteWindow(w); break;
case 4: _switch_mode = SM_MENU; break;
}
case WE_CLICK:
switch(e->click.widget) {
case 3:
DeleteWindow(w);
break;
case 4:
_switch_mode = SM_MENU;
break;
}
break;
case WE_KEYPRESS: /* Return to main menu on pressing 'Enter' */
if (e->keypress.keycode == WKC_RETURN)
_switch_mode = SM_MENU;
break;
case WE_KEYPRESS: /* Return to main menu on pressing 'Enter' */
if (e->keypress.keycode == WKC_RETURN) _switch_mode = SM_MENU;
break;
}
}

View File

@@ -11,76 +11,49 @@ go to: http://www.tt-forums.net/viewtopic.php?t=9576
Of course if you have more knowledge about any of these bugs, have more
specifics, we welcome you to report them. React to the given bug indicated
by the number below on http://sourceforge.net/tracker/?group_id=103924&atid=636365
or http://bugs.openttd.org.
If the bug report is closed, it has been fixed, which then can be verified
If the the bug report is closed, it has been fixed, which then can be verified
in the latest SVN version.
Bugs for 0.4.8
------------------------------------------------------------------------
URL: http://bugs.openttd.org
-78 Low Save vs. Autosave
-73 vehicle selection bug
-66 wagon re-fitting
-65 short wagons bug
-52 desync when server saves game (on slow hardware)
-51 Windows doesn't support CUSTOM_LANG_DIR
-50 Trains chosing an alternative path when encountering a 1-way presignal instead of waiting
-47 Low rating calculation and cargo loading priority
-20 Low Saving files when run from gdb 2005-12-06 Unconfirmed
- 9 Low [MorphOS] write to NULL when going to device root in filerequester 2005-11-28 Assigned Christian Rosentreter
Bugs for 0.4.0.1
------------------------------------------------------------------------
URL: http://sourceforge.net/tracker/?atid=636365&group_id=103924&func=browse
-1436419 Vehicles profits gone negitive.......bug
-1434000 Error in Transfer-Function
-1427531 Newspapers problem
-1417453 Makefile and Variables issue
-1397638 Economics bug?
-1395628 Trackpad panning/scrolling broken
-1394799 Dual headed engines disagreement
-1393415 NPF & one-way sigs
-1389999 Child windows not sticking
-1389986 Shares problem (nightly 3330)
-1362784 Incorrect vehicule profit calcul with inflation on
-1299162 Music volume too low
-1250094 Towns Shrink when center tile is built on
-1244842 Multiplayer interface bug (0.4.0.1)
-1212267 station visited twice when servicing
-1211764 AI companies behave weird on the stock market
-1208170 Duplicate station names can be created
- Minimap crash with certain views and certain resolutions
- "Broken" autoreplace for dual-headed trains
-1203319 Pre-signal exits not working when one way signal
-1197116 Some stations are cargo-less
-1188897 Station with cargo enroute_from INVALID_STATION
-1186802 Company value problem (loans)
-1181888 Invaild Station Order => Crash
-1174829 Waypoint / Orders Bug
-1168820 Some mouse and keyboard events are lost
-1167810 Cargo payment after deleting stations (st->xy = 0)
-1157244 Can't save game if name contains german umlauts
-1144510 Make install tries to install scenarios to the wrong place
-1116638 "More, but smaller changes" deficiency
-1106356 re-offered prototypes
-1099233 production down before it's working
-1085486 Subsidies: Only count when station is in right suburb
-992677 BeOS MIDI does not initialise on newer BeOS releases
Minor Bugs for 0.4.8
Minor Bugs for 0.4.0.1
------------------------------------------------------------------------
URL: http://sourceforge.net/tracker/?atid=669662&group_id=103924&func=browse
-1424115 Reversed arrow sign in list view column headers
-1412031 fast forward scrolling is also fast forward :)
-1387424 overtake insolvent company is to cheap
-1382782 Loan interest calculated 'wrong'
-1372891 Performance loss with NTP & NPF
-1296259 Autosave override for multiplayer games
-1242753 Town population minus 10
-1236320 Bug in main menu allows moving screen
-1201284 permanent hilight in a depot
-1197258 Window Z-order locked when exiting openttd
-1193882 problems with dualhead engins in DB Set XL (v0.81)
-1193870 keep the date counter running
-1185852 Scrollbars get arbitrarily small
-1184634 Replace vehicles window bug
-1183253 Incorrect Load vs Loading Sprites
-1183251 Hangar sprite does not update when refit.
-1179933 autorail removal does not go completely red.
-1160732 little bug with transparency
-1153937 Game wont run from a start menu shortcut
-1117731 Editor-StartingDate
-1114237 Wrong autoreplace hint
-1112784 detailed sound options
-1108046 game freezes
-1106889 Chat Interface enhancements
-1104358 train lost message - history
@@ -90,9 +63,13 @@ URL: http://sourceforge.net/tracker/?atid=669662&group_id=103924&func=browse
-1034310 color mauve in diagrams
-1030661 It's possible to build a tunnel under oil wells
-1009171 Canals and locks at sea level cause flooding
-0993516 Canal + bouy -> wrong graphics.
-0987891 Large UFO destruction bug
-0987883 Aircraft landing/taking off
-0987880 company league table updating
-0985924 aircraft taxi speed
-0941694 Clipping problems stations/vehicles on slopes
-993516 Canal + bouy -> wrong graphics.
-987891 Large UFO destruction bug
-987884 farm fences
-987883 Aircraft landing/taking off
-987880 company league table updating
-985924 aircraft taxi speed
-980276 Overflow in factory directory
-976824 transmitter base
-941694 Clipping problems stations/vehicles on slopes
-936997 Stationname too long to fit in trainwindow bug

View File

@@ -1,18 +1,14 @@
/* $Id$ */
#include "stdafx.h"
#include "openttd.h"
#include "functions.h"
#include "ttd.h"
#include "map.h"
#include "player.h"
#include "spritecache.h"
#include "table/sprites.h"
#include "tile.h"
#include <stdarg.h>
#include "gfx.h"
#include "viewport.h"
#include "command.h"
#include "vehicle.h"
#include "variables.h"
extern const TileTypeProcs
_tile_type_clear_procs,
@@ -47,17 +43,13 @@ 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[] = {
3, 9, 3, 6, 12, 6, 12, 9
};
void FindLandscapeHeightByTile(TileInfo *ti, TileIndex tile)
{
assert(tile < MapSize());
ti->tile = tile;
ti->map5 = _m[tile].m5;
ti->map5 = _map5[tile];
ti->type = GetTileType(tile);
ti->tileh = GetTileSlope(tile, &ti->z);
}
@@ -77,7 +69,7 @@ void FindLandscapeHeight(TileInfo *ti, uint x, uint y)
return;
}
FindLandscapeHeightByTile(ti, TileVirtXY(x, y));
FindLandscapeHeightByTile(ti, TILE_FROM_XY(x,y));
}
uint GetPartialZ(int x, int y, int corners)
@@ -184,60 +176,40 @@ uint GetSlopeZ(int x, int y)
return _tile_type_procs[ti.type]->get_slope_z_proc(&ti);
}
static Slope GetFoundationSlope(TileIndex tile, uint* z)
// direction=true: check for foundation in east and south corner
// direction=false: check for foundation in west and south corner
static bool hasFoundation(TileInfo *ti, bool direction)
{
TileInfo ti;
Slope tileh;
Slope slope;
bool south, other; // southern corner and east/west corner
uint slope = _tile_type_procs[ti->type]->get_slope_tileh_proc(ti);
uint tileh = ti->tileh;
FindLandscapeHeightByTile(&ti, tile);
tileh = ti.tileh;
slope = _tile_type_procs[GetTileType(tile)]->get_slope_tileh_proc(&ti);
if(slope==0 && slope!=tileh) tileh=15;
south = (tileh & 2) != (slope & 2);
if(direction)
other = (tileh & 4) != (slope & 4);
else
other = (tileh & 1) != (slope & 1);
return south || other;
// Flatter slope -> higher base height
if (slope < tileh) *z += TILE_HEIGHT;
return slope;
}
static bool HasFoundationNW(TileIndex tile, Slope slope_here, uint z_here)
{
uint z;
Slope slope = GetFoundationSlope(TILE_ADDXY(tile, 0, -1), &z);
return
(z_here + (slope_here & SLOPE_N ? TILE_HEIGHT : 0) > z + (slope & SLOPE_E ? TILE_HEIGHT : 0)) ||
(z_here + (slope_here & SLOPE_W ? TILE_HEIGHT : 0) > z + (slope & SLOPE_S ? TILE_HEIGHT : 0));
}
static bool HasFoundationNE(TileIndex tile, Slope slope_here, uint z_here)
{
uint z;
Slope slope = GetFoundationSlope(TILE_ADDXY(tile, -1, 0), &z);
return
(z_here + (slope_here & SLOPE_N ? TILE_HEIGHT : 0) > z + (slope & SLOPE_W ? TILE_HEIGHT : 0)) ||
(z_here + (slope_here & SLOPE_E ? TILE_HEIGHT : 0) > z + (slope & SLOPE_S ? TILE_HEIGHT : 0));
}
void DrawFoundation(TileInfo *ti, uint f)
{
uint32 sprite_base = SPR_SLOPES_BASE-14;
Slope slope;
uint z;
slope = GetFoundationSlope(ti->tile, &z);
if (!HasFoundationNW(ti->tile, slope, z)) sprite_base += 22;
if (!HasFoundationNE(ti->tile, slope, z)) sprite_base += 44;
TileInfo ti2;
FindLandscapeHeight(&ti2, ti->x, ti->y-1);
if(hasFoundation( &ti2, true )) sprite_base += 22; // foundation in NW direction
FindLandscapeHeight(&ti2, ti->x-1, ti->y);
if(hasFoundation( &ti2, false )) sprite_base += 22*2; // foundation in NE direction
if (f < 15) {
// leveled foundation
if (sprite_base < SPR_SLOPES_BASE) sprite_base = SPR_FOUNDATION_BASE + 1; // use original slope sprites
if( sprite_base < SPR_SLOPES_BASE ) sprite_base = 990; // use original slope sprites
AddSortableSpriteToDraw(f - 1 + sprite_base, ti->x, ti->y, 16, 16, 7, ti->z);
AddSortableSpriteToDraw(f-1 + sprite_base, ti->x, ti->y, 16, 16, 7, ti->z);
ti->z += 8;
ti->tileh = 0;
OffsetGroundSprite(31, 1);
@@ -246,7 +218,7 @@ void DrawFoundation(TileInfo *ti, uint f)
sprite_base += 14;
AddSortableSpriteToDraw(
HASBIT((1<<1) | (1<<2) | (1<<4) | (1<<8), ti->tileh) ? sprite_base + (f - 15) : SPR_FOUNDATION_BASE + ti->tileh,
HASBIT( (1<<1) | (1<<2) | (1<<4) | (1<<8), ti->tileh) ? sprite_base + (f - 15) : ti->tileh + 0x3DE - 1,
ti->x, ti->y, 1, 1, 1, ti->z
);
@@ -308,7 +280,7 @@ void GetTileDesc(TileIndex tile, TileDesc *td)
*/
int32 CmdLandscapeClear(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
TileIndex tile = TileVirtXY(x, y);
TileIndex tile = TILE_FROM_XY(x, y);
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
@@ -327,7 +299,7 @@ int32 CmdClearArea(int ex, int ey, uint32 flags, uint32 p1, uint32 p2)
int x,y;
bool success = false;
if (p1 >= MapSize()) return CMD_ERROR;
if (p1 > MapSize()) return CMD_ERROR;
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
@@ -342,7 +314,7 @@ int32 CmdClearArea(int ex, int ey, uint32 flags, uint32 p1, uint32 p2)
for (x = sx; x <= ex; x += 16) {
for (y = sy; y <= ey; y += 16) {
ret = DoCommandByTile(TileVirtXY(x, y), 0, 0, flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR);
ret = DoCommandByTile(TILE_FROM_XY(x,y), 0, 0, flags &~DC_EXEC, CMD_LANDSCAPE_CLEAR);
if (CmdFailed(ret)) continue;
cost += ret;
success = true;
@@ -352,7 +324,7 @@ int32 CmdClearArea(int ex, int ey, uint32 flags, uint32 p1, uint32 p2)
_additional_cash_required = ret;
return cost - ret;
}
DoCommandByTile(TileVirtXY(x, y), 0, 0, flags, CMD_LANDSCAPE_CLEAR);
DoCommandByTile(TILE_FROM_XY(x,y), 0, 0, flags, CMD_LANDSCAPE_CLEAR);
// draw explosion animation...
if ((x == sx || x == ex) && (y == sy || y == ey)) {
@@ -377,36 +349,36 @@ void CDECL ModifyTile(TileIndex tile, uint flags, ...)
va_start(va, flags);
if ((i = GB(flags, 8, 4)) != 0) {
if ((i = (flags >> 8) & 0xF) != 0) {
SetTileType(tile, i - 1);
}
if (flags & (MP_MAP2_CLEAR | MP_MAP2)) {
int x = 0;
if (flags & MP_MAP2) x = va_arg(va, int);
_m[tile].m2 = x;
_map2[tile] = x;
}
if (flags & (MP_MAP3LO_CLEAR | MP_MAP3LO)) {
int x = 0;
if (flags & MP_MAP3LO) x = va_arg(va, int);
_m[tile].m3 = x;
_map3_lo[tile] = x;
}
if (flags & (MP_MAP3HI_CLEAR | MP_MAP3HI)) {
int x = 0;
if (flags & MP_MAP3HI) x = va_arg(va, int);
_m[tile].m4 = x;
_map3_hi[tile] = x;
}
if (flags & (MP_MAPOWNER|MP_MAPOWNER_CURRENT)) {
PlayerID x = _current_player;
byte x = _current_player;
if (flags & MP_MAPOWNER) x = va_arg(va, int);
_m[tile].m1 = x;
_map_owner[tile] = x;
}
if (flags & MP_MAP5) {
_m[tile].m5 = va_arg(va, int);
_map5[tile] = va_arg(va, int);
}
va_end(va);
@@ -436,7 +408,7 @@ void RunTileLoop(void)
if (TileX(tile) < MapSizeX() - TILELOOP_SIZE) {
tile += TILELOOP_SIZE; /* no overflow */
} else {
tile = TILE_MASK(tile - TILELOOP_SIZE * (MapSizeX() / TILELOOP_SIZE - 1) + TileDiffXY(0, TILELOOP_SIZE)); /* x would overflow, also increase y */
tile = TILE_MASK(tile - TILELOOP_SIZE * (MapSizeX() / TILELOOP_SIZE-1) + TILE_XY(0, TILELOOP_SIZE)); /* x would overflow, also increase y */
}
} while (--count);
assert( (tile & ~TILELOOP_ASSERTMASK) == 0);
@@ -447,22 +419,21 @@ void RunTileLoop(void)
_cur_tileloop_tile = tile;
}
void InitializeLandscape(void)
void InitializeLandscape(uint log_x, uint log_y)
{
uint map_size;
uint i;
InitMap(log_x, log_y);
map_size = MapSize();
for (i = 0; i < map_size; i++) {
_m[i].type_height = MP_CLEAR << 4;
_m[i].m1 = OWNER_NONE;
_m[i].m2 = 0;
_m[i].m3 = 0;
_m[i].m4 = 0;
_m[i].m5 = 3;
_m[i].extra = 0;
}
memset(_map_type_and_height, MP_CLEAR << 4, map_size);
memset(_map_owner, OWNER_NONE, map_size);
memset(_map2, 0, map_size * sizeof(_map2[0]));
memset(_map3_lo, 0, map_size);
memset(_map3_hi, 0, map_size);
memset(_map5, 3, map_size);
memset(_map_extra_bits, 0, map_size / 4);
// create void tiles at the border
for (i = 0; i < MapMaxY(); ++i)
@@ -479,8 +450,8 @@ void ConvertGroundTilesIntoWaterTiles(void)
for (tile = 0; tile < MapSize(); ++tile) {
if (IsTileType(tile, MP_CLEAR) && GetTileSlope(tile, &h) == 0 && h == 0) {
SetTileType(tile, MP_WATER);
_m[tile].m5 = 0;
SetTileOwner(tile, OWNER_WATER);
_map5[tile] = 0;
_map_owner[tile] = OWNER_WATER;
}
}
}
@@ -497,7 +468,7 @@ static void GenerateTerrain(int type, int flag)
uint h;
const Sprite* template;
const byte *p;
Tile* tile;
byte *tile;
byte direction;
r = Random();
@@ -510,7 +481,7 @@ static void GenerateTerrain(int type, int flag)
if (x < 2 || y < 2)
return;
direction = GB(r, 22, 2);
direction = (r >> 22) & 3;
if (direction & 1) {
w = template->height;
h = template->width;
@@ -550,62 +521,62 @@ static void GenerateTerrain(int type, int flag)
if (y + h >= MapMaxY() - 1)
return;
tile = &_m[TileXY(x, y)];
tile = &_map_type_and_height[TILE_XY(x, y)];
switch (direction) {
case 0:
do {
Tile* tile_cur = tile;
byte *tile_cur = tile;
uint w_cur;
for (w_cur = w; w_cur != 0; --w_cur) {
if (*p >= tile_cur->type_height) tile_cur->type_height = *p;
if (*p >= *tile_cur) *tile_cur = *p;
p++;
tile_cur++;
}
tile += TileDiffXY(0, 1);
tile += TILE_XY(0, 1);
} while (--h != 0);
break;
case 1:
do {
Tile* tile_cur = tile;
byte *tile_cur = tile;
uint h_cur;
for (h_cur = h; h_cur != 0; --h_cur) {
if (*p >= tile_cur->type_height) tile_cur->type_height = *p;
if (*p >= *tile_cur) *tile_cur = *p;
p++;
tile_cur += TileDiffXY(0, 1);
tile_cur += TILE_XY(0, 1);
}
tile++;
} while (--w != 0);
break;
case 2:
tile += TileDiffXY(w - 1, 0);
tile += TILE_XY(w - 1, 0);
do {
Tile* tile_cur = tile;
byte *tile_cur = tile;
uint w_cur;
for (w_cur = w; w_cur != 0; --w_cur) {
if (*p >= tile_cur->type_height) tile_cur->type_height = *p;
if (*p >= *tile_cur) *tile_cur = *p;
p++;
tile_cur--;
}
tile += TileDiffXY(0, 1);
tile += TILE_XY(0, 1);
} while (--h != 0);
break;
case 3:
tile += TileDiffXY(0, h - 1);
tile += TILE_XY(0, h - 1);
do {
Tile* tile_cur = tile;
byte *tile_cur = tile;
uint h_cur;
for (h_cur = h; h_cur != 0; --h_cur) {
if (*p >= tile_cur->type_height) tile_cur->type_height = *p;
if (*p >= *tile_cur) *tile_cur = *p;
p++;
tile_cur -= TileDiffXY(0, 1);
tile_cur -= TILE_XY(0, 1);
}
tile++;
} while (--w != 0);
@@ -639,7 +610,7 @@ static void CreateDesertOrRainForest(void)
for (data = _make_desert_or_rainforest_data;
data != endof(_make_desert_or_rainforest_data); ++data) {
TileIndex t = TILE_MASK(tile + ToTileIndexDiff(*data));
if (IsTileType(t, MP_CLEAR) && (_m[t].m5 & 0x1c) == 0x14) break;
if (IsTileType(t, MP_CLEAR) && (_map5[t] & 0x1c) == 0x14) break;
}
if (data == endof(_make_desert_or_rainforest_data))
SetMapExtraBits(tile, 2);
@@ -657,16 +628,16 @@ void GenerateLandscape(void)
GenerateTerrain(2, 0);
r = Random();
flag = GB(r, 0, 2) | 4;
for (i = ScaleByMapSize(GB(r, 16, 7) + 450); i != 0; --i)
flag = (r & 3) | 4;
for (i = ScaleByMapSize(((r >> 16) & 0x7F) + 450); i != 0; --i)
GenerateTerrain(4, flag);
} else if (_opt.landscape == LT_DESERT) {
for (i = ScaleByMapSize((Random()&0x7F) + 170); i != 0; --i)
GenerateTerrain(0, 0);
r = Random();
flag = GB(r, 0, 2) | 4;
for (i = ScaleByMapSize(GB(r, 16, 8) + 1700); i != 0; --i)
flag = (r & 3) | 4;
for (i = ScaleByMapSize(((r >> 16) & 0xFF) + 1700); i != 0; --i)
GenerateTerrain(0, flag);
flag ^= 2;
@@ -709,9 +680,9 @@ TileIndex AdjustTileCoordRandomly(TileIndex a, byte rng)
int rn = rng;
uint32 r = Random();
return TILE_MASK(TileXY(
TileX(a) + (GB(r, 0, 8) * rn * 2 >> 8) - rn,
TileY(a) + (GB(r, 8, 8) * rn * 2 >> 8) - rn
return TILE_MASK(TILE_XY(
TileX(a) + ((byte)r * rn * 2 >> 8) - rn,
TileY(a) + ((byte)(r >> 8) * rn * 2 >> 8) - rn
));
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

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