newgrf_station.c
author celestar
Fri, 31 Mar 2006 18:36:13 +0000
changeset 3402 812f9dc4baff
parent 2967 77b04531d7a0
child 3573 d120a5847915
permissions -rw-r--r--
(svn r4212) -Codechange: Add and make use of an accessor that retrieves the type of a water tile. Add an enum describing the different water tiles
2625
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
     1
/* $Id$ */
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
     2
2963
f28ce0549513 (svn r3525) - Rename station_newgrf.[ch] to newgrf_station.[ch], and update project files.
peter1138
parents: 2625
diff changeset
     3
/** @file newgrf_station.c Functions for dealing with station classes and custom stations. */
2625
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
     4
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
     5
#include "stdafx.h"
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
     6
#include "openttd.h"
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
     7
#include "debug.h"
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
     8
#include "sprite.h"
2967
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
     9
#include "station.h"
2963
f28ce0549513 (svn r3525) - Rename station_newgrf.[ch] to newgrf_station.[ch], and update project files.
peter1138
parents: 2625
diff changeset
    10
#include "newgrf_station.h"
2625
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    11
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    12
static StationClass station_classes[STAT_CLASS_MAX];
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    13
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    14
/**
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    15
 * Reset station classes to their default state.
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    16
 * This includes initialising the Default and Waypoint classes with an empty
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    17
 * entry, for standard stations and waypoints.
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    18
 */
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    19
void ResetStationClasses(void)
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    20
{
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    21
	StationClassID i;
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    22
	for (i = 0; i < STAT_CLASS_MAX; i++) {
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    23
		station_classes[i].id = 0;
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    24
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    25
		free(station_classes[i].name);
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    26
		station_classes[i].name = NULL;
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    27
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    28
		station_classes[i].stations = 0;
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    29
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    30
		free(station_classes[i].spec);
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    31
		station_classes[i].spec = NULL;
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    32
	}
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    33
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    34
	// Set up initial data
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    35
	station_classes[0].id = 'DFLT';
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    36
	station_classes[0].name = strdup("Default");
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    37
	station_classes[0].stations = 1;
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    38
	station_classes[0].spec = malloc(sizeof(*station_classes[0].spec));
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    39
	station_classes[0].spec[0] = NULL;
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    40
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    41
	station_classes[1].id = 'WAYP';
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    42
	station_classes[1].name = strdup("Waypoints");
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    43
	station_classes[1].stations = 1;
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    44
	station_classes[1].spec = malloc(sizeof(*station_classes[1].spec));
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    45
	station_classes[1].spec[0] = NULL;
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    46
}
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    47
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    48
/**
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    49
 * Allocate a station class for the given class id.
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    50
 * @param classid A 32 bit value identifying the class.
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    51
 * @return Index into station_classes of allocated class.
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    52
 */
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    53
StationClassID AllocateStationClass(uint32 class)
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    54
{
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    55
	StationClassID i;
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    56
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    57
	for (i = 0; i < STAT_CLASS_MAX; i++) {
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    58
		if (station_classes[i].id == class) {
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    59
			// ClassID is already allocated, so reuse it.
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    60
			return i;
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    61
		} else if (station_classes[i].id == 0) {
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    62
			// This class is empty, so allocate it to the ClassID.
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    63
			station_classes[i].id = class;
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    64
			return i;
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    65
		}
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    66
	}
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    67
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    68
	DEBUG(grf, 2)("StationClassAllocate: Already allocated %d classes, using default.", STAT_CLASS_MAX);
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    69
	return STAT_CLASS_DFLT;
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    70
}
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    71
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    72
/**
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    73
 * Return the number of stations for the given station class.
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    74
 * @param sclass Index of the station class.
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    75
 * @return Number of stations in the class.
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    76
 */
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    77
uint GetNumCustomStations(StationClassID sclass)
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    78
{
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    79
	assert(sclass < STAT_CLASS_MAX);
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    80
	return station_classes[sclass].stations;
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    81
}
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    82
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    83
/**
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    84
 * Tie a station spec to its station class.
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    85
 * @param spec The station spec.
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    86
 */
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    87
void SetCustomStation(StationSpec *spec)
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    88
{
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    89
	StationClass *station_class;
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    90
	int i;
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    91
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    92
	assert(spec->sclass < STAT_CLASS_MAX);
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    93
	station_class = &station_classes[spec->sclass];
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    94
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    95
	i = station_class->stations++;
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    96
	station_class->spec = realloc(station_class->spec, station_class->stations * sizeof(*station_class->spec));
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    97
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    98
	station_class->spec[i] = spec;
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
    99
}
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
   100
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
   101
