src/newgrf_fsmports.cpp
author rubidium
Tue, 17 Jul 2007 00:03:21 +0000
branchNewGRF_ports
changeset 6730 f09255ea0123
parent 6722 72f280229ee1
child 6734 6e4db2fda167
permissions -rw-r--r--
(svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
     1
/* $Id$ */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
     2
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
     3
/** @file newgrf_station.cpp Functions for dealing with station classes and custom stations. */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
     4
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
     5
#include "stdafx.h"
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
     6
#include "openttd.h"
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
     7
#include "variables.h"
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
     8
#include "functions.h"
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
     9
#include "landscape.h"
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    10
#include "debug.h"
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    11
#include "sprite.h"
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    12
#include "table/sprites.h"
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    13
#include "table/strings.h"
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    14
#include "station.h"
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    15
#include "station_map.h"
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    16
#include "newgrf.h"
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    17
#include "newgrf_callbacks.h"
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    18
#include "newgrf_commons.h"
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    19
#include "newgrf_station.h"
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    20
#include "newgrf_spritegroup.h"
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    21
#include "date.h"
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    22
#include "helpers.hpp"
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    23
#include "cargotype.h"
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    24
#include "town_map.h"
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    25
#include "newgrf_town.h"
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    26
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    27
static FSMportsClass fsmports_classes[FSMPORTS_CLASS_MAX];
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    28
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    29
enum {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    30
	MAX_SPECLIST = 255,
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    31
};
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    32
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    33
/**
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    34
 * Reset station classes to their default state.
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    35
 * This includes initialising the Default and Waypoint classes with an empty
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    36
 * entry, for standard stations and waypoints.
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    37
 */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    38
void ResetFSMportsClasses()
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    39
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    40
	for (FSMportsClassID i = FSMPORTS_CLASS_BEGIN; i < FSMPORTS_CLASS_MAX; i++) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    41
		fsmports_classes[i].id = 0;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    42
		fsmports_classes[i].name = STR_EMPTY;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    43
		fsmports_classes[i].FSMports = 0;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    44
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    45
		free(fsmports_classes[i].spec);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    46
		fsmports_classes[i].spec = NULL;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    47
	}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    48
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    49
	/* Set up initial data */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    50
	//fsmports_classes[0].id = 'DFLT';
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    51
	//fsmports_classes[0].name = STR_STAT_CLASS_DFLT;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    52
	//fsmports_classes[0].FSMports = 1;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    53
	//fsmports_classes[0].spec = MallocT<FSMportsSpec*>(1);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    54
	//fsmports_classes[0].spec[0] = NULL;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    55
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    56
	//fsmports_classes[1].id = 'WAYP';
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    57
	//fsmports_classes[1].name = STR_STAT_CLASS_WAYP;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    58
	//fsmports_classes[1].FSMports = 1;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    59
	//fsmports_classes[1].spec = MallocT<FSMportsSpec*>(1);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    60
	//fsmports_classes[1].spec[0] = NULL;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    61
}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    62
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    63
/**
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    64
 * Allocate a station class for the given class id.
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    65
 * @param cls A 32 bit value identifying the class.
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    66
 * @return Index into station_classes of allocated class.
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    67
 */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    68
FSMportsClassID AllocateFSMportsClass(uint32 cls)
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    69
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    70
	for (FSMportsClassID i = FSMPORTS_CLASS_BEGIN; i < FSMPORTS_CLASS_MAX; i++) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    71
		if (fsmports_classes[i].id == cls) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    72
			/* ClassID is already allocated, so reuse it. */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    73
			return i;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    74
		} else if (fsmports_classes[i].id == 0) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    75
			/* This class is empty, so allocate it to the ClassID. */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    76
			fsmports_classes[i].id = cls;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    77
			return i;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    78
		}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    79
	}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    80
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    81
	grfmsg(2, "FSMportsClassAllocate: already allocated %d classes, using default", FSMPORTS_CLASS_MAX);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    82
	return FSMPORTS_CLASS_DFLT;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    83
}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    84
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    85
/** Set the name of a custom station class */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    86
void SetFSMportsClassName(FSMportsClassID sclass, StringID name)
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    87
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    88
	assert(sclass < FSMPORTS_CLASS_MAX);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    89
	fsmports_classes[sclass].name = name;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    90
}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    91
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    92
/** Retrieve the name of a custom station class */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    93
StringID GetFSMportsClassName(FSMportsClassID sclass)
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    94
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    95
	assert(sclass < FSMPORTS_CLASS_MAX);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    96
	return fsmports_classes[sclass].name;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    97
}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    98
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    99
/** Build a list of station class name StringIDs to use in a dropdown list
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   100
 * @return Pointer to a (static) array of StringIDs
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   101
 */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   102
