Changeset - r222:4409829eb08f
[Not reviewed]
master
1 39 0
darkvater - 20 years ago 2004-09-12 21:49:38
darkvater@openttd.org
(svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
-CodeLayout: Remove trailing spaces and Windows linebreaks
40 files changed with 717 insertions and 721 deletions:
0 comments (0 inline, 0 general)
Jamfile.next
Show inline comments
 
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 
 
	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;
 

	
 
####################
 
# 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 $(<) $(>) 
 
	$(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 ;	
 
	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) ;
 

	
Makefile
Show inline comments
 
@@ -38,54 +38,54 @@
 
# 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. 
 
# 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. 
 
# 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. 
 
# 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
 
@@ -113,56 +113,56 @@ ifneq ($(MAKEFILE_VERSION),$(CONFIG_VERS
 
		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 
 
VERBOSE_FILTER =  >/dev/null 2>&1
 
else
 
VERBOSE_FILTER = 
 
VERBOSE_FILTER =
 
endif
 

	
 
ifdef DISPLAY_WARNINGS
 
WARNING_DISPLAY:=-fstrict-aliasing
 
VERBOSE_FILTER =  
 
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
 
@@ -496,87 +496,87 @@ 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 
 
	@# 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}') © 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:
 
@@ -600,49 +600,49 @@ install:
 
	@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) $<'; \
airport.c
Show inline comments
 
@@ -67,49 +67,49 @@ static void AirportFTAClass_Constructor(
 
	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 = (uint16*)depots;
 
	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;
 

	
airport.h
Show inline comments
 
@@ -4,49 +4,49 @@
 
#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
 
	uint16 *airport_depots;			// gives the position of the depots on the airports
 
	struct AirportFTA *layout;	// state machine for airport
 
	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 */
changelog.txt
Show inline comments
 
0.3.3 (2004-07-13)
 
------------------------------------------------------------------------
 

	
 
- Feature: (MorphOS/AmigaOS) network support
 
- Feature: improved german town name generator
 
- Change: scenarios now have the file extension .scn
 
- Fix: removing and upgrading tracks under a bridge when a train is on the bridge
 
- Change: default network port from 12345 (known trojan) to 3979 
 
- Change: default network port from 12345 (known trojan) to 3979
 
- Fix: pause button was not synched in network games
 
- Fix: crash caused by invalid screen resolutions
 
- Fix: AI can not build tubular bridges in 1950, etc. Same restrictions apply to it, as to human players.
 
- Feature: transparent station signs
 
- Feature: show total cargo per wagon type in train details window
 
- Fix: volume, liters, was x100, should be x1000
 
- Feature: bridges on slopes
 
- Fix: bridge building by towns was screwed when executed without testing first
 
- Feature: added Galician translation (by Condex)
 
- Change: crossing tunnels is now considered a cheat
 
- Fix: better AI route finding
 
- Fix: AI builds less inner-city bus stations
 
- Fix: Better industry spreading on random maps
 
- Fix: Two industries that accept the same goods can never be very close to each other
 
- Feature: Extra dynamite, allow the removal of town-owned roads, bridges, tunnels for a popularity rating penalty
 
- Feature: magic bulldozer cheat, that lets you remove industries, unmovables and town-owned buildings, roads and bridges
 
- Fix: destroying bridge (over water or 'higher bridge' with vehicle on it)
 
- Fix Game crashes when you hit the build rail button
 
- Fix: some scenarios had a max_railtype of 0
 
- Fix: Bribe Autorithy. A failed attempt to bribe is now also stored in savegame
 
- Fix: 80% CPU load paused in fast-forward
 
- Feature: Enabled 'remove' button for stations
 
- Feature: Cheat GUI (activate with crtl-alt-c) The game remembers if you have used a cheat
 
- Fix: Some airport runways were treated 
 
- Fix: Some airport runways were treated
 
- Fix: minor minimap glitch
 
- Fix: station sorting scroll fails with not ennough stations
 
- Fix: desert ground for depots in the desert
 
- Feature: station sort implemented using qsort()
 
- Feature: station list shows #of stations owned by player
 
- Fix: trains could run on wrong track type under bridges
 
- Fix: screenshot hangs
 
- Feature: split canal/lock tool in two tools, one for building canals, one for locks.
 
- Fix: wrong sound with ships
 
- Fix: toy shop closes even though it has supply
 
- Fix: nordic characters
 
- Feature: make the HQ generate passengers and mail
 
- Fix: slso restore Service Interval when rebuying vehicle
 
- Fix: crash with map bits > 8
 
- Fix: ufo crash in busstop
 
- Fix: town actions has empty row
 
- Change: made helicopters able to land on small airports again
 
- Feature: display number of houses in town overview window
 
- Fix: train stuck with the head in one depot and tail in another
 
- Fix: Optimized random radio tower spreading
 
- Feature: Land info now shows type of signal
 
- Fix: ground below trees is sometimes not covered by snow
 
- Fix: fast forward button in scenario editor
 
- Change: screenshots are saved to PERSONAL_DIR (unix)
 
- Fix: screenshot hotkey does not function in scenario editor
 
- Fix: allow deleting a bridge if a vehicle is below
 
- Fix: crash loading a scenario
 
- Fix: build tracks on water
 
- Fix: fast forward button pressed with tab 
 
- Fix: fast forward button pressed with tab
 
- Fix: vehicles don't get old
 
- Feature: realistic train reversing
 
- Feature: added support for 64 bit CPUs
 
- Fix: finance bug with some original scenarios
 
- Feature: added water quantity level "very low", which is the default for easy mode now
 
- Fix: 'Stopped' is shown when train is stopping and 'Reverse' is clicked
 
- Feature: realistic acceleration turned on, train must first slow down and stop before it can reverse
 
- Feature: (MorphOS build) various small improvement to make the the game feel more native
 
- Feature: alt + f now toggles full screen (alt + enter still works)
 
- Feature: (OSX build) command + q shows the quit window and command + f or enter toggles full screen (alt and control still works too)
 
- Feature: pasky's autorenew, autorenews vehicles if enabled.
 
- Feature: (incomplete) news history window
 
- Feature: larger smallmap size
 
- Feature: Austrian Citynames
 
- Feature: repaying most possible debt
 
- Feature: added Polish translation (by tomek)
 
- Feature: added Danish translation (by Gof.dk)
 
- Feature: pasky's grfspecial loader. You have to enable them in openttd.cfg using [newgrf] setting
 
- Feature: smooth economy changes
 
- Fix: 100% CPU bug
 
- Fix: crash when AI builds airport
 
- Fix: plays wrong music on main screen
 
- Fix: inflation was way too high when intrest rate = 0
 
- Fix: can't sell anything if money is TOO negative
console.c
Show inline comments
 
@@ -186,51 +186,51 @@ void IConsoleInit()
 
	#if defined(WITH_REV)
 
	extern char _openttd_revision[];
 
	#endif
 
	_iconsole_color_default = 1;
 
	_iconsole_color_error = 3;
 
	_iconsole_color_debug = 5;
 
	_iconsole_color_commands = 2;
 
	_iconsole_scroll=79;
 
	_iconsole_cmdbufferpos=19;
 
	_iconsole_inited=true;
 
	_iconsole_mode=ICONSOLE_CLOSED;
 
	_iconsole_win=NULL;
 
	_icursor_state=false;
 
	_icursor_rate=5;
 
	_icursor_counter=0;
 
	for (i=0;i<20;i++) {
 
		_iconsole_cmdbuffer[i]=NULL;
 
		}
 
	for (i=0;i<80;i++) {
 
		_iconsole_buffer[i]=NULL;
 
		_iconsole_cbuffer[i]=0;
 
		}
 
	IConsoleStdLibRegister();
 
	#if defined(WITH_REV)
 
	IConsolePrintF(13,"OpenTTD Game Console Revision 3 - %s",_openttd_revision);
 
	IConsolePrintF(13,"OpenTTD Game Console Revision 4 - %s",_openttd_revision);
 
	#else
 
	IConsolePrint(13,"OpenTTD Game Console Revision 3");
 
	IConsolePrint(13,"OpenTTD Game Console Revision 4");
 
	#endif
 
	IConsolePrint(12,"---------------------------------");
 
	IConsolePrint(12,"use \"help\" for more info");
 
	IConsolePrint(12,"");
 
	IConsoleClearCommand();
 
	IConsoleCmdBufferAdd("");
 
}
 

	
 
void IConsoleClear()
 
{
 
	int i;
 
	for (i=0;i<80;i++) if (_iconsole_buffer[i]!=NULL) {
 
		free(_iconsole_buffer[i]);
 
		}
 
}
 

	
 
void IConsoleFree()
 
{
 
	_iconsole_inited=false;
 
	IConsoleClear();
 
}
 

	
 
void IConsoleResize()
 
{
 
@@ -248,254 +248,254 @@ void IConsoleSwitch()
 
		_iconsole_win->width= _screen.width;
 
		_iconsole_mode=ICONSOLE_OPENED;
 
		} else
 
	if (_iconsole_mode==ICONSOLE_OPENED) {
 
		DeleteWindowById(WC_CONSOLE,0);
 
		_iconsole_win=NULL;
 
		_iconsole_mode=ICONSOLE_CLOSED;
 
		}
 
	MarkWholeScreenDirty();
 
	MarkAllViewportsDirty(0,0,_screen.width,_screen.height);
 
	_video_driver->make_dirty(0,0,_screen.width,_screen.height);
 
}
 

	
 
void IConsoleClose()
 
{
 
	if (_iconsole_mode==ICONSOLE_OPENED)  IConsoleSwitch();
 
	_iconsole_mode=ICONSOLE_CLOSED;
 
}
 

	
 
void IConsoleOpen()
 
{
 
	if (_iconsole_mode==ICONSOLE_CLOSED) IConsoleSwitch();
 
}
 

	
 
void IConsoleCmdBufferAdd(byte * cmd)
 
void IConsoleCmdBufferAdd(const byte * cmd)
 
{
 
	int i;
 
	if (_iconsole_cmdbufferpos != 19) return;
 
	if (_iconsole_cmdbuffer[18]!=NULL) free(_iconsole_cmdbuffer[18]);
 
	for (i=18; i>0; i--) _iconsole_cmdbuffer[i]=_iconsole_cmdbuffer[i-1];
 
	i=strlen((char *)cmd);
 
	i=strlen(cmd);
 
	_iconsole_cmdbuffer[0]=malloc(i+1);
 
	memset(((void *)_iconsole_cmdbuffer[0]),0,i+1);
 
	memcpy(((void *)_iconsole_cmdbuffer[0]),(void *)cmd,i);
 
	memcpy(((void *)_iconsole_cmdbuffer[0]),cmd,i);
 
	_iconsole_cmdbuffer[0][i]=0;
 
	_iconsole_cmdbufferpos = 19;
 
}
 

	
 
void IConsoleCmdBufferNavigate(signed char direction)
 
{
 
	int i;
 
	i=_iconsole_cmdbufferpos + direction;
 
	if (i<0) i=19;
 
	if (i>19) i=0;
 
	if (direction>0) while (_iconsole_cmdbuffer[i]==NULL) {
 
		i++;
 
		if (i>19) i=0;
 
		}
 
	if (direction<0) while (_iconsole_cmdbuffer[i]==NULL) {
 
		i--;
 
		if (i<0) i=19;
 
		}
 
	_iconsole_cmdbufferpos = i;
 
	IConsoleClearCommand();
 
	memcpy((void *)_iconsole_cmdline,(void *)_iconsole_cmdbuffer[i],strlen(_iconsole_cmdbuffer[i]));
 
	_iconsole_cmdpos =strlen(_iconsole_cmdbuffer[i]);
 
}
 

	
 
void IConsolePrint(byte color_code, byte* string)
 
void IConsolePrint(byte color_code, const byte* string)
 
{
 
	byte * _ex;
 
	byte * _new;
 
	byte _exc;
 
	byte _newc;
 
	int i,j;
 

	
 
	if (!_iconsole_inited) return;
 

	
 
	_newc=color_code;
 
	i=strlen((char *)string);
 
	i=strlen(string);
 
	_new=malloc(i+1);
 
	memset(_new,0,i+1);
 
	memcpy(_new,string,i);
 

	
 
	for (j=0;j<i;j++) {
 
		if (_new[j]<0x1F) _new[j]=0x20;
 
		}
 

	
 
	i=79;
 
	while (i>=0) {
 
		_ex=_iconsole_buffer[i];
 
		_exc=_iconsole_cbuffer[i];
 
		_iconsole_buffer[i]=_new;
 
		_iconsole_cbuffer[i]=_newc;
 
		_new=_ex;
 
		_newc=_exc;
 
		i--;
 
		}
 
	if (_ex!=NULL) free(_ex);
 

	
 
	if (_iconsole_win!=NULL) SetWindowDirty(_iconsole_win);
 
}
 

	
 

	
 
void CDECL IConsolePrintF(byte color_code, const char *s, ...)
 
{
 
	va_list va;
 
	char buf[1024];
 
	va_start(va, s);
 
	vsprintf(buf, s, va);
 
	va_end(va);
 
	IConsolePrint(color_code, (byte *) &buf);
 
}
 

	
 
void IConsoleDebug(byte* string)
 
{
 
	if (_stdlib_developer>1) IConsolePrintF(_iconsole_color_debug, "DEBUG: %s", string);
 
}
 

	
 
void IConsoleError(byte* string)
 
void IConsoleError(const byte* string)
 
{
 
	if (_stdlib_developer>0) IConsolePrintF(_iconsole_color_error, "ERROR: %s", string);
 
}
 

	
 
void IConsoleCmdRegister(byte * name, void * addr)
 
void IConsoleCmdRegister(const byte * name, void * addr)
 
{
 
	byte * _new;
 
	_iconsole_cmd * item;
 
	_iconsole_cmd * item_new;
 
	int i;
 

	
 
		i=strlen((char *)name);
 
		_new=malloc(i+1);
 
		memset(_new,0,i+1);
 
		memcpy(_new,name,i);
 
	i=strlen(name);
 
	_new=malloc(i+1);
 
	memset(_new,0,i+1);
 
	memcpy(_new,name,i);
 

	
 
	item_new = malloc(sizeof(_iconsole_cmd));
 

	
 
	item_new->_next = NULL;
 
	item_new->addr  = addr;
 
	item_new->name  = _new;
 

	
 
	item_new->hook_access = NULL;
 
	item_new->hook_after_exec = NULL;
 
	item_new->hook_before_exec = NULL;
 

	
 
	item = _iconsole_cmds;
 
	if (item == NULL) {
 
		_iconsole_cmds = item_new;
 
		} else {
 
		while (item->_next != NULL) { item = item->_next; };
 
		item->_next = item_new;
 
		}
 
}
 

	
 
void* IConsoleCmdGet(byte * name)
 
void* IConsoleCmdGet(const byte * name)
 
{
 
	_iconsole_cmd * item;
 

	
 
	item = _iconsole_cmds;
 
	while (item != NULL) {
 
		if (strcmp(item->name,name)==0) return item;
 
		item = item->_next;
 
		}
 
	return NULL;
 
}
 

	
 
void IConsoleVarRegister(byte * name, void * addr, byte type)
 
void IConsoleVarRegister(const byte * name, void * addr, byte type)
 
{
 
	byte * _new;
 
	_iconsole_var * item;
 
	_iconsole_var * item_new;
 
	int i;
 

	
 
		i=strlen((char *)name)+1;
 
		_new=malloc(i+1);
 
		memset(_new,0,i+1);
 
		_new[0]='*';
 
		memcpy(_new+1,name,i);
 
	i=strlen(name)+1;
 
	_new=malloc(i+1);
 
	memset(_new,0,i+1);
 
	_new[0]='*';
 
	memcpy(_new+1,name,i);
 

	
 
	item_new = malloc(sizeof(_iconsole_var));
 

	
 
	item_new->_next = NULL;
 
	item_new->addr  = addr;
 
	item_new->name  = _new;
 
	item_new->type  = type;
 
	item_new->_malloc = false;
 

	
 
	item_new->hook_access = NULL;
 
	item_new->hook_after_change = NULL;
 
	item_new->hook_before_change = NULL;
 

	
 
	item = _iconsole_vars;
 
	if (item == NULL) {
 
		_iconsole_vars = item_new;
 
		} else {
 
		while (item->_next != NULL) { item = item->_next; };
 
		item->_next = item_new;
 
		}
 
}
 

	
 
void IConsoleVarMemRegister(byte * name, byte type)
 
void IConsoleVarMemRegister(byte * name, byte type) /* XXX TRON */
 
{
 
	_iconsole_var * item;
 
	item = IConsoleVarAlloc(type);
 
	IConsoleVarInsert(item,name);
 
}
 

	
 

	
 
void IConsoleVarInsert(_iconsole_var * var, byte * name)
 
void IConsoleVarInsert(_iconsole_var * var, const byte * name)
 
{
 
	byte * _new;
 
	_iconsole_var * item;
 
	_iconsole_var * item_new;
 
	int i;
 

	
 
	item_new = var;
 

	
 
	// dont allow to build variable rings
 
	if (item_new->_next != NULL) return;
 

	
 
		i=strlen((char *)name)+1;
 
		_new=malloc(i+1);
 
		memset(_new,0,i+1);
 
		_new[0]='*';
 
		memcpy(_new+1,name,i);
 
	i=strlen(name)+1;
 
	_new=malloc(i+1);
 
	memset(_new,0,i+1);
 
	_new[0]='*';
 
	memcpy(_new+1,name,i);
 

	
 
	item_new->name  = _new;
 

	
 
	item = _iconsole_vars;
 
	if (item == NULL) {
 
		_iconsole_vars = item_new;
 
	} else {
 
		while (item->_next != NULL) { item = item->_next; };
 
		item->_next = item_new;
 
	}
 
}
 

	
 

	
 
_iconsole_var * IConsoleVarGet(byte * name)
 
_iconsole_var * IConsoleVarGet(const byte * name)
 
{
 
	_iconsole_var * item;
 

	
 
	item = _iconsole_vars;
 
	while (item != NULL) {
 
		if (strcmp(item->name,name)==0) return item;
 
		item = item->_next;
 
		}
 
	return NULL;
 
}
 

	
 
_iconsole_var * IConsoleVarAlloc(byte type)
 
{
 
	_iconsole_var * item;
 
	item=malloc(sizeof(_iconsole_var));
 
	item->_next = NULL;
 
	item->name  = "";
 
	item->type  = type;
 
	switch (item->type) {
 
			case ICONSOLE_VAR_BOOLEAN:
 
					{
 
					item->addr=malloc(sizeof(bool));
 
					memset(item->addr,0,sizeof(bool));
 
					item->_malloc=true;
 
@@ -530,110 +530,97 @@ void IConsoleVarInsert(_iconsole_var * v
 
					}
 
					break;
 
			case ICONSOLE_VAR_INT32:
 
					{
 
					item->addr=malloc(sizeof(signed int));
 
					memset(item->addr,0,sizeof(signed int));
 
					item->_malloc=true;
 
					}
 
					break;
 
			default:
 
					item->addr  = NULL;
 
					item->_malloc = false;
 
					break;
 
			}
 

	
 
	item->hook_access = NULL;
 
	item->hook_after_change = NULL;
 
	item->hook_before_change = NULL;
 
	return item;
 
}
 

	
 

	
 
void IConsoleVarFree(_iconsole_var * var)
 
{
 
	if (var ->_malloc) {
 
		free(var ->addr);
 
		}
 
	if (var->_malloc)
 
		free(var->addr);
 
	free(var);
 
}
 

	
 
void IConsoleVarSetString(_iconsole_var * var, byte * string)
 
void IConsoleVarSetString(_iconsole_var * var, const byte * string)
 
{
 
	int l;
 

	
 
	if (string == NULL) return;
 

	
 
	if (var->_malloc) {
 
		free(var->addr);
 
		}
 

	
 
	l=strlen((char *) string);
 
	l=strlen(string);
 
	var->addr=malloc(l+1);
 
	var->_malloc=true;
 
	memset(var->addr,0,l);
 
	memcpy((void *) var->addr,(void *) string, l);
 
	memcpy(var->addr, string, l);
 
	((byte *)var->addr)[l]=0;
 
	}
 
}
 

	
 
	void IConsoleVarSetValue(_iconsole_var * var, int value) {
 
void IConsoleVarSetValue(_iconsole_var * var, int value) {
 
	switch (var->type) {
 
			case ICONSOLE_VAR_BOOLEAN:
 
					{
 
					(*(bool *)var->addr)=(value!=0);
 
					}
 
					*(bool *)var->addr = (value != 0);
 
					break;
 
			case ICONSOLE_VAR_BYTE:
 
					{
 
					(*(byte *)var->addr)=value;
 
					}
 
					*(byte *)var->addr = value;
 
					break;
 
			case ICONSOLE_VAR_UINT16:
 
					{
 
					(*(unsigned short *)var->addr)=value;
 
					}
 
					*(unsigned short *)var->addr = value;
 
					break;
 
			case ICONSOLE_VAR_UINT32:
 
					{
 
					(*(unsigned int *)var->addr)=value;
 
					}
 
					*(unsigned int *)var->addr = value;
 
					break;
 
			case ICONSOLE_VAR_INT16:
 
					{
 
					(*(signed short *)var->addr)=value;
 
					}
 
					*(signed short *)var->addr = value;
 
					break;
 
			case ICONSOLE_VAR_INT32:
 
					{
 
					(*(signed int *)var->addr)=value;
 
					}
 
					*(signed int *)var->addr = value;
 
					break;
 
			default:
 
					break;
 
			}
 
	}
 
}
 

	
 
void IConsoleVarDump(_iconsole_var * var, byte * dump_desc)
 
void IConsoleVarDump(_iconsole_var * var, const byte * dump_desc)
 
{
 
	byte var_b; // TYPE BYTE
 
	unsigned short var_ui16; // TYPE UINT16
 
	unsigned int var_ui32; // TYPE UINT32
 
	signed short var_i16; // TYPE INT16
 
	signed int var_i32; // TYPE INT32
 
	byte * var_s; // TYPE STRING
 

	
 
	if (dump_desc==NULL) dump_desc = var->name;
 

	
 
	switch (var->type) {
 
		case ICONSOLE_VAR_BOOLEAN:
 
				{
 
				if (*(bool *)var->addr) {
 
					IConsolePrintF(_iconsole_color_default, "%s = true",dump_desc);
 
					} else {
 
					IConsolePrintF(_iconsole_color_default, "%s = false",dump_desc);
 
					}
 
				}
 
				break;
 
		case ICONSOLE_VAR_BYTE:
 
				{
 
				var_b=*(byte *)var->addr;
 
				IConsolePrintF(_iconsole_color_default, "%s = %i",dump_desc,var_b);
 
@@ -665,115 +652,119 @@ void IConsoleVarDump(_iconsole_var * var
 
				break;
 
		case ICONSOLE_VAR_STRING:
 
				{
 
				var_s=(byte *)var->addr;
 
				IConsolePrintF(_iconsole_color_default, "%s = %s",dump_desc,var_s);
 
				}
 
				break;
 
		case ICONSOLE_VAR_REFERENCE:
 
				IConsolePrintF(_iconsole_color_default, "%s = @%s",dump_desc,((_iconsole_var *)var->addr)->name);
 
				break;
 
		case ICONSOLE_VAR_UNKNOWN:
 
		case ICONSOLE_VAR_POINTER:
 
				{
 
				var_i32=(signed int)((byte *)var->addr);
 
				IConsolePrintF(_iconsole_color_default, "%s = @%i",dump_desc,var_i32);
 
				}
 
				break;
 
		}
 
}
 

	
 
// * ************************* * //
 
// * hooking code              * //
 
// * ************************* * //
 

	
 
void IConsoleVarHook(byte * name, byte type, void * proc)
 
void IConsoleVarHook(const byte * name, byte type, void * proc)
 
{
 
	_iconsole_var * hook_var;
 
	hook_var = IConsoleVarGet(name);
 
	if (hook_var == NULL) return;
 
	switch (type) {
 
	case ICONSOLE_HOOK_BEFORE_CHANGE:
 
		hook_var->hook_after_change = proc;
 
		break;
 
	case ICONSOLE_HOOK_AFTER_CHANGE:
 
		hook_var->hook_after_change = proc;
 
		break;
 
	case ICONSOLE_HOOK_ACCESS:
 
		hook_var->hook_access = proc;
 
		break;
 
	}
 
}
 

	
 
bool IConsoleVarHookHandle(_iconsole_var * hook_var, byte type)
 
{
 
	bool (*proc)(_iconsole_var * hook_var);
 
	bool (*proc)(_iconsole_var * hook_var) = NULL;
 
	switch (type) {
 
	case ICONSOLE_HOOK_BEFORE_CHANGE:
 
		proc = hook_var->hook_before_change;
 
		break;
 
	case ICONSOLE_HOOK_AFTER_CHANGE:
 
		proc = hook_var->hook_after_change;
 
		break;
 
	case ICONSOLE_HOOK_ACCESS:
 
		proc = hook_var->hook_access;
 
		break;
 
	default: return true;
 
	}
 
	if (proc == NULL) return true;
 

	
 
	return proc(hook_var);
 
}
 

	
 
void IConsoleCmdHook(byte * name, byte type, void * proc)
 
void IConsoleCmdHook(const byte * name, byte type, void * proc)
 
{
 
	_iconsole_cmd * hook_cmd;
 
	hook_cmd = IConsoleCmdGet(name);
 
	if (hook_cmd == NULL) return;
 
	switch (type) {
 
	case ICONSOLE_HOOK_AFTER_EXEC:
 
		hook_cmd->hook_after_exec = proc;
 
		break;
 
	case ICONSOLE_HOOK_BEFORE_EXEC:
 
		hook_cmd->hook_before_exec = proc;
 
		break;
 
	case ICONSOLE_HOOK_ACCESS:
 
		hook_cmd->hook_access = proc;
 
		break;
 
	}
 
}
 

	
 
bool IConsoleCmdHookHandle(_iconsole_cmd * hook_cmd, byte type)
 
{
 
	bool (*proc)(_iconsole_cmd * hook_cmd);
 
	switch (type) {
 
	case ICONSOLE_HOOK_AFTER_EXEC:
 
		proc = hook_cmd->hook_after_exec;
 
		break;
 
	case ICONSOLE_HOOK_BEFORE_EXEC:
 
		proc = hook_cmd->hook_before_exec;
 
		break;
 
	case ICONSOLE_HOOK_ACCESS:
 
		proc = hook_cmd->hook_access;
 
		break;
 
	default:
 
		proc = NULL;
 
		break;
 
	}
 
	if (proc == NULL) return true;
 
	return proc(hook_cmd);
 
}
 

	
 
void IConsoleCmdExec(byte * cmdstr)
 
{
 
	_iconsole_var * (*function)(byte argc, byte* argv[], byte argt[]);
 
	byte * tokens[20];
 
	byte tokentypes[20];
 
	byte * tokenstream;
 
	byte * tokenstream_s;
 
	byte execution_mode;
 
	_iconsole_var * var = NULL;
 
	_iconsole_var * result = NULL;
 
	_iconsole_cmd * cmd = NULL;
 

	
 
	bool longtoken;
 
	bool valid_token;
 
	bool skip_lt_change;
 

	
 
	int c;
 
	int i;
 
	int l;
 
@@ -864,49 +855,49 @@ void IConsoleCmdExec(byte * cmdstr)
 
			if (tokens[i]!=NULL) if (tokens[i][0]=='@') if (tokens[i][1]=='*') {
 
				var = IConsoleVarGet(tokens[i]+1);
 
				if (var!=NULL) {
 
					tokens[i]=(byte *)var;
 
					tokentypes[i]=ICONSOLE_VAR_REFERENCE;
 
					}
 
				}
 
			}
 
		}
 

	
 
	execution_mode=0;
 

	
 
	function = NULL;
 
	cmd = IConsoleCmdGet(tokens[0]);
 
	if (cmd != NULL) function = cmd->addr;
 

	
 
	if (function != NULL) {
 
		execution_mode=1; // this is a command
 
		} else {
 
		var = IConsoleVarGet(tokens[0]);
 
		if (var != NULL) {
 
			execution_mode=2; // this is a variable
 
			if (c>2) if (strcmp(tokens[1],"<<")==0) {
 
				// this is command to variable mode [normal]
 
				
 

	
 
				function = NULL;
 
				cmd = IConsoleCmdGet(tokens[2]);
 
				if (cmd != NULL) function = cmd->addr;
 

	
 
				if (function != NULL) {
 
					execution_mode=3;
 
					} else {
 
					result = IConsoleVarGet(tokens[2]);
 
					if (result != NULL) {
 
						execution_mode=4;
 
						}
 
					}
 
				}
 
			}
 
		}
 

	
 
	//** executing **//
 
	if (_stdlib_con_developer) IConsolePrintF(_iconsole_color_debug,"CONDEBUG: execution_mode: %i",execution_mode);
 
	switch (execution_mode) {
 
	case 0:
 
		{
 
		// not found
 
		IConsoleError("command or variable not found");
 
		}
 
@@ -1094,70 +1085,71 @@ void IConsoleCmdExec(byte * cmdstr)
 
					else if (strcmp(tokens[1],"++")==0) {
 
						var->addr = ((char *)var->addr)+1;
 
						IConsoleVarDump(var,NULL);
 
						}
 
					else if (strcmp(tokens[1],"--")==0) {
 
						var->addr = ((char *)var->addr)-1;;
 
						IConsoleVarDump(var,NULL);
 
						}
 
					else { IConsoleError("operation not supported"); }
 
					}
 
					break;
 
				}
 
				IConsoleVarHookHandle(var,ICONSOLE_HOOK_AFTER_CHANGE);
 
		}
 
		if (c==1) {
 
			// ** variable output ** //
 
			IConsoleVarDump(var,NULL);
 
			}
 
		}
 
		break;
 
	case 3:
 
	case 4:
 
		{
 
		// execute command with result or assign a variable
 
			if (execution_mode==3) if (IConsoleCmdHookHandle(cmd,ICONSOLE_HOOK_ACCESS)) {
 
			int i;
 
			int diff;
 
			void * temp;
 
			byte temp2;
 
			if (execution_mode==3) {
 
				if (IConsoleCmdHookHandle(cmd,ICONSOLE_HOOK_ACCESS)) {
 
					int i;
 
					int diff;
 
					void * temp;
 
					byte temp2;
 

	
 
			// tokenshifting
 
			for (diff=0; diff<2; diff++) {
 
				temp=tokens[0];
 
				temp2=tokentypes[0];
 
				for (i=1; i<20; i++) {
 
					tokens[i-1]=tokens[i];
 
					tokentypes[i-1]=tokentypes[i];
 
					// tokenshifting
 
					for (diff=0; diff<2; diff++) {
 
						temp=tokens[0];
 
						temp2=tokentypes[0];
 
						for (i=1; i<20; i++) {
 
							tokens[i-1]=tokens[i];
 
							tokentypes[i-1]=tokentypes[i];
 
						}
 
						tokens[19]=temp;
 
						tokentypes[19]=temp2;
 
					}
 
				tokens[19]=temp;
 
				tokentypes[19]=temp2;
 
				}
 
			IConsoleCmdHookHandle(cmd,ICONSOLE_HOOK_BEFORE_EXEC);
 
			result = function(c,tokens,tokentypes);
 
			IConsoleCmdHookHandle(cmd,ICONSOLE_HOOK_AFTER_EXEC);
 
			} else {
 
				execution_mode=255;
 
					IConsoleCmdHookHandle(cmd,ICONSOLE_HOOK_BEFORE_EXEC);
 
					result = function(c,tokens,tokentypes);
 
					IConsoleCmdHookHandle(cmd,ICONSOLE_HOOK_AFTER_EXEC);
 
				} else
 
					execution_mode=255;
 
			}
 

	
 
		if (IConsoleVarHookHandle(var,ICONSOLE_HOOK_ACCESS)) if (result!=NULL) {
 
			if (result ->type != var -> type) {
 
				IConsoleError("variable type missmatch");
 
				} else {
 
				IConsoleVarHookHandle(var,ICONSOLE_HOOK_BEFORE_CHANGE);
 
				switch (result->type) {
 
				case ICONSOLE_VAR_BOOLEAN:
 
					{
 
					(*(bool *)var->addr)=(*(bool *)result->addr);
 
					IConsoleVarDump(var,NULL);
 
					}
 
					break;
 
				case ICONSOLE_VAR_BYTE:
 
					{
 
					(*(byte *)var->addr)=(*(byte *)result->addr);
 
					IConsoleVarDump(var,NULL);
 
					}
 
					break;
 
				case ICONSOLE_VAR_UINT16:
 
					{
 
					(*(unsigned short *)var->addr)=(*(unsigned short *)result->addr);
 
					IConsoleVarDump(var,NULL);
console.h
Show inline comments
 
@@ -26,103 +26,103 @@ enum {
 

	
 
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;
 
	byte * name;
 
	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_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(byte * cmd);
 
void IConsoleCmdBufferAdd(const byte *cmd);
 
void IConsoleCmdBufferNavigate(signed char direction);
 

	
 
// ** console output ** //
 
void IConsolePrint(byte color_code, byte* string);
 
void IConsolePrint(byte color_code, const byte* string);
 
void CDECL IConsolePrintF(byte color_code, const char *s, ...);
 
void IConsoleDebug(byte* string);
 
void IConsoleError(byte* string);
 
void IConsoleError(const byte* string);
 

	
 
// *** Commands *** //
 

	
 
void IConsoleCmdRegister(byte * name, void * addr);
 
void IConsoleCmdRegister(const byte * name, void * addr);
 
void* IConsoleCmdGetAddr(byte * name);
 

	
 
// *** Variables *** //
 

	
 
void IConsoleVarRegister(byte * name, void * addr, byte type);
 
void IConsoleVarRegister(const byte * name, void * addr, byte type);
 
void IConsoleVarMemRegister(byte * name, byte type);
 
void IConsoleVarInsert(_iconsole_var * var, byte * name);
 
_iconsole_var * IConsoleVarGet(byte * name);
 
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, byte * string);
 
void IConsoleVarSetString(_iconsole_var * var, const byte * string);
 
void IConsoleVarSetValue(_iconsole_var * var, int value);
 
void IConsoleVarDump(_iconsole_var * var, byte * dump_desc);
 
void IConsoleVarDump(_iconsole_var * var, const byte * dump_desc);
 

	
 
// *** Parser *** //
 

	
 
void IConsoleCmdExec(byte * cmdstr);
 

	
 
// ** console std lib ** //
 
void IConsoleStdLibRegister();
 

	
 
// ** hook code ** //
 
void IConsoleVarHook(byte * name, byte type, void * proc);
 
void IConsoleCmdHook(byte * name, byte type, void * proc);
 
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 */
console_cmds.c
Show inline comments
 
/* -------------------- 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
 
 
// ** 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)
 
 
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;
 
}
 
 
DEF_CONSOLE_VAR_HOOK(ConVarHookNoNetwork)
 
{
 
	if (_networking) {
 
		IConsoleError("this variable is forbidden in multiplayer");
 
		return false;
 
		}
 
	return true;
 
}
 
 
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 * b;
 
	byte * ip = NULL;
 
	byte * port = NULL;
 
	byte * player = NULL;
 
	byte c;
 
	uint16 rport;
 
 
	if (argc<2) return NULL;
 
 
	b = argv[1];
 
	rport = _network_server_port;
 
	c = 0;
 
	ip = b;
 
	
 
	while (b[c] != 0) {
 
		if (((char)b[c]) == '#') {
 
			player = &b[c+1];
 
			b[c] = 0;
 
			}
 
		if (((char)b[c]) == ':') {
 
			port = &b[c+1];
 
			b[c] = 0;
 
			}
 
		c++;
 
		}
 
 
	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(b, rport);
 
 
	return NULL;
 
}
 
 
#endif
 
 
/* **************************** */
 
/*   default console commands   */
 
/* **************************** */
 
 
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(ConVarInfo)
 
{
 
	if (argc<2) return NULL;
 
	if (argt[1]!=ICONSOLE_VAR_REFERENCE) {
 
		IConsoleError("variable must be an variable reference");
 
		} else {
 
		_iconsole_var * item;
 
		item = (_iconsole_var *) argv[1];
 
		IConsolePrintF(_iconsole_color_default,"variable_name: %s",item->name);
 
		IConsolePrintF(_iconsole_color_default,"variable_type: %i",item->type);
 
		IConsolePrintF(_iconsole_color_default,"variable_addr: %i",item->addr);
 
		if (item->_malloc) IConsolePrintF(_iconsole_color_default,"variable_malloc: internal allocated"); else IConsolePrintF(_iconsole_color_default, "variable_malloc: external allocated");
 
		}
 
	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((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(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((void *) item->name, (void *) argv[1],l)==0)
 
					IConsoleVarDump(item,NULL);
 
 
			} else {
 
 
			IConsoleVarDump(item,NULL);
 
 
			}
 
		item = item->_next;
 
		}
 
 
	return NULL;
 
}
 
 
#ifdef _DEBUG
 
/* ****************************************** */
 
/*  debug commands and variables */
 
/* ****************************************** */
 
 
void IConsoleDebugLibRegister() 
 
{
 
	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;
 
	extern bool _stdlib_con_developer;
 
 
#ifdef _DEBUG
 
	IConsoleDebugLibRegister();
 
#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("exit",ConExit);
 
	IConsoleCmdRegister("help",ConHelp);
 
	IConsoleCmdRegister("printf",ConPrintF);
 
	IConsoleCmdRegister("printfc",ConPrintFC);
 
	IConsoleCmdRegister("quit",ConExit);
 
	IConsoleCmdRegister("random",ConRandom);
 
	IConsoleCmdRegister("list_cmds",ConListCommands);
 
	IConsoleCmdRegister("list_vars",ConListVariables);
 
	IConsoleCmdRegister("resetengines",ConResetEngines);
 
	IConsoleCmdHook("resetengines",ICONSOLE_HOOK_ACCESS,ConCmdHookNoNetwork);
 
	IConsoleCmdRegister("screenshot",ConScreenShot);
 
	IConsoleCmdRegister("scrollto",ConScrollToTile);
 
	IConsoleCmdRegister("varinfo",ConVarInfo);
 
 
	// variables [please add them alphabeticaly]
 
	IConsoleVarRegister("con_developer",(void *) &_stdlib_con_developer,ICONSOLE_VAR_BOOLEAN);
 
	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 --------------------- */
 
/* -------------------- 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
 

	
 
// ** 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)
 

	
 
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 * b;
 
	byte * ip = NULL;
 
	byte * port = NULL;
 
	byte * player = NULL;
 
	byte c;
 
	uint16 rport;
 

	
 
	if (argc<2) return NULL;
 

	
 
	b = argv[1];
 
	rport = _network_server_port;
 
	c = 0;
 
	ip = b;
 

	
 
	while (b[c] != 0) {
 
		if (((char)b[c]) == '#') {
 
			player = &b[c+1];
 
			b[c] = 0;
 
			}
 
		if (((char)b[c]) == ':') {
 
			port = &b[c+1];
 
			b[c] = 0;
 
			}
 
		c++;
 
		}
 

	
 
	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(b, rport);
 

	
 
	return NULL;
 
}
 

	
 
#endif
 

	
 
/* **************************** */
 
/*   default console commands   */
 
/* **************************** */
 

	
 
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(ConVarInfo)
 
{
 
	if (argc<2) return NULL;
 
	if (argt[1]!=ICONSOLE_VAR_REFERENCE) {
 
		IConsoleError("variable must be an variable reference");
 
		} else {
 
		_iconsole_var * item;
 
		item = (_iconsole_var *) argv[1];
 
		IConsolePrintF(_iconsole_color_default,"variable_name: %s",item->name);
 
		IConsolePrintF(_iconsole_color_default,"variable_type: %i",item->type);
 
		IConsolePrintF(_iconsole_color_default,"variable_addr: %i",item->addr);
 
		if (item->_malloc) IConsolePrintF(_iconsole_color_default,"variable_malloc: internal allocated"); else IConsolePrintF(_iconsole_color_default, "variable_malloc: external allocated");
 
		}
 
	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()
 
{
 
	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;
 
	extern bool _stdlib_con_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("exit",ConExit);
 
	IConsoleCmdRegister("help",ConHelp);
 
	IConsoleCmdRegister("printf",ConPrintF);
 
	IConsoleCmdRegister("printfc",ConPrintFC);
 
	IConsoleCmdRegister("quit",ConExit);
 
	IConsoleCmdRegister("random",ConRandom);
 
	IConsoleCmdRegister("list_cmds",ConListCommands);
 
	IConsoleCmdRegister("list_vars",ConListVariables);
 
	IConsoleCmdRegister("resetengines",ConResetEngines);
 
	IConsoleCmdHook("resetengines",ICONSOLE_HOOK_ACCESS,ConCmdHookNoNetwork);
 
	IConsoleCmdRegister("screenshot",ConScreenShot);
 
	IConsoleCmdRegister("scrollto",ConScrollToTile);
 
	IConsoleCmdRegister("varinfo",ConVarInfo);
 

	
 
	// variables [please add them alphabeticaly]
 
	IConsoleVarRegister("con_developer",(void *) &_stdlib_con_developer,ICONSOLE_VAR_BOOLEAN);
 
	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 --------------------- */
console_cmds.h
Show inline comments
 
deleted file
graph_gui.c
Show inline comments
 
@@ -995,50 +995,50 @@ static const StringID _performance_title
 
	STR_7066_ENGINEER,
 
	STR_7066_ENGINEER,
 
	STR_7067_TRAFFIC_MANAGER,
 
	STR_7067_TRAFFIC_MANAGER,
 
	STR_7068_TRANSPORT_COORDINATOR,
 
	STR_7068_TRANSPORT_COORDINATOR,
 
	STR_7069_ROUTE_SUPERVISOR,
 
	STR_7069_ROUTE_SUPERVISOR,
 
	STR_706A_DIRECTOR,
 
	STR_706A_DIRECTOR,
 
	STR_706B_CHIEF_EXECUTIVE,
 
	STR_706B_CHIEF_EXECUTIVE,
 
	STR_706C_CHAIRMAN,
 
	STR_706C_CHAIRMAN,
 
	STR_706D_PRESIDENT,
 
	STR_706E_TYCOON,
 
};
 

	
 
static StringID GetPerformanceTitleFromValue(uint v)
 
{
 
	return _performance_titles[minu(v, 1000) >> 6];
 
}
 

	
 
static int CDECL _perf_hist_comp(const void *elem1, const void *elem2 ) {
 
	Player *p1 = *(Player**)elem1;
 
	Player *p2 = *(Player**)elem2;
 
	const Player *p1 = *(const Player* const *)elem1;
 
	const Player *p2 = *(const Player* const *)elem2;
 
	int32 v = p2->old_economy[1].performance_history - p1->old_economy[1].performance_history;
 
	return (v!=0) | (v >> (sizeof(int32)*8-1));
 
}
 

	
 
static void CompanyLeagueWndProc(Window *w, WindowEvent *e)
 
{
 
	switch(e->event) {
 
	case WE_PAINT: {
 
		Player *p;
 
		Player *plist[MAX_PLAYERS];
 
		size_t pl_num, i;
 

	
 
		DrawWindowWidgets(w);
 

	
 
		pl_num=0;
 
		FOR_ALL_PLAYERS(p) {
 
			if (p->is_active)
 
				plist[pl_num++] = p;
 
		}
 
		assert(pl_num > 0);
 

	
 
		qsort(plist, pl_num, sizeof(Player*), _perf_hist_comp);
 

	
 
		i = 0;
hal.h
Show inline comments
 
@@ -114,33 +114,33 @@ enum {
 
	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(char **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 */
industry_gui.c
Show inline comments
 
@@ -371,94 +371,94 @@ static const Widget _industry_directory_
 
{    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(*(byte*)a);
 
	Industry *j = DEREF_INDUSTRY(*(byte*)b);
 
	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=*(byte*)b) != _last_industry_idx) {
 
		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);
macros.h
Show inline comments
 
@@ -182,43 +182,43 @@ static INLINE int FindFirstBit2x64(int v
 

	
 
#define for_each_bit(_i,_b)										\
 
	for(_i=0; _b!=0; _i++,_b>>=1)								\
 
		if (_b&1)
 

	
 
#define assert_array(i,j) assert(i < lengthof(j))
 

	
 
#define abs myabs
 

	
 

	
 
static INLINE int intxchg_(int *a, int b) { int t = *a; *a = b; return t; }
 
#define intxchg(a,b) intxchg_(&(a), (b))
 
#define intswap(a,b) ((b) = intxchg_(&(a), (b)))
 

	
 
static INLINE int myabs(int a) { if (a<0) a = -a; return a; }
 

	
 
static INLINE void swap_byte(byte *a, byte *b) { byte t = *a; *a = *b; *b = t; }
 
static INLINE void swap_uint16(uint16 *a, uint16 *b) { uint16 t = *a; *a = *b; *b = t; }
 
static INLINE void swap_int16(int16 *a, int16 *b) { int16 t = *a; *a = *b; *b = t; }
 
static INLINE void swap_tile(TileIndex *a, TileIndex *b) { TileIndex t = *a; *a = *b; *b = t; }
 

	
 

	
 

	
 
#if defined(TTD_LITTLE_ENDIAN)
 
#	define READ_LE_UINT16(b) (*(uint16*)(b))
 
#	define READ_LE_UINT16(b) (*(const uint16*)(b))
 
#	define ADD_WORD(x) (x)&0xFF, ((x) >> 8)&0xFF
 
#	define ADD_DWORD(x) (x)&0xFF, ((x) >> 8)&0xFF, ((x) >> 16)&0xFF, ((x) >> 24)&0xFF
 
#elif defined(TTD_BIG_ENDIAN)
 
	static INLINE uint16 READ_LE_UINT16(const void *b) {
 
		return ((byte*)b)[0] + (((byte*)b)[1] << 8);
 
		return ((const byte*)b)[0] + (((const byte*)b)[1] << 8);
 
	}
 
#	define ADD_WORD(x) ((x) >> 8)&0xFF, (x)&0xFF
 
#	define ADD_DWORD(x) ((x) >> 24)&0xFF, ((x) >> 16)&0xFF, ((x) >> 8)&0xFF,  (x)&0xFF
 
#endif
 

	
 
static INLINE void WRITE_LE_UINT16(const void *b, uint16 x) {
 
static INLINE void WRITE_LE_UINT16(void *b, uint16 x) {
 
	((byte*)b)[0] = (byte)x;
 
	((byte*)b)[1] = (byte)(x >> 8);
 
}
 

	
 
#define MAX_DETOUR 6
 

	
 
#endif /* MACROS_H */
main_gui.c
Show inline comments
 
@@ -2205,52 +2205,52 @@ void SetupColorsAndInitialWindow()
 
		b = GetSpritePtr(0x307 + i);
 
		assert(b);
 
		_color_list[i] = *(ColorList*)(b + 0xC6);
 
	}
 

	
 
	width = _screen.width;
 
	height = _screen.height;
 

	
 
	// XXX: these are not done
 
	switch(_game_mode) {
 
	case GM_MENU:
 
		w = AllocateWindow(0, 0, width, height, MainWindowWndProc, 0, NULL);
 
		AssignWindowViewport(w, 0, 0, width, height, 0x8080, 0);
 
//		w = AllocateWindowDesc(&_toolb_intro_desc);
 
//		w->flags4 &= ~WF_WHITE_BORDER_MASK;
 
		ShowSelectGameWindow();
 
		break;
 
	case GM_NORMAL:
 
		w = AllocateWindow(0, 0, width, height, MainWindowWndProc, 0, NULL);
 
		AssignWindowViewport(w, 0, 0, width, height, 0x8080, 0);
 

	
 
		w = AllocateWindowDesc(&_toolb_normal_desc);
 
		w->disabled_state = 1 << 17; // disable zoon-in button (by default game is zoomed in)
 

	
 
		if (_networking) { // if networking, disable fast-forward button
 
			w->disabled_state |= (1 << 1);
 
			if (!_networking_server) // if not server, disable pause button
 
				w->disabled_state |= (1 << 0);
 
		if (_networking) { // if networking, disable fast-forward button
 
			w->disabled_state |= (1 << 1);
 
			if (!_networking_server) // if not server, disable pause button
 
				w->disabled_state |= (1 << 0);
 
		}
 

	
 
		w->flags4 &= ~WF_WHITE_BORDER_MASK;
 

	
 
		PositionMainToolbar(w); // already WC_MAIN_TOOLBAR passed (&_toolb_normal_desc)
 

	
 
		_main_status_desc.top = height - 12;
 
		w = AllocateWindowDesc(&_main_status_desc);
 
		w->flags4 &= ~WF_WHITE_BORDER_MASK;
 

	
 
		WP(w,def_d).data_1 = -1280;
 

	
 
		break;
 
	case GM_EDITOR:
 
		w = AllocateWindow(0, 0, width, height, MainWindowWndProc, 0, NULL);
 
		AssignWindowViewport(w, 0, 0, width, height, 0, 0);
 

	
 
		w = AllocateWindowDesc(&_toolb_scen_desc);
 
		w->disabled_state = 1 << 9;
 
		w->flags4 &= ~WF_WHITE_BORDER_MASK;
 

	
 
		PositionMainToolbar(w); // already WC_MAIN_TOOLBAR passed (&_toolb_scen_desc)
 
		break;
 
	default:
misc_gui.c
Show inline comments
 
@@ -942,49 +942,49 @@ static const Widget _save_dialog_scen_wi
 
{  WWT_SCROLLBAR,    14,   246,   256,    48,   291, 0x0,								STR_0190_SCROLL_BAR_SCROLLS_LIST},
 
{     WWT_IMGBTN,    14,     0,   256,   292,   307, 0x0,								STR_NULL},
 
{     WWT_IMGBTN,    14,     2,   254,   294,   305, 0x0,								STR_400B_CURRENTLY_SELECTED_NAME},
 
{ WWT_PUSHTXTBTN,    14,     0,   127,   308,   319, STR_4003_DELETE,		STR_400C_DELETE_THE_CURRENTLY_SELECTED},
 
{ WWT_PUSHTXTBTN,    14,   128,   256,   308,   319, STR_4002_SAVE,			STR_400D_SAVE_THE_CURRENT_GAME_USING},
 
{   WIDGETS_END},
 
};
 

	
 

	
 
static FiosItem *_fios_list;
 
static int _fios_num;
 
static int _saveload_mode;
 

	
 
static void BuildFileList()
 
{
 
	FiosFreeSavegameList();
 
	if(_saveload_mode==SLD_NEW_GAME || _saveload_mode==SLD_LOAD_SCENARIO || _saveload_mode==SLD_SAVE_SCENARIO)
 
		_fios_list = FiosGetScenarioList(&_fios_num, _saveload_mode);
 
	else
 
		_fios_list = FiosGetSavegameList(&_fios_num, _saveload_mode);
 
}
 

	
 
static void DrawFiosTexts()
 
{
 
	char *path;
 
	const char *path;
 
	StringID str;
 

	
 
	str = FiosGetDescText(&path);
 
	if (str != 0)
 
		DrawString(2, 37, str, 0);
 
	DoDrawString(path, 2, 27, 16);
 
}
 

	
 
/*	FIOS_TYPE_FILE, FIOS_TYPE_OLDFILE etc. different colours */
 
static const byte _fios_colors[] = {13, 9, 9, 6, 5, 6, 5};
 

	
 
#if defined(_WIN32)
 
	extern int CDECL compare_FiosItems (const void *a, const void *b);
 
#else
 
	extern int compare_FiosItems (const void *a, const void *b);
 
#endif
 

	
 

	
 
static void MakeSortedSaveGameList()
 
{
 
	/*	Directories are always above the files (FIOS_TYPE_DIR)
 
	 *	Drives (A:\ (windows only) are always under the files (FIOS_TYPE_DRIVE)
 
	 *	Only sort savegames/scenarios, not directories
 
	 */
network.c
Show inline comments
 
@@ -507,49 +507,49 @@ void NetworkSendCommand(TileIndex tile, 
 
//   send an ack packet to the actual client.
 

	
 
static void HandleCommandPacket(ClientState *cs, CommandPacket *np)
 
{
 
	QueuedCommand *qp;
 
	ClientState *c;
 
	AckPacket ap;
 
	uint16 cmd;
 

	
 
	DEBUG(net, 2) ("[NET] cmd size %d", np->packet_length);
 
	assert(np->packet_length >= COMMAND_PACKET_BASE_SIZE);
 

	
 
	cmd = np->cmd;
 
#if defined(TTD_BIG_ENDIAN)
 
	cmd = TO_LE16(cmd);
 
#endif
 

	
 
	if (!(cmd & CMD_NET_INSTANT)) {
 
		// put it into the command queue
 
		qp = AllocQueuedCommand(&_command_queue);
 
	} else {
 
		qp = (QueuedCommand*)calloc(sizeof(QueuedCommand), 1);
 
	}
 
	qp->cp = *np;
 
	
 

	
 
	qp->frame = _frame_counter_max - GetNextSyncFrame();
 

	
 
	qp->callback = NULL;
 

	
 
	// extra params
 
	memcpy(&qp->cp.dp, np->dp, np->packet_length - COMMAND_PACKET_BASE_SIZE);
 

	
 
	ap.packet_type = PACKET_TYPE_ACK;
 
	ap.when = GetNextSyncFrame();
 
	ap.packet_length = sizeof(AckPacket);
 
	DEBUG(net,4)("[NET] NewACK: frame=%i %i",ap.when,_frame_counter_max - GetNextSyncFrame());
 

	
 
	// send it to the peers
 
	if (_networking_server) {
 
		for(c=_clients; c->socket != INVALID_SOCKET; c++) {
 
			if (c == cs) {
 
				if (!(cmd & CMD_NET_INSTANT)) SendDirectBytes(c, &ap, ap.packet_length);
 
			} else {
 
				if (!cs->inactive) SendBytes(c, &qp->cp, qp->cp.packet_length);
 
			}
 
		}
 
	}
 

	
 
// convert from little endian to big endian?
network_gui.c
Show inline comments
 
@@ -123,84 +123,84 @@ static void NetworkGameWindowWndProc(Win
 
					cur_item = cur_item->_next;
 

	
 
				if (cur_item == NULL) { return;} // click out of vehicle bounds
 

	
 
				selected_item = cur_item;
 
			}
 
		} break;
 
		case 16: /* Join Game */
 
			if (selected_item != NULL)
 
				NetworkCoreConnectGameStruct(selected_item);
 
			break;
 
		}
 
		break;
 

	
 
	case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */
 
		_network_connection = e->dropdown.index;
 
		switch (_network_connection) {
 
		case 0: /* LAN */
 
			NetworkGameListFromLAN();
 
			break;
 
		case 1: /* Internet */
 
			NetworkGameListFromInternet();
 
			break;
 
		}
 
		
 

	
 
		_network_game_count_last = _network_game_count;
 
		SetWindowDirty(w);
 

	
 
		break;
 

	
 
	case WE_MOUSELOOP:
 
		if (_selected_field == 6)
 
			HandleEditBox(w, 6);
 

	
 
		break;
 

	
 
	case WE_KEYPRESS:
 
		if (_selected_field != 6)
 
			break;
 

	
 
		switch (HandleEditBoxKey(w, 6, e)) {
 
		case 1:
 
			HandleButtonClick(w, 9);
 
			break;
 
		}
 
		break;
 

	
 
	case WE_ON_EDIT_TEXT: {
 
		byte *b = e->edittext.str;
 
		if (*b != 0) {
 
			byte * ip = NULL;
 
			byte * port = NULL;
 
			byte * player = NULL;
 
			byte c;
 
			uint16 rport;
 

	
 
			rport = _network_server_port;
 
			c = 0;
 
			ip = b;
 
			
 

	
 
			while (b[c] != 0) {
 
				if (((char)b[c]) == '#') {
 
					player = &b[c+1];
 
					b[c] = 0;
 
					}
 
				if (((char)b[c]) == ':') {
 
					port = &b[c+1];
 
					b[c] = 0;
 
					}
 
				c++;
 
				}
 

	
 
			if (player!=NULL) _network_playas = atoi(player);
 
			if (port!=NULL) rport = atoi(port);
 

	
 
			NetworkCoreConnectGame(b, rport);
 
		}
 
	} break;
 

	
 
	case WE_TICK: {
 
		if (_network_game_count_last != _network_game_count)
 
			SetWindowDirty(w);
 
	} break;
 

	
rail_cmd.c
Show inline comments
 
@@ -1499,99 +1499,99 @@ static void DrawTile_Track(TileInfo *ti)
 
				if (m5 & RAIL_BIT_LOWER) {
 
					MAYBE_DRAW_SIGNAL(1, 0x505, 6);
 
					MAYBE_DRAW_SIGNAL(0, 0x503, 7);
 
				}
 
			} else {
 
				MAYBE_DRAW_SIGNAL(3, 0x4FB, 8);
 
				MAYBE_DRAW_SIGNAL(2, 0x4FD, 9);
 
			}
 
		} else {
 
			MAYBE_DRAW_SIGNAL(3, 0x4FF, 10);
 
			MAYBE_DRAW_SIGNAL(2, 0x501, 11);
 
		}
 
		}
 
	} else {
 
		const byte *s;
 
		const DrawTrackSeqStruct *drss;
 

	
 
		if (!(m5 & (RAIL_TYPE_MASK&~RAIL_TYPE_SPECIAL)))
 
			return;
 

	
 
		if (ti->tileh != 0) { DrawFoundation(ti, ti->tileh); }
 

	
 
		s = _track_depot_layout_table[m5 & 0x3F];
 

	
 
		image = *(uint16*)s;
 
		image = *(const uint16*)s;
 
		if (image & 0x8000) image = (image & 0x7FFF) + tracktype_offs;
 

	
 
		// adjust ground tile for desert
 
		// (don't adjust for arctic, because snow in depots looks weird)
 
		if ((_map2[ti->tile] & RAIL_MAP2LO_GROUND_MASK)==RAIL_GROUND_ICE_DESERT && _opt.landscape == LT_DESERT)
 
		{
 
			if(image!=3981)
 
				image += 26; // tile with tracks
 
			else
 
				image = 4550; // flat ground
 
		}
 

	
 
		DrawGroundSprite(image);
 

	
 
		drss = (const DrawTrackSeqStruct*)(s + sizeof(uint16));
 

	
 
		while ((image=drss->image) != 0) {
 
			if (image & 0x8000)
 
				image |= _drawtile_track_palette;
 
			image += tracktype_offs;
 
			if (!(_display_opt & DO_TRANS_BUILDINGS)) // show transparent depots
 
				image = (image & 0x3FFF) | 0x3224000;
 
			AddSortableSpriteToDraw(image, ti->x | drss->subcoord_x,
 
				ti->y | drss->subcoord_y, drss->width, drss->height, 0x17, ti->z);
 
			drss++;
 
		}
 
	}
 
}
 

	
 
void DrawTrainDepotSprite(int x, int y, int image, int railtype)
 
{
 
	uint32 ormod, img;
 
	const DrawTrackSeqStruct *dtss;
 
	const byte *t;
 

	
 
	/* baseimage */
 
	railtype *= TRACKTYPE_SPRITE_PITCH;
 

	
 
	ormod = PLAYER_SPRITE_COLOR(_local_player);
 

	
 
	t = _track_depot_layout_table[image];
 

	
 
	x+=33;
 
	y+=17;
 

	
 
	img = *(uint16*)t;
 
	img = *(const uint16*)t;
 
	if (img & 0x8000) img = (img & 0x7FFF) + railtype;
 
	DrawSprite(img, x, y);
 

	
 
	for(dtss = (DrawTrackSeqStruct *)(t + sizeof(uint16)); dtss->image != 0; dtss++) {
 
	for(dtss = (const DrawTrackSeqStruct *)(t + sizeof(uint16)); dtss->image != 0; dtss++) {
 
		Point pt = RemapCoords(dtss->subcoord_x, dtss->subcoord_y, 0);
 
		image = dtss->image;
 
		if (image & 0x8000) image |= ormod;
 
		DrawSprite(image + railtype, x + pt.x, y + pt.y);
 
	}
 
}
 

	
 
#define NUM_SSD_ENTRY 256
 
#define NUM_SSD_STACK 32
 

	
 
typedef struct SetSignalsData {
 
	int cur;
 
	int cur_stack;
 
	bool stop;
 
	bool has_presignal;
 

	
 
	// presignal info
 
	int presignal_exits;
 
	int presignal_exits_free;
 

	
 
	// these are used to keep track of the signals that change.
 
	byte bit[NUM_SSD_ENTRY];
 
	TileIndex tile[NUM_SSD_ENTRY];
 

	
readme.txt
Show inline comments
 
@@ -105,71 +105,71 @@ OpenTTD has a lot of features going beyo
 
Currently there is unfortunately no comprehensive list of features. You could
 
check the features list on the web, and some optional features can be
 
controlled through the Configure patches dialog. We also implement some
 
features known from TTDPatch (http://www.ttdpatch.net/).
 

	
 
Several important non-standard controls:
 

	
 
* Use Ctrl to place presignals
 
* Ctrl-d toggles double mode on win32
 

	
 

	
 
6.0) Configuration File:
 
---- -------------------
 
The configuration file for OpenTTD (openttd.cfg) is in a simple windows-like
 
.INI format. It's mostly undocumented.
 

	
 

	
 
7.0) Compiling:
 
---- ----------
 
Windows:
 
  You need Microsoft Visual Studio 6 or .NET. Open the project file
 
  and it should build automatically. In case you don't build with SDL,
 
  you need to remove WITH_SDL from the project settings.
 
  (see also docs/Readme_Windows_MSVC6.0.txt)
 
  
 

	
 
  You can also build it using the Makefile with MSys/MingW or Cygwin/MingW.
 
  Please read the Makefile for more information.
 

	
 
Unix:
 
  OpenTTD can be built either with "make" or with "jam". To build with
 
  "make", just type "make", or "gmake" on non-gnu systems. To build with "jam",
 
  first run "./configure" and then "jam". Note that you need SDL to compile
 
  OpenTTD.
 
  (see also docs/Readme_Mandrake_Linux.txt)
 

	
 
MacOS:
 
  Use "make".
 

	
 
BeOS:
 
  Use "jam".
 

	
 
FreeBSD
 
  Use "gmake".
 

	
 
MorphOS
 
  Use "make". Note that you need the MorphOS SDK and the 
 
  powersdl.library SDK. 
 
  Use "make". Note that you need the MorphOS SDK and the
 
  powersdl.library SDK.
 

	
 
8.0) Translating:
 
---- -------------------
 
See http://www.openttd.com/translating.php for up-to-date information.
 

	
 
8.1) Guidelines:
 
---- -------------------
 
Here are some translation guidelines which you should follow closely.
 

	
 
    * Please contact the development team before begining the translation process!
 
      This avoids double work, as someone else may have already started translating to the same language.
 
    * Translators must use the charater set "Windows latin-1", also known as ISO 8859-1.
 
      Otherwise, some characters will not display correctly in the game.
 

	
 
8.2) Translation:
 
---- -------------------
 
So, now that you've notified the development team about your intention to translate
 
(You did, right? Of course you did.) you can pick up english.txt (found in the SVN repository
 
under /lang) and translate.
 

	
 
You must change the first two lines of the file appropriately:
 

	
 
##name English-Name-Of-Language
 
##ownname Native-Name-Of-Language
 
@@ -188,38 +188,38 @@ with the strgen utility, which is now bu
 
strgen is a command-line utility. It takes the language filename as parameter.
 
Example:
 

	
 
strgen lang/german.txt
 

	
 
This results in compiling german.txt and produces another file named german.lng.
 
Any missing strings are replaced with the english strings. Note that it looks for english.txt
 
in the lang subdirectory, which is where your language file should also be.
 

	
 
That's all! You should now be able to select the language in the game options.
 

	
 

	
 
X.X) Credits:
 
---- --------
 
The OpenTTD team:
 
  Ludvig Strigeus (ludde)        - OpenTTD author, main coder.
 
  Serge Paquet (vurlix)          - Assistant project manager, coder and webmaster.
 
  Dominik Scherer (dominik81)    - Coder
 
  Tamas Farago (Darkvater)       - Coder
 
  Owen Rudge (orudge)            - Contributor, forum host.
 
  Bjarni Corfitzen (Bjarni)      - MacOS port
 
  Cian Duffy (MYOB)              - BeOS port / manual writing
 
  Christian Rosentreter (tokaiz) - MorphOS/AmigaOS port
 
  Viktor Strigeus (wiggo)        - Web hosting services
 
  
 

	
 
Thanks to:
 
  Josef Drexler - For his great work on TTDPatch.
 
  Marcin Grzegorczyk - For his TTDPatch work and documentation of TTD internals and graphics (signals and track foundations).
 
  Mike Ragsdale - OpenTTD installer
 
  pasky - Many patches, newgrf support, etc.
 
  truesatan - Some patches
 
  TrueLight - Some patches
 
  Michael Polnick - Some patches
 
  Michael Blunck - Nice graphics
 
  George - Canal graphics
 
  Bug Reporters - Thanks for all bug reports.
 
  Chris Sawyer - For an amazing game.
 
  
 

	
road_cmd.c
Show inline comments
 
@@ -789,82 +789,82 @@ static void DrawTile_Road(TileInfo *ti)
 

	
 
		if ( _map3_hi[ti->tile] & 0x80) {
 
			image += 8;
 
		} else {
 
			m2 = _map2[ti->tile] & 7;
 
			if (m2 == 0) image |= 0x3178000;
 
			if (m2 > 1) image += 4;
 
		}
 

	
 
		DrawGroundSprite(image + (_map3_hi[ti->tile] & 0xF) * 12);
 
	} else {
 
		uint32 ormod;
 
		int player;
 
		const DrawRoadSeqStruct *drss;
 

	
 
		if (ti->tileh != 0) { DrawFoundation(ti, ti->tileh); }
 

	
 
		ormod = 0x315;
 
		player = _map_owner[ti->tile];
 
		if (player < MAX_PLAYERS)
 
			ormod = PLAYER_SPRITE_COLOR(player);
 

	
 
		s = _road_display_datas[ti->map5 & 0xF];
 

	
 
		DrawGroundSprite(*(uint32*)s);
 
		DrawGroundSprite(*(const uint32*)s);
 
		s += sizeof(uint32);
 
		drss = (DrawRoadSeqStruct*)s;
 
		drss = (const DrawRoadSeqStruct*)s;
 

	
 
		while ((image=drss->image) != 0) {
 
			if (image & 0x8000)
 
				image |= ormod;
 
			if (!(_display_opt & DO_TRANS_BUILDINGS)) // show transparent depots
 
				image = (image & 0x3FFF) | 0x3224000;
 

	
 
			AddSortableSpriteToDraw(image, ti->x | drss->subcoord_x,
 
				ti->y | drss->subcoord_y, drss->width, drss->height, 0x14, ti->z);
 
			drss++;
 
		}
 
	}
 
}
 

	
 
void DrawRoadDepotSprite(int x, int y, int image)
 
{
 
	uint32 ormod;
 
	const DrawRoadSeqStruct *dtss;
 
	const byte *t;
 

	
 
	ormod = PLAYER_SPRITE_COLOR(_local_player);
 

	
 
	t = _road_display_datas[image];
 

	
 
	x+=33;
 
	y+=17;
 

	
 
	DrawSprite(*(uint32*)t, x, y);
 
	DrawSprite(*(const uint32*)t, x, y);
 
	t += sizeof(uint32);
 

	
 
	for(dtss = (DrawRoadSeqStruct *)t; dtss->image != 0; dtss++) {
 
	for(dtss = (const DrawRoadSeqStruct *)t; dtss->image != 0; dtss++) {
 
		Point pt = RemapCoords(dtss->subcoord_x, dtss->subcoord_y, 0);
 

	
 
		image = dtss->image;
 
		if (image & 0x8000)
 
			image |= ormod;
 

	
 
		DrawSprite(image, x + pt.x, y + pt.y);
 
	}
 
}
 

	
 
uint GetSlopeZ_Road(TileInfo *ti)
 
{
 
	uint z = ti->z;
 
	int th = ti->tileh;
 

	
 
	// check if it's a foundation
 
	if (ti->tileh != 0) {
 
		if ((ti->map5 & 0xE0) == 0) { /* road or crossing */
 
			uint f = GetRoadFoundation(ti->tileh, ti->map5 & 0x3F);
 
			if (f != 0) {
 
				if (f < 15) {
 
					// leveled foundation
 
					return z + 8;
 
				}
saveload.c
Show inline comments
 
@@ -401,91 +401,91 @@ void SlArray(void *array, uint length, u
 
		}
 
	}
 

	
 
	// Optimized cases when input equals output.
 
	switch(conv) {
 
	case SLE_INT8:
 
	case SLE_UINT8:SlCopyBytes(array, length);break;
 
	default: {
 
		// Default "slow" case.
 
		byte *a = (byte*)array;
 
		while (length) {
 
			SlSaveLoadConv(a, conv);
 
			a += _conv_mem_size[(conv >> 4)&0xf];
 
			length--;
 
		}
 
		}
 
	}
 
}
 

	
 
// Calculate the size of an object.
 
static size_t SlCalcObjLength(void *object, const void *desc)
 
{
 
	size_t length = 0;
 
	uint cmd,conv;
 
	byte *d = (byte*)desc;
 
	const byte *d = (const byte*)desc;
 

	
 
	// Need to determine the length and write a length tag.
 
	while (true) {
 
		cmd = (d[0] >> 4);
 
		if (cmd < 8) {
 
			conv = d[2];
 
			d += 3;
 
			if (cmd&4) {
 
				d += 2;
 
				// check if the field is of the right version
 
				if (_sl.version < d[-2] || _sl.version > d[-1]) {
 
					if ((cmd & 3) == 2) d++;
 
					continue;
 
				}
 
			}
 

	
 
			switch(cmd&3) {
 
			// Normal variable
 
			case 0: length += SlCalcConvLen(conv, NULL);break;
 
			// Reference
 
			case 1: length += 2; break;
 
			// Array
 
			case 2:	length += SlCalcArrayLen(NULL, *d++, conv); break;
 
			default:NOT_REACHED();
 
			}
 
		} else if (cmd == 8) {
 
			length++;
 
			d += 4;
 
		} else if (cmd == 9) {
 
			length += SlCalcObjLength(NULL, _sl.includes[d[2]]);
 
			d += 3;
 
		} else if (cmd == 15)
 
			break;
 
		else
 
			assert(0);
 
	}
 
	return length;
 
}
 

	
 
void SlObject(void *object, const void *desc)
 
{
 
	byte *d = (byte*)desc;
 
	const byte *d = (const byte*)desc;
 
	void *ptr;
 
	uint cmd,conv;
 

	
 
	// Automatically calculate the length?
 
	if (_sl.need_length != NL_NONE) {
 
		SlSetLength(SlCalcObjLength(object, d));
 
		if (_sl.need_length == NL_CALCLENGTH)
 
			return;
 
	}
 

	
 
	while (true) {
 
		// Currently it only supports up to 4096 byte big objects
 
		ptr = (byte*)object + (d[0] & 0xF) + (d[1] << 4);
 

	
 
		cmd = d[0] >> 4;
 

	
 
		if (cmd < 8) {
 
			conv = d[2];
 
			d += 3;
 

	
 
			if (cmd&4) {
 
				d += 2;
 
				// check if the field is of the right version
 
				if (_sl.version < d[-2] || _sl.version > d[-1]) {
sdl.c
Show inline comments
 
@@ -191,51 +191,51 @@ static void InitPalette(void) {
 
static void CheckPaletteAnim()
 
{
 
	if(_pal_last_dirty != -1) {
 
		UpdatePalette(_pal_first_dirty, _pal_last_dirty + 1);
 
		_pal_last_dirty = -1;
 
	}
 
}
 

	
 
static void DrawSurfaceToScreen()
 
{
 
	int n;
 

	
 
	if ((n=_num_dirty_rects) != 0) {
 
		_num_dirty_rects = 0;
 
		if (n > MAX_DIRTY_RECTS)
 
			SDL_CALL SDL_UpdateRect(_sdl_screen, 0, 0, 0, 0);
 
		else {
 
			SDL_CALL SDL_UpdateRects(_sdl_screen, n, _dirty_rects);
 
		}
 
	}
 
}
 

	
 
static int CDECL compare_res(const void *pa, const void *pb)
 
{
 
	int x = ((uint16*)pa)[0] - ((uint16*)pb)[0];
 
	int x = ((const uint16*)pa)[0] - ((const uint16*)pb)[0];
 
	if (x) return x;
 
	return ((uint16*)pa)[1] - ((uint16*)pb)[1];
 
	return ((const uint16*)pa)[1] - ((const uint16*)pb)[1];
 
}
 

	
 
static const uint16 default_resolutions[][2] = {
 
	{640,480},
 
	{800,600},
 
	{1024,768},
 
	{1152,864},
 
	{1280,960},
 
	{1280,1024},
 
	{1400,1050},
 
	{1600,1200},
 
};
 

	
 
static void GetVideoModes(void) {
 
	int i;
 
	SDL_Rect **modes;
 

	
 
	modes = SDL_CALL SDL_ListModes(NULL, SDL_SWSURFACE + (_fullscreen ? SDL_FULLSCREEN : 0));
 

	
 
	_all_modes = (int)modes == -1;
 

	
 
	if(!modes) {
 
		error("sdl: no modes available");
 
	} else if((int) modes == -1) {
settings.c
Show inline comments
 
@@ -304,51 +304,51 @@ static bool ini_save(const char *filenam
 
	if (f == NULL) return false;
 

	
 
	for(group = ini->group; group; group = group->next) {
 
		if (group->comment) fputs(group->comment, f);
 
		fprintf(f, "[%s]\n", group->name);
 
		for(item = group->item; item; item = item->next) {
 
			if (item->comment) fputs(item->comment, f);
 
			fprintf(f, "%s = %s\n", item->name, item->value ? item->value : "");
 
		}
 
	}
 
	if (ini->comment) fputs(ini->comment, f);
 

	
 
	fclose(f);
 
	return true;
 
}
 

	
 
static void ini_free(IniFile *ini)
 
{
 
	pool_free(&ini->pool);
 
}
 

	
 
struct SettingDesc {
 
	const char *name;
 
	int flags;
 
	void *def;
 
	const void *def;
 
	void *ptr;
 
	void *b;
 
	const void *b;
 

	
 
};
 

	
 
static int lookup_oneofmany(const char *many, const char *one, int onelen)
 
{
 
	const char *s;
 
	int idx;
 

	
 
	if (onelen == -1) onelen = strlen(one);
 

	
 
	// check if it's an integer
 
	if (*one >= '0' && *one <= '9')
 
		return strtoul(one, NULL, 0);
 

	
 
	idx = 0;
 
	for(;;) {
 
		// find end of item
 
		s = many;
 
		while (*s != '|' && *s != 0) s++;
 
		if (s - many == onelen && !memcmp(one, many, onelen)) return idx;
 
		if (*s == 0) return -1;
 
		many = s + 1;
 
		idx++;
 
	}
 
@@ -472,92 +472,92 @@ static void make_oneofmany(char *buf, co
 
static void make_manyofmany(char *buf, const char *many, uint32 x)
 
{
 
	const char *start;
 
	int i = 0;
 
	bool init = true;
 

	
 
	do {
 
		start = many;
 
		while (*many != 0 && *many != '|') many++;
 
		if (x & 1) {
 
			if (!init) *buf++ = '|';
 
			init = false;
 
			if (start == many) {
 
				buf += sprintf(buf, "%d", i);
 
			} else {
 
				memcpy(buf, start, many - start);
 
				buf += many - start;
 
			}
 
		}
 
		if (*many == '|') many++;
 
	} while (++i, x>>=1);
 
	*buf = 0;
 
}
 

	
 
static void *string_to_val(const SettingDesc *desc, const char *str)
 
static const void *string_to_val(const SettingDesc *desc, const char *str)
 
{
 
	unsigned long val;
 
	char *end;
 

	
 
	switch(desc->flags & 0xF) {
 
	case SDT_INTX:
 
		val = strtol(str, &end, 0);
 
		if (*end != 0) ShowInfoF("ini: trailing characters at end of setting '%s'", desc->name);
 
		return (void*)val;
 
	case SDT_ONEOFMANY: {
 
		int r = lookup_oneofmany((char*)desc->b, str, -1);
 
		if (r != -1) return (void*)r;
 
		ShowInfoF("ini: invalid value '%s' for '%s'", str, desc->name);
 
		return 0;
 
	}
 
	case SDT_MANYOFMANY: {
 
		uint32 r = lookup_manyofmany(desc->b, str);
 
		if (r != (uint32)-1) return (void*)r;
 
		ShowInfoF("ini: invalid value '%s' for '%s'", str, desc->name);
 
		return 0;
 
	}
 
	case SDT_BOOLX:
 
		if (!strcmp(str, "true") || !strcmp(str, "on") || !strcmp(str, "1"))
 
			return (void*)true;
 
		if (!strcmp(str, "false") || !strcmp(str, "off") || !strcmp(str, "0"))
 
			return (void*)false;
 
		ShowInfoF("ini: invalid setting value '%s' for '%s'", str, desc->name);
 
		break;
 

	
 
	case SDT_STRING:
 
	case SDT_STRINGBUF:
 
	case SDT_INTLIST:
 
		return (void*)str;
 
	}
 

	
 
	return NULL;
 
}
 

	
 
static void load_setting_desc(IniFile *ini, const SettingDesc *desc, void *grpname, void *base)
 
static void load_setting_desc(IniFile *ini, const SettingDesc *desc, const void *grpname, void *base)
 
{
 
	IniGroup *group_def = ini_getgroup(ini, grpname, -1), *group;
 
	IniItem *item;
 
	void *p;
 
	const void *p;
 
	void *ptr;
 

	
 
	for (;desc->name;desc++) {
 
		// group override?
 
		const char *s = strchr(desc->name, '.');
 
		if (s) {
 
			group = ini_getgroup(ini, desc->name, s - desc->name);
 
			s++;
 
		} else {
 
			s = desc->name;
 
			group = group_def;
 
		}
 

	
 
		item = ini_getitem(group, s, false);
 
		if (!item) {
 
			p = desc->def;
 
		} else {
 
			p = string_to_val(desc, item->value);
 
		}
 

	
 
		// get ptr to array
 
		ptr = desc->ptr;
 
		if ( (uint32)ptr < 0x10000)
 
			ptr = (byte*)base + (uint32)ptr;
 
@@ -582,53 +582,54 @@ static void load_setting_desc(IniFile *i
 
				*(uint32*)ptr = (uint32)p;
 
				break;
 
			default:
 
				NOT_REACHED();
 
			}
 
			break;
 
		case SDT_STRING:
 
			if (*(char**)ptr) free(*(char**)ptr);
 
			*(char**)ptr = strdup((char*)p);
 
			break;
 
		case SDT_STRINGBUF:
 
			if (p) ttd_strlcpy((char*)ptr, p, desc->flags >> 16);
 
			break;
 
		case SDT_INTLIST: {
 
			if (!load_intlist(p, ptr, desc->flags >> 16, desc->flags >> 4 & 7))
 
				ShowInfoF("ini: error in array '%s'", desc->name);
 
			break;
 
		}
 
		default:
 
			NOT_REACHED();
 
		}
 
	}
 
}
 

	
 
static void save_setting_desc(IniFile *ini, const SettingDesc *desc, void *grpname, void *base)
 
static void save_setting_desc(IniFile *ini, const SettingDesc *desc, const void *grpname, void *base)
 
{
 
	IniGroup *group_def = NULL, *group;
 
	IniItem *item;
 
	void *p, *ptr;
 
	const void *p;
 
	void *ptr;
 
	int i = 0;
 
	char buf[512]; // setting buffer
 
	const char *s;
 

	
 
	for (;desc->name;desc++) {
 
		if (desc->flags & SDT_NOSAVE)
 
			continue;
 

	
 
		// group override?
 
		s = strchr(desc->name, '.');
 
		if (s) {
 
			group = ini_getgroup(ini, desc->name, s - desc->name);
 
			s++;
 
		} else {
 
			if (group_def == NULL)
 
				group_def = ini_getgroup(ini, grpname, -1);
 
			s = desc->name;
 
			group = group_def;
 
		}
 

	
 
		item = ini_getitem(group, s, true);
 

	
 
		// get ptr to array
 
		ptr = desc->ptr;
 
@@ -862,49 +863,49 @@ static const SettingDesc patch_settings[
 

	
 
	{"keep_all_autosave",		SDT_BOOL,		(void*)false, (void*)offsetof(Patches, keep_all_autosave),		NULL},
 

	
 
	{"extra_dynamite",			SDT_BOOL,		(void*)false, (void*)offsetof(Patches, extra_dynamite),				NULL},
 

	
 
	{"never_expire_vehicles",SDT_BOOL,	(void*)false, (void*)offsetof(Patches, never_expire_vehicles),NULL},
 
	{"extend_vehicle_life",	SDT_UINT8,	(void*)0,			(void*)offsetof(Patches, extend_vehicle_life),	NULL},
 

	
 
	{"auto_euro",						SDT_BOOL,		(void*)true,	(void*)offsetof(Patches, auto_euro),						NULL},
 

	
 
	{"serviceathelipad",		SDT_BOOL,		(void*)true,	(void*)offsetof(Patches, serviceathelipad),			NULL},
 
	{"smooth_economy",			SDT_BOOL,		(void*)false, (void*)offsetof(Patches, smooth_economy),				NULL},
 
	{"dist_local_authority",SDT_UINT8,	(void*)20,		(void*)offsetof(Patches, dist_local_authority), NULL},
 

	
 
	{"wait_oneway_signal",	SDT_UINT8,	(void*)15,		(void*)offsetof(Patches, wait_oneway_signal),		NULL},
 
	{"wait_twoway_signal",	SDT_UINT8,	(void*)41,		(void*)offsetof(Patches, wait_twoway_signal),		NULL},
 

	
 
	{"ainew_active",				SDT_BOOL,		(void*)false, (void*)offsetof(Patches, ainew_active),					NULL},
 

	
 
	{"drag_signals_density",SDT_UINT8,	(void*)4,			(void*)offsetof(Patches, drag_signals_density), NULL},
 

	
 
	{NULL,									0,					NULL,					NULL,																						NULL}
 
};
 

	
 
typedef void SettingDescProc(IniFile *ini, const SettingDesc *desc, void *grpname, void *base);
 
typedef void SettingDescProc(IniFile *ini, const SettingDesc *desc, const void *grpname, void *base);
 

	
 
static void HandleSettingDescs(IniFile *ini, SettingDescProc *proc)
 
{
 
	proc(ini, misc_settings,		"misc",			NULL);
 
	proc(ini, win32_settings,		"win32",		NULL);
 
	proc(ini, network_settings, "network",	NULL);
 
	proc(ini, music_settings,		"music",		&msf);
 
	proc(ini, gameopt_settings, "gameopt",	&_new_opt);
 
	proc(ini, patch_settings,		"patches",	&_patches);
 

	
 
	proc(ini, debug_settings,		"debug",		NULL);
 
}
 

	
 
void LoadGrfSettings(IniFile *ini)
 
{
 
	IniGroup *group = ini_getgroup(ini, "newgrf", -1);
 
	IniItem *item;
 
	int i;
 

	
 
	if (!group)
 
		return;
 

	
 
	for(i=0; i!=lengthof(_newgrf_files); i++) {
 
		char buf[3];
station_cmd.c
Show inline comments
 
@@ -1722,97 +1722,97 @@ typedef struct DrawTileSeqStruct {
 
static void DrawTile_Station(TileInfo *ti)
 
{
 
	uint32 image_or_modificator;
 
	uint32 base_img, image;
 
	const DrawTileSeqStruct *dtss;
 
	const byte *t;
 

	
 
	// station_land array has been increased from 82 elements to 114
 
	// but this is something else. If AI builds station with 114 it looks all weird
 
	base_img = (_map3_lo[ti->tile] & 0xF) * 82;
 

	
 
	{
 
		uint owner = _map_owner[ti->tile];
 
		image_or_modificator = 0x315 << 16; /* NOTE: possible bug in ttd here? */
 
		if (owner < MAX_PLAYERS)
 
			image_or_modificator = PLAYER_SPRITE_COLOR(owner);
 
	}
 

	
 
	// don't show foundation for docks (docks are between 76 (0x4C) and 81 (0x51))
 
	if (ti->tileh != 0 && (ti->map5 < 0x4C || ti->map5 > 0x51))
 
		DrawFoundation(ti, ti->tileh);
 

	
 
	t = _station_display_datas[ti->map5];
 

	
 
	image = *(uint32*)t;
 
	image = *(const uint32*)t;
 
	t += sizeof(uint32);
 
	if (image & 0x8000)
 
		image |= image_or_modificator;
 
	DrawGroundSprite(image + base_img);
 

	
 
	for(dtss = (DrawTileSeqStruct *)t; (byte)dtss->delta_x != 0x80; dtss++) {
 
	for(dtss = (const DrawTileSeqStruct *)t; (byte)dtss->delta_x != 0x80; dtss++) {
 
		if ((byte)dtss->delta_z != 0x80) {
 
			image =	dtss->image + base_img;
 
			if (_display_opt & DO_TRANS_BUILDINGS) {
 
				if (image&0x8000) image |= image_or_modificator;
 
			} else {
 
				image = (image & 0x3FFF) | 0x03224000;
 
			}
 

	
 
			AddSortableSpriteToDraw(image, ti->x + dtss->delta_x, ti->y + dtss->delta_y, dtss->width, dtss->height, dtss->unk, ti->z + dtss->delta_z);
 
		} else {
 
			image = *(uint32*)&dtss->height + base_img; /* endian ok */
 
			image = *(const uint32*)&dtss->height + base_img; /* endian ok */
 

	
 
			if (_display_opt & DO_TRANS_BUILDINGS) {
 
				if (image&0x8000) image |= image_or_modificator;
 
			} else {
 
				image = (image & 0x3FFF) | 0x03224000;
 
			}
 
			AddChildSpriteScreen(image, dtss->delta_x, dtss->delta_y);
 
		}
 
	}
 
}
 

	
 
void StationPickerDrawSprite(int x, int y, int railtype, int image)
 
{
 
	uint32 ormod, img;
 
	const DrawTileSeqStruct *dtss;
 
	const byte *t;
 

	
 
	/* baseimage */
 
	railtype *= TRACKTYPE_SPRITE_PITCH;
 

	
 
	ormod = PLAYER_SPRITE_COLOR(_local_player);
 

	
 
	t = _station_display_datas[image];
 

	
 
	img = *(uint32*)t;
 
	img = *(const uint32*)t;
 
	t += sizeof(uint32);
 
	if (img & 0x8000)
 
		img |= ormod;
 
	DrawSprite(img, x, y);
 

	
 
	for(dtss = (DrawTileSeqStruct *)t; (byte)dtss->delta_x != 0x80; dtss++) {
 
	for(dtss = (const DrawTileSeqStruct *)t; (byte)dtss->delta_x != 0x80; dtss++) {
 
		Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z);
 
		DrawSprite((dtss->image | ormod) + railtype, x + pt.x, y + pt.y);
 
	}
 
}
 

	
 
static uint GetSlopeZ_Station(TileInfo *ti)
 
{
 
	uint z = ti->z;
 
	if (ti->tileh != 0)
 
		z += 8;
 
	return z;
 
}
 

	
 
static uint GetSlopeTileh_Station(TileInfo *ti)
 
{
 
	return 0;
 
}
 

	
 
static void GetAcceptedCargo_Station(uint tile, AcceptedCargo *ac)
 
{
 
	/* not used */
 
}
 

	
 
static void GetTileDesc_Station(uint tile, TileDesc *td)
station_gui.c
Show inline comments
 
@@ -33,51 +33,50 @@ static void StationsWndShowStationRating
 
	x -= (acceptance>>3);
 

	
 
	DrawString(x+1, y, _cargoc.names_short[type], 0x10);
 

	
 
	/* draw green/red ratings bar */
 
	GfxFillRect(x+1, y+8, x+7, y+8, 0xB8);
 

	
 
	rating = (rating >> 5);
 

	
 
	if (rating != 0) {
 
		GfxFillRect(x+1, y+8, x+rating, y+8, 0xD0);
 
	}
 
}
 

	
 
static SortStruct _station_sort[lengthof(_stations)];
 
static uint16 _num_station_sort[MAX_PLAYERS];
 

	
 
static char _bufcache[64];
 
static uint16 _last_station_idx;
 

	
 
static int CDECL StationNameSorter(const void *a, const void *b)
 
{
 
	char buf1[64];
 
	Station *st;
 
	SortStruct *cmp1, *cmp2;
 
	cmp1 = (SortStruct*)a;
 
	cmp2 = (SortStruct*)b;
 
	const SortStruct *cmp1 = (const SortStruct*)a;
 
	const SortStruct *cmp2 = (const SortStruct*)b;
 

	
 
	st = DEREF_STATION(cmp1->index);
 
	SET_DPARAM16(0, st->town->townnametype);
 
	SET_DPARAM32(1, st->town->townnameparts);
 
	GetString(buf1, st->string_id);
 

	
 
	if ( cmp2->index != _last_station_idx) {
 
		_last_station_idx = cmp2->index;
 
		st = DEREF_STATION(cmp2->index);
 
		SET_DPARAM16(0, st->town->townnametype);
 
		SET_DPARAM32(1, st->town->townnameparts);
 
		GetString(_bufcache, st->string_id);
 
	}
 

	
 
	return strcmp(buf1, _bufcache);	// sort by name
 
}
 

	
 
static void MakeSortedStationList(byte owner)
 
{
 
	SortStruct *firstelement;
 
	Station *st;
 
	uint32 n = 0;
 
	uint16 *i;
 
	// reset to 0 just to be sure
strgen/strgen.c
Show inline comments
 
@@ -22,49 +22,49 @@ extern char _openttd_revision[];
 
/* Compiles a list of strings into a compiled string list */
 

	
 
#define lengthof(x) (sizeof(x)/sizeof(x[0]))
 

	
 
typedef void (*ParseCmdProc)(char *buf, int value);
 

	
 
typedef struct {
 
	uint32 ident;
 
	uint32 version;			// 32-bits of auto generated version info which is basically a hash of strings.h
 
	char name[32];			// the international name of this language
 
	char own_name[32];	// the localized name of this language
 
	uint16 offsets[32];	// the offsets
 
} LanguagePackHeader;
 

	
 
typedef struct CmdStruct {
 
	const char *cmd;
 
	ParseCmdProc proc;
 
	long value;
 
} CmdStruct;
 

	
 
typedef struct LineName {
 
	struct LineName *hash_next;
 
	int value;
 
	char str[1];
 
} LineName; 
 
} LineName;
 

	
 
int _cur_line;
 
bool _warnings;
 

	
 
uint32 _hash;
 
char _lang_name[32], _lang_ownname[32];
 

	
 
#define HASH_SIZE 1023
 
LineName *_hash_head[HASH_SIZE];
 
unsigned int hash_str(const char *s) {
 
	unsigned int hash = 0;
 
	for(;*s;s++)
 
		hash = ((hash << 3) | (hash >> 29)) ^ *s;
 
	return hash % HASH_SIZE;
 
}
 
void hash_add(const char *s, int value) {
 
	unsigned int len = strlen(s);
 
	LineName *ln = (LineName*)malloc(sizeof(LineName) + len);
 
	unsigned int hash = hash_str(s);
 
	ln->hash_next = _hash_head[hash];
 
	_hash_head[hash] = ln;
 
	ln->value = value;
 
	ln->str[len] = 0;
 
	memcpy(ln->str, s, len);
 
@@ -197,81 +197,81 @@ void EmitSetXY(char *buf, int value) {
 
	char *err;
 
	int x = strtol(buf, &err, 0), y;
 
	if (*err != 0) error("SetXY param invalid");
 
	y = strtol(err+1, &err, 0);
 
	if (*err != 0) error("SetXY param invalid");
 

	
 
	put_byte(0x1F);
 
	put_byte((byte)x);
 
	put_byte((byte)y);
 
}
 

	
 
static const CmdStruct _cmd_structs[] = {
 
	// Update position
 
	{"SETX", EmitSetX, 1},
 
	{"SETXY", EmitSetXY, 2},
 

	
 
	// Font size
 
	{"TINYFONT", EmitSingleByte, 8},
 
	{"BIGFONT", EmitSingleByte, 9},
 

	
 
	// New line
 
	{"", EmitSingleByte, 10},
 

	
 
	// Colors
 
	{"BLUE", EmitSingleByte, 15},		
 
	{"BLUE", EmitSingleByte, 15},
 
	{"SILVER", EmitSingleByte, 16},
 
	{"GOLD", EmitSingleByte, 17},
 
	{"RED", EmitSingleByte, 18},
 
	{"PURPLE", EmitSingleByte, 19},
 
	{"LTBROWN", EmitSingleByte, 20},
 
	{"ORANGE", EmitSingleByte, 21},
 
	{"GREEN", EmitSingleByte, 22},
 
	{"YELLOW", EmitSingleByte, 23},
 
	{"DKGREEN", EmitSingleByte, 24},
 
	{"CREAM", EmitSingleByte, 25},
 
	{"BROWN", EmitSingleByte, 26},
 
	{"WHITE", EmitSingleByte, 27},
 
	{"LTBLUE", EmitSingleByte, 28},
 
	{"GRAY", EmitSingleByte, 29},
 
	{"DKBLUE", EmitSingleByte, 30},
 
	{"BLACK", EmitSingleByte, 31},
 
	
 

	
 
	// 0x7B=123 is the LAST special character we may use.
 

	
 
	// Numbers
 
	{"COMMA32", EmitSingleByte, 0x7B},
 
	{"COMMA16", EmitSingleByte, 0x7C},
 
	{"COMMA8", EmitSingleByte, 0x7D},
 
	{"NUMU16", EmitSingleByte, 0x7E},
 

	
 
	{"CURRENCY", EmitSingleByte, 0x7F},
 
	
 

	
 
	{"CURRCOMPACT", EmitEscapedByte, 0}, // compact currency
 
	{"INT32", EmitEscapedByte, 1}, // compact currency
 
	{"REV", EmitEscapedByte, 2}, // openttd revision string
 
	{"SHORTCARGO", EmitEscapedByte, 3}, // short cargo description, only ### tons, or ### litres
 
	
 

	
 
	{"STRINL", EmitStringInl, 0x81},
 

	
 
	{"DATE_LONG", EmitSingleByte, 0x82},
 
	{"DATE_SHORT", EmitSingleByte, 0x83},
 

	
 
	{"VELOCITY", EmitSingleByte, 0x84},
 
	{"SKIP16", EmitSingleByte, 0x85},
 
	{"SKIP", EmitSingleByte, 0x86},
 
	{"VOLUME", EmitSingleByte, 0x87},
 

	
 
	{"STRING", EmitSingleByte, 0x88},
 

	
 
	{"CARGO", EmitSingleByte, 0x99},
 
	{"STATION", EmitSingleByte, 0x9A},
 
	{"TOWN", EmitSingleByte, 0x9B},
 
	{"CURRENCY64", EmitSingleByte, 0x9C},
 
	{"CHECKPOINT", EmitSingleByte, 0x9D}, // checkpoint name
 
	// 0x9E=158 is the LAST special character we may use.
 

	
 
	{"UPARROW", EmitSingleByte, 0xA0},
 
	{"POUNDSIGN", EmitSingleByte, 0xA3},
 
	{"YENSIGN", EmitSingleByte, 0xA5},
 
	{"COPYRIGHT", EmitSingleByte, 0xA9},
 
	{"DOWNARROW", EmitSingleByte, 0xAA},
 
@@ -367,49 +367,49 @@ bool check_commands_match(char *a, char 
 
	const CmdStruct *ar, *br;
 
	char param[100];
 

	
 
	do {
 
		// read until next command from a.
 
		do {
 
			ar = parse_command_string(&a, param, NULL);
 
		} while (ar != NULL && (unsigned long)ar <= 255);
 

	
 
		// read until next command from b.
 
		do {
 
			br = parse_command_string(&b, param, NULL);
 
		} while (br != NULL && (unsigned long)br <= 255);
 

	
 
		// make sure they are identical
 
		if (ar != br) return false;
 
	} while (ar);
 

	
 
	return true;
 
}
 

	
 
void handle_string(char *str, bool master) {
 
	char *s,*t,*r;
 
	int ent;
 
		
 

	
 
	if (*str == '#') {
 
		if (str[1] == '#' && str[2] != '#')
 
			handle_pragma(str + 2);
 
		return;
 
	}
 

	
 
	// Ignore comments & blank lines
 
	if (*str == ';' || *str == ' ' || *str == 0)
 
		return;
 

	
 
	s = strchr(str, ':');
 
	if (s == NULL) {
 
		warning("Line has no ':' delimiter");
 
		return;
 
	}
 

	
 
	// Trim spaces
 
	for(t=s;t > str && (t[-1]==' ' || t[-1]=='\t'); t--);
 
	*t = 0;
 

	
 
	ent = hash_find(str);
 

	
 
	s++; // skip :
 

	
 
@@ -450,90 +450,90 @@ void handle_string(char *str, bool maste
 
		// check that the commands match
 
		if (!check_commands_match(s, allstr[ent] + 2 + strlen(allstr[ent] + 1))) {
 
			fprintf(stderr, "Warning: String name '%s' does not match the layout of the master string\n", str);
 
			_warnings = 0; // non-fatal
 
			return;
 
		}
 

	
 
		if (s[0] == ':' && s[1] == 0) {
 
			allstr[ent][0] = 0; // use string from master file legitiately
 
			free(r);
 
		} else {
 
			free(allstr[ent]);
 
			allstr[ent] = r;
 
		}
 
	}
 
}
 

	
 
uint32 my_hash_str(uint32 hash, const char *s)
 
{
 
	for(;*s;s++) {
 
		hash = ((hash << 3) | (hash >> 29)) ^ *s;
 
		if (hash & 1) hash = (hash>>1) ^ 0xDEADBEEF; else hash >>= 1;
 
	}
 
	return hash;
 
	
 

	
 
}
 

	
 
void parse_file(const char *file, bool english) {
 
	char buf[2048];
 
	int i;
 
	FILE *in;
 

	
 
	in = fopen(file, "r");
 
	if (in == NULL) { error("Cannot open file '%s'", file); }
 
	
 

	
 
	_cur_line = 1;
 
	while (fgets(buf, sizeof(buf),in) != NULL) {
 
		i = strlen(buf);
 
		while (i>0 && (buf[i-1]=='\r' || buf[i-1]=='\n' || buf[i-1] == ' ')) i--;
 
		buf[i] = 0;
 

	
 
		handle_string(buf, english);
 
		_cur_line++;
 
	}
 

	
 
	fclose(in);
 

	
 
	// make a hash of the file to get a unique "version number"
 
	if (english) {
 
		uint32 hash = 0;
 
		char *s;
 
		const CmdStruct *cs;
 
		for(i = 0; i!=65536; i++) {
 
			if ((s=allstr[i]) != NULL) {
 
				hash ^= i * 0x717239;
 
				if (hash & 1) hash = (hash>>1) ^ 0xDEADBEEF; else hash >>= 1;
 
				hash = my_hash_str(hash, s + 1);
 

	
 
				s = s + 2 + strlen(s + 1);
 
				while ((cs = parse_command_string(&s, buf, NULL)) != 0) {
 
					if ( (uint)cs >= 256) {
 
						hash ^= (cs - _cmd_structs) * 0x1234567;
 
						if (hash & 1) hash = (hash>>1) ^ 0xF00BAA4; else hash >>= 1;
 
					}
 
				}
 
			}	
 
			}
 
		}
 
		_hash = hash;
 
	}
 
}
 

	
 
int count_inuse(int grp) {
 
	int i;
 

	
 
	for(i=0x800; --i >= 0;) {
 
		if (allstr[(grp<<11)+i] != NULL)
 
			break;
 
	}
 
	return i + 1;
 
}
 

	
 
void check_all_used() {
 
	int i;
 
	LineName *ln;
 
	int num_warn = 10;
 

	
 
	for (i=0; i!=HASH_SIZE; i++) {
 
		for(ln = _hash_head[i]; ln!=NULL; ln = ln->hash_next) {
 
			if (allstr[ln->value] == 0) {
 
				if (++num_warn < 50) {
 
@@ -558,49 +558,49 @@ void write_length(FILE *f, uint length)
 
	}
 
}
 

	
 
void gen_output(FILE *f) {
 
	uint16 in_use[32];
 
	uint16 in_use_file[32];
 
	int i,j;
 
	int tot_str = 0;
 

	
 
	check_all_used();
 

	
 
	for(i=0; i!=32; i++) {
 
		int n = count_inuse(i);
 
		in_use[i] = n;
 
		in_use_file[i] = TO_LE16(n);
 
		tot_str += n;
 
	}
 

	
 
	fwrite(in_use_file, 32*sizeof(uint16), 1, f);
 

	
 
	for(i=0; i!=32; i++) {
 
		for(j=0; j!=in_use[i]; j++) {
 
			char *s = allstr[(i<<11)+j];
 
			if (s == NULL) error("Internal error, s==NULL");
 
			
 

	
 
			write_length(f, *(uint16*)s);
 
			fwrite(s + sizeof(uint16), *(uint16*)s , 1, f);
 
			tot_str--;
 
		}
 
	}
 

	
 
	fputc(0, f); // write trailing nul character.
 

	
 
	if (tot_str != 0) {
 
		error("Internal error, tot_str != 0");
 
	}
 
}
 

	
 
bool compare_files(const char *n1, const char *n2)
 
{
 
	FILE *f1, *f2;
 
	char b1[4096];
 
	char b2[4096];
 
	size_t l1, l2;
 

	
 
	f2 = fopen(n2, "rb");
 
	if (f2 == NULL) return false;
 

	
 
	f1 = fopen(n1, "rb");
 
@@ -621,119 +621,119 @@ bool compare_files(const char *n1, const
 
	fclose(f1);
 
	return true;
 
}
 

	
 
void write_strings_h(const char *filename)
 
{
 
	FILE *out;
 
	int i;
 
	int next = -1;
 
	int lastgrp;
 

	
 
	out = fopen("tmp.xxx", "w");
 
	if (out == NULL) { error("can't open tmp.xxx"); }
 

	
 
	fprintf(out, "enum {");
 

	
 
	lastgrp = 0;
 

	
 
	for(i = 0; i!=65536; i++) {
 
		if (allstr[i]) {
 
			if (lastgrp != (i >> 11)) {
 
				lastgrp = (i >> 11);
 
				fprintf(out, "};\n\nenum {");
 
			}
 
			
 

	
 
			fprintf(out, next == i ? "%s,\n" : "\n%s = 0x%X,\n", allstr[i] + 1, i);
 
			next = i + 1;
 
		}
 
	}
 

	
 
	fprintf(out, "};\n");
 

	
 
	fprintf(out, 
 
	fprintf(out,
 
		"\nenum {\n"
 
		"\tLANGUAGE_PACK_IDENT = 0x474E414C, // Big Endian value for 'LANG' (LE is 0x 4C 41 4E 47)\n"
 
		"\tLANGUAGE_PACK_VERSION = 0x%X,\n"
 
		"};\n", (unsigned int)_hash);
 

	
 

	
 
	fclose(out);
 

	
 
	if (compare_files("tmp.xxx", filename)) {
 
		// files are equal. tmp.xxx is not needed
 
		unlink("tmp.xxx");
 
	} else {
 
		// else rename tmp.xxx into filename
 
#if defined(WIN32)
 
		unlink(filename);
 
#endif
 
		if (rename("tmp.xxx", filename) == -1) error("rename() failed");
 
	}
 
}
 

	
 
void write_langfile(const char *filename, int show_todo)
 
{
 
	FILE *f;
 
	int in_use[32];
 
	LanguagePackHeader hdr;
 
	int i,j;
 
	const CmdStruct *cs;
 
	char param[128];
 

	
 
	f = fopen(filename, "wb");
 
	if (f == NULL) error("can't open %s", filename);
 

	
 
	memset(&hdr, 0, sizeof(hdr));
 
	for(i=0; i!=32; i++) {
 
		int n = count_inuse(i);
 
		in_use[i] = n;
 
		hdr.offsets[i] = TO_LE16(n);
 
	}
 

	
 
	// see line 655: fprintf(..."\tLANGUAGE_PACK_IDENT = 0x474E414C,...) 
 
	// see line 655: fprintf(..."\tLANGUAGE_PACK_IDENT = 0x474E414C,...)
 
	hdr.ident = TO_LE32(0x474E414C); // Big Endian value for 'LANG'
 
	hdr.version = TO_LE32(_hash);
 
	strcpy(hdr.name, _lang_name);
 
	strcpy(hdr.own_name, _lang_ownname);
 

	
 
	fwrite(&hdr, sizeof(hdr), 1, f);
 

	
 
	for(i=0; i!=32; i++) {
 
		for(j=0; j!=in_use[i]; j++) {
 
			char *s = allstr[(i<<11)+j], *str;
 

	
 
			if (s == NULL) {
 
				write_length(f, 0);
 
			} else {
 
				// move to string
 
				str = s + 2 + strlen(s + 1);
 

	
 
				if (show_todo && s[0]) {
 
					if (show_todo == 2) {
 
						fprintf(stderr, "Warning:%s: String '%s' is untranslated\n", filename, s + 1);
 
					} else {
 
						char *s = "<TODO> ";
 
						const char *s = "<TODO> ";
 
						while(*s) put_byte(*s++);
 
					}
 
				}
 

	
 
				for(;;) {
 
					cs = parse_command_string(&str, param, s[0] ? "english.lng" : filename);
 
					if (cs == NULL) break;
 
					if ( (unsigned long) cs <= 255) {
 
						put_byte( (byte) (int)cs);
 
					} else {
 
						cs->proc(param, cs->value);
 
					}
 
				}
 

	
 
				write_length(f, _put_pos);
 
				fwrite(_put_buf, 1, _put_pos, f);
 
				_put_pos = 0;
 
			}
 
		}
 
	}
 

	
 
	fputc(0, f);
 

	
 
	fclose(f);
 
@@ -748,44 +748,44 @@ int main(int argc, char* argv[])
 
	if (argc > 1 && (!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version"))) {
 
#ifdef WITH_REV
 
		puts((char*)_openttd_revision);
 
#endif
 
		return 0;
 
	}
 

	
 
	if (argc > 1 && !strcmp(argv[1], "-t")) {
 
		show_todo = 1;
 
		argc--, argv++;
 
	}
 

	
 
	if (argc > 1 && !strcmp(argv[1], "-w")) {
 
		show_todo = 2;
 
		argc--, argv++;
 
	}
 

	
 

	
 
	if (argc == 1) {
 
		// parse master file
 
		parse_file("lang/english.txt", true);
 
		if (_warnings) return 1;
 

	
 
		// write english.lng and strings.h
 
		
 

	
 
		write_langfile("lang/english.lng", 0);
 
		write_strings_h("table/strings.h");
 
		
 

	
 
	} else if (argc == 2) {
 
		parse_file("lang/english.txt", true);
 
		parse_file(argv[1], false);
 
		if (_warnings) return 1;
 
		strcpy(buf, argv[1]);
 
		r = strrchr(buf, '.');
 
		if (!r || strcmp(r, ".txt")) r = strchr(buf, 0);
 
		strcpy(r, ".lng");
 
		write_langfile(buf, show_todo);
 
	} else {
 
		fprintf(stderr, "invalid arguments\n");
 
	}
 

	
 
	return 0;
 
}
 

	
table/landscape_const.h
Show inline comments
 
@@ -45,49 +45,49 @@ static const LandscapePredefVar _landsca
 
			{27, 29, 28, 30, 31, 32, 33, 34, 35, 36, 37, 38},
 
			{57, 59, 58, 60, 61, 62, 63, 64, 65, 66, 67, 68},
 
			{89, 91, 90, 92, 93, 94, 95, 96, 97, 98, 99, 100}
 
		},
 

	
 
		/* normal road veh by cargo start & count */
 
		{116, 123, 126, 132, 135, 138, 141, 144, 147, 150, 153, 156},
 
		{7, 3, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3}
 
	},
 

	
 
	{
 
		/* hilly names */
 
		{
 
			STR_000F_PASSENGERS,
 
			STR_0010_COAL,
 
			STR_0011_MAIL,
 
			STR_0012_OIL,
 
			STR_0013_LIVESTOCK,
 
			STR_0014_GOODS,
 
			STR_0022_WHEAT,
 
			STR_0016_WOOD,
 
			STR_000E,
 
			STR_001F_PAPER,
 
			STR_0020_GOLD,
 
			STR_001E_FOOD,			
 
			STR_001E_FOOD,
 
		},
 
		/* hilly weights */
 
		{
 
			1, 16, 4, 16, 3, 8, 16, 16, 0, 16, 8, 16
 
		},
 

	
 
		/* hilly sprites */
 
		{
 
			0x10C9, 0x10CA, 0x10CB, 0x10CC, 0x10CD, 0x10CE, 0x10CF, 0x10D0, 0x2, 0x10D9, 0x10D3, 0x10D8
 
		},
 

	
 
		/* hilly initial cargo payment */
 
		{
 
			3185, 5916, 4550, 4437, 4322, 6144, 4778, 5005, 5120, 5461, 5802, 5688
 
		},
 

	
 
		/* hilly transit days table 1 */
 
		{
 
			0, 7, 20, 25, 4, 5, 4, 15, 9, 7, 10, 0,
 
		},
 

	
 
		/* hilly transit days table 2 */
 
		{
 
			24, 255, 90, 255, 18, 28, 40, 255, 255, 60, 40, 30
table/landscape_sprite.h
Show inline comments
 
@@ -111,56 +111,56 @@ static const SpriteID _landscape_spritei
 
 0x2D0,  0x2D0,
 
 0xAA5,  0xAA6,
 
 0x50F,  0x50F,
 
 0x2EA,  0x2EA,
 
 0x2ED,  0x2EE,
 
 0x512,  0x513,
 
 0x4EB,  0x4EE,
 
 0x4E7,  0x4EA,
 
 0x985,  0xA28,
 
0x10E4, 0x1133,
 
 0x93D,  0x95C,
 
 0x97D,  0x984,
 
 0x7DA,  0x7DA,
 
 0x2E6,  0x2E6,
 
   0x1,    0x1,
 
 0xE54,  0xE54,
 
 0x51F,  0x520,
 
 0x514,  0x514,
 
 0x511,  0x511,
 
 0x322,  0x322,
 
 0xffff,
 
};
 

	
 

	
 
/* Slope graphics indexes temperate climate 
 
/* Slope graphics indexes temperate climate
 
Skip first 3 sprites and only load the proper set */
 
static const SpriteID _slopes_spriteindexes_0[] = {
 
 0xfffe,  3,
 
 SPR_SLOPES_BASE, SPR_SLOPES_BASE+73,
 
 0xffff,
 
};
 

	
 
/* Slope graphics indexes arctic climate
 
Skip first 79 sprites and only load the proper set */
 
static const SpriteID _slopes_spriteindexes_1[] = {
 
 0xfffe,  79,
 
 SPR_SLOPES_BASE, SPR_SLOPES_BASE+73,
 
 0xffff,
 
};
 

	
 
/* Slope graphics indexes tropical climate 
 
/* Slope graphics indexes tropical climate
 
Skip first 155 sprites and only load the proper set */
 
static const SpriteID _slopes_spriteindexes_2[] = {
 
 0xfffe,  155,
 
 SPR_SLOPES_BASE, SPR_SLOPES_BASE+73,
 
 0xffff,
 
};
 

	
 
/* Slope graphics indexes toyland climate
 
Skip first 231 sprites and only load the proper set */
 
static const SpriteID _slopes_spriteindexes_3[] = {
 
 0xfffe,  231,
 
 SPR_SLOPES_BASE, SPR_SLOPES_BASE+73,
 
 0xffff,
 
};
 

	
table/palettes.h
Show inline comments
 
byte _palettes[4][256 * 3] = {
 
/* palette 1 */
 
{
 
0,   0,   0,   212,   0, 212,   212,   0, 212,   212,   0, 212, 
 
212,   0, 212,   212,   0, 212,   212,   0, 212,   212,   0, 212, 
 
212,   0, 212,   212,   0, 212,   168, 168, 168,   184, 184, 184, 
 
200, 200, 200,   216, 216, 216,   232, 232, 232,   252, 252, 252, 
 
 52,  60,  72,    68,  76,  92,    88,  96, 112,   108, 116, 132, 
 
132, 140, 152,   156, 160, 172,   176, 184, 196,   204, 208, 220, 
 
 48,  44,   4,    64,  60,  12,    80,  76,  20,    96,  92,  28, 
 
120, 120,  64,   148, 148, 100,   176, 176, 132,   204, 204, 168, 
 
100, 100, 100,   116, 116, 116,   104,  80,  44,   124, 104,  72, 
 
152, 132,  92,   184, 160, 120,   212, 188, 148,   244, 220, 176, 
 
132, 132, 132,    88,   4,  16,   112,  16,  32,   136,  32,  52, 
 
160,  56,  76,   188,  84, 108,   204, 104, 124,   220, 132, 144, 
 
236, 156, 164,   252, 188, 192,   252, 212,   0,   252, 232,  60, 
 
252, 248, 128,    76,  40,   0,    96,  60,   8,   116,  88,  28, 
 
136, 116,  56,   156, 136,  80,   176, 156, 108,   196, 180, 136, 
 
 68,  24,   0,    96,  44,   4,   128,  68,   8,   156,  96,  16, 
 
184, 120,  24,   212, 156,  32,   232, 184,  16,   252, 212,   0, 
 
252, 248, 128,   252, 252, 192,    32,   4,   0,    64,  20,   8, 
 
 84,  28,  16,   108,  44,  28,   128,  56,  40,   148,  72,  56, 
 
168,  92,  76,   184, 108,  88,   196, 128, 108,   212, 148, 128, 
 
  8,  52,   0,    16,  64,   0,    32,  80,   4,    48,  96,   4, 
 
 64, 112,  12,    84, 132,  20,   104, 148,  28,   128, 168,  44, 
 
 64,  64,  64,    44,  68,  32,    60,  88,  48,    80, 104,  60, 
 
104, 124,  76,   128, 148,  92,   152, 176, 108,   180, 204, 124, 
 
 16,  52,  24,    32,  72,  44,    56,  96,  72,    76, 116,  88, 
 
 96, 136, 108,   120, 164, 136,   152, 192, 168,   184, 220, 200, 
 
 32,  24,   0,    56,  28,   0,    80,  80,  80,    88,  52,  12, 
 
104,  64,  24,   124,  84,  44,   140, 108,  64,   160, 128,  88, 
 
 76,  40,  16,    96,  52,  24,   116,  68,  40,   136,  84,  56, 
 
164,  96,  64,   184, 112,  80,   204, 128,  96,   212, 148, 112, 
 
224, 168, 128,   236, 188, 148,    80,  28,   4,   100,  40,  20, 
 
120,  56,  40,   140,  76,  64,   160, 100,  96,   184, 136, 136, 
 
 36,  40,  68,    48,  52,  84,    64,  64, 100,    80,  80, 116, 
 
100, 100, 136,   132, 132, 164,   172, 172, 192,   212, 212, 224, 
 
 48,  48,  48,    64,  44, 144,    88,  64, 172,   104,  76, 196, 
 
120,  88, 224,   140, 104, 252,   160, 136, 252,   188, 168, 252, 
 
  0,  24, 108,     0,  36, 132,     0,  52, 160,     0,  72, 184, 
 
  0,  96, 212,    24, 120, 220,    56, 144, 232,    88, 168, 240, 
 
128, 196, 252,   188, 224, 252,    16,  64,  96,    24,  80, 108, 
 
 40,  96, 120,    52, 112, 132,    80, 140, 160,   116, 172, 192, 
 
156, 204, 220,   204, 240, 252,   172,  52,  52,   212,  52,  52, 
 
252,  52,  52,   252, 100,  88,   252, 144, 124,   252, 184, 160, 
 
252, 216, 200,   252, 244, 236,    72,  20, 112,    92,  44, 140, 
 
112,  68, 168,   140, 100, 196,   168, 136, 224,   204, 180, 252, 
 
204, 180, 252,   232, 208, 252,    60,   0,   0,    92,   0,   0, 
 
128,   0,   0,   160,   0,   0,   196,   0,   0,   224,   0,   0, 
 
252,   0,   0,   252,  80,   0,   252, 108,   0,   252, 136,   0, 
 
252, 164,   0,   252, 192,   0,   252, 220,   0,   252, 252,   0, 
 
204, 136,   8,   228, 144,   4,   252, 156,   0,   252, 176,  48, 
 
252, 196, 100,   252, 216, 152,     8,  24,  88,    12,  36, 104, 
 
 20,  52, 124,    28,  68, 140,    40,  92, 164,    56, 120, 188, 
 
 72, 152, 216,   100, 172, 224,    92, 156,  52,   108, 176,  64, 
 
124, 200,  76,   144, 224,  92,   224, 244, 252,   204, 240, 252, 
 
180, 220, 236,   132, 188, 216,    88, 152, 172,    16,  16,  16, 
 
 32,  32,  32,     8,  92, 104,    16, 100, 112,    24, 108, 120, 
 
 32, 116, 128,    44, 124, 140,    92, 164, 184,   116, 180, 196, 
 
148, 200, 216,   180, 220, 232,   216, 244, 252,     0,   0,   0, 
 
  0,   0,   0,     0,   0,   0,     0,   0,   0,     0,   0,   0, 
 
252,  60,   0,   252,  80,   0,   252, 104,   0,   252, 128,   0, 
 
252, 148,   0,   252, 172,   0,   252, 196,   0,   252,   0,   0, 
 
252,   0,   0,     0,   0,   0,     0,   0,   0,     0,   0,   0, 
 
252, 228,   0,   148, 148, 148,   212,   0, 212,   212,   0, 212, 
 
212,   0, 212,   212,   0, 212,   212,   0, 212,   212,   0, 212, 
 
212,   0, 212,   212,   0, 212,   212,   0, 212,   252, 252, 252, 
 
0,   0,   0,   212,   0, 212,   212,   0, 212,   212,   0, 212,
 
212,   0, 212,   212,   0, 212,   212,   0, 212,   212,   0, 212,
 
212,   0, 212,   212,   0, 212,   168, 168, 168,   184, 184, 184,
 
200, 200, 200,   216, 216, 216,   232, 232, 232,   252, 252, 252,
 
 52,  60,  72,    68,  76,  92,    88,  96, 112,   108, 116, 132,
 
132, 140, 152,   156, 160, 172,   176, 184, 196,   204, 208, 220,
 
 48,  44,   4,    64,  60,  12,    80,  76,  20,    96,  92,  28,
 
120, 120,  64,   148, 148, 100,   176, 176, 132,   204, 204, 168,
 
100, 100, 100,   116, 116, 116,   104,  80,  44,   124, 104,  72,
 
152, 132,  92,   184, 160, 120,   212, 188, 148,   244, 220, 176,
 
132, 132, 132,    88,   4,  16,   112,  16,  32,   136,  32,  52,
 
160,  56,  76,   188,  84, 108,   204, 104, 124,   220, 132, 144,
 
236, 156, 164,   252, 188, 192,   252, 212,   0,   252, 232,  60,
 
252, 248, 128,    76,  40,   0,    96,  60,   8,   116,  88,  28,
 
136, 116,  56,   156, 136,  80,   176, 156, 108,   196, 180, 136,
 
 68,  24,   0,    96,  44,   4,   128,  68,   8,   156,  96,  16,
 
184, 120,  24,   212, 156,  32,   232, 184,  16,   252, 212,   0,
 
252, 248, 128,   252, 252, 192,    32,   4,   0,    64,  20,   8,
 
 84,  28,  16,   108,  44,  28,   128,  56,  40,   148,  72,  56,
 
168,  92,  76,   184, 108,  88,   196, 128, 108,   212, 148, 128,
 
  8,  52,   0,    16,  64,   0,    32,  80,   4,    48,  96,   4,
 
 64, 112,  12,    84, 132,  20,   104, 148,  28,   128, 168,  44,
 
 64,  64,  64,    44,  68,  32,    60,  88,  48,    80, 104,  60,
 
104, 124,  76,   128, 148,  92,   152, 176, 108,   180, 204, 124,
 
 16,  52,  24,    32,  72,  44,    56,  96,  72,    76, 116,  88,
 
 96, 136, 108,   120, 164, 136,   152, 192, 168,   184, 220, 200,
 
 32,  24,   0,    56,  28,   0,    80,  80,  80,    88,  52,  12,
 
104,  64,  24,   124,  84,  44,   140, 108,  64,   160, 128,  88,
 
 76,  40,  16,    96,  52,  24,   116,  68,  40,   136,  84,  56,
 
164,  96,  64,   184, 112,  80,   204, 128,  96,   212, 148, 112,
 
224, 168, 128,   236, 188, 148,    80,  28,   4,   100,  40,  20,
 
120,  56,  40,   140,  76,  64,   160, 100,  96,   184, 136, 136,
 
 36,  40,  68,    48,  52,  84,    64,  64, 100,    80,  80, 116,
 
100, 100, 136,   132, 132, 164,   172, 172, 192,   212, 212, 224,
 
 48,  48,  48,    64,  44, 144,    88,  64, 172,   104,  76, 196,
 
120,  88, 224,   140, 104, 252,   160, 136, 252,   188, 168, 252,
 
  0,  24, 108,     0,  36, 132,     0,  52, 160,     0,  72, 184,
 
  0,  96, 212,    24, 120, 220,    56, 144, 232,    88, 168, 240,
 
128, 196, 252,   188, 224, 252,    16,  64,  96,    24,  80, 108,
 
 40,  96, 120,    52, 112, 132,    80, 140, 160,   116, 172, 192,
 
156, 204, 220,   204, 240, 252,   172,  52,  52,   212,  52,  52,
 
252,  52,  52,   252, 100,  88,   252, 144, 124,   252, 184, 160,
 
252, 216, 200,   252, 244, 236,    72,  20, 112,    92,  44, 140,
 
112,  68, 168,   140, 100, 196,   168, 136, 224,   204, 180, 252,
 
204, 180, 252,   232, 208, 252,    60,   0,   0,    92,   0,   0,
 
128,   0,   0,   160,   0,   0,   196,   0,   0,   224,   0,   0,
 
252,   0,   0,   252,  80,   0,   252, 108,   0,   252, 136,   0,
 
252, 164,   0,   252, 192,   0,   252, 220,   0,   252, 252,   0,
 
204, 136,   8,   228, 144,   4,   252, 156,   0,   252, 176,  48,
 
252, 196, 100,   252, 216, 152,     8,  24,  88,    12,  36, 104,
 
 20,  52, 124,    28,  68, 140,    40,  92, 164,    56, 120, 188,
 
 72, 152, 216,   100, 172, 224,    92, 156,  52,   108, 176,  64,
 
124, 200,  76,   144, 224,  92,   224, 244, 252,   204, 240, 252,
 
180, 220, 236,   132, 188, 216,    88, 152, 172,    16,  16,  16,
 
 32,  32,  32,     8,  92, 104,    16, 100, 112,    24, 108, 120,
 
 32, 116, 128,    44, 124, 140,    92, 164, 184,   116, 180, 196,
 
148, 200, 216,   180, 220, 232,   216, 244, 252,     0,   0,   0,
 
  0,   0,   0,     0,   0,   0,     0,   0,   0,     0,   0,   0,
 
252,  60,   0,   252,  80,   0,   252, 104,   0,   252, 128,   0,
 
252, 148,   0,   252, 172,   0,   252, 196,   0,   252,   0,   0,
 
252,   0,   0,     0,   0,   0,     0,   0,   0,     0,   0,   0,
 
252, 228,   0,   148, 148, 148,   212,   0, 212,   212,   0, 212,
 
212,   0, 212,   212,   0, 212,   212,   0, 212,   212,   0, 212,
 
212,   0, 212,   212,   0, 212,   212,   0, 212,   252, 252, 252,
 
}};
 

	
 
#define GET_PALETTE(x) _palettes[x]
 

	
 
typedef struct {
 
	byte a[15];
 
	byte ac[15];
 
	byte lighthouse[12];
 
	byte oil_ref[21];
 
	byte e[15];
 
	byte b[45];
 
	byte bc[45];
 
} ExtraPaletteValues;
 

	
 
static const ExtraPaletteValues _extra_palette_values = {
 
	{32, 68,112, 36, 72,116, 40, 76,120, 44, 80,124, 48, 84,128},
 
	{28,108,124, 32,112,128, 36,116,132, 40,120,136, 44,124,140},
 
	{240,208,  0,  0,  0,  0,  0,  0,	0,  0,  0,  0},
 
	{252, 60,  0,252, 84,  0,252,108,  0,252,124,  0,252,148,  0,
 
	 252,172,  0,252,196,  0},
 
	{ 76, 24,  8,108, 44, 24,144, 72, 52,176,108, 84,212,148,128},
 
	{216,244,252,172,208,224,132,172,196,100,132,168, 72,100,144,
 
	  72,100,144, 72,100,144, 72,100,144, 72,100,144, 72,100,144,
 
		72,100,144, 72,100,144,100,132,168,132,172,196,172,208,224},
table/road_land.h
Show inline comments
 
@@ -22,49 +22,49 @@ static const byte _road_display_datas_2[
 
	TILE_SEQ_END()
 
};
 

	
 
static const byte _road_display_datas_3[] = {
 
	TILE_SEQ_BEGIN(0xA4A)
 
	TILE_SEQ_LINE(0x8585, 15, 0, 1, 16)
 
	TILE_SEQ_END()
 
};
 

	
 
static const byte * const _road_display_datas[4] = {
 
	_road_display_datas_0,
 
	_road_display_datas_1,
 
	_road_display_datas_2,
 
	_road_display_datas_3,
 
};
 

	
 

	
 
static const SpriteID _road_tile_sprites_1[16] = {
 
	0, 0x546, 0x545, 0x53B, 0x544, 0x534, 0x53E, 0x539,
 
  0x543, 0x53C, 0x535, 0x538, 0x53D, 0x537, 0x53A, 0x536
 
};
 

	
 

	
 

	
 
#define MAKELINE(a,b,c) ADD_WORD(a), b, c, 
 
#define MAKELINE(a,b,c) ADD_WORD(a), b, c,
 
static const byte _road_display_datas2_0[] = {
 
	0,0
 
};
 

	
 
static const byte _road_display_datas2_1[] = {
 
	0,0
 
};
 

	
 
static const byte _road_display_datas2_2[] = {
 
	0,0
 
};
 

	
 
static const byte _road_display_datas2_3[] = {
 
	MAKELINE(0x57f,1,8)
 
	0,0
 
};
 

	
 
static const byte _road_display_datas2_4[] = {
 
	0,0
 
};
 

	
 
static const byte _road_display_datas2_5[] = {
 
	MAKELINE(0x57f,1,8)
 
	MAKELINE(0x57e,14,8)
table/station_land.h
Show inline comments
 
@@ -515,93 +515,93 @@ static const byte _station_display_datas
 

	
 
static const byte _station_display_datas_79[] = {
 
	TILE_SEQ_BEGIN(0xFE2)
 
	TILE_SEQ_LINE(  4,  0,  0,  8, 16,  8, 0xAAA)
 
	TILE_SEQ_END()
 
};
 

	
 
static const byte _station_display_datas_80[] = {
 
	TILE_SEQ_BEGIN(0xFDD)
 
	TILE_SEQ_LINE(  0,  4,  0, 16,  8,  8, 0xAAB)
 
	TILE_SEQ_END()
 
};
 

	
 
static const byte _station_display_datas_81[] = {
 
	TILE_SEQ_BEGIN(0xFDD)
 
	TILE_SEQ_LINE(  4,  0,  0,  8, 16,  8, 0xAAC)
 
	TILE_SEQ_END()
 
};
 

	
 
static const byte _station_display_datas_82[] = {
 
	TILE_SEQ_BEGIN(0xFEC)
 
	TILE_SEQ_END()
 
};
 

	
 
// end of runway 
 
// end of runway
 
const byte _station_display_datas_083[] = {
 
	TILE_SEQ_BEGIN(0xA59)
 
	TILE_SEQ_END()
 
};
 

	
 
// runway tiles
 
const byte _station_display_datas_084[] = {
 
	TILE_SEQ_BEGIN(0xA56)
 
	TILE_SEQ_END()
 
};
 

	
 
// control tower with concrete underground and no fence
 
const byte _station_display_datas_085[] = {
 
	TILE_SEQ_BEGIN(0xA4A) // concrete underground
 
	TILE_SEQ_LINE(  3,  3,  0, 10, 10, 60, 0x8A5B)  // control tower
 
	TILE_SEQ_END()
 
};
 

	
 
// new airportdepot, facing west
 
const byte _station_display_datas_086[] = {
 
	TILE_SEQ_BEGIN(0xA4A)
 
	TILE_SEQ_LINE( 14, 0,  0,  2, 16, 28, 0x8A61)
 
	TILE_SEQ_LINE(  0, 0,  0,  2, 16, 28, 0xA62)
 
	TILE_SEQ_END()
 
};
 

	
 
// asphalt tile with fences in north
 
const byte _station_display_datas_087[] = {
 
	TILE_SEQ_BEGIN(0xA4A)
 
	TILE_SEQ_LINE( 0,  0, 0,  1, 16,  6, 0x8A67)
 
	TILE_SEQ_END()
 
};
 

	
 
// end of runway 
 
// end of runway
 
const byte _station_display_datas_088[] = {
 
	TILE_SEQ_BEGIN(0xA59)
 
	TILE_SEQ_LINE(  0,  0,  0, 16,  1,  6, 0x8A68) // fences
 
	TILE_SEQ_END()
 
};
 

	
 
// runway tiles
 
const byte _station_display_datas_089[] = {
 
	TILE_SEQ_BEGIN(0xA56)
 
	TILE_SEQ_LINE(  0,  0,  0, 16,  1,  6, 0x8A68) // fences	
 
	TILE_SEQ_LINE(  0,  0,  0, 16,  1,  6, 0x8A68) // fences
 
	TILE_SEQ_END()
 
};
 

	
 
// turning radar with concrete underground fences on south -- needs 12 tiles
 
//BEGIN
 
const byte _station_display_datas_090[] = {
 
	TILE_SEQ_BEGIN(0xA4A) // concrete underground
 
	TILE_SEQ_LINE(  7,  7,  0,  2,  2,  8, 0xA78)   // turning radar
 
	TILE_SEQ_LINE(15,  0,  0,  1, 16,  6, 0x8A67)  //fences
 
	TILE_SEQ_END()
 
};
 

	
 
const byte _station_display_datas_091[] = {
 
	TILE_SEQ_BEGIN(0xA4A) // concrete underground
 
	TILE_SEQ_LINE(  7,  7,  0,  2,  2,  8, 0xA79)
 
	TILE_SEQ_LINE( 15,  0, 0,  1, 16,  6, 0x8A67)
 
	TILE_SEQ_END()
 
};
 

	
 
const byte _station_display_datas_092[] = {
 
	TILE_SEQ_BEGIN(0xA4A) // concrete underground
 
	TILE_SEQ_LINE(  7,  7,  0,  2,  2,  8, 0xA7A)
 
	TILE_SEQ_LINE( 15,  0, 0,  1, 16,  6, 0x8A67)
 
	TILE_SEQ_END()
 
@@ -836,50 +836,50 @@ static const byte * const _station_displ
 
	_station_display_datas_66,
 
	_station_display_datas_67,
 
	_station_display_datas_68,
 
	_station_display_datas_69,
 
	_station_display_datas_70,
 
	_station_display_datas_71,
 
	_station_display_datas_72,
 
	_station_display_datas_73,
 
	_station_display_datas_74,
 
	_station_display_datas_75,
 
	_station_display_datas_76,
 
	_station_display_datas_77,
 
	_station_display_datas_78,
 
	_station_display_datas_79,
 
	_station_display_datas_80,
 
	_station_display_datas_81,
 
	_station_display_datas_82,
 
	_station_display_datas_083,
 
	_station_display_datas_084,
 
	_station_display_datas_085,
 
	_station_display_datas_086,
 
	_station_display_datas_087,
 
	_station_display_datas_088,
 
	_station_display_datas_089,
 
	_station_display_datas_090,		
 
	_station_display_datas_091,	
 
	_station_display_datas_092,	
 
	_station_display_datas_093,	
 
	_station_display_datas_094,	
 
	_station_display_datas_095,	
 
	_station_display_datas_096,	
 
	_station_display_datas_097,	
 
	_station_display_datas_098,	
 
	_station_display_datas_099,	
 
	_station_display_datas_090,
 
	_station_display_datas_091,
 
	_station_display_datas_092,
 
	_station_display_datas_093,
 
	_station_display_datas_094,
 
	_station_display_datas_095,
 
	_station_display_datas_096,
 
	_station_display_datas_097,
 
	_station_display_datas_098,
 
	_station_display_datas_099,
 
	_station_display_datas_0100,
 
	_station_display_datas_0101,		
 
	_station_display_datas_0102,		
 
	_station_display_datas_0103,	
 
	_station_display_datas_0104,	
 
	_station_display_datas_0105,	
 
	_station_display_datas_0106,	
 
	_station_display_datas_0107,	
 
	_station_display_datas_0108,	
 
	_station_display_datas_0109,	
 
	_station_display_datas_0110,	
 
	_station_display_datas_0111,	
 
	_station_display_datas_0101,
 
	_station_display_datas_0102,
 
	_station_display_datas_0103,
 
	_station_display_datas_0104,
 
	_station_display_datas_0105,
 
	_station_display_datas_0106,
 
	_station_display_datas_0107,
 
	_station_display_datas_0108,
 
	_station_display_datas_0109,
 
	_station_display_datas_0110,
 
	_station_display_datas_0111,
 
	_station_display_datas_0112,
 
	_station_display_datas_0113,
 
  _station_display_datas_0114,
 
};
table/train_cmd.h
Show inline comments
 
static const SpriteID _engine_sprite_base[] = {
 
0x0B59, 0x0B61, 0x0B69, 0x0BE1, 0x0B71, 0x0B75, 0x0B7D, 0x0B7D, 
 
0x0B85, 0x0B85, 0x0B8D, 0x0B8D, 0x0BC9, 0x0BD1, 0x0BD9, 0x0BE9, 
 
0x0BED, 0x0BED, 0x0BF5, 0x0BF9, 0x0B79, 0x0B9D, 0x0B9D, 0x0B95, 
 
0x0B95, 0x0BA5, 0x0BA9, 0x0BA9, 0x0BC1, 0x0BC5, 0x0BB1, 0x0BB9, 
 
0x0BB9, 0x0AAD, 0x0AB1, 0x0AB5, 0x0AB9, 0x0ABD, 0x0AC1, 0x0AC9, 
 
0x0ACD, 0x0AD5, 0x0AD1, 0x0AD9, 0x0AC5, 0x0AD1, 0x0AD5, 0x0AF9, 
 
0x0AFD, 0x0B05, 0x0AB9, 0x0AC1, 0x0AC9, 0x0AD1, 0x0AD9, 0x0AE1, 
 
0x0AE5, 0x0AE9, 0x0AF1, 0x0AF9, 0x0B0D, 0x0B11, 0x0B15, 0x0B19, 
 
0x0B1D, 0x0B21, 0x0B29, 0x0B2D, 0x0B35, 0x0B31, 0x0B39, 0x0B25, 
 
0x0B31, 0x0B35, 
 
0x0B59, 0x0B61, 0x0B69, 0x0BE1, 0x0B71, 0x0B75, 0x0B7D, 0x0B7D,
 
0x0B85, 0x0B85, 0x0B8D, 0x0B8D, 0x0BC9, 0x0BD1, 0x0BD9, 0x0BE9,
 
0x0BED, 0x0BED, 0x0BF5, 0x0BF9, 0x0B79, 0x0B9D, 0x0B9D, 0x0B95,
 
0x0B95, 0x0BA5, 0x0BA9, 0x0BA9, 0x0BC1, 0x0BC5, 0x0BB1, 0x0BB9,
 
0x0BB9, 0x0AAD, 0x0AB1, 0x0AB5, 0x0AB9, 0x0ABD, 0x0AC1, 0x0AC9,
 
0x0ACD, 0x0AD5, 0x0AD1, 0x0AD9, 0x0AC5, 0x0AD1, 0x0AD5, 0x0AF9,
 
0x0AFD, 0x0B05, 0x0AB9, 0x0AC1, 0x0AC9, 0x0AD1, 0x0AD9, 0x0AE1,
 
0x0AE5, 0x0AE9, 0x0AF1, 0x0AF9, 0x0B0D, 0x0B11, 0x0B15, 0x0B19,
 
0x0B1D, 0x0B21, 0x0B29, 0x0B2D, 0x0B35, 0x0B31, 0x0B39, 0x0B25,
 
0x0B31, 0x0B35,
 
};
 

	
 
/* For how many directions do we have sprites? (8 or 4; if 4, the other 4
 
 * directions are symmetric. */
 
static const byte _engine_sprite_and[] = {
 
7, 7, 7, 7, 3, 3, 7, 7, 
 
7, 7, 7, 7, 7, 7, 7, 3, 
 
7, 7, 3, 7, 3, 7, 7, 7, 
 
7, 3, 7, 7, 3, 3, 7, 7, 
 
7, 3, 3, 3, 3, 3, 3, 3, 
 
3, 3, 3, 3, 3, 3, 3, 3, 
 
3, 3, 3, 3, 3, 3, 3, 3, 
 
3, 3, 3, 3, 3, 3, 3, 3, 
 
3, 3, 3, 3, 3, 3, 3, 3, 
 
3, 3, 
 
7, 7, 7, 7, 3, 3, 7, 7,
 
7, 7, 7, 7, 7, 7, 7, 3,
 
7, 7, 3, 7, 3, 7, 7, 7,
 
7, 3, 7, 7, 3, 3, 7, 7,
 
7, 3, 3, 3, 3, 3, 3, 3,
 
3, 3, 3, 3, 3, 3, 3, 3,
 
3, 3, 3, 3, 3, 3, 3, 3,
 
3, 3, 3, 3, 3, 3, 3, 3,
 
3, 3, 3, 3, 3, 3, 3, 3,
 
3, 3,
 
};
 

	
 
/* Non-zero for multihead trains. */
 
static const byte _engine_sprite_add[] = {
 
0, 0, 0, 0, 0, 0, 0, 4, 
 
0, 4, 0, 4, 0, 0, 0, 0, 
 
0, 4, 0, 0, 0, 0, 4, 0, 
 
4, 0, 0, 4, 0, 0, 0, 0, 
 
4, 0, 0, 0, 0, 0, 0, 0, 
 
0, 0, 0, 0, 0, 0, 0, 0, 
 
0, 0, 0, 0, 0, 0, 0, 0, 
 
0, 0, 0, 0, 0, 0, 0, 0, 
 
0, 0, 0, 0, 0, 0, 0, 0, 
 
0, 0, 
 
0, 0, 0, 0, 0, 0, 0, 4,
 
0, 4, 0, 4, 0, 0, 0, 0,
 
0, 4, 0, 0, 0, 0, 4, 0,
 
4, 0, 0, 4, 0, 0, 0, 0,
 
4, 0, 0, 0, 0, 0, 0, 0,
 
0, 0, 0, 0, 0, 0, 0, 0,
 
0, 0, 0, 0, 0, 0, 0, 0,
 
0, 0, 0, 0, 0, 0, 0, 0,
 
0, 0, 0, 0, 0, 0, 0, 0,
 
0, 0,
 
};
 

	
 

	
 
static const byte _wagon_full_adder[] = {
 
	0, 0, 0, 0, 0, 0, 0, 0,
 
	0, 0, 0, 0, 0, 0, 0, 0,
 
	0, 0, 0, 0, 0, 0, 0, 0,
 
	0, 0, 0, 0, 0, 0, 0, 0,
 
	0, 0, 44, 0, 0, 0, 0, 24,
 
	24, 24, 24, 0, 0, 32, 32, 0,
 
	4, 4, 4, 4, 4, 4, 4, 0,
 
	0, 4, 4, 4, 0, 44, 0, 0,
 
	0, 0, 24, 24, 24, 24, 0, 0,
 
	32, 32
 
};
table/water_land.h
Show inline comments
 
static const byte _shipdepot_display_seq_1[] = {
 
	ADD_WORD(0xFDD),
 

	
 
	0,15,0,16,1,0x14,
 
	ADD_WORD(0x8FE8),
 
	
 
	0x80 
 

	
 
	0x80
 
};
 

	
 
static const byte _shipdepot_display_seq_2[] = {
 
	ADD_WORD(0xFDD),
 

	
 
	0,0,0,16,1,0x14, ADD_WORD(0xFEA),
 
	0,15,0,16,1,0x14, ADD_WORD(0x8FE6),
 

	
 
	0x80
 
};
 

	
 
static const byte _shipdepot_display_seq_3[] = {
 
	ADD_WORD(0xFDD),
 

	
 
	15,0,0,1,0x10,0x14,ADD_WORD(0x8FE9),
 

	
 
	0x80
 
};
 

	
 
static const byte _shipdepot_display_seq_4[] = {
 
	ADD_WORD(0xFDD),
 

	
 
	0,0,0,1,16,0x14, ADD_WORD(0xFEB),
 
	15,0,0,1,16,0x14, ADD_WORD(0x8FE7),
 
@@ -100,48 +100,48 @@ static const byte _shiplift_display_seq_
 
	ADD_WORD(0xFDD),
 
	0, 0, 0, 0x10, 1, 0x14, ADD_WORD(SPR_CANALS_BASE + 9 + 16 + 1),
 
	0, 0xF, 0, 0x10, 1, 0x14, ADD_WORD(SPR_CANALS_BASE + 9 + 20 + 1),
 
	0x80, 8
 
};
 

	
 
static const byte _shiplift_display_seq_1t[] = {
 
	ADD_WORD(0xFDD),
 
	0, 0, 0, 0x1, 0x10, 0x14, ADD_WORD(SPR_CANALS_BASE + 9 + 16),
 
	0xF, 0, 0, 0x1, 0x10, 0x14, ADD_WORD(SPR_CANALS_BASE + 9 + 20),
 
	0x80, 8
 
};
 

	
 
static const byte _shiplift_display_seq_2t[] = {
 
	ADD_WORD(0xFDD),
 
	0, 0, 0, 0x10, 1, 0x14, ADD_WORD(SPR_CANALS_BASE + 9 + 16 + 2),
 
	0, 0xF, 0, 0x10, 1, 0x14, ADD_WORD(SPR_CANALS_BASE + 9 + 20 + 2),
 
	0x80, 8
 
};
 

	
 
static const byte _shiplift_display_seq_3t[] = {
 
	ADD_WORD(0xFDD),
 
	0, 0, 0, 1, 0x10, 0x14, ADD_WORD(SPR_CANALS_BASE + 9 + 16 + 3),
 
	0xF, 0, 0, 1, 0x10, 0x14, ADD_WORD(SPR_CANALS_BASE + 9 + 20 + 3),
 
	0x80, 8	
 
	0x80, 8
 
};
 

	
 
static const byte * const _shiplift_display_seq[] = {
 
	_shiplift_display_seq_0,
 
	_shiplift_display_seq_1,
 
	_shiplift_display_seq_2,
 
	_shiplift_display_seq_3,
 

	
 
	_shiplift_display_seq_0b,
 
	_shiplift_display_seq_1b,
 
	_shiplift_display_seq_2b,
 
	_shiplift_display_seq_3b,
 

	
 
	_shiplift_display_seq_0t,
 
	_shiplift_display_seq_1t,
 
	_shiplift_display_seq_2t,
 
	_shiplift_display_seq_3t,
 
};
 

	
 

	
 
static const SpriteID _water_shore_sprites[15] = {
 
	0, 0xFDF, 0xFE0, 0xFE4, 0xFDE, 0, 0xFE2, 0, 0xFE1, 0xFE5, 0, 0, 0xFE3, 0, 0
 
};
town_gui.c
Show inline comments
 
@@ -333,72 +333,72 @@ void ShowTownViewWindow(uint town)
 
	}
 
}
 

	
 
static const Widget _town_directory_widgets[] = {
 
{    WWT_TEXTBTN,    13,     0,    10,     0,    13, STR_00C5, STR_018B_CLOSE_WINDOW},
 
{    WWT_CAPTION,    13,    11,   207,     0,    13, STR_2000_TOWNS, STR_018C_WINDOW_TITLE_DRAG_THIS},
 
{ WWT_PUSHTXTBTN,    13,     0,    98,    14,    25, STR_SORT_BY_NAME, STR_SORT_TIP},
 
{ WWT_PUSHTXTBTN,    13,    99,   196,    14,    25, STR_SORT_BY_POPULATION,STR_SORT_TIP},
 
{     WWT_IMGBTN,    13,     0,   196,    26,   189, 0x0, STR_200A_TOWN_NAMES_CLICK_ON_NAME},
 
{  WWT_SCROLLBAR,    13,   197,   207,    14,   189, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
 
{   WIDGETS_END},
 
};
 

	
 

	
 
// used to get a sorted list of the towns
 
static byte _town_sort[lengthof(_towns)];
 
static uint _num_town_sort;
 

	
 
static char _bufcache[64];
 
static byte _last_town_idx;
 

	
 
static int CDECL TownNameSorter(const void *a, const void *b)
 
{
 
	char buf1[64];
 
	Town *t;
 
	const Town *t;
 
	byte val;
 
	int r;
 

	
 
	t = DEREF_TOWN(*(byte*)a);
 
	t = DEREF_TOWN(*(const byte*)a);
 
	SET_DPARAM32(0, t->townnameparts);
 
	GetString(buf1, t->townnametype);
 

	
 
	if ( (val=*(byte*)b) != _last_town_idx) {
 
	if ( (val=*(const byte*)b) != _last_town_idx) {
 
		_last_town_idx = val;
 
		t = DEREF_TOWN(val);
 
		SET_DPARAM32(0, t->townnameparts);
 
		GetString(_bufcache, t->townnametype);
 
	}
 

	
 
	r = strcmp(buf1, _bufcache);
 
	if (_town_sort_order & 1) r = -r;
 
	return r;
 
}
 

	
 
static int CDECL TownPopSorter(const void *a, const void *b)
 
{
 
	Town *ta = DEREF_TOWN(*(byte*)a);
 
	Town *tb = DEREF_TOWN(*(byte*)b);
 
	const Town *ta = DEREF_TOWN(*(const byte*)a);
 
	const Town *tb = DEREF_TOWN(*(const byte*)b);
 
	int r = ta->population - tb->population;
 
	if (_town_sort_order & 1) r = -r;
 
	return r;
 
}
 

	
 
static void MakeSortedTownList()
 
{
 
	Town *t;
 
	int n = 0;
 
	FOR_ALL_TOWNS(t) if(t->xy) _town_sort[n++] = t->index;
 
	_num_town_sort = n;
 

	
 
	_last_town_idx = 0; // used for "cache"
 
	qsort(_town_sort, n, sizeof(_town_sort[0]), _town_sort_order & 2 ? TownPopSorter : TownNameSorter);
 

	
 
	DEBUG(misc, 1) ("Resorting Towns list...");
 
}
 

	
 

	
 
static void TownDirectoryWndProc(Window *w, WindowEvent *e)
 
{
 
	switch(e->event) {
 
	case WE_PAINT: {
 

	
ttd.c
Show inline comments
 
@@ -258,52 +258,52 @@ void LoadDriver(int driver, const char *
 

	
 
	if (!*name) {
 
		dd = ChooseDefaultDriver(dc->descs);
 
	} else {
 
		// Extract the driver name and put parameter list in parm
 
		ttd_strlcpy(buffer, name, sizeof(buffer));
 
		parm = strchr(buffer, ':');
 
		if (parm) {
 
			int np = 0;
 
			// Tokenize the parm.
 
			do {
 
				*parm++ = 0;
 
				if (np < lengthof(parms) - 1)
 
					parms[np++] = parm;
 
				while (*parm != 0 && *parm != ',')
 
					parm++;
 
			} while (*parm == ',');
 
			parms[np] = NULL;
 
		}
 
		dd = GetDriverByName(dc->descs, buffer);
 
		if (dd == NULL)
 
			error("No such %s driver: %s\n", dc->name, buffer);
 
	}
 
	var = dc->var;
 
	if (*var != NULL) ((HalCommonDriver*)*var)->stop();
 
	if (*var != NULL) ((const HalCommonDriver*)*var)->stop();
 
	*var = NULL;
 
	drv = dd->drv;
 
	if ((err=((HalCommonDriver*)drv)->start(parms)) != NULL)
 
	if ((err=((const HalCommonDriver*)drv)->start(parms)) != NULL)
 
		error("Unable to load driver %s(%s). The error was: %s\n", dd->name, dd->longname, err);
 
	*var = drv;
 
}
 

	
 
void PrintDriverList()
 
{
 
}
 

	
 
static void showhelp()
 
{
 
	char buf[4096], *p;
 
	const DriverClass *dc = _driver_classes;
 
	const DriverDesc *dd;
 
	int i;
 

	
 
	p = strecpy(buf,
 
		"Command line options:\n"
 
		"  -v drv = Set video driver (see below)\n"
 
		"  -s drv = Set sound driver (see below)\n"
 
		"  -m drv = Set music driver (see below)\n"
 
		"  -r res = Set resolution (for instance 800x600)\n"
 
		"  -h     = Display this help text\n"
 
		"  -t date= Set starting date\n"
 
		"  -d dbg = Debug mode\n"
unix.c
Show inline comments
 
@@ -258,49 +258,49 @@ char *FiosBrowseTo(const FiosItem *item)
 

	
 
	case FIOS_TYPE_FILE:
 
		FiosMakeSavegameName(str_buffr, item->name);
 
		return str_buffr;
 

	
 
	case FIOS_TYPE_OLDFILE:
 
		sprintf(str_buffr, "%s/%s.%s", _fios_path, item->name, _old_extensions[item->old_extension]);
 
		return str_buffr;
 

	
 
	case FIOS_TYPE_SCENARIO:
 
		sprintf(str_buffr, "%s/%s.scn", path, item->name);
 
		return str_buffr;
 

	
 
	case FIOS_TYPE_OLD_SCENARIO:
 
		sprintf(str_buffr, "%s/%s.%s", path, item->name, _old_extensions[item->old_extension]);
 
		return str_buffr;
 
	}
 

	
 
	return NULL;
 
}
 

	
 
// Get descriptive texts.
 
// Returns a path as well as a
 
//  string describing the path.
 
StringID FiosGetDescText(char **path)
 
StringID FiosGetDescText(const char **path)
 
{
 
	*path = _fios_path[0] ? _fios_path : "/";
 

	
 
#if defined(__linux__)
 
	{
 
	struct statvfs s;
 

	
 
	if (statvfs(*path, &s) == 0)
 
	{
 
		uint64 tot = (uint64)s.f_bsize * s.f_bavail;
 
		SET_DPARAM32(0, (uint32)(tot >> 20));
 
		return STR_4005_BYTES_FREE;
 
	}
 
	else
 
		return STR_4006_UNABLE_TO_READ_DRIVE;
 
	}
 
#else
 
	SET_DPARAM32(0, 0);
 
	return STR_4005_BYTES_FREE;
 
#endif
 
}
 

	
 
void FiosMakeSavegameName(char *buf, const char *name)
 
{
 
@@ -339,49 +339,49 @@ const DriverDesc _sound_driver_descs[] =
 
#define EXTMIDI_PRI 0
 
#endif
 

	
 
const DriverDesc _music_driver_descs[] = {
 
#ifndef __BEOS__
 
#ifndef __MORPHOS__
 
// MorphOS have no music support
 
	{"extmidi",	"External MIDI Driver",	&_extmidi_music_driver,	EXTMIDI_PRI},
 
#endif
 
#endif
 
#ifdef __BEOS__
 
	{ "bemidi",	"BeOS MIDI Driver",			&_bemidi_music_driver,	1},
 
#endif
 
	{   "null",	"Null Music Driver",		&_null_music_driver,		1},
 
	{     NULL,	NULL,										NULL,										0}
 
};
 

	
 
bool FileExists(const char *filename)
 
{
 
	return access(filename, 0) == 0;
 
}
 

	
 
static int LanguageCompareFunc(const void *a, const void *b)
 
{
 
	return strcmp(*(char**)a, *(char**)b);
 
	return strcmp(*(const char* const *)a, *(const char* const *)b);
 
}
 

	
 
int GetLanguageList(char **languages, int max)
 
{
 
	DIR *dir;
 
	struct dirent *dirent;
 
	int num = 0;
 

	
 
	dir = opendir(_path.lang_dir);
 
	if (dir != NULL) {
 
		while ((dirent = readdir(dir))) {
 
			char *t = strrchr(dirent->d_name, '.');
 
			if (t && !strcmp(t, ".lng")) {
 
				languages[num++] = strdup(dirent->d_name);
 
				if (num == max) break;
 
			}
 
		}
 
		closedir(dir);
 
	}
 

	
 
	qsort(languages, num, sizeof(char*), LanguageCompareFunc);
 
	return num;
 
}
 

	
unmovable_cmd.c
Show inline comments
 
@@ -63,53 +63,53 @@ static void DrawTile_Unmovable(TileInfo 
 
			if (ti->tileh) DrawFoundation(ti, ti->tileh);
 
			DrawClearLandTile(ti, 2);
 

	
 
			dtus = &_draw_tile_unmovable_data[ti->map5];
 

	
 
			image = dtus->image;
 
			if (!(_display_opt & DO_TRANS_BUILDINGS))
 
				image = (image & 0x3FFF) | 0x3224000;
 

	
 
			AddSortableSpriteToDraw(image,
 
				ti->x | dtus->subcoord_x,
 
				ti->y | dtus->subcoord_y,
 
				dtus->width, dtus->height,
 
				dtus->z_size, ti->z);
 
		}
 
	} else {
 
		const DrawTileSeqStruct *dtss;
 
		const byte *t;
 

	
 
		if (ti->tileh) DrawFoundation(ti, ti->tileh);
 

	
 
		ormod = PLAYER_SPRITE_COLOR(_map_owner[ti->tile]);
 

	
 
		t = _unmovable_display_datas[ti->map5 & 0x7F];
 
		DrawGroundSprite(*(uint16*)t | ormod);
 
		DrawGroundSprite(*(const uint16*)t | ormod);
 

	
 
		t += sizeof(uint16);
 

	
 
		for(dtss = (DrawTileSeqStruct *)t; (byte)dtss->delta_x != 0x80; dtss++) {
 
		for(dtss = (const DrawTileSeqStruct *)t; (byte)dtss->delta_x != 0x80; dtss++) {
 
			image =	dtss->image;
 
			if (_display_opt & DO_TRANS_BUILDINGS) {
 
				image |= ormod;
 
			} else {
 
				image = (image & 0x3FFF) | 0x03224000;
 
			}
 
			AddSortableSpriteToDraw(image, ti->x + dtss->delta_x, ti->y + dtss->delta_y,
 
				dtss->width, dtss->height, dtss->unk, ti->z + dtss->delta_z);
 
		}
 
	}
 
}
 

	
 
static uint GetSlopeZ_Unmovable(TileInfo *ti)
 
{
 
	return GetPartialZ(ti->x&0xF, ti->y&0xF, ti->tileh) + ti->z;
 
}
 

	
 
static uint GetSlopeTileh_Unmovable(TileInfo *ti)
 
{
 
	return 0;
 
}
 

	
 
static int32 ClearTile_Unmovable(uint tile, byte flags)
 
{
water_cmd.c
Show inline comments
 
@@ -362,98 +362,98 @@ void DrawCanalWater(uint tile)
 

	
 
typedef struct WaterDrawTileStruct {
 
	int8 delta_x;
 
	int8 delta_y;
 
	int8 delta_z;
 
	byte width;
 
	byte height;
 
	byte unk;
 
	SpriteID image;
 
} WaterDrawTileStruct;
 

	
 
typedef struct LocksDrawTileStruct {
 
	int8 delta_x, delta_y, delta_z;
 
	byte width, height, depth;
 
	SpriteID image;
 
} LocksDrawTileStruct;
 

	
 
#include "table/water_land.h"
 

	
 
static void DrawWaterStuff(TileInfo *ti, const byte *t, uint32 palette, uint base)
 
{
 
	const WaterDrawTileStruct *wdts;
 
	uint32 image;
 

	
 
	DrawGroundSprite(*(uint16*)t);
 
	DrawGroundSprite(*(const uint16*)t);
 
	t += sizeof(uint16);
 

	
 
	for(wdts = (WaterDrawTileStruct *)t; (byte)wdts->delta_x != 0x80; wdts++) {
 
	for(wdts = (const WaterDrawTileStruct *)t; (byte)wdts->delta_x != 0x80; wdts++) {
 
		image =	wdts->image + base;
 
		if (_display_opt & DO_TRANS_BUILDINGS) {
 
			image |= palette;
 
		} else {
 
			image = (image & 0x3FFF) | 0x03224000;
 
		}
 
		AddSortableSpriteToDraw(image, ti->x + wdts->delta_x, ti->y + wdts->delta_y, wdts->width, wdts->height, wdts->unk, ti->z + wdts->delta_z);
 
	}
 
}
 

	
 
static void DrawTile_Water(TileInfo *ti)
 
{
 
	// draw water tile
 
	if (ti->map5 == 0) {
 
		DrawGroundSprite(0xFDD);
 
		if (ti->z != 0) DrawCanalWater(ti->tile);
 
		return;
 
	}
 

	
 
	// draw shore
 
	if (ti->map5 == 1) {
 
		assert(ti->tileh < 16);
 
		DrawGroundSprite(_water_shore_sprites[ti->tileh]);
 
		return;
 
	}
 

	
 
	// draw shiplift
 
	if ((ti->map5 & 0xF0) == 0x10) {
 
		const byte *t = _shiplift_display_seq[ti->map5 & 0xF];
 
		DrawWaterStuff(ti, t, 0, ti->z > t[19] ? 24 : 0);
 
		return;
 
	}
 

	
 
	DrawWaterStuff(ti, _shipdepot_display_seq[ti->map5 & 0x7F], PLAYER_SPRITE_COLOR(_map_owner[ti->tile]), 0);
 
}
 

	
 
void DrawShipDepotSprite(int x, int y, int image)
 
{
 
	const byte *t;
 
	const WaterDrawTileStruct *wdts;
 

	
 
	t = _shipdepot_display_seq[image];
 
	DrawSprite(*(uint16*)t, x, y);
 
	DrawSprite(*(const uint16*)t, x, y);
 
	t += sizeof(uint16);
 

	
 
	for(wdts = (WaterDrawTileStruct *)t; (byte)wdts->delta_x != 0x80; wdts++) {
 
	for(wdts = (const WaterDrawTileStruct *)t; (byte)wdts->delta_x != 0x80; wdts++) {
 
		Point pt = RemapCoords(wdts->delta_x, wdts->delta_y, wdts->delta_z);
 
		DrawSprite(wdts->image + PLAYER_SPRITE_COLOR(_local_player), x + pt.x, y + pt.y);
 
	}
 
}
 

	
 

	
 
uint GetSlopeZ_Water(TileInfo *ti)
 
{
 
	return GetPartialZ(ti->x&0xF, ti->y&0xF, ti->tileh) + ti->z;
 
}
 

	
 
uint GetSlopeTileh_Water(TileInfo *ti)
 
{
 
	return ti->tileh;
 
}
 

	
 
static void GetAcceptedCargo_Water(uint tile, AcceptedCargo *ac)
 
{
 
	/* not used */
 
}
 

	
 
static void GetTileDesc_Water(uint tile, TileDesc *td)
 
{
 
	if (_map5[tile] == 0 && GET_TILEHEIGHT(tile) == 0)
win32.c
Show inline comments
 
@@ -1720,49 +1720,49 @@ char *FiosBrowseTo(const FiosItem *item)
 
		break;
 

	
 
	case FIOS_TYPE_FILE:
 
		FiosMakeSavegameName(str_buffr, item->name);
 
		return str_buffr;
 

	
 
	case FIOS_TYPE_OLDFILE:
 
		sprintf(str_buffr, "%s\\%s.%s", _fios_path, item->name, _old_extensions[item->old_extension]);
 
		return str_buffr;
 

	
 
	case FIOS_TYPE_SCENARIO:
 
		sprintf(str_buffr, "%s\\%s.scn", path, item->name);
 
		return str_buffr;
 
	case FIOS_TYPE_OLD_SCENARIO:
 
		sprintf(str_buffr, "%s\\%s.%s", path, item->name, _old_extensions[item->old_extension]);
 
		return str_buffr;
 
	}
 

	
 
	return NULL;
 
}
 

	
 
// Get descriptive texts.
 
// Returns a path as well as a
 
//  string describing the path.
 
StringID FiosGetDescText(char **path)
 
StringID FiosGetDescText(const char **path)
 
{
 
	char root[4];
 
	DWORD spc, bps, nfc, tnc;
 
	*path = _fios_path;
 

	
 
	root[0] = _fios_path[0];
 
	root[1] = ':';
 
	root[2] = '\\';
 
	root[3] = 0;
 
	if (GetDiskFreeSpace(root, &spc, &bps, &nfc, &tnc)) {
 
		uint32 tot = ((spc*bps)*(uint64)nfc) >> 20;
 
		SET_DPARAM32(0, tot);
 
		return STR_4005_BYTES_FREE;
 
	} else {
 
		return STR_4006_UNABLE_TO_READ_DRIVE;
 
	}
 
}
 

	
 
void FiosMakeSavegameName(char *buf, const char *name)
 
{
 
	if(_game_mode == GM_EDITOR)
 
		sprintf(buf, "%s\\%s.scn", _fios_path, name);
 
	else
 
		sprintf(buf, "%s\\%s.sav", _fios_path, name);
 
@@ -1791,49 +1791,49 @@ const DriverDesc _sound_driver_descs[] =
 
#endif
 
	{"win32", "Win32 WaveOut Driver",	&_win32_sound_driver,	2},
 
	{NULL}
 
};
 

	
 
const DriverDesc _music_driver_descs[] = {
 
	{"null", "Null Music Driver",		&_null_music_driver,	0},
 
#ifdef WIN32_ENABLE_DIRECTMUSIC_SUPPORT
 
	{"dmusic", "DirectMusic MIDI Driver",	&_dmusic_midi_driver,	1},
 
#endif
 
	{"win32", "Win32 MIDI Driver",	&_win32_music_driver,	2},
 
	{NULL}
 
};
 

	
 
bool FileExists(const char *filename)
 
{
 
	HANDLE hand = CreateFile(filename, 0, 0, NULL, OPEN_EXISTING, 0, NULL);
 
	if (hand == INVALID_HANDLE_VALUE) return false;
 
	CloseHandle(hand);
 
	return true;
 
}
 

	
 
static int CDECL LanguageCompareFunc(const void *a, const void *b)
 
{
 
	return strcmp(*(char**)a, *(char**)b);
 
	return strcmp(*(const char* const *)a, *(const char* const *)b);
 
}
 

	
 
int GetLanguageList(char **languages, int max)
 
{
 
	HANDLE hand;
 
	int num = 0;
 
	char filedir[MAX_PATH];
 
	WIN32_FIND_DATA fd;
 
	sprintf(filedir, "%s*.lng", _path.lang_dir);
 

	
 
	hand = FindFirstFile(filedir, &fd);
 
	if (hand != INVALID_HANDLE_VALUE) {
 
		do {
 
			if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
 
				languages[num++] = strdup(fd.cFileName);
 
				if (num == max) break;
 
			}
 
		} while (FindNextFile(hand, &fd));
 
		FindClose(hand);
 
	}
 

	
 
	qsort(languages, num, sizeof(char*), LanguageCompareFunc);
 
	return num;
 
}
window.c
Show inline comments
 
@@ -4,49 +4,49 @@
 
#include "gfx.h"
 
#include "viewport.h"
 
#include "console.h"
 

	
 
void HandleButtonClick(Window *w, byte widget)
 
{
 
	w->click_state |= (1 << widget);
 
	w->flags4 |= 5 << WF_TIMEOUT_SHL;
 
	InvalidateWidget(w, widget);
 
}
 

	
 
void DispatchLeftClickEvent(Window *w, int x, int y) {
 
	WindowEvent e;
 
	const Widget *wi;
 

	
 
	e.click.pt.x = x;
 
	e.click.pt.y = y;
 
	e.event = WE_CLICK;
 

	
 
	if (w->desc_flags & WDF_DEF_WIDGET) {
 
		e.click.widget = GetWidgetFromPos(w, x, y);
 
		if (e.click.widget < 0) return; /* exit if clicked outside of widgets */
 

	
 
		wi = &w->widget[e.click.widget];
 
				
 

	
 
		/* don't allow any interaction if the button has been disabled */
 
		if (HASBIT(w->disabled_state, e.click.widget))
 
			return;
 

	
 
		if (wi->type & 0xE0) {
 
			/* special widget handling for buttons*/
 
			switch(wi->type) {
 
			case WWT_IMGBTN  | WWB_PUSHBUTTON: /* WWT_PUSHIMGBTN */
 
			case WWT_TEXTBTN | WWB_PUSHBUTTON: /* WWT_PUSHTXTBTN */
 
				HandleButtonClick(w, e.click.widget);
 
				break;
 
			case WWT_NODISTXTBTN:
 
				break;
 
			}
 
		} else if (wi->type == WWT_SCROLLBAR || wi->type == WWT_HSCROLLBAR) {
 
			ScrollbarClickHandler(w, wi, e.click.pt.x, e.click.pt.y);
 
		}
 

	
 
		w->wndproc(w, &e);
 

	
 
		if (w->desc_flags & WDF_STD_BTN) {
 
			if (e.click.widget == 0) DeleteWindow(w);
 
			else {
 
				if (e.click.widget == 1) {
0 comments (0 inline, 0 general)