/**
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
   102
 * Retrieve a station spec from a class.
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
   103
 * @param sclass Index of the station class.
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
   104
 * @param station The station index with the class.
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
   105
 * @return The station spec.
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
   106
 */
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
   107
const StationSpec *GetCustomStation(StationClassID sclass, uint station)
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
   108
{
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
   109
	assert(sclass < STAT_CLASS_MAX);
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
   110
	if (station < station_classes[sclass].stations)
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
   111
		return station_classes[sclass].spec[station];
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
   112
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
   113
	// If the custom station isn't defined any more, then the GRF file
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
   114
	// probably was not loaded.
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
   115
	return NULL;
19bf7f695537 (svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff changeset
   116
}
2967
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   117
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   118
static const RealSpriteGroup *ResolveStationSpriteGroup(const SpriteGroup *spg, const Station *st)
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   119
{
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   120
	switch (spg->type) {
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   121
		case SGT_REAL:
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   122
			return &spg->g.real;
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   123
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   124
		case SGT_DETERMINISTIC: {
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   125
			const DeterministicSpriteGroup *dsg = &spg->g.determ;
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   126
			SpriteGroup *target;
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   127
			int value = -1;
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   128
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   129
			if ((dsg->variable >> 6) == 0) {
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   130
				/* General property */
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   131
				value = GetDeterministicSpriteValue(dsg->variable);
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   132
			} else {
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   133
				if (st == NULL) {
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   134
					/* We are in a build dialog of something,
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   135
					 * and we are checking for something undefined.
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   136
					 * That means we should get the first target
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   137
					 * (NOT the default one). */
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   138
					if (dsg->num_ranges > 0) {
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   139
						target = dsg->ranges[0].group;
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   140
					} else {
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   141
						target = dsg->default_group;
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   142
					}
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   143
					return ResolveStationSpriteGroup(target, NULL);
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   144
				}
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   145
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   146
				/* Station-specific property. */
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   147
				if (dsg->var_scope == VSG_SCOPE_PARENT) {
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   148
					/* TODO: Town structure. */
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   149
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   150
				} else /* VSG_SELF */ {
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   151
					if (dsg->variable == 0x40 || dsg->variable == 0x41) {
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   152
						/* FIXME: This is ad hoc only
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   153
						 * for waypoints. */
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   154
						value = 0x01010000;
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   155
					} else {
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   156
						/* TODO: Only small fraction done. */
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   157
						// TTDPatch runs on little-endian arch;
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   158
						// Variable is 0x70 + offset in the TTD's station structure
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   159
						switch (dsg->variable - 0x70) {
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   160
							case 0x80: value = st->facilities;             break;
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   161
							case 0x81: value = st->airport_type;           break;
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   162
							case 0x82: value = st->truck_stops->status;    break;
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   163
							case 0x83: value = st->bus_stops->status;      break;
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   164
							case 0x86: value = st->airport_flags & 0xFFFF; break;
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   165
							case 0x87: value = st->airport_flags & 0xFF;   break;
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   166
							case 0x8A: value = st->build_date;             break;
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   167
						}
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   168
					}
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   169
				}
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   170
			}
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   171
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   172
			target = value != -1 ? EvalDeterministicSpriteGroup(dsg, value) : dsg->default_group;
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   173
			return ResolveStationSpriteGroup(target, st);
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   174
		}
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   175
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   176
		default:
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   177
		case SGT_RANDOMIZED:
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   178
			DEBUG(grf, 6)("I don't know how to handle random spritegroups yet!");
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   179
			return NULL;
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   180
	}
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   181
}
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   182
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   183
uint32 GetCustomStationRelocation(const StationSpec *spec, const Station *st, byte ctype)
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   184
{
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   185
	const RealSpriteGroup *rsg = ResolveStationSpriteGroup(spec->spritegroup[ctype], st);
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   186
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   187
	if (rsg->sprites_per_set != 0) {
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   188
		if (rsg->loading_count != 0) return rsg->loading[0]->g.result.result;
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   189
		if (rsg->loaded_count != 0) return rsg->loaded[0]->g.result.result;
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   190
	}
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   191
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   192
	DEBUG(grf, 6)("Custom station 0x%08x::0x%02x has no sprites associated.",
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   193
		spec->grfid, spec->localidx);
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   194
	/* This is what gets subscribed of dtss->image in newgrf.c,
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   195
	 * so it's probably kinda "default offset". Try to use it as
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   196
	 * emergency measure. */
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   197
	return 0;
77b04531d7a0 (svn r3530) - NewGRF: Move station resolver to newgrf_station
peter1138
parents: 2963
diff changeset
   198
}