StringID *BuildFSMportsClassDropdown()
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   103
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   104
	/* Allow room for all station classes, plus a terminator entry */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   105
	static StringID names[FSMPORTS_CLASS_MAX + 1];
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   106
	uint i;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   107
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   108
	/* Add each name */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   109
	for (i = 0; i < FSMPORTS_CLASS_MAX && fsmports_classes[i].id != 0; i++) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   110
		names[i] = fsmports_classes[i].name;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   111
	}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   112
	/* Terminate the list */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   113
	names[i] = INVALID_STRING_ID;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   114
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   115
	return names;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   116
}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   117
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   118
/**
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   119
 * Get the number of station classes in use.
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   120
 * @return Number of station classes.
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   121
 */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   122
uint GetNumFSMportsClasses()
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   123
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   124
	uint i;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   125
	for (i = 0; i < FSMPORTS_CLASS_MAX && fsmports_classes[i].id != 0; i++);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   126
	return i;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   127
}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   128
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   129
/**
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   130
 * Return the number of stations for the given station class.
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   131
 * @param sclass Index of the station class.
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   132
 * @return Number of stations in the class.
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   133
 */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   134
uint GetNumCustomFSMports(FSMportsClassID sclass)
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   135
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   136
	assert(sclass < FSMPORTS_CLASS_MAX);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   137
	return fsmports_classes[sclass].FSMports;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   138
}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   139
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   140
/**
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   141
 * Tie a fsmport spec to its class.
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   142
 * @param fsmportspec The station spec.
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   143
 */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   144
void SetCustomFSMportsSpec(FSMportsSpec *fsmportspec)
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   145
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   146
	FSMportsClass *fsmports_class;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   147
	int i;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   148
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   149
	/* If the station has already been allocated, don't reallocate it. */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   150
	if (fsmportspec->allocated) return;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   151
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   152
	assert(fsmportspec->sclass < FSMPORTS_CLASS_MAX);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   153
	fsmports_class = &fsmports_classes[fsmportspec->sclass];
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   154
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   155
	i = fsmports_class->FSMports++;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   156
	fsmports_class->spec = ReallocT(fsmports_class->spec, fsmports_class->FSMports);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   157
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   158
	fsmports_class->spec[i] = fsmportspec;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   159
	fsmportspec->allocated = true;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   160
}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   161
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   162
/**
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   163
 * Retrieve a station spec from a class.
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   164
 * @param sclass Index of the station class.
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   165
 * @param station The station index with the class.
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   166
 * @return The station spec.
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   167
 */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   168
