Changeset - r2634:a3ccca486bdf
[Not reviewed]
master
0 7 0
tron - 19 years ago 2005-11-13 21:16:34
tron@openttd.org
(svn r3176) Use proper types, not some variants of int
7 files changed with 13 insertions and 11 deletions:
0 comments (0 inline, 0 general)
gfx.c
Show inline comments
 
@@ -409,95 +409,95 @@ static uint32 FormatStringLinebreaks(cha
 
			if (c >= ASCII_LETTERSTART) {
 
				w += GetCharacterWidth(base + (byte)c);
 
				if (w > maxw) {
 
					str = last_space;
 
					if (str == NULL)
 
						return num + (base << 16);
 
					break;
 
				}
 
			} else {
 
				if (c == 0) return num + (base << 16);
 
				if (c == ASCII_NL) break;
 

	
 
				if (c == ASCII_SETX) str++;
 
				else if (c == ASCII_SETXY) str += 2;
 
				else if (c == ASCII_TINYFONT) base = 224;
 
				else if (c == ASCII_BIGFONT) base = 448;
 
			}
 
		}
 

	
 
		num++;
 
		str[-1] = '\0';
 
	}
 
}
 

	
 
void DrawStringMultiCenter(int x, int y, uint16 str, int maxw)
 
void DrawStringMultiCenter(int x, int y, StringID str, int maxw)
 
{
 
	char buffer[512];
 
	uint32 tmp;
 
	int num, w, mt;
 
	const char *src;
 
	byte c;
 

	
 
	GetString(buffer, str);
 

	
 
	tmp = FormatStringLinebreaks(buffer, maxw);
 
	num = (uint16)tmp;
 

	
 
	switch (GB(tmp, 16, 16)) {
 
		case   0: mt = 10; break;
 
		case 244: mt =  6; break;
 
		default:  mt = 18; break;
 
	}
 

	
 
	y -= (mt >> 1) * num;
 

	
 
	src = buffer;
 

	
 
	for(;;) {
 
		w = GetStringWidth(src);
 
		DoDrawString(src, x - (w>>1), y, 0xFE);
 
		_stringwidth_base = _stringwidth_out;
 

	
 
		for(;;) {
 
			c = *src++;
 
			if (c == 0) {
 
				y += mt;
 
				if (--num < 0) {
 
					_stringwidth_base = 0;
 
					return;
 
				}
 
				break;
 
			} else if (c == ASCII_SETX) {
 
				src++;
 
			} else if (c == ASCII_SETXY) {
 
				src+=2;
 
			}
 
		}
 
	}
 
}
 

	
 
void DrawStringMultiLine(int x, int y, uint16 str, int maxw)
 
void DrawStringMultiLine(int x, int y, StringID str, int maxw)
 
