Changeset - r3382:3f2a31c8cfb5
[Not reviewed]
master
0 2 0
celestar - 18 years ago 2006-03-31 08:18:14
celestar@openttd.org
(svn r4190) -Codechange: Add and make use of an accessor function to create houses
2 files changed with 38 insertions and 61 deletions:
0 comments (0 inline, 0 general)
town_cmd.c
Show inline comments
 
@@ -1281,73 +1281,22 @@ static void DoBuildTownHouse(Town *t, Ti
 
	t->flags12 |= oneof;
 

	
 
	{
 
		int m3lo,m5,eflags;
 
		byte construction_counter = 0, construction_stage = 0, size_flags;
 

	
 
		// ENDING_2
 
		m3lo = 0;
 
		m5 = 0;
 
		if (_generating_world) {
 
			uint32 r = Random();
 

	
 
			// Value for map3lo
 
			m3lo = 0xC0;
 
			if (GB(r, 0, 8) >= 220) m3lo &= (r>>8);
 

	
 
			if (m3lo == 0xC0)
 
				ChangePopulation(t, _housetype_population[house]);
 

	
 
			// Initial value for map5.
 
			m5 = GB(r, 16, 6);
 
		}
 

	
 
		assert(IsTileType(tile, MP_CLEAR));
 

	
 
		ModifyTile(tile,
 
			MP_SETTYPE(MP_HOUSE) | MP_MAP3HI | MP_MAP3LO | MP_MAP2 | MP_MAP5 | MP_MAPOWNER,
 
			t->index,
 
			m3lo,   /* map3_lo */
 
			house,  /* map3_hi */
 
			0,     /* map_owner */
 
			m5		 /* map5 */
 
		);
 

	
 
		eflags = _housetype_extra_flags[house];
 
			construction_stage = 3; /* House is finished */
 
			if (CHANCE16(1, 7)) construction_stage = GB(r, 0, 2);
 

	
 
		if (eflags&0x18) {
 
			assert(IsTileType(tile + TileDiffXY(0, 1), MP_CLEAR));
 
			ModifyTile(tile + TileDiffXY(0, 1),
 
				MP_SETTYPE(MP_HOUSE) | MP_MAP2 | MP_MAP3LO | MP_MAP3HI | MP_MAP5 | MP_MAPOWNER,
 
				t->index,
 
				m3lo,			/* map3_lo */
 
				++house,	/* map3_hi */
 
				0,				/* map_owner */
 
				m5				/* map5 */
 
			);
 
			if (construction_stage == 3) {
 
				ChangePopulation(t, _housetype_population[house]);
 
			} else {
 
				construction_counter = GB(r, 2, 2);
 
			}
 
		}
 

	
 
		if (eflags&0x14) {
 
			assert(IsTileType(tile + TileDiffXY(1, 0), MP_CLEAR));
 
			ModifyTile(tile + TileDiffXY(1, 0),
 
				MP_SETTYPE(MP_HOUSE) | MP_MAP2 | MP_MAP3LO | MP_MAP3HI | MP_MAP5 | MP_MAPOWNER,
 
				t->index,
 
				m3lo,			/* map3_lo */
 
				++house,	/* map3_hi */
 
				0,				/* map_owner */
 
				m5				/* map5 */
 
			);
 
		}
 

	
 
		if (eflags&0x10) {
 
			assert(IsTileType(tile + TileDiffXY(1, 1), MP_CLEAR));
 
			ModifyTile(tile + TileDiffXY(1, 1),
 
				MP_SETTYPE(MP_HOUSE) | MP_MAP2 | MP_MAP3LO | MP_MAP3HI | MP_MAP5 | MP_MAPOWNER,
 
				t->index,
 
				m3lo,			/* map3_lo */
 
				++house,	/* map3_hi */
 
				0,				/* map_owner */
 
				m5				/* map5 */
 
			);
 
		}
 
		size_flags = GB(_housetype_extra_flags[house], 2, 3);
 
		MakeTownHouse(tile, t->index, construction_counter, construction_stage, size_flags, house);
 
	}
 

	
 
	// ENDING
town_map.h
Show inline comments
 
@@ -18,3 +18,31 @@ static inline Town* GetTownByTile(TileIn
 
{
 
	return GetTown(GetTownIndex(t));
 
}
 

	
 
static inline void MakeHouseTile(TileIndex t, TownID tid, byte counter, byte stage, byte type)
 
{
 
	assert(IsTileType(t, MP_CLEAR));
 

	
 
	SetTileType(t, MP_HOUSE);
 
	_m[t].m1 = 0;
 
	_m[t].m2 = tid;
 
	SB(_m[t].m3, 6, 2, stage);
 
	_m[t].m4 = type;
 
	SB(_m[t].m5, 0, 2, counter);
 

	
 
	MarkTileDirtyByTile(t);
 
}
 

	
 
enum {
 
	TWO_BY_TWO_BIT = 2, ///< House is two tiles in X and Y directions
 
	ONE_BY_TWO_BIT = 1, ///< House is two tiles in Y direction
 
	TWO_BY_ONE_BIT = 0, ///< House is two tiles in X direction
 
};
 

	
 
static inline void MakeTownHouse(TileIndex t, TownID tid, byte counter, byte stage, byte size, byte type)
 
{
 
	MakeHouseTile(t, tid, counter, stage, type);
 
	if (HASBIT(size, TWO_BY_TWO_BIT) || HASBIT(size, ONE_BY_TWO_BIT)) MakeHouseTile(t + TileDiffXY(0, 1), tid, counter, stage, ++type);
 
	if (HASBIT(size, TWO_BY_TWO_BIT) || HASBIT(size, TWO_BY_ONE_BIT)) MakeHouseTile(t + TileDiffXY(1, 0), tid, counter, stage, ++type);
 
	if (HASBIT(size, TWO_BY_TWO_BIT)) MakeHouseTile(t + TileDiffXY(1, 1), tid, counter, stage, ++type);
 
}
0 comments (0 inline, 0 general)