# newgrf_canal.cpp

    00001 /* $Id: newgrf_canal.cpp 12042 2008-02-02 09:28:43Z peter1138 $ */
    00002
    00003 #include "stdafx.h"
    00004 #include "openttd.h"
    00005 #include "variables.h"
    00006 #include "landscape.h"
    00007 #include "debug.h"
    00008 #include "newgrf.h"
    00009 #include "newgrf_callbacks.h"
    00010 #include "newgrf_commons.h"
    00011 #include "newgrf_spritegroup.h"
    00012 #include "newgrf_canal.h"
    00013 #include "tile_map.h"
    00014 #include "water_map.h"
    00015
    00016
    00018 WaterFeature _water_feature[CF_END];
    00019
    00020
    00021 /* Random bits and triggers are not supported for canals, so the following
    00022  * three functions are stubs. */
    00023 static uint32 CanalGetRandomBits(const ResolverObject *object)
    00024 {
    00025   /* Return random bits only for water tiles, not station tiles */
    00026   return IsTileType(object->u.canal.tile, MP_WATER) ? GetWaterTileRandomBits(object->u.canal.tile) : 0;
    00027 }
    00028
    00029
    00030 static uint32 CanalGetTriggers(const ResolverObject *object)
    00031 {
    00032   return 0;
    00033 }
    00034
    00035
    00036 static void CanalSetTriggers(const ResolverObject *object, int triggers)
    00037 {
    00038   return;
    00039 }
    00040
    00041
    00042 static uint32 CanalGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available)
    00043 {
    00044   TileIndex tile = object->u.canal.tile;
    00045
    00046   switch (variable) {
    00047     case 0x80:
    00048       return GetTileZ(tile) / TILE_HEIGHT;
    00049
    00050     case 0x81:
    00051       return GetTerrainType(tile);
    00052
    00053     case 0x83:
    00054       return GetWaterTileRandomBits(tile);
    00055   }
    00056
    00057   DEBUG(grf, 1, "Unhandled canal property 0x%02X", variable);
    00058
    00059   *available = false;
    00060   return 0;
    00061 }
    00062
    00063
    00064 static const SpriteGroup *CanalResolveReal(const ResolverObject *object, const SpriteGroup *group)
    00065 {
    00066   if (group->g.real.num_loaded == 0) return NULL;
    00067
    00068   return group->g.real.loaded[0];
    00069 }
    00070
    00071
    00072 static void NewCanalResolver(ResolverObject *res, TileIndex tile)
    00073 {
    00074   res->GetRandomBits = &CanalGetRandomBits;
    00075   res->GetTriggers   = &CanalGetTriggers;
    00076   res->SetTriggers   = &CanalSetTriggers;
    00077   res->GetVariable   = &CanalGetVariable;
    00078   res->ResolveReal   = &CanalResolveReal;
    00079
    00080   res->u.canal.tile = tile;
    00081
    00082   res->callback        = CBID_NO_CALLBACK;
    00083   res->callback_param1 = 0;
    00084   res->callback_param2 = 0;
    00085   res->last_value      = 0;
    00086   res->trigger         = 0;
    00087   res->reseed          = 0;
    00088 }
    00089
    00090
    00091 SpriteID GetCanalSprite(CanalFeature feature, TileIndex tile)
    00092 {
    00093   ResolverObject object;
    00094   const SpriteGroup *group;
    00095
    00096   NewCanalResolver(&object, tile);
    00097
    00098   group = Resolve(_water_feature[feature].group, &object);
    00099   if (group == NULL || group->type != SGT_RESULT) return 0;
    00100
    00101   return group->g.result.sprite;
    00102 }