{
 
	char buffer[512];
 
	uint32 tmp;
 
	int num, w, mt;
 
	const char *src;
 
	byte c;
 

	
 
	GetString(buffer, str);
 

	
 
	tmp = FormatStringLinebreaks(buffer, maxw);
 
	num = (uint16)tmp;
 

	
 
	switch (GB(tmp, 16, 16)) {
 
		case   0: mt = 10; break;
 
		case 244: mt =  6; break;
 
		default:  mt = 18; break;
 
	}
 

	
 
	src = buffer;
 

	
 
	for(;;) {
 
		w = GetStringWidth(src);
 
		DoDrawString(src, x, y, 0xFE);
 
		_stringwidth_base = _stringwidth_out;
gfx.h
Show inline comments
 
@@ -47,50 +47,50 @@ void GfxScroll(int left, int top, int wi
 

	
 
int DrawStringCentered(int x, int y, StringID str, uint16 color);
 
int DrawStringCenteredTruncated(int xl, int xr, int y, StringID str, uint16 color);
 
int DoDrawStringCentered(int x, int y, const char *str, uint16 color);
 

	
 
int DrawString(int x, int y, StringID str, uint16 color);
 
int DrawStringTruncated(int x, int y, StringID str, uint16 color, uint maxw);
 

	
 
int DoDrawString(const char *string, int x, int y, uint16 color);
 
int DoDrawStringTruncated(const char *str, int x, int y, uint16 color, uint maxw);
 

	
 
void DrawStringCenterUnderline(int x, int y, StringID str, uint16 color);
 
void DrawStringCenterUnderlineTruncated(int xl, int xr, int y, StringID str, uint16 color);
 

	
 
void DrawStringRightAligned(int x, int y, StringID str, uint16 color);
 
void DrawStringRightAlignedTruncated(int x, int y, StringID str, uint16 color, uint maxw);
 

	
 
void GfxFillRect(int left, int top, int right, int bottom, int color);
 
void GfxDrawLine(int left, int top, int right, int bottom, int color);
 
void DrawFrameRect(int left, int top, int right, int bottom, int color, int flags);
 
uint16 GetDrawStringPlayerColor(PlayerID player);
 

	
 
int GetStringWidth(const char *str);
 
void LoadStringWidthTable(void);
 
void DrawStringMultiCenter(int x, int y, uint16 str, int maxw);
 
void DrawStringMultiLine(int x, int y, uint16 str, int maxw);
 
void DrawStringMultiCenter(int x, int y, StringID str, int maxw);
 
void DrawStringMultiLine(int x, int y, StringID str, int maxw);
 
void DrawDirtyBlocks(void);
 
void SetDirtyBlocks(int left, int top, int right, int bottom);
 
void MarkWholeScreenDirty(void);
 

	
 
void GfxInitPalettes(void);
 

	
 
bool FillDrawPixelInfo(DrawPixelInfo* n, const DrawPixelInfo* o, int left, int top, int width, int height);
 

	
 
/* window.c */
 
void DrawOverlappedWindowForAll(int left, int top, int right, int bottom);
 

	
 
void SetMouseCursor(uint cursor);
 
void SetAnimatedMouseCursor(const CursorID *table);
 
void CursorTick(void);
 
void DrawMouseCursor(void);
 
void ScreenSizeChanged(void);
 
void UndrawMouseCursor(void);
 
bool ChangeResInGame(int w, int h);
 
void SortResolutions(int count);
 
void ToggleFullScreen(bool fs);
 

	
 
/* gfx.c */
 
#define ASCII_LETTERSTART 32
 
VARDEF int _stringwidth_base;
openttd.c
Show inline comments
 
@@ -768,51 +768,51 @@ void SwitchMode(int new_mode)
 
				snprintf(_network_game_info.map_name, NETWORK_NAME_LENGTH, "%s (Loaded scenario)", _file_to_saveload.title);
 
		#endif /* ENABLE_NETWORK */
 
		StartScenario();
 
		break;
 

	
 
	case SM_LOAD: { /* Load game, Play Scenario */
 
		_opt_ptr = &_opt;
 

	
 
		_error_message = INVALID_STRING_ID;
 
		if (!SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_NORMAL)) {
 
			LoadIntroGame();
 
			ShowErrorMessage(_error_message, STR_4009_GAME_LOAD_FAILED, 0, 0);
 
		} else {
 
			_local_player = 0;
 
			DoCommandP(0, 0, 0, NULL, CMD_PAUSE); // decrease pause counter (was increased from opening load dialog)
 
#ifdef ENABLE_NETWORK
 
			if (_network_server)
 
				snprintf(_network_game_info.map_name, NETWORK_NAME_LENGTH, "%s (Loaded game)", _file_to_saveload.title);
 
#endif /* ENABLE_NETWORK */
 
		}
 
		break;
 
	}
 

	
 
	case SM_LOAD_SCENARIO: { /* Load scenario from scenario editor */
 
		int i;
 
		if (SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_EDITOR)) {
 
			PlayerID i;
 

	
 
		if (SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_EDITOR)) {
 
			_opt_ptr = &_opt;
 

	
 
			_local_player = OWNER_NONE;
 
			_generating_world = true;
 
			// delete all players.
 
			for (i = 0; i != MAX_PLAYERS; i++) {
 
				ChangeOwnershipOfPlayerItems(i, OWNER_SPECTATOR);
 
				_players[i].is_active = false;
 
			}
 
			_generating_world = false;
 
			// delete all stations owned by a player
 
			DeleteAllPlayerStations();
 
		} else
 
			ShowErrorMessage(INVALID_STRING_ID, STR_4009_GAME_LOAD_FAILED, 0, 0);
 

	
 
		break;
 
	}
 

	
 

	
 
	case SM_MENU: /* Switch to game intro menu */
 
		LoadIntroGame();
 
		break;
 

	
 
	case SM_SAVE: /* Save game */
 
@@ -1262,50 +1262,51 @@ bool AfterLoadGame(uint version)
 
			}
 
		} END_TILE_LOOP(tile, MapSizeX(), MapSizeY(), 0);
 
	}
 

	
 
	if (version < 0x900) {
 
		Town *t;
 
		FOR_ALL_TOWNS(t) {
 
			UpdateTownMaxPass(t);
 
		}
 
	}
 

	
 
	if (version < 0xF00) {
 
		BEGIN_TILE_LOOP(tile, MapSizeX(), MapSizeY(), 0) {
 
			if (IsTileType(tile, MP_RAILWAY) && HasSignals(tile) && HASBIT(_m[tile].m4, 2)) {
 
				CLRBIT(_m[tile].m4, 2);
 
				SETBIT(_m[tile].m4, 3);
 
			}
 
			// Clear possible junk data in PBS bits.
 
			if (IsTileType(tile, MP_RAILWAY) && !HASBIT(_m[tile].m5, 7))
 
				SB(_m[tile].m4, 4, 4, 0);
 
		} END_TILE_LOOP(tile, MapSizeX(), MapSizeY(), 0);
 
	}
 

	
 
	if (version < 0x1000) {
 
		int i;
 
		FOR_ALL_PLAYERS(p) {
 
			EngineID i;
 

	
 
			for (i = 0; i < TOTAL_NUM_ENGINES; i++) {
 
				p->engine_replacement[i] = INVALID_ENGINE;
 
			}
 
			p->engine_renew = false;
 
			p->engine_renew_months = -6;
 
			p->engine_renew_money = 100000;
 
		}
 
		if (_local_player < MAX_PLAYERS) {
 
			// Set the human controlled player to the patch settings
 
			// Scenario editor do not have any companies
 
			p = GetPlayer(_local_player);
 
			p->engine_renew = _patches.autorenew;
 
			p->engine_renew_months = _patches.autorenew_months;
 
			p->engine_renew_money = _patches.autorenew_money;
 
		}
 
	}
 

	
 
	/* In version 16.1 of the savegame, trains became aware of station lengths
 
		need to initialized to the invalid state
 
		players needs to set renew_keep_length too */
 
	if (version < 0x1001) {
 
		Vehicle *v;
 
		FOR_ALL_PLAYERS(p) {
 
			p->renew_keep_length = false;
players.c
Show inline comments
 
@@ -598,49 +598,49 @@ void PlayersYearlyLoop(void)
 
		p = GetPlayer(_local_player);
 
		if (p->num_valid_stat_ent > 5 && p->old_economy[0].performance_history < p->old_economy[4].performance_history) {
 
			SndPlayFx(SND_01_BAD_YEAR);
 
		} else {
 
			SndPlayFx(SND_00_GOOD_YEAR);
 
		}
 
	}
 
}
 

	
 
