summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortron <tron@openttd.org>2006-03-24 08:00:45 +0000
committertron <tron@openttd.org>2006-03-24 08:00:45 +0000
commit4b0e8947d5053d0987e9d9024156786acd3aec67 (patch)
tree4204c22d52637b86f21c6792b4e8b1b842f5ed7e
parent742e806d737335cb62a2d471addf19fcbe220f49 (diff)
downloadopenttd-4b0e8947d5053d0987e9d9024156786acd3aec67.tar.xz
(svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
-rw-r--r--disaster_cmd.c13
-rw-r--r--industry_cmd.c17
-rw-r--r--industry_map.h16
3 files changed, 33 insertions, 13 deletions
diff --git a/disaster_cmd.c b/disaster_cmd.c
index d773abfb7..59346e6e7 100644
--- a/disaster_cmd.c
+++ b/disaster_cmd.c
@@ -2,6 +2,7 @@
#include "stdafx.h"
#include "openttd.h"
+#include "industry_map.h"
#include "table/strings.h"
#include "functions.h"
#include "map.h"
@@ -336,7 +337,7 @@ static void DestructIndustry(Industry *i)
TileIndex tile;
for (tile = 0; tile != MapSize(); tile++) {
- if (IsTileType(tile, MP_INDUSTRY) && _m[tile].m2 == i->index) {
+ if (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == i->index) {
_m[tile].m1 = 0;
MarkTileDirtyByTile(tile);
}
@@ -393,7 +394,7 @@ static void DisasterTick_2(Vehicle *v)
} else if (v->current_order.station == 0) {
int x,y;
TileIndex tile;
- int ind;
+ uint ind;
x = v->x_pos - 15*16;
y = v->y_pos;
@@ -405,7 +406,8 @@ static void DisasterTick_2(Vehicle *v)
if (!IsTileType(tile, MP_INDUSTRY))
return;
- v->dest_tile = ind = _m[tile].m2;
+ ind = GetIndustryIndex(tile);
+ v->dest_tile = ind;
if (GetIndustry(ind)->type == IT_OIL_REFINERY) {
v->current_order.station = 1;
@@ -464,7 +466,7 @@ static void DisasterTick_3(Vehicle *v)
} else if (v->current_order.station == 0) {
int x,y;
TileIndex tile;
- int ind;
+ uint ind;
x = v->x_pos - 15*16;
y = v->y_pos;
@@ -476,7 +478,8 @@ static void DisasterTick_3(Vehicle *v)
if (!IsTileType(tile, MP_INDUSTRY))
return;
- v->dest_tile = ind = _m[tile].m2;
+ ind = GetIndustryIndex(tile);
+ v->dest_tile = ind;
if (GetIndustry(ind)->type == IT_FACTORY) {
v->current_order.station = 1;
diff --git a/industry_cmd.c b/industry_cmd.c
index a2f118331..829c91a9d 100644
--- a/industry_cmd.c
+++ b/industry_cmd.c
@@ -3,6 +3,7 @@
#include "stdafx.h"
#include "openttd.h"
#include "clear_map.h"
+#include "industry_map.h"
#include "table/strings.h"
#include "table/sprites.h"
#include "functions.h"
@@ -350,7 +351,7 @@ static void DrawTile_Industry(TileInfo *ti)
uint32 image, ormod;
/* Pointer to industry */
- ind = GetIndustry(_m[ti->tile].m2);
+ ind = GetIndustryByTile(ti->tile);
ormod = (ind->color_map + 0x307) << PALETTE_SPRITE_START;
/* Retrieve pointer to the draw industry tile struct */
@@ -424,7 +425,7 @@ static void GetAcceptedCargo_Industry(TileIndex tile, AcceptedCargo ac)
static void GetTileDesc_Industry(TileIndex tile, TileDesc *td)
{
- const Industry* i = GetIndustry(_m[tile].m2);
+ const Industry* i = GetIndustryByTile(tile);
td->owner = i->owner;
td->str = STR_4802_COAL_MINE + i->type;
@@ -436,7 +437,7 @@ static void GetTileDesc_Industry(TileIndex tile, TileDesc *td)
static int32 ClearTile_Industry(TileIndex tile, byte flags)
{
- Industry *i = GetIndustry(_m[tile].m2);
+ Industry* i = GetIndustryByTile(tile);
/* * water can destroy industries
* in editor you can bulldoze industries
@@ -465,7 +466,7 @@ static const byte _industry_min_cargo[] = {
static void TransportIndustryGoods(TileIndex tile)
{
- Industry* i = GetIndustry(_m[tile].m2);
+ Industry* i = GetIndustryByTile(tile);
uint cw, am;
cw = min(i->cargo_waiting[0], 255);
@@ -821,7 +822,7 @@ static void TileLoop_Industry(TileIndex tile)
case 143: {
- Industry *i = GetIndustry(_m[tile].m2);
+ Industry* i = GetIndustryByTile(tile);
if (i->was_cargo_delivered) {
i->was_cargo_delivered = false;
_m[tile].m4 = 0;
@@ -847,7 +848,7 @@ static void TileLoop_Industry(TileIndex tile)
static void ClickTile_Industry(TileIndex tile)
{
- ShowIndustryViewWindow(_m[tile].m2);
+ ShowIndustryViewWindow(GetIndustryIndex(tile));
}
static uint32 GetTileTrackStatus_Industry(TileIndex tile, TransportType mode)
@@ -857,7 +858,7 @@ static uint32 GetTileTrackStatus_Industry(TileIndex tile, TransportType mode)
static void GetProducedCargo_Industry(TileIndex tile, byte *b)
{
- const Industry* i = GetIndustry(_m[tile].m2);
+ const Industry* i = GetIndustryByTile(tile);
b[0] = i->produced_cargo[0];
b[1] = i->produced_cargo[1];
@@ -872,7 +873,7 @@ void DeleteIndustry(Industry *i)
{
BEGIN_TILE_LOOP(tile_cur, i->width, i->height, i->xy);
if (IsTileType(tile_cur, MP_INDUSTRY)) {
- if (_m[tile_cur].m2 == i->index) {
+ if (GetIndustryIndex(tile_cur) == i->index) {
DoClearSquare(tile_cur);
}
} else if (IsTileType(tile_cur, MP_STATION) && _m[tile_cur].m5 == 0x4B) {
diff --git a/industry_map.h b/industry_map.h
new file mode 100644
index 000000000..c3a8d0b1c
--- /dev/null
+++ b/industry_map.h
@@ -0,0 +1,16 @@
+/* $Id$ */
+
+#include "industry.h"
+#include "macros.h"
+#include "tile.h"
+
+
+static inline uint GetIndustryIndex(TileIndex t)
+{
+ return _m[t].m2;
+}
+
+static inline Industry* GetIndustryByTile(TileIndex t)
+{
+ return GetIndustry(GetIndustryIndex(t));
+}