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
 
@@ -3,44 +3,44 @@ CFILES = 	ai.c aircraft_cmd.c aircraft_g
 
	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 ;
 
@@ -55,68 +55,68 @@ if $(UNIX) {
 
	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) ;
 
}
 
@@ -133,25 +133,25 @@ rule MyMain {
 

	
 
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 ;
 
}
 

	
Makefile
Show inline comments
 
@@ -50,30 +50,30 @@
 
# 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
 

	
 

	
 
##############################################################################
 
@@ -125,32 +125,32 @@ else
 
	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
 
@@ -508,32 +508,32 @@ C_LINK = $(CC) $(LDFLAGS) -o
 

	
 
### 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
 
@@ -546,25 +546,25 @@ endian.h: $(ENDIAN_CHECK)
 

	
 
$(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
 
@@ -612,25 +612,25 @@ 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
 

	
airport.c
Show inline comments
 
@@ -79,25 +79,25 @@ static void AirportFTAClass_Constructor(
 

	
 
	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);
airport.h
Show inline comments
 
@@ -16,33 +16,33 @@ enum {
 
	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();
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
 
@@ -49,25 +49,25 @@ 0.3.3 (2004-07-13)
 
- 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
console.c
Show inline comments
 
@@ -198,27 +198,27 @@ void IConsoleInit()
 
	_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) {
 
@@ -260,70 +260,70 @@ void IConsoleSwitch()
 

	
 
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];
 
@@ -345,145 +345,145 @@ void CDECL IConsolePrintF(byte color_cod
 
	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)
 
@@ -542,86 +542,73 @@ void IConsoleVarInsert(_iconsole_var * v
 
					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:
 
@@ -677,61 +664,62 @@ void IConsoleVarDump(_iconsole_var * var
 
				{
 
				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:
 
@@ -744,24 +732,27 @@ bool IConsoleCmdHookHandle(_iconsole_cmd
 
{
 
	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;
 
@@ -876,25 +867,25 @@ void IConsoleCmdExec(byte * cmdstr)
 
	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;
 
						}
 
					}
 
@@ -1106,46 +1097,47 @@ void IConsoleCmdExec(byte * cmdstr)
 
				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);
console.h
Show inline comments
 
@@ -38,25 +38,25 @@ typedef struct {
 
	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 ** //
 

	
 
@@ -76,53 +76,53 @@ 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
 
@@ -1007,26 +1007,26 @@ static const StringID _performance_title
 
	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;
 

	
hal.h
Show inline comments
 
@@ -126,21 +126,21 @@ void GetOldScenarioGameName(char *title,
 

	
 
// 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
 
@@ -383,26 +383,26 @@ static const Widget _industry_directory_
 
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?
 
@@ -428,25 +428,25 @@ static int CDECL GeneralIndustrySorter(c
 
		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()
macros.h
Show inline comments
 
@@ -194,31 +194,31 @@ static INLINE int intxchg_(int *a, int 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
 
@@ -2217,28 +2217,28 @@ void SetupColorsAndInitialWindow()
 
		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;
 

	
misc_gui.c
Show inline comments
 
@@ -954,25 +954,25 @@ 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)
network.c
Show inline comments
 
@@ -519,25 +519,25 @@ static void HandleCommandPacket(ClientSt
 
	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());
 

	
network_gui.c
Show inline comments
 
@@ -135,25 +135,25 @@ static void NetworkGameWindowWndProc(Win
 
		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:
 
@@ -170,25 +170,25 @@ static void NetworkGameWindowWndProc(Win
 
	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++;
 
				}
 

	
rail_cmd.c
Show inline comments
 
@@ -1511,25 +1511,25 @@ static void DrawTile_Track(TileInfo *ti)
 
		}
 
	} 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
 
		}
 

	
 
@@ -1557,29 +1557,29 @@ void DrawTrainDepotSprite(int x, int y, 
 
	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;
readme.txt
Show inline comments
 
@@ -117,47 +117,47 @@ 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.
 
@@ -200,26 +200,26 @@ That's all! You should now be able to se
 
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
 
@@ -801,27 +801,27 @@ static void DrawTile_Road(TileInfo *ti)
 
		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++;
 
		}
 
	}
 
@@ -831,28 +831,28 @@ void DrawRoadDepotSprite(int x, int y, i
 
{
 
	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)
 
{
saveload.c
Show inline comments
 
@@ -413,25 +413,25 @@ void SlArray(void *array, uint length, u
 
			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++;
 
@@ -455,25 +455,25 @@ static size_t SlCalcObjLength(void *obje
 
			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
sdl.c
Show inline comments
 
@@ -203,27 +203,27 @@ static void DrawSurfaceToScreen()
 
	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},
 
};
settings.c
Show inline comments
 
@@ -316,27 +316,27 @@ static bool ini_save(const char *filenam
 
	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')
 
@@ -484,25 +484,25 @@ static void make_manyofmany(char *buf, c
 
			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;
 
@@ -523,29 +523,29 @@ static void *string_to_val(const Setting
 
		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;
 
		}
 
@@ -594,29 +594,30 @@ static void load_setting_desc(IniFile *i
 
			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);
 
@@ -874,25 +875,25 @@ static const SettingDesc patch_settings[
 
	{"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);
 
}
station_cmd.c
Show inline comments
 
@@ -1734,73 +1734,73 @@ static void DrawTile_Station(TileInfo *t
 
		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;
 
}
station_gui.c
Show inline comments
 
@@ -45,27 +45,26 @@ static void StationsWndShowStationRating
 
}
 

	
 
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);
strgen/strgen.c
Show inline comments
 
@@ -34,25 +34,25 @@ typedef struct {
 
} 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++)
 
@@ -209,57 +209,57 @@ 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},
 

	
 
@@ -379,25 +379,25 @@ bool check_commands_match(char *a, char 
 
		} 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) {
 
@@ -462,35 +462,35 @@ void handle_string(char *str, bool maste
 
			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);
 

	
 
@@ -503,25 +503,25 @@ void parse_file(const char *file, bool e
 
			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;
 
	}
 
@@ -570,25 +570,25 @@ void gen_output(FILE *f) {
 
		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");
 
	}
 
}
 
@@ -633,33 +633,33 @@ void write_strings_h(const char *filenam
 
	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 {
 
@@ -681,47 +681,47 @@ void write_langfile(const char *filename
 
	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);
 
					}
 
@@ -760,28 +760,28 @@ int main(int argc, char* 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");
 
	}
table/landscape_const.h
Show inline comments
 
@@ -57,25 +57,25 @@ static const LandscapePredefVar _landsca
 
		{
 
			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 */
table/landscape_sprite.h
Show inline comments
 
@@ -123,41 +123,41 @@ 0x10E4, 0x1133,
 
 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,
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];
table/road_land.h
Show inline comments
 
@@ -34,25 +34,25 @@ static const byte * const _road_display_
 
	_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
 
};
 

	
table/station_land.h
Show inline comments
 
@@ -527,25 +527,25 @@ static const byte _station_display_datas
 

	
 
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
 
@@ -561,35 +561,35 @@ const byte _station_display_datas_086[] 
 
	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()
 
};
 

	
 
@@ -848,38 +848,38 @@ static const byte * const _station_displ
 
	_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,
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[] = {
 
@@ -112,25 +112,25 @@ static const byte _shiplift_display_seq_
 

	
 
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,
town_gui.c
Show inline comments
 
@@ -345,48 +345,48 @@ static const Widget _town_directory_widg
 

	
 

	
 
// 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;
 

	
ttd.c
Show inline comments
 
@@ -270,28 +270,28 @@ void LoadDriver(int driver, const char *
 
				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;
unix.c
Show inline comments
 
@@ -270,25 +270,25 @@ char *FiosBrowseTo(const FiosItem *item)
 

	
 
	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;
 
@@ -351,25 +351,25 @@ const DriverDesc _music_driver_descs[] =
 
#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, '.');
unmovable_cmd.c
Show inline comments
 
@@ -75,29 +75,29 @@ static void DrawTile_Unmovable(TileInfo 
 
				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);
 
		}
 
	}
 
}
 

	
water_cmd.c
Show inline comments
 
@@ -374,28 +374,28 @@ 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)
 
{
 
@@ -420,28 +420,28 @@ static void DrawTile_Water(TileInfo *ti)
 
		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)
win32.c
Show inline comments
 
@@ -1732,25 +1732,25 @@ char *FiosBrowseTo(const FiosItem *item)
 
		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);
 
@@ -1803,25 +1803,25 @@ const DriverDesc _music_driver_descs[] =
 
};
 

	
 
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) {
window.c
Show inline comments
 
@@ -16,25 +16,25 @@ void DispatchLeftClickEvent(Window *w, i
 
	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:
0 comments (0 inline, 0 general)