void DeletePlayerWindows(PlayerID pi)
 
{
 
	DeleteWindowById(WC_COMPANY, pi);
 
	DeleteWindowById(WC_FINANCES, pi);
 
	DeleteWindowById(WC_STATION_LIST, pi);
 
	DeleteWindowById(WC_TRAINS_LIST,   (INVALID_STATION << 16) | pi);
 
	DeleteWindowById(WC_ROADVEH_LIST,  (INVALID_STATION << 16) | pi);
 
	DeleteWindowById(WC_SHIPS_LIST,    (INVALID_STATION << 16) | pi);
 
	DeleteWindowById(WC_AIRCRAFT_LIST, (INVALID_STATION << 16) | pi);
 
	DeleteWindowById(WC_BUY_COMPANY, pi);
 
}
 

	
 
byte GetPlayerRailtypes(PlayerID p)
 
{
 
	byte rt = 0;
 
	uint i;
 
	EngineID i;
 

	
 
	for (i = 0; i != TOTAL_NUM_ENGINES; i++) {
 
		const Engine* e = GetEngine(i);
 

	
 
		if (e->type == VEH_Train &&
 
				HASBIT(e->player_avail, p) &&
 
				!(RailVehInfo(i)->flags & RVI_WAGON)) {
 
			assert(e->railtype < RAILTYPE_END);
 
			SETBIT(rt, e->railtype);
 
		}
 
	}
 

	
 
	return rt;
 
}
 

	
 
