src/newgrf_canal.cpp
author rubidium
Thu, 19 Jun 2008 11:45:52 +0000
changeset 11023 583f32658248
parent 10429 1b99254f9607
permissions -rw-r--r--
(svn r13579) -Fix [FS#2088]: process the order coming after a conditional order, otherwise the vehicle would already leaving the station before it knows where the next destination is, making it leave in the wrong way. However, after processing as many conditional orders as there are in the order list it will stop processing them in order to not create an infinite loop.
7079
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
     1
/* $Id$ */
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
     2
10429
1b99254f9607 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 9252
diff changeset
     3
/** @file newgrf_canal.cpp Implementation of NewGRF canals. */
1b99254f9607 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 9252
diff changeset
     4
7079
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
     5
#include "stdafx.h"
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
     6
#include "openttd.h"
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
     7
#include "variables.h"
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
     8
#include "landscape.h"
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
     9
#include "debug.h"
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    10
#include "newgrf.h"
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    11
#include "newgrf_callbacks.h"
7702
e9990aaa0909 (svn r10484) -Codechange: reduce code duplication.
rubidium
parents: 7079
diff changeset
    12
#include "newgrf_commons.h"
7079
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    13
#include "newgrf_spritegroup.h"
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    14
#include "newgrf_canal.h"
8604
8afdd9877afd (svn r11669) -Codechange: refactor tile.h -> tile_type.h and tile_map.h
rubidium
parents: 8019
diff changeset
    15
#include "tile_map.h"
8864
0082e49e8351 (svn r11934) -Codechange: add persistent random data for river and canal tiles.
peter1138
parents: 8604
diff changeset
    16
#include "water_map.h"
7079
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    17
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    18
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    19
/** Table of canal 'feature' sprite groups */
8868
822816ce1fcb (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents: 8864
diff changeset
    20
WaterFeature _water_feature[CF_END];
7079
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    21
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    22
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    23
/* Random bits and triggers are not supported for canals, so the following
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    24
 * three functions are stubs. */
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    25
static uint32 CanalGetRandomBits(const ResolverObject *object)
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    26
{
8967
0b56f973bcf0 (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8868
diff changeset
    27
	/* Return random bits only for water tiles, not station tiles */
0b56f973bcf0 (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8868
diff changeset
    28
	return IsTileType(object->u.canal.tile, MP_WATER) ? GetWaterTileRandomBits(object->u.canal.tile) : 0;
7079
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    29
}
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    30
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    31
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    32
static uint32 CanalGetTriggers(const ResolverObject *object)
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    33
{
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    34
	return 0;
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    35
}
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    36
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    37
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    38
static void CanalSetTriggers(const ResolverObject *object, int triggers)
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    39
{
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    40
	return;
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    41
}
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    42
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    43
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    44
static uint32 CanalGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available)
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    45
{
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    46
	TileIndex tile = object->u.canal.tile;
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    47
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    48
	switch (variable) {
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    49
		case 0x80:
8019
35497d94c8d2 (svn r11042) -Fix [FS#1196]: so newgrf callbacks returned slightly wrong heights (height of nothern corner instead of height of lowest corner). Patch by frosch.
rubidium
parents: 7823
diff changeset
    50
			return GetTileZ(tile) / TILE_HEIGHT;
7079
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    51
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    52
		case 0x81:
7702
e9990aaa0909 (svn r10484) -Codechange: reduce code duplication.
rubidium
parents: 7079
diff changeset
    53
			return GetTerrainType(tile);
8864
0082e49e8351 (svn r11934) -Codechange: add persistent random data for river and canal tiles.
peter1138
parents: 8604
diff changeset
    54
0082e49e8351 (svn r11934) -Codechange: add persistent random data for river and canal tiles.
peter1138
parents: 8604
diff changeset
    55
		case 0x83:
0082e49e8351 (svn r11934) -Codechange: add persistent random data for river and canal tiles.
peter1138
parents: 8604
diff changeset
    56
			return GetWaterTileRandomBits(tile);
7079
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    57
	}
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    58
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    59
	DEBUG(grf, 1, "Unhandled canal property 0x%02X", variable);
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    60
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    61
	*available = false;
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    62
	return 0;
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    63
}
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    64
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    65
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    66
static const SpriteGroup *CanalResolveReal(const ResolverObject *object, const SpriteGroup *group)
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    67
{
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    68
	if (group->g.real.num_loaded == 0) return NULL;
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    69
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    70
	return group->g.real.loaded[0];
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    71
}
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    72
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    73
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    74
static void NewCanalResolver(ResolverObject *res, TileIndex tile)
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    75
{
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    76
	res->GetRandomBits = &CanalGetRandomBits;
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    77
	res->GetTriggers   = &CanalGetTriggers;
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    78
	res->SetTriggers   = &CanalSetTriggers;
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    79
	res->GetVariable   = &CanalGetVariable;
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    80
	res->ResolveReal   = &CanalResolveReal;
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    81
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    82
	res->u.canal.tile = tile;
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    83
7823
cad4dec2b899 (svn r10690) -Codechange: use the enum that describes all callback IDs in favor of "just" using an untyped integer.
rubidium
parents: 7702
diff changeset
    84
	res->callback        = CBID_NO_CALLBACK;
7079
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    85
	res->callback_param1 = 0;
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    86
	res->callback_param2 = 0;
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    87
	res->last_value      = 0;
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    88
	res->trigger         = 0;
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    89
	res->reseed          = 0;
9252
92e05c28a994 (svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx
parents: 8967
diff changeset
    90
	res->count           = 0;
7079
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    91
}
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    92
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    93
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    94
SpriteID GetCanalSprite(CanalFeature feature, TileIndex tile)
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    95
{
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    96
	ResolverObject object;
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    97
	const SpriteGroup *group;
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    98
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
    99
	NewCanalResolver(&object, tile);
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
   100
8868
822816ce1fcb (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents: 8864
diff changeset
   101
	group = Resolve(_water_feature[feature].group, &object);
7079
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
   102
	if (group == NULL || group->type != SGT_RESULT) return 0;
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
   103
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
   104
	return group->g.result.sprite;
35743c461482 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff changeset
   105
}