mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r4254) -Codechange: Add and make use of map accessors for town lifts.
This commit is contained in:
parent
89c145b14e
commit
c541a705f7
36
town_cmd.c
36
town_cmd.c
|
@ -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 tile, uint tileh)
|
|||
|
||||
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 tile)
|
|||
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(TileIndex tile)
|
|||
{
|
||||
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);
|
||||
|
||||
|
|
50
town_map.h
50
town_map.h
|
@ -1,5 +1,8 @@
|
|||
/* $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(TileIndex t)
|
|||
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(TileIndex t, TownID tid, byte counter, byte sta
|
|||
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
|
||||
|
|
Loading…
Reference in New Issue