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
25 files changed with 114 insertions and 118 deletions:
0 comments (0 inline, 0 general)
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
 
@@ -23,25 +23,25 @@ enum {
 
	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
 
	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;
 

	
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,80 +345,80 @@ 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);
 
	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;
 
	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;
 
@@ -427,63 +427,63 @@ void IConsoleVarRegister(byte * name, vo
 
	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;
 
	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) {
 
	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) {
 
	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;
 
@@ -1106,45 +1097,46 @@ 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)) {
 
			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];
 
					}
 
				tokens[19]=temp;
 
				tokentypes[19]=temp2;
 
				}
 
			IConsoleCmdHookHandle(cmd,ICONSOLE_HOOK_BEFORE_EXEC);
 
			result = function(c,tokens,tokentypes);
 
			IConsoleCmdHookHandle(cmd,ICONSOLE_HOOK_AFTER_EXEC);
 
			} else {
 
				} 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);
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
 
@@ -30,32 +30,34 @@ static int32 GetArgumentInteger(byte *ar
 
/* 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               */
 
@@ -266,50 +268,50 @@ DEF_CONSOLE_CMD(ConListCommands)
 
 
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)
 
			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((void *) item->name, (void *) argv[1],l)==0)
 
			if (memcmp(item->name, argv[1],l)==0)
 
					IConsoleVarDump(item,NULL);
 
 
			} else {
 
 
			IConsoleVarDump(item,NULL);
 
 
			}
 
		item = item->_next;
 
		}
 
 
	return NULL;
 
}
 
@@ -337,24 +339,26 @@ void IConsoleDebugLibRegister()
 
/* ****************************************** */
 
/*  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);
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 */
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)
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;
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
 
@@ -703,25 +703,25 @@ void write_langfile(const char *filename
 
			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);
 
					}
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) {
0 comments (0 inline, 0 general)