summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-09-23 19:27:35 +0000
committerrubidium <rubidium@openttd.org>2007-09-23 19:27:35 +0000
commit4dca543135cac8034a5391e797711207ecf446b5 (patch)
tree8d414b503256ed5d9878145e189d1eecce904f00 /src
parentf4792f29cb1fc948584cd4c3c818ed8d5ae65473 (diff)
downloadopenttd-4dca543135cac8034a5391e797711207ecf446b5.tar.xz
(svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
Diffstat (limited to 'src')
-rw-r--r--src/industry_map.h22
-rw-r--r--src/newgrf_industries.cpp30
-rw-r--r--src/newgrf_industries.h14
-rw-r--r--src/newgrf_industrytiles.cpp20
4 files changed, 65 insertions, 21 deletions
diff --git a/src/industry_map.h b/src/industry_map.h
index 888f8f7a6..7cf93af5a 100644
--- a/src/industry_map.h
+++ b/src/industry_map.h
@@ -253,12 +253,24 @@ static inline void SetIndustryAnimationState(TileIndex tile, byte state)
* @param tile TileIndex of the tile to query
* @pre IsTileType(tile, MP_INDUSTRY)
* @return requested bits
- * @todo implement the storage in map array
*/
static inline byte GetIndustryRandomBits(TileIndex tile)
{
assert(IsTileType(tile, MP_INDUSTRY));
- return 0;
+ 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)
+ */
+static inline byte GetIndustryRandomBits(TileIndex tile, byte bits)
+{
+ assert(IsTileType(tile, MP_INDUSTRY));
+ _me[tile].m7 = bits;
}
/**
@@ -267,12 +279,11 @@ static inline byte GetIndustryRandomBits(TileIndex tile)
* @param tile TileIndex of the tile to query
* @pre IsTileType(tile, MP_INDUSTRY)
* @return requested triggers
- * @todo implement the storage in map array
*/
static inline byte GetIndustryTriggers(TileIndex tile)
{
assert(IsTileType(tile, MP_INDUSTRY));
- return 0;
+ return GB(_m[tile].m6, 3, 3);
}
@@ -280,12 +291,13 @@ static inline byte GetIndustryTriggers(TileIndex tile)
* Set the activated triggers bits for this industry tile
* Used for grf callbacks
* @param tile TileIndex of the tile to query
+ * @param triggers the triggers to set
* @pre IsTileType(tile, MP_INDUSTRY)
- * @todo implement the storage in map array
*/
static inline void SetIndustryTriggers(TileIndex tile, byte triggers)
{
assert(IsTileType(tile, MP_INDUSTRY));
+ SB(_m[tile].m6, 3, 3, triggers);
}
#endif /* INDUSTRY_MAP_H */
diff --git a/src/newgrf_industries.cpp b/src/newgrf_industries.cpp
index 811f76a6d..1c33f4b2e 100644
--- a/src/newgrf_industries.cpp
+++ b/src/newgrf_industries.cpp
@@ -217,19 +217,21 @@ uint32 IndustryGetVariable(const ResolverObject *object, byte variable, byte par
/* Get industry ID at offset param */
case 0x60: return GetIndustryIDAtOffset(GetNearbyTile(parameter, industry->xy), tile, industry);
- case 0x61: return 0; // Get random tile bits at offset param
+ /* Get random tile bits at offset param */
+ case 0x61:
+ tile = GetNearbyTile(parameter, tile);
+ return (IsTileType(tile, MP_INDUSTRY) && GetIndustryByTile(tile) == industry) ? GetIndustryRandomBits(tile) : 0;
/* Land info of nearby tiles */
case 0x62: return GetNearbyIndustryTileInformation(parameter, tile, INVALID_INDUSTRY);
/* Animation stage of nearby tiles */
- case 0x63: {
+ case 0x63:
tile = GetNearbyTile(parameter, tile);
if (IsTileType(tile, MP_INDUSTRY) && GetIndustryByTile(tile) == industry) {
return GetIndustryAnimationState(tile);
}
return 0xFFFFFFFF;
- }
/* Distance of nearest industry of given type */
case 0x64: return GetClosestIndustry(tile, MapNewGRFIndustryType(parameter, indspec->grf_prop.grffile->grfid), industry);
@@ -318,11 +320,27 @@ static const SpriteGroup *IndustryResolveReal(const ResolverObject *object, cons
return NULL;
}
+static uint32 IndustryGetRandomBits(const ResolverObject *object)
+{
+ return object->u.industry.ind == NULL ? 0 : 0; //object->u.industry.ind->random_bits;
+}
+
+static uint32 IndustryGetTriggers(const ResolverObject *object)
+{
+ return object->u.industry.ind == NULL ? 0 : 0; //object->u.industry.ind->triggers;
+}
+
+static void IndustrySetTriggers(const ResolverObject *object, int triggers)
+{
+ if (object->u.industry.ind == NULL) return;
+ //object->u.industry.ind->triggers = triggers;
+}
+
static void NewIndustryResolver(ResolverObject *res, TileIndex tile, Industry *indus)
{
- res->GetRandomBits = IndustryTileGetRandomBits;
- res->GetTriggers = IndustryTileGetTriggers;
- res->SetTriggers = IndustryTileSetTriggers;
+ res->GetRandomBits = IndustryGetRandomBits;
+ res->GetTriggers = IndustryGetTriggers;
+ res->SetTriggers = IndustrySetTriggers;
res->GetVariable = IndustryGetVariable;
res->ResolveReal = IndustryResolveReal;
diff --git a/src/newgrf_industries.h b/src/newgrf_industries.h
index 779050b33..3fda464dd 100644
--- a/src/newgrf_industries.h
+++ b/src/newgrf_industries.h
@@ -8,6 +8,16 @@
#include "industry.h"
#include "newgrf_spritegroup.h"
+/** When should the industry(tile) be triggered for random bits? */
+enum IndustryTrigger {
+ /** Triggered each tile loop */
+ INDUSTRY_TRIGGER_TILELOOP_PROCESS = 1,
+ /** Triggered (whole industry) each 256 ticks */
+ INDUSTRY_TRIGGER_256_TICKS = 2,
+ /** Triggered on cargo delivery */
+ INDUSTRY_TRIGGER_CARGO_DELIVERY = 4,
+};
+
/* in newgrf_industry.cpp */
uint32 IndustryGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available);
uint16 GetIndustryCallback(CallbackID callback, uint32 param1, uint32 param2, Industry *industry, IndustryType type, TileIndex tile);
@@ -19,10 +29,6 @@ bool CheckIfCallBackAllowsAvailability(IndustryType type, IndustryAvailabilityCa
IndustryType MapNewGRFIndustryType(IndustryType grf_type, uint32 grf_id);
/* in newgrf_industrytiles.cpp*/
-uint32 IndustryTileGetRandomBits(const ResolverObject *object);
-uint32 IndustryTileGetTriggers(const ResolverObject *object);
-void IndustryTileSetTriggers(const ResolverObject *object, int triggers);
-
uint32 GetNearbyIndustryTileInformation(byte parameter, TileIndex tile, IndustryID index);
#endif /* NEWGRF_INDUSTRIES_H */
diff --git a/src/newgrf_industrytiles.cpp b/src/newgrf_industrytiles.cpp
index 7de635808..e59788a13 100644
--- a/src/newgrf_industrytiles.cpp
+++ b/src/newgrf_industrytiles.cpp
@@ -114,22 +114,30 @@ static const SpriteGroup *IndustryTileResolveReal(const ResolverObject *object,
return NULL;
}
-uint32 IndustryTileGetRandomBits(const ResolverObject *object)
+static uint32 IndustryTileGetRandomBits(const ResolverObject *object)
{
const TileIndex tile = object->u.industry.tile;
- return (tile == INVALID_TILE || !IsTileType(tile, MP_INDUSTRY)) ? 0 : GetIndustryRandomBits(tile);
+ if (tile == INVALID_TILE || !IsTileType(tile, MP_INDUSTRY)) return 0;
+ return (object->scope == VSG_SCOPE_SELF) ? GetIndustryRandomBits(tile) : 0; //GetIndustryByTile(tile)->random_bits;
}
-uint32 IndustryTileGetTriggers(const ResolverObject *object)
+static uint32 IndustryTileGetTriggers(const ResolverObject *object)
{
const TileIndex tile = object->u.industry.tile;
- return (tile == INVALID_TILE || !IsTileType(tile, MP_INDUSTRY)) ? 0 : GetIndustryTriggers(tile);
+ if (tile == INVALID_TILE || !IsTileType(tile, MP_INDUSTRY)) return 0;
+ return (object->scope == VSG_SCOPE_SELF) ? GetIndustryTriggers(tile) : 0; //GetIndustryByTile(tile)->triggers;
}
-void IndustryTileSetTriggers(const ResolverObject *object, int triggers)
+static void IndustryTileSetTriggers(const ResolverObject *object, int triggers)
{
const TileIndex tile = object->u.industry.tile;
- if (IsTileType(tile, MP_INDUSTRY)) SetIndustryTriggers(tile, triggers);
+ if (tile == INVALID_TILE || !IsTileType(tile, MP_INDUSTRY)) return;
+
+ if (object->scope != VSG_SCOPE_SELF) {
+ SetIndustryTriggers(tile, triggers);
+ } else {
+ //GetIndustryByTile(tile)->triggers = triggers;
+ }
}
static void NewIndustryTileResolver(ResolverObject *res, IndustryGfx gfx, TileIndex tile, Industry *indus)