summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--projects/openttd.vcproj6
-rw-r--r--projects/openttd_vs80.vcproj8
-rw-r--r--source.list2
-rw-r--r--src/newgrf_industries.cpp11
-rw-r--r--src/newgrf_industries.h6
-rw-r--r--src/newgrf_industrytiles.cpp153
-rw-r--r--src/newgrf_industrytiles.h11
-rw-r--r--src/newgrf_spritegroup.h1
8 files changed, 193 insertions, 5 deletions
diff --git a/projects/openttd.vcproj b/projects/openttd.vcproj
index e7379545f..fe138c330 100644
--- a/projects/openttd.vcproj
+++ b/projects/openttd.vcproj
@@ -546,6 +546,9 @@
RelativePath=".\..\src\newgrf_industries.h">
</File>
<File
+ RelativePath=".\..\src\newgrf_industrytiles.h">
+ </File>
+ <File
RelativePath=".\..\src\newgrf_sound.h">
</File>
<File
@@ -1049,6 +1052,9 @@
RelativePath=".\..\src\newgrf_industries.cpp">
</File>
<File
+ RelativePath=".\..\src\newgrf_industrytiles.cpp">
+ </File>
+ <File
RelativePath=".\..\src\newgrf_sound.cpp">
</File>
<File
diff --git a/projects/openttd_vs80.vcproj b/projects/openttd_vs80.vcproj
index 613a61330..016f7fc56 100644
--- a/projects/openttd_vs80.vcproj
+++ b/projects/openttd_vs80.vcproj
@@ -956,6 +956,10 @@
>
</File>
<File
+ RelativePath="..\src\newgrf_industrytiles.h"
+ >
+ </File>
+ <File
RelativePath=".\..\src\newgrf_sound.h"
>
</File>
@@ -1616,6 +1620,10 @@
>
</File>
<File
+ RelativePath="..\src\newgrf_industrytiles.cpp"
+ >
+ </File>
+ <File
RelativePath=".\..\src\newgrf_sound.cpp"
>
</File>
diff --git a/source.list b/source.list
index 4be5cf88c..83a089112 100644
--- a/source.list
+++ b/source.list
@@ -149,6 +149,7 @@ newgrf_config.h
newgrf_engine.h
newgrf_house.h
newgrf_industries.h
+newgrf_industrytiles.h
newgrf_sound.h
newgrf_spritegroup.h
newgrf_station.h
@@ -322,6 +323,7 @@ newgrf_config.cpp
newgrf_engine.cpp
newgrf_house.cpp
newgrf_industries.cpp
+newgrf_industrytiles.cpp
newgrf_sound.cpp
newgrf_spritegroup.cpp
newgrf_station.cpp
diff --git a/src/newgrf_industries.cpp b/src/newgrf_industries.cpp
index 91961b0db..5c0d74134 100644
--- a/src/newgrf_industries.cpp
+++ b/src/newgrf_industries.cpp
@@ -227,16 +227,17 @@ static const SpriteGroup *IndustryResolveReal(const ResolverObject *object, cons
return NULL;
}
-static void NewIndustryResolver(ResolverObject *res, IndustryType ind_id, TileIndex tile, Industry *indus)
+static void NewIndustryResolver(ResolverObject *res, TileIndex tile, Industry *indus)
{
- res->GetRandomBits = NULL;//IndustryTileGetRandomBits;
- res->GetTriggers = NULL;//IndustryTileGetTriggers;
- res->SetTriggers = NULL;//IndustryTileSetTriggers;
+ res->GetRandomBits = IndustryTileGetRandomBits;
+ res->GetTriggers = IndustryTileGetTriggers;
+ res->SetTriggers = IndustryTileSetTriggers;
res->GetVariable = IndustryGetVariable;
res->ResolveReal = IndustryResolveReal;
res->u.industry.tile = tile;
res->u.industry.ind = indus;
+ res->u.industry.gfx = INVALID_INDUSTRYTILE;
res->callback = 0;
res->callback_param1 = 0;
@@ -251,7 +252,7 @@ uint16 GetIndustryCallback(uint16 callback, uint32 param1, uint32 param2, Indust
ResolverObject object;
const SpriteGroup *group;
- NewIndustryResolver(&object, industry->type, tile, industry);
+ NewIndustryResolver(&object, tile, industry);
object.callback = callback;
object.callback_param1 = param1;
object.callback_param2 = param2;
diff --git a/src/newgrf_industries.h b/src/newgrf_industries.h
index 7c30a26c9..54a54cbf8 100644
--- a/src/newgrf_industries.h
+++ b/src/newgrf_industries.h
@@ -8,8 +8,14 @@
#include "industry.h"
#include "newgrf_spritegroup.h"
+/* in newgrf_industry.cpp */
uint32 IndustryGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available);
uint16 GetIndustryCallback(uint16 callback, uint32 param1, uint32 param2, Industry *industry, TileIndex tile);
uint32 GetIndustryIDAtOffset(TileIndex new_tile, TileIndex old_tile, const Industry *i);
+/* in newgrf_industrytiles.cpp*/
+uint32 IndustryTileGetRandomBits(const ResolverObject *object);
+uint32 IndustryTileGetTriggers(const ResolverObject *object);
+void IndustryTileSetTriggers(const ResolverObject *object, int triggers);
+
#endif /* NEWGRF_INDUSTRIES_H */
diff --git a/src/newgrf_industrytiles.cpp b/src/newgrf_industrytiles.cpp
new file mode 100644
index 000000000..f910dfb67
--- /dev/null
+++ b/src/newgrf_industrytiles.cpp
@@ -0,0 +1,153 @@
+/* $Id$ */
+
+/** @file newgrf_industrytiles.cpp */
+
+#include "stdafx.h"
+#include "openttd.h"
+#include "functions.h"
+#include "variables.h"
+#include "debug.h"
+#include "viewport.h"
+#include "landscape.h"
+#include "newgrf.h"
+#include "industry.h"
+#include "newgrf_commons.h"
+#include "newgrf_spritegroup.h"
+#include "newgrf_callbacks.h"
+#include "newgrf_industries.h"
+#include "industry_map.h"
+#include "clear_map.h"
+#include "table/sprites.h"
+#include "sprite.h"
+
+/**
+ * Based on newhouses equivalent, but adapted for newindustries
+ * @param parameter from callback. It's in fact a pair of coordinates
+ * @param tile TileIndex from which the callback was initiated
+ * @param index of the industry been queried for
+ * @return a construction of bits obeying the newgrf format
+ */
+static uint32 GetNearbyIndustryTileInformation(byte parameter, TileIndex tile, IndustryID index)
+{
+ byte tile_type;
+ bool is_same_industry;
+
+ tile = GetNearbyTile(parameter, tile);
+ is_same_industry = (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == index);
+ tile_type = GetTerrainType(tile) << 2 | (IsTileType(tile, MP_WATER) ? 1 : 0) << 1 | (is_same_industry ? 1 : 0);
+
+ return GetTileType(tile) << 24 | (TileHeight(tile) * 8) << 16 | tile_type << 8 | GetTileSlope(tile, NULL);
+}
+
+/** This is the position of the tile relative to the northernmost tile of the industry.
+ * Format: 00yxYYXX
+ * Variable Content
+ * x the x offset from the northernmost tile
+ * XX same, but stored in a byte instead of a nibble
+ * y the y offset from the northernmost tile
+ * YY same, but stored in a byte instead of a nibble
+ * @param tile TileIndex of the tile to evaluate
+ * @param ind_tile northernmost tile of the industry
+ */
+static uint32 GetRelativePosition(TileIndex tile, TileIndex ind_tile)
+{
+ byte x = TileX(ind_tile) - TileX(tile);
+ byte y = TileY(ind_tile) - TileY(tile);
+
+ return ((y & 0xF) << 20) | ((x & 0xF) << 16) | (y << 8) | x;
+}
+
+static uint32 IndustryTileGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available)
+{
+ const Industry *inds = object->u.industry.ind;
+ TileIndex tile = object->u.industry.tile;
+ IndustryGfx gfx = object->u.industry.gfx;
+
+ if (object->scope == VSG_SCOPE_PARENT) {
+ return IndustryGetVariable(object, variable, parameter, available);
+ }
+
+ switch (variable) {
+ case 0x40 : return GetIndustryConstructionStage(tile); /* Construction state of the tile: a value between 0 and 3 */
+
+ case 0x41 : return GetTerrainType(tile);
+
+ case 0x42 : return GetTownRadiusGroup(ClosestTownFromTile(tile, (uint)-1), tile); /* Current town zone of the tile in the nearest town */
+
+ case 0x43 : return GetRelativePosition(tile, inds->xy); /* Relative position */
+
+ case 0x44 : break; /* Animation frame. Like house variable 46 but can contain anything 0..FF. */
+
+ case 0x60 : return GetNearbyIndustryTileInformation(parameter, tile, inds->index); /* Land info of nearby tiles */
+
+ case 0x61 : {/* Animation stage of nearby tiles */
+ tile = GetNearbyTile(parameter, tile);
+ return 0; // TODO define the animation scheme for newgrf. Based on same as old one?
+ }
+
+ /* Get industry tile ID at offset */
+ case 0x62 : return GetIndustryIDAtOffset(GetNearbyTile(parameter, tile), tile, inds);
+ }
+
+ return 0;
+}
+
+static const SpriteGroup *IndustryTileResolveReal(const ResolverObject *object, const SpriteGroup *group)
+{
+ /* IndustryTile do not have 'real' groups. Or do they?? */
+ return NULL;
+}
+
+uint32 IndustryTileGetRandomBits(const ResolverObject *object)
+{
+ const TileIndex tile = object->u.industry.tile;
+ return (tile == INVALID_TILE || !IsTileType(tile, MP_INDUSTRY)) ? 0 : GetIndustryRandomBits(tile);
+}
+
+uint32 IndustryTileGetTriggers(const ResolverObject *object)
+{
+ const TileIndex tile = object->u.industry.tile;
+ return (tile == INVALID_TILE || !IsTileType(tile, MP_INDUSTRY)) ? 0 : GetIndustryTriggers(tile);
+}
+
+void IndustryTileSetTriggers(const ResolverObject *object, int triggers)
+{
+ const TileIndex tile = object->u.industry.tile;
+ if (IsTileType(tile, MP_INDUSTRY)) SetIndustryTriggers(tile, triggers);
+}
+
+static void NewIndustryTileResolver(ResolverObject *res, IndustryGfx gfx, TileIndex tile, Industry *indus)
+{
+ res->GetRandomBits = IndustryTileGetRandomBits;
+ res->GetTriggers = IndustryTileGetTriggers;
+ res->SetTriggers = IndustryTileSetTriggers;
+ res->GetVariable = IndustryTileGetVariable;
+ res->ResolveReal = IndustryTileResolveReal;
+
+ res->u.industry.tile = tile;
+ res->u.industry.ind = indus;
+ res->u.industry.gfx = gfx;
+
+ res->callback = 0;
+ res->callback_param1 = 0;
+ res->callback_param2 = 0;
+ res->last_value = 0;
+ res->trigger = 0;
+ res->reseed = 0;
+}
+
+uint16 GetIndustryTileCallback(uint16 callback, uint32 param1, uint32 param2, IndustryGfx gfx_id, Industry *industry, TileIndex tile)
+{
+ ResolverObject object;
+ const SpriteGroup *group;
+
+ NewIndustryTileResolver(&object, gfx_id, tile, industry);
+ object.callback = callback;
+ object.callback_param1 = param1;
+ object.callback_param2 = param2;
+
+ group = Resolve(GetIndustryTileSpec(gfx_id)->grf_prop.spritegroup, &object);
+ if (group == NULL || group->type != SGT_CALLBACK) return CALLBACK_FAILED;
+
+ return group->g.callback.result;
+}
diff --git a/src/newgrf_industrytiles.h b/src/newgrf_industrytiles.h
new file mode 100644
index 000000000..e51a0a336
--- /dev/null
+++ b/src/newgrf_industrytiles.h
@@ -0,0 +1,11 @@
+/* $Id$ */
+
+/** @file newgrf_industrytiles.h */
+
+#ifndef NEWGRF_INDUSTRYTILES_H
+#define NEWGRF_INDUSTRYTILES_H
+
+void DrawNewIndustryTile(TileInfo *ti, IndustryGfx gfx);
+uint16 GetIndustryTileCallback(uint16 callback, uint32 param1, uint32 param2, IndustryGfx gfx_id, Industry *industry, TileIndex tile);
+
+#endif /* NEWGRF_INDUSTRYTILES_H */
diff --git a/src/newgrf_spritegroup.h b/src/newgrf_spritegroup.h
index 2f15dbb31..5575351b1 100644
--- a/src/newgrf_spritegroup.h
+++ b/src/newgrf_spritegroup.h
@@ -200,6 +200,7 @@ struct ResolverObject {
struct {
TileIndex tile;
Industry *ind;
+ IndustryGfx gfx;
} industry;
struct {
const struct CargoSpec *cs;