static void DeletePlayerStuff(PlayerID pi)
 
{
 
	Player *p;
 

	
 
	DeletePlayerWindows(pi);
 
	p = GetPlayer(pi);
 
	DeleteName(p->name_1);
 
	DeleteName(p->president_name_1);
 
	p->name_1 = 0;
train_cmd.c
Show inline comments
 
@@ -1937,49 +1937,50 @@ static void TrainPlayLeaveStationSound(c
 
		case RAILTYPE_RAIL:
 
			SndPlayVehicleFx(sfx[RailVehInfo(engtype)->engclass], v);
 
			break;
 

	
 
		case RAILTYPE_MONO:
 
			SndPlayVehicleFx(SND_47_MAGLEV_2, v);
 
			break;
 

	
 
		case RAILTYPE_MAGLEV:
 
			SndPlayVehicleFx(SND_41_MAGLEV, v);
 
			break;
 
	}
 
}
 

	
 
static bool CheckTrainStayInDepot(Vehicle *v)
 
{
 
	Vehicle *u;
 

	
 
	// bail out if not all wagons are in the same depot or not in a depot at all
 
	for (u = v; u != NULL; u = u->next)
 
		if (u->u.rail.track != 0x80 || u->tile != v->tile)
 
			return false;
 

	
 
	if (v->u.rail.force_proceed == 0) {
 
		byte trackdir = GetVehicleTrackdir(v);
 
		Trackdir trackdir = GetVehicleTrackdir(v);
 

	
 
		if (++v->load_unload_time_rem < 37) {
 
			InvalidateWindowClasses(WC_TRAINS_LIST);
 
			return true;
 
		}
 

	
 
		v->load_unload_time_rem = 0;
 

	
 
		if (PBSIsPbsSegment(v->tile, trackdir)) {
 
			NPFFindStationOrTileData fstd;
 
			NPFFoundTargetData ftd;
 

	
 
			if (PBSTileUnavail(v->tile) & (1 << trackdir))
 
				return true;
 

	
 
			NPFFillWithOrderData(&fstd, v);
 

	
 
			DEBUG(pbs, 2) ("pbs: (%i) choose depot (DP), tile:%x, trackdir:%i",v->unitnumber,  v->tile, trackdir);
 
			ftd = NPFRouteToStationOrTile(v->tile, trackdir, &fstd, TRANSPORT_RAIL, v->owner, v->u.rail.railtype, PBS_MODE_GREEN);
 

	
 
			// we found a way out of the pbs block
 
			if (NPFGetFlag(&ftd.node, NPF_FLAG_PBS_EXIT)) {
 
				if (NPFGetFlag(&ftd.node, NPF_FLAG_PBS_BLOCKED) || NPFGetFlag(&ftd.node, NPF_FLAG_PBS_RED))
 
					return true;
 
				else {
vehicle.h
Show inline comments
 
@@ -219,49 +219,49 @@ struct Vehicle {
 
	uint16 cargo_source;// source of cargo
 
	uint16 cargo_cap;	// total capacity
 
	uint16 cargo_count;// how many pieces are used
 

	
 
	byte day_counter; // increased by one for each day
 
	byte tick_counter;// increased by one for each tick
 

	
 
	/* Begin Order-stuff */
 
	Order current_order;     //! The current order (+ status, like: loading)
 
	OrderID cur_order_index; //! The index to the current order
 

	
 
	Order *orders;           //! Pointer to the first order for this vehicle
 
	OrderID num_orders;      //! How many orders there are in the list
 

	
 
	Vehicle *next_shared;    //! If not NULL, this points to the next vehicle that shared the order
 
	Vehicle *prev_shared;    //! If not NULL, this points to the prev vehicle that shared the order
 
	/* End Order-stuff */
 

	
 
	// Boundaries for the current position in the world and a next hash link.
 
	// NOSAVE: All of those can be updated with VehiclePositionChanged()
 
	int32 left_coord;
 
	int32 top_coord;
 
	int32 right_coord;
 
	int32 bottom_coord;
 
	uint16 next_hash;
 
	VehicleID next_hash;
 

	
 
	// Related to age and service time
 
	uint16 age;				// Age in days
 
	uint16 max_age;		// Maximum age
 
	uint16 date_of_last_service;
 
	uint16 service_interval;
 
	uint16 reliability;
 
	uint16 reliability_spd_dec;
 
	byte breakdown_ctr;
 
	byte breakdown_delay;
 
	byte breakdowns_since_last_service;
 
	byte breakdown_chance;
 
	byte build_year;
 

	
 
	bool leave_depot_instantly;	// NOSAVE: stores if the vehicle needs to leave the depot it just entered. Used by autoreplace
 

	
 
	uint16 load_unload_time_rem;
 

	
 
	int32 profit_this_year;
 
	int32 profit_last_year;
 
	uint32 value;
 

	
 

	
 

	
window.h
Show inline comments
 
@@ -35,49 +35,49 @@ typedef void WindowProc(Window *w, Windo
 
   That was all.. good luck, and enjoy :) -- TrueLight */
 

	
 
enum {
 
	RESIZE_NONE   = 0,
 

	
 
	RESIZE_LEFT   = 1,
 
	RESIZE_RIGHT  = 2,
 
	RESIZE_TOP    = 4,
 
	RESIZE_BOTTOM = 8,
 

	
 
	RESIZE_LR     = RESIZE_LEFT  | RESIZE_RIGHT,
 
	RESIZE_RB     = RESIZE_RIGHT | RESIZE_BOTTOM,
 
	RESIZE_TB     = RESIZE_TOP   | RESIZE_BOTTOM,
 
	RESIZE_LRB    = RESIZE_LEFT  | RESIZE_RIGHT  | RESIZE_BOTTOM,
 
	RESIZE_LRTB   = RESIZE_LEFT  | RESIZE_RIGHT  | RESIZE_TOP | RESIZE_BOTTOM,
 
	RESIZE_RTB    = RESIZE_RIGHT | RESIZE_TOP    | RESIZE_BOTTOM,
 
};
 

	
 
typedef struct Widget {
 
	byte type;
 
	byte resize_flag;
 
	byte color;
 
	uint16 left, right, top, bottom;
 
	uint16 unkA;
 
	uint16 tooltips;
 
	StringID tooltips;
 
} Widget;
 

	
 
enum FrameFlags {
 
	FR_TRANSPARENT  = 0x01,  ///< Makes the background transparent if set
 
	FR_NOBORDER     = 0x08,  ///< Hide border (draws just a solid box)
 
	FR_BORDERONLY   = 0x10,  ///< Draw border only, no background
 
	FR_LOWERED      = 0x20,  ///< If set the frame is lowered and the background color brighter (ie. buttons when pressed)
 
	FR_DARKENED     = 0x40,  ///< If set the background is darker, allows for lowered frames with normal background color when used with FR_LOWERED (ie. dropdown boxes)
 
};
 

	
 
/* XXX - outside "byte event" so you can set event directly without going into
 
 * the union elements at first. Because of this every first element of the union
 
 * MUST BE 'byte event'. Whoever did this must get shot! Scheduled for immediate
 
 * rewrite after 0.4.0 */
 
union WindowEvent {
 
	byte event;
 
	struct {
 
		byte event;
 
		Point pt;
 
		int widget;
 
	} click;
 

	
 
	struct {
 
		byte event;
0 comments (0 inline, 0 general)