mirror of https://github.com/OpenTTD/OpenTTD
(svn r4254) -Codechange: Add and make use of map accessors for town lifts.
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)
|
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);
|
typedef void TownDrawTileProc(const TileInfo *ti);
|
||||||
|
@ -157,8 +157,7 @@ static uint GetSlopeTileh_Town(TileIndex tile, uint tileh)
|
||||||
|
|
||||||
static void AnimateTile_Town(TileIndex tile)
|
static void AnimateTile_Town(TileIndex tile)
|
||||||
{
|
{
|
||||||
int old;
|
int pos, dest;
|
||||||
int a,b;
|
|
||||||
|
|
||||||
if (_tick_counter & 3) return;
|
if (_tick_counter & 3) return;
|
||||||
|
|
||||||
|
@ -171,32 +170,26 @@ static void AnimateTile_Town(TileIndex tile)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!((old = _m[tile].m1) & 0x80)) {
|
if (!IsLiftMoving(tile)) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
_m[tile].m1 |= 0x80;
|
|
||||||
|
|
||||||
/** Building has 6 floors, number 0 .. 6, where 1 is illegal.
|
/** 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,
|
* This is due to the fact that the first floor is, in the graphics,
|
||||||
* the height of 2 'normal' floors.
|
* the height of 2 'normal' floors.
|
||||||
* Furthermore, there are 6 lift positions from floor N (incl) to floor N + 1 (excl) */
|
* Furthermore, there are 6 lift positions from floor N (incl) to floor N + 1 (excl) */
|
||||||
do {
|
do {
|
||||||
i = (Random() & 7) - 1;
|
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);
|
pos = GetLiftPosition(tile);
|
||||||
b = GB(_m[tile].m5, 0, 6) * 6;
|
dest = GetLiftDestination(tile) * 6;
|
||||||
a += (a < b) ? 1 : -1;
|
pos += (pos < dest) ? 1 : -1;
|
||||||
SB(_m[tile].m1, 0, 7, a);
|
SetLiftPosition(tile, pos);
|
||||||
|
|
||||||
if (a == b) {
|
if (pos == dest) HaltLift(tile);
|
||||||
_m[tile].m1 &= 0x7F;
|
|
||||||
_m[tile].m5 &= 0x40;
|
|
||||||
DeleteAnimatedTile(tile);
|
|
||||||
}
|
|
||||||
|
|
||||||
MarkTileDirtyByTile(tile);
|
MarkTileDirtyByTile(tile);
|
||||||
}
|
}
|
||||||
|
@ -259,7 +252,7 @@ static void MakeSingleHouseBigger(TileIndex tile)
|
||||||
{
|
{
|
||||||
assert(IsTileType(tile, MP_HOUSE));
|
assert(IsTileType(tile, MP_HOUSE));
|
||||||
|
|
||||||
if (_m[tile].m5 & 0x80) return;
|
if (LiftHasDestination(tile)) return;
|
||||||
|
|
||||||
AB(_m[tile].m5, 0, 3, 1);
|
AB(_m[tile].m5, 0, 3, 1);
|
||||||
if (GB(_m[tile].m5, 0, 3) != 0) return;
|
if (GB(_m[tile].m5, 0, 3) != 0) return;
|
||||||
|
@ -293,12 +286,7 @@ static void TileLoop_Town(TileIndex tile)
|
||||||
}
|
}
|
||||||
|
|
||||||
house = GetHouseType(tile);
|
house = GetHouseType(tile);
|
||||||
if (_housetype_extra_flags[house] & 0x20 &&
|
if ((_housetype_extra_flags[house] & 0x20) && !LiftHasDestination(tile) && CHANCE16(1, 2) && AddAnimatedTile(tile)) BeginLiftMovement(tile);
|
||||||
!(_m[tile].m5 & 0x80) &&
|
|
||||||
CHANCE16(1, 2) &&
|
|
||||||
AddAnimatedTile(tile)) {
|
|
||||||
_m[tile].m5 = (_m[tile].m5 & 0x40) | 0x80;
|
|
||||||
}
|
|
||||||
|
|
||||||
t = GetTownByTile(tile);
|
t = GetTownByTile(tile);
|
||||||
|
|
||||||
|
|
50
town_map.h
50
town_map.h
|
@ -1,5 +1,8 @@
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
|
#ifndef TOWN_MAP_H
|
||||||
|
#define TOWN_MAP_H
|
||||||
|
|
||||||
#include "town.h"
|
#include "town.h"
|
||||||
|
|
||||||
static inline int GetHouseType(TileIndex t)
|
static inline int GetHouseType(TileIndex t)
|
||||||
|
@ -14,11 +17,57 @@ static inline uint GetTownIndex(TileIndex t)
|
||||||
return _m[t].m2;
|
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)
|
static inline Town* GetTownByTile(TileIndex t)
|
||||||
{
|
{
|
||||||
return GetTown(GetTownIndex(t));
|
return GetTown(GetTownIndex(t));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline void MakeHouseTile(TileIndex t, TownID tid, byte counter, byte stage, byte type)
|
static inline void MakeHouseTile(TileIndex t, TownID tid, byte counter, byte stage, byte type)
|
||||||
{
|
{
|
||||||
assert(IsTileType(t, MP_CLEAR));
|
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) || 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);
|
if (HASBIT(size, TWO_BY_TWO_BIT)) MakeHouseTile(t + TileDiffXY(1, 1), tid, counter, stage, ++type);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue