2006-03-24 08:00:45 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2006-04-10 15:09:56 +00:00
|
|
|
/** @file industry_map.h Accessors for industries */
|
|
|
|
|
|
|
|
#ifndef INDUSTRY_MAP_H
|
|
|
|
#define INDUSTRY_MAP_H
|
|
|
|
|
2009-08-30 11:47:41 +00:00
|
|
|
#include "industrytype.h"
|
2008-07-26 16:14:10 +00:00
|
|
|
#include "water_map.h"
|
2006-04-14 01:54:07 +00:00
|
|
|
|
2006-04-15 01:06:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The following enums are indices used to know what to draw for this industry tile.
|
|
|
|
* They all are pointing toward array _industry_draw_tile_data, in table/industry_land.h
|
|
|
|
* How to calculate the correct position ? GFXid << 2 | IndustryStage (0 to 3)
|
|
|
|
*/
|
2006-04-14 01:54:07 +00:00
|
|
|
enum {
|
2006-09-08 22:12:57 +00:00
|
|
|
GFX_COAL_MINE_TOWER_NOT_ANIMATED = 0,
|
|
|
|
GFX_COAL_MINE_TOWER_ANIMATED = 1,
|
|
|
|
GFX_POWERPLANT_CHIMNEY = 8,
|
|
|
|
GFX_POWERPLANT_SPARKS = 10,
|
|
|
|
GFX_OILRIG_1 = 24,
|
|
|
|
GFX_OILRIG_2 = 25,
|
|
|
|
GFX_OILRIG_3 = 26,
|
|
|
|
GFX_OILRIG_4 = 27,
|
|
|
|
GFX_OILRIG_5 = 28,
|
|
|
|
GFX_OILWELL_NOT_ANIMATED = 29,
|
|
|
|
GFX_OILWELL_ANIMATED_1 = 30,
|
|
|
|
GFX_OILWELL_ANIMATED_2 = 31,
|
|
|
|
GFX_OILWELL_ANIMATED_3 = 32,
|
|
|
|
GFX_COPPER_MINE_TOWER_NOT_ANIMATED = 47,
|
|
|
|
GFX_COPPER_MINE_TOWER_ANIMATED = 48,
|
|
|
|
GFX_COPPER_MINE_CHIMNEY = 49,
|
|
|
|
GFX_GOLD_MINE_TOWER_NOT_ANIMATED = 79,
|
|
|
|
GFX_GOLD_MINE_TOWER_ANIMATED = 88,
|
|
|
|
GFX_TOY_FACTORY = 143,
|
|
|
|
GFX_PLASTIC_FOUNTAIN_ANIMATED_1 = 148,
|
|
|
|
GFX_PLASTIC_FOUNTAIN_ANIMATED_2 = 149,
|
|
|
|
GFX_PLASTIC_FOUNTAIN_ANIMATED_3 = 150,
|
|
|
|
GFX_PLASTIC_FOUNTAIN_ANIMATED_4 = 151,
|
|
|
|
GFX_PLASTIC_FOUNTAIN_ANIMATED_5 = 152,
|
|
|
|
GFX_PLASTIC_FOUNTAIN_ANIMATED_6 = 153,
|
|
|
|
GFX_PLASTIC_FOUNTAIN_ANIMATED_7 = 154,
|
|
|
|
GFX_PLASTIC_FOUNTAIN_ANIMATED_8 = 155,
|
|
|
|
GFX_BUBBLE_GENERATOR = 161,
|
|
|
|
GFX_BUBBLE_CATCHER = 162,
|
|
|
|
GFX_TOFFEE_QUARY = 165,
|
|
|
|
GFX_SUGAR_MINE_SIEVE = 174,
|
2007-08-26 00:23:32 +00:00
|
|
|
GFX_WATERTILE_SPECIALCHECK = 255, ///< not really a tile, but rather a very special check
|
2006-04-14 01:54:07 +00:00
|
|
|
};
|
2006-03-24 08:00:45 +00:00
|
|
|
|
2007-04-03 21:51:40 +00:00
|
|
|
/**
|
|
|
|
* Get the industry ID of the given tile
|
|
|
|
* @param t the tile to get the industry ID from
|
|
|
|
* @pre IsTileType(t, MP_INDUSTRY)
|
|
|
|
* @return the industry ID
|
|
|
|
*/
|
2006-08-20 19:31:58 +00:00
|
|
|
static inline IndustryID GetIndustryIndex(TileIndex t)
|
2006-03-24 08:00:45 +00:00
|
|
|
{
|
2006-03-30 09:29:01 +00:00
|
|
|
assert(IsTileType(t, MP_INDUSTRY));
|
2006-03-24 08:00:45 +00:00
|
|
|
return _m[t].m2;
|
|
|
|
}
|
|
|
|
|
2007-04-03 21:51:40 +00:00
|
|
|
/**
|
|
|
|
* Is this industry tile fully built?
|
|
|
|
* @param t the tile to analyze
|
|
|
|
* @pre IsTileType(t, MP_INDUSTRY)
|
|
|
|
* @return true if and only if the industry tile is fully built
|
|
|
|
*/
|
2006-03-30 09:29:01 +00:00
|
|
|
static inline bool IsIndustryCompleted(TileIndex t)
|
2006-03-24 13:46:45 +00:00
|
|
|
{
|
2006-03-30 09:29:01 +00:00
|
|
|
assert(IsTileType(t, MP_INDUSTRY));
|
2007-11-19 21:02:30 +00:00
|
|
|
return HasBit(_m[t].m1, 7);
|
2006-03-24 13:46:45 +00:00
|
|
|
}
|
|
|
|
|
2006-04-10 21:00:56 +00:00
|
|
|
IndustryType GetIndustryType(TileIndex tile);
|
|
|
|
|
2006-04-10 15:09:56 +00:00
|
|
|
/**
|
|
|
|
* Set if the industry that owns the tile as under construction or not
|
|
|
|
* @param tile the tile to query
|
|
|
|
* @param isCompleted whether it is completed or not
|
|
|
|
* @pre IsTileType(tile, MP_INDUSTRY)
|
|
|
|
*/
|
|
|
|
static inline void SetIndustryCompleted(TileIndex tile, bool isCompleted)
|
|
|
|
{
|
|
|
|
assert(IsTileType(tile, MP_INDUSTRY));
|
|
|
|
SB(_m[tile].m1, 7, 1, isCompleted ? 1 :0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the industry construction stage of the specified tile
|
|
|
|
* @param tile the tile to query
|
|
|
|
* @pre IsTileType(tile, MP_INDUSTRY)
|
|
|
|
* @return the construction stage
|
|
|
|
*/
|
|
|
|
static inline byte GetIndustryConstructionStage(TileIndex tile)
|
|
|
|
{
|
|
|
|
assert(IsTileType(tile, MP_INDUSTRY));
|
2007-09-28 21:24:25 +00:00
|
|
|
return IsIndustryCompleted(tile) ? (byte)INDUSTRY_COMPLETED : GB(_m[tile].m1, 0, 2);
|
2006-04-10 15:09:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the industry construction stage of the specified tile
|
|
|
|
* @param tile the tile to query
|
|
|
|
* @param value the new construction stage
|
|
|
|
* @pre IsTileType(tile, MP_INDUSTRY)
|
|
|
|
*/
|
|
|
|
static inline void SetIndustryConstructionStage(TileIndex tile, byte value)
|
|
|
|
{
|
|
|
|
assert(IsTileType(tile, MP_INDUSTRY));
|
|
|
|
SB(_m[tile].m1, 0, 2, value);
|
|
|
|
}
|
2006-03-24 13:46:45 +00:00
|
|
|
|
2009-12-20 13:45:43 +00:00
|
|
|
/**
|
|
|
|
* Get the industry graphics ID for the given industry tile as
|
|
|
|
* stored in the without translation.
|
|
|
|
* @param t the tile to get the gfx for
|
|
|
|
* @pre IsTileType(t, MP_INDUSTRY)
|
|
|
|
* @return the gfx ID
|
|
|
|
*/
|
2007-09-23 19:55:42 +00:00
|
|
|
static inline IndustryGfx GetCleanIndustryGfx(TileIndex t)
|
|
|
|
{
|
|
|
|
assert(IsTileType(t, MP_INDUSTRY));
|
|
|
|
return _m[t].m5 | (GB(_m[t].m6, 2, 1) << 8);
|
|
|
|
}
|
|
|
|
|
2007-04-03 21:51:40 +00:00
|
|
|
/**
|
|
|
|
* Get the industry graphics ID for the given industry tile
|
|
|
|
* @param t the tile to get the gfx for
|
|
|
|
* @pre IsTileType(t, MP_INDUSTRY)
|
|
|
|
* @return the gfx ID
|
|
|
|
*/
|
2006-04-10 21:00:56 +00:00
|
|
|
static inline IndustryGfx GetIndustryGfx(TileIndex t)
|
2006-03-25 10:38:28 +00:00
|
|
|
{
|
2006-03-30 09:29:01 +00:00
|
|
|
assert(IsTileType(t, MP_INDUSTRY));
|
2007-09-23 19:55:42 +00:00
|
|
|
return GetTranslatedIndustryTileID(GetCleanIndustryGfx(t));
|
2006-03-25 10:38:28 +00:00
|
|
|
}
|
|
|
|
|
2007-04-03 21:51:40 +00:00
|
|
|
/**
|
|
|
|
* Set the industry graphics ID for the given industry tile
|
|
|
|
* @param t the tile to set the gfx for
|
|
|
|
* @pre IsTileType(t, MP_INDUSTRY)
|
|
|
|
* @param gfx the graphics ID
|
|
|
|
*/
|
2006-04-10 21:00:56 +00:00
|
|
|
static inline void SetIndustryGfx(TileIndex t, IndustryGfx gfx)
|
2006-03-25 10:38:28 +00:00
|
|
|
{
|
2006-03-30 09:29:01 +00:00
|
|
|
assert(IsTileType(t, MP_INDUSTRY));
|
2007-09-23 19:55:42 +00:00
|
|
|
_m[t].m5 = GB(gfx, 0, 8);
|
|
|
|
SB(_m[t].m6, 2, 1, GB(gfx, 8, 1));
|
2006-03-25 10:38:28 +00:00
|
|
|
}
|
|
|
|
|
2008-07-26 16:14:10 +00:00
|
|
|
/**
|
|
|
|
* Tests if the industry tile was built on water.
|
|
|
|
* @param t the industry tile
|
|
|
|
* @return true iff on water
|
|
|
|
*/
|
|
|
|
static inline bool IsIndustryTileOnWater(TileIndex t)
|
|
|
|
{
|
|
|
|
assert(IsTileType(t, MP_INDUSTRY));
|
|
|
|
return (GetWaterClass(t) != WATER_CLASS_INVALID);
|
|
|
|
}
|
|
|
|
|
2006-04-10 15:09:56 +00:00
|
|
|
/**
|
|
|
|
* Returns this indutry tile's construction counter value
|
|
|
|
* @param tile the tile to query
|
|
|
|
* @pre IsTileType(tile, MP_INDUSTRY)
|
|
|
|
* @return the construction counter
|
|
|
|
*/
|
|
|
|
static inline byte GetIndustryConstructionCounter(TileIndex tile)
|
|
|
|
{
|
|
|
|
assert(IsTileType(tile, MP_INDUSTRY));
|
|
|
|
return GB(_m[tile].m1, 2, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets this indutry tile's construction counter value
|
|
|
|
* @param tile the tile to query
|
|
|
|
* @param value the new value for the construction counter
|
|
|
|
* @pre IsTileType(tile, MP_INDUSTRY)
|
|
|
|
*/
|
|
|
|
static inline void SetIndustryConstructionCounter(TileIndex tile, byte value)
|
|
|
|
{
|
|
|
|
assert(IsTileType(tile, MP_INDUSTRY));
|
|
|
|
SB(_m[tile].m1, 2, 2, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset the construction stage counter of the industry,
|
|
|
|
* as well as the completion bit.
|
|
|
|
* In fact, it is the same as restarting construction frmo ground up
|
|
|
|
* @param tile the tile to query
|
|
|
|
* @pre IsTileType(tile, MP_INDUSTRY)
|
|
|
|
*/
|
|
|
|
static inline void ResetIndustryConstructionStage(TileIndex tile)
|
|
|
|
{
|
|
|
|
assert(IsTileType(tile, MP_INDUSTRY));
|
2008-08-03 18:56:44 +00:00
|
|
|
SB(_m[tile].m1, 0, 4, 0);
|
2008-08-03 18:51:13 +00:00
|
|
|
SB(_m[tile].m1, 7, 1, 0);
|
2006-04-10 15:09:56 +00:00
|
|
|
}
|
|
|
|
|
2006-04-12 18:10:54 +00:00
|
|
|
/**
|
|
|
|
* Get the animation loop number
|
|
|
|
* @param tile the tile to get the animation loop number of
|
2006-12-30 11:41:54 +00:00
|
|
|
* @pre IsTileType(tile, MP_INDUSTRY)
|
2006-04-12 18:10:54 +00:00
|
|
|
*/
|
|
|
|
static inline byte GetIndustryAnimationLoop(TileIndex tile)
|
|
|
|
{
|
|
|
|
assert(IsTileType(tile, MP_INDUSTRY));
|
|
|
|
return _m[tile].m4;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the animation loop number
|
|
|
|
* @param tile the tile to set the animation loop number of
|
|
|
|
* @param count the new animation frame number
|
2006-12-30 11:41:54 +00:00
|
|
|
* @pre IsTileType(tile, MP_INDUSTRY)
|
2006-04-12 18:10:54 +00:00
|
|
|
*/
|
|
|
|
static inline void SetIndustryAnimationLoop(TileIndex tile, byte count)
|
|
|
|
{
|
|
|
|
assert(IsTileType(tile, MP_INDUSTRY));
|
|
|
|
_m[tile].m4 = count;
|
|
|
|
}
|
|
|
|
|
2006-12-30 11:51:37 +00:00
|
|
|
/**
|
|
|
|
* Get the animation state
|
|
|
|
* @param tile the tile to get the animation state of
|
|
|
|
* @pre IsTileType(tile, MP_INDUSTRY)
|
|
|
|
*/
|
|
|
|
static inline byte GetIndustryAnimationState(TileIndex tile)
|
|
|
|
{
|
|
|
|
assert(IsTileType(tile, MP_INDUSTRY));
|
2006-12-30 11:57:52 +00:00
|
|
|
return _m[tile].m3;
|
2006-12-30 11:51:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the animation state
|
|
|
|
* @param tile the tile to set the animation state of
|
2007-04-03 21:51:40 +00:00
|
|
|
* @param state the new animation state
|
2006-12-30 11:51:37 +00:00
|
|
|
* @pre IsTileType(tile, MP_INDUSTRY)
|
|
|
|
*/
|
|
|
|
static inline void SetIndustryAnimationState(TileIndex tile, byte state)
|
|
|
|
{
|
|
|
|
assert(IsTileType(tile, MP_INDUSTRY));
|
2006-12-30 11:57:52 +00:00
|
|
|
_m[tile].m3 = state;
|
2006-12-30 11:51:37 +00:00
|
|
|
}
|
|
|
|
|
2007-06-12 14:22:28 +00:00
|
|
|
/**
|
|
|
|
* Get the random bits for this tile.
|
|
|
|
* Used for grf callbacks
|
|
|
|
* @param tile TileIndex of the tile to query
|
|
|
|
* @pre IsTileType(tile, MP_INDUSTRY)
|
|
|
|
* @return requested bits
|
|
|
|
*/
|
|
|
|
static inline byte GetIndustryRandomBits(TileIndex tile)
|
|
|
|
{
|
|
|
|
assert(IsTileType(tile, MP_INDUSTRY));
|
2007-09-23 19:27:35 +00:00
|
|
|
return _me[tile].m7;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the random bits for this tile.
|
|
|
|
* Used for grf callbacks
|
|
|
|
* @param tile TileIndex of the tile to query
|
|
|
|
* @param bits the random bits
|
|
|
|
* @pre IsTileType(tile, MP_INDUSTRY)
|
|
|
|
*/
|
2007-10-07 01:37:06 +00:00
|
|
|
static inline void SetIndustryRandomBits(TileIndex tile, byte bits)
|
2007-09-23 19:27:35 +00:00
|
|
|
{
|
|
|
|
assert(IsTileType(tile, MP_INDUSTRY));
|
|
|
|
_me[tile].m7 = bits;
|
2007-06-12 14:22:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the activated triggers bits for this industry tile
|
|
|
|
* Used for grf callbacks
|
|
|
|
* @param tile TileIndex of the tile to query
|
|
|
|
* @pre IsTileType(tile, MP_INDUSTRY)
|
|
|
|
* @return requested triggers
|
|
|
|
*/
|
|
|
|
static inline byte GetIndustryTriggers(TileIndex tile)
|
|
|
|
{
|
|
|
|
assert(IsTileType(tile, MP_INDUSTRY));
|
2007-09-23 19:27:35 +00:00
|
|
|
return GB(_m[tile].m6, 3, 3);
|
2007-06-12 14:22:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the activated triggers bits for this industry tile
|
|
|
|
* Used for grf callbacks
|
|
|
|
* @param tile TileIndex of the tile to query
|
2007-09-23 19:27:35 +00:00
|
|
|
* @param triggers the triggers to set
|
2007-06-12 14:22:28 +00:00
|
|
|
* @pre IsTileType(tile, MP_INDUSTRY)
|
|
|
|
*/
|
|
|
|
static inline void SetIndustryTriggers(TileIndex tile, byte triggers)
|
|
|
|
{
|
|
|
|
assert(IsTileType(tile, MP_INDUSTRY));
|
2007-09-23 19:27:35 +00:00
|
|
|
SB(_m[tile].m6, 3, 3, triggers);
|
2007-06-12 14:22:28 +00:00
|
|
|
}
|
|
|
|
|
2009-03-08 16:10:39 +00:00
|
|
|
/**
|
|
|
|
* Make the given tile an industry tile
|
|
|
|
* @param t the tile to make an industry tile
|
|
|
|
* @param index the industry this tile belongs to
|
|
|
|
* @param gfx the graphics to use for the tile
|
|
|
|
* @param random the random value
|
2009-09-19 09:51:14 +00:00
|
|
|
* @param wc the water class for this industry; only useful when build on water
|
2009-03-08 16:10:39 +00:00
|
|
|
*/
|
|
|
|
static inline void MakeIndustry(TileIndex t, IndustryID index, IndustryGfx gfx, uint8 random, WaterClass wc)
|
|
|
|
{
|
|
|
|
SetTileType(t, MP_INDUSTRY);
|
|
|
|
_m[t].m1 = 0;
|
|
|
|
_m[t].m2 = index;
|
|
|
|
_m[t].m3 = 0;
|
|
|
|
_m[t].m4 = 0;
|
|
|
|
SetIndustryGfx(t, gfx); // m5, part of m6
|
|
|
|
SetIndustryTriggers(t, 0); // rest of m6
|
|
|
|
SetIndustryRandomBits(t, random); // m7
|
|
|
|
SetWaterClass(t, wc);
|
|
|
|
}
|
|
|
|
|
2006-04-10 15:09:56 +00:00
|
|
|
#endif /* INDUSTRY_MAP_H */
|