const FSMportsSpec *GetCustomFSMportsSpec(FSMportsClassID sclass, uint fsmport)
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   169
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   170
	assert(sclass < FSMPORTS_CLASS_MAX);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   171
	if (fsmport < fsmports_classes[sclass].FSMports)
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   172
		return fsmports_classes[sclass].spec[fsmport];
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   173
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   174
	/* If the custom station isn't defined any more, then the GRF file
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   175
	 * probably was not loaded. */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   176
	return NULL;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   177
}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   178
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   179
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   180
const FSMportsSpec *GetCustomFSMportsSpecByGrf(uint32 grfid, byte localidx)
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   181
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   182
	uint j;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   183
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   184
	for (FSMportsClassID i = FSMPORTS_CLASS_BEGIN; i < FSMPORTS_CLASS_MAX; i++) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   185
		for (j = 0; j < fsmports_classes[i].FSMports; j++) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   186
			const FSMportsSpec *fsmportspec = fsmports_classes[i].spec[j];
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   187
			if (fsmportspec == NULL) continue;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   188
			if (fsmportspec->grffile->grfid == grfid && fsmportspec->localidx == localidx) return fsmportspec;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   189
		}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   190
	}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   191
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   192
	return NULL;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   193
}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   194
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   195
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   196
/* FSMports Resolver Functions */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   197
static uint32 FSMportsGetRandomBits(const ResolverObject *object)
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   198
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   199
	const Station *st = object->u.station.st;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   200
	const TileIndex tile = object->u.station.tile;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   201
	return (st == NULL ? 0 : st->random_bits) | (tile == INVALID_TILE ? 0 : GetStationTileRandomBits(tile) << 16);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   202
}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   203
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   204
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   205
static uint32 FSMportsGetTriggers(const ResolverObject *object)
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   206
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   207
	const Station *st = object->u.station.st;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   208
	return st == NULL ? 0 : st->waiting_triggers;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   209
}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   210
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   211
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   212
static void FSMportsSetTriggers(const ResolverObject *object, int triggers)
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   213
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   214
	Station *st = (Station*)object->u.station.st;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   215
	assert(st != NULL);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   216
	st->waiting_triggers = triggers;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   217
}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   218
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   219
/**
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   220
 * FSMports variable cache
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   221
 * This caches 'expensive' station variable lookups which iterate over
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   222
 * several tiles that may be called multiple times per Resolve().
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   223
 */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   224
