Changeset - r4:44fa2d88cb6a
[Not reviewed]
master
0 5 0
darkvater - 20 years ago 2004-08-10 14:42:52
darkvater@openttd.org
(svn r5) -Fix: townname generation of TTDLX savegames. All work
except for German Townnames (also fix one typo on
English town-names)
-CodeChange: *act_paper to *act_water in Town to
more resemble its use
-Fix: AI players now retain AI status. Since TTDLX
savegame status is not fully documented, some holes
exist (AI state is set to one without a vehicle, otherwise
it crashes)
5 files changed with 91 insertions and 32 deletions:
0 comments (0 inline, 0 general)
economy.c
Show inline comments
 
@@ -1055,13 +1055,13 @@ static int32 DeliverGoods(int num_pieces
 
	subsidised = CheckSubsidised(s_from, s_to, cargo_type);
 

	
 
	// Increase town's counter for some special goods types
 
	{
 
		Town *t = s_to->town;
 
		if (cargo_type == CT_FOOD) t->new_act_food += num_pieces;
 
		if (cargo_type == CT_STEEL)  t->new_act_paper += num_pieces;
 
		if (cargo_type == CT_STEEL)  t->new_act_water += num_pieces;
 
	}
 

	
 
	// Give the goods to the industry.
 
	DeliverGoodsToIndustry(s_to->xy, cargo_type, num_pieces);
 
	
 
	// Determine profit
namegen.c
Show inline comments
 
@@ -531,34 +531,34 @@ static byte MakeGermanTownName(byte *buf
 
	
 
	ext=GETNUM(7, 28); /* Extension - Prefix / Suffix */
 

	
 
	if ((ext==12) || (ext==19)) {
 
		i=GETNUM(2,NUM_GERMAN_3-2);
 
		AppendPart(&buf, 2+i, german_3);
 
		}
 
	}
 

	
 

	
 
	i=GETNUM(3,NUM_GERMAN_1);
 

	
 
	AppendPart(&buf, i, german_1);
 

	
 
	if (i>NUM_GERMAN_1_HARDCODED-1) {
 
		AppendPart(&buf, GETNUM(5, NUM_GERMAN_2), german_2);
 
		}
 
	}
 

	
 
	if (ext==24) {
 
		i=GETNUM(9,NUM_GERMAN_4);
 

	
 
		if (i<=NUM_GERMAN_4_PRECHANGE-1) {
 
			AppendPart(&buf, 0, german_3);
 
			AppendPart(&buf, i, german_4);
 
			} else {
 
		} else {
 
			AppendPart(&buf, 1, german_3);
 
			AppendPart(&buf, i, german_4);
 
			}
 
		}
 
	}
 

	
 
	return 0;
 
}
 

	
 
#define NUM_SPANISH_1 86
 
static const char spanish_1[] = 
 
@@ -799,13 +799,13 @@ static const char silly_1[] =
 

	
 
	MK("Sleepy")
 
	MK("Scatter")
 
	MK("Scramble")
 
	MK("Silly")
 
	MK("Simple")
 
	MK("Tricky")
 
	MK("Trickle")
 
	MK("Slippery")
 
	MK("Slimey")
 
	MK("Slumber")
 
	MK("Soggy")
 

	
 
	MK("Sliggles")
 
@@ -1969,6 +1969,37 @@ TownNameGenerator * const _town_name_gen
 
	MakeFinnishTownName,
 
	MakePolishTownName,
 
	MakeSlovakishTownName,
 
	MakeHungarianTownName,
 
	MakeAustrianTownName
 
};
 

	
 
#define FIXNUM(x, y, z) (((((x) << 16) / (y)) + 1) << z)
 

	
 
uint32 GetOldTownName(uint32 townnameparts, byte old_town_name_type)
 
{
 
	uint32 a = 0;
 
	switch (old_town_name_type) {
 
		case 0: case 3: /* English, American */
 
			/*	Already OK */
 
			return townnameparts;
 
		case 1: /* French */
 
			/*	For some reason 86 needs to be subtracted from townnameparts
 
			 *	0000 0000 0000 0000 0000 0000 1111 1111 */
 
			return FIXNUM(townnameparts - 86, NUM_FRENCH_1, 0);
 
		case 2: /* German */
 
			#ifdef _DEBUG
 
				printf("German Townnames are buggy... (%d)\n", townnameparts);
 
			#endif
 
			return townnameparts;
 
		case 4: /* Latin-American */
 
			/*	0000 0000 0000 0000 0000 0000 1111 1111 */
 
			return FIXNUM(townnameparts, NUM_SPANISH_1, 0);
 
		case 5: /* Silly */
 
				//AppendPart(&buf, GETNUM(16, NUM_SILLY_2),silly_2);
 
			/*	NUM_SILLY_1	-	lower 16 bits
 
			 *	NUM_SILLY_2	-	upper 16 bits without leading 1 (first 8 bytes)
 
			 *	1000 0000 2222 2222 0000 0000 1111 1111 */
 
			return FIXNUM(townnameparts, NUM_SILLY_1, 0) | FIXNUM(((townnameparts >> 16)&0xFF), NUM_SILLY_2, 16);
 
	}
 
	return 0;
 
}
oldloader.c
Show inline comments
 
