Changeset - r3426:24da0f786db6
[Not reviewed]
master
0 2 0
celestar - 18 years ago 2006-04-03 11:46:28
celestar@openttd.org
(svn r4254) -Codechange: Add and make use of map accessors for town lifts.
2 files changed with 62 insertions and 24 deletions:
0 comments (0 inline, 0 general)
town_cmd.c
Show inline comments
 
@@ -81,7 +81,7 @@ typedef struct DrawTownTileStruct {
 

	
 
static void TownDrawHouseLift(const TileInfo *ti)
 
{
 
	AddChildSpriteScreen(SPR_LIFT, 14, 60 - GB(_m[ti->tile].m1, 0, 7));
 
	AddChildSpriteScreen(SPR_LIFT, 14, 60 - GetLiftPosition(ti->tile));
 
}
 

	
 
typedef void TownDrawTileProc(const TileInfo *ti);
 
@@ -157,8 +157,7 @@ static uint GetSlopeTileh_Town(TileIndex
 

	
 
static void AnimateTile_Town(TileIndex tile)
 
{
 
	int old;
 
	int a,b;
 
	int pos, dest;
 

	
 
	if (_tick_counter & 3) return;
 

	
 
@@ -171,32 +170,26 @@ static void AnimateTile_Town(TileIndex t
 
		return;
 
	}
 

	
 
	if (!((old = _m[tile].m1) & 0x80)) {
 
	if (!IsLiftMoving(tile)) {
 
		int i;
 

	
 
		_m[tile].m1 |= 0x80;
 

	
 
		/** Building has 6 floors, number 0 .. 6, where 1 is illegal.
 
		 *  This is due to the fact that the first floor is, in the graphics,
 
		 *  the height of 2 'normal' floors.
 
		 *  Furthermore, there are 6 lift positions from floor N (incl) to floor N + 1 (excl) */
 
		do {
 
			i = (Random() & 7) - 1;
 
		} while (i < 0 || i == 1 || i * 6 == old);
 
		} while (i < 0 || i == 1 || i * 6 == GetLiftPosition(tile));
 

	
 
		SB(_m[tile].m5, 0, 6, i);
 
		SetLiftDestination(tile, i);
 
	}
 

	
 
	a = GB(_m[tile].m1, 0, 7);
 
	b = GB(_m[tile].m5, 0, 6) * 6;
 
	a += (a < b) ? 1 : -1;
 
	SB(_m[tile].m1, 0, 7, a);
 
	pos = GetLiftPosition(tile);
 
	dest = GetLiftDestination(tile) * 6;
 
	pos += (pos < dest) ? 1 : -1;
 
	SetLiftPosition(tile, pos);
 

	
 
	if (a == b) {
 
		_m[tile].m1 &= 0x7F;
 
		_m[tile].m5 &= 0x40;
 
		DeleteAnimatedTile(tile);
 
	}
 
	if (pos == dest) HaltLift(tile);
 

	
 
	MarkTileDirtyByTile(tile);
 
}
 
@@ -259,7 +252,7 @@ static void MakeSingleHouseBigger(TileIn
 
{
 
	assert(IsTileType(tile, MP_HOUSE));
 

	
 
	if (_m[tile].m5 & 0x80) return;
 
	if (LiftHasDestination(tile)) return;
 

	
 
	AB(_m[tile].m5, 0, 3, 1);
 
	if (GB(_m[tile].m5, 0, 3) != 0) return;
 
@@ -293,12 +286,7 @@ static void TileLoop_Town(TileIndex tile
 
	}
 

	
 
	house = GetHouseType(tile);
 
	if (_housetype_extra_flags[house] & 0x20 &&
 
			!(_m[tile].m5 & 0x80) &&
 
			CHANCE16(1, 2) &&
 
			AddAnimatedTile(tile)) {
 
		_m[tile].m5 = (_m[tile].m5 & 0x40) | 0x80;
 
	}
 
	if ((_housetype_extra_flags[house] & 0x20) && !LiftHasDestination(tile) && CHANCE16(1, 2) && AddAnimatedTile(tile)) BeginLiftMovement(tile);
 

	
 
	t = GetTownByTile(tile);
 

	
town_map.h
Show inline comments
 
/* $Id$ */
 

	
 
#ifndef TOWN_MAP_H
 
#define TOWN_MAP_H
 

	
 
#include "town.h"
 

	
 
static inline int GetHouseType(TileIndex t)
 
@@ -14,11 +17,57 @@ static inline uint GetTownIndex(TileInde
 
	return _m[t].m2;
 
}
 

	
 
static inline bool LiftHasDestination(TileIndex t)
 
{
 
	return HASBIT(_m[t].m5, 7);
 
}
 

	
 
static inline void SetLiftDestination(TileIndex t, byte dest)
 
{
 
	SB(_m[t].m5, 0, 6, dest);
 
	SETBIT(_m[t].m1, 7); /* Start moving */
 
}
 

	
 
static inline byte GetLiftDestination(TileIndex t)
 
{
 
	return GB(_m[t].m5, 0, 6);
 
}
 

	
 
static inline bool IsLiftMoving(TileIndex t)
 
{
 
	return HASBIT(_m[t].m1, 7);
 
}
 

	
 
static inline void BeginLiftMovement(TileIndex t)
 
{
 
	SETBIT(_m[t].m5, 7);
 
}
 

	
 
static inline void HaltLift(TileIndex t)
 
{
 
	CLRBIT(_m[t].m1, 7);
 
	CLRBIT(_m[t].m5, 7);
 
	SB(_m[t].m5, 0, 6, 0);
 

	
 
	DeleteAnimatedTile(t);
 
}
 

	
 
static inline byte GetLiftPosition(TileIndex t)
 
{
 
	return GB(_m[t].m1, 0, 7);
 
}
 

	
 
static inline void SetLiftPosition(TileIndex t, byte pos)
 
{
 
	SB(_m[t].m1, 0, 7, pos);
 
}
 

	
 
static inline Town* GetTownByTile(TileIndex t)
 
{
 
	return GetTown(GetTownIndex(t));
 
}
 

	
 

	
 
static inline void MakeHouseTile(TileIndex t, TownID tid, byte counter, byte stage, byte type)
 
{
 
	assert(IsTileType(t, MP_CLEAR));
 
@@ -46,3 +95,4 @@ static inline void MakeTownHouse(TileInd
 
	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);
 
}
 
#endif
0 comments (0 inline, 0 general)