static struct {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   225
	uint32 v40;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   226
	uint32 v41;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   227
	uint32 v45;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   228
	uint32 v46;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   229
	uint32 v47;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   230
	uint32 v49;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   231
	uint8 valid;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   232
} _svc;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   233
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   234
static uint32 FSMportsGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available)
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   235
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   236
	const Station *st = object->u.station.st;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   237
	TileIndex tile = object->u.station.tile;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   238
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   239
	if (object->scope == VSG_SCOPE_PARENT) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   240
		/* Pass the request on to the town of the station */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   241
		Town *t;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   242
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   243
		if (st != NULL) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   244
			t = st->town;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   245
		} else if (tile != INVALID_TILE) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   246
			t = GetTownByTile(tile);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   247
		} else {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   248
			*available = false;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   249
			return UINT_MAX;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   250
		}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   251
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   252
		return TownGetVariable(variable, parameter, available, t);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   253
	}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   254
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   255
	if (st == NULL) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   256
		/* Station does not exist, so we're in a purchase list */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   257
		switch (variable) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   258
			case 0x40:
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   259
			case 0x41:
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   260
			case 0x46:
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   261
			case 0x47:
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   262
			case 0x49: return 0x2110000;       // Platforms, tracks & position
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   263
			case 0x42: return 0;               // Rail type (XXX Get current type from GUI?)
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   264
			case 0x43: return _current_player; // Station owner
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   265
			case 0x44: return 2;               // PBS status
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   266
			case 0xFA: return clamp(_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535); // Build date, clamped to a 16 bit value
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   267
		}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   268
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   269
		*available = false;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   270
		return UINT_MAX;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   271
	}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   272
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   273
	switch (variable) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   274
		/* Calculated station variables */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   275
		case 0x42: return GetTerrainType(tile) | (GetRailType(tile) << 8);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   276
		case 0x43: return st->owner; // Station owner
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   277
		case 0x48: { // Accepted cargo types
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   278
			CargoID cargo_type;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   279
			uint32 value = 0;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   280
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   281
			for (cargo_type = 0; cargo_type < NUM_CARGO; cargo_type++) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   282
				if (st->goods[cargo_type].acceptance) SETBIT(value, cargo_type);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   283
			}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   284
			return value;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   285
		}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   286
		/* Variables which use the parameter */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   287
		/* Variables 0x60 to 0x65 are handled separately below */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   288
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   289
		/* General station properties */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   290
		case 0x82: return 50;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   291
		case 0x84: return st->string_id;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   292
		case 0x86: return 0;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   293
		case 0x8A: return st->had_vehicle_of_type;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   294
		case 0xF0: return st->facilities;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   295
		case 0xF1: return st->airport_type;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   296
		case 0xF2: return st->truck_stops->status;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   297
		case 0xF3: return st->bus_stops->status;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   298
		case 0xF6: return st->airport_flags;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   299
		case 0xF7: return GB(st->airport_flags, 8, 8);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   300
		case 0xFA: return clamp(st->build_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   301
	}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   302
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   303
	/* Handle cargo variables with parameter, 0x60 to 0x65 */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   304
	if (variable >= 0x60 && variable <= 0x65) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   305
		CargoID c = GetCargoTranslation(parameter, object->u.station.statspec->grffile);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   306
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   307
		if (c == CT_INVALID) return 0;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   308
		const GoodsEntry *ge = &st->goods[c];
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   309
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   310
		switch (variable) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   311
			case 0x60: return min(ge->cargo.Count(), 4095);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   312
			case 0x61: return ge->days_since_pickup;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   313
			case 0x62: return ge->rating;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   314
			case 0x63: return ge->cargo.DaysInTransit();
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   315
			case 0x64: return ge->last_speed | (ge->last_age << 8);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   316
			case 0x65: return ge->acceptance << 3;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   317
		}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   318
	}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   319
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   320
	/* Handle cargo variables (deprecated) */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   321
	if (variable >= 0x8C && variable <= 0xEC) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   322
		const GoodsEntry *g = &st->goods[GB(variable - 0x8C, 3, 4)];
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   323
		switch (GB(variable - 0x8C, 0, 3)) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   324
			case 0: return g->cargo.Count();
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   325
			case 1: return GB(min(g->cargo.Count(), 4095), 0, 4) | (g->acceptance << 7);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   326
			case 2: return g->days_since_pickup;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   327
			case 3: return g->rating;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   328
			case 4: return g->cargo.Source();
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   329
			case 5: return g->cargo.DaysInTransit();
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   330
			case 6: return g->last_speed;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   331
			case 7: return g->last_age;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   332
		}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   333
	}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   334
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   335
	DEBUG(grf, 1, "Unhandled station property 0x%X", variable);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   336
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   337
	*available = false;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   338
	return UINT_MAX;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   339
}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   340
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   341
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   342
static const SpriteGroup *FSMportsResolveReal(const ResolverObject *object, const SpriteGroup *group)
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   343
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   344
	const Station *st = object->u.station.st;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   345
	const FSMportsSpec *fsmportspec = object->u.station.fsmportspec;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   346
	uint set;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   347
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   348
	uint cargo = 0;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   349
	CargoID cargo_type = object->u.station.cargo_type;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   350
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   351
	if (st == NULL || fsmportspec->sclass == FSMPORTS_CLASS_WAYP) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   352
		return group->g.real.loading[0];
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   353
	}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   354
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   355
	switch (cargo_type) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   356
		case CT_INVALID:
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   357
		case CT_DEFAULT_NA:
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   358
		case CT_PURCHASE:
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   359
			cargo = 0;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   360
			break;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   361
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   362
		case CT_DEFAULT:
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   363
			for (cargo_type = 0; cargo_type < NUM_CARGO; cargo_type++) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   364
				cargo += st->goods[cargo_type].cargo.Count();
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   365
			}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   366
			break;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   367
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   368
		default:
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   369
			cargo = st->goods[cargo_type].cargo.Count();
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   370
			break;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   371
	}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   372
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   373
	if (HASBIT(fsmportspec->flags, 1)) cargo /= (st->trainst_w + st->trainst_h);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   374
	cargo = min(0xfff, cargo);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   375
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   376
	if (cargo > fsmportspec->cargo_threshold) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   377
		if (group->g.real.num_loading > 0) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   378
			set = ((cargo - fsmportspec->cargo_threshold) * group->g.real.num_loading) / (4096 - fsmportspec->cargo_threshold);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   379
			return group->g.real.loading[set];
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   380
		}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   381
	} else {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   382
		if (group->g.real.num_loaded > 0) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   383
			set = (cargo * group->g.real.num_loaded) / (fsmportspec->cargo_threshold + 1);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   384
			return group->g.real.loaded[set];
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   385
		}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   386
	}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   387
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   388
	return group->g.real.loading[0];
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   389
}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   390
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   391
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   392
static void NewFSMportsResolver(ResolverObject *res, const FSMportsSpec *fsmportspec, const Station *st, TileIndex tile)
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   393
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   394
	res->GetRandomBits = FSMportsGetRandomBits;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   395
	res->GetTriggers   = FSMportsGetTriggers;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   396
	res->SetTriggers   = FSMportsSetTriggers;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   397
	res->GetVariable   = FSMportsGetVariable;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   398
	res->ResolveReal   = FSMportsResolveReal;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   399
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   400
	res->u.station.st       = st;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   401
	res->u.station.fsmportspec = fsmportspec;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   402
	res->u.station.tile     = tile;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   403
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   404
	res->callback        = 0;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   405
	res->callback_param1 = 0;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   406
	res->callback_param2 = 0;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   407
	res->last_value      = 0;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   408
	res->trigger         = 0;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   409
	res->reseed          = 0;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   410
}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   411
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   412
static const SpriteGroup *ResolveFSMports(ResolverObject *object)
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   413
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   414
	const SpriteGroup *group;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   415
	CargoID ctype = CT_DEFAULT_NA;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   416
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   417
	if (object->u.station.st == NULL) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   418
		/* No station, so we are in a purchase list */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   419
		ctype = CT_PURCHASE;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   420
	} else {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   421
		/* Pick the first cargo that we have waiting */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   422
		for (CargoID cargo = 0; cargo < NUM_CARGO; cargo++) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   423
			const CargoSpec *cs = GetCargo(cargo);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   424
			if (cs->IsValid() && object->u.station.fsmportspec->spritegroup[cargo] != NULL &&
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   425
					!object->u.station.st->goods[cargo].cargo.Empty()) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   426
				ctype = cargo;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   427
				break;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   428
			}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   429
		}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   430
	}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   431
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   432
	group = object->u.station.fsmportspec->spritegroup[ctype];
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   433
	if (group == NULL) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   434
		ctype = CT_DEFAULT;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   435
		group = object->u.station.fsmportspec->spritegroup[ctype];
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   436
	}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   437
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   438
	if (group == NULL) return NULL;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   439
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   440
	/* Remember the cargo type we've picked */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   441
	object->u.station.cargo_type = ctype;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   442
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   443
	/* Invalidate all cached vars */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   444
	_svc.valid = 0;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   445
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   446
	return Resolve(group, object);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   447
}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   448
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   449
SpriteID GetCustomFSMportsRelocation(const FSMportsSpec *fsmportspec, const Station *st, TileIndex tile)
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   450
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   451
	const SpriteGroup *group;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   452
	ResolverObject object;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   453
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   454
	NewFSMportsResolver(&object, fsmportspec, st, tile);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   455
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   456
	group = ResolveFSMports(&object);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   457
	if (group == NULL || group->type != SGT_RESULT) return 0;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   458
	return group->g.result.sprite - 0x42D;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   459
}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   460
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   461
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   462
SpriteID GetCustomFSMportsGroundRelocation(const FSMportsSpec *fsmportspec, const Station *st, TileIndex tile)
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   463
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   464
	const SpriteGroup *group;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   465
	ResolverObject object;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   466
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   467
	NewFSMportsResolver(&object, fsmportspec, st, tile);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   468
	object.callback_param1 = 1; // Indicate we are resolving the ground sprite
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   469
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   470
	group = ResolveFSMports(&object);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   471
	if (group == NULL || group->type != SGT_RESULT) return 0;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   472
	return group->g.result.sprite - 0x42D;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   473
}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   474
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   475
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   476
uint16 GetFSMportsCallback(uint16 callback, uint32 param1, uint32 param2, const FSMportsSpec *fsmportspec, const Station *st, TileIndex tile)
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   477
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   478
	const SpriteGroup *group;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   479
	ResolverObject object;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   480
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   481
	NewFSMportsResolver(&object, fsmportspec, st, tile);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   482
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   483
	object.callback        = callback;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   484
	object.callback_param1 = param1;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   485
	object.callback_param2 = param2;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   486
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   487
	group = ResolveFSMports(&object);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   488
	if (group == NULL || group->type != SGT_CALLBACK) return CALLBACK_FAILED;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   489
	return group->g.callback.result;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   490
}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   491
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   492
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   493
/**
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   494
 * Allocate a FSMportsSpec to a Station. This is called once per build operation.
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   495
 * @param statspec FSMportsSpec to allocate.
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   496
 * @param st Station to allocate it to.
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   497
 * @param exec Whether to actually allocate the spec.
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   498
 * @return Index within the FSMports's spec list, or -1 if the allocation failed.
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   499
 */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   500
