newgrf_canal.cpp

Go to the documentation of this file.
00001 /* $Id$ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
00008  */
00009 
00012 #include "stdafx.h"
00013 #include "tile_type.h"
00014 #include "debug.h"
00015 #include "newgrf_commons.h"
00016 #include "newgrf_spritegroup.h"
00017 #include "newgrf_canal.h"
00018 #include "tile_map.h"
00019 #include "water_map.h"
00020 
00021 
00023 WaterFeature _water_feature[CF_END];
00024 
00025 
00026 /* Random bits and triggers are not supported for canals, so the following
00027  * three functions are stubs. */
00028 static uint32 CanalGetRandomBits(const ResolverObject *object)
00029 {
00030   /* Return random bits only for water tiles, not station tiles */
00031   return IsTileType(object->u.canal.tile, MP_WATER) ? GetWaterTileRandomBits(object->u.canal.tile) : 0;
00032 }
00033 
00034 
00035 static uint32 CanalGetTriggers(const ResolverObject *object)
00036 {
00037   return 0;
00038 }
00039 
00040 
00041 static void CanalSetTriggers(const ResolverObject *object, int triggers)
00042 {
00043   return;
00044 }
00045 
00046 
00047 static uint32 CanalGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available)
00048 {
00049   TileIndex tile = object->u.canal.tile;
00050 
00051   switch (variable) {
00052     /* Height of tile */
00053     case 0x80: return GetTileZ(tile) / TILE_HEIGHT;
00054 
00055     /* Terrain type */
00056     case 0x81: return GetTerrainType(tile);
00057 
00058     /* Random data for river or canal tiles, otherwise zero */
00059     case 0x83: return GetWaterTileRandomBits(tile);
00060   }
00061 
00062   DEBUG(grf, 1, "Unhandled canal property 0x%02X", variable);
00063 
00064   *available = false;
00065   return UINT_MAX;
00066 }
00067 
00068 
00069 static const SpriteGroup *CanalResolveReal(const ResolverObject *object, const RealSpriteGroup *group)
00070 {
00071   if (group->num_loaded == 0) return NULL;
00072 
00073   return group->loaded[0];
00074 }
00075 
00076 
00077 static void NewCanalResolver(ResolverObject *res, TileIndex tile, const GRFFile *grffile)
00078 {
00079   res->GetRandomBits = &CanalGetRandomBits;
00080   res->GetTriggers   = &CanalGetTriggers;
00081   res->SetTriggers   = &CanalSetTriggers;
00082   res->GetVariable   = &CanalGetVariable;
00083   res->ResolveReal   = &CanalResolveReal;
00084 
00085   res->u.canal.tile = tile;
00086 
00087   res->callback        = CBID_NO_CALLBACK;
00088   res->callback_param1 = 0;
00089   res->callback_param2 = 0;
00090   res->last_value      = 0;
00091   res->trigger         = 0;
00092   res->reseed          = 0;
00093   res->count           = 0;
00094   res->grffile         = grffile;
00095 }
00096 
00097 
00098 SpriteID GetCanalSprite(CanalFeature feature, TileIndex tile)
00099 {
00100   ResolverObject object;
00101   const SpriteGroup *group;
00102 
00103   NewCanalResolver(&object, tile, _water_feature[feature].grffile);
00104 
00105   group = SpriteGroup::Resolve(_water_feature[feature].group, &object);
00106   if (group == NULL) return 0;
00107 
00108   return group->GetResult();
00109 }

Generated on Wed Dec 30 20:40:04 2009 for OpenTTD by  doxygen 1.5.6