@@ -46,16 +46,17 @@ typedef struct {
 
	byte growth_rate;
 
	uint16 new_max_pass, new_max_mail;
 
	uint16 new_act_pass, new_act_mail;
 
	uint16 max_pass, max_mail;
 
	uint16 act_pass, act_mail;
 
	byte pct_pass_transported, pct_mail_transported;
 
	uint16 new_act_food, new_act_paper;
 
	uint16 act_food, act_paper;
 
	uint16 new_act_food, new_act_water;
 
	uint16 act_food, act_water;
 
	byte road_build_months;
 
	byte fund_buildings_months;
 
	// unused bytes at the end of the Town Struct
 
	uint32 unk56;
 
	uint32 unk5A;
 
} GCC_PACK OldTown;
 
assert_compile(sizeof(OldTown) == 0x5E);
 

	
 
typedef struct {
 
@@ -576,21 +577,27 @@ static void LoadSavegameBytes(void *p, s
 
	assert(count > 0);
 
	do {
 
		*ptr++ = DecodeSavegameByte();
 
	} while (--count);
 
}
 

	
 
static void FixTown(Town *t, OldTown *o, int num)
 
extern uint32 GetOldTownName(uint32 townnameparts, byte old_town_name_type);
 

	
 
static void FixTown(Town *t, OldTown *o, int num, byte town_name_type)
 
{
 
	do {
 
		t->xy = o->xy;
 
		t->population = o->population;
 
		t->townnametype = o->townnametype;
 
		t->townnameparts = o->townnameparts;
 
		if (IS_INT_INSIDE(o->townnametype, 0x20C1, 0x20C2 + 1))
 
			t->townnametype = SPECSTR_TOWNNAME_ENGLISH;
 
		// Random TownNames
 
		if (IS_INT_INSIDE(o->townnametype, 0x20C1, 0x20C2 + 1)) {
 
			t->townnametype = SPECSTR_TOWNNAME_ENGLISH + town_name_type;
 
			if (o->xy)
 
				t->townnameparts = GetOldTownName(o->townnameparts, town_name_type);
 
		}
 

	
 
		t->grow_counter = o->grow_counter;
 
		t->flags12 = o->flags12;
 
		memcpy(t->ratings,o->ratings,sizeof(t->ratings));
 
		t->have_ratings = o->have_ratings;
 
		t->statues = o->statues;
 
@@ -605,15 +612,15 @@ static void FixTown(Town *t, OldTown *o,
 
		t->max_mail = o->max_mail;
 
		t->act_pass = o->act_pass;
 
		t->act_mail = o->act_mail;
 
		t->pct_pass_transported = o->pct_pass_transported;
 
		t->pct_mail_transported = o->pct_mail_transported;
 
		t->new_act_food = o->new_act_food;
 
		t->new_act_paper = o->new_act_paper;
 
		t->new_act_water = o->new_act_water;
 
		t->act_food = o->act_food;
 
		t->act_paper = o->act_paper;
 
		t->act_water = o->act_water;
 
		t->road_build_months = o->road_build_months;
 
		t->fund_buildings_months = o->fund_buildings_months;
 
	} while (t++,o++,--num);
 
}
 

	
 
static void FixIndustry(Industry *i, OldIndustry *o, int num)
 
@@ -850,24 +857,34 @@ static void FixAiBuildRec(AiBuildRec *n,
 
	n->buildcmd_a = o->buildcmd_a;
 
	n->buildcmd_b = o->buildcmd_b;
 
	n->direction = o->direction;
 
	n->cargo = o->cargo;
 
}
 

	
 
static void FixPlayer(Player *n, OldPlayer *o, int num)
 
static void FixPlayer(Player *n, OldPlayer *o, int num, byte town_name_type)
 
{
 
	int i, j;
 
	int x = 0;
 

	
 
	
 
	do {
 
		n->name_1 = RemapOldStringID(o->name_1);
 
		n->name_2 = o->name_2;
 
		if (o->name_1 == 0 && x == 0)
 
			n->name_1 = STR_SV_UNNAMED;
 
		else
 
			n->is_active=true;
 
		/*	In every Old TTD(Patch) game Player1 (0) is human, and all others are AI
 
		 *	(Except in .SV2 savegames, which were 2 player games, but we are not fixing
 
		 *	that
 
		 */
 

	
 
		if (x == 0) {
 
			if (o->name_1 == 0) // if first player doesn't have a name, he is 'unnamed'
 
				n->name_1 = STR_SV_UNNAMED;
 
		} else {
 
			n->is_ai = 1;
 
		}
 

	
 
		if (o->name_1 != 0)
 
			n->is_active = true;
 
		
 
		n->face = o->face;
 
		n->president_name_1 = o->pres_name_1;
 
		n->president_name_2 = o->pres_name_2;
 
		
 
		n->money64 = n->player_money = o->money;
 
@@ -896,13 +913,18 @@ static void FixPlayer(Player *n, OldPlay
 
		FixEconomy(&n->cur_economy, &o->economy[0]);
 
		for(i=0; i!=24; i++) FixEconomy(&n->old_economy[i], &o->economy[i+1]);
 
		n->inaugurated_year = o->inaugurated_date - 1920;
 
		n->last_build_coordinate = o->last_build_coordinate;
 
		n->num_valid_stat_ent = o->num_valid_stat_ent;
 

	
 
		n->ai.state = o->ai_state;
 
		/*	Not good, since AI doesn't have a vehicle assigned as 
 
		 *	in p->ai.cur_veh and thus will crash on certain actions.
 
		 *	Best is to set state to AiStateVehLoop (2)
 
		 *	n->ai.state = o->ai_state;
 
		 */
 
		n->ai.state = 2;
 
		n->ai.state_mode = o->ai_state_mode;
 
		n->ai.state_counter = o->ai_state_counter;
 
		n->ai.timeout_counter = o->ai_timeout_counter;
 
		n->ai.banned_tile_count = o->ai_banned_tile_count;
 
		n->ai.railtype_to_use = o->ai_railtype_to_use;
 
		
 
@@ -1029,15 +1051,21 @@ bool LoadOldSaveGame(const char *file)
 
	_cur_state = &lss;
 
	memset(&lss, 0, sizeof(lss));
 

	
 
	lss.fin = fopen(file, "rb");
 
	if (lss.fin == NULL) return false;
 

	
 
	fseek(lss.fin, 49, SEEK_SET);
 
	/*	B - byte 8bit					(1)
 
	 *	W - word 16bit				(2 bytes)
 
	 *	L - 'long' word 32bit	(4 bytes)
 
	 */
 
	fseek(lss.fin, 49, SEEK_SET); // 47B TITLE, W Checksum - Total 49
 

	
 
	// load the file into memory
 
	/*	Load the file into memory
 
	 *	Game Data 0x77179 + L4 (256x256) + L5 (256x256)
 
	 */
 
	m = (OldMain *)malloc(sizeof(OldMain));
 
	LoadSavegameBytes(m, sizeof(OldMain));
 

	
 
	// copy sections of it to our datastructures.
 
	memcpy(_map_owner, m->map_owner, sizeof(_map_owner));
 
	memcpy(_map2, m->map2, sizeof(_map2));
 
@@ -1060,21 +1088,21 @@ bool LoadOldSaveGame(const char *file)
 
		}
 
	}
 

	
 
	memcpy(_order_array, m->order_list, sizeof(m->order_list));
 
	_ptr_to_next_order = _order_array + REMAP_ORDER_IDX(m->ptr_to_next_order);
 

	
 
	FixTown(_towns, m->town_list, lengthof(m->town_list));
 
	FixTown(_towns, m->town_list, lengthof(m->town_list), m->town_name_type);
 
	FixIndustry(_industries, m->industries, lengthof(m->industries));
 
	FixStation(_stations, m->stations, lengthof(m->stations));
 

	
 
	FixDepot(_depots, m->depots, lengthof(m->depots));
 
	FixVehicle(_vehicles, m->vehicles, lengthof(m->vehicles));
 
	FixSubsidy(_subsidies, m->subsidies, lengthof(m->subsidies));
 
	
 
	FixPlayer(_players, m->players, lengthof(m->players));
 
	FixPlayer(_players, m->players, lengthof(m->players), m->town_name_type);
 
	FixName(m->names, lengthof(m->names));
 
	FixSign(_sign_list, m->signs, lengthof(m->signs));
 
	FixEngine(_engines, m->engines, lengthof(m->engines));
 

	
 
	_opt.diff_level = m->difficulty_level;
 
	_opt.currency = m->currency;
town.h
Show inline comments
 
@@ -44,15 +44,15 @@ struct Town {
 
	// Amount of passengers that were transported.
 
	byte pct_pass_transported;
 
	byte pct_mail_transported;
 

	
 
	// Amount of food and paper that was transported. Actually a bit mask would be enough.
 
	uint16 act_food;
 
	uint16 act_paper;
 
	uint16 act_water;
 
	uint16 new_act_food;
 
	uint16 new_act_paper;
 
	uint16 new_act_water;
 
	
 
	// Time until we rebuild a house.
 
	byte time_until_rebuild;
 

	
 
	// When to grow town next time.
 
	byte grow_counter;
town_cmd.c
Show inline comments
 
@@ -847,15 +847,15 @@ static void DoCreateTown(Town *t, TileIn
 
	t->act_mail = 0;
 

	
 
	t->pct_pass_transported = 0;
 
	t->pct_mail_transported = 0;
 
	t->fund_buildings_months = 0;
 
	t->new_act_food = 0;
 
	t->new_act_paper = 0;
 
	t->new_act_water = 0;
 
	t->act_food = 0;
 
	t->act_paper = 0;
 
	t->act_water = 0;
 

	
 
	for(i = 0; i != MAX_PLAYERS; i++)
 
		t->ratings[i] = 500;
 

	
 
	t->have_ratings = 0;
 
	t->statues = 0;
 
@@ -1587,13 +1587,13 @@ static void UpdateTownGrowRate(Town *t)
 
	}
 

	
 
	if (_opt.landscape == LT_HILLY) {
 
		if (GET_TILEHEIGHT(t->xy) >= _opt.snow_line &&	t->act_food == 0)
 
			return;
 
	} else if (_opt.landscape == LT_DESERT) {
 
		if (GetMapExtraBits(t->xy) == 1 && (t->act_food==0 || t->act_paper==0))
 
		if (GetMapExtraBits(t->xy) == 1 && (t->act_food==0 || t->act_water==0))
 
			return;
 
	}
 

	
 
	t->growth_rate = m;
 
	if (m <= t->grow_counter)
 
		t->grow_counter = m;
 
@@ -1606,13 +1606,13 @@ static void UpdateTownAmounts(Town *t)
 
	// Using +1 here to prevent overflow and division by zero
 
	t->pct_pass_transported = t->new_act_pass * 256 / (t->new_max_pass + 1);
 

	
 
	t->max_pass = t->new_max_pass; t->new_max_pass = 0;
 
	t->act_pass = t->new_act_pass; t->new_act_pass = 0;
 
	t->act_food = t->new_act_food; t->new_act_food = 0;
 
	t->act_paper = t->new_act_paper; t->new_act_paper = 0;
 
	t->act_water = t->new_act_water; t->new_act_water = 0;
 

	
 
	// Using +1 here to prevent overflow and division by zero
 
	t->pct_mail_transported = t->new_act_mail * 256 / (t->new_max_mail + 1);
 
	t->max_mail = t->new_max_mail; t->new_max_mail = 0;
 
	t->act_mail = t->new_act_mail; t->new_act_mail = 0;
 

	
 
@@ -1808,15 +1808,15 @@ static const byte _town_desc[] = {
 
	SLE_VAR(Town,new_act_mail,SLE_UINT16),
 

	
 
	SLE_VAR(Town,pct_pass_transported,SLE_UINT8),
 
	SLE_VAR(Town,pct_mail_transported,SLE_UINT8),
 

	
 
	SLE_VAR(Town,act_food,		SLE_UINT16),
 
	SLE_VAR(Town,act_paper,		SLE_UINT16),
 
	SLE_VAR(Town,act_water,		SLE_UINT16),
 
	SLE_VAR(Town,new_act_food,SLE_UINT16),
 
	SLE_VAR(Town,new_act_paper,SLE_UINT16),
 
	SLE_VAR(Town,new_act_water,SLE_UINT16),
 

	
 
	SLE_VAR(Town,time_until_rebuild,		SLE_UINT8),
 
	SLE_VAR(Town,grow_counter,					SLE_UINT8),
 
	SLE_VAR(Town,growth_rate,						SLE_UINT8),
 
	SLE_VAR(Town,fund_buildings_months,	SLE_UINT8),
 
	SLE_VAR(Town,road_build_months,			SLE_UINT8),
0 comments (0 inline, 0 general)