int AllocateFSMportsSpecToStation(const FSMportsSpec *fsmportspec, Station *st, bool exec)
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   501
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   502
	uint i;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   503
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   504
	if (fsmportspec == NULL) return 0;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   505
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   506
	/* Check if this spec has already been allocated */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   507
	for (i = 1; i < st->num_fsmportsspecs && i < MAX_SPECLIST; i++) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   508
		if (st->fsmportsspeclist[i].spec == fsmportspec) return i;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   509
	}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   510
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   511
	for (i = 1; i < st->num_fsmportsspecs && i < MAX_SPECLIST; i++) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   512
		if (st->fsmportsspeclist[i].spec == NULL && st->fsmportsspeclist[i].grfid == 0) break;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   513
	}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   514
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   515
	if (i == MAX_SPECLIST) return -1;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   516
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   517
	if (exec) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   518
		if (i >= st->num_fsmportsspecs) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   519
			st->num_fsmportsspecs = i + 1;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   520
			st->fsmportsspeclist = ReallocT(st->fsmportsspeclist, st->num_fsmportsspecs);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   521
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   522
			if (st->num_fsmportsspecs == 2) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   523
				/* Initial allocation */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   524
				st->fsmportsspeclist[0].spec     = NULL;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   525
				st->fsmportsspeclist[0].grfid    = 0;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   526
				st->fsmportsspeclist[0].localidx = 0;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   527
			}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   528
		}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   529
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   530
		st->fsmportsspeclist[i].spec     = fsmportspec;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   531
		st->fsmportsspeclist[i].grfid    = fsmportspec->grffile->grfid;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   532
		st->fsmportsspeclist[i].localidx = fsmportspec->localidx;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   533
	}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   534
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   535
	return i;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   536
}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   537
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   538
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   539
/** Deallocate a FSMportsSpec from a Station. Called when removing a single station tile.
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   540
 * @param st Station to work with.
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   541
 * @param specindex Index of the custom station within the FSMports's spec list.
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   542
 * @return Indicates whether the FSMportsSpec was deallocated.
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   543
 */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   544
