# newgrf_canal.cpp

Go to the documentation of this file.

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