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

Compare commits

..

3 Commits

Author SHA1 Message Date
truelight
e8c8a3f397 (svn r257) Hopefully now the 0.3.4 tag is correct 2004-09-14 19:03:03 +00:00
darkvater
be94ee8859 (svn r255) tagged 0.3.4 (again) 2004-09-14 18:58:39 +00:00
darkvater
eea1731db1 (svn r254) tag for revision 0.3.4 created 2004-09-14 18:54:10 +00:00
827 changed files with 143967 additions and 343777 deletions

11
.gitignore vendored
View File

@@ -1,11 +0,0 @@
Makefile*
bin/*
!bin/data/chars.grf
!bin/data/openttdd.grf
!bin/data/openttdw.grf
!bin/data/opntitle.grf
!bin/scenario/README
!bin/scripts*
config.*
objs/*
src/rev.cpp

39
COPYING
View File

@@ -1,12 +1,12 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
@@ -15,7 +15,7 @@ software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
@@ -55,8 +55,8 @@ patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
@@ -110,7 +110,7 @@ above, provided that you also meet all of these conditions:
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
@@ -168,7 +168,7 @@ access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
@@ -225,7 +225,7 @@ impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
@@ -255,7 +255,7 @@ make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
@@ -277,9 +277,9 @@ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
@@ -303,9 +303,10 @@ the "copyright" line and a pointer to where the full notice is found.
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
@@ -335,5 +336,5 @@ necessary. Here is a sample; alter the names:
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.

231
Doxyfile
View File

@@ -1,231 +0,0 @@
#---------------------------------------------------------------------------
# Project related configuration options
#---------------------------------------------------------------------------
PROJECT_NAME = openttd
OUTPUT_DIRECTORY = docs/source/
CREATE_SUBDIRS = NO
OUTPUT_LANGUAGE = English
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 \
*.hpp \
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 = YES
EXPAND_ONLY_PREDEF = YES
SEARCH_INCLUDES = YES
INCLUDE_PATH =
INCLUDE_FILE_PATTERNS =
PREDEFINED =
EXPAND_AS_DEFINED = DEF_COMMAND
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_DEPTH = 1000
DOT_TRANSPARENT = NO
DOT_MULTI_TARGETS = NO
GENERATE_LEGEND = YES
DOT_CLEANUP = YES
#---------------------------------------------------------------------------
# Configuration::additions related to the search engine
#---------------------------------------------------------------------------
SEARCHENGINE = NO

163
Jamfile.next Normal file
View File

@@ -0,0 +1,163 @@
CFILES = ai.c aircraft_cmd.c aircraft_gui.c airport_gui.c
bridge_gui.c clear_cmd.c command.c disaster_cmd.c
dock_gui.c dummy_land.c economy.c engine.c engine_gui.c
fileio.c gfx.c graph_gui.c industry_cmd.c industry_gui.c
intro_gui.c landscape.c main_gui.c minilzo.c misc.c
misc_cmd.c misc_gui.c music_gui.c namegen.c network.c
news_gui.c oldloader.c order_cmd.c order_gui.c pathfind.c
player_gui.c players.c rail_cmd.c rail_gui.c road_cmd.c
road_gui.c roadveh_cmd.c roadveh_gui.c saveload.c sdl.c
settings.c settings_gui.c ship_cmd.c ship_gui.c smallmap_gui.c
sound.c spritecache.c station_cmd.c station_gui.c
strings.c subsidy_gui.c texteff.c town_cmd.c town_gui.c
train_cmd.c train_gui.c tree_cmd.c ttd.c
tunnelbridge_cmd.c unmovable_cmd.c vehicle.c
viewport.c water_cmd.c widget.c window.c screenshot.c
airport.c grfspecial.c terraform_gui.c ;
LANGFILES = english.txt swedish.txt french.txt german.txt italian.txt slovak.txt hungarian.txt norwegian.txt danish.txt czech.txt galician.txt polish.txt romanian.txt;
####################
# On UNIX we use gcc
####################
if $(UNIX) {
SDL_CONFIG_CFLAGS = `XX_SDL_CONFIG_PLACEHOLDER_XX --cflags` ;
SDL_CONFIG_LIBS = `XX_SDL_CONFIG_PLACEHOLDER_XX --libs` ;
LINKFLAGS += $(SDL_CONFIG_LIBS) ;
CC = gcc ;
CCFLAGS += -Wall -Wno-multichar -DUNIX -DWITH_SDL ;
OPTIMFLAGS = -O2 -fomit-frame-pointer ;
DEBUGFLAGS = -g ;
# also include extmidi
CFILES += extmidi.c unix.c ;
# compile in PNG support?
if $(WITH_PNG) {
CCFLAGS += -DWITH_PNG -I$(WITH_PNG) ;
LINKFLAGS += -lpng ;
}
# compile in zlib support?
if $(WITH_ZLIB) {
CCFLAGS += -DWITH_ZLIB ;
LINKFLAGS += -lz ;
}
# compile for BeOS 5.1 and higher
if $(WITH_BONE_NETWORKING) {
CCFLAGS += -DENABLE_NETWORK ;
LINKFLAGS += -lsocket -lbind ;
}
# link in BeOS MIDI and Be API libraries
if $(BEOS_MIDI) {
CCFLAGS += -DBEOS_MIDI ;
LINKFLAGS += -lbe -lmidi ;
CFILES += bemidi.cpp ;
}
}
####################
# MSVC on Win32
####################
actions ActWin32Res {
$(VISUALC)\\..\\common\\msdev98\\bin\\rc /r /i $(STDHDRS) /fo $(<) $(>)
}
rule Win32Res { ActWin32Res $(<) : $(>) ; DEPENDS $(<) : $(>) ; }
if $(TOOLSET) = VISUALC {
OPTIMFLAGS = /Oa /Os /Ow /Oy /Oi /Og /Ox /Gr /Gf /Gy /Zp4 /J /WX /W3 -DNDEBUG ;
CCFLAGS += -DWIN32 -DWIN32_EXCEPTION_TRACKER ;
CFILES += win32.c ;
LINKFLAGS += /opt:nowin98 /LIBPATH:$(VISUALC)\\lib ;
LINKLIBS = ws2_32.lib winmm.lib user32.lib gdi32.lib ;
# compile resources too
EOBJ = ttd.res ;
Win32Res ttd.res : ttd.rc ;
# png screenshots?
if $(WITH_PNG) {
CCFLAGS += -DWITH_PNG -I$(WITH_PNG) ;
LINKLIBS += libpng.lib ;
}
# zlib savegames?
if $(WITH_ZLIB) {
CCFLAGS += -DWITH_ZLIB ;
LINKLIBS += zlibstat.lib ;
}
# build release by default
RELEASE = 1 ;
}
####################
# Common
####################
rule MyObjects {
local _i _t _s ;
_t = $(OUTDIR)/$(>:S=$(SUFOBJ)) ;
OPTIM on $(_t) = $(3) ;
MkDir $(OUTDIR) ;
Depends $(_t) : $(OUTDIR) ;
for _i in $(>) {
_s = $(OUTDIR)/$(_i:S=$(SUFOBJ)) ;
Object $(_s) : $(_i) ;
# special handling for sdl.c and unix.c
if $(_i) = sdl.c || $(_i) = unix.c { CCFLAGS on $(_s) += $(SDL_CONFIG_CFLAGS) ; }
}
MainFromObjects $(OUTDIR)/$(<) : $(_t) $(EOBJ) ;
}
rule MyMain {
if $(RELEASE) {
OUTDIR = release ;
MyObjects ttd : $(>) : $(OPTIMFLAGS) ;
} else {
OUTDIR = debug ;
MyObjects ttd : $(>) : -D_DEBUG $(DEBUGFLAGS) ;
}
}
actions CompileLang {
strgen$(SLASH)strgen $(>)
}
rule LangFile {
if $(>) = lang/english.txt {
CompileLang $(<) table/strings.h : ;
DEPENDS table/string.h : $(>) ;
} else {
CompileLang $(<) : $(>) ;
}
Clean clean : $(<) ;
DEPENDS $(<) : $(>) ;
DEPENDS all : $(<) ;
DEPENDS $(<) : strgen/strgen ;
}
rule LangFiles {
local _i ;
for _i in $(<) { LangFile $(_i:S=.lng) : $(_i) ; }
Clean clean : table/strings.h ;
}
LangFiles lang/$(LANGFILES) ;
Main strgen/strgen : strgen/strgen.c ;
MyMain ttd : $(CFILES) ;

662
Makefile Normal file
View File

@@ -0,0 +1,662 @@
# 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 $
##############################################################################
#
# Usage
#
# Synopsis:
#
# make WITH_ZLIB=1 UNIX=1 MANUAL_CONFIG=1
#
# (See below for the list of possible options.)
#
# Alternately, you can run make without the MANUAL_CONFIG part. It then
# generates Makefile.config, where you can customize all the options.
# However beware that for all subsequent calls the option values from
# Makefile.config take precedence to the commandline options.
#
# (That means that you probably want to either specify the options on command
# line together with MANUAL_CONFIG=1 or you want to specify no commandline
# options at all.)
# Targets:
#
# Defaults to building binary
# clean: remove intermediate build files
# mrproper: remove intermediate files and makefile configuration
# upgradeconf: add new options to old Makefile.config
# osx: OS X application
# Options:
#
# Summary of OS choice defines
# WIN32: building on Windows
# UNIX: building on *nix derivate (Linux, FreeBSD)
# OSX: building on Mac OS X
# MORPHOS: building on MorphOS
#
# Summary of library choice defines
# WITH_ZLIB: savegames using zlib
# WITH_PNG: screenshots using PNG
# WITH_SDL: SDL 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
# DISPLAY_WARNINGS: when off, some errors are not displayed while compiling
# TRANSLATOR: build in translator mode (untranslated strings are prepended by
# a <TODO> mark)
# RELEASE: this will be the released version number. It replaces all places
# where it normally would print the revision number
# 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
# NOVERBOSE: supress all warnings and errors during compilation.
# It looks nicer, but you will not know what went wrong. Use it on released (stable) sources only
#
# DATA_DIR_PREFIX: This sets the dir OpenTTD looks for the needed files.
# MUST END WITH / if defined
#
# STATIC: link statically
# CYGWIN: build in Cygwin environment
# MINGW: build with MingW compiler, link with MingW libraries
#
# Experimental (does not work properly):
# WITH_NETWORK: enable networking
# WITH_DIRECTMUSIC: enable DirectMusic MIDI support
##############################################################################
#
# Configuration
#
# Makefile version tag
# it checks if the version tag in makefile.config is the same and force update outdated config files
MAKEFILE_VERSION:=1
# CONFIG_WRITER have to be found even for manual configuration
CONFIG_WRITER=makefiledir/Makefile.config_writer
ifndef MANUAL_CONFIG
# Automatic configuration
MAKE_CONFIG:=Makefile.config
MAKEFILE:=Makefile
LIB_DETECTION=makefiledir/Makefile.libdetection
CONFIG_WRITER=makefiledir/Makefile.config_writer
# Apply automatic configuration
# 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
else
# this should define SDL-CONFIG for manual configuration
ifeq ($(shell uname),FreeBSD)
SDL-CONFIG:=sdl11-config
else
SDL-CONFIG:=sdl-config
endif
endif
# this is used if there aren't any makefile.config
ifndef CONFIG_INCLUDED
ENABLE_NETWORK:=1 # sets network on by default if there aren't any config file
-include $(LIB_DETECTION)
endif
# Verbose filter
ifdef NOVERBOSE
VERBOSE_FILTER = >/dev/null 2>&1
else
VERBOSE_FILTER =
endif
ifdef DISPLAY_WARNINGS
WARNING_DISPLAY:=-fstrict-aliasing
VERBOSE_FILTER =
else
WARNING_DISPLAY:=-fno-strict-aliasing
endif
ifdef SUPRESS_LANG_ERRORS
ifndef VERBOSE_FILTER
LANG_ERRORS = >/dev/null 2>&1
endif
endif
ifdef STATIC
ifndef WIN32
ifndef OSX
ifndef MORPHOS
ifndef SKIP_STATIC_CHECK
$(error Static is only known to work on MorphOS and MacOSX!!! --- Check makefile.config for more info and howto bypass this check)
endif
endif
endif
endif
endif
# Force SDL on UNIX platforms
ifndef WITH_SDL
ifdef UNIX
$(error You need to have SDL installed in order to run OpenTTD on UNIX.)
endif
endif
##############################################################################
#
# Compiler configuration
#
CC=gcc
CXX=g++
ifdef MORPHOS
CC += -noixemul -pipe
CXX += -noixemul -pipe
endif
# Executable file extension
ifdef WIN32
EXE=.exe
else
EXE=
endif
# Set output executable names
TTD=openttd$(EXE)
ENDIAN_CHECK=endian_check$(EXE)
STRGEN=strgen/strgen$(EXE)
OSXAPP="OpenTTD.app"
# 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 echo -n r; svnversion .; 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
# 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.
CFLAGS=-Wall -Wno-multichar
CDEFS=-DWITH_REV
LDFLAGS=
LIBS=
ifdef DEBUG
# Debug mode
CDEFS += -D_DEBUG
BASECFLAGS += -g
else
ifdef PROFILE
BASECFLAGS += -pg
else
# Release mode
ifndef MORPHOS
# automatical strip breaks under morphos
BASECFLAGS += -s
LDFLAGS += -s
endif
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 -mpowerpc-gpopt -force_cpusubtype_ALL $(WARNING_DISPLAY)
else
ifdef MORPHOS
BASECFLAGS += -O2 -funroll-loops -fexpensive-optimizations -mstring -mmultiple $(WARNING_DISPLAY)
else
BASECFLAGS += -O2 $(WARNING_DISPLAY)
endif
ifndef PROFILE
BASECFLAGS += -fomit-frame-pointer
endif
endif
endif
ifdef STATIC
ifndef OSX # OSX can't build static if -static flag is used
LDFLAGS += -static
endif
endif
# If building on Cygwin/MingW don't link with Cygwin libs
ifdef WIN32
ifdef MINGW
ifdef CYGWIN
BASECFLAGS += -mno-cygwin
LDFLAGS += -mno-cygwin
endif
endif
endif
CFLAGS += $(BASECFLAGS)
ifdef UNIX
CDEFS += -DUNIX
endif
# SDL config
ifdef WITH_SDL
CDEFS += -DWITH_SDL
CFLAGS += `$(SDL-CONFIG) --cflags`
ifdef STATIC
LIBS += `$(SDL-CONFIG) --static-libs`
else
LIBS += `$(SDL-CONFIG) --libs`
endif
endif
# zlib config
ifdef WITH_ZLIB
CDEFS += -DWITH_ZLIB
ifdef STATIC
ifdef OSX
# 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
LIBS += -lz
endif
endif
# libpng config
ifdef WITH_PNG
CDEFS += -DWITH_PNG
# FreeBSD doesn't use libpng-config
ifdef FREEBSD
LIBS += -lpng
else
CFLAGS += `libpng-config --cflags`
ifdef OSX
ifdef STATIC
# Seems like we need a tiny hack for OSX static to work
LIBS += `libpng-config --prefix`/lib/libpng.a
else
LIBS += `libpng-config --libs`
endif
else
# seems like older libpng versions are broken and need this
PNGCONFIG_FLAGS = --ldflags --libs
ifdef STATIC
LIBS += `libpng-config --static $(PNGCONFIG_FLAGS)`
else
LIBS += `libpng-config $(PNGCONFIG_FLAGS)`
endif
endif
endif
endif
ifdef TRANSLATOR
STRGEN_FLAGS=-t
else
STRGEN_FLAGS=
endif
# file paths setup
ifdef GAME_DATA_DIR
CDEFS += -DGAME_DATA_DIR=\"$(GAME_DATA_DIR)\"
endif
ifdef PERSONAL_DIR
CDEFS += -DPERSONAL_DIR=\"$(PERSONAL_DIR)\"
endif
ifdef USE_HOMEDIR
CDEFS += -DUSE_HOMEDIR
endif
# MIDI setup
ifdef OSX
ifndef MIDI
MIDI:=$(OSXAPP)/contents/macos/track_starter
endif
endif
ifdef MIDI
CDEFS += -DEXTERNAL_PLAYER=\"$(MIDI)\"
ifdef MIDI_ARG
CDEFS += -DMIDI_ARG=\"$(MIDI_ARG)\"
endif
endif
# Experimental
ifdef WITH_NETWORK
CDEFS += -DENABLE_NETWORK
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
ifdef WITH_DIRECTMUSIC
CDEFS += -DWIN32_ENABLE_DIRECTMUSIC_SUPPORT
endif
ifdef WIN32
LIBS += -lws2_32 -lwinmm -lgdi32 -ldxguid -lole32 -lstdc++
TTDLDFLAGS += -Wl,--subsystem,windows
endif
# sets up the paths for use for make install
ifdef BINARY_DIR
BINARY_INSTALL:=$(BINARY_DIR)$(TTD)
else
BINARY_INSTALL:=$(INSTALL_DIR)$(TTD)
endif
ifdef DATA_DIR_PREFIX
DATA_DIR:=$(DATA_DIR_PREFIX)
else
DATA_DIR:=$(INSTALL_DIR)
endif
##############################################################################
#
# What to compile
# (users do not want to modify anything below)
#
### Sources
ttd_SOURCES = \
ai.c ai_build.c ai_new.c ai_pathfinder.c ai_shared.c aircraft_cmd.c \
aircraft_gui.c airport.c airport_gui.c aystar.c bridge_gui.c \
clear_cmd.c command.c console.c console_cmds.c disaster_cmd.c dock_gui.c dummy_land.c economy.c \
engine.c engine_gui.c fileio.c gfx.c graph_gui.c grfspecial.c \
industry_cmd.c industry_gui.c intro_gui.c landscape.c main_gui.c \
minilzo.c misc.c misc_cmd.c misc_gui.c music_gui.c namegen.c network.c \
network_gui.c news_gui.c oldloader.c order_cmd.c order_gui.c \
pathfind.c player_gui.c players.c queue.c rail_cmd.c rail_gui.c rev.c \
road_cmd.c road_gui.c roadveh_cmd.c roadveh_gui.c saveload.c \
screenshot.c settings.c settings_gui.c ship_cmd.c ship_gui.c \
smallmap_gui.c sound.c spritecache.c station_cmd.c station_gui.c \
strings.c subsidy_gui.c terraform_gui.c texteff.c town_cmd.c \
town_gui.c train_cmd.c train_gui.c tree_cmd.c ttd.c tunnelbridge_cmd.c \
unmovable_cmd.c vehicle.c vehicle_gui.c viewport.c water_cmd.c widget.c window.c \
ifdef WITH_SDL
ttd_SOURCES += sdl.c
endif
ifdef WIN32
ttd_SOURCES += win32.c w32dm.c
else
ttd_SOURCES += extmidi.c unix.c
endif
ttd_OBJS = $(ttd_SOURCES:%.c=%.o)
ifdef WIN32
# Resource file
ttd_OBJS += winres.o
endif
ifdef WITH_DIRECTMUSIC
ttd_SOURCES += w32dm2.cpp
ttd_OBJS += w32dm2.o
endif
ttd_DEPS1 = $(foreach obj,$(ttd_OBJS),.deps/$(obj))
ttd_DEPS = $(ttd_DEPS1:%.o=%.P)
LANG_TXT = $(filter-out %.unfinished.txt,$(wildcard lang/*.txt))
LANGS = $(LANG_TXT:%.txt=%.lng)
C_COMPILE = $(CC) $(CFLAGS) $(CDEFS)
CXX_COMPILE = $(CXX) $(CFLAGS) $(CDEFS)
C_BUILD = $(C_COMPILE) -c
CXX_BUILD = $(CXX_COMPILE) -c
C_LINK = $(CC) $(LDFLAGS) -o
##############################################################################
#
# Targets
#
### Normal build rules
ifdef OSX
OSX:=OSX
endif
all: endian.h $(UPDATECONFIG) $(TTD) $(OSX) $(endwarnings)
endian.h: $(ENDIAN_CHECK)
@# Check if system is LITTLE_ENDIAN or BIG_ENDIAN
@echo 'Running endian_check'; \
./$(ENDIAN_CHECK) > $@
$(ENDIAN_CHECK): endian_check.c
@echo 'Compiling and Linking $@'; \
$(CC) $(BASECFLAGS) $(CDEFS) endian_check.c -o $@
$(TTD): table/strings.h $(ttd_OBJS) $(LANGS) $(MAKE_CONFIG)
@echo 'Compiling and Linking $@'; \
$(C_LINK) $@ $(TTDLDFLAGS) $(ttd_OBJS) $(LIBS) $(VERBOSE_FILTER)
$(OSX):
@mkdir -p $(OSXAPP)/Contents/MacOS
@mkdir -p $(OSXAPP)/Contents/Resources
@echo "APPL????" > $(OSXAPP)/Contents/PkgInfo
@cp os/macos/ttd.icns $(OSXAPP)/Contents/Resources/openttd.icns
@os/macos/plistgen.sh $(OSXAPP) $(REV)
@cp os/macos/track_starter $(OSXAPP)/contents/macos
@ls os/macos | grep -q "\.class" || \
javac os/macos/OpenTTDMidi.java
@cp os/macos/OpenTTDMidi.class $(OSXAPP)/contents/macos
@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 rev.o
@echo 'Compiling and Linking $@'; \
$(CC) $(BASECFLAGS) $(CDEFS) -o $@ $^ $(VERBOSE_FILTER)
lang/english.lng: lang/english.txt $(STRGEN)
@echo 'Generating $@'; \
$(STRGEN)
table/strings.h: lang/english.lng
lang/%.lng: lang/%.txt $(STRGEN)
@echo 'Generating $@'; \
$(STRGEN) $(STRGEN_FLAGS) $< $(VERBOSE_FILTER) $(LANG_ERRORS)
winres.o: ttd.rc
windres -o $@ $<
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
@echo '#endif' >>rev.c.new
@# Only update the real rev.c if it actually changed, to prevent
@# useless rebuilds.
@cmp -s rev.c rev.c.new 2>/dev/null || mv rev.c.new rev.c
@rm -f rev.c.new
FORCE:
# ttd$(EXE) is removed just to make sure people execute the right binary (openttd$(EXE))
# remove this for next release!
clean:
@echo 'Cleaning up...'; \
rm -rf .deps *~ $(TTD) $(STRGEN) core table/strings.h $(LANGS) $(ttd_OBJS) endian.h $(ENDIAN_CHECK) ttd$(EXE)
mrproper: clean
rm -rf $(MAKE_CONFIG)
ifndef OSX
ifndef MORPHOS
install:
@if [ "$(INSTALL)" == "" ]; then $(error make install is highly experimental at his state and not\
tested very much - use at your own risk - to use run \"make install INSTALL:=1\" - make sure makefile.config\
is set correctly up - run \"make upgradeconf\")
@if [ "$(DATA_DIR)" == "" ]; then $(error no install path set - check makefile.config)
mkdir -p $(DATA_DIR)/lang
mkdir -p $(DATA_DIR)/data
cp $(TTD) $(BINARY_INSTALL)
cp lang/*.lng $(DATA_DIR)/lang
cp data/*.grf $(DATA_DIR)/data
else #MorphOS
install:
$(error make install is not supported on MorphOS)
endif
else # OSX
install:
$(error make install is not supported on MacOSX)
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 $(64_bit_warnings) $(endwarnings) love
### Automatic configuration
-include $(CONFIG_WRITER)
# Export all variables set to subprocesses (a bit dirty)
.EXPORT_ALL_VARIABLES:
upgradeconf: $(MAKE_CONFIG)
rm $(MAKE_CONFIG)
$(MAKE) $(MAKE_CONFIG)
.PHONY: upgradeconf
### Internal build rules
# This makes sure the .deps dir is always around.
DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
# Introduce the dependencies
-include $(ttd_DEPS)
# 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.
#@echo '$(C_BUILD) $<'; \
%.o: %.c $(MAKE_CONFIG)
@echo 'Compiling $(*F).o'; \
$(C_BUILD) $< -Wp,-MD,.deps/$(*F).pp $(VERBOSE_FILTER)
@-cp .deps/$(*F).pp .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm .deps/$(*F).pp
# For DirectMusic build
%.o: %.cpp $(MAKE_CONFIG)
$(CXX_BUILD) $<

View File

@@ -1,274 +0,0 @@
# Auto-generated file -- DO NOT EDIT
# Check if we want to show what we are doing
ifdef VERBOSE
Q =
else
Q = @
endif
include Makefile.am
SOURCE_LIST = !!SOURCE_LIST!!
CONFIG_CACHE_SOURCE_LIST = !!CONFIG_CACHE_SOURCE_LIST!!
CONFIGURE_FILES = !!CONFIGURE_FILES!!
LIPO = !!LIPO!!
BIN_DIR = !!BIN_DIR!!
SRC_DIR = !!SRC_DIR!!
ROOT_DIR = !!ROOT_DIR!!
BUNDLE_DIR = "$(ROOT_DIR)/bundle"
BUNDLES_DIR = "$(ROOT_DIR)/bundles"
INSTALL_DIR = !!INSTALL_DIR!!
INSTALL_BINARY_DIR = "$(INSTALL_DIR)/"!!BINARY_DIR!!
INSTALL_ICON_DIR = "$(INSTALL_DIR)/"!!ICON_DIR!!
INSTALL_DATA_DIR = "$(INSTALL_DIR)/"!!DATA_DIR!!
TTD = !!TTD!!
TTDS = $(SRC_DIRS:%=%/$(TTD))
OS = !!OS!!
OSXAPP = !!OSXAPP!!
REVISION = !!REVISION!!
AWK = !!AWK!!
DISTCC = !!DISTCC!!
RES := $(shell if ! [ -f $(CONFIG_CACHE_SOURCE_LIST) ] || [ -n "`cmp $(CONFIG_CACHE_SOURCE_LIST) $(SOURCE_LIST)`" ]; then cp $(SOURCE_LIST) $(CONFIG_CACHE_SOURCE_LIST); fi )
all: config.cache
ifdef DISTCC
@if [ -z "`echo '$(MFLAGS)' | grep '\-j'`" ]; then echo; echo "WARNING: you enabled distcc support, but you don't seem to be using the -jN paramter"; echo; fi
endif
@for dir in $(DIRS); do \
$(MAKE) -C $$dir all; \
done
ifdef LIPO
# Lipo is an OSX thing. If it is defined, it means we are building for universal,
# and so we have have to combine the binaries into one big binary
# Remove the last binary made by the last compiled target
$(Q)rm -f $(BIN_DIR)/$(TTD)
# Make all the binaries into one
$(Q)$(LIPO) -create -output $(BIN_DIR)/$(TTD) $(TTDS)
endif
help:
@echo "Available make commands:"
@echo ""
@echo "Compilation:"
@echo " all compile the executable and the lang files"
@echo " lang compile the lang files only"
@echo "Clean up:"
@echo " clean remove the files generated during compilation"
@echo " mrproper remove the files generated during configuration and compilation"
@echo "Run after compilation:"
@echo " run execute openttd after the compilation"
@echo " run-gdb execute openttd in debug mode after the compilation"
@echo " run-prof execute openttd in profiling mode after the compilation"
@echo "Installation:"
@echo " install install the compiled files and the data-files after the compilation"
@echo " bundle create the base for an installation bundle"
@echo " bundle_zip create the zip installation bundle"
@echo " bundle_gzip create the gzip installation bundle"
@echo " bundle_bzip2 create the bzip2 installation bundle"
@echo " bundle_lha create the lha installation bundle"
@echo " bundle_dmg create the dmg installation bundle"
config.cache: $(CONFIG_CACHE_SOURCE_LIST) $(CONFIGURE_FILES)
ifeq ($(shell if test -f config.cache; then echo 1; fi), 1)
@echo "----------------"
@echo "The system detected that source.list or any configure file is altered."
@echo " Going to reconfigure with last known settings..."
@echo "----------------"
# Make sure we don't lock config.cache
@$(shell cat config.cache | sed 's/\\ /\\\\ /g') || exit 1
@echo "----------------"
@echo "Reconfig done. Now compiling..."
@echo "----------------"
else
@echo "----------------"
@echo "Have not found a configuration, please run configure first."
@echo "----------------"
@exit 1
endif
clean:
@for dir in $(DIRS); do \
$(MAKE) -C $$dir clean; \
done
$(Q)rm -rf $(BUNDLE_TARGET)
lang:
@for dir in $(LANG_DIRS); do \
$(MAKE) -C $$dir all; \
done
mrproper:
@for dir in $(DIRS); do \
$(MAKE) -C $$dir mrproper; \
rm -f $$dir/Makefile; \
done
$(Q)rm -rf objs
$(Q)rm -f Makefile Makefile.am
$(Q)rm -f $(CONFIG_CACHE_SOURCE_LIST) config.cache config.log
$(Q)rm -rf $(BUNDLE_DIR)
$(Q)rm -rf $(BUNDLES_DIR)
depend:
@for dir in $(SRC_DIRS); do \
$(MAKE) -C $$dir depend; \
done
run: all
$(Q)cd !!BIN_DIR!! && ./!!TTD!! $(OPENTTD_ARGS)
run-gdb: all
$(Q)cd !!BIN_DIR!! && gdb --ex run --args ./!!TTD!! $(OPENTTD_ARGS)
run-prof: all
$(Q)cd !!BIN_DIR!! && ./!!TTD!! $(OPENTTD_ARGS) && gprof !!TTD!! | less
%.o:
@for dir in $(SRC_DIRS); do \
$(MAKE) -C $$dir $(@:src/%=%); \
done
%.lng:
@for dir in $(LANG_DIRS); do \
$(MAKE) -C $$dir $@; \
done
#
# Creation of bundles
#
# The revision is needed for the bundle name and creating an OSX application bundle.
ifdef REVISION
REV := $(REVISION)
else
# Are we a SVN dir?
ifeq ($(shell if test -d $(SRC_DIR)/.svn; then echo 1; fi), 1)
# Find if the local source if modified
REV_MODIFIED := $(shell svnversion $(SRC_DIR) | sed -n 's/.*\(M\).*/\1/p' )
# Find the revision like: rXXXX-branch
REV := $(shell LC_ALL=C svn info $(SRC_DIR) | $(AWK) '/^URL:.*branches/ { split($$2, a, "/"); BRANCH="-"a[5] } /^Last Changed Rev:/ { REV="r"$$4"$(REV_MODIFIED)" } END { print REV BRANCH }')
endif
endif
# Make sure we have something in REV
ifeq ($(REV),)
REV := norev000
endif
ifndef BUNDLE_NAME
BUNDLE_NAME = OTTD-$(OS)-custom-$(REV)
endif
# An OSX application bundle needs the data files, lang files and openttd executable in a different location.
ifdef OSXAPP
DATA_DIR = $(BUNDLE_DIR)/$(OSXAPP)/Contents/Resources/data
LANG_DIR = $(BUNDLE_DIR)/$(OSXAPP)/Contents/Resources/lang
TTD_DIR = $(BUNDLE_DIR)/$(OSXAPP)/Contents/MacOS
else
DATA_DIR = $(BUNDLE_DIR)/data
LANG_DIR = $(BUNDLE_DIR)/lang
TTD_DIR = $(BUNDLE_DIR)
endif
bundle: all
@echo '[BUNDLE] Constructing bundle'
$(Q)rm -rf "${BUNDLE_DIR}"
$(Q)mkdir -p "${BUNDLE_DIR}"
$(Q)mkdir -p "$(BUNDLE_DIR)/docs"
$(Q)mkdir -p "$(BUNDLE_DIR)/scenario"
$(Q)mkdir -p "$(BUNDLE_DIR)/scenario/heightmap"
$(Q)mkdir -p "$(BUNDLE_DIR)/media"
$(Q)mkdir -p "$(TTD_DIR)"
$(Q)mkdir -p "$(DATA_DIR)"
$(Q)mkdir -p "$(LANG_DIR)"
ifdef OSXAPP
$(Q)mkdir -p "$(BUNDLE_DIR)/$(OSXAPP)/Contents/Resources"
$(Q)echo "APPL????" > "$(BUNDLE_DIR)/$(OSXAPP)/Contents/PkgInfo"
$(Q)cp "$(ROOT_DIR)/os/macosx/openttd.icns" "$(BUNDLE_DIR)/$(OSXAPP)/Contents/Resources/openttd.icns"
$(Q)$(ROOT_DIR)/os/macosx/plistgen.sh "${BUNDLE_DIR}/$(OSXAPP)" "$(REV)"
$(Q)cp "$(ROOT_DIR)/docs/OSX_install_instructions.txt" "$(BUNDLE_DIR)/docs/"
$(Q)cp "$(ROOT_DIR)/os/macosx/splash.png" "$(DATA_DIR)"
endif
$(Q)cp "$(BIN_DIR)/$(TTD)" "$(TTD_DIR)/"
$(Q)cp "$(BIN_DIR)/data/"*.grf "$(DATA_DIR)/"
$(Q)cp "$(BIN_DIR)/data/opntitle.dat" "$(DATA_DIR)/"
$(Q)cp "$(BIN_DIR)/lang/"*.lng "$(LANG_DIR)/"
$(Q)cp "$(ROOT_DIR)/readme.txt" "$(BUNDLE_DIR)/"
$(Q)cp "$(ROOT_DIR)/COPYING" "$(BUNDLE_DIR)/"
$(Q)cp "$(ROOT_DIR)/known-bugs.txt" "$(BUNDLE_DIR)/docs/"
$(Q)cp "$(ROOT_DIR)/docs/multiplayer.txt" "$(BUNDLE_DIR)/docs/"
$(Q)cp "$(ROOT_DIR)/docs/32bpp.txt" "$(BUNDLE_DIR)/docs/"
$(Q)cp "$(ROOT_DIR)/changelog.txt" "$(BUNDLE_DIR)/docs/"
$(Q)cp "$(ROOT_DIR)/media/openttd.64.png" "$(BUNDLE_DIR)/media/"
$(Q)cp "$(ROOT_DIR)/media/openttd.32.xpm" "$(BUNDLE_DIR)/media/"
$(Q)cp "$(ROOT_DIR)/media/openttd.32.bmp" "$(BUNDLE_DIR)/media/"
ifeq ($(shell if test -n "`ls -l \"$(BIN_DIR)/scenario/\"*.scn 2> /dev/null`"; then echo 1; fi), 1)
$(Q)cp "$(BIN_DIR)/scenario/"*.scn "$(BUNDLE_DIR)/scenario/"
endif
ifeq ($(shell if test -n "`ls -l \"$(BIN_DIR)/scenario/heightmaps/\"* 2>/dev/null`"; then echo 1; fi), 1)
$(Q)cp "$(BIN_DIR)/scenario/heightmaps/"* "$(BUNDLE_DIR)/scenario/heightmap/"
endif
ifeq ($(TTD), openttd.exe)
$(Q)unix2dos "$(BUNDLE_DIR)/docs/"* "$(BUNDLE_DIR)/readme.txt" "$(BUNDLE_DIR)/COPYING"
endif
### Packing the current bundle into several compressed file formats ###
#
# Zips & dmgs do not contain a root folder, i.e. they have files in the root of the zip/dmg.
# gzip, bzip2 and lha archives have a root folder, with the same name as the bundle.
#
# One can supply a custom name by adding BUNDLE_NAME:=<name> to the make command.
#
bundle_zip: bundle
@echo '[BUNDLE] Creating $(BUNDLE_NAME).zip'
$(Q)mkdir -p "$(BUNDLES_DIR)"
$(Q)cd "$(BUNDLE_DIR)" && zip -r $(shell if test -z "$(VERBOSE)"; then echo '-q'; fi) "$(BUNDLES_DIR)/$(BUNDLE_NAME).zip" .
bundle_gzip: bundle
@echo '[BUNDLE] Creating $(BUNDLE_NAME).tar.gz'
$(Q)mkdir -p "$(BUNDLES_DIR)/.gzip/$(BUNDLE_NAME)"
$(Q)cp -R "$(BUNDLE_DIR)/"* "$(BUNDLES_DIR)/.gzip/$(BUNDLE_NAME)/"
$(Q)cd "$(BUNDLES_DIR)/.gzip" && tar -zc$(shell if test -n "$(VERBOSE)"; then echo 'v'; fi)f "$(BUNDLES_DIR)/$(BUNDLE_NAME).tar.gz" "$(BUNDLE_NAME)"
$(Q)rm -rf "$(BUNDLES_DIR)/.gzip"
bundle_bzip2: bundle
@echo '[BUNDLE] Creating $(BUNDLE_NAME).tar.bz2'
$(Q)mkdir -p "$(BUNDLES_DIR)/.bzip2/$(BUNDLE_NAME)"
$(Q)cp -R "$(BUNDLE_DIR)/"* "$(BUNDLES_DIR)/.bzip2/$(BUNDLE_NAME)/"
$(Q)cd "$(BUNDLES_DIR)/.bzip2" && tar -jc$(shell if test -n "$(VERBOSE)"; then echo 'v'; fi)f "$(BUNDLES_DIR)/$(BUNDLE_NAME).tar.bz2" "$(BUNDLE_NAME)"
$(Q)rm -rf "$(BUNDLES_DIR)/.bzip2"
bundle_lha: bundle
@echo '[BUNDLE] Creating $(BUNDLE_NAME).lha'
$(Q)mkdir -p "$(BUNDLES_DIR)/.lha/$(BUNDLE_NAME)"
$(Q)cp -R "$(BUNDLE_DIR)/"* "$(BUNDLES_DIR)/.lha/$(BUNDLE_NAME)/"
$(Q)cd "$(BUNDLES_DIR)/.lha" && lha ao6 "$(BUNDLES_DIR)/$(BUNDLE_NAME).lha" "$(BUNDLE_NAME)"
$(Q)rm -rf "$(BUNDLES_DIR)/.lha"
bundle_dmg: bundle
@echo '[BUNDLE] Creating $(BUNDLE_NAME).dmg'
$(Q)mkdir -p "$(BUNDLES_DIR)/OpenTTD $(REV)"
$(Q)cp -R "$(BUNDLE_DIR)/" "$(BUNDLES_DIR)/OpenTTD $(REV)"
$(Q)hdiutil create -ov -format UDZO -srcfolder "$(BUNDLES_DIR)/OpenTTD $(REV)" "$(BUNDLES_DIR)/$(BUNDLE_NAME).dmg"
$(Q)rm -fr "$(BUNDLES_DIR)/OpenTTD $(REV)"
ifdef OSXAPP
install:
@echo '[INSTALL] Cannot install the OSX Application Bundle'
else
install: bundle
@echo '[INSTALL] Installing OpenTTD'
$(Q)install -d "$(INSTALL_BINARY_DIR)"
$(Q)install -d "$(INSTALL_ICON_DIR)"
$(Q)install -d "$(INSTALL_DATA_DIR)/gm"
$(Q)install -d "$(INSTALL_DATA_DIR)/data"
$(Q)install -d "$(INSTALL_DATA_DIR)/lang"
$(Q)install -d "$(INSTALL_DATA_DIR)/docs"
$(Q)install -m 755 "$(BUNDLE_DIR)/$(TTD)" "$(INSTALL_BINARY_DIR)"
$(Q)install -m 644 "$(BUNDLE_DIR)/lang/"* "$(INSTALL_DATA_DIR)/lang"
$(Q)install -m 644 "$(BUNDLE_DIR)/data/"* "$(INSTALL_DATA_DIR)/data"
$(Q)install -m 644 "$(BUNDLE_DIR)/docs/"* "$(INSTALL_DATA_DIR)/docs"
$(Q)install -m 644 "$(BUNDLE_DIR)/media/"* "$(INSTALL_ICON_DIR)"
$(Q)cp -R "$(BUNDLE_DIR)/scenario" "$(INSTALL_DATA_DIR)"
endif # OSXAPP

View File

@@ -1,89 +0,0 @@
# Auto-generated file -- DO NOT EDIT
STRGEN = !!STRGEN!!
ENDIAN_CHECK = !!ENDIAN_CHECK!!
SRC_DIR = !!SRC_DIR!!
LANG_DIR = !!LANG_DIR!!
BIN_DIR = !!BIN_DIR!!
LANGS_SRC = $(shell ls $(LANG_DIR)/*.txt)
LANGS = $(LANGS_SRC:$(LANG_DIR)/%.txt=%.lng)
CXX_BUILD = !!CXX_BUILD!!
CFLAGS_BUILD = !!CFLAGS_BUILD!!
STRGEN_FLAGS = !!STRGEN_FLAGS!!
STAGE = !!STAGE!!
LANG_SUPPRESS= !!LANG_SUPPRESS!!
LANG_OBJS_DIR= !!LANG_OBJS_DIR!!
ifeq ($(LANG_SUPPRESS), yes)
LANG_ERRORS = >/dev/null 2>&1
endif
# Make sure endian_host.h is reasable as if it was in the src/ dir
CFLAGS_BUILD += -I $(LANG_OBJS_DIR)
ENDIAN_TARGETS := endian_host.h endian_target.h $(ENDIAN_CHECK)
# Check if we want to show what we are doing
ifdef VERBOSE
Q =
E = @true
else
Q = @
E = @echo
endif
RES := $(shell mkdir -p $(BIN_DIR)/lang )
all: table/strings.h $(LANGS)
strgen.o: $(SRC_DIR)/strgen/strgen.cpp endian_host.h $(SRC_DIR)/table/control_codes.h
$(E) '$(STAGE) Compiling $(<:$(SRC_DIR)/%.cpp=%.cpp)'
$(Q)$(CXX_BUILD) $(CFLAGS_BUILD) -DSTRGEN -c -o $@ $<
string.o: $(SRC_DIR)/string.cpp endian_host.h
$(E) '$(STAGE) Compiling $(<:$(SRC_DIR)/%.cpp=%.cpp)'
$(Q)$(CXX_BUILD) $(CFLAGS_BUILD) -DSTRGEN -c -o $@ $<
alloc_func.o: $(SRC_DIR)/core/alloc_func.cpp endian_host.h
$(E) '$(STAGE) Compiling $(<:$(SRC_DIR)/%.cpp=%.cpp)'
$(Q)$(CXX_BUILD) $(CFLAGS_BUILD) -DSTRGEN -c -o $@ $<
lang/english.txt: $(LANG_DIR)/english.txt
$(Q)mkdir -p lang
$(Q)cp $(LANG_DIR)/english.txt lang/english.txt
$(STRGEN): alloc_func.o string.o strgen.o
$(E) '$(STAGE) Compiling and Linking $@'
$(Q)$(CXX_BUILD) $^ -o $@
table/strings.h: lang/english.txt $(STRGEN)
$(E) '$(STAGE) Generating $@'
@mkdir -p table
$(Q)./$(STRGEN) -s $(LANG_DIR) -d table
$(LANGS): %.lng: $(LANG_DIR)/%.txt $(STRGEN) lang/english.txt
$(E) '$(STAGE) Compiling language $(*F)'
$(Q)./$(STRGEN) $(STRGEN_FLAGS) -s $(LANG_DIR) -d $(LANG_OBJS_DIR) $< $(LANG_ERRORS) && cp $@ $(BIN_DIR)/lang || true # Do not fail all languages when one fails
# The targets to compile the endian-code
endian_host.h: $(ENDIAN_CHECK)
$(E) '$(STAGE) Testing endianness for host'
$(Q)./$(ENDIAN_CHECK) > $@
$(ENDIAN_CHECK): $(SRC_DIR)/endian_check.cpp
$(E) '$(STAGE) Compiling and Linking $@'
$(Q)$(CXX_BUILD) $(CFLAGS_BUILD) $< -o $@
depend:
clean:
$(E) '$(STAGE) Cleaning up language files'
$(Q)rm -f strgen.o string.o table/strings.h $(STRGEN) $(LANGS) $(LANGS:%=$(BIN_DIR)/lang/%) lang/english.* $(ENDIAN_TARGETS)
mrproper: clean
%.lng:
@echo '$(STAGE) No such language: $(@:%.lng=%)'
.PHONY: all mrproper depend clean

View File

@@ -1,309 +0,0 @@
# Auto-generated file -- DO NOT EDIT
CC_HOST = !!CC_HOST!!
CXX_HOST = !!CXX_HOST!!
CC_BUILD = !!CC_BUILD!!
CXX_BUILD = !!CXX_BUILD!!
WINDRES = !!WINDRES!!
STRIP = !!STRIP!!
CC_CFLAGS = !!CC_CFLAGS!!
CFLAGS = !!CFLAGS!!
CFLAGS_BUILD = !!CFLAGS_BUILD!!
LIBS = !!LIBS!!
LDFLAGS = !!LDFLAGS!!
BIN_DIR = !!BIN_DIR!!
LANG_DIR = !!LANG_DIR!!
SRC_OBJS_DIR = !!SRC_OBJS_DIR!!
LANG_OBJS_DIR= !!LANG_OBJS_DIR!!
SRC_DIR = !!SRC_DIR!!
MEDIA_DIR = !!MEDIA_DIR!!
TTD = !!TTD!!
STRGEN = !!STRGEN!!
ENDIAN_CHECK = !!ENDIAN_CHECK!!
ENDIAN_FORCE = !!ENDIAN_FORCE!!
OS = !!OS!!
STAGE = !!STAGE!!
MAKEDEPEND = !!MAKEDEPEND!!
CFLAGS_MAKEDEP= !!CFLAGS_MAKEDEP!!
SORT = !!SORT!!
REVISION = !!REVISION!!
AWK = !!AWK!!
GCC295 = !!GCC295!!
CONFIG_CACHE_COMPILER = $(SRC_OBJS_DIR)/!!CONFIG_CACHE_COMPILER!!
CONFIG_CACHE_LINKER = $(SRC_OBJS_DIR)/!!CONFIG_CACHE_LINKER!!
CONFIG_CACHE_ENDIAN = $(SRC_OBJS_DIR)/!!CONFIG_CACHE_ENDIAN!!
CONFIG_CACHE_SOURCE = $(SRC_OBJS_DIR)/!!CONFIG_CACHE_SOURCE!!
CONFIG_CACHE_VERSION = $(SRC_OBJS_DIR)/!!CONFIG_CACHE_VERSION!!
OBJS_C := !!OBJS_C!!
OBJS_CPP := !!OBJS_CPP!!
OBJS_MM := !!OBJS_MM!!
OBJS_RC := !!OBJS_RC!!
OBJS := $(OBJS_C) $(OBJS_CPP) $(OBJS_MM) $(OBJS_RC)
SRCS := !!SRCS!!
# All C-files depend on those 3 files
FILE_DEP := $(CONFIG_CACHE_COMPILER) $(LANG_OBJS_DIR)/table/strings.h endian_target.h
# Create all dirs and subdirs
RES := $(shell mkdir -p $(BIN_DIR) $(sort $(dir $(OBJS))))
# Make sure endian_target.h is reasable as if it was in the src/ dir
CFLAGS += -I $(SRC_OBJS_DIR) -I $(LANG_OBJS_DIR)
ENDIAN_TARGETS := endian_target.h $(ENDIAN_CHECK)
# This 'sed' basicly just removes 'const' from the line if it is a 2+D array
# For more information, please check:
# http://maillist.openttd.org/pipermail/devs/2007-April/000284.html
# http://maillist.openttd.org/pipermail/devs/2007-February/000248.html
GCC295_FIX=sed -r 's/^(\t*)(.*)( const )([A-Za-z0-9_ ]+(\[.*\]){2,})(( = \{)|(;))(.*)$$/\1\2 \4\6\8\9/g'
# This 'sed' removes the 3rd '4' in the # lines of the -E output of
# gcc 2.95.3 and lower, as it should indicate that it is a C-linkage, but the
# compiler can't handle that information (just don't ask). So we remove it
# and then it compiles happily and without bitching :)
# Furthermore gcc 2.95 has some trouble with protected and private when
# accessing the protected/private stuff of the enclosing class (or the
# super class of the enclosing class).
GCC295_FIX_2=sed -e 's|\(^\# [0-9][0-9]* "[^"]*"[ 0-9]*\) 4$$|\1|g;s|private:|public:|g;s|protected:|public:|g'
# Check if we want to show what we are doing
ifdef VERBOSE
Q =
E = @true
else
Q = @
E = @echo
endif
# Our default target
all: $(BIN_DIR)/$(TTD)
# This are 2 rules that are pointing back to STRGEN stuff.
# There is not really a need to have them here, but in case
# some weirdo wants to run 'make' in the 'src' dir and expects
# the languages to be recompiled, this catches that case and
# takes care of it nicely.
$(LANG_OBJS_DIR)/$(STRGEN):
$(MAKE) -C $(LANG_OBJS_DIR) $(STRGEN)
$(LANG_OBJS_DIR)/table/strings.h: $(LANG_DIR)/english.txt $(LANG_OBJS_DIR)/$(STRGEN)
$(MAKE) -C $(LANG_OBJS_DIR) table/strings.h
# Make the revision number
ifdef REVISION
REV := $(REVISION)
REV_NR := $(shell echo $(REVISION) | sed "s/[^0-9]//g")
else
# Are we a SVN dir?
ifeq ($(shell if test -d $(SRC_DIR)/.svn; then echo 1; fi), 1)
# Find if the local source if modified
REV_MODIFIED := $(shell svnversion $(SRC_DIR) | sed -n 's/.*\(M\).*/\1/p' )
# Find the revision like: rXXXX-branch
REV := $(shell LC_ALL=C svn info $(SRC_DIR) | $(AWK) '/^URL:.*branch/ { split($$2, a, "/"); BRANCH="-"a[5] } /^Last Changed Rev:/ { REV="r"$$4"$(REV_MODIFIED)" } END { print REV BRANCH }')
REV_NR := $(shell LC_ALL=C svn info $(SRC_DIR) | $(AWK) '/^Last Changed Rev:/ { print $$4 }')
else
# Are we a git dir?
ifeq ($(shell if test -d $(SRC_DIR)/../.git; then echo 1; fi), 1)
# Find the revision like: gXXXXM-branch
REV := g$(shell if head=`LC_ALL=C git rev-parse --verify HEAD 2>/dev/null`; then echo "$$head" | cut -c1-8; fi)$(shell if cd "$(SRC_DIR)/.." && git diff-index HEAD src | read dummy; then echo M; fi)$(shell git branch|grep '[*]' | sed 's/\* /-/;s/^-master$$//')
REV_NR := $(shell LC_ALL=C cd "$(SRC_DIR)/.." && git log --pretty=format:%s src | grep -m 1 "^(svn r[0-9]*)" | sed "s/.*(svn r\([0-9]*\)).*/\1/" )
else
# Are we a hg (Mercurial) dir?
ifeq ($(shell if test -d $(SRC_DIR)/../.hg; then echo 1; fi), 1)
# Find the revision like: hXXXXM-branch
REV := h$(shell if head=`LC_ALL=C hg tip 2>/dev/null`; then echo "$$head" | head -n 1 | cut -c19-26; fi)$(shell if hg status $(SRC_DIR) | grep -v '^?' | read dummy; then echo M; fi)$(shell hg branch | sed 's/^/-/;s/^-default$$//')
REV_NR := $(shell LC_ALL=C hg log -k "svn" -l 1 --template "{desc}\n" $(SRC_DIR) | grep -m 1 "^(svn r[0-9]*)" | sed "s/.*(svn r\([0-9]*\)).*/\1/" )
endif
endif
endif
endif
# Make sure we have something in REV
ifeq ($(REV),)
REV := norev000
REV_NR := 0
endif
# This helps to recompile if flags change
RES := $(shell if [ "`cat $(CONFIG_CACHE_COMPILER) 2>/dev/null`" != "$(CC_CFLAGS) $(CFLAGS)" ]; then echo "$(CC_CFLAGS) $(CFLAGS)" > $(CONFIG_CACHE_COMPILER); fi )
RES := $(shell if [ "`cat $(CONFIG_CACHE_LINKER) 2>/dev/null`" != "$(LDFLAGS) $(LIBS)" ]; then echo "$(LDFLAGS) $(LIBS)" > $(CONFIG_CACHE_LINKER); fi )
RES := $(shell if [ "`cat $(CONFIG_CACHE_ENDIAN) 2>/dev/null`" != "$(ENDIAN_FORCE)" ]; then echo "$(ENDIAN_FORCE)" > $(CONFIG_CACHE_ENDIAN); fi )
# If there is a change in the source-file-list, make sure we recheck the deps
RES := $(shell if [ "`cat $(CONFIG_CACHE_SOURCE) 2>/dev/null`" != "$(SRCS)" ]; then echo "$(SRCS)" > $(CONFIG_CACHE_SOURCE); fi )
# If there is a change in the revision, make sure we recompile rev.cpp
RES := $(shell if [ "`cat $(CONFIG_CACHE_VERSION) 2>/dev/null`" != "$(REV)" ]; then echo "$(REV)" > $(CONFIG_CACHE_VERSION); fi )
ifndef MAKEDEPEND
# The slow, but always correct, dep-check
DEP_MASK := %.d
DEPS := $(OBJS:%.o=%.d)
# Only include the deps if we are compiling everything
ifeq ($(filter $(ENDIAN_TARGETS) %.o clean mrproper, $(MAKECMDGOALS)),)
-include $(DEPS)
else
# In case we want to compile a single target, include the .d file for it
ifneq ($(filter %.o, $(MAKECMDGOALS)),)
SINGLE_DEP := $(filter %.o, $(MAKECMDGOALS))
-include $(SINGLE_DEP:%.o=%.d)
endif
endif
# Find the deps via GCC. Rarely wrong, but a bit slow
$(OBJS_C:%.o=%.d): %.d: $(SRC_DIR)/%.c $(FILE_DEP)
$(E) '$(STAGE) DEP $(<:$(SRC_DIR)/%.c=%.c)'
$(Q)$(CC_HOST) $(CC_CFLAGS) $(CFLAGS) -MM $< | sed 's#^$(@F:%.d=%.o):#$@ $(@:%.d=%.o):#' > $@
$(OBJS_CPP:%.o=%.d): %.d: $(SRC_DIR)/%.cpp $(FILE_DEP)
$(E) '$(STAGE) DEP $(<:$(SRC_DIR)/%.cpp=%.cpp)'
$(Q)$(CXX_HOST) $(CFLAGS) -MM $< | sed 's#^$(@F:%.d=%.o):#$@ $(@:%.d=%.o):#' > $@
$(OBJS_MM:%.o=%.d): %.d: $(SRC_DIR)/%.mm $(FILE_DEP)
$(E) '$(STAGE) DEP $(<:$(SRC_DIR)/%.mm=%.mm)'
$(Q)$(CC_HOST) $(CFLAGS) -MM $< | sed 's#^$(@F:%.d=%.o):#$@ $(@:%.d=%.o):#' > $@
$(OBJS_RC:%.o=%.d): %.d: $(SRC_DIR)/%.rc $(FILE_DEP)
$(E) '$(STAGE) DEP $(<:$(SRC_DIR)/%.mm=%.mm)'
$(Q)touch $@
else
# The much faster, but can be wrong, dep-check
DEP_MASK :=
DEPS := Makefile.dep
# Only include the deps if we are not cleaning
ifeq ($(filter $(ENDIAN_TARGETS) depend clean mrproper, $(MAKECMDGOALS)),)
-include Makefile.dep
endif
# Make sure that only 'make depend' ALWAYS triggers a recheck
ifeq ($(filter depend, $(MAKECMDGOALS)),)
Makefile.dep: $(FILE_DEP) $(SRCS:%=$(SRC_DIR)/%) $(CONFIG_CACHE_SOURCE)
else
Makefile.dep: FORCE
endif
$(E) '$(STAGE) DEP CHECK (all files)'
$(Q)rm -f Makefile.dep.tmp
$(Q)touch Makefile.dep.tmp
# Calculate the deps via makedepend
$(Q)$(MAKEDEPEND) -f$(SRC_OBJS_DIR)/Makefile.dep.tmp -o.o -Y -v -- $(CFLAGS_MAKEDEP) -- $(SRCS:%=$(SRC_DIR)/%) 2>/dev/null
# Convert x:/... paths to /x/... for mingw
ifeq ($(OS), MINGW)
@cat Makefile.dep.tmp | sed 's@\([a-zA-Z]\):\/@\/\1\/@g' > Makefile.dep.tmp.mingw
@cp Makefile.dep.tmp.mingw Makefile.dep.tmp
@rm -f Makefile.dep.tmp.mingw
endif
# Remove all comments and includes that don't start with $(SRC_DIR)
# Remove $(SRC_DIR) from object-file-name
@$(AWK) ' \
/^# DO NOT/ { print $$0 ; next} \
/^#/ {next} \
/:/ { \
left = NF - 1; \
for (n = 2; n <= NF; n++) { \
if (match($$n, "^$(SRC_DIR)") == 0) { \
$$n = ""; \
left--; \
} \
} \
gsub("$(SRC_DIR)/", "", $$1); \
if (left > 0) { \
print $$0; \
$$1 = "Makefile.dep:"; \
print $$0; \
} \
next \
} \
{ \
print $$0 \
} \
' < Makefile.dep.tmp | sed 's/ */ /g;s/ $$//' | $(SORT) > Makefile.dep
$(Q)rm -f Makefile.dep.tmp Makefile.dep.tmp.bak
endif
# Avoid problems with deps if a .h/.hpp file is deleted without the deps
# being updated. Now the Makefile continues, the deps are recreated
# and all will be fine.
%.h %.hpp:
@true
# Compile all the files according to the targets
$(OBJS_C): %.o: $(SRC_DIR)/%.c $(DEP_MASK) $(FILE_DEP)
$(E) '$(STAGE) Compiling $(<:$(SRC_DIR)/%.c=%.c)'
$(Q)$(CC_HOST) $(CC_CFLAGS) $(CFLAGS) -c -o $@ $<
$(OBJS_CPP): %.o: $(SRC_DIR)/%.cpp $(DEP_MASK) $(FILE_DEP)
$(E) '$(STAGE) Compiling $(<:$(SRC_DIR)/%.cpp=%.cpp)'
ifeq ($(GCC295), 1)
$(Q)$(CXX_HOST) -E $(CFLAGS) $< | $(GCC295_FIX) | $(GCC295_FIX_2) | $(CXX_HOST) $(CFLAGS) -c -o $@ -x c++ -
else
$(Q)$(CXX_HOST) $(CFLAGS) -c -o $@ $<
endif
$(OBJS_MM): %.o: $(SRC_DIR)/%.mm $(DEP_MASK) $(FILE_DEP)
$(E) '$(STAGE) Compiling $(<:$(SRC_DIR)/%.mm=%.mm)'
$(Q)$(CC_HOST) $(CFLAGS) -c -o $@ $<
$(OBJS_RC): %.o: $(SRC_DIR)/%.rc $(FILE_DEP)
$(E) '$(STAGE) Compiling resource $(<:$(SRC_DIR)/%.rc=%.rc)'
$(Q)$(WINDRES) -o $@ -I $(MEDIA_DIR) $<
$(BIN_DIR)/$(TTD): $(TTD)
$(Q)cp $< $@
$(TTD): $(OBJS) $(CONFIG_CACHE_LINKER)
$(E) '$(STAGE) Linking $@'
ifeq ($(OS), PSP)
# Because of a bug in the PSP GCC tools, linking via CXX results
# in total chaos and more problems then you can handle. So we need
# CC to link OpenTTD for PSP
$(Q)$(CC_HOST) $(LDFLAGS) $(OBJS) $(LIBS) -o $@
else
$(Q)$(CXX_HOST) $(LDFLAGS) $(OBJS) $(LIBS) -o $@
endif
ifdef STRIP
$(Q)$(STRIP) $@
endif
# The targets to compile the endian-code
endian_target.h: $(ENDIAN_CHECK) $(CONFIG_CACHE_ENDIAN)
$(E) '$(STAGE) Testing endianness for target'
$(Q)./$(ENDIAN_CHECK) $(ENDIAN_FORCE) > $@
$(ENDIAN_CHECK): $(SRC_DIR)/endian_check.cpp
$(E) '$(STAGE) Compiling and Linking $@'
$(Q)$(CXX_BUILD) $(CFLAGS_BUILD) $< -o $@
# Revision files
$(SRC_DIR)/rev.cpp: $(CONFIG_CACHE_VERSION) $(SRC_DIR)/rev.cpp.in
$(Q)cat $(SRC_DIR)/rev.cpp.in | sed "s#@@REVISION@@#$(REV_NR)#g;s#@@VERSION@@#$(REV)#g;s#@@DATE@@#`date +%d.%m.%y`#g" > $(SRC_DIR)/rev.cpp
$(SRC_DIR)/ottdres.rc: $(CONFIG_CACHE_VERSION) $(SRC_DIR)/ottdres.rc.in
$(Q)cat $(SRC_DIR)/ottdres.rc.in | sed "s#@@REVISION@@#$(REV_NR)#g;s#@@VERSION@@#$(REV)#g;s#@@DATE@@#`date +%d.%m.%y`#g" > $(SRC_DIR)/ottdres.rc
FORCE:
depend: $(DEPS)
clean:
$(E) '$(STAGE) Cleaning up object files'
$(Q)rm -f $(DEPS) $(OBJS) $(TTD) $(TTD:%=$(BIN_DIR)/%) $(CONFIG_CACHE_COMPILER) $(CONFIG_CACHE_LINKER) $(CONFIG_CACHE_ENDIAN) $(CONFIG_CACHE_SOURCE) $(ENDIAN_TARGETS)
mrproper: clean
$(Q)rm -f $(SRC_DIR)/rev.cpp $(SRC_DIR)/ottdres.rc
%.o:
@echo '$(STAGE) No such source-file: $(@:%.o=%).[c|cpp|mm|rc]'
.PHONY: all mrproper depend clean FORCE

8
StdAfx.c Normal file
View File

@@ -0,0 +1,8 @@
// 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
#include "stdafx.h"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file

3961
ai.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,12 +1,7 @@
/* $Id$ */
#ifndef AI_H
#define AI_H
#ifndef AI_TROLLY_H
#define AI_TROLLY_H
#include "../../aystar.h"
#include "../../player_type.h"
#include "../../vehicle_type.h"
#include "../../date_type.h"
#include "aystar.h"
/*
* These defines can be altered to change the behavoir of the AI
@@ -42,8 +37,6 @@
#define AI_PATHFINDER_PENALTY 150
// The penalty given to a tile that is going up
#define AI_PATHFINDER_TILE_GOES_UP_PENALTY 450
// The penalty given to a tile which would have to use fundation
#define AI_PATHFINDER_FOUNDATION_PENALTY 100
// Changing direction is a penalty, to prevent curved ways (with that: slow ways)
#define AI_PATHFINDER_DIRECTION_CHANGE_PENALTY 200
// Same penalty, only for when road already exists
@@ -78,7 +71,7 @@
#define AI_LOCATE_ROUTE_MAX_COUNTER 200
// How many days must there be between building the first station and the second station
// within one city. This number is in days and should be more than 4 months.
// within one city. This number is in days and should be more then 4 months.
#define AI_CHECKCITY_DATE_BETWEEN 180
// How many cargo is needed for one station in a city?
@@ -137,7 +130,7 @@
// reuse the station instead of building a new one!
#define AI_STATION_REUSE_MULTIPLER 2
// No more than this amount of vehicles per station..
// No more then this amount of vehicles per station..
#define AI_CHECK_MAX_VEHICLE_PER_STATION 10
// How many thick between building 2 vehicles
@@ -156,7 +149,7 @@
// while old vehicles stay longer, because we do get less in return.
#define AI_MINIMUM_ROUTE_PROFIT 1000
// A vehicle is considered lost when he his cargo is more than 180 days old
// A vehicle is considered lost when he his cargo is more then 180 days old
#define AI_VEHICLE_LOST_DAYS 180
// How many times may the AI try to find a route before it gives up
@@ -168,34 +161,40 @@
// 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
};
static const TileIndexDiff _tiles_around[4] = {
TILE_XY(-1,0),
TILE_XY(0,1),
TILE_XY(1,0),
TILE_XY(0,-1),
};
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)
@@ -215,7 +214,7 @@ enum {
// Used for from_type/to_type
enum {
AI_NO_TYPE = 0,
AI_NO_TYPE = 0,
AI_CITY,
AI_INDUSTRY,
};
@@ -228,7 +227,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(TILE_X_MAX, TILE_Y_MAX)
#define AI_PATHFINDER_NO_DIRECTION (byte)-1
@@ -236,105 +235,37 @@ enum {
#define AI_PATHFINDER_FLAG_BRIDGE 1
#define AI_PATHFINDER_FLAG_TUNNEL 2
// A macro for mp_street, where 0x20 is depot
// mp_tunnelbridge, where 0xf0 is a bridge, and 0x4/0x2 means: roadtunnel/bridge
#define AI_PATHFINDER_IS_ROAD(tile) ((IS_TILETYPE(tile, MP_STREET) && !(_map5[tile] & 0x20)) || \
(IS_TILETYPE(tile, MP_TUNNELBRIDGE) && \
(((_map5[tile] & 0x80) == 0 && (_map5[tile] & 0x4) == 0x4) || \
((_map5[tile] & 0x80) != 0 && (_map5[tile] & 0x2) == 0x2))))
typedef void AiNew_StateFunction(Player *p);
// ai_new.c
void AiNewDoGameLoop(Player *p);
struct Ai_PathFinderInfo {
TileIndex start_tile_tl; ///< tl = top-left
TileIndex start_tile_br; ///< br = bottom-right
TileIndex end_tile_tl; ///< tl = top-left
TileIndex end_tile_br; ///< br = bottom-right
DiagDirection start_direction; ///< 0 to 3 or AI_PATHFINDER_NO_DIRECTION
DiagDirection end_direction; ///< 0 to 3 or AI_PATHFINDER_NO_DIRECTION
TileIndex route[500];
byte route_extra[500]; ///< Some extra information about the route like bridge/tunnel
int route_length;
int position; ///< Current position in the build-path, needed to build the path
bool rail_or_road; ///< true = rail, false = road
};
// ai_pathfinder.c
AyStar *new_AyStar_AiPathFinder(int max_tiles_around, Ai_PathFinderInfo *PathFinderInfo);
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);
DiagDirection 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);
CommandCost AiNew_Build_Station(Player *p, byte type, TileIndex tile, byte length, byte numtracks, byte direction, byte flag);
CommandCost AiNew_Build_Bridge(Player *p, TileIndex tile_a, TileIndex tile_b, byte flag);
CommandCost AiNew_Build_RoutePart(Player *p, Ai_PathFinderInfo *PathFinderInfo, byte flag);
EngineID AiNew_PickVehicle(Player *p);
CommandCost AiNew_Build_Vehicle(Player *p, TileIndex tile, byte flag);
CommandCost AiNew_Build_Depot(Player* p, TileIndex tile, DiagDirection direction, 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, uint tile, byte flag);
int AiNew_Build_Depot(Player *p, uint tile, byte direction, byte flag);
/* The amount of memory reserved for the AI-special-vehicles */
#define AI_MAX_SPECIAL_VEHICLES 100
struct Ai_SpecialVehicle {
VehicleID veh_id;
uint32 flag;
};
struct PlayerAiNew {
uint8 state;
uint tick;
uint idle;
int temp; ///< A value used in more than one function, but it just temporary
///< The use is pretty simple: with this we can 'think' about stuff
///< in more than one tick, and more than one AI. A static will not
///< do, because they are not saved. This way, the AI is almost human ;)
int counter; ///< For the same reason as temp, we have counter. It can count how
///< long we are trying something, and just abort if it takes too long
/* Pathfinder stuff */
Ai_PathFinderInfo path_info;
AyStar *pathfinder;
/* Route stuff */
CargoID cargo;
byte tbt; ///< train/bus/truck 0/1/2 AI_TRAIN/AI_BUS/AI_TRUCK
Money new_cost;
byte action;
int last_id; ///< here is stored the last id of the searched city/industry
Date last_vehiclecheck_date; // Used in CheckVehicle
Ai_SpecialVehicle special_vehicles[AI_MAX_SPECIAL_VEHICLES]; ///< Some vehicles have some special flags
TileIndex from_tile;
TileIndex to_tile;
DiagDirectionByte from_direction;
DiagDirectionByte to_direction;
bool from_deliver; ///< True if this is the station that GIVES cargo
bool to_deliver;
TileIndex depot_tile;
DiagDirectionByte depot_direction;
byte amount_veh; ///< How many vehicles we are going to build in this route
byte cur_veh; ///< How many vehicles did we bought?
VehicleID veh_id; ///< Used when bought a vehicle
VehicleID veh_main_id; ///< The ID of the first vehicle, for shared copy
int from_ic; ///< ic = industry/city. This is the ID of them
byte from_type; ///< AI_NO_TYPE/AI_CITY/AI_INDUSTRY
int to_ic;
byte to_type;
};
extern PlayerAiNew _players_ainew[MAX_PLAYERS];
#endif /* AI_TROLLY_H */
#endif

257
ai_build.c Normal file
View File

@@ -0,0 +1,257 @@
#include "stdafx.h"
#include "ttd.h"
#include "command.h"
#include "ai.h"
#include "engine.h"
// Build HQ
// Params:
// tile : tile where HQ is going to be build
bool AiNew_Build_CompanyHQ(Player *p, uint tile) {
if (DoCommandByTile(tile, 0, 0, DC_AUTO | DC_NO_WATER, CMD_BUILD_COMPANY_HQ) == CMD_ERROR)
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);
else if (type == AI_BUS)
return DoCommandByTile(tile, direction, 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_BUS_STATION);
else
return DoCommandByTile(tile, direction, 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_TRUCK_STATION);
}
// 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);
else
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 (cost == CMD_ERROR) {
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 (cost == CMD_ERROR) {
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 (res == CMD_ERROR) {
// 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 (cost == CMD_ERROR) {
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 (cost == CMD_ERROR) {
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 (!IS_TILETYPE(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 (res == CMD_ERROR && flag == DC_EXEC && !IS_TILETYPE(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;
} else {
if (res != CMD_ERROR)
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, r = 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?
r = DoCommandByTile(0, i, 0, DC_QUERY_COST, CMD_BUILD_ROAD_VEH);
if (r != CMD_ERROR) break;
}
// We did not find a vehicle :(
if (r == CMD_ERROR) { 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;
} else {
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 r, r2;
if (p->ainew.tbt == AI_TRAIN) {
return DoCommandByTile(tile, 0, direction, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_TRAIN_DEPOT);
} else {
r = DoCommandByTile(tile, direction, 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD_DEPOT);
if (r == CMD_ERROR) return r;
// Try to build the road from the depot
r2 = DoCommandByTile(tile + _tileoffs_by_dir[direction], _roadbits_by_dir[direction], 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD);
// If it fails, ignore it..
if (r2 == CMD_ERROR) return r;
return r + r2;
}
}

1302
ai_new.c Normal file

File diff suppressed because it is too large Load Diff

457
ai_pathfinder.c Normal file
View File

@@ -0,0 +1,457 @@
#include "stdafx.h"
#include "ttd.h"
#include "command.h"
#include "ai.h"
#define TEST_STATION_NO_DIR 0xFF
// Tests if a station can be build on the given spot
// TODO: make it train compatible
bool TestCanBuildStationHere(uint tile, byte dir) {
Player *p = DEREF_PLAYER(_current_player);
if (dir == TEST_STATION_NO_DIR) {
// TODO: currently we only allow spots that can be access from al 4 directions...
// should be fixed!!!
for (dir=0;dir<4;dir++) {
int res = AiNew_Build_Station(p, p->ainew.tbt, tile, 1, 1, dir, DC_QUERY_COST);
if (res != CMD_ERROR)
return true;
}
return false;
} else {
int res = AiNew_Build_Station(p, p->ainew.tbt, tile, 1, 1, dir, DC_QUERY_COST);
if (res == CMD_ERROR)
return false;
}
return true;
}
// Checks if a tile 'a' is between the tiles 'b' and 'c'
#define TILES_BETWEEN(a,b,c) (GET_TILE_X(a) >= GET_TILE_X(b) && GET_TILE_X(a) <= GET_TILE_X(c) && GET_TILE_Y(a) >= GET_TILE_Y(b) && GET_TILE_Y(a) <= GET_TILE_Y(c))
// Check if the current tile is in our end-area
int32 AyStar_AiPathFinder_EndNodeCheck(AyStar *aystar, OpenListNode *current) {
Ai_PathFinderInfo *PathFinderInfo = (Ai_PathFinderInfo*)aystar->user_target;
// It is not allowed to have a station on the end of a bridge or tunnel ;)
if (current->path.node.user_data[0] != 0) return AYSTAR_DONE;
if (TILES_BETWEEN(current->path.node.tile, PathFinderInfo->end_tile_tl, PathFinderInfo->end_tile_br))
if (IS_TILETYPE(current->path.node.tile, MP_CLEAR) || IS_TILETYPE(current->path.node.tile, MP_TREES))
if (current->path.parent == NULL || TestCanBuildStationHere(current->path.node.tile,AiNew_GetDirection(current->path.parent->node.tile, current->path.node.tile)))
return AYSTAR_FOUND_END_NODE;
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)
uint AiPathFinder_Hash(uint key1, uint key2) {
return (GET_TILE_X(key1) & 0x1F) + ((GET_TILE_Y(key1) & 0x1F) << 5);
}
// Clear the memory of all the things
void AyStar_AiPathFinder_Free(AyStar *aystar) {
AyStarMain_Free(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) {
PathNode start_node;
uint x,y;
// Create AyStar
AyStar *result = malloc(sizeof(AyStar));
init_AyStar(result, AiPathFinder_Hash, 1 << 10);
// Set the function pointers
result->CalculateG = AyStar_AiPathFinder_CalculateG;
result->CalculateH = AyStar_AiPathFinder_CalculateH;
result->EndNodeCheck = AyStar_AiPathFinder_EndNodeCheck;
result->FoundEndNode = AyStar_AiPathFinder_FoundEndNode;
result->GetNeighbours = AyStar_AiPathFinder_GetNeighbours;
result->free = AyStar_AiPathFinder_Free;
// Set some information
result->loops_per_tick = AI_PATHFINDER_LOOPS_PER_TICK;
result->max_path_cost = 0;
result->max_search_nodes = AI_PATHFINDER_MAX_SEARCH_NODES;
// Set the user_data to the PathFinderInfo
result->user_target = PathFinderInfo;
// Set the start node
start_node.parent = NULL;
start_node.node.direction = 0;
start_node.node.user_data[0] = 0;
// Now we add all the starting tiles
for (x=GET_TILE_X(PathFinderInfo->start_tile_tl);x<=GET_TILE_X(PathFinderInfo->start_tile_br);x++) {
for (y=GET_TILE_Y(PathFinderInfo->start_tile_tl);y<=GET_TILE_Y(PathFinderInfo->start_tile_br);y++) {
start_node.node.tile = TILE_XY(x,y);
result->addstart(result, &start_node.node);
}
}
return result;
}
// To reuse AyStar we sometimes have to clean all the memory
void clean_AyStar_AiPathFinder(AyStar *aystar, Ai_PathFinderInfo *PathFinderInfo) {
PathNode start_node;
uint x,y;
aystar->clear(aystar);
// Set the user_data to the PathFinderInfo
aystar->user_target = PathFinderInfo;
// Set the start node
start_node.parent = NULL;
start_node.node.direction = 0;
start_node.node.user_data[0] = 0;
start_node.node.tile = PathFinderInfo->start_tile_tl;
// Now we add all the starting tiles
for (x=GET_TILE_X(PathFinderInfo->start_tile_tl);x<=GET_TILE_X(PathFinderInfo->start_tile_br);x++) {
for (y=GET_TILE_Y(PathFinderInfo->start_tile_tl);y<=GET_TILE_Y(PathFinderInfo->start_tile_br);y++) {
if (!(IS_TILETYPE(TILE_XY(x,y), MP_CLEAR) || IS_TILETYPE(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);
}
}
}
// The h-value, simple calculation
static int32 AyStar_AiPathFinder_CalculateH(AyStar *aystar, AyStarNode *current, OpenListNode *parent) {
Ai_PathFinderInfo *PathFinderInfo = (Ai_PathFinderInfo*)aystar->user_target;
int r, r2;
if (PathFinderInfo->end_direction != AI_PATHFINDER_NO_DIRECTION) {
// The station is pointing to a direction, add a tile towards that direction, so the H-value is more accurate
r = GetTileDist(current->tile, PathFinderInfo->end_tile_tl + _tiles_around[PathFinderInfo->end_direction]);
r2 = GetTileDist(current->tile, PathFinderInfo->end_tile_br + _tiles_around[PathFinderInfo->end_direction]);
} else {
// No direction, so just get the fastest route to the station
r = GetTileDist(current->tile, PathFinderInfo->end_tile_tl);
r2 = GetTileDist(current->tile, PathFinderInfo->end_tile_br);
}
// See if the bottomright is faster then the topleft..
if (r2 < r) r = r2;
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) {
Ai_PathFinderInfo *PathFinderInfo = (Ai_PathFinderInfo*)aystar->user_target;
int i = 0;
PathNode *parent = &current->path;
do {
PathFinderInfo->route_extra[i] = parent->node.user_data[0];
PathFinderInfo->route[i++] = parent->node.tile;
if (i > lengthof(PathFinderInfo->route)) {
// We ran out of space for the PathFinder
DEBUG(ai,0)("[AiPathFinder] Ran out of spacein the route[] array!!!");
PathFinderInfo->route_length = -1; // -1 indicates out of space
return;
}
parent = parent->parent;
} while (parent != NULL);
PathFinderInfo->route_length = i;
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) {
int i, r, dir;
Ai_PathFinderInfo *PathFinderInfo = (Ai_PathFinderInfo*)aystar->user_target;
aystar->num_neighbours = 0;
// Go through all surrounding tiles and check if they are within the limits
for (i=0;i<4;i++) {
if (GET_TILE_X(_tiles_around[i] + current->path.node.tile) > 1 && GET_TILE_X(_tiles_around[i] + current->path.node.tile) < TILE_X_MAX - 1 &&
GET_TILE_Y(_tiles_around[i] + current->path.node.tile) > 1 && GET_TILE_Y(_tiles_around[i] + current->path.node.tile) < TILE_Y_MAX - 1) {
// We also directly test if the current tile can connect to this tile..
// We do this simply by just building the tile!
// If the next step is a bridge, we have to enter it the right way
if (!PathFinderInfo->rail_or_road && AI_PATHFINDER_IS_ROAD(current->path.node.tile + _tiles_around[i])) {
if (IS_TILETYPE(current->path.node.tile + _tiles_around[i], MP_TUNNELBRIDGE)) {
// An existing bridge... let's test the direction ;)
if ((_map5[current->path.node.tile + _tiles_around[i]] & 1) != (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 (!IS_TILETYPE(current->path.node.tile, MP_TUNNELBRIDGE) && (_map5[current->path.node.tile + _tiles_around[i]] & 0x80) == 0) {
if (i != (_map5[current->path.node.tile + _tiles_around[i]] & 3)) continue;
}
}
}
// But also if we are on a bridge, we can only move a certain direction
if (!PathFinderInfo->rail_or_road && AI_PATHFINDER_IS_ROAD(current->path.node.tile)) {
if (IS_TILETYPE(current->path.node.tile, MP_TUNNELBRIDGE)) {
// An existing bridge/tunnel... let's test the direction ;)
if ((_map5[current->path.node.tile] & 1) != (i & 1)) continue;
}
}
if ((AI_PATHFINDER_FLAG_BRIDGE & current->path.node.user_data[0]) != 0 ||
(AI_PATHFINDER_FLAG_TUNNEL & current->path.node.user_data[0]) != 0) {
// We are a bridge/tunnel, how cool!!
// This means we can only point forward.. get the direction from the user_data
if (i != (current->path.node.user_data[0] >> 8)) continue;
}
dir = 0;
// First, check if we have a parent
if (current->path.parent == NULL && current->path.node.user_data[0] == 0) {
// If not, this means we are at the starting station
if (PathFinderInfo->start_direction != AI_PATHFINDER_NO_DIRECTION) {
// We do need a direction?
if (AiNew_GetDirection(current->path.node.tile, current->path.node.tile + _tiles_around[i]) != PathFinderInfo->start_direction)
// We are not pointing the right way, invalid tile
continue;
}
} else if (current->path.node.user_data[0] == 0) {
if (PathFinderInfo->rail_or_road) {
// Rail check
dir = AiNew_GetRailDirection(current->path.parent->node.tile, current->path.node.tile, current->path.node.tile + _tiles_around[i]);
r = DoCommandByTile(current->path.node.tile, 0, dir, DC_AUTO | DC_NO_WATER, CMD_BUILD_SINGLE_RAIL);
if (r == CMD_ERROR) continue;
#ifdef AI_PATHFINDER_NO_90DEGREES_TURN
if (current->path.parent->parent != NULL) {
// Check if we don't make a 90degree curve
int dir1 = AiNew_GetRailDirection(current->path.parent->parent->node.tile, current->path.parent->node.tile, current->path.node.tile);
if (_illegal_curves[dir1] == dir || _illegal_curves[dir] == dir1) {
continue;
}
}
#endif
} else {
// Road check
dir = AiNew_GetRoadDirection(current->path.parent->node.tile, current->path.node.tile, current->path.node.tile + _tiles_around[i]);
if (AI_PATHFINDER_IS_ROAD(current->path.node.tile)) {
if (IS_TILETYPE(current->path.node.tile, MP_TUNNELBRIDGE)) {
// We have a bridge, how nicely! We should mark it...
dir = 0;
} else {
// It already has road.. check if we miss any bits!
if ((_map5[current->path.node.tile] & dir) != dir) {
// We do miss some pieces :(
dir &= ~_map5[current->path.node.tile];
} else {
dir = 0;
}
}
}
// Only destruct things if it is MP_CLEAR of MP_TREES
if (dir != 0) {
r = DoCommandByTile(current->path.node.tile, dir, 0, DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD);
if (r == CMD_ERROR) continue;
}
}
}
// The tile can be connected
aystar->neighbours[aystar->num_neighbours].tile = _tiles_around[i] + current->path.node.tile;
aystar->neighbours[aystar->num_neighbours].user_data[0] = 0;
aystar->neighbours[aystar->num_neighbours++].direction = 0;
}
}
// Next step, check for bridges and tunnels
if (current->path.parent != NULL && current->path.node.user_data[0] == 0) {
TileInfo ti;
// First we get the dir from this tile and his parent
int dir = AiNew_GetDirection(current->path.parent->node.tile, current->path.node.tile);
// It means we can only walk with the track, so the bridge has to be in the same direction
TileIndex tile = current->path.node.tile;
TileIndex new_tile = tile;
FindLandscapeHeightByTile(&ti, tile);
// Bridges can only be build on land that is not flat
// And if there is a road or rail blocking
if (ti.tileh != 0 ||
(PathFinderInfo->rail_or_road && IS_TILETYPE(tile + _tiles_around[dir], MP_STREET)) ||
(!PathFinderInfo->rail_or_road && IS_TILETYPE(tile + _tiles_around[dir], MP_RAILWAY))) {
for (;;) {
new_tile += _tiles_around[dir];
// Precheck, is the length allowed?
if (!CheckBridge_Stuff(0,GetBridgeLength(tile, new_tile))) break;
// Check if we hit the station-tile.. we don't like that!
if (TILES_BETWEEN(new_tile,PathFinderInfo->end_tile_tl,PathFinderInfo->end_tile_br)) break;
// Try building the bridge..
r = DoCommandByTile(tile, new_tile, (0<<8) + (MAX_BRIDGES / 2), DC_AUTO, CMD_BUILD_BRIDGE);
if (r == CMD_ERROR) continue;
// We can build a bridge here.. add him to the neighbours
aystar->neighbours[aystar->num_neighbours].tile = new_tile;
aystar->neighbours[aystar->num_neighbours].user_data[0] = AI_PATHFINDER_FLAG_BRIDGE + (dir << 8);
aystar->neighbours[aystar->num_neighbours++].direction = 0;
// We can only have 12 neighbours, and we need 1 left for tunnels
if (aystar->num_neighbours == 11) break;
}
}
// Next, check for tunnels!
// Tunnels can only be build with tileh of 3, 6, 9 or 12, depending on the direction
// For now, we check both sides for this tile.. terraforming gives fuzzy result
if ((dir == 0 && ti.tileh == 12) ||
(dir == 1 && ti.tileh == 6) ||
(dir == 2 && ti.tileh == 3) ||
(dir == 3 && ti.tileh == 9)) {
// Now simply check if a tunnel can be build
r = DoCommandByTile(tile, (PathFinderInfo->rail_or_road?0:0x200), 0, DC_AUTO, CMD_BUILD_TUNNEL);
FindLandscapeHeightByTile(&ti, _build_tunnel_endtile);
if (r != CMD_ERROR && (ti.tileh == 3 || ti.tileh == 6 || ti.tileh == 9 || ti.tileh == 12)) {
aystar->neighbours[aystar->num_neighbours].tile = _build_tunnel_endtile;
aystar->neighbours[aystar->num_neighbours].user_data[0] = AI_PATHFINDER_FLAG_TUNNEL + (dir << 8);
aystar->neighbours[aystar->num_neighbours++].direction = 0;
}
}
}
}
extern uint GetRailFoundation(uint tileh, uint bits);
extern uint GetRoadFoundation(uint tileh, uint bits);
extern uint GetBridgeFoundation(uint tileh, byte direction);
enum {
BRIDGE_NO_FOUNDATION = 1 << 0 | 1 << 3 | 1 << 6 | 1 << 9 | 1 << 12,
};
// The most important function: it calculates the g-value
static int32 AyStar_AiPathFinder_CalculateG(AyStar *aystar, AyStarNode *current, OpenListNode *parent) {
Ai_PathFinderInfo *PathFinderInfo = (Ai_PathFinderInfo*)aystar->user_target;
int r, res = 0;
TileInfo ti, parent_ti;
// Gather some information about the tile..
FindLandscapeHeightByTile(&ti, current->tile);
FindLandscapeHeightByTile(&parent_ti, parent->path.node.tile);
// 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)
// 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;
}
// Give everything a small penalty
res += AI_PATHFINDER_PENALTY;
if (!PathFinderInfo->rail_or_road) {
// Road has the lovely advantage it can use other road... check if
// the current tile is road, and if so, give a good bonus
if (AI_PATHFINDER_IS_ROAD(current->tile)) {
res -= AI_PATHFINDER_ROAD_ALREADY_EXISTS_BONUS;
}
}
// We should give a penalty when the tile is going up or down.. this is one way to do so!
// Too bad we have to count it from the parent.. but that is not so bad
if (parent_ti.tileh != 0 && parent->path.parent != NULL) {
// Skip if the tile was from a bridge or tunnel
if (parent->path.node.user_data[0] == 0 && current->user_data[0] == 0) {
if (PathFinderInfo->rail_or_road) {
r = GetRailFoundation(parent_ti.tileh, 1 << AiNew_GetRailDirection(parent->path.parent->node.tile, parent->path.node.tile, current->tile));
// Maybe is BRIDGE_NO_FOUNDATION a bit strange here, but it contains just the right information..
if (r >= 15 || (r == 0 && (BRIDGE_NO_FOUNDATION & (1 << ti.tileh)))) {
res += AI_PATHFINDER_TILE_GOES_UP_PENALTY;
}
} else {
if (!(AI_PATHFINDER_IS_ROAD(parent->path.node.tile) && IS_TILETYPE(parent->path.node.tile, MP_TUNNELBRIDGE))) {
r = GetRoadFoundation(parent_ti.tileh, AiNew_GetRoadDirection(parent->path.parent->node.tile, parent->path.node.tile, current->tile));
if (r >= 15 || r == 0)
res += AI_PATHFINDER_TILE_GOES_UP_PENALTY;
}
}
}
}
// Are we part of a tunnel?
if ((AI_PATHFINDER_FLAG_TUNNEL & current->user_data[0]) != 0) {
// Tunnels are very expensive when build on long routes..
// Ironicly, we are using BridgeCode here ;)
r = AI_PATHFINDER_TUNNEL_PENALTY * GetBridgeLength(current->tile, parent->path.node.tile);
res += r + (r >> 8);
}
// Are we part of a bridge?
if ((AI_PATHFINDER_FLAG_BRIDGE & current->user_data[0]) != 0) {
// That means for every length a penalty
res += AI_PATHFINDER_BRIDGE_PENALTY * GetBridgeLength(current->tile, parent->path.node.tile);
// Check if we are going up or down, first for the starting point
// In user_data[0] is at the 8th bit the direction
if (!(BRIDGE_NO_FOUNDATION & (1 << parent_ti.tileh))) {
if (GetBridgeFoundation(parent_ti.tileh, (current->user_data[0] >> 8) & 1) < 15)
res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY;
}
// Second for the end point
if (!(BRIDGE_NO_FOUNDATION & (1 << ti.tileh))) {
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;
}
// To prevent the AI from taking the fastest way in tiles, but not the fastest way
// in speed, we have to give a good penalty to direction changing
// 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)) {
// When road exists, we don't like turning, but its free, so don't be to piggy about it
if (AI_PATHFINDER_IS_ROAD(parent->path.node.tile))
res += AI_PATHFINDER_DIRECTION_CHANGE_ON_EXISTING_ROAD_PENALTY;
else
res += AI_PATHFINDER_DIRECTION_CHANGE_PENALTY;
}
} else {
// For rail we have 1 exeption: diagonal rail..
// So we fetch 2 raildirection. That of the current one, and of the one before that
if (parent->path.parent != NULL && parent->path.parent->parent != NULL) {
int dir1 = AiNew_GetRailDirection(parent->path.parent->node.tile, parent->path.node.tile, current->tile);
int dir2 = AiNew_GetRailDirection(parent->path.parent->parent->node.tile, parent->path.parent->node.tile, parent->path.node.tile);
// First, see if we are on diagonal path, that is better then straight path
if (dir1 > 1) { res -= AI_PATHFINDER_DIAGONAL_BONUS; }
// First see if they are different
if (dir1 != dir2) {
// dir 2 and 3 are 1 diagonal track, and 4 and 5.
if (!(((dir1 == 2 || dir1 == 3) && (dir2 == 2 || dir2 == 3)) || ((dir1 == 4 || dir1 == 5) && (dir2 == 4 || dir2 == 5)))) {
// It is not, so we changed of direction
res += AI_PATHFINDER_DIRECTION_CHANGE_PENALTY;
}
if (parent->path.parent->parent->parent != NULL) {
int dir3 = AiNew_GetRailDirection(parent->path.parent->parent->parent->node.tile, parent->path.parent->parent->node.tile, parent->path.parent->node.tile);
// Check if we changed 3 tiles of direction in 3 tiles.. bad!!!
if ((dir1 == 0 || dir1 == 1) && dir2 > 1 && (dir3 == 0 || dir3 == 1)) {
res += AI_PATHFINDER_CURVE_PENALTY;
}
}
}
}
}
// Res should never be below zero.. if so, make it zero!
if (res < 0) { res = 0; }
// Return our value
return res;
}

117
ai_shared.c Normal file
View File

@@ -0,0 +1,117 @@
#include "stdafx.h"
#include "ttd.h"
#include "ai.h"
#include "vehicle.h"
int AiNew_GetRailDirection(uint tile_a, uint tile_b, uint tile_c) {
// 0 = vert
// 1 = horz
// 2 = dig up-left
// 3 = dig down-right
// 4 = dig down-left
// 5 = dig up-right
int x1, x2, x3;
int y1, y2, y3;
x1 = GET_TILE_X(tile_a);
x2 = GET_TILE_X(tile_b);
x3 = GET_TILE_X(tile_c);
y1 = GET_TILE_Y(tile_a);
y2 = GET_TILE_Y(tile_b);
y3 = GET_TILE_Y(tile_c);
if (y1 == y2 && y2 == y3) return 0;
if (x1 == x2 && x2 == x3) return 1;
if (y2 > y1) {
if (x2 > x3) return 2;
else return 4;
}
if (x2 > x1) {
if (y2 > y3) return 2;
else return 5;
}
if (y1 > y2) {
if (x2 > x3) return 5;
else return 3;
}
if (x1 > x2) {
if (y2 > y3) return 4;
else return 3;
}
return 0;
}
int AiNew_GetRoadDirection(uint tile_a, uint tile_b, uint tile_c) {
int x1, x2, x3;
int y1, y2, y3;
int r;
x1 = GET_TILE_X(tile_a);
x2 = GET_TILE_X(tile_b);
x3 = GET_TILE_X(tile_c);
y1 = GET_TILE_Y(tile_a);
y2 = GET_TILE_Y(tile_b);
y3 = GET_TILE_Y(tile_c);
r = 0;
if (x1 < x2) r += 8;
if (y1 < y2) r += 1;
if (x1 > x2) r += 2;
if (y1 > y2) r += 4;
if (x2 < x3) r += 2;
if (y2 < y3) r += 4;
if (x2 > x3) r += 8;
if (y2 > y3) r += 1;
return r;
}
// Get's the direction between 2 tiles seen from tile_a
int AiNew_GetDirection(uint tile_a, uint tile_b) {
if (GET_TILE_Y(tile_a) < GET_TILE_Y(tile_b)) return 1;
if (GET_TILE_Y(tile_a) > GET_TILE_Y(tile_b)) return 3;
if (GET_TILE_X(tile_a) < GET_TILE_X(tile_b)) return 2;
return 0;
}
// This functions looks up if this vehicle is special for this AI
// and returns his flag
uint AiNew_GetSpecialVehicleFlag(Player *p, Vehicle *v) {
int i;
for (i=0;i<AI_MAX_SPECIAL_VEHICLES;i++) {
if (p->ainew.special_vehicles[i].veh_id == v->index) {
return p->ainew.special_vehicles[i].flag;
}
}
// Not found :(
return 0;
}
bool AiNew_SetSpecialVehicleFlag(Player *p, Vehicle *v, uint flag) {
int i, new_id = -1;
for (i=0;i<AI_MAX_SPECIAL_VEHICLES;i++) {
if (p->ainew.special_vehicles[i].veh_id == v->index) {
p->ainew.special_vehicles[i].flag |= flag;
return true;
}
if (new_id == -1 && p->ainew.special_vehicles[i].veh_id == 0 &&
p->ainew.special_vehicles[i].flag == 0)
new_id = i;
}
// Out of special_vehicle spots :s
if (new_id == -1) {
DEBUG(ai, 1)("special_vehicles list is too small :(");
return false;
}
p->ainew.special_vehicles[new_id].veh_id = v->index;
p->ainew.special_vehicles[new_id].flag = flag;
return true;
}

1898
aircraft_cmd.c Normal file

File diff suppressed because it is too large Load Diff

1145
aircraft_gui.c Normal file

File diff suppressed because it is too large Load Diff

282
airport.c Normal file
View File

@@ -0,0 +1,282 @@
#include "stdafx.h"
#include "ttd.h"
#include "airport.h"
AirportFTAClass *CountryAirport;
AirportFTAClass *CityAirport;
AirportFTAClass *Heliport, *Oilrig;
AirportFTAClass *MetropolitanAirport;
AirportFTAClass *InternationalAirport;
static void AirportFTAClass_Constructor(AirportFTAClass *Airport,
const byte nofterminals, const byte nofterminalgroups,
const byte nofhelipads, const byte nofhelipadgroups,
const byte entry_point, const byte acc_planes,
const AirportFTAbuildup *FA,
const TileIndex *depots);
static void AirportFTAClass_Destructor(AirportFTAClass *Airport);
static uint16 AirportGetNofElements(const AirportFTAbuildup *FA);
static void AirportBuildAutomata(AirportFTAClass *Airport, const AirportFTAbuildup *FA);
static byte AirportTestFTA(const AirportFTAClass *Airport);
/*static void AirportPrintOut(const AirportFTAClass *Airport, const bool full_report);
static byte AirportBlockToString(uint32 block);*/
void InitializeAirports()
{
// country airport
CountryAirport = (AirportFTAClass *)malloc(sizeof(AirportFTAClass));
AirportFTAClass_Constructor(CountryAirport, 2, 1, 0, 0, 16, ALL, _airport_fta_country, _airport_depots_country);
// city airport
CityAirport = (AirportFTAClass *)malloc(sizeof(AirportFTAClass));
AirportFTAClass_Constructor(CityAirport, 3, 1, 0, 0, 19, ALL, _airport_fta_city, _airport_depots_city);
// metropolitan airport
MetropolitanAirport = (AirportFTAClass *)malloc(sizeof(AirportFTAClass));
AirportFTAClass_Constructor(MetropolitanAirport, 3, 1, 0, 0, 20, ALL, _airport_fta_metropolitan, _airport_depots_metropolitan);
// international airport
InternationalAirport = (AirportFTAClass *)malloc(sizeof(AirportFTAClass));
AirportFTAClass_Constructor(InternationalAirport, 6, 2, 2, 1, 37, ALL, _airport_fta_international, _airport_depots_international);
// heliport, oilrig
Heliport = (AirportFTAClass *)malloc(sizeof(AirportFTAClass));
AirportFTAClass_Constructor(Heliport, 0, 0, 1, 1, 7, HELICOPTERS_ONLY, _airport_fta_heliport_oilrig, _airport_depots_heliport_oilrig);
Oilrig = Heliport; // exactly the same structure for heliport/oilrig, so share state machine
}
void UnInitializeAirports()
{
AirportFTAClass_Destructor(CountryAirport);
AirportFTAClass_Destructor(CityAirport);
AirportFTAClass_Destructor(Heliport);
AirportFTAClass_Destructor(MetropolitanAirport);
AirportFTAClass_Destructor(InternationalAirport);
}
static void AirportFTAClass_Constructor(AirportFTAClass *Airport,
const byte nofterminals, const byte nofterminalgroups,
const byte nofhelipads, const byte nofhelipadgroups,
const byte entry_point, const byte acc_planes,
const AirportFTAbuildup *FA,
const TileIndex *depots)
{
// if there are more terminals than 6, internal variables have to be changed, so don't allow that
// same goes for helipads
if (nofterminals > MAX_TERMINALS) { printf("Currently only maximum of %2d terminals are supported (you wanted %2d)\n", MAX_TERMINALS, nofterminals);}
if (nofhelipads > MAX_HELIPADS) { printf("Currently only maximum of %2d helipads are supported (you wanted %2d)\n", MAX_HELIPADS, nofhelipads);}
// terminals/helipads are divided into groups. Groups are computed by dividing the number
// of terminals by the number of groups. Half in half. If #terminals is uneven, first group
// will get the less # of terminals
if (nofterminalgroups > nofterminals) { printf("# of terminalgroups (%2d) must be less or equal to terminals (%2d)", nofterminals, nofterminalgroups);}
if (nofhelipadgroups > nofhelipads) { printf("# of helipadgroups (%2d) must be less or equal to helipads (%2d)", nofhelipads, nofhelipadgroups);}
assert(nofterminals <= MAX_TERMINALS);
assert(nofhelipads <= MAX_HELIPADS);
assert(nofterminalgroups <= nofterminals);
assert(nofhelipadgroups <= nofhelipads);
Airport->nofelements = AirportGetNofElements(FA);
// check
if (entry_point >= Airport->nofelements) {printf("Entry point (%2d) must be within the airport positions (which is max %2d)\n", entry_point, Airport->nofelements);}
assert(entry_point < Airport->nofelements);
Airport->nofterminals = nofterminals;
Airport->nofterminalgroups = nofterminalgroups;
Airport->nofhelipads = nofhelipads;
Airport->nofhelipadgroups = nofhelipadgroups;
Airport->acc_planes = acc_planes;
Airport->entry_point = entry_point;
Airport->airport_depots = (const uint16*)depots;
// build the state machine
AirportBuildAutomata(Airport, FA);
DEBUG(misc, 1) ("#Elements %2d; #Terminals %2d in %d group(s); #Helipads %2d in %d group(s)", Airport->nofelements,
Airport->nofterminals, Airport->nofterminalgroups, Airport->nofhelipads, Airport->nofhelipadgroups);
{
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
// false -- short info, only position and next position
//AirportPrintOut(Airport, false);
}
static void AirportFTAClass_Destructor(AirportFTAClass *Airport)
{
int i;
AirportFTA *current, *next;
for (i = 0; i < Airport->nofelements; i++) {
current = Airport->layout[i].next_in_chain;
while (current != NULL) {
next = current->next_in_chain;
free(current);
current = next;
};
}
free(Airport->layout);
free(Airport);
}
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;}
}
return nofelements;
}
static void AirportBuildAutomata(AirportFTAClass *Airport, const AirportFTAbuildup *FA)
{
AirportFTA *FAutomata;
AirportFTA *current;
uint16 internalcounter, i;
FAutomata = (AirportFTA *)malloc(sizeof(AirportFTA) * Airport->nofelements);
Airport->layout = FAutomata;
internalcounter = 0;
for (i = 0; i < Airport->nofelements; i++) {
current = &Airport->layout[i];
current->position = FA[internalcounter].position;
current->heading = FA[internalcounter].heading;
current->block = FA[internalcounter].block;
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 = (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;
internalcounter++;
} // while
current->next_in_chain = NULL;
internalcounter++;
}
}
static byte AirportTestFTA(const AirportFTAClass *Airport)
{
byte position, i, next_element;
AirportFTA *temp;
next_element = 0;
for (i = 0; i < Airport->nofelements; i++) {
position = Airport->layout[i].position;
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;}
temp = temp->next_in_chain;
} while (temp != NULL);
next_element++;
}
return MAX_ELEMENTS;
}
static const char* const _airport_heading_strings[MAX_HEADINGS+2] = {
"TO_ALL",
"HANGAR",
"TERM1",
"TERM2",
"TERM3",
"TERM4",
"TERM5",
"TERM6",
"HELIPAD1",
"HELIPAD2",
"TAKEOFF",
"STARTTAKEOFF",
"ENDTAKEOFF",
"HELITAKEOFF",
"FLYING",
"LANDING",
"ENDLANDING",
"HELILANDING",
"HELIENDLANDING",
"DUMMY" // extra heading for 255
};
/*
static void AirportPrintOut(const AirportFTAClass *Airport, const bool full_report)
{
AirportFTA *temp;
uint16 i;
byte heading;
printf("(P = Current Position; NP = Next Position)\n");
for (i = 0; i < Airport->nofelements; i++) {
temp = &Airport->layout[i];
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);}
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);}
}
printf("\n");
}
}
static byte AirportBlockToString(uint32 block)
{
byte i = 0;
if (block & 0xffff0000) { block >>= 16; i += 16; }
if (block & 0x0000ff00) { block >>= 8; i += 8; }
if (block & 0x000000f0) { block >>= 4; i += 4; }
if (block & 0x0000000c) { block >>= 2; i += 2; }
if (block & 0x00000002) { i += 1; }
return i;
}*/
const AirportFTAClass* GetAirport(const byte airport_type)
{
AirportFTAClass *Airport = NULL;
//FIXME -- AircraftNextAirportPos_and_Order -> Needs something nicer, don't like this code
// needs constant change if more airports are added
switch (airport_type) {
case AT_SMALL: Airport = CountryAirport; break;
case AT_LARGE: Airport = CityAirport; break;
case AT_METROPOLITAN: Airport = MetropolitanAirport; break;
case AT_HELIPORT: Airport = Heliport; break;
case AT_OILRIG: Airport = Oilrig; break;
case AT_INTERNATIONAL: Airport = InternationalAirport; break;
default:
#ifdef DEBUG__
printf("Airport AircraftNextAirportPos_and_Order not yet implemented\n");
#endif
assert(airport_type <= AT_INTERNATIONAL);
}
return Airport;
}

52
airport.h Normal file
View File

@@ -0,0 +1,52 @@
#ifndef AIRPORT_H
#define AIRPORT_H
#include "airport_movement.h"
enum {MAX_TERMINALS = 6};
enum {MAX_HELIPADS = 2};
// Airport types
enum {
AT_SMALL = 0,
AT_LARGE = 1,
AT_HELIPORT = 2,
AT_METROPOLITAN = 3,
AT_INTERNATIONAL = 4,
AT_OILRIG = 5
};
// do not change unless you change v->subtype too. This aligns perfectly with its current setting
enum {
AIRCRAFT_ONLY = 0,
ALL = 1,
HELICOPTERS_ONLY = 2
};
// Finite sTate mAchine --> FTA
typedef struct AirportFTAClass {
byte nofelements; // number of positions the airport consists of
byte nofterminals; // number of terminals this airport has
byte nofterminalgroups; // terminals belong to so many groups (MAX is the nofterminals)
byte nofhelipads; // number of helipads this airport has
byte nofhelipadgroups; // helipads belong to so many groups (MAX is the nofhelipads)
byte entry_point; // when an airplane arrives at this airport, enter it at position entry_point
byte acc_planes; // accept airplanes or helicopters or both
const uint16 *airport_depots; // gives the position of the depots on the airports
struct AirportFTA *layout; // state machine for airport
} AirportFTAClass;
// internal structure used in openttd - Finite sTate mAchine --> FTA
typedef struct AirportFTA {
byte position; // the position that an airplane is at
byte next_position; // next position from this position
uint32 block; // 32 bit blocks (st->airport_flags), should be enough for the most complex airports
byte heading; // heading (current orders), guiding an airplane to its target on an airport
struct AirportFTA *next_in_chain; // possible extra movement choices from this position
} AirportFTA;
void InitializeAirports();
void UnInitializeAirports();
const AirportFTAClass* GetAirport(const byte airport_type);
#endif /* AIRPORT_H */

227
airport_gui.c Normal file
View File

@@ -0,0 +1,227 @@
#include "stdafx.h"
#include "ttd.h"
#include "window.h"
#include "gui.h"
#include "viewport.h"
#include "gfx.h"
#include "command.h"
#include "vehicle.h"
#include "station.h"
#include "airport.h"
static byte _selected_airport_type;
static void ShowBuildAirportPicker();
static void CcBuildAirport(bool success, uint tile, uint32 p1, uint32 p2)
{
if (success) {
SndPlayTileFx(0x1D, tile);
ResetObjectToPlace();
}
}
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(uint tile)
{
VpStartPlaceSizing(tile, 4);
}
static void BuildAirClick_Airport(Window *w)
{
if (HandlePlacePushButton(w, 2, 0xAA4, 1, PlaceAirport)) ShowBuildAirportPicker();
}
static void BuildAirClick_Demolish(Window *w)
{
HandlePlacePushButton(w, 3, ANIMCURSOR_DEMOLISH, 1, PlaceAir_DemolishArea);
}
static void BuildAirClick_Lower(Window *w)
{
HandlePlacePushButton(w, 4, ANIMCURSOR_LOWERLAND, 2, PlaceProc_LowerLand);
}
static void BuildAirClick_Raise(Window *w)
{
HandlePlacePushButton(w, 5, ANIMCURSOR_RAISELAND, 2, PlaceProc_RaiseLand);
}
static void BuildAirClick_Purchase(Window *w)
{
HandlePlacePushButton(w, 6, 0x12B8, 1, PlaceProc_BuyLand);
}
typedef void OnButtonClick(Window *w);
static OnButtonClick * const _build_air_button_proc[] = {
BuildAirClick_Airport,
BuildAirClick_Demolish,
BuildAirClick_Lower,
BuildAirClick_Raise,
BuildAirClick_Purchase,
};
static void BuildAirToolbWndProc(Window *w, WindowEvent *e)
{
switch(e->event) {
case WE_PAINT:
DrawWindowWidgets(w);
break;
case WE_CLICK:
if (e->click.widget-2 >= 0)
_build_air_button_proc[e->click.widget - 2](w);
break;
case WE_PLACE_OBJ:
_place_proc(e->place.tile);
break;
case WE_PLACE_DRAG: {
VpSelectTilesWithMethod(e->place.pt.x, e->place.pt.y, e->place.userdata);
return;
}
case WE_PLACE_MOUSEUP:
if (e->place.pt.x != -1) {
DoCommandP(e->place.tile, e->place.starttile, 0, CcPlaySound10, CMD_CLEAR_AREA | CMD_MSG(STR_00B5_CAN_T_CLEAR_THIS_AREA));
}
break;
case WE_ABORT_PLACE_OBJ:
w->click_state = 0;
SetWindowDirty(w);
w = FindWindowById(WC_BUILD_STATION, 0);
if (w != 0)
WP(w,def_d).close = true;
break;
}
}
static const Widget _air_toolbar_widgets[] = {
{ WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, 7, 11, 129, 0, 13, STR_A000_AIRPORT_CONSTRUCT, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_PANEL, 7, 0, 41, 14, 35, 0x2E8, STR_A01E_BUILD_AIRPORT},
{ WWT_PANEL, 7, 42, 63, 14, 35, 0x2BF, STR_018D_DEMOLISH_BUILDINGS_ETC},
{ WWT_PANEL, 7, 64, 85, 14, 35, 0x2B7, STR_018E_LOWER_A_CORNER_OF_LAND},
{ WWT_PANEL, 7, 86, 107, 14, 35, 0x2B6, STR_018F_RAISE_A_CORNER_OF_LAND},
{ WWT_PANEL, 7, 108, 129, 14, 35, 0x12B7, STR_0329_PURCHASE_LAND_FOR_FUTURE},
{ WIDGETS_END},
};
static const WindowDesc _air_toolbar_desc = {
510, 22, 130, 36,
WC_BUILD_TOOLBAR,0,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
_air_toolbar_widgets,
BuildAirToolbWndProc
};
void ShowBuildAirToolbar()
{
DeleteWindowById(WC_BUILD_TOOLBAR, 0);
AllocateWindowDescFront(&_air_toolbar_desc, 0);
}
static void BuildAirportPickerWndProc(Window *w, WindowEvent *e)
{
switch(e->event) {
case WE_PAINT: {
int sel;
if (WP(w,def_d).close)
return;
w->disabled_state = 0;
sel = _selected_airport_type;
// FIXME -- BuildAirportPickerWndProc - set availability of airports by year, instead of airplane
if (!(_avail_aircraft & 1)) { w->disabled_state |= (1<<3); if (sel == AT_SMALL) sel = AT_LARGE; }
if (!(_avail_aircraft & 2)) { w->disabled_state |= (1<<4); if (sel == AT_LARGE) sel = AT_SMALL; }
if (!(_avail_aircraft & 4)) { w->disabled_state |= (1<<5); } // heliport
// 1980-1-1 is --> 21915
// 1990-1-1 is --> 25568
if (_date < 21915) {w->disabled_state |= (1<<6);} // metropilitan airport 1980
if (_date < 25568) {w->disabled_state |= (1<<7);} // international airport 1990
_selected_airport_type = sel;
// select default the coverage area to 'Off' (8)
w->click_state = ((1<<3) << sel) | ((1<<8) << _station_show_coverage);
SetTileSelectSize(_airport_size_x[sel],_airport_size_y[sel]);
if (_station_show_coverage) SetTileSelectBigSize(-4, -4, 8, 8);
DrawWindowWidgets(w);
// strings such as 'Size' and 'Coverage Area'
DrawStringCentered(74, 16, STR_305B_SIZE, 0);
DrawStringCentered(74, 78, STR_3066_COVERAGE_AREA_HIGHLIGHT, 0);
DrawStationCoverageAreaText(2, 104, (uint)-1);
break;
}
case WE_CLICK: {
switch(e->click.widget) {
case 0:
ResetObjectToPlace();
break;
case 3: case 4: case 5: case 6: case 7:
_selected_airport_type = e->click.widget - 3;
SndPlayFx(0x13);
SetWindowDirty(w);
break;
case 8: case 9:
_station_show_coverage = e->click.widget - 8;
SndPlayFx(0x13);
SetWindowDirty(w);
break;
}
} break;
case WE_MOUSELOOP: {
if (WP(w,def_d).close) {
DeleteWindow(w);
return;
}
CheckRedrawStationCoverage(w);
} break;
}
}
static const Widget _build_airport_picker_widgets[] = {
{ WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, 7, 11, 147, 0, 13, STR_3001_AIRPORT_SELECTION, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_PANEL, 7, 0, 147, 14, 130, 0x0, STR_NULL},
{WWT_NODISTXTBTN, 14, 2, 73, 27, 38, STR_3059_SMALL, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
{WWT_NODISTXTBTN, 14, 74, 145, 27, 38, STR_305A_LARGE, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
{WWT_NODISTXTBTN, 14, 2, 145, 63, 74, STR_306B_HELIPORT, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
{WWT_NODISTXTBTN, 14, 2, 145, 39, 50, STR_305AA_LARGE, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
{WWT_NODISTXTBTN, 14, 2, 145, 51, 62, STR_305AB_LARGE, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
{ WWT_CLOSEBOX, 14, 14, 73, 88, 98, STR_02DB_OFF, STR_3065_DON_T_HIGHLIGHT_COVERAGE},
{ WWT_CLOSEBOX, 14, 74, 133, 88, 98, STR_02DA_ON, STR_3064_HIGHLIGHT_COVERAGE_AREA},
{ WIDGETS_END},
};
static const WindowDesc _build_airport_desc = {
-1, -1, 148, 131, // height, 130+1
WC_BUILD_STATION,WC_BUILD_TOOLBAR,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
_build_airport_picker_widgets,
BuildAirportPickerWndProc
};
static void ShowBuildAirportPicker()
{
AllocateWindowDesc(&_build_airport_desc);
}
void InitializeAirportGui()
{
_selected_airport_type = AT_SMALL;
_last_built_aircraft_depot_tile = 0;
}

456
airport_movement.h Normal file
View File

@@ -0,0 +1,456 @@
#ifndef AIRPORT_MOVEMENT_H
#define AIRPORT_MOVEMENT_H
#include "stdafx.h"
#include "macros.h"
// don't forget to change the airport_depots too for larger mapsizes. TILE_X_BITS 16
// won't fit in uint16 for example and overflow will occur in the checking code!
// TrueLight -- So make it a TileIndex..
typedef struct AirportMovingData {
int x,y;
byte flag;
byte direction;
} AirportMovingData;
// state machine input struct (from external file, etc.)
// Finite sTate mAchine --> FTA
typedef struct AirportFTAbuildup {
byte position; // the position that an airplane is at
byte heading; // the current orders (eg. TAKEOFF, HANGAR, ENDLANDING, etc.)
uint32 block; // the block this position is on on the airport (st->airport_flags)
byte next_in_chain; // next position from this position
} AirportFTAbuildup;
enum {
AMED_NOSPDCLAMP = 1<<0,
AMED_TAKEOFF = 1<<1,
AMED_SLOWTURN = 1<<2,
AMED_LAND = 1<<3,
AMED_EXACTPOS = 1<<4,
AMED_BRAKE = 1<<5,
AMED_HELI_RAISE = 1<<6,
AMED_HELI_LOWER = 1<<7,
};
enum {MAX_ELEMENTS = 255};
enum {MAX_HEADINGS = 18};
///////////////////////////////////////////////////////////////////////
///////***********Movement States on Airports********************//////
// headings target
enum {
TO_ALL = 0,
HANGAR = 1,
TERM1 = 2,
TERM2 = 3,
TERM3 = 4,
TERM4 = 5,
TERM5 = 6,
TERM6 = 7,
HELIPAD1 = 8,
HELIPAD2 = 9,
TAKEOFF = 10,
STARTTAKEOFF = 11,
ENDTAKEOFF = 12,
HELITAKEOFF = 13,
FLYING = 14,
LANDING = 15,
ENDLANDING = 16,
HELILANDING = 17,
HELIENDLANDING = 18
};
///////////////////////////////////////////////////////////////////////
///////**********Movement Blocks on Airports*********************//////
// blocks (eg_airport_flags)
enum {
TERM1_block = 1 << 0,
TERM2_block = 1 << 1,
TERM3_block = 1 << 2,
TERM4_block = 1 << 3,
TERM5_block = 1 << 4,
TERM6_block = 1 << 5,
HELIPAD1_block = 1 << 6,
HELIPAD2_block = 1 << 7,
RUNWAY_IN_OUT_block = 1 << 8,
RUNWAY_IN_block = 1 << 8,
AIRPORT_BUSY_block = 1 << 8,
RUNWAY_OUT_block = 1 << 9,
TAXIWAY_BUSY_block = 1 << 10,
OUT_WAY_block = 1 << 11,
IN_WAY_block = 1 << 12,
AIRPORT_ENTRANCE_block = 1 << 13,
TERM_GROUP1_block = 1 << 14,
TERM_GROUP2_block = 1 << 15,
HANGAR2_AREA_block = 1 << 16,
TERM_GROUP2_ENTER1_block = 1 << 17,
TERM_GROUP2_ENTER2_block = 1 << 18,
TERM_GROUP2_EXIT1_block = 1 << 19,
TERM_GROUP2_EXIT2_block = 1 << 20,
PRE_HELIPAD_block = 1 << 21,
NOTHING_block = 1 << 30
};
///////////////////////////////////////////////////////////////////////
/////*********Movement Positions on Airports********************///////
// Country Airfield (small) 4x3
static const AirportMovingData _airport_moving_data_country[22] = {
{ 53, 3,AMED_EXACTPOS,3}, // 00 In Hangar
{ 53, 27,0,0}, // 01 Taxi to right outside depot
{ 32, 23,AMED_EXACTPOS,7}, // 02 Terminal 1
{ 10, 23,AMED_EXACTPOS,7}, // 03 Terminal 2
{ 43, 37,0,0}, // 04 Going towards terminal 2
{ 24, 37,0,0}, // 05 Going towards terminal 2
{ 53, 37,0,0}, // 06 Going for takeoff
{ 61, 40,AMED_EXACTPOS,1}, // 07 Taxi to start of runway (takeoff)
{ 3, 40,AMED_NOSPDCLAMP,0}, // 08 Accelerate to end of runway
{-79, 40,AMED_NOSPDCLAMP | AMED_TAKEOFF,0}, // 09 Take off
{177, 40,AMED_NOSPDCLAMP | AMED_SLOWTURN,0}, // 10 Fly to landing position in air
{ 56, 40,AMED_NOSPDCLAMP | AMED_LAND,0}, // 11 Going down for land
{ 3, 40,AMED_NOSPDCLAMP | AMED_BRAKE,0}, // 12 Just landed, brake until end of runway
{ 7, 40,0,0}, // 13 Just landed, turn around and taxi 1 square
{ 53, 40,0,0}, // 14 Taxi from runway to crossing
{-31,193,AMED_NOSPDCLAMP | AMED_SLOWTURN,0}, // 15 Fly around waiting for a landing spot (north-east)
{ 1, 1,AMED_NOSPDCLAMP | AMED_SLOWTURN,0}, // 16 Fly around waiting for a landing spot (north-west)
{257, 1,AMED_NOSPDCLAMP | AMED_SLOWTURN,0}, // 17 Fly around waiting for a landing spot (south-west)
{273, 49,AMED_NOSPDCLAMP | AMED_SLOWTURN,0}, // 18 Fly around waiting for a landing spot (south)
{ 44, 37,AMED_HELI_RAISE,0}, // 19 Helicopter takeoff
{ 44, 40,AMED_NOSPDCLAMP | AMED_SLOWTURN,0}, // 20 In position above landing spot helicopter
{ 44, 40,AMED_HELI_LOWER,0} // 21 Helicopter landing
};
// City Airport (large) 6x6
static const AirportMovingData _airport_moving_data_town[25] = {
{ 85, 3,AMED_EXACTPOS,3}, // 00 In Hangar
{ 85, 27,0,0}, // 01 Taxi to right outside depot
{ 26, 41,AMED_EXACTPOS,5}, // 02 Terminal 1
{ 56, 20,AMED_EXACTPOS,3}, // 03 Terminal 2
{ 38, 8,AMED_EXACTPOS,5}, // 04 Terminal 3
{ 65, 6,0,0}, // 05 Taxi to right in infront of terminal 2/3
{ 80, 27,0,0}, // 06 Taxiway terminals 2-3
{ 44, 63,0,0}, // 07 Taxi to Airport center
{ 58, 71,0,0}, // 08 Towards takeoff
{ 72, 85,0,0}, // 09 Taxi to runway (takeoff)
{ 89, 85,AMED_EXACTPOS,1}, // 10 Taxi to start of runway (takeoff)
{ 3, 85,AMED_NOSPDCLAMP,0}, // 11 Accelerate to end of runway
{-79, 85,AMED_NOSPDCLAMP | AMED_TAKEOFF,0}, // 12 Take off
{177, 85,AMED_NOSPDCLAMP | AMED_SLOWTURN,0}, // 13 Fly to landing position in air
{ 89, 85,AMED_NOSPDCLAMP | AMED_LAND,0}, // 14 Going down for land
{ 3, 85,AMED_NOSPDCLAMP | AMED_BRAKE,0}, // 15 Just landed, brake until end of runway
{ 20, 87,0,0}, // 16 Just landed, turn around and taxi 1 square
{ 36, 71,0,0}, // 17 Taxi from runway to crossing
{-31,193,AMED_NOSPDCLAMP | AMED_SLOWTURN,0}, // 18 Fly around waiting for a landing spot (north-east)
{ 1, 1,AMED_NOSPDCLAMP | AMED_SLOWTURN,0}, // 19 Fly around waiting for a landing spot (north-west)
{257, 1,AMED_NOSPDCLAMP | AMED_SLOWTURN,0}, // 20 Fly around waiting for a landing spot (south-west)
{273, 49,AMED_NOSPDCLAMP | AMED_SLOWTURN,0}, // 21 Fly around waiting for a landing spot (south)
{ 44, 63,AMED_HELI_RAISE,0}, // 22 Helicopter takeoff
{ 28, 74,AMED_NOSPDCLAMP | AMED_SLOWTURN,0}, // 23 In position above landing spot helicopter
{ 28, 74,AMED_HELI_LOWER,0} // 24 Helicopter landing
};
// Metropolitan Airport (metropolitan) - 2 runways
static const AirportMovingData _airport_moving_data_metropolitan[27] = {
{ 85, 3,AMED_EXACTPOS,3}, // 00 In Hangar
{ 85, 27,0,0}, // 01 Taxi to right outside depot
{ 26, 41,AMED_EXACTPOS,5}, // 02 Terminal 1
{ 56, 20,AMED_EXACTPOS,3}, // 03 Terminal 2
{ 38, 8,AMED_EXACTPOS,5}, // 04 Terminal 3
{ 65, 6,0,0}, // 05 Taxi to right in infront of terminal 2/3
{ 70, 33,0,0}, // 06 Taxiway terminals 2-3
{ 44, 58,0,0}, // 07 Taxi to Airport center
{ 72, 58,0,0}, // 08 Towards takeoff
{ 72, 69,0,0}, // 09 Taxi to runway (takeoff)
{ 89, 69,AMED_EXACTPOS,1}, // 10 Taxi to start of runway (takeoff)
{ 3, 69,AMED_NOSPDCLAMP,0}, // 11 Accelerate to end of runway
{-79, 69,AMED_NOSPDCLAMP | AMED_TAKEOFF,0}, // 12 Take off
{177, 85,AMED_NOSPDCLAMP | AMED_SLOWTURN,0}, // 13 Fly to landing position in air
{ 89, 85,AMED_NOSPDCLAMP | AMED_LAND,0}, // 14 Going down for land
{ 3, 85,AMED_NOSPDCLAMP | AMED_BRAKE,0}, // 15 Just landed, brake until end of runway
{ 21, 85,0,0}, // 16 Just landed, turn around and taxi 1 square
{ 21, 69,0,0}, // 17 On Runway-out taxiing to In-Way
{ 21, 54,AMED_EXACTPOS,5}, // 18 Taxi from runway to crossing
{-31,193,AMED_NOSPDCLAMP | AMED_SLOWTURN,0}, // 19 Fly around waiting for a landing spot (north-east)
{ 1, 1,AMED_NOSPDCLAMP | AMED_SLOWTURN,0}, // 20 Fly around waiting for a landing spot (north-west)
{257, 1,AMED_NOSPDCLAMP | AMED_SLOWTURN,0}, // 21 Fly around waiting for a landing spot (south-west)
{273, 49,AMED_NOSPDCLAMP | AMED_SLOWTURN,0}, // 22 Fly around waiting for a landing spot (south)
{ 44, 58,0,0}, // 23 Helicopter takeoff spot on ground (to clear airport sooner)
{ 44, 63,AMED_HELI_RAISE,0}, // 24 Helicopter takeoff
{ 15, 54,AMED_NOSPDCLAMP | AMED_SLOWTURN,0}, // 25 Get in position above landing spot helicopter
{ 15, 54,AMED_HELI_LOWER,0} // 26 Helicopter landing
};
// International Airport (international) - 2 runways, 6 terminals, dedicated helipod
static const AirportMovingData _airport_moving_data_international[51] = {
{ 7, 55,AMED_EXACTPOS,3}, // 00 In Hangar 1
{100, 21,AMED_EXACTPOS,3}, // 01 In Hangar 2
{ 7, 70,0,0}, // 02 Taxi to right outside depot
{100, 36,0,0}, // 03 Taxi to right outside depot
{ 38, 70,AMED_EXACTPOS,5}, // 04 Terminal 1
{ 38, 54,AMED_EXACTPOS,5}, // 05 Terminal 2
{ 38, 38,AMED_EXACTPOS,5}, // 06 Terminal 3
{ 70, 70,AMED_EXACTPOS,1}, // 07 Terminal 4
{ 70, 54,AMED_EXACTPOS,1}, // 08 Terminal 5
{ 70, 38,AMED_EXACTPOS,1}, // 09 Terminal 6
{104, 71,AMED_EXACTPOS,1}, // 10 Helipad 1
{104, 55,AMED_EXACTPOS,1}, // 11 Helipad 2
{ 22, 87,0,0}, // 12 Towards Terminals 4/5/6, Helipad 1/2
{ 60, 87,0,0}, // 13 Towards Terminals 4/5/6, Helipad 1/2
{ 66, 87,0,0}, // 14 Towards Terminals 4/5/6, Helipad 1/2
{ 86, 87,AMED_EXACTPOS,7}, // 15 Towards Terminals 4/5/6, Helipad 1/2
{ 86, 70,0,0}, // 16 In Front of Terminal 4 / Helipad 1
{ 86, 54,0,0}, // 17 In Front of Terminal 5 / Helipad 2
{ 86, 38,0,0}, // 18 In Front of Terminal 6
{ 86, 22,0,0}, // 19 Towards Terminals Takeoff (Taxiway)
{ 66, 22,0,0}, // 20 Towards Terminals Takeoff (Taxiway)
{ 60, 22,0,0}, // 21 Towards Terminals Takeoff (Taxiway)
{ 38, 22,0,0}, // 22 Towards Terminals Takeoff (Taxiway)
{ 22, 70,0,0}, // 23 In Front of Terminal 1
{ 22, 58,0,0}, // 24 In Front of Terminal 2
{ 22, 38,0,0}, // 25 In Front of Terminal 3
{ 22, 22,AMED_EXACTPOS,7}, // 26 Going for Takeoff
{ 22, 6,0,0}, // 27 On Runway-out, prepare for takeoff
{ 3, 6,AMED_EXACTPOS,5}, // 28 Accelerate to end of runway
{ 60, 6,AMED_NOSPDCLAMP,0}, // 29 Release control of runway, for smoother movement
{105, 6,AMED_NOSPDCLAMP,0}, // 30 End of runway
{190, 6,AMED_NOSPDCLAMP | AMED_TAKEOFF,0}, // 31 Take off
{193,104,AMED_NOSPDCLAMP | AMED_SLOWTURN,0}, // 32 Fly to landing position in air
{105,104,AMED_NOSPDCLAMP | AMED_LAND,0}, // 33 Going down for land
{ 3,104,AMED_NOSPDCLAMP | AMED_BRAKE,0}, // 34 Just landed, brake until end of runway
{ 12,104,0,0}, // 35 Just landed, turn around and taxi 1 square
{ 7, 84,0,0}, // 36 Taxi from runway to crossing
{-31,209,AMED_NOSPDCLAMP | AMED_SLOWTURN,0}, // 37 Fly around waiting for a landing spot (north-east)
{ 1, 6,AMED_NOSPDCLAMP | AMED_SLOWTURN,0}, // 38 Fly around waiting for a landing spot (north-west)
{273, 6,AMED_NOSPDCLAMP | AMED_SLOWTURN,0}, // 39 Fly around waiting for a landing spot (south-west)
{305, 81,AMED_NOSPDCLAMP | AMED_SLOWTURN,0}, // 40 Fly around waiting for a landing spot (south)
// Helicopter
{128, 80,AMED_NOSPDCLAMP | AMED_SLOWTURN,0}, // 41 Bufferspace before helipad
{128, 80,AMED_NOSPDCLAMP | AMED_SLOWTURN,0}, // 42 Bufferspace before helipad
{ 96, 71,AMED_NOSPDCLAMP | AMED_SLOWTURN,0}, // 43 Get in position for Helipad1
{ 96, 55,AMED_NOSPDCLAMP | AMED_SLOWTURN,0}, // 44 Get in position for Helipad2
{ 96, 71,AMED_HELI_LOWER,0}, // 45 Land at Helipad1
{ 96, 55,AMED_HELI_LOWER,0}, // 46 Land at Helipad2
{104, 71,AMED_HELI_RAISE,0}, // 47 Takeoff Helipad1
{104, 55,AMED_HELI_RAISE,0}, // 48 Takeoff Helipad2
{104, 32,AMED_NOSPDCLAMP | AMED_SLOWTURN,0}, // 49 Go to position for Hangarentrance in air
{104, 32,AMED_HELI_LOWER,0} // 50 Land in HANGAR2_AREA to go to hangar
};
// Heliport (heliport)
static const AirportMovingData _airport_moving_data_heliport[9] = {
{ 5, 9,AMED_EXACTPOS,1}, // 0 - At heliport terminal
{ 2, 9,AMED_HELI_RAISE,0}, // 1 - Take off (play sound)
{ -3, 9,AMED_NOSPDCLAMP | AMED_SLOWTURN,0}, // 2 - In position above landing spot helicopter
{ -3, 9,AMED_HELI_LOWER,0}, // 3 - Land
{ 2, 9,0,0}, // 4 - Goto terminal on ground
{-31, 59,AMED_NOSPDCLAMP | AMED_SLOWTURN,0}, // 5 - Circle #1 (north-east)
{-31,-49,AMED_NOSPDCLAMP | AMED_SLOWTURN,0}, // 6 - Circle #2 (north-west)
{ 49,-49,AMED_NOSPDCLAMP | AMED_SLOWTURN,0}, // 7 - Circle #3 (south-west)
{ 70, 9,AMED_NOSPDCLAMP | AMED_SLOWTURN,0}, // 8 - Circle #4 (south)
};
// Oilrig
static const AirportMovingData _airport_moving_data_oilrig[9] = {
{ 31, 9,AMED_EXACTPOS,1}, // 0 - At oilrig terminal
{ 28, 9,AMED_HELI_RAISE,0}, // 1 - Take off (play sound)
{ 23, 9,AMED_NOSPDCLAMP | AMED_SLOWTURN,0}, // 2 - In position above landing spot helicopter
{ 23, 9,AMED_HELI_LOWER,0}, // 3 - Land
{ 28, 9,0,0}, // 4 - Goto terminal on ground
{-31, 69,AMED_NOSPDCLAMP | AMED_SLOWTURN,0}, // 5 - circle #1 (north-east)
{-31,-49,AMED_NOSPDCLAMP | AMED_SLOWTURN,0}, // 6 - circle #2 (north-west)
{ 69,-49,AMED_NOSPDCLAMP | AMED_SLOWTURN,0}, // 7 - circle #3 (south-west)
{ 70, 9,AMED_NOSPDCLAMP | AMED_SLOWTURN,0}, // 8 - circle #4 (south)
};
///////////////////////////////////////////////////////////////////////
/////**********Movement Machine on Airports*********************///////
// first element of depots array tells us how many depots there are (to know size of array)
// this may be changed later when airports are moved to external file
static const TileIndex _airport_depots_country[] = {1, TILE_XY(3,0)};
static const AirportFTAbuildup _airport_fta_country[] = {
{ 0,HANGAR,NOTHING_block,1},
{ 1,255,AIRPORT_BUSY_block,0}, {1,HANGAR,0,0}, {1,TERM1,TERM1_block,2}, {1,TERM2,0,4}, {1,HELITAKEOFF,0,19}, {1,0,0,6},
{ 2,TERM1,TERM1_block,1},
{ 3,TERM2,TERM2_block,5},
{ 4,255,AIRPORT_BUSY_block,0}, {4,TERM2,0,5}, {4,HANGAR,0,1}, {4,TAKEOFF,0,6}, {4,HELITAKEOFF,0,1},
{ 5,255,AIRPORT_BUSY_block,0}, {5,TERM2,TERM2_block,3}, {5,0,0,4},
{ 6,0,AIRPORT_BUSY_block,7},
// takeoff
{ 7,TAKEOFF,AIRPORT_BUSY_block,8},
{ 8,STARTTAKEOFF,NOTHING_block,9},
{ 9,ENDTAKEOFF,NOTHING_block,0},
// landing
{10,FLYING,NOTHING_block,15}, {10,LANDING,0,11}, {10,HELILANDING,0,20},
{11,LANDING,AIRPORT_BUSY_block,12},
{12,0,AIRPORT_BUSY_block,13},
{13,ENDLANDING,AIRPORT_BUSY_block,14}, {13,TERM2,0,5}, {13,0,0,14},
{14,0,AIRPORT_BUSY_block,1},
// In air
{15,0,NOTHING_block,16},
{16,0,NOTHING_block,17},
{17,0,NOTHING_block,18},
{18,0,NOTHING_block,10},
{19,HELITAKEOFF,NOTHING_block,0},
{20,HELILANDING,AIRPORT_BUSY_block,21},
{21,HELIENDLANDING,AIRPORT_BUSY_block,1},
{MAX_ELEMENTS,0,0,0} // end marker. DO NOT REMOVE
};
static const TileIndex _airport_depots_city[] = {1, TILE_XY(5,0)};
static const AirportFTAbuildup _airport_fta_city[] = {
{ 0,HANGAR,NOTHING_block,1}, {0,TAKEOFF,OUT_WAY_block,1}, {0,0,0,1},
{ 1,255,TAXIWAY_BUSY_block,0}, {1,HANGAR,0,0}, {1,TERM2,0,6}, {1,TERM3,0,6}, {1,0,0,7}, // for all else, go to 7
{ 2,TERM1,TERM1_block,7}, {2,TAKEOFF,OUT_WAY_block,7}, {2,0,0,7},
{ 3,TERM2,TERM2_block,5}, {3,TAKEOFF,OUT_WAY_block,5}, {3,0,0,5},
{ 4,TERM3,TERM3_block,5}, {4,TAKEOFF,OUT_WAY_block,5}, {4,0,0,5},
{ 5,255,TAXIWAY_BUSY_block,0}, {5,TERM2,TERM2_block,3}, {5,TERM3,TERM3_block,4}, {5,0,0,6},
{ 6,255,TAXIWAY_BUSY_block,0}, {6,TERM2,0,5}, {6,TERM3,0,5}, {6,HANGAR,0,1}, {6,0,0,7},
{ 7,255,TAXIWAY_BUSY_block,0}, {7,TERM1,TERM1_block,2}, {7,TAKEOFF,OUT_WAY_block,8}, {7,HELITAKEOFF,0,22}, {7,HANGAR,0,1}, {7,0,0,6},
{ 8,0,OUT_WAY_block,9},
{ 9,0,RUNWAY_IN_OUT_block,10},
// takeoff
{10,TAKEOFF,RUNWAY_IN_OUT_block,11},
{11,STARTTAKEOFF,NOTHING_block,12},
{12,ENDTAKEOFF,NOTHING_block,0},
// landing
{13,FLYING,NOTHING_block,18}, {13,LANDING,0,14}, {13,HELILANDING,0,23},
{14,LANDING,RUNWAY_IN_OUT_block,15},
{15,0,RUNWAY_IN_OUT_block,16},
{16,0,RUNWAY_IN_OUT_block,17},
{17,ENDLANDING,IN_WAY_block,7},
// In Air
{18,0,NOTHING_block,19},
{19,0,NOTHING_block,20},
{20,0,NOTHING_block,21},
{21,0,NOTHING_block,13},
// helicopter
{22,HELITAKEOFF,NOTHING_block,0},
{23,HELILANDING,IN_WAY_block,24},
{24,HELIENDLANDING,IN_WAY_block,17},
{MAX_ELEMENTS,0,0,0} // end marker. DO NOT REMOVE
};
static const TileIndex _airport_depots_metropolitan[] = {1, TILE_XY(5,0)};
static const AirportFTAbuildup _airport_fta_metropolitan[] = {
{ 0,HANGAR,NOTHING_block,1},
{ 1,255,TAXIWAY_BUSY_block,0}, {1,HANGAR,0,0}, {1,TERM2,0,6}, {1,TERM3,0,6}, {1,0,0,7}, // for all else, go to 7
{ 2,TERM1,TERM1_block,7},
{ 3,TERM2,TERM2_block,5},
{ 4,TERM3,TERM3_block,5},
{ 5,255,TAXIWAY_BUSY_block,0}, {5,TERM2,TERM2_block,3}, {5,TERM3,TERM3_block,4}, {5,0,0,6},
{ 6,255,TAXIWAY_BUSY_block,0}, {6,TERM2,0,5}, {6,TERM3,0,5}, {6,HANGAR,0,1}, {6,0,0,7},
{ 7,255,TAXIWAY_BUSY_block,0}, {7,TERM1,TERM1_block,2}, {7,TAKEOFF,0,8}, {7,HELITAKEOFF,0,23}, {7,HANGAR,0,1}, {7,0,0,6},
{ 8,0,OUT_WAY_block,9},
{ 9,0,RUNWAY_OUT_block,10},
// takeoff
{10,TAKEOFF,RUNWAY_OUT_block,11},
{11,STARTTAKEOFF,NOTHING_block,12},
{12,ENDTAKEOFF,NOTHING_block,0},
// landing
{13,FLYING,NOTHING_block,19}, {13,LANDING,0,14}, {13,HELILANDING,0,25},
{14,LANDING,RUNWAY_IN_block,15},
{15,0,RUNWAY_IN_block,16},
{16,255,RUNWAY_IN_block,0}, {16,ENDLANDING,IN_WAY_block,17},
{17,255,RUNWAY_OUT_block,0}, {17,ENDLANDING,IN_WAY_block,18},
{18,ENDLANDING,IN_WAY_block,7},
// In Air
{19,0,NOTHING_block,20},
{20,0,NOTHING_block,21},
{21,0,NOTHING_block,22},
{22,0,NOTHING_block,13},
// helicopter
{23,0,NOTHING_block,24},
{24,HELITAKEOFF,NOTHING_block,0},
{25,HELILANDING,IN_WAY_block,26},
{26,HELIENDLANDING,IN_WAY_block,18},
{MAX_ELEMENTS,0,0,0} // end marker. DO NOT REMOVE
};
static const TileIndex _airport_depots_international[] = {2, TILE_XY(0,3), TILE_XY(6,1)};
static const AirportFTAbuildup _airport_fta_international[] = {
{ 0,HANGAR,NOTHING_block,2}, {0,255,TERM_GROUP1_block,0}, {0,255,TERM_GROUP2_ENTER1_block,1}, {0,HELITAKEOFF,HELIPAD1_block,2}, {0,0,0,2},
{ 1,HANGAR,NOTHING_block,3}, {1,255,HANGAR2_AREA_block,1}, {1,HELITAKEOFF,HELIPAD2_block,3}, {1,0,0,3},
{ 2,255,AIRPORT_ENTRANCE_block,0}, {2,HANGAR,0,0}, {2,TERM4,0,12}, {2,TERM5,0,12}, {2,TERM6,0,12}, {2,HELIPAD1,0,12}, {2,HELIPAD2,0,12}, {2,HELITAKEOFF,0,12}, {2,0,0,23},
{ 3,255,HANGAR2_AREA_block,0}, {3,HANGAR,0,1}, {3,0,0,18},
{ 4,TERM1,TERM1_block,23}, {4,HANGAR,AIRPORT_ENTRANCE_block,23}, {4,0,0,23},
{ 5,TERM2,TERM2_block,24}, {5,HANGAR,AIRPORT_ENTRANCE_block,24}, {5,0,0,24},
{ 6,TERM3,TERM3_block,25}, {6,HANGAR,AIRPORT_ENTRANCE_block,25}, {6,0,0,25},
{ 7,TERM4,TERM4_block,16}, {7,HANGAR,HANGAR2_AREA_block,16}, {7,0,0,16},
{ 8,TERM5,TERM5_block,17}, {8,HANGAR,HANGAR2_AREA_block,17}, {8,0,0,17},
{ 9,TERM6,TERM6_block,18}, {9,HANGAR,HANGAR2_AREA_block,18}, {9,0,0,18},
{10,HELIPAD1,HELIPAD1_block,10}, {10,HANGAR,HANGAR2_AREA_block,16}, {10,HELITAKEOFF,0,47},
{11,HELIPAD2,HELIPAD2_block,11}, {11,HANGAR,HANGAR2_AREA_block,17}, {11,HELITAKEOFF,0,48},
{12,0,TERM_GROUP2_ENTER1_block,13},
{13,0,TERM_GROUP2_ENTER1_block,14},
{14,0,TERM_GROUP2_ENTER2_block,15},
{15,0,TERM_GROUP2_ENTER2_block,16},
{16,255,TERM_GROUP2_block,0}, {16,TERM4,TERM4_block,7}, {16,HELIPAD1,HELIPAD1_block,10}, {16,HELITAKEOFF,HELIPAD1_block,10}, {16,0,0,17},
{17,255,TERM_GROUP2_block,0}, {17,TERM5,TERM5_block,8}, {17,TERM4,0,16}, {17,HELIPAD1,0,16}, {17,HELIPAD2,HELIPAD2_block,11}, {17,HELITAKEOFF,HELIPAD2_block,11}, {17,0,0,18},
{18,255,TERM_GROUP2_block,0}, {18,TERM6,TERM6_block,9}, {18,TAKEOFF,0,19}, {18,HANGAR,HANGAR2_AREA_block,3}, {18,0,0,17},
{19,0,TERM_GROUP2_EXIT1_block,20},
{20,0,TERM_GROUP2_EXIT1_block,21},
{21,0,TERM_GROUP2_EXIT2_block,22},
{22,0,TERM_GROUP2_EXIT2_block,26},
{23,255,TERM_GROUP1_block,0}, {23,TERM1,TERM1_block,4}, {23,HANGAR,AIRPORT_ENTRANCE_block,2}, {23,0,0,24},
{24,255,TERM_GROUP1_block,0}, {24,TERM2,TERM2_block,5}, {24,TERM1,0,23}, {24,HANGAR,0,23}, {24,0,0,25},
{25,255,TERM_GROUP1_block,0}, {25,TERM3,TERM3_block,6}, {25,TAKEOFF,0,26}, {25,0,0,24},
{26,255,TAXIWAY_BUSY_block,0}, {26,TAKEOFF,0,27}, {26,0,0,25},
{27,0,OUT_WAY_block,28},
// takeoff
{28,TAKEOFF,OUT_WAY_block,29},
{29,0,RUNWAY_OUT_block,30},
{30,STARTTAKEOFF,NOTHING_block,31},
{31,ENDTAKEOFF,NOTHING_block,0},
// landing
{32,FLYING,NOTHING_block,37}, {32,LANDING,0,33}, {32,HELILANDING,0,41},
{33,LANDING,RUNWAY_IN_block,34},
{34,0,RUNWAY_IN_block,35},
{35,0,RUNWAY_IN_block,36},
{36,ENDLANDING,IN_WAY_block,36}, {36,255,TERM_GROUP1_block,0}, {36,255,TERM_GROUP2_ENTER1_block,1}, {36,TERM4,0,12}, {36,TERM5,0,12}, {36,TERM6,0,12}, {36,0,0,2},
// In Air
{37,0,NOTHING_block,38},
{38,0,NOTHING_block,39},
{39,0,NOTHING_block,40},
{40,0,NOTHING_block,32},
// Helicopter -- stay in air in special place as a buffer to choose from helipads
{41,HELILANDING,PRE_HELIPAD_block,42},
{42,HELIENDLANDING,PRE_HELIPAD_block,42}, {42,HELIPAD1,0,43}, {42,HELIPAD2,0,44}, {42,HANGAR,0,49},
{43,0,NOTHING_block,45},
{44,0,NOTHING_block,46},
// landing
{45,255,NOTHING_block,0}, {45,HELIPAD1,HELIPAD1_block,10},
{46,255,NOTHING_block,0}, {46,HELIPAD2,HELIPAD2_block,11},
// Helicopter -- takeoff
{47,HELITAKEOFF,NOTHING_block,0},
{48,HELITAKEOFF,NOTHING_block,0},
{49,0,HANGAR2_AREA_block,50}, // need to go to hangar when waiting in air
{50,0,HANGAR2_AREA_block,3},
{MAX_ELEMENTS,0,0,0} // end marker. DO NOT REMOVE
};
static const TileIndex _airport_depots_heliport_oilrig[] = {0};
static const AirportFTAbuildup _airport_fta_heliport_oilrig[] = {
{0,HELIPAD1,HELIPAD1_block,1},
{1,HELITAKEOFF,NOTHING_block,0}, // takeoff
{2,255,AIRPORT_BUSY_block,0}, {2,HELILANDING,0,3}, {2,HELITAKEOFF,0,1},
{3,HELILANDING,AIRPORT_BUSY_block,4},
{4,HELIENDLANDING,AIRPORT_BUSY_block,4}, {4,HELIPAD1,HELIPAD1_block,0}, {4,HELITAKEOFF,0,2},
// In Air
{5,0,NOTHING_block,6},
{6,0,NOTHING_block,7},
{7,0,NOTHING_block,8},
{8,FLYING,NOTHING_block,5}, {8,HELILANDING,HELIPAD1_block,2}, // landing
{MAX_ELEMENTS,0,0,0} // end marker. DO NOT REMOVE
};
static const AirportMovingData * const _airport_moving_datas[6] = {
_airport_moving_data_country, // Country Airfield (small) 4x3
_airport_moving_data_town, // City Airport (large) 6x6
_airport_moving_data_heliport, // Heliport
_airport_moving_data_metropolitan, // Metropolitain Airport (large) - 2 runways
_airport_moving_data_international, // International Airport (xlarge) - 2 runways
_airport_moving_data_oilrig // Oilrig
};
#endif /* AIRPORT_MOVEMENT_H */

View File

@@ -1,7 +1,3 @@
/* $Id$ */
/** @file aystar.cpp */
/*
* This file has the core function for AyStar
* AyStar is a fast pathfinding routine and is used for things like
@@ -19,57 +15,46 @@
*/
#include "stdafx.h"
#include "openttd.h"
#include "ttd.h"
#include "aystar.h"
#include "core/alloc_func.hpp"
int _aystar_stats_open_size;
int _aystar_stats_closed_size;
// This looks in the Hash if a node exists in ClosedList
// If so, it returns the PathNode, else NULL
static PathNode* AyStarMain_ClosedList_IsInList(AyStar *aystar, const AyStarNode *node)
{
PathNode *AyStarMain_ClosedList_IsInList(AyStar *aystar, AyStarNode *node) {
return (PathNode*)Hash_Get(&aystar->ClosedListHash, node->tile, node->direction);
}
// This adds a node to the ClosedList
// It makes a copy of the data
static void AyStarMain_ClosedList_Add(AyStar *aystar, const PathNode *node)
{
void AyStarMain_ClosedList_Add(AyStar *aystar, PathNode *node) {
// Add a node to the ClosedList
PathNode *new_node = MallocT<PathNode>(1);
PathNode *new_node = malloc(sizeof(PathNode));
*new_node = *node;
Hash_Set(&aystar->ClosedListHash, node->node.tile, node->node.direction, new_node);
}
// Checks if a node is in the OpenList
// If so, it returns the OpenListNode, else NULL
static OpenListNode *AyStarMain_OpenList_IsInList(AyStar *aystar, const AyStarNode *node)
{
OpenListNode *AyStarMain_OpenList_IsInList(AyStar *aystar, AyStarNode *node) {
return (OpenListNode*)Hash_Get(&aystar->OpenListHash, node->tile, node->direction);
}
// Gets the best node from OpenList
// returns the best node, or NULL of none is found
// Also it deletes the node from the OpenList
static OpenListNode *AyStarMain_OpenList_Pop(AyStar *aystar)
{
OpenListNode *AyStarMain_OpenList_Pop(AyStar *aystar) {
// Return the item the Queue returns.. the best next OpenList item.
OpenListNode *res = (OpenListNode*)aystar->OpenListQueue.pop(&aystar->OpenListQueue);
if (res != NULL) {
OpenListNode* res = (OpenListNode*)aystar->OpenListQueue.pop(&aystar->OpenListQueue);
if (res != NULL)
Hash_Delete(&aystar->OpenListHash, res->path.node.tile, res->path.node.direction);
}
return res;
}
// Adds a node to the OpenList
// It makes a copy of node, and puts the pointer of parent in the struct
static void AyStarMain_OpenList_Add(AyStar *aystar, PathNode *parent, const AyStarNode *node, int f, int g)
{
void AyStarMain_OpenList_Add(AyStar *aystar, PathNode *parent, AyStarNode *node, int f, int g, int userdata) {
// Add a new Node to the OpenList
OpenListNode *new_node = MallocT<OpenListNode>(1);
OpenListNode* new_node = malloc(sizeof(OpenListNode));
new_node->g = g;
new_node->path.parent = parent;
new_node->path.node = *node;
@@ -82,10 +67,9 @@ static void AyStarMain_OpenList_Add(AyStar *aystar, PathNode *parent, const AySt
/*
* Checks one tile and calculate his f-value
* return values:
* AYSTAR_DONE : indicates we are done
* AYSTAR_DONE : indicates we are done
*/
int AyStarMain_CheckTile(AyStar *aystar, AyStarNode *current, OpenListNode *parent)
{
int AyStarMain_CheckTile(AyStar *aystar, AyStarNode *current, OpenListNode *parent) {
int new_f, new_g, new_h;
PathNode *closedlist_parent;
OpenListNode *check;
@@ -116,9 +100,8 @@ int AyStarMain_CheckTile(AyStar *aystar, AyStarNode *current, OpenListNode *pare
closedlist_parent = AyStarMain_ClosedList_IsInList(aystar, &parent->path.node);
// Check if this item is already in the OpenList
check = AyStarMain_OpenList_IsInList(aystar, current);
if (check != NULL) {
uint i;
if ((check = AyStarMain_OpenList_IsInList(aystar, current)) != NULL) {
int i;
// Yes, check if this g value is lower..
if (new_g > check->g) return AYSTAR_DONE;
aystar->OpenListQueue.del(&aystar->OpenListQueue, check, 0);
@@ -126,14 +109,13 @@ int AyStarMain_CheckTile(AyStar *aystar, AyStarNode *current, OpenListNode *pare
check->g = new_g;
check->path.parent = closedlist_parent;
/* Copy user data, will probably have changed */
for (i = 0; i < lengthof(current->user_data); i++) {
for (i=0;i<lengthof(current->user_data);i++)
check->path.node.user_data[i] = current->user_data[i];
}
// Readd him in the OpenListQueue
aystar->OpenListQueue.push(&aystar->OpenListQueue, check, new_f);
} else {
// A new node, add him to the OpenList
AyStarMain_OpenList_Add(aystar, closedlist_parent, current, new_f, new_g);
AyStarMain_OpenList_Add(aystar, closedlist_parent, current, new_f, new_g, 0);
}
return AYSTAR_DONE;
@@ -143,15 +125,14 @@ int AyStarMain_CheckTile(AyStar *aystar, AyStarNode *current, OpenListNode *pare
* This function is the core of AyStar. It handles one item and checks
* his neighbour items. If they are valid, they are added to be checked too.
* return values:
* AYSTAR_EMPTY_OPENLIST : indicates all items are tested, and no path
* has been found.
* AYSTAR_LIMIT_REACHED : Indicates that the max_nodes limit has been
* reached.
* AYSTAR_FOUND_END_NODE : indicates we found the end. Path_found now is true, and in path is the path found.
* AYSTAR_STILL_BUSY : indicates we have done this tile, did not found the path yet, and have items left to try.
* AYSTAR_EMPTY_OPENLIST : indicates all items are tested, and no path
* has been found.
* AYSTAR_LIMIT_REACHED : Indicates that the max_nodes limit has been
* reached.
* AYSTAR_FOUND_END_NODE : indicates we found the end. Path_found now is true, and in path is the path found.
* AYSTAR_STILL_BUSY : indicates we have done this tile, did not found the path yet, and have items left to try.
*/
int AyStarMain_Loop(AyStar *aystar)
{
int AyStarMain_Loop(AyStar *aystar) {
int i, r;
// Get the best node from OpenList
@@ -174,7 +155,7 @@ int AyStarMain_Loop(AyStar *aystar)
aystar->GetNeighbours(aystar, current);
// Go through all neighbours
for (i = 0; i < aystar->num_neighbours; i++) {
for (i=0;i<aystar->num_neighbours;i++) {
// Check and add them to the OpenList if needed
r = aystar->checktile(aystar, &aystar->neighbours[i], current);
}
@@ -182,20 +163,18 @@ int AyStarMain_Loop(AyStar *aystar)
// Free the node
free(current);
if (aystar->max_search_nodes != 0 && Hash_Size(&aystar->ClosedListHash) >= aystar->max_search_nodes) {
if (aystar->max_search_nodes != 0 && Hash_Size(&aystar->ClosedListHash) >= aystar->max_search_nodes)
/* We've expanded enough nodes */
return AYSTAR_LIMIT_REACHED;
} else {
else
// Return that we are still busy
return AYSTAR_STILL_BUSY;
}
}
/*
* This function frees the memory it allocated
*/
void AyStarMain_Free(AyStar *aystar)
{
void AyStarMain_Free(AyStar *aystar) {
aystar->OpenListQueue.free(&aystar->OpenListQueue, false);
/* 2nd argument above is false, below is true, to free the values only
* once */
@@ -210,8 +189,7 @@ void AyStarMain_Free(AyStar *aystar)
* This function make the memory go back to zero
* This function should be called when you are using the same instance again.
*/
void AyStarMain_Clear(AyStar *aystar)
{
void AyStarMain_Clear(AyStar *aystar) {
// Clean the Queue, but not the elements within. That will be done by
// the hash.
aystar->OpenListQueue.clear(&aystar->OpenListQueue, false);
@@ -227,9 +205,9 @@ void AyStarMain_Clear(AyStar *aystar)
/*
* This is the function you call to run AyStar.
* return values:
* AYSTAR_FOUND_END_NODE : indicates we found an end node.
* AYSTAR_NO_PATH : indicates that there was no path found.
* AYSTAR_STILL_BUSY : indicates we have done some checked, that we did not found the path yet, and that we still have items left to try.
* AYSTAR_FOUND_END_NODE : indicates we found an end node.
* AYSTAR_NO_PATH : indicates that there was no path found.
* AYSTAR_STILL_BUSY : indicates we have done some checked, that we did not found the path yet, and that we still have items left to try.
* When the algorithm is done (when the return value is not AYSTAR_STILL_BUSY)
* aystar->clear() is called. Note that when you stop the algorithm halfway,
* you should still call clear() yourself!
@@ -237,29 +215,27 @@ void AyStarMain_Clear(AyStar *aystar)
int AyStarMain_Main(AyStar *aystar) {
int r, i = 0;
// Loop through the OpenList
// Quit if result is no AYSTAR_STILL_BUSY or is more than loops_per_tick
// Quit if result is no AYSTAR_STILL_BUSY or is more then loops_per_tick
while ((r = aystar->loop(aystar)) == AYSTAR_STILL_BUSY && (aystar->loops_per_tick == 0 || ++i < aystar->loops_per_tick)) { }
#ifdef AYSTAR_DEBUG
switch (r) {
case AYSTAR_FOUND_END_NODE: printf("[AyStar] Found path!\n"); break;
case AYSTAR_EMPTY_OPENLIST: printf("[AyStar] OpenList run dry, no path found\n"); break;
case AYSTAR_LIMIT_REACHED: printf("[AyStar] Exceeded search_nodes, no path found\n"); break;
default: break;
}
if (r == AYSTAR_FOUND_END_NODE)
printf("[AyStar] Found path!\n");
else if (r == AYSTAR_EMPTY_OPENLIST)
printf("[AyStar] OpenList run dry, no path found\n");
else if (r == AYSTAR_LIMIT_REACHED)
printf("[AyStar] Exceeded search_nodes, no path found\n");
#endif
if (r != AYSTAR_STILL_BUSY) {
if (r != AYSTAR_STILL_BUSY)
/* We're done, clean up */
_aystar_stats_open_size = aystar->OpenListHash.size;
_aystar_stats_closed_size = aystar->ClosedListHash.size;
aystar->clear(aystar);
}
switch (r) {
case AYSTAR_FOUND_END_NODE: return AYSTAR_FOUND_END_NODE;
case AYSTAR_EMPTY_OPENLIST:
case AYSTAR_LIMIT_REACHED: return AYSTAR_NO_PATH;
default: return AYSTAR_STILL_BUSY;
}
// Check result-value
if (r == AYSTAR_FOUND_END_NODE) return AYSTAR_FOUND_END_NODE;
// Check if we have some left in the OpenList
if (r == AYSTAR_EMPTY_OPENLIST || r == AYSTAR_LIMIT_REACHED) return AYSTAR_NO_PATH;
// Return we are still busy
return AYSTAR_STILL_BUSY;
}
/*
@@ -267,19 +243,15 @@ int AyStarMain_Main(AyStar *aystar) {
* if wanted. You should make sure that clear() is called before adding nodes
* if the AyStar has been used before (though the normal main loop calls
* clear() automatically when the algorithm finishes
* g is the cost for starting with this node.
*/
void AyStarMain_AddStartNode(AyStar *aystar, AyStarNode *start_node, uint g)
{
void AyStarMain_AddStartNode(AyStar *aystar, AyStarNode *start_node) {
#ifdef AYSTAR_DEBUG
printf("[AyStar] Starting A* Algorithm from node (%d, %d, %d)\n",
TileX(start_node->tile), TileY(start_node->tile), start_node->direction);
printf("[AyStar] Starting A* Algorithm from node (%d, %d, %d)\n", GET_TILE_X(start_node->tile), GET_TILE_Y(start_node->tile), start_node->direction);
#endif
AyStarMain_OpenList_Add(aystar, NULL, start_node, 0, g);
AyStarMain_OpenList_Add(aystar, NULL, start_node, 0, 0, 0);
}
void init_AyStar(AyStar *aystar, Hash_HashProc hash, uint num_buckets)
{
void init_AyStar(AyStar* aystar, Hash_HashProc hash, uint num_buckets) {
// Allocated the Hash for the OpenList and ClosedList
init_Hash(&aystar->OpenListHash, hash, num_buckets);
init_Hash(&aystar->ClosedListHash, hash, num_buckets);
@@ -290,10 +262,10 @@ void init_AyStar(AyStar *aystar, Hash_HashProc hash, uint num_buckets)
// That is why it can stay this high
init_BinaryHeap(&aystar->OpenListQueue, 102400);
aystar->addstart = AyStarMain_AddStartNode;
aystar->main = AyStarMain_Main;
aystar->loop = AyStarMain_Loop;
aystar->free = AyStarMain_Free;
aystar->clear = AyStarMain_Clear;
aystar->checktile = AyStarMain_CheckTile;
aystar->addstart = AyStarMain_AddStartNode;
aystar->main = AyStarMain_Main;
aystar->loop = AyStarMain_Loop;
aystar->free = AyStarMain_Free;
aystar->clear = AyStarMain_Clear;
aystar->checktile = AyStarMain_CheckTile;
}

View File

@@ -1,18 +1,15 @@
/* $Id$ */
/** @file aystar.h
/*
* This file has the header for AyStar
* AyStar is a fast pathfinding routine and is used for things like
* AI_pathfinding and Train_pathfinding.
* For more information about AyStar (A* Algorithm), you can look at
* http://en.wikipedia.org/wiki/A-star_search_algorithm
* http://en.wikipedia.org/wiki/A-star_search_algorithm
*/
#ifndef AYSTAR_H
#define AYSTAR_H
#include "queue.h"
#include "tile_type.h"
//#define AYSTAR_DEBUG
enum {
@@ -28,13 +25,15 @@ enum{
AYSTAR_INVALID_NODE = -1,
};
typedef struct AyStarNode AyStarNode;
struct AyStarNode {
TileIndex tile;
int direction;
uint tile;
uint direction;
uint user_data[2];
};
// The resulting path has nodes looking like this.
typedef struct PathNode PathNode;
struct PathNode {
AyStarNode node;
// The parent of this item
@@ -44,33 +43,26 @@ struct PathNode {
// For internal use only
// We do not save the h-value, because it is only needed to calculate the f-value.
// h-value should _always_ be the distance left to the end-tile.
typedef struct OpenListNode OpenListNode;
struct OpenListNode {
int g;
PathNode path;
};
struct AyStar;
typedef struct AyStar AyStar;
/*
* This function is called to check if the end-tile is found
* return values can be:
* AYSTAR_FOUND_END_NODE : indicates this is the end tile
* AYSTAR_DONE : indicates this is not the end tile (or direction was wrong)
*/
/*
* The 2nd parameter should be OpenListNode, and NOT AyStarNode. AyStarNode is
* part of OpenListNode and so it could be accessed without any problems.
* The good part about OpenListNode is, and how AIs use it, that you can
* access the parent of the current node, and so check if you, for example
* don't try to enter the file tile with a 90-degree curve. So please, leave
* this an OpenListNode, it works just fine -- TrueLight
* AYSTAR_FOUND_END_NODE : indicates this is the end tile
* AYSTAR_DONE : indicates this is not the end tile (or direction was wrong)
*/
typedef int32 AyStar_EndNodeCheck(AyStar *aystar, OpenListNode *current);
/*
* This function is called to calculate the G-value for AyStar Algorithm.
* return values can be:
* AYSTAR_INVALID_NODE : indicates an item is not valid (e.g.: unwalkable)
* Any value >= 0 : the g-value for this tile
* AYSTAR_INVALID_NODE : indicates an item is not valid (e.g.: unwalkable)
* Any value >= 0 : the g-value for this tile
*/
typedef int32 AyStar_CalculateG(AyStar *aystar, AyStarNode *current, OpenListNode *parent);
@@ -79,7 +71,7 @@ typedef int32 AyStar_CalculateG(AyStar *aystar, AyStarNode *current, OpenListNod
* Mostly, this must result the distance (Manhattan way) between the
* current point and the end point
* return values can be:
* Any value >= 0 : the h-value for this tile
* Any value >= 0 : the h-value for this tile
*/
typedef int32 AyStar_CalculateH(AyStar *aystar, AyStarNode *current, OpenListNode *parent);
@@ -97,7 +89,7 @@ typedef void AyStar_GetNeighbours(AyStar *aystar, OpenListNode *current);
typedef void AyStar_FoundEndNode(AyStar *aystar, OpenListNode *current);
// For internal use, see aystar.c
typedef void AyStar_AddStartNode(AyStar *aystar, AyStarNode *start_node, uint g);
typedef void AyStar_AddStartNode(AyStar *aystar, AyStarNode* start_node);
typedef int AyStar_Main(AyStar *aystar);
typedef int AyStar_Loop(AyStar *aystar);
typedef int AyStar_CheckTile(AyStar *aystar, AyStarNode *current, OpenListNode *parent);
@@ -110,11 +102,11 @@ struct AyStar {
/* These should point to the application specific routines that do the
* actual work */
AyStar_CalculateG *CalculateG;
AyStar_CalculateH *CalculateH;
AyStar_GetNeighbours *GetNeighbours;
AyStar_EndNodeCheck *EndNodeCheck;
AyStar_FoundEndNode *FoundEndNode;
AyStar_CalculateG* CalculateG;
AyStar_CalculateH* CalculateH;
AyStar_GetNeighbours* GetNeighbours;
AyStar_EndNodeCheck* EndNodeCheck;
AyStar_FoundEndNode* FoundEndNode;
/* These are completely untouched by AyStar, they can be accesed by
* the application specific routines to input and output data.
@@ -142,12 +134,12 @@ struct AyStar {
/* These will contain the methods for manipulating the AyStar. Only
* main() should be called externally */
AyStar_AddStartNode *addstart;
AyStar_Main *main;
AyStar_Loop *loop;
AyStar_Free *free;
AyStar_Clear *clear;
AyStar_CheckTile *checktile;
AyStar_AddStartNode* addstart;
AyStar_Main* main;
AyStar_Loop* loop;
AyStar_Free* free;
AyStar_Clear* clear;
AyStar_CheckTile* checktile;
/* These will contain the open and closed lists */
@@ -161,7 +153,7 @@ struct AyStar {
};
void AyStarMain_AddStartNode(AyStar *aystar, AyStarNode *start_node, uint g);
void AyStarMain_AddStartNode(AyStar *aystar, AyStarNode *start_node);
int AyStarMain_Main(AyStar *aystar);
int AyStarMain_Loop(AyStar *aystar);
int AyStarMain_CheckTile(AyStar *aystar, AyStarNode *current, OpenListNode *parent);
@@ -171,7 +163,7 @@ void AyStarMain_Clear(AyStar *aystar);
/* Initialize an AyStar. You should fill all appropriate fields before
* callling init_AyStar (see the declaration of AyStar for which fields are
* internal */
void init_AyStar(AyStar *aystar, Hash_HashProc hash, uint num_buckets);
void init_AyStar(AyStar* aystar, Hash_HashProc hash, uint num_buckets);
#endif /* AYSTAR_H */
#endif

55
bemidi.cpp Normal file
View File

@@ -0,0 +1,55 @@
#ifdef __BEOS__
#include "stdafx.h"
#include "ttd.h"
#include "hal.h"
// BeOS System Includes
#include <MidiSynthFile.h>
BMidiSynthFile midiSynthFile;
static char *bemidi_start(char **parm) {
return NULL;
}
static void bemidi_stop(void) {
midiSynthFile.UnloadFile();
}
static void bemidi_play_song(const char *filename) {
bemidi_stop();
entry_ref midiRef;
get_ref_for_path(filename, &midiRef);
midiSynthFile.LoadFile(&midiRef);
midiSynthFile.Start();
}
static void bemidi_stop_song(void) {
midiSynthFile.UnloadFile();
}
static bool bemidi_is_playing(void) {
if(midiSynthFile.IsFinished() == true)
{
return 0;
} else {
return 1;
}
}
static void bemidi_set_volume(byte vol) {
fprintf(stderr, "BeMidi: Set volume not implemented\n");
}
const HalMusicDriver _bemidi_music_driver = {
bemidi_start,
bemidi_stop,
bemidi_play_song,
bemidi_stop_song,
bemidi_is_playing,
bemidi_set_volume,
};
#endif // __BEOS__

Binary file not shown.

Binary file not shown.

View File

@@ -1,4 +0,0 @@
You can place you scenarios in this dir.
This file is really here to make the Makefile happy, it should be modified to
properly handle scenarios (or maybe even not at all...).

View File

@@ -1,4 +0,0 @@
# send chat messages from the console with
# ] s i love this chat
#
alias s "say %!"

View File

@@ -1,4 +0,0 @@
echo "Setting dedicated network server settings..."
# empty the server password
server_pw = "*"
server_name = "My example dedicated gameserver"

View File

@@ -1,3 +0,0 @@
# set default server port, and have the dedicated server listen on all interfaces
server_ip = all
server_port = 3979

View File

@@ -1,2 +0,0 @@
# set the server port to the default value
server_port = 3979

View File

@@ -1,21 +0,0 @@
Scripting
---------
OpenTTD supports scripts.
local scripts:
- 'autoexec.scr' is executed on gamestart [all - use this for custom aliases per ex.]
+network scripts:
should be used to set client optimization settings:
- 'on_client.scr' is executed when you join a server [all clients]
should be used to set the servers port/ip and/or server optimization settings/patches:
- 'pre_server.scr' is executed before the servers tcp stack is started [in-game only]
- 'pre_dedicated.scr' is executed before the servers tcp stack is started [dedicated only]
should be used to set the servers name, password and so on:
- 'on_server.scr' is executed after starting a server [dedicated and in-game]
- 'on_dedicated.scr' is additionally executed after starting a server [dedicated only]
For examples how a script can look, check the .example examples.

164
bridge_gui.c Normal file
View File

@@ -0,0 +1,164 @@
#include "stdafx.h"
#include "ttd.h"
#include "window.h"
#include "gui.h"
#include "viewport.h"
#include "gfx.h"
#include "command.h"
static struct BridgeData {
int count;
TileIndex start_tile;
TileIndex end_tile;
byte type;
byte indexes[MAX_BRIDGES];
int32 costs[MAX_BRIDGES];
} _bridge;
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];
static void CcBuildBridge(bool success, uint tile, uint32 p1, uint32 p2)
{
if (success) { SndPlayTileFx(0x25, tile); }
}
static void BuildBridge(Window *w, int i)
{
DeleteWindow(w);
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));
}
static void BuildBridgeWndProc(Window *w, WindowEvent *e)
{
switch(e->event) {
case WE_PAINT: {
int i;
DrawWindowWidgets(w);
for(i=0; i < 4 && i + w->vscroll.pos < _bridge.count; i++) {
int ind = _bridge.indexes[i + w->vscroll.pos];
SET_DPARAM32(2, _bridge.costs[i + w->vscroll.pos]);
SET_DPARAM16(1, (_bridge_speeds[ind] >> 4) * 10);
SET_DPARAM16(0, _bridge_material[ind]);
DrawSprite(_bridge_sprites[ind], 3, 15 + i * 22);
DrawString(44, 15 + i*22 , STR_500D, 0);
}
} break;
case WE_KEYPRESS: {
uint i = e->keypress.keycode - '1';
if (i < 9 && i < (uint)_bridge.count) {
e->keypress.cont = false;
BuildBridge(w, i);
}
break;
}
case WE_CLICK:
if (e->click.widget == 2) {
uint ind = ((int)e->click.pt.y - 14) / 22;
if (ind < 4 && (ind += w->vscroll.pos) < (uint)_bridge.count)
BuildBridge(w, ind);
}
break;
}
}
static const Widget _build_bridge_widgets[] = {
{ WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, 7, 11, 199, 0, 13, STR_100D_SELECT_RAIL_BRIDGE, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_MATRIX, 7, 0, 188, 14, 101, 0x401, STR_101F_BRIDGE_SELECTION_CLICK},
{ WWT_SCROLLBAR, 7, 189, 199, 14, 101, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
{ WIDGETS_END},
};
static const WindowDesc _build_bridge_desc = {
-1, -1, 200, 102,
WC_BUILD_BRIDGE,WC_BUILD_TOOLBAR,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
_build_bridge_widgets,
BuildBridgeWndProc
};
static const Widget _build_road_bridge_widgets[] = {
{ WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, 7, 11, 199, 0, 13, STR_1803_SELECT_ROAD_BRIDGE, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_MATRIX, 7, 0, 188, 14, 101, 0x401, STR_101F_BRIDGE_SELECTION_CLICK},
{ WWT_SCROLLBAR, 7, 189, 199, 14, 101, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
{ WIDGETS_END},
};
static const WindowDesc _build_road_bridge_desc = {
-1, -1, 200, 102,
WC_BUILD_BRIDGE,WC_BUILD_TOOLBAR,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
_build_road_bridge_widgets,
BuildBridgeWndProc
};
void ShowBuildBridgeWindow(uint start, uint end, byte bridge_type)
{
int j = 0;
int32 ret;
uint16 errmsg;
DeleteWindowById(WC_BUILD_BRIDGE, 0);
_bridge.type = bridge_type;
_bridge.start_tile = start;
_bridge.end_tile = end;
errmsg = 0xFFFF;
// only query bridge building possibility once, result is the same for all bridges!
// 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 (ret == CMD_ERROR) {
errmsg = _error_message;
}
// check which bridges can be built
else {
int bridge_len; // length of the middle parts of the bridge
int tot_bridge_len; // total length of bridge
// get absolute bridge length
bridge_len = GetBridgeLength(start, end);
tot_bridge_len = bridge_len + 2;
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)) {
// bridge is accepted, add to list
// add to terraforming & bulldozing costs the cost of the bridge itself (not computed with DC_QUERY_COST)
_bridge.costs[j] = ret + (((int64)tot_bridge_len * _price.build_bridge * _bridge_type_price_mod[bridge_type]) >> 8);
_bridge.indexes[j] = bridge_type;
j++;
}
}
}
_bridge.count = j;
if (j != 0) {
Window *w = AllocateWindowDesc((_bridge.type & 0x80) ? &_build_road_bridge_desc : &_build_bridge_desc);
w->vscroll.cap = 4;
w->vscroll.count = (byte)j;
} else {
ShowErrorMessage(errmsg, STR_5015_CAN_T_BUILD_BRIDGE_HERE, GET_TILE_X(end) * 16, GET_TILE_Y(end) * 16);
}
}

File diff suppressed because it is too large Load Diff

812
clear_cmd.c Normal file
View File

@@ -0,0 +1,812 @@
#include "stdafx.h"
#include "ttd.h"
#include "viewport.h"
#include "command.h"
typedef struct TerraformerHeightMod {
TileIndex tile;
byte height;
} TerraformerHeightMod;
typedef struct TerraformerState {
int height[4];
uint32 flags;
int direction;
int modheight_count;
int tile_table_count;
int32 cost;
TileIndex *tile_table;
TerraformerHeightMod *modheight;
} TerraformerState;
static int TerraformAllowTileProcess(TerraformerState *ts, TileIndex tile)
{
TileIndex *t;
int count;
if ((GET_TILE_X(tile) == TILE_X_MAX) || (GET_TILE_Y(tile) == TILE_Y_MAX))
return -1;
t = ts->tile_table;
for(count = ts->tile_table_count; count != 0; count--,t++) {
if (*t == tile)
return 0;
}
return 1;
}
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;
}
return _map_type_and_height[tile] & 0xF;
}
static void TerraformAddDirtyTile(TerraformerState *ts, TileIndex tile)
{
int count;
TileIndex *t;
count = ts->tile_table_count;
if (count >= 625)
return;
for(t = ts->tile_table; count != 0; count--,t++) {
if (*t == tile)
return;
}
ts->tile_table[ts->tile_table_count++] = tile;
}
static void TerraformAddDirtyTileAround(TerraformerState *ts, TileIndex tile)
{
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, uint tile, int mode)
{
int r;
int32 ret;
assert(tile < TILES_X * TILES_Y);
if ((r=TerraformAllowTileProcess(ts, tile)) <= 0)
return r;
if ((_map_type_and_height[tile] >> 4) == MP_RAILWAY) {
static const byte _railway_modes[4] = {8, 0x10, 4, 0x20};
static const byte _railway_dangslopes[4] = {0xd, 0xe, 7, 0xb};
// 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 the other corner.
if ((GetTileSlope(tile, NULL)&0xF) == _railway_dangslopes[mode]) {
_error_message = STR_1008_MUST_REMOVE_RAILROAD_TRACK;
return -1;
}
// If we have a single diagonal track there, the other side of
// tile can be terraformed.
if ((_map5[tile]&~0x40) == _railway_modes[mode])
return 0;
}
ret = DoCommandByTile(tile, 0,0, ts->flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR);
if (ret == CMD_ERROR) {
_terraform_err_tile = tile;
return -1;
}
ts->cost += ret;
if (ts->tile_table_count >= 625)
return -1;
ts->tile_table[ts->tile_table_count++] = tile;
return 0;
}
static bool TerraformTileHeight(TerraformerState *ts, uint tile, int height)
{
int nh;
TerraformerHeightMod *mod;
int count;
assert(tile < TILES_X * TILES_Y);
if (height < 0) {
_error_message = STR_1003_ALREADY_AT_SEA_LEVEL;
return false;
}
_error_message = STR_1004_TOO_HIGH;
if (height > 0xF)
return false;
nh = TerraformGetHeightOfTile(ts, tile);
if (nh < 0 || height == nh)
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(;;) {
if (count == 0) {
if (ts->modheight_count >= 576)
return false;
ts->modheight_count++;
break;
}
if (mod->tile == (TileIndex)tile)
break;
mod++;
count--;
}
mod->tile = (TileIndex)tile;
mod->height = (byte)height;
ts->cost += _price.terraform;
{
int direction = ts->direction, r;
const TileIndexDiff *ttm;
static const TileIndexDiff _terraform_tilepos[5] = {TILE_XY(1,0), TILE_XY(-2,0), TILE_XY(1,1), TILE_XY(0,-2), 0 };
for(ttm = _terraform_tilepos; *ttm != 0; ttm++) {
tile += *ttm;
r = TerraformGetHeightOfTile(ts, tile);
if (r != height && r-direction != height && r+direction != height) {
if (!TerraformTileHeight(ts, tile, r+direction))
return false;
}
}
}
return true;
}
/* Terraform land
* p1 - corners
* p2 - direction
*/
int32 CmdTerraformLand(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
TerraformerState ts;
uint tile;
int direction;
TerraformerHeightMod modheight_data[576];
TileIndex tile_table_data[625];
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
_error_message = INVALID_STRING_ID;
_terraform_err_tile = 0;
ts.direction = direction = p2 ? 1 : -1;
ts.flags = flags;
ts.modheight_count = ts.tile_table_count = 0;
ts.cost = 0;
ts.modheight = modheight_data;
ts.tile_table = tile_table_data;
tile = TILE_FROM_XY(x,y);
if (p1 & 1) {
if (!TerraformTileHeight(&ts, tile+TILE_XY(1,0),
(_map_type_and_height[tile+TILE_XY(1,0)]&0xF) + direction))
return CMD_ERROR;
}
if (p1 & 2) {
if (!TerraformTileHeight(&ts, tile+TILE_XY(1,1),
(_map_type_and_height[tile+TILE_XY(1,1)]&0xF) + direction))
return CMD_ERROR;
}
if (p1 & 4) {
if (!TerraformTileHeight(&ts, tile+TILE_XY(0,1),
(_map_type_and_height[tile+TILE_XY(0,1)]&0xF) + direction))
return CMD_ERROR;
}
if (p1 & 8) {
if (!TerraformTileHeight(&ts, tile+TILE_XY(0,0),
(_map_type_and_height[tile+TILE_XY(0,0)]&0xF) + direction))
return CMD_ERROR;
}
if (direction == -1) {
/* Check if tunnel would take damage */
int count;
TileIndex *ti = ts.tile_table;
for(count = ts.tile_table_count; count != 0; count--, ti++) {
uint z, t;
uint tile = *ti;
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 + TILE_XY(1,1));
if (t <= z) z = t;
t = TerraformGetHeightOfTile(&ts, tile + TILE_XY(0,1));
if (t <= z) z = t;
if (!CheckTunnelInWay(tile, z*8))
return_cmd_error(STR_1002_EXCAVATION_WOULD_DAMAGE);
}
}
if (flags & DC_EXEC) {
/* Clear the landscape at the tiles */
{
int count;
TileIndex *ti = ts.tile_table;
for(count = ts.tile_table_count; count != 0; count--, ti++) {
DoCommandByTile(*ti, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
}
}
/* change the height */
{
int count;
TerraformerHeightMod *mod;
uint til;
mod = ts.modheight;
for(count = ts.modheight_count; count != 0; count--, mod++) {
til = mod->tile;
// Change tile height
_map_type_and_height[til] = (_map_type_and_height[til]&~0x0F)|mod->height;
TerraformAddDirtyTileAround(&ts, til);
}
}
/* finally mark the dirty tiles dirty */
{
int count;
TileIndex *ti = ts.tile_table;
for(count = ts.tile_table_count; count != 0; count--, ti++) {
MarkTileDirtyByTile(*ti);
}
}
}
return ts.cost;
}
/*
* p1 - start
*/
int32 CmdLevelLand(int ex, int ey, uint32 flags, uint32 p1, uint32 p2)
{
int size_x, size_y;
int sx, sy;
uint h, curh;
uint tile;
int32 ret, cost, money;
// remember level height
h = _map_type_and_height[p1]&0xF;
ex >>= 4; ey >>= 4;
// make sure sx,sy are smaller than ex,ey
sx = GET_TILE_X(p1);
sy = GET_TILE_Y(p1);
if (ex < sx) intswap(ex, sx);
if (ey < sy) intswap(ey, sy);
tile = TILE_XY(sx,sy);
size_x = ex-sx+1;
size_y = ey-sy+1;
money = GetAvailableMoneyForCommand();
cost = 0;
BEGIN_TILE_LOOP(tile2, size_x, size_y, tile)
curh = _map_type_and_height[tile2]&0xF;
while (curh != h) {
ret = DoCommandByTile(tile2, 8, (curh > h)?0:1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND);
if (ret == CMD_ERROR) break;
cost += ret;
if (flags & DC_EXEC) {
if ((money -= ret) < 0) {
_additional_cash_required = ret;
return cost - ret;
}
DoCommandByTile(tile2, 8, (curh > h)?0:1, flags, CMD_TERRAFORM_LAND);
}
curh += (curh > h) ? -1 : 1;
}
END_TILE_LOOP(tile2, size_x, size_y, tile)
if (cost == 0) return CMD_ERROR;
return cost;
}
/* Purchase a land area
* p1 = unused
* p2 = unused
*/
int32 CmdPurchaseLandArea(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
uint tile;
int32 cost;
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
tile = TILE_FROM_XY(x,y);
if (!EnsureNoVehicle(tile))
return CMD_ERROR;
if (IS_TILETYPE(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);
if (cost == CMD_ERROR)
return CMD_ERROR;
if (flags & DC_EXEC) {
ModifyTile(tile,
MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5,
3 /* map5 */
);
}
return cost + _price.purchase_land * 10;
}
int32 ClearTile_Clear(uint tile, byte flags) {
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[_map5[tile] & 0x1F];
if (flags & DC_EXEC)
DoClearSquare(tile);
if (price == NULL)
return 0;
return *price;
}
int32 CmdSellLandArea(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
uint tile;
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
tile = TILE_FROM_XY(x,y);
if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER)
return CMD_ERROR;
if (!EnsureNoVehicle(tile))
return CMD_ERROR;
if (flags & DC_EXEC)
DoClearSquare(tile);
return - _price.purchase_land*2;
}
#include "table/clear_land.h"
void DrawClearLandTile(TileInfo *ti, byte set)
{
DrawGroundSprite(0xF54 + _tileh_to_sprite[ti->tileh] + set * 19);
}
void DrawHillyLandTile(TileInfo *ti)
{
if (ti->tileh != 0) {
DrawGroundSprite(0xFA0 + _tileh_to_sprite[ti->tileh]);
} else {
DrawGroundSprite(_landscape_clear_sprites[((ti->x^ti->y) >> 4) & 0x7]);
}
}
void DrawClearLandFence(TileInfo *ti, byte img)
{
byte z = ti->z;
if (ti->tileh & 2) {
z += 8;
if (ti->tileh == 0x17)
z += 8;
}
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 (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((ti->map5 & (7<<2)) >> 2) {
case 0:
DrawClearLandTile(ti, (ti->map5 & 3));
break;
case 1:
DrawHillyLandTile(ti);
break;
case 2:
DrawGroundSprite(0xFB7 + _tileh_to_sprite[ti->tileh]);
break;
case 3:
DrawGroundSprite( _clear_land_sprites_1[_map3_lo[ti->tile]&0xF] + _tileh_to_sprite[ti->tileh]);
break;
case 4:
DrawGroundSprite( _clear_land_sprites_2[ti->map5&3] + _tileh_to_sprite[ti->tileh]);
break;
case 5:
DrawGroundSprite( _clear_land_sprites_3[ti->map5&3] + _tileh_to_sprite[ti->tileh]);
break;
}
DrawClearLandFence(ti, _map3_hi[ti->tile] >> 2);
}
uint GetSlopeZ_Clear(TileInfo *ti) { return GetPartialZ(ti->x&0xF, ti->y&0xF, ti->tileh) + ti->z; }
uint GetSlopeTileh_Clear(TileInfo *ti)
{
return ti->tileh;
}
static void GetAcceptedCargo_Clear(uint tile, AcceptedCargo *ac)
{
/* unused */
}
static void AnimateTile_Clear(uint tile)
{
/* unused */
}
void TileLoopClearHelper(uint tile)
{
byte img_1, img_2;
static byte img_by_map5[8] = { 0,0,0,2, 1,1,0,0, };
uint dirty = -1;
img_1 = 0;
if (IS_TILETYPE(tile, MP_CLEAR)) {
img_1 = img_by_map5[(_map5[tile] & 0x1C) >> 2];
} else if (IS_TILETYPE(tile, MP_TREES) && (_map2[tile] & 0x30) == 0x20) {
img_1 = 1;
}
img_2 = 0;
if (IS_TILETYPE(TILE_ADDXY(tile, 1, 0), MP_CLEAR)) {
img_2 = img_by_map5[(_map5[TILE_ADDXY(tile, 1, 0)] & 0x1C) >> 2];
} else if (IS_TILETYPE(TILE_ADDXY(tile, 1, 0), MP_TREES) && (_map2[TILE_ADDXY(tile, 1, 0)] & 0x30) == 0x20) {
img_2 = 1;
}
if (!(_map3_hi[tile] & 0xE0)) {
if ( (img_1&2) != (img_2&2) ) {
_map3_hi[tile] |= 3 << 5;
dirty = tile;
}
} else {
if (img_1 == 1 && img_2 == 1) {
_map3_hi[tile] &= ~(3 << 5);
dirty = tile;
}
}
img_2 = 0;
if (IS_TILETYPE(TILE_ADDXY(tile, 0, 1), MP_CLEAR)) {
img_2 = img_by_map5[(_map5[TILE_ADDXY(tile, 0, 1)] & 0x1C) >> 2];
} else if (IS_TILETYPE(TILE_ADDXY(tile, 0, 1), MP_TREES) && (_map2[TILE_ADDXY(tile, 0, 1)] & 0x30) == 0x20) {
img_2 = 1;
}
if (!(_map3_hi[tile] & 0x1C)) {
if ( (img_1&2) != (img_2&2) ) {
_map3_hi[tile] |= 3 << 2;
dirty = tile;
}
} else {
if (img_1 == 1 && img_2 == 1) {
_map3_hi[tile] &= ~(3 << 2);
dirty = tile;
}
}
if (dirty != -1)
MarkTileDirtyByTile(dirty);
}
/* convert into snowy tiles */
static void TileLoopClearAlps(uint tile)
{
int k;
byte m5,tmp;
/* distance from snow line, in steps of 8 */
k = GetTileZ(tile) - _opt.snow_line;
m5 = _map5[tile] & 0x1C;
tmp = _map5[tile] & 3;
if (k < -8) {
/* snow_m2_down */
if (m5 != 0x10)
return;
if (tmp == 0)
m5 = 3;
} else if (k == -8) {
/* snow_m1 */
if (m5 != 0x10) {
m5 = 0x10;
} else if (tmp != 0) {
m5 = (tmp - 1) + 0x10;
} else
return;
} else if (k < 8) {
/* snow_0 */
if (m5 != 0x10) {
m5 = 0x10;
} else if (tmp != 1) {
m5 = 1;
if (tmp != 0)
m5 = tmp - 1;
m5 += 0x10;
} else
return;
} else if (k == 8) {
/* snow_p1 */
if (m5 != 0x10) {
m5 = 0x10;
} else if (tmp != 2) {
m5 = 2;
if (tmp <= 2)
m5 = tmp + 1;
m5 += 0x10;
} else
return;
} else {
/* snow_p2_up */
if (m5 != 0x10) {
m5 = 0x10;
} else if (tmp != 3) {
m5 = tmp + 1 + 0x10;
} else
return;
}
_map5[tile] = m5;
MarkTileDirtyByTile(tile);
}
static void TileLoopClearDesert(uint tile)
{
if ( (_map5[tile] & 0x1C) == 0x14)
return;
if (GetMapExtraBits(tile) == 1) {
_map5[tile] = 0x17;
} else {
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(uint tile)
{
byte m5,m3;
TileLoopClearHelper(tile);
if (_opt.landscape == LT_DESERT) {
TileLoopClearDesert(tile);
} else if (_opt.landscape == LT_HILLY) {
TileLoopClearAlps(tile);
}
m5 = _map5[tile];
if ( (m5 & 0x1C) == 0x10 || (m5 & 0x1C) == 0x14)
return;
if ( (m5 & 0x1C) != 0xC) {
if ( (m5 & 3) == 3)
return;
if (_game_mode != GM_EDITOR) {
m5 += 0x20;
if (m5 >= 0x20) {
// Didn't overflow
_map5[tile] = m5;
return;
}
/* did overflow, so continue */
} else {
m5 = ((byte)Random() > 21) ? (2) : (6);
}
m5++;
} else if (_game_mode != GM_EDITOR) {
/* handle farm field */
m5 += 0x20;
if (m5 >= 0x20) {
// Didn't overflow
_map5[tile] = m5;
return;
}
/* overflowed */
m3 = _map3_lo[tile] + 1;
assert( (m3 & 0xF) != 0);
if ( (m3 & 0xF) >= 9) /* NOTE: will not work properly if m3&0xF == 0xF */
m3 &= ~0xF;
_map3_lo[tile] = m3;
}
_map5[tile] = m5;
MarkTileDirtyByTile(tile);
}
void GenerateClearTile()
{
int i,j;
uint tile,tile_new;
uint32 r;
/* add hills */
i = (Random() & 0x3FF) | 0x400;
do {
tile = TILE_MASK(Random());
if (IS_TILETYPE(tile, MP_CLEAR))
_map5[tile] = (byte)((_map5[tile] & ~(3<<2)) | (1<<2));
} while (--i);
/* add grey squares */
i = (Random() & 0x7F) | 0x80;
do {
r = Random();
tile = TILE_MASK(r);
if (IS_TILETYPE(tile, MP_CLEAR)) {
j = ((r >> 16) & 0xF) + 5;
for(;;) {
_map5[tile] = (byte)((_map5[tile] & ~(3<<2)) | (2<<2));
do {
if (--j == 0) goto get_out;
tile_new = tile + _tileoffs_by_dir[Random() & 3];
} while (!IS_TILETYPE(tile_new, MP_CLEAR));
tile = tile_new;
}
get_out:;
}
} while (--i);
}
static void ClickTile_Clear(uint tile)
{
/* not used */
}
uint32 GetTileTrackStatus_Clear(uint tile, TransportType mode)
{
return 0;
}
static const StringID _clear_land_str[4+8-1] = {
STR_080B_ROUGH_LAND,
STR_080A_ROCKS,
STR_080E_FIELDS,
STR_080F_SNOW_COVERED_LAND,
STR_0810_DESERT,
0,
0,
STR_080C_BARE_LAND,
STR_080D_GRASS,
STR_080D_GRASS,
STR_080D_GRASS,
};
static void GetTileDesc_Clear(uint tile, TileDesc *td)
{
int i = (_map5[tile]>>2) & 7;
if (i == 0)
i = (_map5[tile] & 3) + 8;
td->str = _clear_land_str[i - 1];
td->owner = _map_owner[tile];
}
static void ChangeTileOwner_Clear(uint tile, byte old_player, byte new_player)
{
return;
}
void InitializeClearLand() {
_opt.snow_line = _patches.snow_line_height * 8;
}
const TileTypeProcs _tile_type_clear_procs = {
DrawTile_Clear, /* draw_tile_proc */
GetSlopeZ_Clear, /* get_slope_z_proc */
ClearTile_Clear, /* clear_tile_proc */
GetAcceptedCargo_Clear, /* get_accepted_cargo_proc */
GetTileDesc_Clear, /* get_tile_desc_proc */
GetTileTrackStatus_Clear, /* get_tile_track_status_proc */
ClickTile_Clear, /* click_tile_proc */
AnimateTile_Clear, /* animate_tile_proc */
TileLoop_Clear, /* tile_loop_clear */
ChangeTileOwner_Clear, /* change_tile_owner_clear */
NULL, /* get_produced_cargo_proc */
NULL, /* vehicle_enter_tile_proc */
NULL, /* vehicle_leave_tile_proc */
GetSlopeTileh_Clear, /* get_slope_tileh_proc */
};

510
command.c Normal file
View File

@@ -0,0 +1,510 @@
#include "stdafx.h"
#include "ttd.h"
#include "gui.h"
#include "command.h"
#include "player.h"
#define DEF_COMMAND(yyyy) int32 yyyy(int x, int y, uint32 flags, uint32 p1, uint32 p2)
DEF_COMMAND(CmdBuildRailroadTrack);
DEF_COMMAND(CmdRemoveRailroadTrack);
DEF_COMMAND(CmdBuildSingleRail);
DEF_COMMAND(CmdRemoveSingleRail);
DEF_COMMAND(CmdLandscapeClear);
DEF_COMMAND(CmdBuildBridge);
DEF_COMMAND(CmdBuildRailroadStation);
DEF_COMMAND(CmdRemoveFromRailroadStation);
DEF_COMMAND(CmdConvertRail);
DEF_COMMAND(CmdBuildSignals);
DEF_COMMAND(CmdRemoveSignals);
DEF_COMMAND(CmdTerraformLand);
DEF_COMMAND(CmdPurchaseLandArea);
DEF_COMMAND(CmdSellLandArea);
DEF_COMMAND(CmdBuildTunnel);
DEF_COMMAND(CmdBuildTrainDepot);
DEF_COMMAND(CmdBuildTrainCheckpoint);
DEF_COMMAND(CmdRenameCheckpoint);
DEF_COMMAND(CmdRemoveTrainCheckpoint);
DEF_COMMAND(CmdBuildTruckStation);
DEF_COMMAND(CmdBuildBusStation);
DEF_COMMAND(CmdBuildLongRoad);
DEF_COMMAND(CmdRemoveLongRoad);
DEF_COMMAND(CmdBuildRoad);
DEF_COMMAND(CmdRemoveRoad);
DEF_COMMAND(CmdBuildRoadDepot);
DEF_COMMAND(CmdBuildAirport);
DEF_COMMAND(CmdBuildDock);
DEF_COMMAND(CmdBuildShipDepot);
DEF_COMMAND(CmdBuildBuoy);
DEF_COMMAND(CmdPlantTree);
DEF_COMMAND(CmdBuildRailVehicle);
DEF_COMMAND(CmdMoveRailVehicle);
DEF_COMMAND(CmdStartStopTrain);
DEF_COMMAND(CmdSellRailWagon);
DEF_COMMAND(CmdTrainGotoDepot);
DEF_COMMAND(CmdForceTrainProceed);
DEF_COMMAND(CmdReverseTrainDirection);
DEF_COMMAND(CmdModifyOrder);
DEF_COMMAND(CmdSkipOrder);
DEF_COMMAND(CmdDeleteOrder);
DEF_COMMAND(CmdInsertOrder);
DEF_COMMAND(CmdChangeTrainServiceInt);
DEF_COMMAND(CmdRestoreOrderIndex);
DEF_COMMAND(CmdBuildIndustry);
//DEF_COMMAND(CmdDestroyIndustry);
DEF_COMMAND(CmdBuildCompanyHQ);
DEF_COMMAND(CmdDestroyCompanyHQ);
DEF_COMMAND(CmdSetPlayerFace);
DEF_COMMAND(CmdSetPlayerColor);
DEF_COMMAND(CmdIncreaseLoan);
DEF_COMMAND(CmdDecreaseLoan);
DEF_COMMAND(CmdWantEnginePreview);
DEF_COMMAND(CmdNameVehicle);
DEF_COMMAND(CmdRenameEngine);
DEF_COMMAND(CmdChangeCompanyName);
DEF_COMMAND(CmdChangePresidentName);
DEF_COMMAND(CmdRenameStation);
DEF_COMMAND(CmdSellAircraft);
DEF_COMMAND(CmdStartStopAircraft);
DEF_COMMAND(CmdBuildAircraft);
DEF_COMMAND(CmdSendAircraftToHangar);
DEF_COMMAND(CmdChangeAircraftServiceInt);
DEF_COMMAND(CmdRefitAircraft);
DEF_COMMAND(CmdPlaceSign);
DEF_COMMAND(CmdRenameSign);
DEF_COMMAND(CmdBuildRoadVeh);
DEF_COMMAND(CmdStartStopRoadVeh);
DEF_COMMAND(CmdSellRoadVeh);
DEF_COMMAND(CmdSendRoadVehToDepot);
DEF_COMMAND(CmdTurnRoadVeh);
DEF_COMMAND(CmdChangeRoadVehServiceInt);
DEF_COMMAND(CmdPause);
DEF_COMMAND(CmdResume);
DEF_COMMAND(CmdBuyShareInCompany);
DEF_COMMAND(CmdSellShareInCompany);
DEF_COMMAND(CmdBuyCompany);
DEF_COMMAND(CmdBuildTown);
DEF_COMMAND(CmdRenameTown);
DEF_COMMAND(CmdDoTownAction);
DEF_COMMAND(CmdSetRoadDriveSide);
DEF_COMMAND(CmdSetTownNameType);
DEF_COMMAND(CmdChangeDifficultyLevel);
DEF_COMMAND(CmdStartStopShip);
DEF_COMMAND(CmdSellShip);
DEF_COMMAND(CmdBuildShip);
DEF_COMMAND(CmdSendShipToDepot);
DEF_COMMAND(CmdChangeShipServiceInt);
DEF_COMMAND(CmdRefitShip);
DEF_COMMAND(CmdStartNewGame);
DEF_COMMAND(CmdLoadGame);
DEF_COMMAND(CmdCreateScenario);
DEF_COMMAND(CmdSetSinglePlayer);
DEF_COMMAND(CmdSetNewLandscapeType);
DEF_COMMAND(CmdGenRandomNewGame);
DEF_COMMAND(CmdCloneOrder);
DEF_COMMAND(CmdClearArea);
DEF_COMMAND(CmdMoneyCheat);
DEF_COMMAND(CmdBuildCanal);
DEF_COMMAND(CmdBuildLock);
DEF_COMMAND(CmdPlayerCtrl);
DEF_COMMAND(CmdLevelLand);
DEF_COMMAND(CmdRefitRailVehicle);
DEF_COMMAND(CmdStartScenario);
DEF_COMMAND(CmdBuildManySignals);
/* The master command table */
static CommandProc * const _command_proc_table[] = {
CmdBuildRailroadTrack, /* 0 */
CmdRemoveRailroadTrack, /* 1 */
CmdBuildSingleRail, /* 2 */
CmdRemoveSingleRail, /* 3 */
CmdLandscapeClear, /* 4 */
CmdBuildBridge, /* 5 */
CmdBuildRailroadStation, /* 6 */
CmdBuildTrainDepot, /* 7 */
CmdBuildSignals, /* 8 */
CmdRemoveSignals, /* 9 */
CmdTerraformLand, /* 10 */
CmdPurchaseLandArea, /* 11 */
CmdSellLandArea, /* 12 */
CmdBuildTunnel, /* 13 */
CmdRemoveFromRailroadStation, /* 14 */
CmdConvertRail, /* 15 */
CmdBuildTrainCheckpoint, /* 16 */
CmdRenameCheckpoint, /* 17 */
CmdRemoveTrainCheckpoint, /* 18 */
CmdBuildTruckStation, /* 19 */
NULL, /* 20 */
CmdBuildBusStation, /* 21 */
NULL, /* 22 */
CmdBuildLongRoad, /* 23 */
CmdRemoveLongRoad, /* 24 */
CmdBuildRoad, /* 25 */
CmdRemoveRoad, /* 26 */
CmdBuildRoadDepot, /* 27 */
NULL, /* 28 */
CmdBuildAirport, /* 29 */
CmdBuildDock, /* 30 */
CmdBuildShipDepot, /* 31 */
CmdBuildBuoy, /* 32 */
CmdPlantTree, /* 33 */
CmdBuildRailVehicle, /* 34 */
CmdMoveRailVehicle, /* 35 */
CmdStartStopTrain, /* 36 */
NULL, /* 37 */
CmdSellRailWagon, /* 38 */
CmdTrainGotoDepot, /* 39 */
CmdForceTrainProceed, /* 40 */
CmdReverseTrainDirection, /* 41 */
CmdModifyOrder, /* 42 */
CmdSkipOrder, /* 43 */
CmdDeleteOrder, /* 44 */
CmdInsertOrder, /* 45 */
CmdChangeTrainServiceInt, /* 46 */
CmdBuildIndustry, /* 47 */
CmdBuildCompanyHQ, /* 48 */
CmdSetPlayerFace, /* 49 */
CmdSetPlayerColor, /* 50 */
CmdIncreaseLoan, /* 51 */
CmdDecreaseLoan, /* 52 */
CmdWantEnginePreview, /* 53 */
CmdNameVehicle, /* 54 */
CmdRenameEngine, /* 55 */
CmdChangeCompanyName, /* 56 */
CmdChangePresidentName, /* 57 */
CmdRenameStation, /* 58 */
CmdSellAircraft, /* 59 */
CmdStartStopAircraft, /* 60 */
CmdBuildAircraft, /* 61 */
CmdSendAircraftToHangar, /* 62 */
CmdChangeAircraftServiceInt, /* 63 */
CmdRefitAircraft, /* 64 */
CmdPlaceSign, /* 65 */
CmdRenameSign, /* 66 */
CmdBuildRoadVeh, /* 67 */
CmdStartStopRoadVeh, /* 68 */
CmdSellRoadVeh, /* 69 */
CmdSendRoadVehToDepot, /* 70 */
CmdTurnRoadVeh, /* 71 */
CmdChangeRoadVehServiceInt, /* 72 */
CmdPause, /* 73 */
CmdBuyShareInCompany, /* 74 */
CmdSellShareInCompany, /* 75 */
CmdBuyCompany, /* 76 */
CmdBuildTown, /* 77 */
NULL, /* 78 */
NULL, /* 79 */
CmdRenameTown, /* 80 */
CmdDoTownAction, /* 81 */
CmdSetRoadDriveSide, /* 82 */
CmdSetTownNameType, /* 83 */
NULL, /* 84 */
CmdChangeDifficultyLevel, /* 85 */
CmdStartStopShip, /* 86 */
CmdSellShip, /* 87 */
CmdBuildShip, /* 88 */
CmdSendShipToDepot, /* 89 */
CmdChangeShipServiceInt, /* 90 */
CmdRefitShip, /* 91 */
CmdStartNewGame, /* 92 */
CmdLoadGame, /* 93 */
CmdCreateScenario, /* 94 */
CmdSetSinglePlayer, /* 95 */
NULL, /* 96 */
CmdSetNewLandscapeType, /* 97 */
CmdGenRandomNewGame, /* 98 */
CmdCloneOrder, /* 99 */
CmdClearArea, /* 100 */
CmdResume, /* 101 */
CmdMoneyCheat, /* 102 */
CmdBuildCanal, /* 103 */
CmdPlayerCtrl, /* 104 */
CmdLevelLand, /* 105 */
CmdRefitRailVehicle, /* 106 */
CmdRestoreOrderIndex, /* 107 */
CmdBuildLock, /* 108 */
CmdStartScenario, /* 109 */
CmdBuildManySignals, /* 110 */
//CmdDestroyIndustry, /* 109 */
CmdDestroyCompanyHQ, /* 111 */
};
int32 DoCommandByTile(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc)
{
return DoCommand(GET_TILE_X(tile)*16, GET_TILE_Y(tile)*16, p1, p2, flags, procc);
}
//extern void _stdcall Sleep(int s);
int32 DoCommand(int x, int y, uint32 p1, uint32 p2, uint32 flags, uint procc)
{
int32 res;
CommandProc *proc;
proc = _command_proc_table[procc];
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++;
// only execute the test call if it's toplevel, or we're not execing.
if (_docommand_recursive == 1 || !(flags & DC_EXEC) || (flags & DC_FORCETEST) ) {
res = proc(x, y, flags&~DC_EXEC, p1, p2);
if ((uint32)res >> 16 == 0x8000) {
if (res & 0xFFFF) _error_message = res & 0xFFFF;
goto error;
}
if (_docommand_recursive == 1) {
if (!(flags&DC_QUERY_COST) && res != 0 && !CheckPlayerHasMoney(res))
goto error;
}
if (!(flags & DC_EXEC)) {
_docommand_recursive--;
return res;
}
}
// execute the command here.
_yearly_expenses_type = 0;
res = proc(x, y, flags, p1, p2);
if ((uint32)res >> 16 == 0x8000) {
if (res & 0xFFFF) _error_message = res & 0xFFFF;
error:
_docommand_recursive--;
return CMD_ERROR;
}
// if toplevel, subtract the money.
if (--_docommand_recursive == 0) {
SubtractMoneyFromPlayer(res);
}
return res;
}
int32 GetAvailableMoneyForCommand()
{
uint pid = _current_player;
if (pid >= MAX_PLAYERS) return 0x7FFFFFFF; // max int
return DEREF_PLAYER(pid)->player_money;
}
// toplevel network safe docommand function for the current player. must not be called recursively.
// the callback is called when the command succeeded or failed.
bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback, uint32 cmd)
{
int32 res = 0,res2;
CommandProc *proc;
uint32 flags;
bool notest;
int x = GET_TILE_X(tile)*16;
int y = GET_TILE_Y(tile)*16;
assert(_docommand_recursive == 0);
if (_networking && !(cmd & CMD_NET_INSTANT) && _pause) {
// When the game is paused, and we are in a network game
// we do not allow any commands. This is because
// of some technical reasons
ShowErrorMessage(-1, STR_MULTIPLAYER_PAUSED, x, y);
_docommand_recursive = 0;
return true;
}
_error_message = INVALID_STRING_ID;
_error_message_2 = cmd >> 16;
_additional_cash_required = 0;
// spectator has no rights.
if (_current_player == OWNER_SPECTATOR) {
ShowErrorMessage(_error_message, _error_message_2, x, y);
return false;
}
flags = 0;
if (cmd & CMD_AUTO) flags |= DC_AUTO;
if (cmd & CMD_NO_WATER) flags |= DC_NO_WATER;
// get pointer to command handler
assert((cmd & 0xFF) < lengthof(_command_proc_table));
proc = _command_proc_table[cmd & 0xFF];
// this command is a notest command?
notest =
(cmd & 0xFF) == CMD_CLEAR_AREA ||
(cmd & 0xFF) == CMD_CONVERT_RAIL ||
(cmd & 0xFF) == CMD_LEVEL_LAND ||
(cmd & 0xFF) == CMD_TRAIN_GOTO_DEPOT;
if (_networking && (cmd & CMD_ASYNC)) notest = true;
_docommand_recursive = 1;
// cost estimation only?
if (_shift_pressed && _current_player == _local_player && !(cmd & CMD_DONT_NETWORK)) {
// estimate the cost.
res = proc(x, y, flags, p1, p2);
if ((uint32)res >> 16 == 0x8000) {
if (res & 0xFFFF) _error_message = res & 0xFFFF;
ShowErrorMessage(_error_message, _error_message_2, x, y);
} else {
ShowEstimatedCostOrIncome(res, x, y);
}
_docommand_recursive = 0;
return false;
}
// unless the command is a notest command, check if it can be executed.
if (!notest) {
// first test if the command can be executed.
res = proc(x,y, flags, p1, p2);
if ((uint32)res >> 16 == 0x8000) {
if (res & 0xFFFF) _error_message = res & 0xFFFF;
goto show_error;
}
// no money?
if (res != 0 && !CheckPlayerHasMoney(res)) goto show_error;
}
// put the command in a network queue and execute it later?
if (_networking && !(cmd & CMD_DONT_NETWORK)) {
if (!(cmd & CMD_NET_INSTANT)) {
NetworkSendCommand(tile, p1, p2, cmd, callback);
_docommand_recursive = 0;
return true;
} else {
// Instant Command ... Relay and Process then
NetworkSendCommand(tile, p1, p2, cmd, callback);
}
}
// update last build coordinate of player.
if ( tile != 0 && _current_player < MAX_PLAYERS) DEREF_PLAYER(_current_player)->last_build_coordinate = tile;
// actually try and execute the command.
_yearly_expenses_type = 0;
res2 = proc(x,y, flags|DC_EXEC, p1, p2);
if (!notest) {
assert(res == res2); // sanity check
} else {
if ((uint32)res2 >> 16 == 0x8000) {
if (res2 & 0xFFFF) _error_message = res2 & 0xFFFF;
goto show_error;
}
}
SubtractMoneyFromPlayer(res2);
if (_current_player == _local_player && _game_mode != GM_EDITOR) {
if (res2 != 0)
ShowCostOrIncomeAnimation(x, y, GetSlopeZ(x, y), res2);
if (_additional_cash_required) {
SET_DPARAM32(0, _additional_cash_required);
ShowErrorMessage(STR_0003_NOT_ENOUGH_CASH_REQUIRES, _error_message_2, x,y);
if (res2 == 0) goto callb_err;
}
}
_docommand_recursive = 0;
if (callback) callback(true, tile, p1, p2);
return true;
show_error:
// show error message if the command fails?
if (_current_player == _local_player && _error_message_2 != 0)
ShowErrorMessage(_error_message, _error_message_2, x,y);
callb_err:
_docommand_recursive = 0;
if (callback) callback(false, tile, p1, p2);
return false;
}

183
command.h Normal file
View File

@@ -0,0 +1,183 @@
#ifndef COMMAND_H
#define COMMAND_H
enum {
CMD_BUILD_RAILROAD_TRACK = 0,
CMD_REMOVE_RAILROAD_TRACK = 1,
CMD_BUILD_SINGLE_RAIL = 2,
CMD_REMOVE_SINGLE_RAIL = 3,
CMD_LANDSCAPE_CLEAR = 4,
CMD_BUILD_BRIDGE = 5,
CMD_BUILD_RAILROAD_STATION = 6,
CMD_BUILD_TRAIN_DEPOT = 7,
CMD_BUILD_SIGNALS = 8,
CMD_REMOVE_SIGNALS = 9,
CMD_TERRAFORM_LAND = 10,
CMD_PURCHASE_LAND_AREA = 11,
CMD_SELL_LAND_AREA = 12,
CMD_BUILD_TUNNEL = 13,
CMD_REMOVE_FROM_RAILROAD_STATION = 14,
CMD_CONVERT_RAIL = 15,
CMD_BUILD_TRAIN_CHECKPOINT = 16,
CMD_RENAME_CHECKPOINT = 17,
CMD_REMOVE_TRAIN_CHECKPOINT = 18,
CMD_BUILD_TRUCK_STATION = 19,
CMD_BUILD_BUS_STATION = 21,
CMD_BUILD_LONG_ROAD = 23,
CMD_REMOVE_LONG_ROAD = 24,
CMD_BUILD_ROAD = 25,
CMD_REMOVE_ROAD = 26,
CMD_BUILD_ROAD_DEPOT = 27,
CMD_BUILD_AIRPORT = 29,
CMD_BUILD_DOCK = 30,
CMD_BUILD_SHIP_DEPOT = 31,
CMD_BUILD_BUOY = 32,
CMD_PLANT_TREE = 33,
CMD_BUILD_RAIL_VEHICLE = 34,
CMD_MOVE_RAIL_VEHICLE = 35,
CMD_START_STOP_TRAIN = 36,
CMD_SELL_RAIL_WAGON = 38,
CMD_TRAIN_GOTO_DEPOT = 39,
CMD_FORCE_TRAIN_PROCEED = 40,
CMD_REVERSE_TRAIN_DIRECTION = 41,
CMD_MODIFY_ORDER = 42,
CMD_SKIP_ORDER = 43,
CMD_DELETE_ORDER = 44,
CMD_INSERT_ORDER = 45,
CMD_CHANGE_TRAIN_SERVICE_INT = 46,
CMD_BUILD_INDUSTRY = 47,
CMD_BUILD_COMPANY_HQ = 48,
CMD_SET_PLAYER_FACE = 49,
CMD_SET_PLAYER_COLOR = 50,
CMD_INCREASE_LOAN = 51,
CMD_DECREASE_LOAN = 52,
CMD_WANT_ENGINE_PREVIEW = 53,
CMD_NAME_VEHICLE = 54,
CMD_RENAME_ENGINE = 55,
CMD_CHANGE_COMPANY_NAME = 56,
CMD_CHANGE_PRESIDENT_NAME = 57,
CMD_RENAME_STATION = 58,
CMD_SELL_AIRCRAFT = 59,
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,
CMD_RENAME_SIGN = 66,
CMD_BUILD_ROAD_VEH = 67,
CMD_START_STOP_ROADVEH = 68,
CMD_SELL_ROAD_VEH = 69,
CMD_SEND_ROADVEH_TO_DEPOT = 70,
CMD_TURN_ROADVEH = 71,
CMD_CHANGE_ROADVEH_SERVICE_INT = 72,
CMD_PAUSE = 73,
CMD_BUY_SHARE_IN_COMPANY = 74,
CMD_SELL_SHARE_IN_COMPANY = 75,
CMD_BUY_COMPANY = 76,
CMD_BUILD_TOWN = 77,
CMD_RENAME_TOWN = 80,
CMD_DO_TOWN_ACTION = 81,
CMD_SET_ROAD_DRIVE_SIDE = 82,
CMD_SET_TOWN_NAME_TYPE = 83,
CMD_CHANGE_DIFFICULTY_LEVEL = 85,
CMD_START_STOP_SHIP = 86,
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_START_NEW_GAME = 92,
CMD_LOAD_GAME = 93,
CMD_CREATE_SCENARIO = 94,
CMD_SET_SINGLE_PLAYER = 95,
CMD_SET_NEW_LANDSCAPE_TYPE = 97,
CMD_GEN_RANDOM_NEW_GAME = 98,
CMD_CLONE_ORDER = 99,
CMD_CLEAR_AREA = 100,
CMD_RESUME = 101,
CMD_MONEY_CHEAT = 102,
CMD_BUILD_CANAL = 103,
CMD_PLAYER_CTRL = 104, // used in multiplayer to create a new player etc.
CMD_LEVEL_LAND = 105, // level land
CMD_REFIT_RAIL_VEHICLE = 106,
CMD_RESTORE_ORDER_INDEX = 107,
CMD_BUILD_LOCK = 108,
CMD_START_SCENARIO = 109,
CMD_BUILD_MANY_SIGNALS = 110,
//CMD_DESTROY_INDUSTRY = 109,
CMD_DESTROY_COMPANY_HQ = 111,
};
enum {
DC_EXEC = 1,
DC_AUTO = 2, // don't allow building on structures
DC_QUERY_COST = 4, // query cost only, don't build.
DC_NO_WATER = 8, // don't allow building on water
DC_NO_RAIL_OVERLAP = 0x10, // don't allow overlap of rails (used in buildrail)
DC_AI_BUILDING = 0x20, // special building rules for AI
DC_NO_TOWN_RATING = 0x40, // town rating does not disallow you from building
DC_FORCETEST = 0x80, // force test too.
CMD_ERROR = ((int32)0x80000000),
};
#define CMD_MSG(x) ((x)<<16)
enum {
CMD_AUTO = 0x200,
CMD_NO_WATER = 0x400,
CMD_DONT_NETWORK = 0x800, // execute the command without sending it on the network
CMD_ASYNC = 0x1000, // execute the command asynchronously without testing first in networking
CMD_NET_INSTANT = 0x2000,
};
//#define return_cmd_error(errcode) do { _error_message=(errcode); return CMD_ERROR; } while(0)
#define return_cmd_error(errcode) do { return CMD_ERROR | (errcode); } while (0)
/* command.c */
int32 DoCommand(int x, int y, uint32 p1, uint32 p2, uint32 flags, uint procc);
int32 DoCommandByTile(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc);
int32 GetAvailableMoneyForCommand();
#endif /* COMMAND_H */

2384
config.lib

File diff suppressed because it is too large Load Diff

148
configure vendored Executable file → Normal file
View File

@@ -1,134 +1,24 @@
#!/bin/sh
#!/bin/sh -
CONFIGURE_EXECUTABLE="$_"
# On *nix systems those two are equal when ./configure is done
if [ "$0" != "$CONFIGURE_EXECUTABLE" ]; then
# On some systems, when ./configure is triggered from 'make'
# the $_ is filled with 'make'. So if that is true, skip 'make'
# and use $0 (and hope that is correct ;))
if [ -n "`echo $CONFIGURE_EXECUTABLE | grep make`" ]; then
CONFIGURE_EXECUTABLE="$0"
else
CONFIGURE_EXECUTABLE="$CONFIGURE_EXECUTABLE $0"
fi
fi
# Find out where configure is (in what dir)
ROOT_DIR="`dirname $0`"
ROOT_DIR="`cd $ROOT_DIR && pwd`"
PWD="`pwd`"
PREFIX="`pwd`/bin"
. $ROOT_DIR/config.lib
# Set default dirs
OBJS_DIR="$PWD/objs"
BASE_SRC_OBJS_DIR="$OBJS_DIR"
LANG_OBJS_DIR="$OBJS_DIR/lang"
BIN_DIR="$PREFIX"
SRC_DIR="$ROOT_DIR/src"
LANG_DIR="$SRC_DIR/lang"
MEDIA_DIR="$ROOT_DIR/media"
SOURCE_LIST="$ROOT_DIR/source.list"
if [ "$1" = "--reconfig" ] || [ "$1" = "--reconfigure" ]; then
if ! [ -f "config.cache" ]; then
echo "can't reconfigure, because never configured before"
exit 1
fi
# Make sure we don't lock config.cache
cat config.cache | sed 's/\\ /\\\\ /g' > cache.tmp
sh cache.tmp
rm -f cache.tmp
exit $?
fi
set_default
detect_params "$@"
check_params
save_params
make_cflags_and_ldflags
EXE=""
if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ] || [ "$os" = "OS2" ] || [ "$os" = "WINCE" ]; then
EXE=".exe"
fi
TTD="openttd$EXE"
STRGEN="strgen$EXE"
ENDIAN_CHECK="endian_check$EXE"
if [ -z "$sort" ]; then
PIPE_SORT="sed s/a/a/"
SDLCONFIG=`which sdl-config || which sdl11-config || which sdl12-config || echo `
if [ -n "$SDLCONFIG" ] ; then
echo "SDL config is located at: $SDLCONFIG"
sed -e"s@XX_SDL_CONFIG_PLACEHOLDER_XX@$SDLCONFIG@g" < Jamfile.next > tmp && mv tmp Jamfile
else
PIPE_SORT="$sort"
echo "********************************"
echo "ERROR! SDL CONFIG WAS NOT FOUND!"
echo "********************************"
exit 1
fi
if ! [ -f "$LANG_DIR/english.txt" ]; then
echo "Languages not found in $LANG_DIR. Can't continue without it."
echo "Please make sure the dir exists and contains at least english.txt"
fi
echo "Configure complete. Now use 'jam' to build"
echo "Add -sWITH_PNG=<dir to png.h> to build with PNG support"
echo "Add -sWITH_ZLIB=1 to enable zlib savegame support"
echo "Add -sRELEASE=1 to build an optimized executable"
echo "Add -sWITH_BONE_NETWORKING=1 to build with BeOS BONE networking support"
echo "Add -sBEOS_MIDI=1 to enable BeOS native MIDI (libmidi.so) music output"
echo ""
echo "For people using make:"
echo "write make (or gmake)"
echo "configure have nothing to do with the makefile"
# Read the source.list and process it
SRCS="`< $ROOT_DIR/source.list tr '\r' '\n' | $awk '
{ }
/^( *)#end/ { if (deep == skip) { skip -= 1; } deep -= 1; next; }
/^( *)#else/ { if (deep == skip) { skip -= 1; } else if (deep - 1 == skip) { skip += 1; } next; }
/^( *)#if/ {
gsub(" ", "", $0);
gsub("^#if ", "", $0);
if (deep != skip) { deep += 1; next; }
deep += 1;
if ($0 == "SDL" && "'$sdl_config'" == "") { next; }
if ($0 == "PNG" && "'$png_config'" == "") { next; }
if ($0 == "OSX" && "'$os'" != "OSX") { next; }
if ($0 == "OS2" && "'$os'" != "OS2") { next; }
if ($0 == "PSP" && "'$os'" != "PSP") { next; }
if ($0 == "DEDICATED" && "'$enable_dedicated'" != "1") { next; }
if ($0 == "COCOA" && "'$with_cocoa'" == "0") { next; }
if ($0 == "BEOS" && "'$os'" != "BEOS") { next; }
if ($0 == "WIN32" && "'$os'" != "MINGW" &&
"'$os'" != "CYGWIN" && "'$os'" != "MSVC" ) { next; }
if ($0 == "WINCE" && "'$os'" != "WINCE") { next; }
if ($0 == "MSVC" && "'$os'" != "MSVC") { next; }
if ($0 == "DIRECTMUSIC" && "'$with_direct_music'" == "0") { next; }
if ($0 == "LIBTIMIDITY" && "'$libtimidity'" == "" ) { next; }
if ($0 == "NO_THREADS" && "'$with_threads'" == "0") { next; }
skip += 1;
next;
}
/^( *)#/ { next }
/^$/ { next }
/\.h$/ { next }
/\.hpp$/ { next }
{
if (deep == skip) {
gsub(" ", "", $0);
print $0;
}
}
' | $PIPE_SORT`"
OBJS_C="` echo \"$SRCS\" | $awk ' { ORS = " " } /\.c$/ { gsub(".c$", ".o", $0); print $0; }'`"
OBJS_CPP="`echo \"$SRCS\" | $awk ' { ORS = " " } /\.cpp$/ { gsub(".cpp$", ".o", $0); print $0; }'`"
OBJS_MM="` echo \"$SRCS\" | $awk ' { ORS = " " } /\.mm$/ { gsub(".mm$", ".o", $0); print $0; }'`"
OBJS_RC="` echo \"$SRCS\" | $awk ' { ORS = " " } /\.rc$/ { gsub(".rc$", ".o", $0); print $0; }'`"
SRCS="` echo \"$SRCS\" | $awk ' { ORS = " " } { print $0; }'`"
# In makefiles, we always use -u for sort
if [ -z "$sort" ]; then
sort="sed s/a/a/"
else
sort="$sort -u"
fi
CONFIGURE_FILES="$ROOT_DIR/configure $ROOT_DIR/config.lib $ROOT_DIR/Makefile.in $ROOT_DIR/Makefile.lang.in $ROOT_DIR/Makefile.src.in"
generate_main
generate_lang
generate_src

1235
console.c Normal file

File diff suppressed because it is too large Load Diff

129
console.h Normal file
View File

@@ -0,0 +1,129 @@
#ifndef CONSOLE_H
#define CONSOLE_H
// ** console ** //
enum {
ICONSOLE_OPENED=0,
ICONSOLE_CLOSED,
} _iconsole_modes;
// ** console parser ** //
enum {
ICONSOLE_VAR_NONE=0,
ICONSOLE_VAR_BOOLEAN,
ICONSOLE_VAR_BYTE,
ICONSOLE_VAR_UINT16,
ICONSOLE_VAR_UINT32,
ICONSOLE_VAR_INT16,
ICONSOLE_VAR_INT32,
ICONSOLE_VAR_STRING,
ICONSOLE_VAR_POINTER,
ICONSOLE_VAR_REFERENCE,
ICONSOLE_VAR_UNKNOWN,
} _iconsole_var_types;
enum {
ICONSOLE_HOOK_ACCESS,
ICONSOLE_HOOK_BEFORE_CHANGE,
ICONSOLE_HOOK_BEFORE_EXEC,
ICONSOLE_HOOK_AFTER_CHANGE,
ICONSOLE_HOOK_AFTER_EXEC,
} _iconsole_hook_types;
typedef struct {
// -------------- //
void * addr;
byte * name;
// -------------- //
void * hook_access;
void * hook_before_exec;
void * hook_after_exec;
// -------------- //
void * _next;
} _iconsole_cmd;
typedef struct {
// --------------- //
void * addr;
const byte * name;
byte type;
// -------------- //
void * hook_access;
void * hook_before_change;
void * hook_after_change;
// -------------- //
void * _next;
bool _malloc;
} _iconsole_var;
// ** console parser ** //
_iconsole_cmd * _iconsole_cmds; // list of registred commands
_iconsole_var * _iconsole_vars; // list of registred vars
// ** console colors ** //
VARDEF byte _iconsole_color_default;
VARDEF byte _iconsole_color_error;
VARDEF byte _iconsole_color_warning;
VARDEF byte _iconsole_color_debug;
VARDEF byte _iconsole_color_commands;
// ** ttd.c functions ** //
void SetDebugString(const char *s);
// ** console functions ** //
void IConsoleClearCommand();
void IConsoleInit();
void IConsoleClear();
void IConsoleFree();
void IConsoleResize();
void IConsoleSwitch();
void IConsoleClose();
void IConsoleOpen();
// ** console cmd buffer ** //
void IConsoleCmdBufferAdd(const byte *cmd);
void IConsoleCmdBufferNavigate(signed char direction);
// ** console output ** //
void IConsolePrint(byte color_code, const byte* string);
void CDECL IConsolePrintF(byte color_code, const char *s, ...);
void IConsoleDebug(byte* string);
void IConsoleError(const byte* string);
void IConsoleWarning(const byte* string);
// *** Commands *** //
void IConsoleCmdRegister(const byte * name, void * addr);
_iconsole_cmd * IConsoleCmdGet(const byte * name);
// *** Variables *** //
void IConsoleVarRegister(const byte * name, void * addr, byte type);
void IConsoleVarMemRegister(const byte * name, byte type);
void IConsoleVarInsert(_iconsole_var * var, const byte * name);
_iconsole_var * IConsoleVarGet(const byte * name);
_iconsole_var * IConsoleVarAlloc(byte type);
void IConsoleVarFree(_iconsole_var * var);
void IConsoleVarSetString(_iconsole_var * var, const byte * string);
void IConsoleVarSetValue(_iconsole_var * var, int value);
void IConsoleVarDump(_iconsole_var * var, const byte * dump_desc);
// *** Parser *** //
void IConsoleCmdExec(const byte* cmdstr);
// ** console std lib ** //
void IConsoleStdLibRegister();
// ** hook code ** //
void IConsoleVarHook(const byte * name, byte type, void * proc);
void IConsoleCmdHook(const byte * name, byte type, void * proc);
bool IConsoleVarHookHandle(_iconsole_var * hook_var, byte type);
bool IConsoleCmdHookHandle(_iconsole_cmd * hook_cmd, byte type);
#endif /* CONSOLE_H */

476
console_cmds.c Normal file
View File

@@ -0,0 +1,476 @@
/* -------------------- dont cross this line --------------------- */
#include "stdafx.h"
#include "ttd.h"
#include "console.h"
#include "engine.h"
#include "functions.h"
#include "variables.h"
#if defined(WIN32)
# define ENABLE_NETWORK
#endif
// ** scriptfile handling ** //
static FILE * _script_file;
static bool _script_running;
// ** console command / variable defines ** //
#define DEF_CONSOLE_CMD(yyyy) static _iconsole_var * yyyy(byte argc, byte* argv[], byte argt[])
#define DEF_CONSOLE_CMD_HOOK(yyyy) static bool yyyy(_iconsole_cmd * hookcmd)
#define DEF_CONSOLE_VAR_HOOK(yyyy) static bool yyyy(_iconsole_var * hookvar)
// ** supporting functions ** //
static int32 GetArgumentInteger(byte *arg)
{
int32 result;
sscanf((char *)arg, "%u", &result);
if (result == 0 && arg[0] == '0' && arg[1] == 'x')
sscanf((char *)arg, "%x", &result);
return result;
}
/* **************************** */
/* variable and command hooks */
/* **************************** */
DEF_CONSOLE_CMD_HOOK(ConCmdHookNoNetwork)
{
if (_networking) {
IConsoleError("this command is forbidden in multiplayer");
return false;
}
return true;
}
#if 0 /* Not used atm */
DEF_CONSOLE_VAR_HOOK(ConVarHookNoNetwork)
{
if (_networking) {
IConsoleError("this variable is forbidden in multiplayer");
return false;
}
return true;
}
#endif
DEF_CONSOLE_VAR_HOOK(ConVarHookNoNetClient)
{
if (!_networking_server) {
IConsoleError("this variable only makes sense for a network server");
return false;
}
return true;
}
/* **************************** */
/* reset commands */
/* **************************** */
DEF_CONSOLE_CMD(ConResetEngines)
{
StartupEngines();
return 0;
}
DEF_CONSOLE_CMD(ConResetTile)
{
if (argc == 2) {
TileIndex tile = (TileIndex)GetArgumentInteger(argv[1]);
DoClearSquare(tile);
}
return 0;
}
DEF_CONSOLE_CMD(ConScrollToTile)
{
if (argc == 2) {
TileIndex tile = (TileIndex)GetArgumentInteger(argv[1]);
ScrollMainWindowToTile(tile);
}
return 0;
}
// ********************************* //
// * Network Core Console Commands * //
// ********************************* //
#ifdef ENABLE_NETWORK
DEF_CONSOLE_CMD(ConNetworkConnect)
{
byte * ip;
const byte *port = NULL;
const byte *player = NULL;
uint16 rport;
if (argc<2) return NULL;
ip = argv[1];
rport = _network_server_port;
ParseConnectionString(&player, &port, ip);
IConsolePrintF(_iconsole_color_default,"Connecting to %s...", ip);
if (player!=NULL) {
_network_playas = atoi(player);
IConsolePrintF(_iconsole_color_default," player-no: %s", player);
}
if (port!=NULL) {
rport = atoi(port);
IConsolePrintF(_iconsole_color_default," port: %s", port);
}
NetworkCoreConnectGame(ip, rport);
return NULL;
}
#endif
/* ******************************** */
/* script file console commands */
/* ******************************** */
DEF_CONSOLE_CMD(ConExec)
{
char cmd[1024];
bool doerror;
if (argc<2) return NULL;
doerror = true;
_script_file = fopen(argv[1],"rb");
if (_script_file == NULL) {
if (argc>2) if (atoi(argv[2])==0) doerror=false;
if (doerror) IConsoleError("script file not found");
return NULL;
}
_script_running = true;
while (!feof(_script_file) && _script_running) {
fgets((char *)&cmd, 1024, _script_file);
IConsoleCmdExec((byte *) &cmd);
}
_script_running = false;
fclose(_script_file);
return NULL;
}
DEF_CONSOLE_CMD(ConReturn)
{
_script_running = false;
return NULL;
}
/* **************************** */
/* default console commands */
/* **************************** */
DEF_CONSOLE_CMD(ConScript)
{
extern FILE* _iconsole_output_file;
if (_iconsole_output_file!=NULL) {
if (argc<2) return NULL;
IConsolePrintF(_iconsole_color_default,"file output complete");
fclose(_iconsole_output_file);
} else {
IConsolePrintF(_iconsole_color_default,"file output started to: %s",argv[1]);
_iconsole_output_file = fopen(argv[1],"ab");
if (_iconsole_output_file == NULL) IConsoleError("could not open file");
}
return NULL;
}
DEF_CONSOLE_CMD(ConEcho)
{
if (argc<2) return NULL;
IConsolePrint(_iconsole_color_default, argv[1]);
return NULL;
}
DEF_CONSOLE_CMD(ConEchoC)
{
if (argc<3) return NULL;
IConsolePrint(atoi(argv[1]), argv[2]);
return NULL;
}
DEF_CONSOLE_CMD(ConPrintF)
{
if (argc<3) return NULL;
IConsolePrintF(_iconsole_color_default, argv[1] ,argv[2],argv[3],argv[4],argv[5],argv[6],argv[7],argv[8],argv[9],argv[10],argv[11],argv[12],argv[13],argv[14],argv[15],argv[16],argv[17],argv[18],argv[19]);
return NULL;
}
DEF_CONSOLE_CMD(ConPrintFC)
{
if (argc<3) return NULL;
IConsolePrintF(atoi(argv[1]), argv[2] ,argv[3],argv[4],argv[5],argv[6],argv[7],argv[8],argv[9],argv[10],argv[11],argv[12],argv[13],argv[14],argv[15],argv[16],argv[17],argv[18],argv[19]);
return NULL;
}
DEF_CONSOLE_CMD(ConScreenShot)
{
if (argc<2) {
_make_screenshot=1;
} else {
if (strcmp(argv[1],"big")==0) {
_make_screenshot=2;
}
if (strcmp(argv[1],"no_con")==0) {
IConsoleClose();
_make_screenshot=1;
}
}
return NULL;
}
DEF_CONSOLE_CMD(ConInfoVar)
{
if (argc<2) return NULL;
if (argt[1]!=ICONSOLE_VAR_REFERENCE) {
IConsoleError("first argument has to be a variable reference");
} else {
_iconsole_var * item;
item = (_iconsole_var *) argv[1];
IConsolePrintF(_iconsole_color_default,"var_name: %s",item->name);
IConsolePrintF(_iconsole_color_default,"var_type: %i",item->type);
IConsolePrintF(_iconsole_color_default,"var_addr: %i",item->addr);
if (item->_malloc) IConsolePrintF(_iconsole_color_default,"var_malloc: internal");
else IConsolePrintF(_iconsole_color_default, "var_malloc: external");
if (item->hook_access) IConsoleWarning("var_access hooked");
if (item->hook_before_change) IConsoleWarning("var_before_change hooked");
if (item->hook_after_change) IConsoleWarning("var_after_change hooked");
}
return NULL;
}
DEF_CONSOLE_CMD(ConInfoCmd)
{
if (argc<2) return NULL;
if (argt[1]!=ICONSOLE_VAR_UNKNOWN) {
IConsoleError("first argument has to be a command name");
} else {
_iconsole_cmd * item;
item = IConsoleCmdGet(argv[1]);
if (item==NULL) {
IConsoleError("the given command was not found");
return NULL;
}
IConsolePrintF(_iconsole_color_default,"cmd_name: %s",item->name);
IConsolePrintF(_iconsole_color_default,"cmd_addr: %i",item->addr);
if (item->hook_access) IConsoleWarning("cmd_access hooked");
if (item->hook_before_exec) IConsoleWarning("cmd_before_exec hooked");
if (item->hook_after_exec) IConsoleWarning("cmd_after_exec hooked");
}
return NULL;
}
DEF_CONSOLE_CMD(ConDebugLevel)
{
if (argc<2) return NULL;
SetDebugString(argv[1]);
return NULL;
}
DEF_CONSOLE_CMD(ConExit)
{
_exit_game = true;
return NULL;
}
DEF_CONSOLE_CMD(ConHelp)
{
IConsolePrint(13 ," -- console help -- ");
IConsolePrint(1 ," variables: [command to list them: list_vars]");
IConsolePrint(1 ," *temp_string = \"my little \"");
IConsolePrint(1 ,"");
IConsolePrint(1 ," commands: [command to list them: list_cmds]");
IConsolePrint(1 ," [command] [\"string argument with spaces\"] [argument 2] ...");
IConsolePrint(1 ," printf \"%s world\" *temp_string");
IConsolePrint(1 ,"");
IConsolePrint(1 ," command/variable returning a value into an variable:");
IConsolePrint(1 ," *temp_uint16 << random");
IConsolePrint(1 ," *temp_uint16 << *temp_uint16_2");
IConsolePrint(1 ,"");
return NULL;
}
DEF_CONSOLE_CMD(ConRandom)
{
_iconsole_var * result;
result = IConsoleVarAlloc(ICONSOLE_VAR_UINT16);
IConsoleVarSetValue(result,rand());
return result;
}
DEF_CONSOLE_CMD(ConListCommands)
{
_iconsole_cmd * item;
int l = 0;
if (argv[1]!=NULL) l = strlen((char *) argv[1]);
item = _iconsole_cmds;
while (item != NULL) {
if (argv[1]!=NULL) {
if (memcmp((void *) item->name, (void *) argv[1],l)==0)
IConsolePrintF(_iconsole_color_default,"%s",item->name);
} else {
IConsolePrintF(_iconsole_color_default,"%s",item->name);
}
item = item->_next;
}
return NULL;
}
DEF_CONSOLE_CMD(ConListVariables)
{
_iconsole_var * item;
int l = 0;
if (argv[1]!=NULL) l = strlen((char *) argv[1]);
item = _iconsole_vars;
while (item != NULL) {
if (argv[1]!=NULL) {
if (memcmp(item->name, argv[1],l)==0)
IConsolePrintF(_iconsole_color_default,"%s",item->name);
} else {
IConsolePrintF(_iconsole_color_default,"%s",item->name);
}
item = item->_next;
}
return NULL;
}
DEF_CONSOLE_CMD(ConListDumpVariables)
{
_iconsole_var * item;
int l = 0;
if (argv[1]!=NULL) l = strlen((char *) argv[1]);
item = _iconsole_vars;
while (item != NULL) {
if (argv[1]!=NULL) {
if (memcmp(item->name, argv[1],l)==0)
IConsoleVarDump(item,NULL);
} else {
IConsoleVarDump(item,NULL);
}
item = item->_next;
}
return NULL;
}
#ifdef _DEBUG
/* ****************************************** */
/* debug commands and variables */
/* ****************************************** */
void IConsoleDebugLibRegister()
{
// stdlib
extern bool _stdlib_con_developer;
IConsoleVarRegister("con_developer",(void *) &_stdlib_con_developer,ICONSOLE_VAR_BOOLEAN);
IConsoleVarMemRegister("temp_bool",ICONSOLE_VAR_BOOLEAN);
IConsoleVarMemRegister("temp_int16",ICONSOLE_VAR_INT16);
IConsoleVarMemRegister("temp_int32",ICONSOLE_VAR_INT32);
IConsoleVarMemRegister("temp_pointer",ICONSOLE_VAR_POINTER);
IConsoleVarMemRegister("temp_uint16",ICONSOLE_VAR_UINT16);
IConsoleVarMemRegister("temp_uint16_2",ICONSOLE_VAR_UINT16);
IConsoleVarMemRegister("temp_uint32",ICONSOLE_VAR_UINT32);
IConsoleVarMemRegister("temp_string",ICONSOLE_VAR_STRING);
IConsoleVarMemRegister("temp_string2",ICONSOLE_VAR_STRING);
IConsoleCmdRegister("resettile",ConResetTile);
}
#endif
/* ****************************************** */
/* console command and variable registration */
/* ****************************************** */
void IConsoleStdLibRegister()
{
// stdlib
extern byte _stdlib_developer;
#ifdef _DEBUG
IConsoleDebugLibRegister();
#else
(void)ConResetTile; // Silence warning, this is only used in _DEBUG
#endif
// functions [please add them alphabeticaly]
#ifdef ENABLE_NETWORK
IConsoleCmdRegister("connect",ConNetworkConnect);
IConsoleCmdHook("connect",ICONSOLE_HOOK_ACCESS,ConCmdHookNoNetwork);
#endif
IConsoleCmdRegister("debug_level",ConDebugLevel);
IConsoleCmdRegister("dump_vars",ConListDumpVariables);
IConsoleCmdRegister("echo",ConEcho);
IConsoleCmdRegister("echoc",ConEchoC);
IConsoleCmdRegister("exec",ConExec);
IConsoleCmdRegister("exit",ConExit);
IConsoleCmdRegister("help",ConHelp);
IConsoleCmdRegister("info_cmd",ConInfoCmd);
IConsoleCmdRegister("info_var",ConInfoVar);
IConsoleCmdRegister("list_cmds",ConListCommands);
IConsoleCmdRegister("list_vars",ConListVariables);
IConsoleCmdRegister("printf",ConPrintF);
IConsoleCmdRegister("printfc",ConPrintFC);
IConsoleCmdRegister("quit",ConExit);
IConsoleCmdRegister("random",ConRandom);
IConsoleCmdRegister("resetengines",ConResetEngines);
IConsoleCmdHook("resetengines",ICONSOLE_HOOK_ACCESS,ConCmdHookNoNetwork);
IConsoleCmdRegister("return",ConReturn);
IConsoleCmdRegister("screenshot",ConScreenShot);
IConsoleCmdRegister("script",ConScript);
IConsoleCmdRegister("scrollto",ConScrollToTile);
// variables [please add them alphabeticaly]
IConsoleVarRegister("developer",(void *) &_stdlib_developer,ICONSOLE_VAR_BYTE);
#ifdef ENABLE_NETWORK
IConsoleVarRegister("net_client_timeout",&_network_client_timeout,ICONSOLE_VAR_UINT16);
IConsoleVarHook("*net_client_timeout",ICONSOLE_HOOK_ACCESS,ConVarHookNoNetClient);
IConsoleVarRegister("net_ready_ahead",&_network_ready_ahead,ICONSOLE_VAR_UINT16);
IConsoleVarRegister("net_sync_freq",&_network_sync_freq,ICONSOLE_VAR_UINT16);
IConsoleVarHook("*net_sync_freq",ICONSOLE_HOOK_ACCESS,ConVarHookNoNetClient);
#endif
}
/* -------------------- dont cross this line --------------------- */

BIN
data/canalsw.grf Normal file

Binary file not shown.

BIN
data/openttd.grf Normal file

Binary file not shown.

BIN
data/signalsw.grf Normal file

Binary file not shown.

BIN
data/trkfoundw.grf Normal file

Binary file not shown.

980
disaster_cmd.c Normal file
View File

@@ -0,0 +1,980 @@
#include "stdafx.h"
#include "ttd.h"
#include "vehicle.h"
#include "command.h"
#include "news.h"
#include "gfx.h"
#include "station.h"
#include "town.h"
#include "industry.h"
#include "player.h"
#include "airport_movement.h"
static void DisasterClearSquare(uint tile)
{
int type;
if (!EnsureNoVehicle(tile))
return;
type = _map_type_and_height[tile] >> 4;
if (type == MP_RAILWAY) {
if (IS_HUMAN_PLAYER(_map_owner[tile]))
DoClearSquare(tile);
} else if (type == MP_HOUSE) {
byte p = _current_player;
_current_player = OWNER_NONE;
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
_current_player = p;
} else if (type == MP_TREES || type == MP_CLEAR) {
DoClearSquare(tile);
}
}
static const SpriteID _disaster_images_1[] = {0xF41,0xF41,0xF41,0xF41,0xF41,0xF41,0xF41,0xF41};
static const SpriteID _disaster_images_2[] = {0xF44,0xF44,0xF44,0xF44,0xF44,0xF44,0xF44,0xF44};
static const SpriteID _disaster_images_3[] = {0xF4E,0xF4E,0xF4E,0xF4E,0xF4E,0xF4E,0xF4E,0xF4E};
static const SpriteID _disaster_images_4[] = {0xF46,0xF46,0xF47,0xF47,0xF48,0xF48,0xF49,0xF49};
static const SpriteID _disaster_images_5[] = {0xF4A,0xF4A,0xF4B,0xF4B,0xF4C,0xF4C,0xF4D,0xF4D};
static const SpriteID _disaster_images_6[] = {0xF50,0xF50,0xF50,0xF50,0xF50,0xF50,0xF50,0xF50};
static const SpriteID _disaster_images_7[] = {0xF51,0xF51,0xF51,0xF51,0xF51,0xF51,0xF51,0xF51};
static const SpriteID _disaster_images_8[] = {0xF52,0xF52,0xF52,0xF52,0xF52,0xF52,0xF52,0xF52};
static const SpriteID _disaster_images_9[] = {0xF3E,0xF3E,0xF3E,0xF3E,0xF3E,0xF3E,0xF3E,0xF3E};
static const SpriteID * const _disaster_images[] = {
_disaster_images_1,_disaster_images_1,
_disaster_images_2,_disaster_images_2,
_disaster_images_3,_disaster_images_3,
_disaster_images_8,_disaster_images_8,_disaster_images_9,
_disaster_images_6,_disaster_images_6,
_disaster_images_7,_disaster_images_7,
_disaster_images_4,_disaster_images_5,
};
static void DisasterVehicleUpdateImage(Vehicle *v)
{
int img = v->u.disaster.image_override;
if (img == 0)
img = _disaster_images[v->subtype][v->direction];
v->cur_image = img;
}
static void InitializeDisasterVehicle(Vehicle *v, int x, int y, byte z, byte direction, byte subtype)
{
v->type = VEH_Disaster;
v->x_pos = x;
v->y_pos = y;
v->z_pos = z;
v->tile = TILE_FROM_XY(x,y);
v->direction = direction;
v->subtype = subtype;
v->x_offs = -1;
v->y_offs = -1;
v->sprite_width = 2;
v->sprite_height = 2;
v->z_height = 5;
v->owner = OWNER_NONE;
v->vehstatus = VS_UNCLICKABLE;
v->u.disaster.image_override = 0;
v->next_order = 0;
DisasterVehicleUpdateImage(v);
VehiclePositionChanged(v);
BeginVehicleMove(v);
EndVehicleMove(v);
}
static void DeleteDisasterVeh(Vehicle *v)
{
DeleteVehicleChain(v);
}
static void SetDisasterVehiclePos(Vehicle *v, int x, int y, byte z)
{
Vehicle *u;
int yt;
BeginVehicleMove(v);
v->x_pos = x;
v->y_pos = y;
v->z_pos = z;
v->tile = TILE_FROM_XY(x,y);
DisasterVehicleUpdateImage(v);
VehiclePositionChanged(v);
EndVehicleMove(v);
if ( (u=v->next) != NULL) {
BeginVehicleMove(u);
u->x_pos = x;
u->y_pos = yt = y - 1 - (max(z - GetSlopeZ(x, y-1), 0) >> 3);
u->z_pos = GetSlopeZ(x,yt);
u->direction = v->direction;
DisasterVehicleUpdateImage(u);
VehiclePositionChanged(u);
EndVehicleMove(u);
if ( (u=u->next) != NULL) {
BeginVehicleMove(u);
u->x_pos = x;
u->y_pos = y;
u->z_pos = z + 5;
VehiclePositionChanged(u);
EndVehicleMove(u);
}
}
}
static void DisasterTick_Zeppeliner(Vehicle *v)
{
GetNewVehiclePosResult gp;
Station *st;
int x,y;
byte z;
uint tile;
++v->tick_counter;
if (v->next_order < 2) {
if (v->tick_counter&1)
return;
GetNewVehiclePos(v, &gp);
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
if (v->next_order == 1) {
if (++v->age == 38) {
v->next_order = 2;
v->age = 0;
}
if ((v->tick_counter&7)==0) {
CreateEffectVehicleRel(v, 0, -17, 2, EV_SMOKE_3);
}
} else if (v->next_order == 0) {
tile = v->tile; /**/
if (IS_TILETYPE(tile, MP_STATION) &&
IS_BYTE_INSIDE(_map5[tile], 8, 0x43) &&
IS_HUMAN_PLAYER(_map_owner[tile])) {
v->next_order = 1;
v->age = 0;
SET_DPARAM16(0, _map2[tile]);
AddNewsItem(STR_B000_ZEPPELIN_DISASTER_AT,
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ACCIDENT, 0),
v->index,
0);
}
}
if (v->y_pos >= (TILES_Y+9) * 16 - 1)
DeleteDisasterVeh(v);
return;
}
if (v->next_order > 2) {
if (++v->age <= 13320)
return;
tile = v->tile; /**/
if (IS_TILETYPE(tile, MP_STATION) &&
IS_BYTE_INSIDE(_map5[tile], 8, 0x43) &&
IS_HUMAN_PLAYER(_map_owner[tile])) {
st = DEREF_STATION(_map2[tile]);
CLRBITS(st->airport_flags, RUNWAY_IN_block);
}
SetDisasterVehiclePos(v, v->x_pos, v->y_pos, v->z_pos);
DeleteDisasterVeh(v);
return;
}
x = v->x_pos;
y = v->y_pos;
z = GetSlopeZ(x,y);
if (z < v->z_pos)
z = v->z_pos - 1;
SetDisasterVehiclePos(v, x, y, z);
if (++v->age == 1) {
CreateEffectVehicleRel(v, 0, 7, 8, EV_CRASHED_SMOKE);
SndPlayVehicleFx(0x10, v);
v->u.disaster.image_override = 0xF42;
} else if (v->age == 70) {
v->u.disaster.image_override = 0xF43;
} else if (v->age <= 300) {
if (!(v->tick_counter&7)) {
uint32 r = Random();
CreateEffectVehicleRel(v,
-7 + (r&0xF),
-7 + (r>>4&0xF),
5 + (r>>8&0x7),
EV_DEMOLISH);
}
} else if (v->age == 350) {
v->next_order = 3;
v->age = 0;
}
tile = v->tile;/**/
if (IS_TILETYPE(tile, MP_STATION) &&
IS_BYTE_INSIDE(_map5[tile], 8, 0x43) &&
IS_HUMAN_PLAYER(_map_owner[tile])) {
st = DEREF_STATION(_map2[tile]);
SETBITS(st->airport_flags, RUNWAY_IN_block);
}
}
// UFO starts in the middle, and flies around a bit until it locates
// a road vehicle which it targets.
static void DisasterTick_UFO(Vehicle *v)
{
GetNewVehiclePosResult gp;
Vehicle *u;
uint dist;
byte z;
v->u.disaster.image_override = (++v->tick_counter & 8) ? 0xF45 : 0xF44;
if (v->next_order == 0) {
// fly around randomly
int x = GET_TILE_X(v->dest_tile)*16;
int y = GET_TILE_Y(v->dest_tile)*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 = TILE_MASK(Random());
return;
}
v->next_order = 1;
FOR_ALL_VEHICLES(u) {
if (u->type == VEH_Road && IS_HUMAN_PLAYER(u->owner)) {
v->dest_tile = u->index;
v->age = 0;
return;
}
}
DeleteDisasterVeh(v);
} else {
// target a vehicle
u = &_vehicles[v->dest_tile];
if (u->type != VEH_Road) {
DeleteDisasterVeh(v);
return;
}
dist = abs(v->x_pos - u->x_pos) + abs(v->y_pos - u->y_pos);
if (dist < 16 && !(u->vehstatus&VS_HIDDEN) && u->breakdown_ctr==0) {
u->breakdown_ctr = 3;
u->breakdown_delay = 140;
}
v->direction = GetDirectionTowards(v, u->x_pos, u->y_pos);
GetNewVehiclePos(v, &gp);
z = v->z_pos;
if (dist <= 16 && z > u->z_pos) z--;
SetDisasterVehiclePos(v, gp.x, gp.y, z);
if (z <= u->z_pos && (u->vehstatus&VS_HIDDEN)==0) {
v->age++;
if (u->u.road.crashed_ctr == 0) {
u->u.road.crashed_ctr++;
u->vehstatus |= VS_CRASHED;
AddNewsItem(STR_B001_ROAD_VEHICLE_DESTROYED,
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ACCIDENT, 0),
u->index,
0);
}
}
// destroy?
if (v->age > 50) {
CreateEffectVehicleRel(v, 0, 7, 8, EV_CRASHED_SMOKE);
SndPlayVehicleFx(0x10, v);
DeleteDisasterVeh(v);
}
}
}
static void DestructIndustry(Industry *i)
{
uint tile;
byte index = i - _industries;
for(tile=0; tile != TILES_X*TILES_Y; tile++) {
if (IS_TILETYPE(tile, MP_INDUSTRY) && _map2[tile] == index) {
_map_owner[tile] = 0;
MarkTileDirtyByTile(tile);
}
}
}
// Airplane which destroys an oil refinery
static void DisasterTick_2(Vehicle *v)
{
GetNewVehiclePosResult gp;
v->tick_counter++;
v->u.disaster.image_override = (v->next_order == 1 && v->tick_counter&4) ? 0xF4F : 0;
GetNewVehiclePos(v, &gp);
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
if (gp.x < -160) {
DeleteDisasterVeh(v);
return;
}
if (v->next_order == 2) {
if (!(v->tick_counter&3)) {
Industry *i = DEREF_INDUSTRY(v->dest_tile);
int x = GET_TILE_X(i->xy)*16;
int y = GET_TILE_Y(i->xy)*16;
uint32 r = Random();
CreateEffectVehicleAbove(
x + (r & 0x3F),
y + (r >> 6 & 0x3F),
(r >> 12 & 0xF),
EV_DEMOLISH);
if (++v->age >= 55)
v->next_order = 3;
}
} else if (v->next_order == 1) {
if (++v->age == 112) {
Industry *i;
v->next_order = 2;
v->age = 0;
i = DEREF_INDUSTRY(v->dest_tile);
DestructIndustry(i);
SET_DPARAM16(0, i->town->index);
AddNewsItem(STR_B002_OIL_REFINERY_EXPLOSION, NEWS_FLAGS(NM_THIN,NF_VIEWPORT|NF_TILE,NT_ACCIDENT,0), i->xy, 0);
SndPlayTileFx(0x10, i->xy);
}
} else if (v->next_order == 0) {
int x,y;
uint tile;
int ind;
x = v->x_pos - 15*16;
y = v->y_pos;
if ( (uint)x > (TILES_X-1) * 16-1)
return;
tile = TILE_FROM_XY(x,y);
if (!IS_TILETYPE(tile, MP_INDUSTRY))
return;
v->dest_tile = ind = _map2[tile];
if (DEREF_INDUSTRY(ind)->type == IT_OIL_REFINERY) {
v->next_order = 1;
v->age = 0;
}
}
}
// Helicopter which destroys a factory
static void DisasterTick_3(Vehicle *v)
{
GetNewVehiclePosResult gp;
v->tick_counter++;
v->u.disaster.image_override = (v->next_order == 1 && v->tick_counter&4) ? 0xF53 : 0;
GetNewVehiclePos(v, &gp);
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
if (gp.x > TILES_X * 16 + 9*16 - 1) {
DeleteDisasterVeh(v);
return;
}
if (v->next_order == 2) {
if (!(v->tick_counter&3)) {
Industry *i = DEREF_INDUSTRY(v->dest_tile);
int x = GET_TILE_X(i->xy)*16;
int y = GET_TILE_Y(i->xy)*16;
uint32 r = Random();
CreateEffectVehicleAbove(
x + (r & 0x3F),
y + (r >> 6 & 0x3F),
(r >> 12 & 0xF),
EV_DEMOLISH);
if (++v->age >= 55)
v->next_order = 3;
}
} else if (v->next_order == 1) {
if (++v->age == 112) {
Industry *i;
v->next_order = 2;
v->age = 0;
i = DEREF_INDUSTRY(v->dest_tile);
DestructIndustry(i);
SET_DPARAM16(0, i->town->index);
AddNewsItem(STR_B003_FACTORY_DESTROYED_IN_SUSPICIOUS, NEWS_FLAGS(NM_THIN,NF_VIEWPORT|NF_TILE,NT_ACCIDENT,0), i->xy, 0);
SndPlayTileFx(0x10, i->xy);
}
} else if (v->next_order == 0) {
int x,y;
uint tile;
int ind;
x = v->x_pos - 15*16;
y = v->y_pos;
if ( (uint)x > (TILES_X-1) * 16-1)
return;
tile = TILE_FROM_XY(x,y);
if (!IS_TILETYPE(tile, MP_INDUSTRY))
return;
v->dest_tile = ind = _map2[tile];
if (DEREF_INDUSTRY(ind)->type == IT_FACTORY) {
v->next_order = 1;
v->age = 0;
}
}
}
// Helicopter rotor blades
static void DisasterTick_3b(Vehicle *v)
{
if (++v->tick_counter & 1)
return;
if (++v->cur_image == 0xF40 + 1)
v->cur_image = 0xF3E;
VehiclePositionChanged(v);
BeginVehicleMove(v);
EndVehicleMove(v);
}
// Big UFO which lands on a piece of rail.
// Will be shot down by a plane
static void DisasterTick_4(Vehicle *v)
{
GetNewVehiclePosResult gp;
byte z;
Vehicle *u,*w;
Town *t;
uint tile,tile_org;
v->tick_counter++;
if (v->next_order == 1) {
int x = GET_TILE_X(v->dest_tile)*16 + 8;
int y = GET_TILE_Y(v->dest_tile)*16 + 8;
if (abs(v->x_pos - x) + abs(v->y_pos - y) >= 8) {
v->direction = GetDirectionTowards(v, x, y);
GetNewVehiclePos(v, &gp);
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
return;
}
z = GetSlopeZ(v->x_pos, v->y_pos);
if (z < v->z_pos) {
SetDisasterVehiclePos(v, v->x_pos, v->y_pos, v->z_pos - 1);
return;
}
v->next_order = 2;
FOR_ALL_VEHICLES(u) {
if (u->type == VEH_Train || u->type == VEH_Road) {
if (abs(u->x_pos - v->x_pos) + abs(u->y_pos - v->y_pos) <= 12*16) {
u->breakdown_ctr = 5;
u->breakdown_delay = 0xF0;
}
}
}
t = ClosestTownFromTile(v->dest_tile, (uint)-1);
SET_DPARAM16(0, t->index);
AddNewsItem(STR_B004_UFO_LANDS_NEAR,
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ACCIDENT, 0),
v->tile,
0);
u = ForceAllocateSpecialVehicle();
if (u == NULL) {
DeleteDisasterVeh(v);
return;
}
InitializeDisasterVehicle(u, -6*16, v->y_pos, 135, 5, 11);
u->u.disaster.unk2 = v->index;
w = ForceAllocateSpecialVehicle();
if (w == NULL)
return;
u->next = w;
InitializeDisasterVehicle(w, -6*16, v->y_pos, 0, 5, 12);
w->vehstatus |= VS_DISASTER;
} else if (v->next_order < 1) {
int x = GET_TILE_X(v->dest_tile)*16;
int y = GET_TILE_Y(v->dest_tile)*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 = TILE_MASK(Random());
return;
}
v->next_order = 1;
tile_org = tile = TILE_MASK(Random());
do {
if (IS_TILETYPE(tile, MP_RAILWAY) &&
(_map5[tile]&~3)!=0xC0 && IS_HUMAN_PLAYER(_map_owner[tile]))
break;
tile = TILE_MASK(tile+1);
} while (tile != tile_org);
v->dest_tile = tile;
v->age = 0;
} else
return;
}
// The plane which will shoot down the UFO
static void DisasterTick_4b(Vehicle *v)
{
GetNewVehiclePosResult gp;
Vehicle *u;
int i;
v->tick_counter++;
GetNewVehiclePos(v, &gp);
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
if (gp.x > TILES_X * 16 + 9*16 - 1) {
DeleteDisasterVeh(v);
return;
}
if (v->next_order == 0) {
u = &_vehicles[v->u.disaster.unk2];
if (abs(v->x_pos - u->x_pos) > 16)
return;
v->next_order = 1;
CreateEffectVehicleRel(u, 0, 7, 8, EV_CRASHED_SMOKE);
SndPlayVehicleFx(0x10, u);
DeleteDisasterVeh(u);
for(i=0; i!=80; i++) {
uint32 r = Random();
CreateEffectVehicleAbove(
v->x_pos-32+(r&0x3F),
v->y_pos-32+(r>>5&0x3F),
0,
EV_DEMOLISH);
}
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 - TILE_XY(3,3))
}
}
// Submarine handler
static void DisasterTick_5_and_6(Vehicle *v)
{
uint32 r;
GetNewVehiclePosResult gp;
uint tile;
v->tick_counter++;
if (++v->age > 8880) {
VehiclePositionChanged(v);
BeginVehicleMove(v);
EndVehicleMove(v);
DeleteVehicle(v);
return;
}
if (!(v->tick_counter&1))
return;
tile = v->tile + _tileoffs_by_dir[v->direction >> 1];
if (IsValidTile(tile) &&
(r=GetTileTrackStatus(tile,TRANSPORT_WATER),(byte)(r+(r >> 8)) == 0x3F) &&
!CHANCE16(1,90)) {
GetNewVehiclePos(v, &gp);
SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
return;
}
v->direction = (v->direction + ((Random()&1)?2:-2))&7;
}
static void DisasterTick_NULL(Vehicle *v) {}
typedef void DisasterVehicleTickProc(Vehicle *v);
static DisasterVehicleTickProc * const _disastervehicle_tick_procs[] = {
DisasterTick_Zeppeliner,DisasterTick_NULL,
DisasterTick_UFO,DisasterTick_NULL,
DisasterTick_2,DisasterTick_NULL,
DisasterTick_3,DisasterTick_NULL,DisasterTick_3b,
DisasterTick_4,DisasterTick_NULL,
DisasterTick_4b,DisasterTick_NULL,
DisasterTick_5_and_6,
DisasterTick_5_and_6,
};
void DisasterVehicle_Tick(Vehicle *v)
{
_disastervehicle_tick_procs[v->subtype](v);
}
void HandleClickOnDisasterVeh(Vehicle *v)
{
// not used
}
void OnNewDay_DisasterVehicle(Vehicle *v)
{
// not used
}
typedef void DisasterInitProc();
// Zeppeliner which crashes on a small airport
static void Disaster0_Init()
{
Vehicle *v = ForceAllocateSpecialVehicle(), *u;
Station *st;
int x;
if (v == NULL)
return;
for(st=_stations;;) {
if (st->xy && st->airport_tile != 0 &&
st->airport_type <= 1 &&
IS_HUMAN_PLAYER(st->owner)) {
x = (GET_TILE_X(st->xy) + 2) * 16;
break;
}
if (++st == endof(_stations)) {
x = (GET_TILE_X(Random())) * 16 + 8;
break;
}
}
InitializeDisasterVehicle(v, x, 0, 135, 3, 0);
// Allocate shadow too?
u = ForceAllocateSpecialVehicle();
if (u != NULL) {
v->next = u;
InitializeDisasterVehicle(u,x,0,0,3,1);
u->vehstatus |= VS_DISASTER;
}
}
static void Disaster1_Init()
{
Vehicle *v = ForceAllocateSpecialVehicle(), *u;
int x;
if (v == NULL)
return;
x = (GET_TILE_X(Random())) * 16 + 8;
InitializeDisasterVehicle(v, x, 0, 135, 3, 2);
v->dest_tile = TILE_XY(TILES_X/2,TILES_Y/2);
v->age = 0;
// Allocate shadow too?
u = ForceAllocateSpecialVehicle();
if (u != NULL) {
v->next = u;
InitializeDisasterVehicle(u,x,0,0,3,3);
u->vehstatus |= VS_DISASTER;
}
}
static void Disaster2_Init()
{
Industry *i, *found;
Vehicle *v,*u;
int x,y;
for(found=NULL,i=_industries; i != endof(_industries); i++) {
if (i->xy != 0 &&
i->type == IT_OIL_REFINERY &&
(found==NULL || CHANCE16(1,2))) {
found = i;
}
}
if (found == NULL)
return;
v = ForceAllocateSpecialVehicle();
if (v == NULL)
return;
x = (TILES_X+9) * 16 - 1;
y = GET_TILE_Y(found->xy)*16 + 37;
InitializeDisasterVehicle(v,x,y, 135,1,4);
u = ForceAllocateSpecialVehicle();
if (u != NULL) {
v->next = u;
InitializeDisasterVehicle(u,x,y,0,3,5);
u->vehstatus |= VS_DISASTER;
}
}
static void Disaster3_Init()
{
Industry *i, *found;
Vehicle *v,*u,*w;
int x,y;
for(found=NULL,i=_industries; i != endof(_industries); i++) {
if (i->xy != 0 &&
i->type == IT_FACTORY &&
(found==NULL || CHANCE16(1,2))) {
found = i;
}
}
if (found == NULL)
return;
v = ForceAllocateSpecialVehicle();
if (v == NULL)
return;
x = -16 * 16;
y = GET_TILE_Y(found->xy)*16 + 37;
InitializeDisasterVehicle(v,x,y, 135,5,6);
u = ForceAllocateSpecialVehicle();
if (u != NULL) {
v->next = u;
InitializeDisasterVehicle(u,x,y,0,5,7);
u->vehstatus |= VS_DISASTER;
w = ForceAllocateSpecialVehicle();
if (w != NULL) {
u->next = w;
InitializeDisasterVehicle(w,x,y,140,5,8);
}
}
}
static void Disaster4_Init()
{
Vehicle *v = ForceAllocateSpecialVehicle(), *u;
int x,y;
if (v == NULL)
return;
x = (GET_TILE_X(Random())) * 16 + 8;
y = (TILES_X-1)*16-1;
InitializeDisasterVehicle(v, x, y, 135, 7, 9);
v->dest_tile = TILE_XY(TILES_X/2,TILES_Y/2);
v->age = 0;
// Allocate shadow too?
u = ForceAllocateSpecialVehicle();
if (u != NULL) {
v->next = u;
InitializeDisasterVehicle(u,x,y,0,7,10);
u->vehstatus |= VS_DISASTER;
}
}
// Submarine type 1
static void Disaster5_Init()
{
Vehicle *v = ForceAllocateSpecialVehicle();
int x,y;
byte dir;
uint32 r;
if (v == NULL)
return;
r = Random();
x = (GET_TILE_X(r)) * 16 + 8;
y = 8;
dir = 3;
if (r & 0x80000000) { y = (TILES_X-1) * 16 - 8 - 1; dir = 7; }
InitializeDisasterVehicle(v, x, y, 0, dir,13);
v->age = 0;
}
// Submarine type 2
static void Disaster6_Init()
{
Vehicle *v = ForceAllocateSpecialVehicle();
int x,y;
byte dir;
uint32 r;
if (v == NULL)
return;
r = Random();
x = (GET_TILE_X(r)) * 16 + 8;
y = 8;
dir = 3;
if (r & 0x80000000) { y = (TILES_X-1) * 16 - 8 - 1; dir = 7; }
InitializeDisasterVehicle(v, x, y, 0, dir,14);
v->age = 0;
}
static void Disaster7_Init()
{
Industry *i;
int maxloop = 15;
int index = Random() & 0xF;
do {
for(i=_industries; i != endof(_industries); i++) {
if (i->xy != 0 && i->type == IT_COAL_MINE && --index < 0) {
SET_DPARAM16(0, i->town->index);
AddNewsItem(STR_B005_COAL_MINE_SUBSIDENCE_LEAVES,
NEWS_FLAGS(NM_THIN,NF_VIEWPORT|NF_TILE,NT_ACCIDENT,0), i->xy + TILE_XY(1,1), 0);
{
uint tile = i->xy;
int step = _tileoffs_by_dir[Random() & 3];
int count = 30;
do {
DisasterClearSquare(tile);
tile = TILE_MASK(tile + step);
} while (--count);
}
return;
}
}
} while (--maxloop != 0);
}
static DisasterInitProc * const _disaster_initprocs[] = {
Disaster0_Init,
Disaster1_Init,
Disaster2_Init,
Disaster3_Init,
Disaster4_Init,
Disaster5_Init,
Disaster6_Init,
Disaster7_Init,
};
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),
};
void DoDisaster()
{
byte buf[8];
byte year = _cur_year;
int i,j;
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;
_disaster_initprocs[buf[(uint16)Random() * j >> 16]]();
}
static void ResetDisasterDelay()
{
_disaster_delay = (int)(Random() & 0x1FF) + 730;
}
void DisasterDailyLoop()
{
if (--_disaster_delay != 0)
return;
ResetDisasterDelay();
if (_opt.diff.disasters != 0)
DoDisaster();
}
void StartupDisasters() {
ResetDisasterDelay();
}

323
dock_gui.c Normal file
View File

@@ -0,0 +1,323 @@
#include "stdafx.h"
#include "ttd.h"
#include "window.h"
#include "gui.h"
#include "viewport.h"
#include "gfx.h"
#include "command.h"
static void ShowBuildDockStationPicker();
static void ShowBuildDocksDepotPicker();
static byte _ship_depot_direction;
static void CcBuildDocks(bool success, uint tile, uint32 p1, uint32 p2)
{
if (success) {
SndPlayTileFx(0, tile);
ResetObjectToPlace();
}
}
static void CcBuildCanal(bool success, uint tile, uint32 p1, uint32 p2)
{
if (success) { SndPlayTileFx(0, 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(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(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(uint tile)
{
VpStartPlaceSizing(tile, VPM_X_AND_Y);
}
static void PlaceDocks_BuildCanal(uint tile)
{
VpStartPlaceSizing(tile, VPM_X_OR_Y);
}
static void PlaceDocks_BuildLock(uint tile)
{
DoCommandP(tile, 0, 0, CcBuildDocks, CMD_BUILD_LOCK | CMD_AUTO | CMD_MSG(STR_CANT_BUILD_LOCKS));
}
static void BuildDocksClick_Dock(Window *w)
{
if (HandlePlacePushButton(w, 2, 0xE54, 3, PlaceDocks_Dock)) ShowBuildDockStationPicker();
}
static void BuildDocksClick_Depot(Window *w)
{
if (HandlePlacePushButton(w, 3, 0x2D1, 1, PlaceDocks_Depot)) ShowBuildDocksDepotPicker();
}
static void BuildDocksClick_Buoy(Window *w)
{
HandlePlacePushButton(w, 4, 0x2BE, 1, PlaceDocks_Buoy);
}
static void BuildDocksClick_Demolish(Window *w)
{
HandlePlacePushButton(w, 5, ANIMCURSOR_DEMOLISH, 1, PlaceDocks_DemolishArea);
}
static void BuildDocksClick_Lower(Window *w)
{
HandlePlacePushButton(w, 6, ANIMCURSOR_LOWERLAND, 2, PlaceProc_LowerLand);
}
static void BuildDocksClick_Raise(Window *w)
{
HandlePlacePushButton(w, 7, ANIMCURSOR_RAISELAND, 2, PlaceProc_RaiseLand);
}
static void BuildDocksClick_Purchase(Window *w)
{
HandlePlacePushButton(w, 8, 0x12B8, 1, PlaceProc_BuyLand);
}
static void BuildDocksClick_Canal(Window *w)
{
HandlePlacePushButton(w, 9, SPR_OPENTTD_BASE + 11, 1, PlaceDocks_BuildCanal);
}
static void BuildDocksClick_Lock(Window *w)
{
HandlePlacePushButton(w, 10, SPR_OPENTTD_BASE + 64, 1, PlaceDocks_BuildLock);
}
typedef void OnButtonClick(Window *w);
static OnButtonClick * const _build_docks_button_proc[] = {
BuildDocksClick_Dock,
BuildDocksClick_Depot,
BuildDocksClick_Buoy,
BuildDocksClick_Demolish,
BuildDocksClick_Lower,
BuildDocksClick_Raise,
BuildDocksClick_Purchase,
BuildDocksClick_Canal,
BuildDocksClick_Lock,
};
static void BuildDocksToolbWndProc(Window *w, WindowEvent *e)
{
switch(e->event) {
case WE_PAINT:
DrawWindowWidgets(w);
break;
case WE_CLICK: {
if (e->click.widget - 2 >= 0) _build_docks_button_proc[e->click.widget - 2](w);
} break;
case WE_PLACE_OBJ:
_place_proc(e->place.tile);
break;
case WE_PLACE_DRAG: {
VpSelectTilesWithMethod(e->place.pt.x, e->place.pt.y, e->place.userdata);
return;
}
case WE_PLACE_MOUSEUP:
if (e->click.pt.x != -1) {
if (e->place.userdata == VPM_X_AND_Y)
DoCommandP(e->place.tile, e->place.starttile, 0, CcPlaySound10, CMD_CLEAR_AREA | CMD_MSG(STR_00B5_CAN_T_CLEAR_THIS_AREA));
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;
case WE_ABORT_PLACE_OBJ:
w->click_state = 0;
SetWindowDirty(w);
w = FindWindowById(WC_BUILD_STATION, 0);
if (w != NULL) WP(w,def_d).close=true;
w = FindWindowById(WC_BUILD_DEPOT, 0);
if (w != NULL) WP(w,def_d).close=true;
break;
case WE_PLACE_PRESIZE: {
uint tile_from, tile_to;
tile_from = tile_to = e->place.tile;
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;
}
}
static const Widget _build_docks_toolb_widgets[] = {
{ WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, 7, 11, 197, 0, 13, STR_9801_DOCK_CONSTRUCTION, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_PANEL, 7, 0, 21, 14, 35, 746, STR_981D_BUILD_SHIP_DOCK},
{ WWT_PANEL, 7, 22, 43, 14, 35, 748, STR_981E_BUILD_SHIP_DEPOT_FOR_BUILDING},
{ WWT_PANEL, 7, 44, 65, 14, 35, 693, STR_9834_POSITION_BUOY_WHICH_CAN},
{ WWT_PANEL, 7, 66, 87, 14, 35, 703, STR_018D_DEMOLISH_BUILDINGS_ETC},
{ WWT_PANEL, 7, 88, 109, 14, 35, 695, STR_018E_LOWER_A_CORNER_OF_LAND},
{ WWT_PANEL, 7, 110, 131, 14, 35, 694, STR_018F_RAISE_A_CORNER_OF_LAND},
{ WWT_PANEL, 7, 132, 153, 14, 35, 4791, STR_0329_PURCHASE_LAND_FOR_FUTURE},
{ WWT_PANEL, 7, 154, 175, 14, 35, SPR_OPENTTD_BASE+65, STR_BUILD_CANALS_TIP},
{ WWT_PANEL, 7, 176, 197, 14, 35, SPR_CANALS_BASE+69, STR_BUILD_LOCKS_TIP},
{ WIDGETS_END},
};
static const WindowDesc _build_docks_toolbar_desc = {
640-197, 22, 198, 36,
WC_BUILD_TOOLBAR,0,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
_build_docks_toolb_widgets,
BuildDocksToolbWndProc
};
void ShowBuildDocksToolbar()
{
DeleteWindowById(WC_BUILD_TOOLBAR, 0);
AllocateWindowDesc(&_build_docks_toolbar_desc);
}
static void BuildDockStationWndProc(Window *w, WindowEvent *e)
{
switch(e->event) {
case WE_PAINT: {
if (WP(w,def_d).close)
return;
DrawWindowWidgets(w);
DrawStationCoverageAreaText(2, 15, (uint)-1);
} break;
case WE_CLICK: {
if (e->click.widget == 0) {
ResetObjectToPlace();
}
} break;
case WE_MOUSELOOP: {
if (WP(w,def_d).close) {
DeleteWindow(w);
return;
}
CheckRedrawStationCoverage(w);
break;
}
}
}
static const Widget _build_dock_station_widgets[] = {
{ WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, 7, 11, 147, 0, 13, STR_3068_DOCK, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_PANEL, 7, 0, 147, 14, 45, 0x0, STR_NULL},
{ WIDGETS_END},
};
static const WindowDesc _build_dock_station_desc = {
-1, -1, 148, 46,
WC_BUILD_STATION,WC_BUILD_TOOLBAR,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
_build_dock_station_widgets,
BuildDockStationWndProc
};
static void ShowBuildDockStationPicker()
{
AllocateWindowDesc(&_build_dock_station_desc);
}
static void UpdateDocksDirection()
{
if (_ship_depot_direction != 0) {
SetTileSelectSize(1, 2);
} else {
SetTileSelectSize(2, 1);
}
}
static void BuildDocksDepotWndProc(Window *w, WindowEvent *e)
{
switch(e->event) {
case WE_PAINT:
w->click_state = (1<<3) << _ship_depot_direction;
DrawWindowWidgets(w);
DrawShipDepotSprite(67, 35, 0);
DrawShipDepotSprite(35, 51, 1);
DrawShipDepotSprite(135, 35, 2);
DrawShipDepotSprite(167, 51, 3);
return;
case WE_CLICK: {
switch(e->click.widget) {
case 0:
ResetObjectToPlace();
break;
case 3:
case 4:
_ship_depot_direction = e->click.widget - 3;
SndPlayFx(0x13);
UpdateDocksDirection();
SetWindowDirty(w);
break;
}
} break;
case WE_MOUSELOOP:
if (WP(w,def_d).close)
DeleteWindow(w);
break;
}
}
static const Widget _build_docks_depot_widgets[] = {
{ WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, 7, 11, 203, 0, 13, STR_3800_SHIP_DEPOT_ORIENTATION, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_PANEL, 7, 0, 203, 14, 85, 0x0, STR_NULL},
{ WWT_PANEL, 14, 3, 100, 17, 82, 0x0, STR_3803_SELECT_SHIP_DEPOT_ORIENTATION},
{ WWT_PANEL, 14, 103, 200, 17, 82, 0x0, STR_3803_SELECT_SHIP_DEPOT_ORIENTATION},
{ WIDGETS_END},
};
static const WindowDesc _build_docks_depot_desc = {
-1, -1, 204, 86,
WC_BUILD_DEPOT,WC_BUILD_TOOLBAR,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
_build_docks_depot_widgets,
BuildDocksDepotWndProc
};
static void ShowBuildDocksDepotPicker()
{
AllocateWindowDesc(&_build_docks_depot_desc);
UpdateDocksDirection();
}
void InitializeDockGui()
{
_ship_depot_direction = 0;
}

View File

@@ -1,36 +0,0 @@
32bpp and OpenTTD
=================
OpenTTD has 32bpp support. This means: OpenTTD still is 8bpp, but it has the
posibility to override the graphics with 32bpp. This means that it isn't a
replacement of grf or newgrf, but simply an addition. If you want to use 32bpp
graphics of a newgrf, you do need the newgrf itself too (with 8bpp graphics).
The Format
----------
32bpp images are stored in PNG. They should go in:
data/sprites/<grfname>/<SpriteID>.png
For example, a grfname would be 'openttd' (without .grf, lowercase), and the
SpriteID 3, to override the 3rd sprite in openttd.grf with a 32bpp version.
The format of this PNG can be almost anything, but we advise to use RGBA
format. Alpha-channel is fully supported.
As the core of OpenTTD is 8bpp, and because you of course want company colours
in your images, you will need to add a mask for every sprite that needs colour
remapping. The name is simular as above, only you have to put a 'm' behind the
SpriteID. This image should be a 8bpp palette image, where the palette is the
OpenTTD palette. Upon load of the PNG, the mask is loaded too, and overrides
the RGB (not the Alpha) of the original PNG image, and replacing it with a
8bpp color remapped and converted to 32bpp.
An other thing that OpenTTD needs in your png, is 2 tEXt chunks: x_offs and
y_offs. This to define the x- and y-offset, of course. Use the tool we supply
to add this information. Sadly enough most graphical editors trashes those
chunks upon save, so you have to readd it every time you save your image.
Your images should be the same as the grf, in size.

View File

@@ -1,59 +0,0 @@
STRGEN USAGE
------------
This guide is only interesting for people who want to alter something
themselves without access to WT2 (translator2.openttd.org). Please note that
your compiled language file will only be compatible with the OpenTTD version
you have downloaded english.txt, the master language file, for. While this is
not always true, namely when changes in the code have not touched language
files, your safest bet is to assume this 'limitation'.
As a first step you need to compile strgen. This is as easy as typing
'make strgen'. You can also download a precompiled binary from a release,
nightly, etc.
strgen takes as argument a txt file and translates it to a lng file, allowing
it to be used inside OpenTTD. strgen needs the master language file
english.txt to work. Below are some examples of strgen usage.
EXAMPLES
--------
Example 1:
if you are in the root of your working copy (svn code), you should type
strgen/strgen -s lang lang/english.txt
to compile englist.txt into english.lng. It will be placed in the lang dir
Example 2:
you only have the strgen executable (no working copy) and you want to compile
a txt file in the same directory. You should type
./strgen english.txt
and you will get and english.lng in the same dir
Example 3:
you have strgen somewhere, english.txt in /usr/openttd/lang and you want the
resulting language file to go to /tmp. Use
./strgen -s /usr/openttd/lang -d /tmp english.txt
You can interchange english.txt to whichever language you want to generate a
.lng file for.
STRGEN COMMAND SWITCHES
-----------------------
-v | --version
strgen will tell what svn revision it was last modified
-t | --todo
strgen will add <TODO> to any untranslated/missing strings and use the english
strings while compiling the language file
-w | --warning
strgen will print any missing strings or wrongly translated (bad format)
to standard error output(stderr)
-h | --help | -?
Print out a summarized help message explaining these switches
-s | --source_dir
strgen will search for the master file english.txt in the directory specified
by this switch instead of the current directory
-d | --dest_dir
strgen will put <language>.lng in the directory specified by this switch; if
no dest_dir is given, output is the same as source_dir

View File

@@ -0,0 +1,49 @@
This is a guide to compile strgen on gcc
All this is done in the makefile, so it's only interesting for people, who wants to alter something themselves (translators)
HOWTO compile lng files:
First you get strgen compiled (look below/download nightly build/run makefile)
strgen takes the argument of a txt file and translates it to a lng file and places that lng file in the same dir as the txt file.
Example 1:
if you are in the root of your working copy (svn code), you should type
strgen/strgen lang/english.txt
to compile englist.lng. It will be placed in the lang dir
Example 2:
you have strgen but not the source and you want to compile a txt file in the same dir. YOu should type
./strgen english.txt
and you will get english.lng in the same dir
You can change english to whatever language you want
Commands used by strgen
-v --version
strgen will tell what svn revision it is based on
-t
strgen will add <TODO> to the missing strings and use the english strings while compiling
this will need english.txt to be present
-w
strgen will print any missing strings to standard error output(stderr)
this will need english.txt to be present
here are a very useful tool for translators:
http://openttd.rulez.org/
HOWTO compile strgen:
(this should be useless as you can just type make)
Goto the main dir
Compile by typing
gcc strgen/strgen.c -o strgen/strgen -DUNIX
or if you want it to tell the revision too
gcc strgen/strgen.c rev.o -o strgen/strgen -DUNIX -DWITH_REV (this is the one the makefile uses)
you now have a program called strgen in the strgen directory

View File

@@ -2,9 +2,9 @@ Welcome to the manual for OpenTTD. The latest release version at the time of wr
1 Obtaining OpenTTD.
You can obtain built binaries of OpenTTD for the 4 supported platforms - Win32, Linux,-x86, BeOS 5 and MacOS-X from the projects Sourceforge page, at http://sourceforge.net/projects/openttd . For the non-Win32 builds you will need libSDL.so, libpng.so and zlib.so compiled for your platform. Some builds will include these.
You can obtain built binaries of OpenTTD for the 4 supported platforms - Win32, Linux,-x86, BeOS 5 and MacOS-X from the projects Sourceforge page, at http://sourceforge.net/projects/openttd . For the non-Win32 builds you will need libSDL.so, libpng.so and zlib.so compiled for your platform. Some builds will include these.
If you use another platform, such as FreeBSD, which has POSIX file i/o and an SDL port, you should be able to build OpenTTD from its source. This is available in the proejcts Subversion repository at svn://svn.openttd.com . The module name is "trunk".
If you use another platform, such as FreeBSD, which has POSIX file i/o and an SDL port, you should be able to build OpenTTD from its source. This is available in the proejcts Subversion repository at svn://svn.openttd.com . The module name is "trunk".
1.1 Building OpenTTD.
@@ -13,17 +13,17 @@ Once you have obtained a recent copy of the source, you must build it. Windows b
On UNIX platforms (including OS-X and BeOS), ensure you have a recent GCC (2.9 or above, or 3 and above).You will also need SDL development headers and libraries (libSDL 1.2 or higher). For PNG screenshot support and zlib compressed games, you will need libpng 1.0.12 or higher and zlib 1.2 or higher.
Most UNIX platforms:
First run ./configure, them use make or gmake to compile OpenTTD. You can configure the different compile options via ./configure.
Use make or gmake to compile OpenTTD. You can adjust Makefile.config to compile with other options.
BeOS:
On BeOS, run ./configure and then use jam. There are a variaty of options you can pass to your build tool, these are reported by ./configure.
1.2 Installing OpenTTD.
On Windows, insert your "Transport Tycoon Deluxe for Windows 95" disk. You can use a DOS version, but your graphics will be purple. NB: Even if your version of Transport Tycoon Deluxe ran on Windows 95, it may still be the DOS version. Then run the OpenTTD installer.
On Windows, insert your "Transport Tycoon Deluxe for Windows 95" disk. You can use a DOS version, but your graphics will be purple. NB: Even if your version of Transport Tycoon Deluxe ran on Windows 95, it may still be the DOS version. Then run the OpenTTD installer.
On UNIX platforms; decompress your OpenTTD archive, or otherwise run the installer. You should be left with an OpenTTD directory on your system. In this directory, make a subdirectory called 'data', and into this place the sample.cat file and all the .grf files from the install CD of 'Transport Tycoon Deluxe for Windows 95".
(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.)
On UNIX platforms; decompress your OpenTTD archive, or otherwise run the installer. You should be left with an OpenTTD directory on your system. In this directory, make a subdirectory called 'data', and into this place the sample.cat file and all the .grf files from the install CD of 'Transport Tycoon Deluxe for Windows 95".
If you want MIDI music, copy the 'gm' folder from the original game directory/CD to the OpenTTD folder.
@@ -37,7 +37,7 @@ On BeOS and Mac OS-X, just double click the ttd binary in the Tracker/Finder. Yo
1.4 Configuring OpenTTD
OpenTTD's launch menu contains three configuration menus - Difficulty Settings, Configure Patches and Game Settings. Most of these menus can be configured from within a running game as well.
OpenTTD's launch menu contains three configuration menus - Difficulty Settings, Configure Patches and Game Settings. Most of these menus can be configured from within a running game as well.
Difficulty Settings lets you configure settings that affect the difficulty of playing the game. These include when your (computer-controlled) competitors can start building, how many of them there are, and how intelligent they are. You can also control how much the subsidy mutliplier is for subsidised routes, and how stable/volitile the in-game economy is. You can also set how you want the terrain to be configured in a random game.
@@ -51,13 +51,14 @@ This section of the manual is written with the assumption that you already know
2.2 Station Construction
In OpenTTD, you can build rail stations up to seven squares long and with up to seven platforms. You can also have stations spreading across far larger distances, allowing a large rail station to be connected to a large airport, for instance.
In OpenTTD, you can build rail stations up to seven squares long and with up to seven platforms. You can also have stations spreading across far larger distances, allowing a large rail station to be connected to a large airport, for instance.
However, there is an even more noticable difference in rail station construction. You may now add platforms and lenght to a station after it has been built, and you may also add platforms of a different type. Users of TTDPatch will be used to this behaviour. But beyond what TTDPatch has, you can make stations of uneven lenght/width, and even ones with perpendicular tracks. You can also delete single tiles or tracks from a station, by holding down Shift before pressing the station construction button.
2.3 Checkpoint Stations
Checkpoint stations (the small blue item in the rail construction window) are small 1x1 stations. They must be built on top of pre-existing track. They do not accept or produce carge of any kind. They exist solely for use as route points. They become useful when dealing with large networks where trains may attempt to route themselves along undesirable or impossible routes. As an alternative to checkpoint stations, you can also direct trains to visit depots along the way. This has the advantage of also servicing the train and hence the train will rarely to never need to depart from its route to be serviced.
Checkpoint stations (the small blue item in the rail construction window) are small 1x1 stations. They must be built on top of pre-existing track. They do not accept or produce carge of any kind. They exist solely for use as route points. They become useful when dealing with large networks where trains may attempt to route themselves along undesirable or impossible routes. As an alternative to checkpoint stations, you can also direct trains to visit depots along the way. This has the advantage of also servicing the train and hence the train will rarely to never need to depart from its route to be serviced.
2.4 Freeform Rail Laying.
@@ -73,7 +74,7 @@ This allows you to build roads, rails, stations and depots on slopes. It also al
2.7 Long Bridges
OpenTTD allows you to constuct bridges up to 127 squares - half the size of the current map. This means that the crossing of large estuaries, such at the Bristol Channel in the original "West Country 90210" scenario can be acheived with one bridge instead of many bridges with staging points.
OpenTTD allows you to constuct bridges up to 127 squares - half the size of the current map. This means that the crossing of large estuaries, such at the Bristol Channel in the original "West Country 90210" scenario can be acheived with one bridge instead of many bridges with staging points.
2.8 Long trains
@@ -87,9 +88,9 @@ This addition to OpenTTD allows you to see the current speed of any vehicle in t
Virtually any settings - train numbers, start date, what vehicles your competitors can use, etc - can be set in OpenTTD. Just use the Configure Patches menu on the main screen.
2.11 Network Play
2.11 Network Play
See multiplayer.txt for more info.
OpenTTD now supports rudimentary TCP/IP based network play. This is not supported on all platforms. To start a server, use the '-n' CLI switch, and start a client with '-n' and the servers IP adress. The OpenTTD network play runs over port 12345, so you may need to open this on your firewall.
2.12 Rail Recycling.
@@ -97,4 +98,4 @@ This button, at the end of the train construction window, lets you 'recycle' tra
2.13 Canal Building
This button, at the end of the water construction window, lets you build canals and shiplifts across the landscape. These act just like normal water.
This button, at the end of the water construction window, lets you build canals and shiplifts across the landscape. These act just like normal water.

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,38 @@
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
The first thing you need to do is to get the error message. You can access OSX's build-in log by double-clicking Crash_Log_Opener. OTTD will do that if that file is present in the same folder as OTTD and is not renamed. However, major crashes can prevent the autoopen feature and you have to do it manually then
If Crash_Log_Opener doesn't work you can view the log by opening Console inside Applications/utilities.
If you use the Console app, you should look at the buttom of the console.log window
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

@@ -0,0 +1,60 @@
Compiling and developing OpenTTD on MandrakeLinux 10.0 Official
A quick guide to get started with OpenTTD development on Linux.
---------------------------------------------------------------
1.) RPMs:
Most packages that are required for development (like gcc) should already be installed on your box. You will require those RPMs additionally:
- libsdl1.2-devel-1.2.7-2mdk
- subversion-1.0.1-1mdk (+ dependencies)
- libsvn_ra_svn1_0-1.0.1-1mdk
2.) Subversion:
To obtain the source code from the subversion server type
$ svn co svn://svn.openttd.com/openttd/trunk openttd
from command line to dump the code into the directory 'openttd'.
To update your working copy to the latest revision use
$ svn update
Don't worry, your version will be merged with the latest version.
The command
$ svn diff > mypatch.diff
creates a patch file (aka diff file) which you can submit to the developers to share your improvements.
You can undo changes to a file with
$svn revert filename
3.) Required data files:
Copy the following files from the WINDOWS version of Transport Tycoon Deluxe to openttd/data/
sample.cat
trg1r.grf
trgcr.grf
trghr.grf
trgir.grf
trgtr.grf
4.) Compiling and running:
Compile OpenTTD with
$ make
and run it with
$ ./ttd
5.) Playing the soundtrack:
If you want the original TTD music you need to copy the whole /gm/ directory from Windows. Additionally the TiMidity driver is required:
TiMidity++-2.12.0-0.pre1.4mdk (+ dependencies)
To run OpenTTD with music support type
$ ./ttd -m extmidi
X.) Last Update: $Date: 2004-06-01 19:08:09 +0200 (Tue, 01 Jun 2004) $
Written for revision $Rev: 710 $

View File

@@ -1,139 +0,0 @@
OpenTTD: OS/2 version
=====================
OpenTTD has been ported to work on OS/2 4.x or later (including
eComStation). The game should work as well as it does on Windows
or other platforms: the main issues you may encounter are graphics
card problems, but that is really the fault of SDL.
=========================
USING OPENTTD FOR OS/2
=========================
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/.
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).
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
incarnation (see www.scitech.com) are necessary for it to work. If
you have trouble with your native drivers, try the Scitech drivers
and see if they help the problem.
KNOWN ISSUES
------------
- If an error occurs during loading, the OS/2 error message window
is not always displayed.
A NOTE ABOUT MUSIC
------------------
OpenTTD includes a music driver which uses the MCI MIDI system. Unfortunately,
due to the lack of proper MIDI hardware myself, I have been unable to test it,
but during testing, I found that when MIDI was enabled, I got no sound
effects. I therefore decided to DISABLE music by default.
To enable music, start OpenTTD with the command line:
openttd -m os2
If I hear enough responses that both music and sound work together (it might
just be my system), I'll have the defaults changed.
Please note also that the GCC version does not currently support the MCI MIDI
system.
A NOTE ABOUT DEDICATED MULTIPLAYER SERVERS
------------------------------------------
To start a dedicated multiplayer server, you should run the dedicated.cmd
file. This enables OpenTTD to open up a VIO console window to display
its output and gather any necessary input. Running "openttd -D"
directly will result in the console not being displayed. You may
still pass any other parameters ('-D' is already passed) to
dedicated.cmd.
You can find the dedicated.cmd file in the os/os2 directory.
=========================
BUILDING THE OS/2 VERSION
=========================
Compiler
--------
Innotek GCC, an OS/2 port of the popular GCC compiler, was used to build OpenTTD.
See www.innotek.de for more information. You WILL need a reasonably UNIX-like
build environment in order to build OpenTTD successfully - the following link
may help to set one up (although some of the links from that page are broken):
http://www.mozilla.org/ports/os2/gccsetup.html
Alternatively, Paul Smedley's ready-to-go GCC build environment has been known to
successfully build the game:
http://www.smedley.info/os2ports/index.php?page=build-environment
To build, you should, if your environment is set up well enough, be able to just
type `./configure' (or `sh configure' if you're using the OS/2 shell) and `make'.
You may have to manually specify `--os OS2' on the configure command line, as
configure cannot always detect OS/2 correctly.
A note on Open Watcom
---------------------
Open Watcom C/C++ was previously used to build OpenTTD (version 0.4.x and earlier).
However, due to advanced C++ features used in the YAPF portion of OpenTTD 0.5
in particular, the compiler is no longer able to build the game at the moment.
Hopefully one day Open Watcom will be able to catch up and we will be able to build
the game once again (it's easier than getting an OS/2 UNIX-like environment set up
in my opinion!), but until then, OpenTTD 0.5 and later can only be built with GCC.
Libraries Required
------------------
The following libraries are required. To build zlib and libpng, I
simply added the required files (watch out for sample programs, etc)
to an IDE project file and built a library. Do not use the makefiles
provided, they are not designed for Watcom (apart from SDL):
- zlib
http://www.zlib.org/
- libpng
http://www.libpng.org/
- SDL for OS/2
ftp://ftp.netlabs.org/pub/sdl/sdl-1.2.7-src-20051222.zip used for
0.4.7
- Freetype
http://freetype.sourceforge.net/
Currently, there are no pre-built libraries available for GCC. If you manage to get
OpenTTD working on Watcom though (do let us know if this is the case!), pre-built
versions can be downloaded from the Files section at
http://sourceforge.net/projects/openttd/ - see "os2-useful-v1.1.zip".
Contact Information
-------------------
If you have any questions regarding OS/2 issues, please contact me
(owen@owenrudge.net) and I'll try to help you out. For general OpenTTD
issues, see the Contacting section of readme.txt.
Thanks to Paul Smedley for his help with getting OpenTTD to compile under GCC on OS/2.
- Owen Rudge, 24th June 2007

View File

@@ -1,115 +0,0 @@
Compiling OpenTTD using Microsoft Visual C++
January 2, 2007
--------------------------------------------
PLEASE READ THE ENTIRE DOCUMENT BEFORE DOING ANY ACTUAL CHANGES!!
SUPPORTED MSVC COMPILERS
------------------------
OpenTTD includes projects for MSVC 2005.NET and MSVC 2008.NET. Both will
compile out of the box, providing you have the required libraries/headers;
which ones, see below. There is no support for VS6 or MSVC 2002, or
MSVC 2003.NET. You are therefore strongly encouraged to either upgrade to
MSVC 2005 Express (free) or use GCC.
1) REQUIRED FILES
-----------------
You might already have some of the files already installed, so check before
downloading; mostly because the DirectX SDK and Platform SDK are about
500MB each.
Download the following files:
* openttd-useful.zip (http://sf.net/project/showfiles.php?group_id=103924&package_id=114307)
* DirectX 8.1 SDK (http://neuron.tuke.sk/~mizanin/eng/Dx81sdk-include-lib.rar) (or alternatively the latest DirectX SDK from Microsoft)
* MS Windows Platform SDK (http://www.microsoft.com/downloads/details.aspx?FamilyId=A55B6B43-E24F-4EA3-A93E-40C0EC4F68E5&displaylang=en)
* 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
You need an SVN-client to download the source from subversion:
* CLI Subversion (http://subversion.tigris.org/servlets/ProjectDocumentList?folderID=91)
* GUI TortoiseSVN (http://tortoisesvn.tigris.org/download.html)
2) INCLUDES AND LIBRARIES
-------------------------
Put the newly downloaded files in the VC lib\ and include\ directories; where
"C:\Program Files\Microsoft Visual Studio 8\VC" is your location of Visual C.
If you are compiling for an x64 system, use the include\ and lib\ directories
from the win64/ folder.
* openttd-useful.zip\include\*
* afxresh.h
to > C:\Program Files\Microsoft Visual Studio 8\VC\Include
* openttd-useful.zip\lib\*
to > C:\Program Files\Microsoft Visual Studio 8\VC\Lib
Custom directories might be recommended, check 2.2)
2.1) INCLUDES AND LIBRARIES - DIRECTX/PLATFORM SDK
--------------------------------------------------
Basically the same procedure as with the useful zip file, providing
you are not using the Microsoft installer. Put the include files in the
include\ directory and the library files to the Lib\ directory.
It is recommended to use custom directories so you don't overwrite any
default header or library files.
2.2) CUSTOM DIRECTORIES
-----------------------
If you have put the above include and/or library files into custom folders,
MSVC will not find them by default. You need to add these paths to VC through:
Tools > Options > Projects and Solutions > VC++ Directories > show directories for
* Include files: Add the DirectX/Platform SDK include dir you've created
* Library files: Add the path to the SDK custom lib dir
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!!
3) TTD GRAPHICS FILES
---------------------
Copy the following files from Transport Tycoon Deluxe to the bin/data folder
* sample.cat
* trg1r.grf
* trgcr.grf
* trghr.grf
* trgir.grf
* trgtr.grf
4) COMPILING
------------
Open trunk/openttd_vs[89]0.sln
Set the build mode to 'Release' in
Build > Configuration manager > Active solution configuration > select "Release"
Compile...
If everything works well the binary should be in trunk/objs/Win[32|64]/Release/openttd.exe
5) EDITING, CHANGING SOURCE CODE
--------------------------------
Set the build mode (back to) 'Debug'
Change the startup project to openttd by right-clicking the 'openttd' project
in the Solution Explorer and selecting 'Set as Startup Project'. The 'openttd'
project should now show up bold instead of 'strgen'.
6) PROBLEMS?
------------
If compilation fails, double-check that you are using the latest SVN (!)
source. If it still doesn't work, check in on IRC (irc://irc.oftc.net/openttd),
to ask about reasons; or just wait. The problem will most likely solve itself
within a few days as the problem is noticed and fixed.
An up-to-date version of this README can be found on the wiki:
http://wiki.openttd.org/index.php/MicrosoftVisualCExpress

View File

@@ -0,0 +1,89 @@
Compilung OpenTTD using MS VC6.0
Step 1
------------------
Downloaded:
Useful.zip http://sourceforge.net/project/showfiles.php?group_id=103924&package_id=114307&release_id=228633
SDL.zip http://www.libsdl.org/release/SDL-1.2.7-win32.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
Step 2
------------------
Put the newly downloaded files in the VC lib and include directories
(Where D:\program files\ is your local location of VC)
* zconf.h [useful.zip]
* zlib.h [useful.zip]
* afxres.h
in
D:\Program Files\Microsoft Visual Studio\VC98\Include
* zlibstat.lib [usefull.zip]
* SDL.lib [SDL.zip
* libpng.lib [usefull.zip]
in
D:\Program Files\Microsoft Visual Studio\VC98\Lib
You can also make custum 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: D:\Program Files\Microsoft Visual Studio\VC98\DirectX 7 SDK\include )
b) library files (the lib dir, D:\Program Files\Microsoft Visual Studio\VC98\DirectX 7 SDK\lib )
Step 3: DirextX SDK
------------------
(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.
Copy the DirectX 7 SDK files, leaving the directory stucture intact, to the directory:
D:\Program Files\Microsoft Visual Studio\VC98\
thus resulting in
D:\Program Files\Microsoft Visual Studio\VC98\DirectX 7 SDK\include and
D:\Program Files\Microsoft Visual Studio\VC98\DirectX 7 SDK\lib
Step 3.1
Add these two folders to the search path of VC.
In VC6.0: Tools -> Options -> Directories -> show directories for:
a) include files (the include dir: D:\Program Files\Microsoft Visual Studio\VC98\DirectX 7 SDK\include )
b) libraru files (the lib dir, D:\Program Files\Microsoft Visual Studio\VC98\DirectX 7 SDK\lib )
Step 4
-----------------
Copy the following files from the WINDOWS version of Transport Tycoon Deluxe to the data folder
sample.cat
trg1r.grf
trgcr.grf
trghr.grf
trgir.grf
trgtr.grf
Step 5
-----------------
Compile ...
Step 6
-----------------
Now it should work, it worked for me :)
Go ahead and make that patch!
Happy Hacking!
------------------
written by Dribbel

54
docs/console.txt Normal file
View File

@@ -0,0 +1,54 @@
OPENTTD INGAME CONSOLE DOCUMENTATION
====================================
http://openttd.rulez.org/wiki2/index.php/OpenTTDDevBlackBook
for detailed information
HOTKEY: BACKQUOTE (aka tilde, the key left to "1")
COMMANDS:
---------
echo [string]
echoc [color-code] [string]
exit
debug_level [0-9]
dump_vars [filter]
help
list_cmds [filter]
list_vars [filter]
printf [formatstring] [var] [var] [var]....
printfc [color-code] [formatstring] [var] [var] [var]....
quit
random
screenshot ["big"/"no_con"]
VARIABLES:
----------
*con_developer
-> true = console debugging info
-> false = no output
*developer
-> 0 = no output
-> 1 = console error output [like command not found]
-> 2 = console error and debug output
*cursor_rate
-> 1-12 = defines the cursor blink interval
VARIABLE HANDLING:
------------------
*developer = 0
*developer ++
*temp_string = test
*temp_string = "my little"
printf "%s world" *temp_string
---------------------------------------------------
feel free to add more commands and use this in-game
console for your debugging / enhancements

20
docs/directmusic.txt Normal file
View File

@@ -0,0 +1,20 @@
Notes about DirectMusic driver for Win32
----------------------------------------
If compiling under MinGW32, you require the DirectX 7.0 files for MinGW32, available from
http://alleg.sourceforge.net/files/dx70_mgw.zip.
If compiling under MSVC 6.0, you require the equivalent for MSVC, available from
http://alleg.sourceforge.net/files/dx70_min.zip. MSVC 7.0/7.1 include header files that
are recent enough.
If you do not want to compile the DirectMusic driver, undefine WIN32_ENABLE_DIRECTMUSIC_SUPPORT
in stdafx.h.
Bugs, etc
---------
- The volume control doesn't work properly. I'll fix this soon.
Owen Rudge
14th March 2004

File diff suppressed because it is too large Load Diff

Before

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 61 KiB

File diff suppressed because it is too large Load Diff

View File

@@ -1,616 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="Author" content="Marcin Grzegorczyk">
<meta name="Description" content="Structure of OpenTTD (OTTD) landscape arrays">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>OpenTTD Landscape externals</title>
</head>
<body>
<h3><a name="Landscape">Landscape</a></h3>
<p>
These are the different house types available on standard game.<br>
<small>Note: In the climate list, 'sub-arctic' means below the snow line, 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>
<tr>
<td nowrap valign=top><tt>00</tt>&nbsp; </td>
<td>1&times;1</td>
<td>temperate</td>
<td align=left>tall office block</td>
</tr>
<tr>
<td nowrap valign=top><tt>01</tt>&nbsp; </td>
<td>1&times;1</td>
<td>temperate</td>
<td align=left>office block</td>
</tr>
<tr>
<td nowrap valign=top><tt>02</tt>&nbsp; </td>
<td>1&times;1</td>
<td>temperate</td>
<td align=left>small block of flats</td>
</tr>
<tr>
<td nowrap valign=top><tt>03</tt>&nbsp; </td>
<td>1&times;1</td>
<td>temperate</td>
<td align=left>church</td>
</tr>
<tr>
<td nowrap valign=top><tt>04</tt>&nbsp; </td>
<td>1&times;1</td>
<td>temperate, sub-arctic, sub-tropical</td>
<td align=left>large office block</td>
</tr>
<tr>
<td nowrap valign=top><tt>05</tt>&nbsp; </td>
<td>1&times;1</td>
<td>snow</td>
<td align=left>large office block</td>
</tr>
<tr>
<td nowrap valign=top><tt>06</tt>&nbsp; </td>
<td>1&times;1</td>
<td>temperate</td>
<td align=left>town houses</td>
</tr>
<tr>
<td nowrap valign=top><tt>07</tt>..<tt>08</tt>&nbsp; </td>
<td>1&times;2</td>
<td>temperate</td>
<td align=left>hotel</td>
</tr>
<tr>
<td nowrap valign=top><tt>09</tt>&nbsp; </td>
<td>1&times;1</td>
<td>temperate, sub-arctic, sub-tropical&nbsp;&nbsp;</td>
<td align=left>statue</td>
</tr>
<tr>
<td nowrap valign=top><tt>0A</tt>&nbsp; </td>
<td>1&times;1</td>
<td>temperate, sub-arctic, sub-tropical</td>
<td align=left>fountain</td>
</tr>
<tr>
<td nowrap valign=top><tt>0B</tt>&nbsp; </td>
<td>1&times;1</td>
<td>temperate</td>
<td align=left>park (with a pond)</td>
</tr>
<tr>
<td nowrap valign=top><tt>0C</tt>&nbsp; </td>
<td>1&times;1</td>
<td>temperate</td>
<td align=left>park (with an alley)</td>
</tr>
<tr>
<td nowrap valign=top><tt>0D</tt>&nbsp; </td>
<td>1&times;1</td>
<td>temperate</td>
<td align=left>office block</td>
</tr>
<tr>
<td nowrap valign=top><tt>0E</tt>..<tt>10</tt>&nbsp; </td>
<td>1&times;1</td>
<td>temperate</td>
<td align=left>various types of shops and offices</td>
</tr>
<tr>
<td nowrap valign=top><tt>11</tt>&nbsp; </td>
<td>1&times;1</td>
<td>temperate, sub-arctic, sub-tropical</td>
<td align=left>modern office building</td>
</tr>
<tr>
<td nowrap valign=top><tt>12</tt>&nbsp; </td>
<td>1&times;1</td>
<td>temperate</td>
<td align=left>warehouse</td>
</tr>
<tr>
<td nowrap valign=top><tt>13</tt>&nbsp; </td>
<td>1&times;1</td>
<td>temperate</td>
<td align=left>office block (with spiral stairway on the side)</td>
</tr>
<tr>
<td nowrap valign=top><tt>14</tt>..<tt>17</tt>&nbsp; </td>
<td>2&times;2</td>
<td>temperate</td>
<td align=left>stadium</td>
</tr>
<tr>
<td nowrap valign=top><tt>18</tt>&nbsp; </td>
<td>1&times;1</td>
<td>temperate</td>
<td align=left>old houses</td>
</tr>
<tr>
<td nowrap valign=top><tt>19</tt>&nbsp; </td>
<td>1&times;1</td>
<td>temperate</td>
<td align=left>cottages</td>
</tr>
<tr>
<td nowrap valign=top><tt>1A</tt>&nbsp; </td>
<td>1&times;1</td>
<td>temperate</td>
<td align=left>houses</td>
</tr>
<tr>
<td nowrap valign=top><tt>1B</tt>&nbsp; </td>
<td>1&times;1</td>
<td>temperate</td>
<td align=left>flats</td>
</tr>
<tr>
<td nowrap valign=top><tt>1C</tt>&nbsp; </td>
<td>1&times;1</td>
<td>temperate</td>
<td align=left>tall office block</td>
</tr>
<tr>
<td nowrap valign=top><tt>1D</tt>&nbsp; </td>
<td>1&times;1</td>
<td>temperate</td>
<td align=left>shops and offices</td>
</tr>
<tr>
<td nowrap valign=top><tt>1E</tt>&nbsp; </td>
<td>1&times;1</td>
<td>temperate, sub-tropical</td>
<td align=left>shops and offices</td>
</tr>
<tr>
<td nowrap valign=top><tt>1F</tt>&nbsp; </td>
<td>1&times;1</td>
<td>temperate</td>
<td align=left>theatre</td>
</tr>
<tr>
<td nowrap valign=top><tt>20</tt>..<tt>23</tt>&nbsp; </td>
<td>2&times;2</td>
<td>temperate, sub-arctic, sub-tropical</td>
<td align=left>stadium (modern style)</td>
</tr>
<tr>
<td nowrap valign=top><tt>24</tt>&nbsp; </td>
<td>1&times;1</td>
<td>temperate, sub-arctic, sub-tropical</td>
<td align=left>offices (the modern 'vertical tube' style)</td>
</tr>
<tr>
<td nowrap valign=top><tt>25</tt>&nbsp; </td>
<td>1&times;1</td>
<td>sub-arctic</td>
<td align=left>houses</td>
</tr>
<tr>
<td nowrap valign=top><tt>26</tt>&nbsp; </td>
<td>1&times;1</td>
<td>snow</td>
<td align=left>houses</td>
</tr>
<tr>
<td nowrap valign=top><tt>27</tt>&nbsp; </td>
<td>1&times;1</td>
<td>temperate</td>
<td align=left>cinema</td>
</tr>
<tr>
<td nowrap valign=top><tt>28</tt>..<tt>2B</tt>&nbsp; </td>
<td>2&times;2</td>
<td>temperate</td>
<td align=left>shopping mall</td>
</tr>
<tr>
<td nowrap valign=top><tt>2C</tt>&nbsp; </td>
<td>1&times;1</td>
<td>sub-arctic</td>
<td align=left>flats</td>
</tr>
<tr>
<td nowrap valign=top><tt>2D</tt>&nbsp; </td>
<td>1&times;1</td>
<td>snow</td>
<td align=left>flats</td>
</tr>
<tr>
<td nowrap valign=top><tt>2E</tt>&nbsp; </td>
<td>1&times;1</td>
<td>sub-arctic</td>
<td align=left>houses</td>
</tr>
<tr>
<td nowrap valign=top><tt>2F</tt>&nbsp; </td>
<td>1&times;1</td>
<td>snow</td>
<td align=left>houses</td>
</tr>
<tr>
<td nowrap valign=top><tt>30</tt>&nbsp; </td>
<td>1&times;1</td>
<td>sub-arctic</td>
<td align=left>houses</td>
</tr>
<tr>
<td nowrap valign=top><tt>31</tt>&nbsp; </td>
<td>1&times;1</td>
<td>snow</td>
<td align=left>houses</td>
</tr>
<tr>
<td nowrap valign=top><tt>32</tt>&nbsp; </td>
<td>1&times;1</td>
<td>sub-arctic, sub-tropical</td>
<td align=left>tall office block</td>
</tr>
<tr>
<td nowrap valign=top><tt>33</tt>&nbsp; </td>
<td>1&times;1</td>
<td>snow</td>
<td align=left>tall office block</td>
</tr>
<tr>
<td nowrap valign=top><tt>34</tt>&nbsp; </td>
<td>1&times;1</td>
<td>sub-arctic</td>
<td align=left>tall office block</td>
</tr>
<tr>
<td nowrap valign=top><tt>35</tt>&nbsp; </td>
<td>1&times;1</td>
<td>snow</td>
<td align=left>tall office block</td>
</tr>
<tr>
<td nowrap valign=top><tt>36</tt>&nbsp; </td>
<td>1&times;1</td>
<td>sub-arctic, sub-tropical</td>
<td align=left>tall office block</td>
</tr>
<tr>
<td nowrap valign=top><tt>37</tt>&nbsp; </td>
<td>1&times;1</td>
<td>snow</td>
<td align=left>tall office block</td>
</tr>
<tr>
<td nowrap valign=top><tt>38</tt>&nbsp; </td>
<td>1&times;1</td>
<td>sub-arctic</td>
<td align=left>houses</td>
</tr>
<tr>
<td nowrap valign=top><tt>39</tt>&nbsp; </td>
<td>1&times;1</td>
<td>snow</td>
<td align=left>houses</td>
</tr>
<tr>
<td nowrap valign=top><tt>3A</tt>&nbsp; </td>
<td>1&times;1</td>
<td>sub-arctic</td>
<td align=left>shops and offices</td>
</tr>
<tr>
<td nowrap valign=top><tt>3B</tt>&nbsp; </td>
<td>1&times;1</td>
<td>snow</td>
<td align=left>shops and offices</td>
</tr>
<tr>
<td nowrap valign=top><tt>3C</tt>&nbsp; </td>
<td>1&times;1</td>
<td>sub-arctic</td>
<td align=left>church</td>
</tr>
<tr>
<td nowrap valign=top><tt>3D</tt>&nbsp; </td>
<td>1&times;1</td>
<td>snow</td>
<td align=left>church</td>
</tr>
<tr>
<td nowrap valign=top><tt>3E</tt>&nbsp; </td>
<td>1&times;1</td>
<td>sub-arctic</td>
<td align=left>houses</td>
</tr>
<tr>
<td nowrap valign=top><tt>3F</tt>&nbsp; </td>
<td>1&times;1</td>
<td>snow</td>
<td align=left>houses</td>
</tr>
<tr>
<td nowrap valign=top><tt>40</tt>&nbsp; </td>
<td>1&times;1</td>
<td>sub-arctic</td>
<td align=left>shops and offices</td>
</tr>
<tr>
<td nowrap valign=top><tt>41</tt>&nbsp; </td>
<td>1&times;1</td>
<td>snow</td>
<td align=left>shops and offices</td>
</tr>
<tr>
<td nowrap valign=top><tt>42</tt>..<tt>43</tt>&nbsp; </td>
<td>1&times;2</td>
<td>sub-arctic</td>
<td align=left>hotel</td>
</tr>
<tr>
<td nowrap valign=top><tt>44</tt>..<tt>45</tt>&nbsp; </td>
<td>1&times;2</td>
<td>snow</td>
<td align=left>hotel</td>
</tr>
<tr>
<td nowrap valign=top><tt>46</tt>&nbsp; </td>
<td>1&times;1</td>
<td>sub-arctic, sub-tropical</td>
<td align=left>shops and offices</td>
</tr>
<tr>
<td nowrap valign=top><tt>47</tt>&nbsp; </td>
<td>1&times;1</td>
<td>snow</td>
<td align=left>shops and offices</td>
</tr>
<tr>
<td nowrap valign=top><tt>48</tt>&nbsp; </td>
<td>1&times;1</td>
<td>sub-arctic</td>
<td align=left>tall office block</td>
</tr>
<tr>
<td nowrap valign=top><tt>49</tt>&nbsp; </td>
<td>1&times;1</td>
<td>snow</td>
<td align=left>tall office block</td>
</tr>
<tr>
<td nowrap valign=top><tt>4A</tt>..<tt>4B</tt>&nbsp; </td>
<td>2&times;1</td>
<td>sub-arctic</td>
<td align=left>tall office block</td>
</tr>
<tr>
<td nowrap valign=top><tt>4C</tt>..<tt>4D</tt>&nbsp; </td>
<td>2&times;1</td>
<td>snow</td>
<td align=left>tall office block</td>
</tr>
<tr>
<td nowrap valign=top><tt>4E</tt>&nbsp; </td>
<td>1&times;1</td>
<td>sub-tropical</td>
<td align=left>houses (with a tree in a corner)</td>
</tr>
<tr>
<td nowrap valign=top><tt>4F</tt>, <tt>50</tt>&nbsp; </td>
<td>1&times;1</td>
<td>sub-tropical</td>
<td align=left>houses</td>
</tr>
<tr>
<td nowrap valign=top><tt>51</tt>&nbsp; </td>
<td>1&times;1</td>
<td>sub-tropical</td>
<td align=left>houses (suburb-type)</td>
</tr>
<tr>
<td nowrap valign=top><tt>52</tt>&nbsp; </td>
<td>1&times;1</td>
<td>sub-tropical</td>
<td align=left>flats</td>
</tr>
<tr>
<td nowrap valign=top><tt>53</tt>&nbsp; </td>
<td>1&times;1</td>
<td>sub-tropical</td>
<td align=left>church</td>
</tr>
<tr>
<td nowrap valign=top><tt>54</tt>&nbsp; </td>
<td>1&times;1</td>
<td>sub-tropical</td>
<td align=left>houses (with two trees in front)</td>
</tr>
<tr>
<td nowrap valign=top><tt>55</tt>, <tt>56</tt>&nbsp; </td>
<td>1&times;1</td>
<td>sub-tropical</td>
<td align=left>flats</td>
</tr>
<tr>
<td nowrap valign=top><tt>57</tt>..<tt>58</tt>&nbsp; </td>
<td>2&times;1</td>
<td>sub-tropical</td>
<td align=left>tall office block</td>
</tr>
<tr>
<td nowrap valign=top><tt>59</tt>&nbsp; </td>
<td>1&times;1</td>
<td>sub-tropical</td>
<td align=left>flats</td>
</tr>
<tr>
<td nowrap valign=top><tt>5A</tt>&nbsp; </td>
<td>1&times;1</td>
<td>sub-tropical</td>
<td align=left>tall office block</td>
</tr>
<tr>
<td nowrap valign=top><tt>5B</tt>&nbsp; </td>
<td>1&times;1</td>
<td>toyland</td>
<td align=left>church</td>
</tr>
<tr>
<td nowrap valign=top><tt>5C</tt>..<tt>61</tt>&nbsp; </td>
<td>1&times;1</td>
<td>toyland</td>
<td align=left>various types of toyland houses</td>
</tr>
<tr>
<td nowrap valign=top><tt>62</tt>&nbsp; </td>
<td>1&times;1</td>
<td>toyland</td>
<td align=left>tall office block</td>
</tr>
<tr>
<td nowrap valign=top><tt>63</tt>..<tt>64</tt>&nbsp; </td>
<td>1&times;2</td>
<td>toyland</td>
<td align=left>houses ('shoe' style)</td>
</tr>
<tr>
<td nowrap valign=top><tt>65</tt>&nbsp; </td>
<td>1&times;1</td>
<td>toyland</td>
<td align=left>tall office block</td>
</tr>
<tr>
<td nowrap valign=top><tt>66</tt>&nbsp; </td>
<td>1&times;1</td>
<td>toyland</td>
<td align=left>igloo</td>
</tr>
<tr>
<td nowrap valign=top><tt>67</tt>&nbsp; </td>
<td>1&times;1</td>
<td>toyland</td>
<td align=left>tepees</td>
</tr>
<tr>
<td nowrap valign=top><tt>68</tt>, <tt>69</tt>&nbsp; </td>
<td>1&times;1</td>
<td>toyland</td>
<td align=left>shops and offices</td>
</tr>
<tr>
<td nowrap valign=top><tt>6A</tt>&nbsp; </td>
<td>1&times;1</td>
<td>toyland</td>
<td align=left>tall office block</td>
</tr>
<tr>
<td nowrap valign=top><tt>6B</tt>&nbsp; </td>
<td>1&times;1</td>
<td>toyland</td>
<td align=left>statue</td>
</tr>
<tr>
<td nowrap valign=top><tt>6C</tt>&nbsp; </td>
<td>1&times;1</td>
<td>toyland</td>
<td align=left>teapot-house</td>
</tr>
<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>
</table>
</body>
</html>

View File

@@ -1,355 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type">
<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.option{ font-family: "Courier New", Courier, mono; background-color: rgb(255,255, 30); }
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; }
</style>
</head>
<body style="direction: ltr;">
<h3 style="font-weight: bold;">Landscape</h3>
<span style="font-weight: bold;"></span>Six attributes hold the information about a 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, i.e. other bits define the actual meaning.</li>
<li><span style="font-weight: bold;"><span class="option">~</span></span> - bit is accessed, but does not really have a meaning (e.g. owner of clear land is always OWNER_NONE)</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;">m6</span> - 8 bits in size, special meaning : lower 2 bits only valid in tropic climate, upper 2 bits for bridges</li>
<li><span style="font-weight: bold;">m7</span> - 8 bits in size, is used for general storage</li>
</ul>
<table align=center border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<th colspan=2>class</th>
<th>type_height (8)</th>
<th>m1 (8)</th>
<th>m2 (16)</th>
<th>m3 (8)</th>
<th>m4 (8)</th>
<th>m5 (8)</th>
<th>m6 (8)</th>
<th>m7 (8)</th>
</tr>
<tr>
<td colspan=2 class="caption">bits</td>
<td class="bits">7654 3210</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 class="bits">7654 3210</td>
</tr>
<tr>
<td rowspan="2">0</td>
<td class="caption">ground</td>
<td class="bits">XXXX XXXX</td>
<td class="bits"><span class="option">~~~~ ~~~~</span></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">XXXX XX<span class="free">OO</span></td>
<td class="bits">XXXX XXXX</td>
<td class="bits">XX<span class="free">OO OO</span>XX</td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
</tr>
<tr>
<td class="caption">farmland</td>
<td class="bits">-inherit-</td>
<td class="bits"><span class="option">~~~~ ~~~~</span></td>
<td class="bits">XXXX XXXX XXXX XXXX</td>
<td class="bits"><span class="free">OOOO</span> XXXX</td>
<td class="bits">-inherit-</td>
<td class="bits">-inherit-</td>
<td class="bits">XX<span class="free">OO OO</span>XX</td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
</tr>
<tr>
<td rowspan=4>1</td>
<td class="caption">rail</td>
<td class="bits">XXXX XXXX</td>
<td class="bits"><span class="option">~~~</span>X XXXX</td>
<td class="bits"><span class="free">OOOO OOOO OOOO OOOO</span></td>
<td class="bits"><span class="free">OOOO</span> <span class="option">~~</span>XX</td>
<td class="bits"><span class="free">OOOO</span> XXXX</td>
<td class="bits">XXXX XXXX</td>
<td class="bits">XX<span class="free">OO OO</span>XX</td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
</tr>
<tr>
<td class="caption">rail with signals</td>
<td class="bits">-inherit-</td>
<td class="bits">-inherit-</td>
<td class="bits"><span class="free">OOOO OOOO O</span>XXX <span class="free">O</span>XXX</td>
<td class="bits">XXXX <span class="option">~~</span>XX</td>
<td class="bits">XXXX XXXX</td>
<td class="bits">-inherit-</td>
<td class="bits">XX<span class="free">OO OO</span>XX</td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
</tr>
<tr>
<td class="caption">depot</td>
<td class="bits">-inherit-</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> <span class="option">~~</span>XX</td>
<td class="bits"><span class="free">OOOO</span> XXXX</td>
<td class="bits">XX<span class="free">OO OO</span>XX</td>
<td class="bits">XX<span class="free">OO OO</span>XX</td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
</tr>
<tr>
<td class="caption">waypoint</td>
<td class="bits">-inherit-</td>
<td class="bits">-inherit-</td>
<td class="bits">XXXX XXXX XXXX XXXX</td>
<td class="bits"><span class="free">OOOO</span> <span class="option">~~</span>XX</td>
<td class="bits"><span class="free">OOOO</span> XXXX</td>
<td class="bits">XX<span class="free">OO OOO</span>X</td>
<td class="bits">XX<span class="free">OO OO</span>XX</td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
</tr>
<tr>
<td rowspan=3>2</td>
<td class="caption">road</td>
<td class="bits">XXXX XXXX</td>
<td class="bits"><span class="option">~~~</span>X XXXX</td>
<td class="bits">XXXX XXXX XXXX XXXX</td>
<td class="bits">XXXX XXXX</td>
<td class="bits">XXXX XXXX</td>
<td class="bits">XXXX XXXX</td>
<td class="bits">XXXX XXXX</td>
<td class="bits">XXXX XXXX</td>
</tr>
<tr>
<td class="caption">level crossing</td>
<td class="bits">-inherit-</td>
<td class="bits">-inherit-</td>
<td class="bits">-inherit-</td>
<td class="bits">XXXX <span class="option">~~</span>XX</td>
<td class="bits"><span class="free">O</span>XXX XXXX</td>
<td class="bits">XX<span class="free">OO</span> XXXX</td>
<td class="bits">XX<span class="free">OO OO</span>XX</td>
<td class="bits">-inherit-</td>
</tr>
<tr>
<td class="caption">road depot</td>
<td class="bits">-inherit-</td>
<td class="bits">-inherit-</td>
<td class="bits"><span class="free">OOOO OOOO OOOO OOOO</span></td>
<td class="bits">X<span class="free">OOO OOOO</span></td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
<td class="bits">XX<span class="free">OO OO</span>XX</td>
<td class="bits">XX<span class="free">OO OO</span>XX</td>
<td class="bits">XXX<span class="free">O OOOO</span></td>
</tr>
<tr>
<td>3</td>
<td class="caption">house</td>
<td class="bits">XXXX XXXX</td>
<td class="bits">XXXX XXXX</td>
<td class="bits">XXXX XXXX XXXX XXXX</td>
<td class="bits">XXX<span class="option">~ ~~</span>XX</td>
<td class="bits">XXXX XXXX</td>
<td class="bits">XXX<span class="abuse">X XXXX</span></td>
<td class="bits"><span class="abuse">XXXX XX</span>XX</td>
<td class="bits">XXXX <span class="abuse">XXXX</span></td>
</tr>
<tr>
<td>4</td>
<td class="caption">trees</td>
<td class="bits">XXXX XXXX</td>
<td class="bits"><span class="option">~~~~ ~~~~</span></td>
<td class="bits"><span class="free">OOOO OOOO</span> XXXX XXXX</td>
<td class="bits"><span class="option">~~</span>XX XXXX</td>
<td class="bits">XXXX XX<span class="free">OO</span></td>
<td class="bits">XX<span class="free">OO O</span>XXX</td>
<td class="bits"><span class="free">OOOO OO</span>XX</td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
</tr>
<tr>
<td rowspan=6>5</td>
<td class="caption">rail station</td>
<td class="bits">XXXX XXXX</td>
<td class="bits"><span class="option">~~~</span>X XXXX</td>
<td class="bits">XXXX XXXX XXXX XXXX</td>
<td class="bits">XXXX <span class="option">~~</span>XX</td>
<td class="bits">XXXX XXXX</td>
<td class="bits">XXXX XXXX</td>
<td class="bits"><span class="free">OO</span>XX X<span class="free">O</span>XX</td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
</tr>
<tr>
<td class="caption">road stop</td>
<td class="bits">-inherit-</td>
<td class="bits">-inherit-</td>
<td class="bits">-inherit-</td>
<td class="bits"><span class="free">OOOO O</span>XXX</td>
<td class="bits"><span class="option">~~~~ ~~~~</span></td>
<td class="bits"><span class="option">~~~~ ~</span>XXX</td>
<td class="bits"><span class="free">OO</span>XX XXXX</td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
</tr>
<tr>
<td class="caption">dock</td>
<td class="bits">-inherit-</td>
<td class="bits">-inherit-</td>
<td class="bits">-inherit-</td>
<td class="bits"><span class="free">OOOO OO</span>XX</td>
<td class="bits"><span class="option">~~~~ ~~~~</span></td>
<td class="bits"><span class="option">~~~~ ~</span>XXX</td>
<td class="bits"><span class="free">OO</span>XX X<span class="free">O</span>XX</td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
</tr>
<tr>
<td class="caption">airport</td>
<td class="bits">-inherit-</td>
<td class="bits">-inherit-</td>
<td class="bits">-inherit-</td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
<td class="bits"><span class="option">~~~~ ~~~~</span></td>
<td class="bits">XXXX XXXX</td>
<td class="bits"><span class="free">OO</span>XX X<span class="free">O</span>XX</td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
</tr>
<tr>
<td class="caption">buoy</td>
<td class="bits">-inherit-</td>
<td class="bits">-inherit-</td>
<td class="bits">-inherit-</td>
<td class="bits"><span class="free">OOOO OO</span>XX</td>
<td class="bits"><span class="option">~~~~ ~~~~</span></td>
<td class="bits"><span class="option">~~~~ ~~~~</span></td>
<td class="bits"><span class="free">OO</span>XX X<span class="free">O</span>XX</td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
</tr>
<tr>
<td class="caption">oilrig</td>
<td class="bits">-inherit-</td>
<td class="bits">-inherit-</td>
<td class="bits">-inherit-</td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
<td class="bits"><span class="option">~~~~ ~~~~</span></td>
<td class="bits"><span class="option">~~~~ ~~~~</span></td>
<td class="bits"><span class="free">OO</span>XX X<span class="free">O</span>XX</td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
</tr>
<tr>
<td rowspan=3>6</td>
<td class="caption">sea, shore</td>
<td class="bits">XXXX XXXX</td>
<td class="bits"><span class="option">~~~</span>X XXXX</td>
<td class="bits"><span class="free">OOOO OOOO OOOO OOOO</span></td>
<td class="bits"><span class="free">OOOO OO</span>XX</td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
<td class="bits">X<span class="option">~~</span>X XXXX</td>
<td class="bits">XX<span class="free">OO OO</span>XX</td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
</tr>
<tr>
<td class="caption">canal, river</td>
<td class="bits">-inherit-</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 OO</span>XX</td>
<td class="bits">XXXX XXXX</td>
<td class="bits">-inherit-</td>
<td class="bits">XX<span class="free">OO OO</span>XX</td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
</tr>
<tr>
<td class="caption">shipdepot</td>
<td class="bits">-inherit-</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 OO</span>XX</td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
<td class="bits">-inherit-</td>
<td class="bits">XX<span class="free">OO OO</span>XX</td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
</tr>
<tr>
<td>8</td>
<td class="caption">industry</td>
<td class="bits">XXXX XXXX</td>
<td class="bits">X<span class="free">OOO</span> <span class="abuse">
XXXX</span></td>
<td class="bits">XXXX XXXX XXXX XXXX</td>
<td class="bits">XXXX XXXX</td>
<td class="bits">XXXX XXXX</td>
<td class="bits">XXXX XXXX</td>
<td class="bits"><span class="free">OO</span>XX XXXX</td>
<td class="bits">XXXX XXXX</td>
</tr>
<tr>
<td rowspan=2>9</td>
<td class="caption">tunnel entrance</td>
<td class="bits">XXXX XXXX</td>
<td class="bits"><span class="option">~~~</span>X XXXX</td>
<td class="bits"><span class="free">OOOO OOOO OOOO OOOO</span></td>
<td class="bits"><span class="free">OOOO</span> <span class="option">~</span><span class="abuse">XXX</span></td>
<td class="bits">X<span class="free">OOO OOOO</span></td>
<td class="bits">X<span class="free">OOO</span> <span class="option">~</span>XXX</td>
<td class="bits">XX<span class="free">OO OO</span>XX</td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
</tr>
<tr>
<td>bridge ramp</td>
<td class="bits">-inherit-</td>
<td class="bits">-inherit-</td>
<td class="bits"><span class="free">OOOO OOOO</span> XXXX <span class="free">OOOO</span></td>
<td class="bits"><span class="free">OOOO</span> <span class="option">~</span><span class="abuse">XXX</span></td>
<td class="bits">X<span class="free">OOO OOOO</span></td>
<td class="bits">X<span class="free">OOO</span> <span class="option">~</span>XXX</td>
<td class="bits">XX<span class="free">OO OO</span>XX</td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
</tr>
<tr>
<td rowspan=2>A</td>
<td class="caption">unmovables</td>
<td class="bits">XXXX XXXX</td>
<td class="bits"><span class="option">~~~</span>X 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">X<span class="option">~~</span>X XXXX</td>
<td class="bits">XX<span class="free">OO OO</span>XX</td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
</tr>
<tr>
<td class="caption">company statue</td>
<td class="bits">-inherit-</td>
<td class="bits">-inherit-</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">-inherit-</td>
<td class="bits">XX<span class="free">OO OO</span>XX</td>
<td class="bits"><span class="free">OOOO OOOO</span></td>
</tr>
</tbody>
</table>
</body>
</html>

View File

@@ -1,121 +1,70 @@
Multiplayer Manual for OpenTTD (0.3.5)
=======================================
Multiplayer Manual for OpenTTD
----------------------------------------
1. Starting a Server
---------------------
- Click "multiplayer" on the startup screen
- Click "start server"
- Type in a game name
- Select the type of game ('LAN/Internet' or 'Internet (advertise)'. With the last one
other people are able to see you online. Else they need your IP and port to join)
- Click "start game", "load game" or "load scenario"
- Start playing
- click "multiplayer" on the startup screen
- click "start server"
- type in a game name
- click "start game" ,"load game" or "load scenario"
2. Connecting to a Server
--------------------------
- Click "multiplayer" on the startup screen
- If you want to connect to any network game in your LAN click on 'LAN', then on
'Find Server'
- If you want to see which servers all online on the Internet, click on 'Internet'
and 'Find Server'
- If there were more then one server
- click "multiplayer" on the startup screen
- if you want to connect to any network game in your LAN click "find server"
- if there were more then one server
- select one in the list below the buttons
- click on 'join game'
- click on "join game".
- If you want to play and you have the ip or hostname of the game server you want connect to.
- click add server
- if you want to play over the internet you should have the ip of the game server you want connect to.
- click direct connect
- type in the ip address or hostname
- if you want to add a port use :<port>
- Now you can select a company and press: "Join company", to help that company
- Or you can press "Spectate game", to spectate the game
- Or you can press "New company", and start your own company (if there are slots free)
- You see a progressbar how far you are with joining the server.
- Happy playing
- if you want to connect as an special player use #<player-no>
3. Connecting to a Server over the Console
-------------------------------------------
- Open the console and type in the following command:
connect <ip/host>:<port>#<player-no>
- open the console and type in the following command:
]connect <ip/host>:<port>#<player-no>
4. Playing Internet-Games
--------------------------
- Since OpenTTD 0.3.5 the network protocol has been rewritten and is very stable, even over slow connections.
- Servers with a red dot behind it have a different version then you have. You will not be able to join those servers.
- Servers with a yellow dot behind it have NewGRFs that you do not have. You will not be able to join those servers.
- It can happen that a connection is that slow, or you have that many clients connected to your server, that your clients start to loose their connection. Some things you can do about it:
- net_frame_freq:
change it in console with: net_frame_freq = <number>
the number should be between the 0 and 10, not much higher. It indicates the delay between clicking and showing up. The higher, the more you notice it, but the less bandwidth you use.
A good value for Internet-games is 2 or 3.
- net_sync_freq:
change it in console with: net_sync_freq = <number>
the number should be between the 50 and 1000, not much lower, not much higer. It indicates the time between sync-frames. A sync-frame is a frame which checks if all clients are still in sync. When the value it too high, clients can desync in 1960, but the server detects it in 1970. Not really handy. The lower the value, the more bandwidth it uses.
NB: changing net_frame_freq has more effect on the bandwidth then net_sync_freq. You should never change net_sync_freq!
5. Tips for servers
--------------------
- You can launch a dedicated server by adding -D as parameter
- In UNIX like systems, you can fork your dedicated server by adding -f as parameter
- You can automaticly clean companies that do not have a client connected to them, for, let's say,
3 years. You can do this via: 'set autoclean_companies' and 'set autoclean_protected' and
'set autoclean_unprotected'. Unprotected removes a password from a company when it is
not used for more then the defined amount of months.
- You can also do this manually via the console: 'reset_company'.
Both ways, the company will go bankrupt.
- You can let your server automaticly restart a map when, let's say, year 2030 is reached.
See 'set restart_game_date' for detail.
- If you want to be on the server-list, enable Advertising. To do this, select 'Internet (advertise)'
in the Start Server menu, or type in console: 'set server_advertise 1'.
- You can protect your server with a password via the console: 'set server_pw', or via the
Start Server menu.
- When you have many clients connected to your server via Internet, watch your bandwidth (if
you have any limit on it, set by your ISP). 1 client uses +/- 3 kb/s up and down. To decrease
this amount, set 'net_frame_freq' to 1 for example. This will reduce it to 1.5 kb/s per client.
6. Some useful things
----------------------
- You can protect your company so nobody else can join uninvited. To do this, check your Company Screen
- You can give other players some money via the ClientList (under the 'head' in the mainbar).
- You can chat with other players via ENTER or via SHIFT+T or via the ClientList
- Servers can now kick players, so don't make them use it!
- From 0.3.5, desyncs should not happen anymore
- From 0.3.5, patch-settings are also synced. You can now play without deleting openttd.cfg, and with, for example, extra large trains enabled.
7. Troubleshooting
------------------
- My advertised server does not show up in the 'advertised server list' (servers.openttd.org)
Run openttd with the '-d net=2' parameter, as this will show whether it receives replies from the master server.
If it does not receive replies it is most likely that you need to configure your router to forward the OpenTTD ports 3979 (both TCP and UDP) to the computer that is hosting the game.
- since OpenTTD 0.3.4 you can also play internet games over higher latency connections.
- to do this the gameservers sync frequency should be highered to a decent value.
- open the console [on the server]
- type in the following command:
] *net_sync_freq = <4-80>
default value: 4
- this is lowering the sync frequency of the server and your game should be less laggy.
- this is a server variable: it has nothing to do with the clients
- you can also change when the clients ready packet is sent if you still have lags.
- open the console
- type in the following command:
] *net_ready_ahead = <1-8>
default value: 1
- in that way your client is sending its "i am ready for next sync" a bit earlier
thats quite good for games where some players have higher latencies than the others.
- this is a client variable: it has nothing to do with the server
- to change the client timeout time
- open the console [on the server]
- type in the following command:
] *net_client_timeout = <30-x>
default value: 300
- warning: a too low value will disconnect your clients if they have a short lag

View File

@@ -1,66 +0,0 @@
.\" Hey, EMACS: -*- nroff -*-
.\" Please adjust this date whenever revising the manpage.
.Dd Sep 15, 2007
.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[:port][#player]
.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[:port][#player]"
.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 Ar host[:port][#player]
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/, http://www.openttd.org
.Sh HISTORY
Transport Tycoon Deluxe was written by Chris Sawyer and published by Microprose.
.Nm
is a free reimplementation.

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

77
dummy_land.c Normal file
View File

@@ -0,0 +1,77 @@
#include "stdafx.h"
#include "ttd.h"
#include "viewport.h"
#include "command.h"
static void DrawTile_Dummy(TileInfo *ti)
{
DrawGroundSpriteAt(0x3EC, ti->x, ti->y, ti->z);
}
static uint GetSlopeZ_Dummy(TileInfo *ti) {
return GetPartialZ(ti->x&0xF, ti->y&0xF, ti->tileh) + ti->z;
}
static uint GetSlopeTileh_Dummy(TileInfo *ti) {
return ti->tileh;
}
static int32 ClearTile_Dummy(uint tile, byte flags) {
return_cmd_error(STR_0001_OFF_EDGE_OF_MAP);
}
static void GetAcceptedCargo_Dummy(uint tile, AcceptedCargo *ac)
{
/* not used */
}
static void GetTileDesc_Dummy(uint tile, TileDesc *td)
{
td->str = STR_EMPTY;
td->owner = OWNER_NONE;
}
static void AnimateTile_Dummy(uint tile)
{
/* not used */
}
static void TileLoop_Dummy(uint tile)
{
/* not used */
}
static void ClickTile_Dummy(uint tile)
{
/* not used */
}
static void ChangeTileOwner_Dummy(uint tile, byte old_player, byte new_player)
{
/* not used */
}
static uint32 GetTileTrackStatus_Dummy(uint tile, TransportType mode)
{
return 0;
}
const TileTypeProcs _tile_type_dummy_procs = {
DrawTile_Dummy, /* draw_tile_proc */
GetSlopeZ_Dummy, /* get_slope_z_proc */
ClearTile_Dummy, /* clear_tile_proc */
GetAcceptedCargo_Dummy, /* get_accepted_cargo_proc */
GetTileDesc_Dummy, /* get_tile_desc_proc */
GetTileTrackStatus_Dummy, /* get_tile_track_status_proc */
ClickTile_Dummy, /* click_tile_proc */
AnimateTile_Dummy, /* animate_tile_proc */
TileLoop_Dummy, /* tile_loop_clear */
ChangeTileOwner_Dummy, /* change_tile_owner_clear */
NULL, /* get_produced_cargo_proc */
NULL, /* vehicle_enter_tile_proc */
NULL, /* vehicle_leave_tile_proc */
GetSlopeTileh_Dummy, /* get_slope_tileh_proc */
};

1471
economy.c Normal file

File diff suppressed because it is too large Load Diff

78
economy.h Normal file
View File

@@ -0,0 +1,78 @@
#ifndef ECONOMY_H
#define ECONOMY_H
typedef struct {
// Maximum possible loan
int32 max_loan;
int32 max_loan_unround;
// Economy fluctuation status
int fluct;
// Interest
byte interest_rate;
byte infl_amount;
byte infl_amount_pr;
} Economy;
VARDEF Economy _economy;
typedef struct Subsidy {
byte cargo_type;
byte age;
byte from;
byte to;
} Subsidy;
enum {
SCORE_VEHICLES = 0,
SCORE_STATIONS = 1,
SCORE_MIN_PROFIT = 2,
SCORE_MIN_INCOME = 3,
SCORE_MAX_INCOME = 4,
SCORE_DELIVERED = 5,
SCORE_CARGO = 6,
SCORE_MONEY = 7,
SCORE_LOAN = 8,
SCORE_TOTAL = 9, // This must always be the last entry
NUM_SCORE = 10, // How many scores are there..
SCORE_MAX = 1000, // The max score that can be in the performance history
// the scores together of score_info is allowed to be more!
};
typedef struct ScoreInfo {
byte id; // Unique ID of the score
int needed; // How much you need to get the perfect score
int score; // How much score it will give
} ScoreInfo;
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(Subsidy *s, bool mode);
void DeleteSubsidyWithIndustry(byte index);
void DeleteSubsidyWithStation(byte index);
void RemoteSubsidyAdd(Subsidy *s_new);
int32 GetTransportedGoodsIncome(uint num_pieces, uint dist, byte transit_days, byte cargo_type);
uint MoveGoodsToStation(uint tile, int w, int h, int type, uint amount);
#endif /* ECONOMY_H */

22
endian_check.c Normal file
View File

@@ -0,0 +1,22 @@
#include <stdio.h>
// This pretty simple file checks if the system is LITTLE_ENDIAN or BIG_ENDIAN
// it does that by putting a 1 and a 0 in an array, and read it out as one
// number. If it is 1, it is LITTLE_ENDIAN, if it is 256, it is BIG_ENDIAN
//
// After that it outputs the contents of an include files (endian.h)
// that says or TTD_LITTLE_ENDIAN, or TTD_BIG_ENDIAN. Makefile takes
// care of the real writing to the file.
int main () {
unsigned char EndianTest[2] = { 1, 0 };
printf("#ifndef ENDIAN_H\n#define ENDIAN_H\n");
if( *(short *) EndianTest == 1 )
printf("#define TTD_LITTLE_ENDIAN\n");
else
printf("#define TTD_BIG_ENDIAN\n");
printf("#endif\n");
return 0;
}

557
engine.c Normal file
View File

@@ -0,0 +1,557 @@
#include "stdafx.h"
#include "ttd.h"
#include "engine.h"
#include "table/engines.h"
#include "player.h"
#include "command.h"
#include "vehicle.h"
#include "news.h"
#include "saveload.h"
#define UPDATE_PLAYER_RAILTYPE(e,p) if ((byte)(e->railtype + 1) > p->max_railtype) p->max_railtype = e->railtype + 1;
enum {
ENGINE_AVAILABLE = 1,
ENGINE_INTRODUCING = 2,
ENGINE_PREVIEWING = 4,
};
/* This maps per-landscape cargo ids to globally unique cargo ids usable ie. in
* the custom GRF files. It is basically just a transcribed table from
* TTDPatch's newgrf.txt. */
byte _global_cargo_id[NUM_LANDSCAPE][NUM_CARGO] = {
/* LT_NORMAL */ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12 },
/* LT_HILLY */ { 0, 1, 2, 3, 4, 5, 6, 7, 28, 11, 10, 12 },
/* LT_DESERT */ { 0, 16, 2, 3, 13, 5, 6, 7, 14, 15, 10, 12 },
/* LT_CANDY */ { 0, 17, 2, 18, 19, 20, 21, 22, 23, 24, 25, 26 },
// 27 is paper in temperate climate in TTDPatch
// Following can be renumbered:
// 29 is the default cargo for the purpose of spritesets
// 30 is the purchase list image (the equivalent of 0xff) for the purpose of spritesets
};
/* These two arrays provide a reverse mapping. */
byte _local_cargo_id_ctype[NUM_CID] = {
CT_PASSENGERS, CT_COAL, CT_MAIL, CT_OIL, CT_LIVESTOCK, CT_GOODS, CT_GRAIN, CT_WOOD, // 0-7
CT_IRON_ORE, CT_STEEL, CT_VALUABLES, CT_PAPER, CT_FOOD, CT_FRUIT, CT_COPPER_ORE, CT_WATER, // 8-15
CT_RUBBER, CT_SUGAR, CT_TOYS, CT_BATTERIES, CT_CANDY, CT_TOFFEE, CT_COLA, CT_COTTON_CANDY, // 16-23
CT_BUBBLES, CT_PLASTIC, CT_FIZZY_DRINKS, CT_PAPER /* unsup. */, CT_HILLY_UNUSED // 24-28
};
/* LT'th bit is set of the particular landscape if cargo available there.
* 1: LT_NORMAL, 2: LT_HILLY, 4: LT_DESERT, 8: LT_CANDY */
byte _local_cargo_id_landscape[NUM_CID] = {
15, 3, 15, 7, 3, 7, 7, 7, 1, 1, 7, 2, 7, // 0-12
4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 1, 2, // 13-28
};
void ShowEnginePreviewWindow(int engine);
void DeleteCustomEngineNames()
{
uint i;
StringID old;
for(i=0; i!=TOTAL_NUM_ENGINES; i++) {
old = _engine_name_strings[i];
_engine_name_strings[i] = i + STR_8000_KIRBY_PAUL_TANK_STEAM;
DeleteName(old);
}
_vehicle_design_names &= ~1;
}
void LoadCustomEngineNames()
{
// XXX: not done */
DEBUG(misc, 1) ("LoadCustomEngineNames: not done");
}
static void SetupEngineNames()
{
uint i;
for(i=0; i!=TOTAL_NUM_ENGINES; i++)
_engine_name_strings[i] = STR_SV_EMPTY;
DeleteCustomEngineNames();
LoadCustomEngineNames();
}
static void AdjustAvailAircraft()
{
uint16 date = _date;
byte avail = 0;
if (date >= 12784) avail |= 2; // big airport
if (date < 14610 || _patches.always_small_airport) avail |= 1; // small airport
if (date >= 15706) avail |= 4; // enable heliport
if (avail != _avail_aircraft) {
_avail_aircraft = avail;
InvalidateWindow(WC_BUILD_STATION, 0);
}
}
static void CalcEngineReliability(Engine *e)
{
uint age = e->age;
if (age < e->duration_phase_1) {
uint start = e->reliability_start;
e->reliability = age * (e->reliability_max - start) / e->duration_phase_1 + start;
} else if ((age -= e->duration_phase_1) < e->duration_phase_2) {
e->reliability = e->reliability_max;
} else if ((age -= e->duration_phase_2) < e->duration_phase_3) {
uint max = e->reliability_max;
e->reliability = (int)age * (int)(e->reliability_final - max) / e->duration_phase_3 + max;
} else {
e->player_avail = _patches.never_expire_vehicles ? -1 : 0;
e->reliability = e->reliability_final;
}
}
void StartupEngines()
{
Engine *e;
const EngineInfo *ei;
uint32 r;
SetupEngineNames();
for(e=_engines, ei=_engine_info; e != endof(_engines); e++,ei++) {
e->age = 0;
e->railtype = ei->railtype_climates >> 4;
e->flags = 0;
e->player_avail = 0;
r = Random();
e->intro_date = (uint16)((r & 0x1FF) + ei->base_intro);
if (e->intro_date <= _date) {
e->age = (_date - e->intro_date) >> 5;
e->player_avail = (byte)-1;
e->flags |= ENGINE_AVAILABLE;
}
e->reliability_start = (uint16)(((r >> 16) & 0x3fff) + 0x7AE0);
r = Random();
e->reliability_max = (uint16)((r & 0x3fff) + 0xbfff);
e->reliability_final = (uint16)(((r>>16) & 0x3fff) + 0x3fff);
r = Random();
e->duration_phase_1 = (uint16)((r & 0x1F) + 7);
e->duration_phase_2 = (uint16)(((r >> 5) & 0xF) + ei->base_life * 12 - 96);
e->duration_phase_3 = (uint16)(((r >> 9) & 0x7F) + 120);
e->reliability_spd_dec = (ei->unk2&0x7F) << 2;
/* my invented flag for something that is a wagon */
if (ei->unk2 & 0x80) {
e->age = 0xFFFF;
} else {
CalcEngineReliability(e);
}
e->lifelength = ei->lifelength + _patches.extend_vehicle_life;
// prevent certain engines from ever appearing.
if (!HASBIT(ei->railtype_climates, _opt.landscape)) {
e->flags |= ENGINE_AVAILABLE;
e->player_avail = 0;
}
}
AdjustAvailAircraft();
}
uint32 _engine_refit_masks[256];
// TODO: We don't support cargo-specific wagon overrides. Pretty exotic... ;-) --pasky
struct WagonOverride {
byte *train_id;
int trains;
struct SpriteSuperSet superset;
};
static struct WagonOverrides {
int overrides_count;
struct WagonOverride *overrides;
} _engine_wagon_overrides[256];
void SetWagonOverrideSprites(byte engine, struct SpriteSuperSet *superset,
byte *train_id, int trains)
{
struct WagonOverrides *wos;
struct WagonOverride *wo;
wos = &_engine_wagon_overrides[engine];
wos->overrides_count++;
wos->overrides = realloc(wos->overrides,
wos->overrides_count * sizeof(struct WagonOverride));
wo = &wos->overrides[wos->overrides_count - 1];
wo->superset = *superset;
wo->trains = trains;
wo->train_id = malloc(trains);
memcpy(wo->train_id, train_id, trains);
}
static struct SpriteSuperSet *GetWagonOverrideSpriteSet(byte engine, byte overriding_engine)
{
struct WagonOverrides *wos = &_engine_wagon_overrides[engine];
int i;
// XXX: This could turn out to be a timesink on profiles. We could always just
// dedicate 65535 bytes for an [engine][train] trampoline.
for (i = 0; i < wos->overrides_count; i++) {
struct WagonOverride *wo = &wos->overrides[i];
int j;
for (j = 0; j < wo->trains; j++) {
if (wo->train_id[j] == overriding_engine)
return &wo->superset;
}
}
return NULL;
}
byte _engine_original_sprites[256];
// 0 - 28 are cargos, 29 is default, 30 is the advert (purchase list)
// (It isn't and shouldn't be like this in the GRF files since new cargo types
// may appear in future - however it's more convenient to store it like this in
// memory. --pasky)
static struct SpriteSuperSet _engine_custom_sprites[256][NUM_CID];
void SetCustomEngineSprites(byte engine, byte cargo, struct SpriteSuperSet *superset)
{
assert(superset->sprites_per_set == 4 || superset->sprites_per_set == 8);
_engine_custom_sprites[engine][cargo] = *superset;
}
int GetCustomEngineSprite(byte engine, uint16 overriding_engine, byte cargo,
byte loaded, byte in_motion, byte direction)
{
struct SpriteSuperSet *superset = &_engine_custom_sprites[engine][cargo];
int totalsets, spriteset;
int r;
if (overriding_engine != 0xffff) {
struct SpriteSuperSet *overset;
overset = GetWagonOverrideSpriteSet(engine, overriding_engine);
if (overset) superset = overset;
}
if (!superset->sprites_per_set && cargo != 29) {
// This superset is empty but perhaps there'll be a default one.
superset = &_engine_custom_sprites[engine][29];
}
if (!superset->sprites_per_set) {
// This superset is empty. This function users should therefore
// look up the sprite number in _engine_original_sprites.
return 0;
}
direction %= 8;
if (superset->sprites_per_set == 4)
direction %= 4;
totalsets = in_motion ? superset->loaded_count : superset->loading_count;
// My aim here is to make it possible to visually determine absolutely
// empty and totally full vehicles. --pasky
if (loaded == 100 || totalsets == 1) { // full
spriteset = totalsets - 1;
} else if (loaded == 0 || totalsets == 2) { // empty
spriteset = 0;
} else { // something inbetween
spriteset = loaded * (totalsets - 2) / 100 + 1;
// correct possible rounding errors
if (!spriteset)
spriteset = 1;
else if (spriteset == totalsets - 1)
spriteset--;
}
r = (in_motion ? superset->loaded[spriteset] : superset->loading[spriteset]) + direction;
return r;
}
static char *_engine_custom_names[256];
void SetCustomEngineName(int engine, char *name)
{
_engine_custom_names[engine] = strdup(name);
}
StringID GetCustomEngineName(int engine)
{
if (!_engine_custom_names[engine])
return _engine_name_strings[engine];
strcpy(_userstring, _engine_custom_names[engine]);
return STR_SPEC_USERSTRING;
}
void AcceptEnginePreview(Engine *e, int player)
{
Player *p;
SETBIT(e->player_avail, player);
p = DEREF_PLAYER(player);
UPDATE_PLAYER_RAILTYPE(e,p);
e->preview_player = 0xFF;
InvalidateWindowClasses(WC_BUILD_VEHICLE);
}
void EnginesDailyLoop()
{
Engine *e;
int i,num;
Player *p;
uint mask;
int32 best_hist;
int best_player;
if (_cur_year >= 130)
return;
for(e=_engines,i=0; i!=TOTAL_NUM_ENGINES; e++,i++) {
if (e->flags & ENGINE_INTRODUCING) {
if (e->flags & ENGINE_PREVIEWING) {
if (!--e->preview_wait) {
e->flags &= ~ENGINE_PREVIEWING;
DeleteWindowById(WC_ENGINE_PREVIEW, i);
e->preview_player++;
}
} else if (e->preview_player != 0xFF) {
num = e->preview_player;
mask = 0;
do {
best_hist = -1;
best_player = -1;
FOR_ALL_PLAYERS(p) {
if (p->is_active && p->block_preview == 0 && !HASBIT(mask,p->index) &&
p->old_economy[0].performance_history > best_hist) {
best_hist = p->old_economy[0].performance_history;
best_player = p->index;
}
}
if (best_player == -1) {
e->preview_player = 0xFF;
goto next_engine;
}
mask |= (1 << best_player);
} while (--num != 0);
if (!IS_HUMAN_PLAYER(best_player)) {
/* TTDBUG: TTD has a bug here */
AcceptEnginePreview(e, best_player);
} else {
e->flags |= ENGINE_PREVIEWING;
e->preview_wait = 20;
if (IS_INTERACTIVE_PLAYER(best_player)) {
ShowEnginePreviewWindow(i);
}
}
}
}
next_engine:;
}
}
int32 CmdWantEnginePreview(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
if (flags & DC_EXEC) {
AcceptEnginePreview(&_engines[p1], _current_player);
}
return 0;
}
void NewVehicleAvailable(Engine *e)
{
Vehicle *v;
Player *p;
int index = e - _engines;
// In case the player didn't build the vehicle during the intro period,
// prevent that player from getting future intro periods for a while.
if (e->flags&ENGINE_INTRODUCING) {
FOR_ALL_PLAYERS(p) {
if (!HASBIT(e->player_avail,p->index))
continue;
for(v=_vehicles;;) {
if (v->type == VEH_Train || v->type == VEH_Road || v->type == VEH_Ship ||
(v->type == VEH_Aircraft && v->subtype <= 2)) {
if (v->owner == p->index && v->engine_type == index) break;
}
if (++v == endof(_vehicles)) {
p->block_preview = 20;
break;
}
}
}
}
e->flags = (e->flags & ~ENGINE_INTRODUCING) | ENGINE_AVAILABLE;
InvalidateWindowClasses(WC_BUILD_VEHICLE);
// Now available for all players
e->player_avail = (byte)-1;
// Do not introduce new rail wagons
if ((byte)index < NUM_TRAIN_ENGINES) {
const RailVehicleInfo *rvi = &_rail_vehicle_info[index];
if(rvi->flags & RVI_WAGON)
return;
}
// make maglev / monorail available
FOR_ALL_PLAYERS(p) {
if (p->is_active)
UPDATE_PLAYER_RAILTYPE(e,p);
}
if ((byte)index < NUM_TRAIN_ENGINES) {
AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_TRAINAVAIL), 0, 0);
} else if ((byte)index < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES) {
AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_ROADAVAIL), 0, 0);
} else if ((byte)index < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES) {
AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_SHIPAVAIL), 0, 0);
} else {
AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_AIRCRAFTAVAIL), 0, 0);
}
}
void EnginesMonthlyLoop()
{
Engine *e;
if (_cur_year < 130) {
for(e=_engines; e != endof(_engines); e++) {
// Age the vehicle
if (e->flags&ENGINE_AVAILABLE && e->age != 0xFFFF) {
e->age++;
CalcEngineReliability(e);
}
if (!(e->flags & ENGINE_AVAILABLE) && (uint16)(_date - min(_date, 365)) >= e->intro_date) {
// Introduce it to all players
NewVehicleAvailable(e);
} else if (!(e->flags & (ENGINE_AVAILABLE|ENGINE_INTRODUCING)) && _date >= e->intro_date) {
// Introduction date has passed.. show introducing dialog to one player.
e->flags |= ENGINE_INTRODUCING;
e->preview_player = 1; // Give to the player with the highest rating.
}
}
}
AdjustAvailAircraft();
}
int32 CmdRenameEngine(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
StringID str;
str = AllocateName((byte*)_decode_parameters, 0);
if (str == 0)
return CMD_ERROR;
if (flags & DC_EXEC) {
StringID old_str = _engine_name_strings[p1];
_engine_name_strings[p1] = str;
DeleteName(old_str);
_vehicle_design_names |= 3;
MarkWholeScreenDirty();
} else {
DeleteName(str);
}
return 0;
}
int GetPlayerMaxRailtype(int p)
{
Engine *e;
int rt = 0;
int i;
for(e=_engines,i=0; i!=lengthof(_engines); e++,i++) {
if (!HASBIT(e->player_avail, p))
continue;
if ((i >= 27 && i < 54) || (i >= 57 && i < 84) || (i >= 89 && i < 116))
continue;
if (rt < e->railtype)
rt = e->railtype;
}
return rt + 1;
}
static const byte _engine_desc[] = {
SLE_VAR(Engine,intro_date, SLE_UINT16),
SLE_VAR(Engine,age, SLE_UINT16),
SLE_VAR(Engine,reliability, SLE_UINT16),
SLE_VAR(Engine,reliability_spd_dec, SLE_UINT16),
SLE_VAR(Engine,reliability_start, SLE_UINT16),
SLE_VAR(Engine,reliability_max, SLE_UINT16),
SLE_VAR(Engine,reliability_final, SLE_UINT16),
SLE_VAR(Engine,duration_phase_1, SLE_UINT16),
SLE_VAR(Engine,duration_phase_2, SLE_UINT16),
SLE_VAR(Engine,duration_phase_3, SLE_UINT16),
SLE_VAR(Engine,lifelength, SLE_UINT8),
SLE_VAR(Engine,flags, SLE_UINT8),
SLE_VAR(Engine,preview_player, SLE_UINT8),
SLE_VAR(Engine,preview_wait, SLE_UINT8),
SLE_VAR(Engine,railtype, SLE_UINT8),
SLE_VAR(Engine,player_avail, SLE_UINT8),
// reserve extra space in savegame here. (currently 16 bytes)
SLE_CONDARR(NullStruct,null,SLE_FILE_U64 | SLE_VAR_NULL, 2, 2, 255),
SLE_END()
};
static void Save_ENGN()
{
Engine *e;
int i;
for(i=0,e=_engines; i != lengthof(_engines); i++,e++) {
SlSetArrayIndex(i);
SlObject(e, _engine_desc);
}
}
static void Load_ENGN()
{
int index;
while ((index = SlIterateArray()) != -1) {
SlObject(&_engines[index], _engine_desc);
}
}
static void LoadSave_ENGS()
{
SlArray(_engine_name_strings, lengthof(_engine_name_strings), SLE_STRINGID);
}
const ChunkHandler _engine_chunk_handlers[] = {
{ 'ENGN', Save_ENGN, Load_ENGN, CH_ARRAY},
{ 'ENGS', LoadSave_ENGS, LoadSave_ENGS, CH_RIFF | CH_LAST},
};

137
engine.h Normal file
View File

@@ -0,0 +1,137 @@
#ifndef ENGINE_H
#define ENGINE_H
typedef struct RailVehicleInfo {
byte image_index;
byte flags; /* 1=multihead engine, 2=wagon */
byte base_cost;
uint16 max_speed;
uint16 power;
byte weight;
byte running_cost_base;
byte engclass; // 0: steam, 1: diesel, 2: electric
byte capacity;
byte cargo_type;
} RailVehicleInfo;
typedef struct ShipVehicleInfo {
byte image_index;
byte base_cost;
uint16 max_speed;
byte cargo_type;
uint16 capacity;
byte running_cost;
byte sfx;
byte refittable;
} ShipVehicleInfo;
typedef struct EngineInfo {
uint16 base_intro;
byte unk2;
byte lifelength;
byte base_life;
byte railtype_climates;
} EngineInfo;
typedef struct Engine {
uint16 intro_date;
uint16 age;
uint16 reliability;
uint16 reliability_spd_dec;
uint16 reliability_start, reliability_max, reliability_final;
uint16 duration_phase_1, duration_phase_2, duration_phase_3;
byte lifelength;
byte flags;
byte preview_player;
byte preview_wait;
byte railtype;
byte player_avail;
} Engine;
enum {
RVI_MULTIHEAD = 1,
RVI_WAGON = 2,
};
void StartupEngines();
struct SpriteSuperSet {
// XXX: Would anyone ever need more than 16 spritesets? Maybe we should
// use even less, now we take whole 8kb for custom sprites table, oh my!
byte sprites_per_set; // means number of directions - 4 or 8
// Loaded = in motion, loading = not moving
// Each superset contains several spritesets, for various loading stages
byte loaded_count;
uint16 loaded[16]; // sprite ids
byte loading_count;
uint16 loading[16]; // sprite ids
};
extern byte _global_cargo_id[NUM_LANDSCAPE][NUM_CARGO];
enum {
CID_DEFAULT = 29,
CID_PURCHASE = 30,
NUM_CID = 31,
};
extern byte _local_cargo_id_ctype[NUM_CID];
extern byte _local_cargo_id_landscape[NUM_CID];
extern uint32 _engine_refit_masks[256];
extern byte _engine_original_sprites[256];
void SetWagonOverrideSprites(byte engine, struct SpriteSuperSet *superset, byte *train_id, int trains);
void SetCustomEngineSprites(byte engine, byte cargo, struct SpriteSuperSet *superset);
// loaded is in percents, overriding_engine 0xffff is none
int GetCustomEngineSprite(byte engine, uint16 overriding_engine, byte cargo, byte loaded, byte in_motion, byte direction);
#define GetCustomVehicleSprite(v, direction) \
GetCustomEngineSprite(v->engine_type, v->type == VEH_Train ? v->u.rail.first_engine : -1, \
_global_cargo_id[_opt.landscape][v->cargo_type], \
((v->cargo_count + 1) * 100) / (v->cargo_cap + 1), \
!!v->cur_speed, direction);
void SetCustomEngineName(int engine, char *name);
StringID GetCustomEngineName(int engine);
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, int player);
void LoadCustomEngineNames();
void DeleteCustomEngineNames();
enum {
NUM_NORMAL_RAIL_ENGINES = 54,
NUM_MONORAIL_ENGINES = 30,
NUM_MAGLEV_ENGINES = 32,
NUM_TRAIN_ENGINES = NUM_NORMAL_RAIL_ENGINES + NUM_MONORAIL_ENGINES + NUM_MAGLEV_ENGINES,
NUM_ROAD_ENGINES = 88,
NUM_SHIP_ENGINES = 11,
NUM_AIRCRAFT_ENGINES = 41,
TOTAL_NUM_ENGINES = NUM_NORMAL_RAIL_ENGINES+NUM_MONORAIL_ENGINES+NUM_MAGLEV_ENGINES+NUM_ROAD_ENGINES+NUM_SHIP_ENGINES+NUM_AIRCRAFT_ENGINES,
AIRCRAFT_ENGINES_INDEX = NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES,
SHIP_ENGINES_INDEX = NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES,
ROAD_ENGINES_INDEX = NUM_TRAIN_ENGINES,
};
VARDEF Engine _engines[TOTAL_NUM_ENGINES];
VARDEF StringID _engine_name_strings[TOTAL_NUM_ENGINES];
extern EngineInfo _engine_info[TOTAL_NUM_ENGINES];
extern RailVehicleInfo _rail_vehicle_info[];
#define ship_vehicle_info(e) _ship_vehicle_info[e - SHIP_ENGINES_INDEX]
extern ShipVehicleInfo _ship_vehicle_info[];
#endif

224
engine_gui.c Normal file
View File

@@ -0,0 +1,224 @@
#include "stdafx.h"
#include "ttd.h"
#include "window.h"
#include "gui.h"
#include "viewport.h"
#include "gfx.h"
#include "engine.h"
#include "command.h"
#include "news.h"
void DrawShipEngine(int x, int y, int engine, uint32 image_ormod);
void DrawShipEngineInfo(int engine, int x, int y, int maxw);
StringID GetEngineCategoryName(byte engine)
{
if (engine < NUM_NORMAL_RAIL_ENGINES)
return STR_8102_RAILROAD_LOCOMOTIVE;
if (engine < NUM_NORMAL_RAIL_ENGINES + NUM_MONORAIL_ENGINES)
return STR_8106_MONORAIL_LOCOMOTIVE;
if (engine < NUM_TRAIN_ENGINES)
return STR_8107_MAGLEV_LOCOMOTIVE;
if (engine < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES)
return STR_8103_ROAD_VEHICLE;
if (engine < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES)
return STR_8105_SHIP;
return STR_8104_AIRCRAFT;
}
static const Widget _engine_preview_widgets[] = {
{ WWT_TEXTBTN, 5, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, 5, 11, 299, 0, 13, STR_8100_MESSAGE_FROM_VEHICLE_MANUFACTURE, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_IMGBTN, 5, 0, 299, 14, 191, 0x0, STR_NULL},
{ WWT_PUSHTXTBTN, 5, 85, 144, 172, 183, STR_00C9_NO, STR_NULL},
{ WWT_PUSHTXTBTN, 5, 155, 214, 172, 183, STR_00C8_YES, STR_NULL},
{ WIDGETS_END},
};
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 const DrawEngineInfo _draw_engine_list[4] = {
{DrawTrainEngine,DrawTrainEngineInfo},
{DrawRoadVehEngine,DrawRoadVehEngineInfo},
{DrawShipEngine,DrawShipEngineInfo},
{DrawAircraftEngine,DrawAircraftEngineInfo},
};
static void EnginePreviewWndProc(Window *w, WindowEvent *e)
{
byte eng;
int engine;
const DrawEngineInfo *dei;
int width;
switch(e->event) {
case WE_PAINT:
DrawWindowWidgets(w);
engine = w->window_number;
SET_DPARAM16(0, GetEngineCategoryName(engine));
DrawStringMultiCenter(150, 44, STR_8101_WE_HAVE_JUST_DESIGNED_A, 296);
DrawStringCentered(w->width >> 1, 80, GetCustomEngineName(engine), 0x10);
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;
}
break;
}
}
static const WindowDesc _engine_preview_desc = {
WDP_CENTER, WDP_CENTER, 300, 192,
WC_ENGINE_PREVIEW,0,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
_engine_preview_widgets,
EnginePreviewWndProc
};
void ShowEnginePreviewWindow(int engine)
{
Window *w;
w = AllocateWindowDesc(&_engine_preview_desc);
w->window_number = engine;
}
void DrawNewsNewTrainAvail(Window *w)
{
int engine;
DrawNewsBorder(w);
engine = WP(w,news_d).ni->string_id;
SET_DPARAM16(0, GetEngineCategoryName(engine));
DrawStringMultiCenter(w->width >> 1, 20, STR_8859_NEW_NOW_AVAILABLE, w->width - 2);
GfxFillRect(25, 56, w->width - 25, w->height - 2, 10);
SET_DPARAM16(0, GetCustomEngineName(engine));
DrawStringMultiCenter(w->width >> 1, 57, STR_885A, w->width - 2);
DrawTrainEngine(w->width >> 1, 88, engine, 0);
GfxFillRect(25, 56, w->width - 56, 112, 0x4323);
DrawTrainEngineInfo(engine, w->width >> 1, 129, w->width - 52);
}
StringID GetNewsStringNewTrainAvail(NewsItem *ni)
{
int engine = ni->string_id;
SET_DPARAM16(0, STR_8859_NEW_NOW_AVAILABLE);
SET_DPARAM16(1, GetEngineCategoryName(engine));
SET_DPARAM16(2, GetCustomEngineName(engine));
return STR_02B6;
}
void DrawNewsNewAircraftAvail(Window *w)
{
int engine;
DrawNewsBorder(w);
engine = WP(w,news_d).ni->string_id;
DrawStringMultiCenter(w->width >> 1, 20, STR_A02C_NEW_AIRCRAFT_NOW_AVAILABLE, w->width - 2);
GfxFillRect(25, 56, w->width - 25, w->height - 2, 10);
SET_DPARAM16(0, GetCustomEngineName(engine));
DrawStringMultiCenter(w->width >> 1, 57, STR_A02D, w->width - 2);
DrawAircraftEngine(w->width >> 1, 93, engine, 0);
GfxFillRect(25, 56, w->width - 56, 110, 0x4323);
DrawAircraftEngineInfo(engine, w->width >> 1, 131, w->width - 52);
}
StringID GetNewsStringNewAircraftAvail(NewsItem *ni)
{
int engine = ni->string_id;
SET_DPARAM16(0, STR_A02C_NEW_AIRCRAFT_NOW_AVAILABLE);
SET_DPARAM16(1, GetCustomEngineName(engine));
return STR_02B6;
}
void DrawNewsNewRoadVehAvail(Window *w)
{
int engine;
DrawNewsBorder(w);
engine = WP(w,news_d).ni->string_id;
DrawStringMultiCenter(w->width >> 1, 20, STR_9028_NEW_ROAD_VEHICLE_NOW_AVAILABLE, w->width - 2);
GfxFillRect(25, 56, w->width - 25, w->height - 2, 10);
SET_DPARAM16(0, GetCustomEngineName(engine));
DrawStringMultiCenter(w->width >> 1, 57, STR_9029, w->width - 2);
DrawRoadVehEngine(w->width >> 1, 88, engine, 0);
GfxFillRect(25, 56, w->width - 56, 112, 0x4323);
DrawRoadVehEngineInfo(engine, w->width >> 1, 129, w->width - 52);
}
StringID GetNewsStringNewRoadVehAvail(NewsItem *ni)
{
int engine = ni->string_id;
SET_DPARAM16(0, STR_9028_NEW_ROAD_VEHICLE_NOW_AVAILABLE);
SET_DPARAM16(1, GetCustomEngineName(engine));
return STR_02B6;
}
void DrawNewsNewShipAvail(Window *w)
{
int engine;
DrawNewsBorder(w);
engine = WP(w,news_d).ni->string_id;
DrawStringMultiCenter(w->width >> 1, 20, STR_982C_NEW_SHIP_NOW_AVAILABLE, w->width - 2);
GfxFillRect(25, 56, w->width - 25, w->height - 2, 10);
SET_DPARAM16(0, GetCustomEngineName(engine));
DrawStringMultiCenter(w->width >> 1, 57, STR_982D, w->width - 2);
DrawShipEngine(w->width >> 1, 93, engine, 0);
GfxFillRect(25, 56, w->width - 56, 110, 0x4323);
DrawShipEngineInfo(engine, w->width >> 1, 131, w->width - 52);
}
StringID GetNewsStringNewShipAvail(NewsItem *ni)
{
int engine = ni->string_id;
SET_DPARAM16(0, STR_982C_NEW_SHIP_NOW_AVAILABLE);
SET_DPARAM16(1, GetCustomEngineName(engine));
return STR_02B6;
}

103
extmidi.c Normal file
View File

@@ -0,0 +1,103 @@
#ifndef __BEOS__
#ifndef __MORPHOS__
#include "stdafx.h"
#include "ttd.h"
#include "hal.h"
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <signal.h>
#include <sys/stat.h>
#include <errno.h>
#ifndef EXTERNAL_PLAYER
#define EXTERNAL_PLAYER "/usr/bin/timidity"
#endif
static pid_t _pid;
static void extmidi_kill(void) {
if(_pid > 0) {
kill(_pid, SIGKILL);
while(waitpid(_pid, NULL, WNOHANG) != _pid);
}
_pid = 0;
}
static char *extmidi_start(char **parm) {
_pid = 0;
return NULL;
}
static void extmidi_stop(void) {
extmidi_kill();
}
static void extmidi_play_song(const char *filename) {
extmidi_kill();
_pid = fork();
if(_pid < 0) {
fprintf(stderr, "extmidi: couldn't fork: %s\n", strerror(errno));
_pid = 0;
return;
}
if(_pid == 0) {
#if defined(MIDI_ARG)
execl(EXTERNAL_PLAYER, "extmidi", MIDI_ARG, filename, NULL);
#else
execl(EXTERNAL_PLAYER, "extmidi", filename, NULL);
#endif
fprintf(stderr, "extmidi: couldn't execl: %s\n", strerror(errno));
exit(0);
}
usleep(500);
if(_pid == waitpid(_pid, NULL, WNOHANG)) {
fprintf(stderr, "extmidi: play song failed\n");
_pid = 0;
usleep(5000);
}
}
static void extmidi_stop_song(void) {
extmidi_kill();
}
static bool extmidi_is_playing(void) {
if(_pid == 0)
return 0;
if(waitpid(_pid, NULL, WNOHANG) == _pid) {
_pid = 0;
return 0;
}
return 1;
}
static void extmidi_set_volume(byte vol) {
fprintf(stderr, "extmidi: set volume not implemented\n");
}
const HalMusicDriver _extmidi_music_driver = {
extmidi_start,
extmidi_stop,
extmidi_play_song,
extmidi_stop_song,
extmidi_is_playing,
extmidi_set_volume,
};
#endif /* __MORPHOS__ */
#endif /* __BEOS__ */

123
fileio.c Normal file
View File

@@ -0,0 +1,123 @@
#include "stdafx.h"
#include "ttd.h"
#if defined(UNIX)
#include <ctype.h> // required for tolower()
#endif
/*************************************************/
/* FILE IO ROUTINES ******************************/
/*************************************************/
#define FIO_BUFFER_SIZE 512
typedef struct {
byte *buffer, *buffer_end;
uint32 pos;
FILE *cur_fh;
FILE *handles[32];
byte buffer_start[512];
} Fio;
static Fio _fio;
// Get current position in file
uint32 FioGetPos()
{
return _fio.pos + (_fio.buffer - _fio.buffer_start) - FIO_BUFFER_SIZE;
}
void FioSeekTo(uint32 pos, int mode)
{
if (mode == SEEK_CUR) pos += FioGetPos();
_fio.buffer = _fio.buffer_end = _fio.buffer_start + FIO_BUFFER_SIZE;
fseek(_fio.cur_fh, (_fio.pos=pos), SEEK_SET);
}
// Seek to a file and a position
void FioSeekToFile(uint32 pos)
{
FILE *f = _fio.handles[pos >> 24];
assert(f != NULL);
_fio.cur_fh = f;
FioSeekTo(pos & 0xFFFFFF, SEEK_SET);
}
byte FioReadByte()
{
if (_fio.buffer == _fio.buffer_end) {
_fio.pos += FIO_BUFFER_SIZE;
fread(_fio.buffer = _fio.buffer_start, 1, FIO_BUFFER_SIZE, _fio.cur_fh);
}
return *_fio.buffer++;
}
void FioSkipBytes(int n)
{
for(;;) {
int m = min(_fio.buffer_end - _fio.buffer, n);
_fio.buffer += m;
n -= m;
if (n == 0) break;
FioReadByte();
n--;
}
}
uint16 FioReadWord()
{
byte b = FioReadByte();
return (FioReadByte() << 8) | b;
}
uint32 FioReadDword()
{
uint b = FioReadWord();
return (FioReadWord() << 16) | b;
}
void FioReadBlock(void *ptr, uint size)
{
FioSeekTo(FioGetPos(), SEEK_SET);
_fio.pos += size;
fread(ptr, 1, size, _fio.cur_fh);
}
void FioCloseAll()
{
int i;
for(i=0; i!=lengthof(_fio.handles); i++) {
if (_fio.handles[i] != NULL) {
fclose(_fio.handles[i]);
_fio.handles[i] = NULL;
}
}
}
void FioOpenFile(int slot, 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");
}
#endif
if (f == NULL)
error("Cannot open file '%s'", buf);
_fio.handles[slot] = f;
FioSeekToFile(slot << 24);
}

15
fileio.h Normal file
View File

@@ -0,0 +1,15 @@
#ifndef FILEIO_H
#define FILEIO_H
void FioSeekTo(uint32 pos, int mode);
void FioSeekToFile(uint32 pos);
uint32 FioGetPos();
byte FioReadByte();
uint16 FioReadWord();
uint32 FioReadDword();
void FioCloseAll();
void FioOpenFile(int slot, const char *filename);
void FioReadBlock(void *ptr, uint size);
void FioSkipBytes(int n);
#endif /* FILEIO_H */

286
functions.h Normal file
View File

@@ -0,0 +1,286 @@
#ifndef FUNCTIONS_H
#define FUNCTIONS_H
#include "network.h"
/* vehicle.c */
/* window.c */
/* landscape.c */
void FindLandscapeHeight(TileInfo *ti, uint x, uint y);
void FindLandscapeHeightByTile(TileInfo *ti, uint tile);
uint GetTileSlope(uint tile, int *h);
int GetTileZ(uint tile);
void DoClearSquare(uint tile);
void CDECL ModifyTile(uint tile, uint flags, ...);
void SetMapExtraBits(uint tile, byte flags);
uint GetMapExtraBits(uint tile);
void RunTileLoop();
uint GetPartialZ(int x, int y, int corners);
uint GetSlopeZ(int x, int y);
uint32 GetTileTrackStatus(uint tile, TransportType mode);
void GetAcceptedCargo(uint tile, AcceptedCargo *ac);
void ChangeTileOwner(uint tile, byte old_player, byte new_player);
void AnimateTile(uint tile);
void ClickTile(uint tile);
void GetTileDesc(uint tile, TileDesc *td);
void DrawTile(TileInfo *ti);
uint TileAddWrap(TileIndex tile, int addx, int addy);
enum {
TILE_WRAPPED = (uint)-1
};
bool IsValidTile(uint tile);
#if !defined(NEW_ROTATION)
static Point FORCEINLINE RemapCoords(int x, int y, int z) { Point pt = { (y-x)*2, y + x -z }; return pt; }
#else
static Point FORCEINLINE RemapCoords(int x, int y, int z) { Point pt = { (x + y)*2, x - y -z }; return pt; }
#endif
static Point FORCEINLINE RemapCoords2(int x, int y) { return RemapCoords(x, y, GetSlopeZ(x, y)); }
/* game.c */
byte *GetString(byte *buffr, uint16 string);
void InjectDparam(int amount);
int32 GetParamInt32();
int GetParamInt16();
int GetParamInt8();
int GetParamUint16();
/* sound.c */
void SndPlayTileFx(int sound, TileIndex tile);
void SndPlayVehicleFx(int sound, Vehicle *v);
void SndPlayFx(int sound);
/* clear_land.c */
void DrawHillyLandTile(TileInfo *ti);
void DrawClearLandTile(TileInfo *ti, byte set);
void DrawClearLandFence(TileInfo *ti, byte img);
void TileLoopClearHelper(uint 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(uint tile);
/* players.c */
bool CheckPlayerHasMoney(int32 cost);
void SubtractMoneyFromPlayer(int32 cost);
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, ...);
void memswap(void *a, void *b, size_t size);
/* ttd.c */
uint32 Random();
uint RandomRange(uint max);
void InitPlayerRandoms();
uint32 InteractiveRandom(); /* Used for random sequences that are not the same on the other end of the multiplayer link */
uint InteractiveRandomRange(uint max);
void SetDate(uint date);
/* facedraw.c */
void DrawPlayerFace(uint32 face, int color, int x, int y);
/* texteff.c */
void MoveAllTextEffects();
void AddTextEffect(StringID msg, int x, int y, uint16 duration);
void InitTextEffects();
void DrawTextEffects(DrawPixelInfo *dpi);
bool AddAnimatedTile(uint tile);
void DeleteAnimatedTile(uint tile);
void AnimateAnimatedTiles();
void InitializeAnimatedTiles();
/* tunnelbridge_cmd.c */
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);
/* network.c */
typedef void CommandCallback(bool success, uint tile, uint32 p1, uint32 p2);
bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback, uint32 cmd);
void NetworkReceive();
void NetworkSend();
void NetworkProcessCommands();
void NetworkListen();
void NetworkInitialize();
void NetworkShutdown();
void NetworkSendCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback);
void NetworkSendEvent(uint16 type, uint16 data_len, void * data);
void NetworkStartSync(bool fcreset);
void NetworkClose(bool client);
void NetworkSendReadyPacket();
void NetworkSendSyncPackets();
void NetworkSendFrameSyncPackets();
bool NetworkCheckClientReady();
void NetworkIPListInit();
void NetworkCoreInit();
void NetworkCoreShutdown();
void NetworkCoreDisconnect();
void NetworkCoreLoop(bool incomming);
bool NetworkCoreConnectGame(const byte* b, unsigned short port);
bool NetworkCoreConnectGameStruct(NetworkGameList * item);
bool NetworkCoreStartGame();
void NetworkLobbyShutdown();
void NetworkLobbyInit();
void NetworkGameListClear();
NetworkGameList * NetworkGameListAdd();
void NetworkGameListFromLAN();
void NetworkGameListFromInternet();
NetworkGameList * NetworkGameListItem(uint16 index);
void NetworkGameFillDefaults();
void NetworkGameChangeDate(uint16 newdate);
/* misc_cmd.c */
void PlaceTreesRandomly();
uint GetTileDist(TileIndex xy1, TileIndex xy2);
uint GetTileDist1D(TileIndex xy1, TileIndex xy2);
uint GetTileDist1Db(TileIndex xy1, TileIndex xy2);
uint GetTileDistAdv(TileIndex xy1, TileIndex xy2);
bool CheckDistanceFromEdge(TileIndex tile, uint distance);
void InitializeLandscapeVariables(bool only_constants);
/* misc.c */
void DeleteName(StringID id);
byte *GetName(int id, byte *buff);
StringID AllocateName(const byte *name, byte skip);
void ConvertDayToYMD(YearMonthDay *ymd, uint16 date);
uint ConvertYMDToDay(uint year, uint month, uint day);
uint ConvertIntDate(uint date);
/* misc functions */
void MarkTileDirty(int x, int y);
void MarkTileDirtyByTile(TileIndex tile);
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 SetObjectToPlaceWnd(int icon, byte mode, Window *w);
void SetObjectToPlace(int icon, byte mode, byte window_class, uint16 window_num);
void ResetObjectToPlace();
bool ScrollWindowToTile(TileIndex tile, Window * w);
bool ScrollWindowTo(int x, int y, Window * w);
bool ScrollMainWindowToTile(TileIndex tile);
bool ScrollMainWindowTo(int x, int y);
void DrawSprite(uint32 img, int x, int y);
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 MarkWholeScreenDirty();
void DrawFoundation(TileInfo *ti, uint f);
bool CheckIfAuthorityAllows(uint tile);
Town *ClosestTownFromTile(uint tile, uint threshold);
void ChangeTownRating(Town *t, int add, int max);
uint GetRoadBitsByTile(TileIndex tile);
int GetTownRadiusGroup(Town *t, uint tile);
int32 GetTransportedGoodsIncome(uint num_pieces, uint dist, byte transit_days, byte cargo_type);
void ShowRenameSignWindow(SignStruct *ss);
void ShowRenameCheckpointWindow(Checkpoint *cp);
int FindFirstBit(uint32 x);
void ShowHighscoreTable(int tbl);
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 AskExitGame();
void AskExitToGameMenu();
void RedrawAutosave();
StringID RemapOldStringID(StringID s);
void UpdateViewportSignPos(ViewportSign *sign, int left, int top, StringID str);
enum {
SLD_LOAD_GAME = 0,
SLD_LOAD_SCENARIO = 1,
SLD_SAVE_GAME = 2,
SLD_SAVE_SCENARIO = 3,
SLD_NEW_GAME = 4,
};
void ShowSaveLoadDialog(int mode);
void ttd_strlcpy(char *dst, const char *src, size_t len);
// callback from drivers that is called if the game size changes dynamically
void GameSizeChanged();
bool MakeScreenshot();
bool MakeWorldScreenshot(int left, int top, int width, int height, int zoom);
bool FileExists(const char *filename);
bool ReadLanguagePack(int index);
void InitializeLanguagePacks();
byte *ReadFileToMem(const char *filename, size_t *lenp, size_t maxsize);
int GetLanguageList(char **languages, int max);
const char *GetScreenshotFormatDesc(int i);
void InitializeScreenshotFormats();
void SetScreenshotFormat(int i);
void CheckSwitchToEuro();
void LoadFromConfig();
void SaveToConfig();
int ttd_main(int argc, char* argv[]);
byte GetOSVersion();
void DeterminePaths();
char * CDECL str_fmt(const char *str, ...);
#endif /* FUNCTIONS_H */

1930
gfx.c Normal file

File diff suppressed because it is too large Load Diff

110
gfx.h Normal file
View File

@@ -0,0 +1,110 @@
#ifndef GFX_H
#define GFX_H
typedef struct ColorList {
byte unk0, unk1, unk2;
byte window_color_1a, window_color_1b;
byte window_color_bga, window_color_bgb;
byte window_color_2;
} ColorList;
struct DrawPixelInfo {
byte *dst_ptr;
int left, top, width, height;
int pitch;
uint16 zoom;
};
typedef struct SpriteHdr {
byte info;
byte height;
uint16 width;
int16 x_offs, y_offs;
} SpriteHdr;
assert_compile(sizeof(SpriteHdr) == 8);
typedef struct CursorVars {
Point pos, size, offs, delta;
Point draw_pos, draw_size;
uint32 sprite;
int wheel; // mouse wheel movement
const uint16 *animate_list, *animate_cur;
uint animate_timeout;
bool visible;
bool dirty;
bool fix_at;
} 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);
int DrawStringCentered(int x, int y, uint16 str, byte color);
int DrawString(int x, int y, uint16 str, byte color);
void DrawStringCenterUnderline(int x, int y, uint16 str, byte color);
int DoDrawString(const byte *string, int x, int y, byte color);
void DrawStringRightAligned(int x, int y, uint16 str, byte 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);
int GetStringWidth(const byte *str);
void LoadStringWidthTable();
void DrawStringMultiCenter(int x, int y, uint16 str, int maxw);
void DrawStringMultiLine(int x, int y, uint16 str, int maxw);
void DrawDirtyBlocks();
void SetDirtyBlocks(int left, int top, int right, int bottom);
void MarkWholeScreenDirty();
void GfxInitPalettes();
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);
/* spritecache.c */
byte *GetSpritePtr(uint sprite);
void GfxInitSpriteMem(byte *ptr, uint32 size);
void GfxLoadSprites();
void SetMouseCursor(uint cursor);
void SetAnimatedMouseCursor(const uint16 *table);
void CursorTick();
void DrawMouseCursor();
void ScreenSizeChanged();
void UndrawMouseCursor();
bool ChangeResInGame(int w, int h);
typedef struct {
int xoffs, yoffs;
int xsize, ysize;
} SpriteDimension;
const SpriteDimension *GetSpriteDimension(uint sprite);
/* gfx.c */
VARDEF int _stringwidth_base;
VARDEF byte _stringwidth_table[0x2A0];
VARDEF DrawPixelInfo _screen;
VARDEF DrawPixelInfo *_cur_dpi;
VARDEF ColorList _color_list[16];
VARDEF CursorVars _cursor;
VARDEF int _pal_first_dirty;
VARDEF int _pal_last_dirty;
/* spritecache.c */
//enum { NUM_SPRITES = 0x1320 };
//enum { NUM_SPRITES = 0x1500 };
enum { NUM_SPRITES = 0x3500 }; // 1500 + space for custom GRF sets
/* tables.h */
extern byte _palettes[4][256 * 3];
VARDEF byte _cur_palette[768];
#endif

1103
graph_gui.c Normal file

File diff suppressed because it is too large Load Diff

1072
grfspecial.c Normal file

File diff suppressed because it is too large Load Diff

121
gui.h Normal file
View File

@@ -0,0 +1,121 @@
#ifndef GUI_H
#define GUI_H
#include "window.h"
/* main_gui.c */
void SetupColorsAndInitialWindow();
void CcPlaySound10(bool success, uint tile, uint32 p1, uint32 p2);
void PlaceProc_Sign(uint tile);
/* settings_gui.c */
void ShowGameOptions();
void ShowGameDifficulty();
void ShowPatchesSelection();
/* graph_gui.c */
void ShowOperatingProfitGraph();
void ShowIncomeGraph();
void ShowDeliveredCargoGraph();
void ShowPerformanceHistoryGraph();
void ShowCompanyValueGraph();
void ShowCargoPaymentRates();
void ShowCompanyLeagueTable();
void ShowPerformanceRatingDetail();
/* news_gui.c */
void ShowLastNewsMessage();
void ShowMessageOptions();
void ShowMessageHistory();
/* traintoolb_gui.c */
void ShowBuildRailToolbar(int index, int button);
void PlaceProc_BuyLand(uint tile);
/* train_gui.c */
void ShowPlayerTrains(int player);
void ShowTrainViewWindow(Vehicle *v);
void ShowTrainDetailsWindow(Vehicle *v);
void ShowOrdersWindow(Vehicle *v);
void ShowRoadVehViewWindow(Vehicle *v);
/* road_gui.c */
void ShowBuildRoadToolbar();
void ShowBuildRoadScenToolbar();
void ShowPlayerRoadVehicles(int player);
/* dock_gui.c */
void ShowBuildDocksToolbar();
void ShowPlayerShips(int player);
void ShowShipViewWindow(Vehicle *v);
/* aircraft_gui.c */
void ShowBuildAirToolbar();
void ShowPlayerAircraft(int player);
/* terraform_gui.c */
void PlaceProc_DemolishArea(uint tile);
void PlaceProc_LowerLand(uint tile);
void PlaceProc_RaiseLand(uint tile);
void PlaceProc_LevelLand(uint tile);
void ShowTerraformToolbar();
/* misc_gui.c */
void PlaceLandBlockInfo();
void ShowAboutWindow();
void ShowBuildTreesToolbar();
void ShowBuildTreesScenToolbar();
void ShowTownDirectory();
void ShowIndustryDirectory();
void ShowSubsidiesList();
void ShowPlayerStations(int player);
void ShowPlayerFinances(int player);
void ShowPlayerCompany(int player);
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);
void CheckRedrawStationCoverage(Window *w);
void ShowSmallMap();
void ShowExtraViewPortWindow();
void SetVScrollCount(Window *w, int num);
void SetHScrollCount(Window *w, int num);
int HandleEditBoxKey(Window *w, int wid, WindowEvent *we);
void ShowCheatWindow();
void AskForNewGameToStart();
void DrawEditBox(Window *w, int wid);
void HandleEditBox(Window *w, int wid);
/* network gui */
void ShowNetworkGameWindow();
/* bridge_gui.c */
void ShowBuildBridgeWindow(uint start, uint end, byte type);
enum {
ZOOM_IN = 0,
ZOOM_OUT = 1,
ZOOM_NONE = 2, // hack, used to update the button status
};
bool DoZoomInOutWindow(int how, Window * w);
void ShowBuildIndustryWindow();
void ShowQueryString(StringID str, StringID caption, int maxlen, int maxwidth, byte window_class, uint16 window_number);
void ShowMusicWindow();
/* main_gui.c */
VARDEF byte _newspaper_flag;
VARDEF byte _construct_mode;
VARDEF byte _station_show_coverage;
VARDEF PlaceProc *_place_proc;
VARDEF bool _no_button_sound;
#endif /* GUI_H */

146
hal.h Normal file
View File

@@ -0,0 +1,146 @@
#ifndef HAL_H
#define HAL_H
typedef struct {
char *(*start)(char **parm);
void (*stop)();
} HalCommonDriver;
typedef struct {
const char *(*start)(char **parm);
void (*stop)();
void (*make_dirty)(int left, int top, int width, int height);
int (*main_loop)();
bool (*change_resolution)(int w, int h);
} HalVideoDriver;
enum {
ML_QUIT = 0,
ML_SWITCHDRIVER = 1,
};
typedef struct {
char *(*start)(char **parm);
void (*stop)();
} HalSoundDriver;
typedef struct {
char *(*start)(char **parm);
void (*stop)();
void (*play_song)(const char *filename);
void (*stop_song)();
bool (*is_song_playing)();
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
enum DriverType {
VIDEO_DRIVER = 0,
SOUND_DRIVER = 1,
MUSIC_DRIVER = 2,
};
extern void GameLoop();
extern bool _dbg_screen_rect;
void LoadDriver(int driver, const char *name);
char *GetDriverParam(char **parm, const char *name);
bool GetDriverParamBool(char **parm, const char *name);
int GetDriverParamInt(char **parm, const char *name, int def);
// Deals with finding savegames
typedef struct {
uint16 id;
byte type;
uint64 mtime;
char title[64];
char name[256-12-64];
int old_extension;
} FiosItem;
// extensions of old savegames, scenarios
static const char* const _old_extensions[] = {
// old savegame types
"ss1", // Transport Tycoon Deluxe preset game
"sv1", // Transport Tycoon Deluxe (Patch) saved game
"sv2", // Transport Tycoon Deluxe (Patch) saved 2-player game
// old scenario game type
"sv0", // Transport Tycoon Deluxe (Patch) scenario
"ss0", // Transport Tycoon Deluxe preset scenario
};
enum {
FIOS_TYPE_DRIVE = 0,
FIOS_TYPE_PARENT = 1,
FIOS_TYPE_DIR = 2,
FIOS_TYPE_FILE = 3,
FIOS_TYPE_OLDFILE = 4,
FIOS_TYPE_SCENARIO = 5,
FIOS_TYPE_OLD_SCENARIO = 6,
};
// get the name of an oldstyle savegame
void GetOldSaveGameName(char *title, const char *file);
// get the name of an oldstyle scenario
void GetOldScenarioGameName(char *title, const char *file);
// Get a list of savegames
FiosItem *FiosGetSavegameList(int *num, int mode);
// Get a list of scenarios
FiosItem *FiosGetScenarioList(int *num, int mode);
// Free the list of savegames
void FiosFreeSavegameList();
// Browse to. Returns a filename w/path if we reached a file.
char *FiosBrowseTo(const FiosItem *item);
// Get descriptive texts.
// Returns a path as well as a
// string describing the path.
StringID FiosGetDescText(const char **path);
// Delete a name
void FiosDelete(const char *name);
// Make a filename from a name
void FiosMakeSavegameName(char *buf, const char *name);
void CreateConsole();
#endif /* HAL_H */

74
industry.h Normal file
View File

@@ -0,0 +1,74 @@
#ifndef INDUSTRY_H
#define INDUSTRY_H
struct Industry {
TileIndex xy;
byte width; /* swapped order of w/h with town */
byte height;
Town *town;
byte produced_cargo[2];
uint16 cargo_waiting[2];
byte production_rate[2];
byte accepts_cargo[3];
byte prod_level;
uint16 last_mo_production[2];
uint16 last_mo_transported[2];
byte pct_transported[2];
uint16 total_production[2];
uint16 total_transported[2];
uint16 counter;
byte type;
byte owner;
byte color_map;
byte last_prod_year;
byte was_cargo_delivered;
};
VARDEF int _total_industries; // For the AI: the amount of industries active
VARDEF Industry _industries[90];
#define DEREF_INDUSTRY(i) (&_industries[i])
VARDEF bool _industry_sort_dirty;
void DeleteIndustry(Industry *is);
enum {
IT_COAL_MINE = 0,
IT_POWER_STATION = 1,
IT_SAWMILL = 2,
IT_FOREST = 3,
IT_OIL_REFINERY = 4,
IT_OIL_RIG = 5,
IT_FACTORY = 6,
IT_PRINTING_WORKS = 7,
IT_STEEL_MILL = 8,
IT_FARM = 9,
IT_COPPER_MINE = 10,
IT_OIL_WELL = 11,
IT_BANK = 12,
IT_FOOD_PROCESS = 13,
IT_PAPER_MILL = 14,
IT_GOLD_MINE = 15,
IT_BANK_2 = 16,
IT_DIAMOND_MINE = 17,
IT_IRON_MINE = 18,
IT_FRUIT_PLANTATION = 19,
IT_RUBBER_PLANTATION = 20,
IT_WATER_SUPPLY = 21,
IT_WATER_TOWER = 22,
IT_FACTORY_2 = 23,
IT_FARM_2 = 24,
IT_LUMBER_MILL = 25,
IT_COTTON_CANDY = 26,
IT_CANDY_FACTORY = 27,
IT_BATTERY_FARM = 28,
IT_COLA_WELLS = 29,
IT_TOY_SHOP = 30,
IT_TOY_FACTORY = 31,
IT_PLASTIC_FOUNTAINS = 32,
IT_FIZZY_DRINK_FACTORY = 33,
IT_BUBBLE_GENERATOR = 34,
IT_TOFFEE_QUARRY = 35,
IT_SUGAR_MINE = 36,
};
#endif

1905
industry_cmd.c Normal file

File diff suppressed because it is too large Load Diff

589
industry_gui.c Normal file
View File

@@ -0,0 +1,589 @@
#include "stdafx.h"
#include "ttd.h"
//#include "gui.h"
#include "window.h"
#include "gfx.h"
#include "command.h"
#include "viewport.h"
#include "industry.h"
#include "town.h"
static const byte _build_industry_types[4][12] = {
{ 1, 2, 4, 6, 8, 0, 3, 5, 9, 11, 18 },
{ 1, 14, 4, 13, 7, 0, 3, 9, 11, 15 },
{ 25, 13, 4, 23, 22, 11, 17, 10, 24, 19, 20, 21 },
{ 27, 30, 31, 33, 26, 28, 29, 32, 34, 35, 36 },
};
extern const byte _industry_type_costs[37];
static void BuildIndustryWndProc(Window *w, WindowEvent *e)
{
switch(e->event) {
case WE_PAINT:
DrawWindowWidgets(w);
if (_thd.place_mode == 1 && _thd.window_class == WC_BUILD_INDUSTRY) {
int ind_type = _build_industry_types[_opt.landscape][WP(w,def_d).data_1];
SET_DPARAM32(0, (_price.build_industry >> 5) * _industry_type_costs[ind_type]);
DrawStringCentered(85, w->height - 21, STR_482F_COST, 0);
}
break;
case WE_CLICK: {
int wid = e->click.widget;
if (wid >= 3) {
if (HandlePlacePushButton(w, wid, 0xFF1, 1, NULL))
WP(w,def_d).data_1 = wid - 3;
}
} break;
case WE_PLACE_OBJ:
if (DoCommandP(e->place.tile, _build_industry_types[_opt.landscape][WP(w,def_d).data_1], 0, NULL, CMD_BUILD_INDUSTRY | CMD_MSG(STR_4830_CAN_T_CONSTRUCT_THIS_INDUSTRY)))
ResetObjectToPlace();
break;
case WE_ABORT_PLACE_OBJ:
w->click_state = 0;
SetWindowDirty(w);
break;
}
}
static const Widget _build_industry_land0_widgets[] = {
{ WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_PANEL, 7, 0, 169, 14, 115, 0x0, STR_NULL},
{ WWT_CLOSEBOX, 14, 2, 167, 16, 27, STR_0241_POWER_STATION, STR_0263_CONSTRUCT_POWER_STATION},
{ WWT_CLOSEBOX, 14, 2, 167, 29, 40, STR_0242_SAWMILL, STR_0264_CONSTRUCT_SAWMILL},
{ WWT_CLOSEBOX, 14, 2, 167, 42, 53, STR_0244_OIL_REFINERY, STR_0266_CONSTRUCT_OIL_REFINERY},
{ WWT_CLOSEBOX, 14, 2, 167, 55, 66, STR_0246_FACTORY, STR_0268_CONSTRUCT_FACTORY},
{ WWT_CLOSEBOX, 14, 2, 167, 68, 79, STR_0247_STEEL_MILL, STR_0269_CONSTRUCT_STEEL_MILL},
{ WIDGETS_END},
};
static const Widget _build_industry_land1_widgets[] = {
{ WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_PANEL, 7, 0, 169, 14, 115, 0x0, STR_NULL},
{ WWT_CLOSEBOX, 14, 2, 167, 16, 27, STR_0241_POWER_STATION, STR_0263_CONSTRUCT_POWER_STATION},
{ WWT_CLOSEBOX, 14, 2, 167, 29, 40, STR_024C_PAPER_MILL, STR_026E_CONSTRUCT_PAPER_MILL},
{ WWT_CLOSEBOX, 14, 2, 167, 42, 53, STR_0244_OIL_REFINERY, STR_0266_CONSTRUCT_OIL_REFINERY},
{ WWT_CLOSEBOX, 14, 2, 167, 55, 66, STR_024D_FOOD_PROCESSING_PLANT,STR_026F_CONSTRUCT_FOOD_PROCESSING},
{ WWT_CLOSEBOX, 14, 2, 167, 68, 79, STR_024E_PRINTING_WORKS, STR_0270_CONSTRUCT_PRINTING_WORKS},
{ WIDGETS_END},
};
static const Widget _build_industry_land2_widgets[] = {
{ WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_PANEL, 7, 0, 169, 14, 115, 0x0, STR_NULL},
{ WWT_CLOSEBOX, 14, 2, 167, 16, 27, STR_0250_LUMBER_MILL, STR_0273_CONSTRUCT_LUMBER_MILL_TO},
{ WWT_CLOSEBOX, 14, 2, 167, 29, 40, STR_024D_FOOD_PROCESSING_PLANT,STR_026F_CONSTRUCT_FOOD_PROCESSING},
{ WWT_CLOSEBOX, 14, 2, 167, 42, 53, STR_0244_OIL_REFINERY, STR_0266_CONSTRUCT_OIL_REFINERY},
{ WWT_CLOSEBOX, 14, 2, 167, 55, 66, STR_0246_FACTORY, STR_0268_CONSTRUCT_FACTORY},
{ WWT_CLOSEBOX, 14, 2, 167, 68, 79, STR_0254_WATER_TOWER, STR_0277_CONSTRUCT_WATER_TOWER_CAN},
{ WIDGETS_END},
};
static const Widget _build_industry_land3_widgets[] = {
{ WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_PANEL, 7, 0, 169, 14, 115, 0x0, STR_NULL},
{ WWT_CLOSEBOX, 14, 2, 167, 16, 27, STR_0258_CANDY_FACTORY, STR_027B_CONSTRUCT_CANDY_FACTORY},
{ WWT_CLOSEBOX, 14, 2, 167, 29, 40, STR_025B_TOY_SHOP, STR_027E_CONSTRUCT_TOY_SHOP},
{ WWT_CLOSEBOX, 14, 2, 167, 42, 53, STR_025C_TOY_FACTORY, STR_027F_CONSTRUCT_TOY_FACTORY},
{ WWT_CLOSEBOX, 14, 2, 167, 55, 66, STR_025E_FIZZY_DRINK_FACTORY, STR_0281_CONSTRUCT_FIZZY_DRINK_FACTORY},
{ WIDGETS_END},
};
static const Widget _build_industry_land0_widgets_extra[] = {
{ WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY,STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_PANEL, 7, 0, 169, 14, 187, 0x0, STR_NULL},
{ WWT_CLOSEBOX, 14, 2, 167, 16, 27, STR_0241_POWER_STATION,STR_0263_CONSTRUCT_POWER_STATION},
{ WWT_CLOSEBOX, 14, 2, 167, 29, 40, STR_0242_SAWMILL, STR_0264_CONSTRUCT_SAWMILL},
{ WWT_CLOSEBOX, 14, 2, 167, 42, 53, STR_0244_OIL_REFINERY, STR_0266_CONSTRUCT_OIL_REFINERY},
{ WWT_CLOSEBOX, 14, 2, 167, 55, 66, STR_0246_FACTORY, STR_0268_CONSTRUCT_FACTORY},
{ WWT_CLOSEBOX, 14, 2, 167, 68, 79, STR_0247_STEEL_MILL, STR_0269_CONSTRUCT_STEEL_MILL},
{ WWT_CLOSEBOX, 14, 2, 167, 84, 95, STR_0240_COAL_MINE, STR_CONSTRUCT_COAL_MINE_TIP},
{ WWT_CLOSEBOX, 14, 2, 167, 97, 108, STR_0243_FOREST, STR_CONSTRUCT_FOREST_TIP},
{ WWT_CLOSEBOX, 14, 2, 167, 110, 121, STR_0245_OIL_RIG, STR_CONSTRUCT_OIL_RIG_TIP},
{ WWT_CLOSEBOX, 14, 2, 167, 123, 134, STR_0248_FARM, STR_CONSTRUCT_FARM_TIP},
{ WWT_CLOSEBOX, 14, 2, 167, 136, 147, STR_024A_OIL_WELLS, STR_CONSTRUCT_OIL_WELLS_TIP},
{ WWT_CLOSEBOX, 14, 2, 167, 149, 160, STR_0249_IRON_ORE_MINE, STR_CONSTRUCT_IRON_ORE_MINE_TIP},
{ WIDGETS_END},
};
static const Widget _build_industry_land1_widgets_extra[] = {
{ WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_PANEL, 7, 0, 169, 14, 174, 0x0, STR_NULL},
{ WWT_CLOSEBOX, 14, 2, 167, 16, 27, STR_0241_POWER_STATION, STR_0263_CONSTRUCT_POWER_STATION},
{ WWT_CLOSEBOX, 14, 2, 167, 29, 40, STR_024C_PAPER_MILL, STR_026E_CONSTRUCT_PAPER_MILL},
{ WWT_CLOSEBOX, 14, 2, 167, 42, 53, STR_0244_OIL_REFINERY, STR_0266_CONSTRUCT_OIL_REFINERY},
{ WWT_CLOSEBOX, 14, 2, 167, 55, 66, STR_024D_FOOD_PROCESSING_PLANT,STR_026F_CONSTRUCT_FOOD_PROCESSING},
{ WWT_CLOSEBOX, 14, 2, 167, 68, 79, STR_024E_PRINTING_WORKS, STR_0270_CONSTRUCT_PRINTING_WORKS},
{ WWT_CLOSEBOX, 14, 2, 167, 81+3, 92+3, STR_0240_COAL_MINE, STR_CONSTRUCT_COAL_MINE_TIP},
{ WWT_CLOSEBOX, 14, 2, 167, 94+3, 105+3, STR_0243_FOREST, STR_CONSTRUCT_FOREST_TIP},
{ WWT_CLOSEBOX, 14, 2, 167, 107+3, 118+3, STR_0248_FARM, STR_CONSTRUCT_FARM_TIP},
{ WWT_CLOSEBOX, 14, 2, 167, 120+3, 131+3, STR_024A_OIL_WELLS, STR_CONSTRUCT_OIL_WELLS_TIP},
{ WWT_CLOSEBOX, 14, 2, 167, 133+3, 144+3, STR_024F_GOLD_MINE, STR_CONSTRUCT_GOLD_MINE_TIP},
{ WIDGETS_END},
};
static const Widget _build_industry_land2_widgets_extra[] = {
{ WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_PANEL, 7, 0, 169, 14, 200, 0x0, STR_NULL},
{ WWT_CLOSEBOX, 14, 2, 167, 16, 27, STR_0250_LUMBER_MILL, STR_0273_CONSTRUCT_LUMBER_MILL_TO},
{ WWT_CLOSEBOX, 14, 2, 167, 29, 40, STR_024D_FOOD_PROCESSING_PLANT,STR_026F_CONSTRUCT_FOOD_PROCESSING},
{ WWT_CLOSEBOX, 14, 2, 167, 42, 53, STR_0244_OIL_REFINERY, STR_0266_CONSTRUCT_OIL_REFINERY},
{ WWT_CLOSEBOX, 14, 2, 167, 55, 66, STR_0246_FACTORY, STR_0268_CONSTRUCT_FACTORY},
{ WWT_CLOSEBOX, 14, 2, 167, 68, 79, STR_0254_WATER_TOWER, STR_0277_CONSTRUCT_WATER_TOWER_CAN},
{ WWT_CLOSEBOX, 14, 2, 167, 81+3, 92+3, STR_024A_OIL_WELLS,STR_CONSTRUCT_OIL_WELLS_TIP},
{ WWT_CLOSEBOX, 14, 2, 167, 94+3, 105+3, STR_0255_DIAMOND_MINE, STR_CONSTRUCT_DIAMOND_MINE_TIP},
{ WWT_CLOSEBOX, 14, 2, 167, 107+3, 118+3, STR_0256_COPPER_ORE_MINE, STR_CONSTRUCT_COPPER_ORE_MINE_TIP},
{ WWT_CLOSEBOX, 14, 2, 167, 120+3, 131+3, STR_0248_FARM, STR_CONSTRUCT_FARM_TIP},
{ WWT_CLOSEBOX, 14, 2, 167, 133+3, 144+3, STR_0251_FRUIT_PLANTATION, STR_CONSTRUCT_FRUIT_PLANTATION_TIP},
{ WWT_CLOSEBOX, 14, 2, 167, 146+3, 157+3, STR_0252_RUBBER_PLANTATION,STR_CONSTRUCT_RUBBER_PLANTATION_TIP},
{ WWT_CLOSEBOX, 14, 2, 167, 159+3, 170+3, STR_0253_WATER_SUPPLY, STR_CONSTRUCT_WATER_SUPPLY_TIP},
{ WIDGETS_END},
};
static const Widget _build_industry_land3_widgets_extra[] = {
{ WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, 7, 11, 169, 0, 13, STR_0314_FUND_NEW_INDUSTRY, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_PANEL, 7, 0, 169, 14, 187, 0x0, STR_NULL},
{ WWT_CLOSEBOX, 14, 2, 167, 16, 27, STR_0258_CANDY_FACTORY, STR_027B_CONSTRUCT_CANDY_FACTORY},
{ WWT_CLOSEBOX, 14, 2, 167, 29, 40, STR_025B_TOY_SHOP, STR_027E_CONSTRUCT_TOY_SHOP},
{ WWT_CLOSEBOX, 14, 2, 167, 42, 53, STR_025C_TOY_FACTORY, STR_027F_CONSTRUCT_TOY_FACTORY},
{ WWT_CLOSEBOX, 14, 2, 167, 55, 66, STR_025E_FIZZY_DRINK_FACTORY, STR_0281_CONSTRUCT_FIZZY_DRINK_FACTORY},
{ WWT_CLOSEBOX, 14, 2, 167, 68+3, 79+3, STR_0257_COTTON_CANDY_FOREST,STR_CONSTRUCT_COTTON_CANDY_TIP},
{ WWT_CLOSEBOX, 14, 2, 167, 81+3, 92+3, STR_0259_BATTERY_FARM, STR_CONSTRUCT_BATTERY_FARM_TIP},
{ WWT_CLOSEBOX, 14, 2, 167, 94+3, 105+3, STR_025A_COLA_WELLS, STR_CONSTRUCT_COLA_WELLS_TIP},
{ WWT_CLOSEBOX, 14, 2, 167, 107+3, 118+3, STR_025D_PLASTIC_FOUNTAINS,STR_CONSTRUCT_PLASTIC_FOUNTAINS_TIP},
{ WWT_CLOSEBOX, 14, 2, 167, 120+3, 131+3, STR_025F_BUBBLE_GENERATOR, STR_CONSTRUCT_BUBBLE_GENERATOR_TIP},
{ WWT_CLOSEBOX, 14, 2, 167, 133+3, 144+3, STR_0260_TOFFEE_QUARRY, STR_CONSTRUCT_TOFFEE_QUARRY_TIP},
{ WWT_CLOSEBOX, 14, 2, 167, 146+3, 157+3, STR_0261_SUGAR_MINE, STR_CONSTRUCT_SUGAR_MINE_TIP},
{ WIDGETS_END},
};
static const WindowDesc _build_industry_land0_desc = {
-1, -1, 170, 116,
WC_BUILD_INDUSTRY,0,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
_build_industry_land0_widgets,
BuildIndustryWndProc
};
static const WindowDesc _build_industry_land1_desc = {
-1, -1, 170, 116,
WC_BUILD_INDUSTRY,0,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
_build_industry_land1_widgets,
BuildIndustryWndProc
};
static const WindowDesc _build_industry_land2_desc = {
-1, -1, 170, 116,
WC_BUILD_INDUSTRY,0,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
_build_industry_land2_widgets,
BuildIndustryWndProc
};
static const WindowDesc _build_industry_land3_desc = {
-1, -1, 170, 116,
WC_BUILD_INDUSTRY,0,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
_build_industry_land3_widgets,
BuildIndustryWndProc
};
static const WindowDesc _build_industry_land0_desc_extra = {
-1, -1, 170, 188,
WC_BUILD_INDUSTRY,0,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
_build_industry_land0_widgets_extra,
BuildIndustryWndProc
};
static const WindowDesc _build_industry_land1_desc_extra = {
-1, -1, 170, 175,
WC_BUILD_INDUSTRY,0,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
_build_industry_land1_widgets_extra,
BuildIndustryWndProc
};
static const WindowDesc _build_industry_land2_desc_extra = {
-1, -1, 170, 201,
WC_BUILD_INDUSTRY,0,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
_build_industry_land2_widgets_extra,
BuildIndustryWndProc
};
static const WindowDesc _build_industry_land3_desc_extra = {
-1, -1, 170, 188,
WC_BUILD_INDUSTRY,0,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
_build_industry_land3_widgets_extra,
BuildIndustryWndProc
};
static const WindowDesc * const _industry_window_desc[2][4] = {
{
&_build_industry_land0_desc,
&_build_industry_land1_desc,
&_build_industry_land2_desc,
&_build_industry_land3_desc,
},
{
&_build_industry_land0_desc_extra,
&_build_industry_land1_desc_extra,
&_build_industry_land2_desc_extra,
&_build_industry_land3_desc_extra,
},
};
void ShowBuildIndustryWindow()
{
AllocateWindowDescFront(_industry_window_desc[_patches.build_rawmaterial_ind][_opt.landscape],0);
}
static void IndustryViewWndProc(Window *w, WindowEvent *e)
{
Industry *i;
StringID str;
switch(e->event) {
case WE_PAINT:
// 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 = DEREF_INDUSTRY(w->window_number);
SET_DPARAM16(0, i->town->index);
SET_DPARAM16(1, i->type + STR_4802_COAL_MINE);
DrawWindowWidgets(w);
if (i->accepts_cargo[0] != 0xFF) {
SET_DPARAM16(0, _cargoc.names_s[i->accepts_cargo[0]]);
str = STR_4827_REQUIRES;
if (i->accepts_cargo[1] != 0xFF) {
SET_DPARAM16(1, _cargoc.names_s[i->accepts_cargo[1]]);
str++;
if (i->accepts_cargo[2] != 0xFF) {
SET_DPARAM16(2, _cargoc.names_s[i->accepts_cargo[2]]);
str++;
}
}
DrawString(2, 107, str, 0);
}
if (i->produced_cargo[0] != 0xFF) {
DrawString(2, 117, STR_482A_PRODUCTION_LAST_MONTH, 0);
SET_DPARAM16(1, i->total_production[0]);
SET_DPARAM16(0, _cargoc.names_long_s[i->produced_cargo[0]] + ((i->total_production[0]!=1)<<5));
SET_DPARAM16(2, i->pct_transported[0] * 100 >> 8);
DrawString(4, 127, STR_482B_TRANSPORTED, 0);
if (i->produced_cargo[1] != 0xFF) {
SET_DPARAM16(1, i->total_production[1]);
SET_DPARAM16(0, _cargoc.names_long_s[i->produced_cargo[1]] + ((i->total_production[1]!=1)<<5));
SET_DPARAM16(2, i->pct_transported[1] * 100 >> 8);
DrawString(4, 137, STR_482B_TRANSPORTED, 0);
}
}
DrawWindowViewport(w);
break;
case WE_CLICK:
switch(e->click.widget) {
case 5:
i = DEREF_INDUSTRY(w->window_number);
ScrollMainWindowToTile(i->xy + TILE_XY(1,1));
break;
case 6:
// Destroy Industry button costing money removed per request of dominik
//i = DEREF_INDUSTRY(w->window_number);
/* passing only i->xy is not safe if industry has a weird shape like:
_ X X
X X X
_ <--- grass, no industry, but i->xy points there (first top-left tile)!,
so passing i->xy to destroy industry will fail in called procedure
*/
//DoCommandP(i->xy, w->window_number, 0, CcPlaySound10, CMD_DESTROY_INDUSTRY | CMD_MSG(STR_00B5_CAN_T_CLEAR_THIS_AREA));
break;
}
break;
}
}
static const Widget _industry_view_widgets[] = {
{ WWT_TEXTBTN, 9, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, 9, 11, 259, 0, 13, STR_4801, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_IMGBTN, 9, 0, 259, 14, 105, 0x0, STR_NULL},
{ WWT_6, 9, 2, 257, 16, 103, 0x0, STR_NULL},
{ WWT_IMGBTN, 9, 0, 259, 106, 147, 0x0, STR_NULL},
{ WWT_PUSHTXTBTN, 9, 0, 129, 148, 159, STR_00E4_LOCATION, STR_482C_CENTER_THE_MAIN_VIEW_ON},
{ WWT_IMGBTN, 9, 130, 259, 148, 159, 0x0, STR_NULL},
// Destroy Industry button costing money removed per request of dominik
//{ WWT_PUSHTXTBTN, 9, 130, 259, 148, 159, STR_INDUSTRYDIR_DESTROY, STR_482C_DESTROY_INDUSTRY},
{ WIDGETS_END},
};
static const WindowDesc _industry_view_desc = {
-1, -1, 260, 160,
WC_INDUSTRY_VIEW,0,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
_industry_view_widgets,
IndustryViewWndProc
};
void ShowIndustryViewWindow(int industry)
{
Window *w;
Industry *i;
w = AllocateWindowDescFront(&_industry_view_desc, industry);
if (w) {
w->flags4 |= WF_DISABLE_VP_SCROLL;
i = DEREF_INDUSTRY(w->window_number);
AssignWindowViewport(w, 3, 17, 0xFE, 0x56, i->xy + TILE_XY(1,1), 1);
}
}
static const Widget _industry_directory_widgets[] = {
{ WWT_TEXTBTN, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, 13, 11, 507, 0, 13, STR_INDUSTRYDIR_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_PUSHTXTBTN, 13, 0, 100, 14, 25, STR_SORT_BY_NAME, STR_SORT_TIP},
{ WWT_PUSHTXTBTN, 13, 101, 200, 14, 25, STR_SORT_BY_TYPE, STR_SORT_TIP},
{ WWT_PUSHTXTBTN, 13, 201, 300, 14, 25, STR_SORT_BY_PRODUCTION, STR_SORT_TIP},
{ WWT_PUSHTXTBTN, 13, 301, 400, 14, 25, STR_SORT_BY_TRANSPORTED, STR_SORT_TIP},
{ WWT_PANEL, 13, 401, 496, 14, 25, 0x0, STR_NULL},
{ WWT_IMGBTN, 13, 0, 496, 26, 189, 0x0, STR_200A_TOWN_NAMES_CLICK_ON_NAME},
{ WWT_SCROLLBAR, 13, 497, 507, 14, 189, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
{ WIDGETS_END},
};
static byte _industry_sort[lengthof(_industries)];
static uint _num_industry_sort;
static char _bufcache[96];
static byte _last_industry_idx;
static byte _industry_sort_order;
static int CDECL GeneralIndustrySorter(const void *a, const void *b)
{
char buf1[96];
byte val;
Industry *i = DEREF_INDUSTRY(*(const byte*)a);
Industry *j = DEREF_INDUSTRY(*(const byte*)b);
int r = 0;
switch (_industry_sort_order >> 1) {
/* case 0: Sort by Name (handled later) */
case 1: /* Sort by Type */
r = i->type - j->type;
break;
// 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] != 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] == 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] == 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] != 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] == 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] == 0xFF) // end up the non-producer industry first/last in list
r = 1;
else
r = -1;
break;
}
// default to string sorting if they are otherwise equal
if (r == 0) {
SET_DPARAM32(0, i->town->townnameparts);
GetString(buf1, i->town->townnametype);
if ( (val=*(const byte*)b) != _last_industry_idx) {
_last_industry_idx = val;
SET_DPARAM32(0, j->town->townnameparts);
GetString(_bufcache, j->town->townnametype);
}
r = strcmp(buf1, _bufcache);
}
if (_industry_sort_order & 1) r = -r;
return r;
}
static void MakeSortedIndustryList()
{
Industry *i;
int n = 0, index = 0;
for(i=_industries; i != endof(_industries); i++) {
if(i->xy) _industry_sort[n++] = index;
index++;
}
_num_industry_sort = n;
_last_industry_idx = 255; // used for "cache"
qsort(_industry_sort, n, 1, GeneralIndustrySorter);
DEBUG(misc, 1) ("Resorting Industries list...");
}
static void IndustryDirectoryWndProc(Window *w, WindowEvent *e)
{
switch(e->event) {
case WE_PAINT: {
int n;
uint p;
Industry *i;
static const uint16 _indicator_positions[4] = {88, 187, 284, 387};
if (_industry_sort_dirty) {
_industry_sort_dirty = false;
MakeSortedIndustryList();
}
w->vscroll.count = _num_industry_sort;
DrawWindowWidgets(w);
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 = DEREF_INDUSTRY(_industry_sort[p]);
SET_DPARAM16(0, i->town->index);
SET_DPARAM16(1, i->type + STR_4802_COAL_MINE);
if (i->produced_cargo[0] != 0xFF) {
SET_DPARAM16(3, i->total_production[0]);
SET_DPARAM16(2, _cargoc.names_long_s[i->produced_cargo[0]] + ((i->total_production[0]!=1)<<5));
if (i->produced_cargo[1] != 0xFF) {
SET_DPARAM16(5, i->total_production[1]);
SET_DPARAM16(4, _cargoc.names_long_s[i->produced_cargo[1]] + ((i->total_production[1]!=1)<<5));
SET_DPARAM16(6, i->pct_transported[0] * 100 >> 8);
SET_DPARAM16(7, i->pct_transported[1] * 100 >> 8);
DrawString(4, 28+n*10, STR_INDUSTRYDIR_ITEM_TWO, 0);
} else {
SET_DPARAM16(4, i->pct_transported[0] * 100 >> 8);
DrawString(4, 28+n*10, STR_INDUSTRYDIR_ITEM, 0);
}
} else {
DrawString(4, 28+n*10, STR_INDUSTRYDIR_ITEM_NOPROD, 0);
}
p++;
if (++n == 16)
break;
}
} break;
case WE_CLICK:
switch(e->click.widget) {
case 2: {
_industry_sort_order = _industry_sort_order==0 ? 1 : 0;
_industry_sort_dirty = true;
SetWindowDirty(w);
} break;
case 3: {
_industry_sort_order = _industry_sort_order==2 ? 3 : 2;
_industry_sort_dirty = true;
SetWindowDirty(w);
} break;
case 4: {
_industry_sort_order = _industry_sort_order==4 ? 5 : 4;
_industry_sort_dirty = true;
SetWindowDirty(w);
} break;
case 5: {
_industry_sort_order = _industry_sort_order==6 ? 7 : 6;
_industry_sort_dirty = true;
SetWindowDirty(w);
} break;
case 7: {
int y = (e->click.pt.y - 28) / 10;
byte p;
Industry *c;
if (!IS_INT_INSIDE(y, 0, 16))
return;
p = y + w->vscroll.pos;
if (p < _num_industry_sort) {
c = DEREF_INDUSTRY(_industry_sort[p]);
ScrollMainWindowToTile(c->xy);
}
} break;
}
break;
case WE_4:
SetWindowDirty(w);
break;
}
}
/* Industry List */
static const WindowDesc _industry_directory_desc = {
-1, -1, 508, 190,
WC_INDUSTRY_DIRECTORY,0,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
_industry_directory_widgets,
IndustryDirectoryWndProc
};
void ShowIndustryDirectory()
{
/* Industry List */
Window *w;
w = AllocateWindowDescFront(&_industry_directory_desc, 0);
if (w) {
w->vscroll.cap = 16;
SetWindowDirty(w);
}
}

291
intro_gui.c Normal file
View File

@@ -0,0 +1,291 @@
#include "stdafx.h"
#include "ttd.h"
#include "window.h"
#include "gui.h"
#include "viewport.h"
#include "gfx.h"
#include "player.h"
#include "command.h"
#include "console.h"
extern void MakeNewGame();
extern void StartScenario();
/*
static void ShowSelectTutorialWindow()
{
}
*/
static const Widget _select_game_widgets[] = {
{ WWT_CAPTION, 13, 0, 335, 0, 13, STR_0307_OPENTTD, STR_NULL},
{ WWT_IMGBTN, 13, 0, 335, 14, 196, 0x0, STR_NULL},
{ WWT_PUSHTXTBTN, 12, 10, 167, 22, 33, STR_0140_NEW_GAME, STR_02FB_START_A_NEW_GAME},
{ WWT_PUSHTXTBTN, 12, 168, 325, 22, 33, STR_0141_LOAD_GAME, STR_02FC_LOAD_A_SAVED_GAME_FROM},
//{ WWT_PUSHTXTBTN, 12, 10, 167, 177, 188, STR_0142_TUTORIAL_DEMONSTRATION, STR_02FD_VIEW_DEMONSTRATIONS_TUTORIALS},
{ WWT_PUSHTXTBTN, 12, 10, 167, 177, 188, STR_CONFIG_PATCHES, STR_CONFIG_PATCHES_TIP},
{ WWT_PUSHTXTBTN, 12, 10, 167, 40, 51, STR_0220_CREATE_SCENARIO,STR_02FE_CREATE_A_CUSTOMIZED_GAME},
{ WWT_PUSHTXTBTN, 12, 10, 167, 136, 147, STR_SINGLE_PLAYER, STR_02FF_SELECT_SINGLE_PLAYER_GAME},
{ WWT_PUSHTXTBTN, 12, 168, 325, 136, 147, STR_MULTIPLAYER, STR_0300_SELECT_TWO_PLAYER_GAME},
{ WWT_PUSHTXTBTN, 12, 10, 167, 159, 170, STR_0148_GAME_OPTIONS, STR_0301_DISPLAY_GAME_OPTIONS},
{ WWT_PUSHTXTBTN, 12, 168, 325, 159, 170, STR_01FE_DIFFICULTY, STR_0302_DISPLAY_DIFFICULTY_OPTIONS},
{ WWT_PUSHTXTBTN, 12, 168, 325, 40, 51, STR_029A_PLAY_SCENARIO, STR_0303_START_A_NEW_GAME_USING},
{ WWT_PUSHTXTBTN, 12, 168, 325, 177, 188, STR_0304_QUIT, STR_0305_LEAVE_OPENTTD},
{ WWT_PANEL_2, 12, 10, 85, 69, 122, 0x1312, STR_030E_SELECT_TEMPERATE_LANDSCAPE},
{ WWT_PANEL_2, 12, 90, 165, 69, 122, 0x1314, STR_030F_SELECT_SUB_ARCTIC_LANDSCAPE},
{ WWT_PANEL_2, 12, 170, 245, 69, 122, 0x1316, STR_0310_SELECT_SUB_TROPICAL_LANDSCAPE},
{ WWT_PANEL_2, 12, 250, 325, 69, 122, 0x1318, STR_0311_SELECT_TOYLAND_LANDSCAPE},
{ WIDGETS_END},
};
static void SelectGameWndProc(Window *w, WindowEvent *e) {
switch(e->event) {
case WE_PAINT:
w->click_state = (w->click_state & ~(0xC0) & ~(0xF << 12)) | (1 << (_new_opt.landscape+12)) | (!_networking?(1<<6):(1<<7));
w->disabled_state = _networking ? 0x30 : 0;
SET_DPARAM16(0, STR_6801_EASY + _new_opt.diff_level);
DrawWindowWidgets(w);
break;
case WE_CLICK:
switch(e->click.widget) {
case 2: DoCommandP(0, 0, 0, NULL, CMD_START_NEW_GAME); break;
case 3: ShowSaveLoadDialog(SLD_LOAD_GAME); break;
case 4: ShowPatchesSelection(); break;
case 5: DoCommandP(0, InteractiveRandom(), 0, NULL, CMD_CREATE_SCENARIO); break;
case 6:
if (_networking)
DoCommandP(0, 0, 0, NULL, CMD_SET_SINGLE_PLAYER);
break;
case 7:
if (!_network_available) {
ShowErrorMessage(-1,STR_NETWORK_ERR_NOTAVAILABLE, 0, 0);
} else {
ShowNetworkGameWindow();
ShowErrorMessage(-1, TEMP_STRING_NO_NETWORK, 0, 0);
}
break;
case 8: ShowGameOptions(); break;
case 9: ShowGameDifficulty(); break;
case 10:ShowSaveLoadDialog(SLD_LOAD_SCENARIO); break;
case 11:AskExitGame(); break;
case 12: case 13: case 14: case 15:
DoCommandP(0, e->click.widget - 12, 0, NULL, CMD_SET_NEW_LANDSCAPE_TYPE);
break;
}
case WE_KEYPRESS:
switch(e->keypress.keycode) {
case WKC_BACKQUOTE: IConsoleSwitch(); break;
}
break;
}
}
static const WindowDesc _select_game_desc = {
WDP_CENTER, WDP_CENTER, 336, 197,
WC_SELECT_GAME,0,
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
_select_game_widgets,
SelectGameWndProc
};
void ShowSelectGameWindow()
{
AllocateWindowDesc(&_select_game_desc);
}
// p1 = mode
// 0 - start new game
// 1 - close new game dialog
int32 CmdStartNewGame(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
if (!(flags & DC_EXEC))
return 0;
switch(p1) {
case 0: // show select game window
AskForNewGameToStart();
break;
case 1: // close select game window
DeleteWindowById(WC_SAVELOAD, 0);
break;
}
return 0;
}
int32 CmdGenRandomNewGame(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
if (!(flags & DC_EXEC))
return 0;
// this forces stuff into test mode.
_docommand_recursive = 0;
_random_seeds[0][0] = p1;
_random_seeds[0][1] = p2;
if (_networking) { NetworkStartSync(true); }
MakeNewGame();
return 0;
}
int32 CmdLoadGame(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
if (!(flags & DC_EXEC))
return 0;
// ShowSaveLoadDialog(0);
return 0;
}
int32 CmdCreateScenario(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
if (!(flags & DC_EXEC))
return 0;
_switch_mode = SM_EDITOR;
return 0;
}
int32 CmdSetSinglePlayer(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
printf("CmdSetSinglePlayer\n");
return 0;
}
int32 CmdStartScenario(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
if (!(flags & DC_EXEC))
return 0;
// this forces stuff into test mode.
_docommand_recursive = 0;
_random_seeds[0][0] = p1;
_random_seeds[0][1] = p2;
if (_networking) { NetworkStartSync(true); }
StartScenario();
return 0;
}
static const Widget _ask_abandon_game_widgets[] = {
{ WWT_TEXTBTN, 4, 0, 10, 0, 13, STR_00C5, STR_NULL},
{ WWT_CAPTION, 4, 11, 179, 0, 13, STR_00C7_QUIT, STR_NULL},
{ WWT_IMGBTN, 4, 0, 179, 14, 91, 0x0, STR_NULL},
{ WWT_TEXTBTN, 12, 25, 84, 72, 83, STR_00C9_NO, STR_NULL},
{ WWT_TEXTBTN, 12, 95, 154, 72, 83, STR_00C8_YES, STR_NULL},
{ WIDGETS_END},
};
static void AskAbandonGameWndProc(Window *w, WindowEvent *e) {
switch(e->event) {
case WE_PAINT:
DrawWindowWidgets(w);
#if defined(_WIN32)
SET_DPARAM16(0, STR_0133_WINDOWS);
#elif defined(__APPLE__)
SET_DPARAM16(0, STR_0135_OSX);
#elif defined(__BEOS__)
SET_DPARAM16(0, STR_OSNAME_BEOS);
#elif defined(__MORPHOS__)
SET_DPARAM16(0, STR_OSNAME_MORPHOS);
#else
SET_DPARAM16(0, STR_0134_UNIX);
#endif
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;
}
break;
case WE_KEYPRESS: /* Exit game on pressing 'Enter' */
if (e->keypress.keycode == WKC_RETURN)
_exit_game = true;
break;
}
}
static const WindowDesc _ask_abandon_game_desc = {
WDP_CENTER, WDP_CENTER, 180, 92,
WC_ASK_ABANDON_GAME,0,
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS,
_ask_abandon_game_widgets,
AskAbandonGameWndProc
};
void AskExitGame()
{
AllocateWindowDescFront(&_ask_abandon_game_desc, 0);
}
static const Widget _ask_quit_game_widgets[] = {
{ WWT_TEXTBTN, 4, 0, 10, 0, 13, STR_00C5, STR_NULL},
{ WWT_CAPTION, 4, 11, 179, 0, 13, STR_0161_QUIT_GAME, STR_NULL},
{ WWT_IMGBTN, 4, 0, 179, 14, 91, 0x0, STR_NULL},
{ WWT_TEXTBTN, 12, 25, 84, 72, 83, STR_00C9_NO, STR_NULL},
{ WWT_TEXTBTN, 12, 95, 154, 72, 83, STR_00C8_YES, STR_NULL},
{ WIDGETS_END},
};
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;
}
break;
}
}
static const WindowDesc _ask_quit_game_desc = {
WDP_CENTER, WDP_CENTER, 180, 92,
WC_QUIT_GAME,0,
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS,
_ask_quit_game_widgets,
AskQuitGameWndProc
};
void AskExitToGameMenu()
{
AllocateWindowDescFront(&_ask_quit_game_desc, 0);
}
int32 CmdSetNewLandscapeType(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
if (flags & DC_EXEC) {
// XXX: some stuff
_new_opt.landscape = p1;
InvalidateWindowClasses(WC_SELECT_GAME);
}
return 0;
}

View File

@@ -1,36 +0,0 @@
README
------------------------------------------------------------------------
All bugs listed below are marked as known. Please do not submit any bugs
that are the same as these. If you do, do not act surprised, because
we WILL flame you!!
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://bugs.openttd.org.
If the bug report is closed, it has been fixed, which then can be verified
in the latest SVN version of /trunk.
Bugs for 0.6.1
------------------------------------------------------------------------
URL: http://bugs.openttd.org
- 1944 Road vehicles not picking empty drivethrough platform
- 1923 Unique names not always enforced
- 1891 Go to depot for servicing is forgotten
- 1890 Airplanes copy helipcopters goto heliport order
- 1885 Almost all unserved industries die in big maps
- 1868 In depot, cannot move wagon from another line before first wagon in a wagon-only line
- 1858 Industry legend in small map overwrites buttons
- 1852 Minor tram reversing glitches
- 1802 Path with space in configure fails
- 1793 Inconsistent travel time for fast trains
- 1762 Strange Autoreplace behaviour
- 1752 User input is not checked
- 1693 Removing road does not reset owner
- 1473 Train not going to available platform
- 1404 Spinner widget interprets one click as many
- 1264 Autoreplace for multiple NewGRF DMU sets fails
- 1140 [OSX] Not smooth moving map with touchpad
- 1072 Text overflows in several windows
- 119 Clipping problems with vehicles on slopes

767
landscape.c Normal file
View File

@@ -0,0 +1,767 @@
#include "stdafx.h"
#include "ttd.h"
#include <stdarg.h>
#include "gfx.h"
#include "viewport.h"
#include "command.h"
#include "vehicle.h"
byte _map_type_and_height[TILES_X * TILES_Y];
byte _map5[TILES_X * TILES_Y];
byte _map3_lo[TILES_X * TILES_Y];
byte _map3_hi[TILES_X * TILES_Y];
byte _map_owner[TILES_X * TILES_Y];
byte _map2[TILES_X * TILES_Y];
byte _map_extra_bits[TILES_X * TILES_Y/4];
extern const TileTypeProcs
_tile_type_clear_procs,
_tile_type_rail_procs,
_tile_type_road_procs,
_tile_type_town_procs,
_tile_type_trees_procs,
_tile_type_station_procs,
_tile_type_water_procs,
_tile_type_dummy_procs,
_tile_type_industry_procs,
_tile_type_tunnelbridge_procs,
_tile_type_unmovable_procs;
const TileTypeProcs * const _tile_type_procs[16] = {
&_tile_type_clear_procs,
&_tile_type_rail_procs,
&_tile_type_road_procs,
&_tile_type_town_procs,
&_tile_type_trees_procs,
&_tile_type_station_procs,
&_tile_type_water_procs,
&_tile_type_dummy_procs,
&_tile_type_industry_procs,
&_tile_type_tunnelbridge_procs,
&_tile_type_unmovable_procs,
};
/* landscape slope => sprite */
const byte _tileh_to_sprite[32] = {
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,0,
0,0,0,0,0,0,0,16,0,0,0,17,0,15,18,0,
};
uint GetTileSlope(uint tile, int *h)
{
uint a,b,c,d,min;
int r;
if (GET_TILE_X(tile) == TILE_X_MAX || GET_TILE_Y(tile) == TILE_Y_MAX) {
if (h)
*h = 0;
return 0;
}
assert(tile < TILES_X * TILES_Y && GET_TILE_X(tile) != TILE_X_MAX && GET_TILE_Y(tile) != TILE_Y_MAX);
min = a = _map_type_and_height[tile] & 0xF;
b = _map_type_and_height[tile+TILE_XY(1,0)] & 0xF;
if (min >= b) min = b;
c = _map_type_and_height[tile+TILE_XY(0,1)] & 0xF;
if (min >= c) min = c;
d = _map_type_and_height[tile+TILE_XY(1,1)] & 0xF;
if (min >= d) min = d;
r = 0;
if ((a-=min)!=0) { r += (--a << 4) + 8; }
if ((c-=min)!=0) { r += (--c << 4) + 4; }
if ((d-=min)!=0) { r += (--d << 4) + 2; }
if ((b-=min)!=0) { r += (--b << 4) + 1; }
if (h != 0)
*h = min * 8;
return r;
}
int GetTileZ(uint tile)
{
int h;
GetTileSlope(tile, &h);
return h;
}
void FindLandscapeHeightByTile(TileInfo *ti, uint tile)
{
if (GET_TILE_X(tile) == TILE_X_MAX ||
GET_TILE_Y(tile) == TILE_Y_MAX) {
ti->tileh = 0;
ti->type = MP_STRANGE;
ti->tile = 0;
ti->map5 = 0;
ti->z = 0;
return;
}
ti->tile = tile;
ti->map5 = _map5[tile];
ti->type = GET_TILETYPE(tile);
ti->tileh = GetTileSlope(tile, &ti->z);
// ti->z = min * 8;
}
/* find the landscape height for the coordinates x y */
void FindLandscapeHeight(TileInfo *ti, uint x, uint y)
{
int tile;
ti->x = x;
ti->y = y;
if (x >= TILE_X_MAX*16-1 || y >= TILE_Y_MAX*16-1) {
ti->tileh = 0;
ti->type = MP_STRANGE;
ti->tile = 0;
ti->map5 = 0;
ti->z = 0;
return;
}
tile = TILE_FROM_XY(x,y);
FindLandscapeHeightByTile(ti, tile);
}
uint GetPartialZ(int x, int y, int corners)
{
int z = 0;
switch(corners) {
case 1:
if (x - y >= 0)
z = (x - y) >> 1;
break;
case 2:
y^=0xF;
if ( (x - y) >= 0)
z = (x - y) >> 1;
break;
case 3:
z = (x>>1) + 1;
break;
case 4:
if (y - x >= 0)
z = (y - x) >> 1;
break;
case 5:
case 10:
case 15:
z = 4;
break;
case 6:
z = (y>>1) + 1;
break;
case 7:
z = 8;
y^=0xF;
if (x - y < 0)
z += (x - y) >> 1;
break;
case 8:
y ^= 0xF;
if (y - x >= 0)
z = (y - x) >> 1;
break;
case 9:
z = (y^0xF)>>1;
break;
case 11:
z = 8;
if (x - y < 0)
z += (x - y) >> 1;
break;
case 12:
z = (x^0xF)>>1;
break;
case 13:
z = 8;
y ^= 0xF;
if (y - x < 0)
z += (y - x) >> 1;
break;
case 14:
z = 8;
if (y - x < 0)
z += (y - x) >> 1;
break;
case 23:
z = 1 + ((x+y)>>1);
break;
case 27:
z = 1 + ((x+(y^0xF))>>1);
break;
case 29:
z = 1 + (((x^0xF)+(y^0xF))>>1);
break;
case 30:
z = 1 + (((x^0xF)+(y^0xF))>>1);
break;
}
return z;
}
uint GetSlopeZ(int x, int y)
{
TileInfo ti;
// int z;
FindLandscapeHeight(&ti, x, y);
/*
z = ti.z;
x &= 0xF;
y &= 0xF;
assert(z < 256);
*/
return _tile_type_procs[ti.type]->get_slope_z_proc(&ti);
}
// direction=true: check for foundation in east and south corner
// direction=false: check for foundation in west and south corner
bool hasFoundation(TileInfo *ti, bool direction)
{
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;
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;
}
void DrawFoundation(TileInfo *ti, uint f)
{
uint32 sprite_base = SPR_SLOPES_BASE-14;
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 = 990; // use original slope sprites
AddSortableSpriteToDraw(f-1 + sprite_base, ti->x, ti->y, 16, 16, 7, ti->z);
ti->z += 8;
ti->tileh = 0;
OffsetGroundSprite(31, 1);
} else {
// inclined foundation
sprite_base += 14;
AddSortableSpriteToDraw(
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
);
ti->tileh = _inclined_tileh[f - 15];
OffsetGroundSprite(31, 9);
}
}
void DoClearSquare(uint tile)
{
ModifyTile(tile,
MP_SETTYPE(MP_CLEAR) |
MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR | MP_MAPOWNER | MP_MAP5,
OWNER_NONE, /* map_owner */
_generating_world ? 3 : 0 /* map5 */
);
}
uint32 GetTileTrackStatus(uint tile, TransportType mode)
{
return _tile_type_procs[GET_TILETYPE(tile)]->get_tile_track_status_proc(tile, mode);
}
void ChangeTileOwner(uint tile, byte old_player, byte new_player)
{
_tile_type_procs[GET_TILETYPE(tile)]->change_tile_owner_proc(tile, old_player, new_player);
}
void GetAcceptedCargo(uint tile, AcceptedCargo *ac)
{
memset(ac, 0, sizeof(AcceptedCargo));
_tile_type_procs[GET_TILETYPE(tile)]->get_accepted_cargo_proc(tile, ac);
}
void AnimateTile(uint tile)
{
_tile_type_procs[GET_TILETYPE(tile)]->animate_tile_proc(tile);
}
void ClickTile(uint tile)
{
_tile_type_procs[GET_TILETYPE(tile)]->click_tile_proc(tile);
}
void DrawTile(TileInfo *ti)
{
_tile_type_procs[ti->type]->draw_tile_proc(ti);
}
void GetTileDesc(uint tile, TileDesc *td)
{
_tile_type_procs[GET_TILETYPE(tile)]->get_tile_desc_proc(tile, td);
}
/* Clear a piece of landscape
* p1 = 0,
* p2 = 0
*/
int32 CmdLandscapeClear(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
uint tile;
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
tile = TILE_FROM_XY(x,y);
return _tile_type_procs[GET_TILETYPE(tile)]->clear_tile_proc(tile, flags);
}
// p1 = end tile
int32 CmdClearArea(int ex, int ey, uint32 flags, uint32 p1, uint32 p2)
{
int32 cost,ret, money;
int sx,sy;
int x,y;
bool success = false;
// make sure sx,sy are smaller than ex,ey
sx = GET_TILE_X(p1)*16;
sy = GET_TILE_Y(p1)*16;
if (ex < sx) intswap(ex, sx);
if (ey < sy) intswap(ey, sy);
money = GetAvailableMoneyForCommand();
cost = 0;
for(x=sx; x<=ex; x+=16) {
for(y=sy; y<=ey; y+=16) {
ret = DoCommandByTile(TILE_FROM_XY(x,y), 0, 0, flags &~DC_EXEC, CMD_LANDSCAPE_CLEAR);
if (ret == CMD_ERROR) continue;
cost += ret;
success = true;
if (flags & DC_EXEC) {
if ( ret>0 && (money -= ret) < 0) {
_additional_cash_required = ret;
return cost - ret;
}
DoCommandByTile(TILE_FROM_XY(x,y), 0, 0, flags, CMD_LANDSCAPE_CLEAR);
// draw explosion animation...
if ((x==sx || x==ex) && (y==sy || y==ey)) {
// big explosion in each corner, or small explosion for single tiles
CreateEffectVehicleAbove(x + 8,y + 8, 2, sy==ey && sx==ex ? EV_DEMOLISH : EV_CRASHED_SMOKE);
}
}
}
}
if (!success)
cost = CMD_ERROR;
return cost;
}
/* utility function used to modify a tile */
void CDECL ModifyTile(uint tile, uint flags, ...)
{
va_list va;
int i;
va_start(va, flags);
if ((i = (flags >> 8) & 0xF) != 0) {
_map_type_and_height[tile] = (_map_type_and_height[tile]&~0xF0)|((i-1) << 4);
}
if (flags & (MP_MAP2_CLEAR | MP_MAP2)) {
int x = 0;
if (flags & MP_MAP2) x = va_arg(va, int);
_map2[tile] = x;
}
if (flags & (MP_MAP3LO_CLEAR | MP_MAP3LO)) {
int x = 0;
if (flags & MP_MAP3LO) x = va_arg(va, int);
_map3_lo[tile] = x;
}
if (flags & (MP_MAP3HI_CLEAR | MP_MAP3HI)) {
int x = 0;
if (flags & MP_MAP3HI) x = va_arg(va, int);
_map3_hi[tile] = x;
}
if (flags & (MP_MAPOWNER|MP_MAPOWNER_CURRENT)) {
byte x = _current_player;
if (flags & MP_MAPOWNER) x = va_arg(va, int);
_map_owner[tile] = x;
}
if (flags & MP_MAP5) {
_map5[tile] = va_arg(va, int);
}
va_end(va);
if (!(flags & MP_NODIRTY))
MarkTileDirtyByTile(tile);
}
void SetMapExtraBits(uint tile, byte bits)
{
_map_extra_bits[tile >> 2] &= ~(3 << ((tile&3)*2));
_map_extra_bits[tile >> 2] |= (bits&3) << ((tile&3)*2);
}
uint GetMapExtraBits(uint tile)
{
return (_map_extra_bits[tile >> 2] >> (tile&3)*2)&3;
}
#define TILELOOP_BITS 4
#define TILELOOP_SIZE (1 << TILELOOP_BITS)
#define TILELOOP_ASSERTMASK ((TILELOOP_SIZE-1) + ((TILELOOP_SIZE-1) << TILE_X_BITS))
#define TILELOOP_CHKMASK (((1 << (TILE_X_BITS - TILELOOP_BITS))-1) << TILELOOP_BITS)
void RunTileLoop()
{
uint tile;
uint count;
tile = _cur_tileloop_tile;
assert( (tile & ~TILELOOP_ASSERTMASK) == 0);
count = (TILES_X/TILELOOP_SIZE) * (TILES_Y/TILELOOP_SIZE);
do {
_tile_type_procs[GET_TILETYPE(tile)]->tile_loop_proc(tile);
if ( GET_TILE_X(tile) < TILES_X - TILELOOP_SIZE) {
tile += TILELOOP_SIZE; /* no overflow */
} else {
tile = TILE_MASK(tile - TILELOOP_SIZE * (TILES_X/TILELOOP_SIZE-1) + TILE_XY(0, TILELOOP_SIZE)); /* x would overflow, also increase y */
}
} while (--count);
assert( (tile & ~TILELOOP_ASSERTMASK) == 0);
tile += 9;
if (tile & TILELOOP_CHKMASK)
tile = (tile + TILES_X) & TILELOOP_ASSERTMASK;
_cur_tileloop_tile = tile;
}
void InitializeLandscape()
{
int i;
memset(_map_owner, OWNER_NONE, sizeof(_map_owner));
memset(_map2, 0, sizeof(_map2));
memset(_map3_lo, 0, sizeof(_map3_lo));
memset(_map3_hi, 0, sizeof(_map3_hi));
memset(_map_extra_bits, 0, sizeof(_map_extra_bits));
memset(_map_type_and_height, MP_WATER << 4, sizeof(_map_type_and_height));
for(i=0; i!=TILES_Y-1; i++)
memset(_map_type_and_height + i*TILES_X, 0, TILES_X-1);
memset(_map5, 3, sizeof(_map5));
}
void ConvertGroundTilesIntoWaterTiles()
{
uint tile = 0;
int h;
while(true) {
if (IS_TILETYPE(tile, MP_CLEAR) && GetTileSlope(tile, &h) == 0 && h == 0) {
_map_type_and_height[tile] = MP_WATER << 4;
_map5[tile] = 0;
_map_owner[tile] = OWNER_WATER;
}
tile++;
if (GET_TILE_X(tile) == TILE_X_MAX) {
tile += TILE_XY(-TILE_X_MAX, 1);
if (GET_TILE_Y(tile) == TILE_Y_MAX)
break;
}
}
}
static const byte _genterrain_tbl_1[5] = { 10, 22, 33, 37, 4 };
static const byte _genterrain_tbl_2[5] = { 0, 0, 0, 0, 33 };
static void GenerateTerrain(int type, int flag)
{
uint32 r;
int x,y;
int w,h;
byte *p,*tile;
byte direction;
r = Random();
p = GetSpritePtr((((r >> 24) * _genterrain_tbl_1[type]) >> 8) + _genterrain_tbl_2[type] + 4845);
x = r & TILE_X_MAX;
y = (r >> TILE_X_BITS) & TILE_Y_MAX;
if (x < 2 || y < 2)
return;
direction = (byte)(r >> 22) & 3;
w = p[2];
h = p[1];
if (direction & 1) { w = p[1]; h = p[2]; }
p += 8;
if (flag & 4) {
if (!(flag & 2)) {
if (!(flag & 1)) {
if (x + y > 190)
return;
} else {
if (y < 30 + x)
return;
}
} else {
if (!(flag & 1)) {
if (x + y < 256)
return;
} else {
if (x < 30 + y)
return;
}
}
}
if (x + w >= TILE_X_MAX-1)
return;
if (y + h >= TILE_Y_MAX-1)
return;
tile = &_map_type_and_height[TILE_XY(x,y)];
if (direction == 0) {
do {
int w_cur = w;
byte *tile_cur = tile;
do {
if (*p >= *tile_cur) *tile_cur = *p;
p++;
tile_cur++;
} while (--w_cur != 0);
tile += TILE_XY(0,1);
} while (--h != 0);
} else if (direction == 1) {
do {
int h_cur = h;
byte *tile_cur = tile;
do {
if (*p >= *tile_cur) *tile_cur = *p;
p++;
tile_cur+=TILE_XY(0,1);
} while (--h_cur != 0);
tile++;
} while (--w != 0);
} else if (direction == 2) {
tile += w - 1;
do {
int w_cur = w;
byte *tile_cur = tile;
do {
if (*p >= *tile_cur) *tile_cur = *p;
p++;
tile_cur--;
} while (--w_cur != 0);
tile += TILE_XY(0,1);
} while (--h != 0);
} else {
tile += (h - 1) * TILE_XY(0,1);
do {
int h_cur = h;
byte *tile_cur = tile;
do {
if (*p >= *tile_cur) *tile_cur = *p;
p++;
tile_cur-=TILE_XY(0,1);
} while (--h_cur != 0);
tile++;
} while (--w != 0);
}
}
#include "table/genland.h"
static void CreateDesertOrRainForest()
{
uint tile;
const TileIndexDiff *data;
byte mt;
int i;
tile = 0;
do {
data = _make_desert_or_rainforest_data;
do {
if ((i = *data++) == MDORD_LAST) {
SetMapExtraBits(tile, 1);
break;
}
mt = _map_type_and_height[TILE_MASK(tile + i)];
} while ((mt & 0xC) == 0 && (mt >> 4) != MP_WATER);
} while (++tile != TILES_X*TILES_Y);
for(i=0; i!=256; i++)
RunTileLoop();
tile = 0;
do {
data = _make_desert_or_rainforest_data;
do {
if ((i = *data++) == MDORD_LAST) {
SetMapExtraBits(tile, 2);
break;
}
} while ( !IS_TILETYPE(TILE_MASK(tile+i), MP_CLEAR) || (_map5[TILE_MASK(tile + i)]&0x1C) != 0x14);
} while (++tile != TILES_X*TILES_Y);
}
void GenerateLandscape()
{
int i,flag;
uint32 r;
if (_opt.landscape == LT_HILLY) {
i = ((Random() & 0x7F) + 950) * LANDSCAPE_SIZE_FACTOR;
do {
GenerateTerrain(2, 0);
} while (--i);
r = Random();
flag = (r & 3) | 4;
i = (((r >> 16) & 0x7F) + 450) * LANDSCAPE_SIZE_FACTOR;
do {
GenerateTerrain(4, flag);
} while (--i);
} else if (_opt.landscape == LT_DESERT) {
i = ((Random()&0x7F) + 170) * LANDSCAPE_SIZE_FACTOR;
do {
GenerateTerrain(0, 0);
} while (--i);
r = Random();
flag = (r & 3) | 4;
i = (((r >> 16) & 0xFF) + 1700) * LANDSCAPE_SIZE_FACTOR;
do {
GenerateTerrain(0, flag);
} while (--i);
flag ^= 2;
i = ((Random() & 0x7F) + 410) * LANDSCAPE_SIZE_FACTOR;
do {
GenerateTerrain(3, flag);
} while (--i);
} else {
i = ((Random() & 0x7F) + (3 - _opt.diff.quantity_sea_lakes)*256 + 100) * LANDSCAPE_SIZE_FACTOR;
do {
GenerateTerrain(_opt.diff.terrain_type, 0);
} while (--i);
}
ConvertGroundTilesIntoWaterTiles();
if (_opt.landscape == LT_DESERT)
CreateDesertOrRainForest();
}
void OnTick_Town();
void OnTick_Trees();
void OnTick_Station();
void OnTick_Industry();
void OnTick_Players();
void OnTick_Train();
void CallLandscapeTick()
{
OnTick_Town();
OnTick_Trees();
OnTick_Station();
OnTick_Industry();
OnTick_Players();
OnTick_Train();
}
TileIndex AdjustTileCoordRandomly(TileIndex a, byte rng)
{
int rn = rng;
uint32 r = Random();
return TILE_XY(
GET_TILE_X(a) + ((byte)r * rn * 2 >> 8) - rn,
GET_TILE_Y(a) + ((byte)(r>>8) * rn * 2 >> 8) - rn
);
}
// This function checks if we add addx/addy to tile, if we
// do wrap around the edges. For example, tile = (10,2) and
// addx = +3 and addy = -4. This function will now return
// TILE_WRAPPED, because the y is wrapped. This is needed in
// for example, farmland. When the tile is not wrapped,
// the result will be tile + TILE_XY(addx, addy)
uint TileAddWrap(TileIndex tile, int addx, int addy)
{
int x, y;
x = GET_TILE_X(tile) + addx;
y = GET_TILE_Y(tile) + addy;
// Are we about to wrap?
if (x > 0 && x < TILE_X_MAX && y > 0 && y < TILE_Y_MAX)
return tile + TILE_XY(addx, addy);
return TILE_WRAPPED;
}
bool IsValidTile(uint tile)
{
return (tile < TILES_X * TILE_Y_MAX && GET_TILE_X(tile) != TILE_X_MAX);
}

2592
lang/american.txt Normal file

File diff suppressed because it is too large Load Diff

2592
lang/czech.txt Normal file

File diff suppressed because it is too large Load Diff

2426
lang/danish.txt Normal file

File diff suppressed because it is too large Load Diff

2110
lang/dutch.txt Normal file

File diff suppressed because it is too large Load Diff

2592
lang/english.txt Normal file

File diff suppressed because it is too large Load Diff

2592
lang/finnish.txt Normal file

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