richk@6719: /* $Id$ */ richk@6719: richk@6719: #include "stdafx.h" richk@6719: #include "openttd.h" richk@6719: #include "variables.h" richk@6719: #include "landscape.h" richk@6719: #include "debug.h" richk@6719: #include "newgrf.h" richk@6719: #include "newgrf_callbacks.h" richk@6720: #include "newgrf_commons.h" richk@6719: #include "newgrf_spritegroup.h" richk@6719: #include "newgrf_canal.h" rubidium@6872: #include "tile_map.h" rubidium@6872: #include "water_map.h" richk@6719: richk@6719: richk@6719: /** Table of canal 'feature' sprite groups */ rubidium@6872: WaterFeature _water_feature[CF_END]; richk@6719: richk@6719: richk@6719: /* Random bits and triggers are not supported for canals, so the following richk@6719: * three functions are stubs. */ richk@6719: static uint32 CanalGetRandomBits(const ResolverObject *object) richk@6719: { rubidium@6877: /* Return random bits only for water tiles, not station tiles */ rubidium@6877: return IsTileType(object->u.canal.tile, MP_WATER) ? GetWaterTileRandomBits(object->u.canal.tile) : 0; richk@6719: } richk@6719: richk@6719: richk@6719: static uint32 CanalGetTriggers(const ResolverObject *object) richk@6719: { richk@6719: return 0; richk@6719: } richk@6719: richk@6719: richk@6719: static void CanalSetTriggers(const ResolverObject *object, int triggers) richk@6719: { richk@6719: return; richk@6719: } richk@6719: richk@6719: richk@6719: static uint32 CanalGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available) richk@6719: { richk@6719: TileIndex tile = object->u.canal.tile; richk@6719: richk@6719: switch (variable) { richk@6719: case 0x80: rubidium@6870: return GetTileZ(tile) / TILE_HEIGHT; richk@6719: richk@6719: case 0x81: richk@6720: return GetTerrainType(tile); rubidium@6872: rubidium@6872: case 0x83: rubidium@6872: return GetWaterTileRandomBits(tile); richk@6719: } richk@6719: richk@6719: DEBUG(grf, 1, "Unhandled canal property 0x%02X", variable); richk@6719: richk@6719: *available = false; richk@6719: return 0; richk@6719: } richk@6719: richk@6719: richk@6719: static const SpriteGroup *CanalResolveReal(const ResolverObject *object, const SpriteGroup *group) richk@6719: { richk@6719: if (group->g.real.num_loaded == 0) return NULL; richk@6719: richk@6719: return group->g.real.loaded[0]; richk@6719: } richk@6719: richk@6719: richk@6719: static void NewCanalResolver(ResolverObject *res, TileIndex tile) richk@6719: { richk@6719: res->GetRandomBits = &CanalGetRandomBits; richk@6719: res->GetTriggers = &CanalGetTriggers; richk@6719: res->SetTriggers = &CanalSetTriggers; richk@6719: res->GetVariable = &CanalGetVariable; richk@6719: res->ResolveReal = &CanalResolveReal; richk@6719: richk@6719: res->u.canal.tile = tile; richk@6719: richk@6743: res->callback = CBID_NO_CALLBACK; richk@6719: res->callback_param1 = 0; richk@6719: res->callback_param2 = 0; richk@6719: res->last_value = 0; richk@6719: res->trigger = 0; richk@6719: res->reseed = 0; richk@10184: res->count = 0; richk@6719: } richk@6719: richk@6719: richk@6719: SpriteID GetCanalSprite(CanalFeature feature, TileIndex tile) richk@6719: { richk@6719: ResolverObject object; richk@6719: const SpriteGroup *group; richk@6719: richk@6719: NewCanalResolver(&object, tile); richk@6719: rubidium@6872: group = Resolve(_water_feature[feature].group, &object); richk@6719: if (group == NULL || group->type != SGT_RESULT) return 0; richk@6719: richk@6719: return group->g.result.sprite; richk@6719: }