void DeallocateSpecFromFSMports(Station* st, byte specindex)
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   545
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   546
	/* specindex of 0 (default) is never freeable */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   547
	if (specindex == 0) return;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   548
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   549
	/* Check all tiles over the station to check if the specindex is still in use */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   550
	BEGIN_TILE_LOOP(tile, st->trainst_w, st->trainst_h, st->train_tile) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   551
		if (IsTileType(tile, MP_STATION) && GetStationIndex(tile) == st->index && GetCustomStationSpecIndex(tile) == specindex) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   552
			return;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   553
		}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   554
	} END_TILE_LOOP(tile, st->trainst_w, st->trainst_h, st->train_tile)
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   555
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   556
	/* This specindex is no longer in use, so deallocate it */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   557
	st->speclist[specindex].spec     = NULL;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   558
	st->speclist[specindex].grfid    = 0;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   559
	st->speclist[specindex].localidx = 0;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   560
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   561
	/* If this was the highest spec index, reallocate */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   562
	if (specindex == st->num_specs - 1) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   563
		for (; st->speclist[st->num_specs - 1].grfid == 0 && st->num_specs > 1; st->num_specs--);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   564
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   565
		if (st->num_specs > 1) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   566
			st->speclist = ReallocT(st->speclist, st->num_specs);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   567
		} else {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   568
			free(st->speclist);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   569
			st->num_specs = 0;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   570
			st->speclist  = NULL;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   571
		}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   572
	}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   573
}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   574
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   575
/** Draw representation of a station tile for GUI purposes.
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   576
 * @param x Position x of image.
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   577
 * @param y Position y of image.
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   578
 * @param axis Axis.
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   579
 * @param railtype Rail type.
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   580
 * @param sclass, station Type of station.
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   581
 * @param station station ID
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   582
 * @return True if the tile was drawn (allows for fallback to default graphic)
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   583
 */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   584
