newgrf_canal.cpp

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

Generated on Sat Apr 17 23:24:50 2010 for OpenTTD by  doxygen 1.6.1