bool DrawFSMportsTile(int x, int y, RailType railtype, Axis axis, FSMportsClassID sclass, uint station)
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   585
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   586
	const FSMportsSpec *fsmportsspec;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   587
	const DrawTileSprites *sprites;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   588
	const DrawTileSeqStruct *seq;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   589
	const RailtypeInfo *rti = GetRailTypeInfo(railtype);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   590
	SpriteID relocation;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   591
	SpriteID image;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   592
	SpriteID pal = PLAYER_SPRITE_COLOR(_local_player);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   593
	uint tile = 2;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   594
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   595
	fsmportsspec = GetCustomFSMportsSpec(sclass, station);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   596
	if (fsmportsspec == NULL) return false;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   597
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   598
	relocation = GetCustomFSMportsRelocation(fsmportsspec, NULL, INVALID_TILE);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   599
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   600
	if (HASBIT(fsmportsspec->callbackmask, CBM_CUSTOM_LAYOUT)) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   601
		uint16 callback = GetFSMportsCallback(CBID_STATION_SPRITE_LAYOUT, 0x2110000, 0, fsmportsspec, NULL, INVALID_TILE);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   602
		if (callback != CALLBACK_FAILED) tile = callback;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   603
	}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   604
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   605
	if (fsmportsspec->renderdata == NULL) {
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6722
diff changeset
   606
		sprites = GetStationTileLayout(STATION_AIRPORT, tile + axis);
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   607
	} else {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   608
		sprites = &fsmportsspec->renderdata[(tile < fsmportsspec->tiles) ? tile + axis : (uint)axis];
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   609
	}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   610
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   611
	image = sprites->ground_sprite;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   612
	if (HASBIT(image, SPRITE_MODIFIER_USE_OFFSET)) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   613
		image += GetCustomFSMportsGroundRelocation(fsmportsspec, NULL, INVALID_TILE);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   614
		image += rti->custom_ground_offset;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   615
	} else {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   616
		image += rti->total_offset;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   617
	}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   618
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   619
	DrawSprite(image, PAL_NONE, x, y);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   620
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   621
	foreach_draw_tile_seq(seq, sprites->seq) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   622
		Point pt;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   623
		image = seq->image;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   624
		if (HASBIT(image, SPRITE_MODIFIER_USE_OFFSET)) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   625
			image += rti->total_offset;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   626
		} else {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   627
			image += relocation;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   628
		}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   629
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   630
		if ((byte)seq->delta_z != 0x80) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   631
			pt = RemapCoords(seq->delta_x, seq->delta_y, seq->delta_z);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   632
			DrawSprite(image, pal, x + pt.x, y + pt.y);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   633
		}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   634
	}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   635
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   636
	return true;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   637
}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   638
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   639
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   640
static const FSMportsSpec* GetFSMportsSpec(TileIndex t)
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   641
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   642
	const Station* st;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   643
	uint specindex;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   644
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   645
	if (!IsCustomStationSpecIndex(t)) return NULL;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   646
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   647
	st = GetStationByTile(t);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   648
	specindex = GetCustomStationSpecIndex(t);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   649
	return specindex < st->num_fsmportsspecs ? st->fsmportsspeclist[specindex].spec : NULL;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   650
	//TODO: expect quirky behaviour here. specindex is one var, but pointing into two speclists... need to resolve which
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   651
}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   652