src/newgrf_fsmports.cpp
author richk
Sat, 02 Feb 2008 02:05:14 +0000
branchNewGRF_ports
changeset 6874 5d69ad7a3c98
parent 6872 1c4a4a609f85
child 6878 7d1ff2f621c7
permissions -rw-r--r--
(svn r12039) [NewGRF_ports] -Fix: Corrected GUI to revised format.
Added enums for widgets.
Now use ShowDropDownList and corrected BuildFSMportsClassDropdown to return a DropDownList rather than String*.
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 "cargotype.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 "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
    23
#include "newgrf_town.h"
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    24
#include "player_func.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    25
#include "gfx_func.h"
6874
5d69ad7a3c98 (svn r12039) [NewGRF_ports] -Fix: Corrected GUI to revised format.
richk
parents: 6872
diff changeset
    26
#include "widgets/dropdown_type.h"
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    27
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    28
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
    29
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    30
enum {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    31
	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
    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
/**
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    35
 * 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
    36
 * 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
    37
 * 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
    38
 */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    39
void ResetFSMportsClasses()
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    40
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    41
	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
    42
		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
    43
		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
    44
		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
    45
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    46
		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
    47
		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
    48
	}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    49
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    50
	/* 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
    51
	//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
    52
	//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
    53
	//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
    54
	//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
    55
	//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
    56
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].id = '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].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
    59
	//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
    60
	//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
    61
	//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
    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
/**
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    65
 * 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
    66
 * @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
    67
 * @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
    68
 */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    69
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
    70
{
6795
8a27be8048e3 (svn r10867) [NewGRF_ports] -Fix: SYST class needed to be loaded to the specific class 31 to avoid disturbing list sequences.
richk
parents: 6793
diff changeset
    71
	if (cls == SYSTEM_HIDDEN_CLASS) {
8a27be8048e3 (svn r10867) [NewGRF_ports] -Fix: SYST class needed to be loaded to the specific class 31 to avoid disturbing list sequences.
richk
parents: 6793
diff changeset
    72
		fsmports_classes[31].id = cls;
8a27be8048e3 (svn r10867) [NewGRF_ports] -Fix: SYST class needed to be loaded to the specific class 31 to avoid disturbing list sequences.
richk
parents: 6793
diff changeset
    73
		return FSMPORTS_CLASS_SYST;
8a27be8048e3 (svn r10867) [NewGRF_ports] -Fix: SYST class needed to be loaded to the specific class 31 to avoid disturbing list sequences.
richk
parents: 6793
diff changeset
    74
	}
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    75
	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
    76
		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
    77
			/* 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
    78
			return i;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    79
		} 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
    80
			/* 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
    81
			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
    82
			return i;
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
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    86
	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
    87
	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
    88
}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    89
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    90
/** 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
    91
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
    92
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    93
	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
    94
	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
    95
}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    96
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
    97
/** 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
    98
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
    99
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   100
	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
   101
	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
   102
}
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
/** 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
   105
 * @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
   106
 */
6874
5d69ad7a3c98 (svn r12039) [NewGRF_ports] -Fix: Corrected GUI to revised format.
richk
parents: 6872
diff changeset
   107
DropDownList *BuildFSMportsClassDropdown()
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   108
{
6874
5d69ad7a3c98 (svn r12039) [NewGRF_ports] -Fix: Corrected GUI to revised format.
richk
parents: 6872
diff changeset
   109
	DropDownList *list = new DropDownList();
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   110
6874
5d69ad7a3c98 (svn r12039) [NewGRF_ports] -Fix: Corrected GUI to revised format.
richk
parents: 6872
diff changeset
   111
	for (uint i = 0; i < GetNumFSMportsClasses() && fsmports_classes[i].id != 0; i++) {
5d69ad7a3c98 (svn r12039) [NewGRF_ports] -Fix: Corrected GUI to revised format.
richk
parents: 6872
diff changeset
   112
		if (fsmports_classes[i].id == SYSTEM_HIDDEN_CLASS) continue;
5d69ad7a3c98 (svn r12039) [NewGRF_ports] -Fix: Corrected GUI to revised format.
richk
parents: 6872
diff changeset
   113
		list->push_back(new DropDownListStringItem(GetFSMportsClassName((FSMportsClassID)i), i, false));
6722
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
6874
5d69ad7a3c98 (svn r12039) [NewGRF_ports] -Fix: Corrected GUI to revised format.
richk
parents: 6872
diff changeset
   116
	return list;
6722
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
/**
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   120
 * 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
   121
 * @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
   122
 */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   123
uint GetNumFSMportsClasses()
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   124
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   125
	uint i;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   126
	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
   127
	return i;
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
/**
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   131
 * 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
   132
 * @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
   133
 * @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
   134
 */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   135
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
   136
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   137
	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
   138
	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
   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
/**
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   142
 * 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
   143
 * @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
   144
 */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   145
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
   146
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   147
	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
   148
	int i;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   149
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   150
	/* 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
   151
	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
   152
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   153
	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
   154
	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
   155
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   156
	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
   157
	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
   158
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   159
	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
   160
	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
   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
/**
6734
6e4db2fda167 (svn r10666) [NewGRF_ports] -Change: portFSM added to FSMportsSpec.
richk
parents: 6730
diff changeset
   164
 * Retrieve a fsmspec from a class.
6e4db2fda167 (svn r10666) [NewGRF_ports] -Change: portFSM added to FSMportsSpec.
richk
parents: 6730
diff changeset
   165
 * @param sclass Index of the fsm class.
6e4db2fda167 (svn r10666) [NewGRF_ports] -Change: portFSM added to FSMportsSpec.
richk
parents: 6730
diff changeset
   166
 * @param fsport The index with the class.
6e4db2fda167 (svn r10666) [NewGRF_ports] -Change: portFSM added to FSMportsSpec.
richk
parents: 6730
diff changeset
   167
 * @return The fsmspec.
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   168
 */
6760
d7a806a9aa44 (svn r10802) [NewGRF_ports] -Feature: Added availability dates for airports, using callbacks. Gui modified to disable unavailable airports. If no airports available at all, airport placement disabled.
richk
parents: 6746
diff changeset
   169
FSMportsSpec *GetCustomFSMportsSpec(FSMportsClassID sclass, uint fsmport)
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   170
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   171
	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
   172
	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
   173
		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
   174
6734
6e4db2fda167 (svn r10666) [NewGRF_ports] -Change: portFSM added to FSMportsSpec.
richk
parents: 6730
diff changeset
   175
	/* If the custom fsmport isn't defined any more, then the GRF file
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   176
	 * 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
   177
	return NULL;
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
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   181
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
   182
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   183
	uint j;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   184
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   185
	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
   186
		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
   187
			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
   188
			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
   189
			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
   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
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   193
	return NULL;
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
6746
837a9ca5a2f0 (svn r10784) [NewGRF_ports] -Feature: Added rotation of FSMport movement.
richk
parents: 6745
diff changeset
   196
TileIndexDiffC RotateFSMPosition(TileIndexDiffC position, byte size_x, byte size_y, byte FSM_orientation)
837a9ca5a2f0 (svn r10784) [NewGRF_ports] -Feature: Added rotation of FSMport movement.
richk
parents: 6745
diff changeset
   197
{
837a9ca5a2f0 (svn r10784) [NewGRF_ports] -Feature: Added rotation of FSMport movement.
richk
parents: 6745
diff changeset
   198
	TileIndexDiffC new_position;
837a9ca5a2f0 (svn r10784) [NewGRF_ports] -Feature: Added rotation of FSMport movement.
richk
parents: 6745
diff changeset
   199
837a9ca5a2f0 (svn r10784) [NewGRF_ports] -Feature: Added rotation of FSMport movement.
richk
parents: 6745
diff changeset
   200
	switch (FSM_orientation) {
837a9ca5a2f0 (svn r10784) [NewGRF_ports] -Feature: Added rotation of FSMport movement.
richk
parents: 6745
diff changeset
   201
		case DIR_NE:
837a9ca5a2f0 (svn r10784) [NewGRF_ports] -Feature: Added rotation of FSMport movement.
richk
parents: 6745
diff changeset
   202
			new_position = position;
837a9ca5a2f0 (svn r10784) [NewGRF_ports] -Feature: Added rotation of FSMport movement.
richk
parents: 6745
diff changeset
   203
			break;
837a9ca5a2f0 (svn r10784) [NewGRF_ports] -Feature: Added rotation of FSMport movement.
richk
parents: 6745
diff changeset
   204
		case DIR_SE:
837a9ca5a2f0 (svn r10784) [NewGRF_ports] -Feature: Added rotation of FSMport movement.
richk
parents: 6745
diff changeset
   205
			new_position.x = position.y;
837a9ca5a2f0 (svn r10784) [NewGRF_ports] -Feature: Added rotation of FSMport movement.
richk
parents: 6745
diff changeset
   206
			new_position.y = size_y - (position.x + 1);
837a9ca5a2f0 (svn r10784) [NewGRF_ports] -Feature: Added rotation of FSMport movement.
richk
parents: 6745
diff changeset
   207
			/*note that size_y is used here, because the size_x is the size_x of the set, which is size_y in the 01 orientation */
837a9ca5a2f0 (svn r10784) [NewGRF_ports] -Feature: Added rotation of FSMport movement.
richk
parents: 6745
diff changeset
   208
			break;
837a9ca5a2f0 (svn r10784) [NewGRF_ports] -Feature: Added rotation of FSMport movement.
richk
parents: 6745
diff changeset
   209
		case DIR_SW:
837a9ca5a2f0 (svn r10784) [NewGRF_ports] -Feature: Added rotation of FSMport movement.
richk
parents: 6745
diff changeset
   210
			new_position.x = size_x - (position.x + 1);
837a9ca5a2f0 (svn r10784) [NewGRF_ports] -Feature: Added rotation of FSMport movement.
richk
parents: 6745
diff changeset
   211
			new_position.y = size_y - (position.y + 1);
837a9ca5a2f0 (svn r10784) [NewGRF_ports] -Feature: Added rotation of FSMport movement.
richk
parents: 6745
diff changeset
   212
			break;
837a9ca5a2f0 (svn r10784) [NewGRF_ports] -Feature: Added rotation of FSMport movement.
richk
parents: 6745
diff changeset
   213
		case DIR_NW:
837a9ca5a2f0 (svn r10784) [NewGRF_ports] -Feature: Added rotation of FSMport movement.
richk
parents: 6745
diff changeset
   214
			new_position.x = size_x - (position.y + 1);
837a9ca5a2f0 (svn r10784) [NewGRF_ports] -Feature: Added rotation of FSMport movement.
richk
parents: 6745
diff changeset
   215
			/*note that size_x is used here, because the size_y is the size_y of the set, which is size_x in the 01 orientation */
837a9ca5a2f0 (svn r10784) [NewGRF_ports] -Feature: Added rotation of FSMport movement.
richk
parents: 6745
diff changeset
   216
			new_position.y = position.x;
837a9ca5a2f0 (svn r10784) [NewGRF_ports] -Feature: Added rotation of FSMport movement.
richk
parents: 6745
diff changeset
   217
			break;
837a9ca5a2f0 (svn r10784) [NewGRF_ports] -Feature: Added rotation of FSMport movement.
richk
parents: 6745
diff changeset
   218
		default:
837a9ca5a2f0 (svn r10784) [NewGRF_ports] -Feature: Added rotation of FSMport movement.
richk
parents: 6745
diff changeset
   219
			new_position = position;
837a9ca5a2f0 (svn r10784) [NewGRF_ports] -Feature: Added rotation of FSMport movement.
richk
parents: 6745
diff changeset
   220
			break;
837a9ca5a2f0 (svn r10784) [NewGRF_ports] -Feature: Added rotation of FSMport movement.
richk
parents: 6745
diff changeset
   221
	}
837a9ca5a2f0 (svn r10784) [NewGRF_ports] -Feature: Added rotation of FSMport movement.
richk
parents: 6745
diff changeset
   222
837a9ca5a2f0 (svn r10784) [NewGRF_ports] -Feature: Added rotation of FSMport movement.
richk
parents: 6745
diff changeset
   223
	return new_position;
837a9ca5a2f0 (svn r10784) [NewGRF_ports] -Feature: Added rotation of FSMport movement.
richk
parents: 6745
diff changeset
   224
}
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   225
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   226
/* 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
   227
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
   228
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   229
	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
   230
	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
   231
	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
   232
}
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
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   235
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
   236
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   237
	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
   238
	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
   239
}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   240
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   241
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   242
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
   243
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   244
	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
   245
	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
   246
	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
   247
}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   248
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   249
/**
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   250
 * 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
   251
 * 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
   252
 * 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
   253
 */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   254
static struct {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   255
	uint32 v40;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   256
	uint32 v41;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   257
	uint32 v45;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   258
	uint32 v46;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   259
	uint32 v47;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   260
	uint32 v49;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   261
	uint8 valid;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   262
} _svc;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   263
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   264
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
   265
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   266
	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
   267
	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
   268
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   269
	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
   270
		/* 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
   271
		Town *t;
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
		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
   274
			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
   275
		} 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
   276
			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
   277
		} else {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   278
			*available = false;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   279
			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
   280
		}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   281
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   282
		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
   283
	}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   284
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   285
	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
   286
		/* 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
   287
		switch (variable) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   288
			case 0x40:
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   289
			case 0x41:
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   290
			case 0x46:
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   291
			case 0x47:
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   292
			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
   293
			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
   294
			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
   295
			case 0x44: return 2;               // PBS status
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
   296
			case 0xFA: return Clamp(_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535); // Build date, Clamped to a 16 bit value
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   297
		}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   298
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   299
		*available = false;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   300
		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
   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
	switch (variable) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   304
		/* 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
   305
		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
   306
		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
   307
		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
   308
			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
   309
			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
   310
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   311
			for (cargo_type = 0; cargo_type < NUM_CARGO; cargo_type++) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
   312
				if (HasBit(st->goods[cargo_type].acceptance_pickup, GoodsEntry::ACCEPTANCE)) SetBit(value, cargo_type);
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   313
			}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   314
			return value;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   315
		}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   316
		/* 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
   317
		/* 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
   318
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   319
		/* 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
   320
		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
   321
		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
   322
		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
   323
		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
   324
		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
   325
		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
   326
		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
   327
		case 0xF3: return st->bus_stops->status;
6739
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents: 6734
diff changeset
   328
		//TODO: need to decide how/what to return
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents: 6734
diff changeset
   329
		//case 0xF6: return st->airport_flags;
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents: 6734
diff changeset
   330
		//case 0xF7: return GB(st->airport_flags, 8, 8);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
   331
		case 0xFA: return Clamp(st->build_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535);
6722
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
	/* 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
   335
	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
   336
		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
   337
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   338
		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
   339
		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
   340
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   341
		switch (variable) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   342
			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
   343
			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
   344
			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
   345
			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
   346
			case 0x64: return ge->last_speed | (ge->last_age << 8);
6868
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6795
diff changeset
   347
			case 0x65: return GB(ge->acceptance_pickup, GoodsEntry::ACCEPTANCE, 1) << 3;
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   348
		}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   349
	}
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
	/* 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
   352
	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
   353
		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
   354
		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
   355
			case 0: return g->cargo.Count();
6868
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6795
diff changeset
   356
			case 1: return GB(min(g->cargo.Count(), 4095), 0, 4) | (GB(g->acceptance_pickup, GoodsEntry::ACCEPTANCE, 1) << 7);
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   357
			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
   358
			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
   359
			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
   360
			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
   361
			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
   362
			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
   363
		}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   364
	}
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
	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
   367
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   368
	*available = false;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   369
	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
   370
}
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
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
   374
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   375
	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
   376
	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
   377
	uint set;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   378
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   379
	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
   380
	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
   381
6795
8a27be8048e3 (svn r10867) [NewGRF_ports] -Fix: SYST class needed to be loaded to the specific class 31 to avoid disturbing list sequences.
richk
parents: 6793
diff changeset
   382
	if (st == NULL || fsmportspec->sclass == FSMPORTS_CLASS_SYST) {
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   383
		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
   384
	}
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
	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
   387
		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
   388
		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
   389
		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
   390
			cargo = 0;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   391
			break;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   392
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   393
		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
   394
			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
   395
				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
   396
			}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   397
			break;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   398
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   399
		default:
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   400
			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
   401
			break;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   402
	}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   403
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
   404
	if (HasBit(fsmportspec->flags, 1)) cargo /= (st->trainst_w + st->trainst_h);
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   405
	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
   406
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   407
	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
   408
		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
   409
			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
   410
			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
   411
		}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   412
	} else {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   413
		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
   414
			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
   415
			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
   416
		}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   417
	}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   418
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   419
	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
   420
}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   421
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   422
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   423
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
   424
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   425
	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
   426
	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
   427
	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
   428
	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
   429
	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
   430
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   431
	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
   432
	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
   433
	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
   434
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   435
	res->callback        = CBID_NO_CALLBACK;
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   436
	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
   437
	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
   438
	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
   439
	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
   440
	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
   441
}
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
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
   444
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   445
	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
   446
	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
   447
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   448
	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
   449
		/* 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
   450
		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
   451
	} else {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   452
		/* 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
   453
		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
   454
			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
   455
			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
   456
					!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
   457
				ctype = cargo;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   458
				break;
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
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   463
	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
   464
	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
   465
		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
   466
		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
   467
	}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   468
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   469
	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
   470
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   471
	/* 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
   472
	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
   473
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   474
	/* 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
   475
	_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
   476
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   477
	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
   478
}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   479
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   480
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
   481
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   482
	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
   483
	ResolverObject object;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   484
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   485
	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
   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_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
   489
	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
   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
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
   494
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   495
	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
   496
	ResolverObject object;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   497
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   498
	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
   499
	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
   500
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   501
	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
   502
	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
   503
	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
   504
}
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
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   507
uint16 GetFSMportsCallback(CallbackID callback, uint32 param1, uint32 param2, const FSMportsSpec *fsmportspec, const Station *st, TileIndex tile)
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   508
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   509
	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
   510
	ResolverObject object;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   511
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   512
	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
   513
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   514
	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
   515
	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
   516
	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
   517
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   518
	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
   519
	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
   520
	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
   521
}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   522
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   523
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   524
/**
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   525
 * 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
   526
 * @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
   527
 * @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
   528
 * @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
   529
 * @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
   530
 */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   531
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
   532
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   533
	uint i;
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
	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
   536
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   537
	/* 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
   538
	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
   539
		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
   540
	}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   541
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   542
	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
   543
		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
   544
	}
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
	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
   547
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   548
	if (exec) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   549
		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
   550
			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
   551
			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
   552
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   553
			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
   554
				/* Initial allocation */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   555
				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
   556
				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
   557
				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
   558
			}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   559
		}
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
		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
   562
		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
   563
		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
   564
	}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   565
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   566
	return i;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   567
}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   568
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   569
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   570
/** 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
   571
 * @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
   572
 * @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
   573
 * @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
   574
 */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   575
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
   576
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   577
	/* 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
   578
	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
   579
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   580
	/* 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
   581
	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
   582
		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
   583
			return;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   584
		}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   585
	} 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
   586
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   587
	/* 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
   588
	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
   589
	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
   590
	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
   591
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   592
	/* 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
   593
	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
   594
		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
   595
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   596
		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
   597
			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
   598
		} else {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   599
			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
   600
			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
   601
			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
   602
		}
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
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   606
/** 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
   607
 * @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
   608
 * @param y Position y of image.
6745
f45a41940079 (svn r10783) [NewGRF_ports] -Feature: Added placing FSMport in any of up to 4 different orientations. GUI now has a preview image for each orientation - not interactive, just a screenshot stored.
richk
parents: 6743
diff changeset
   609
 * @param tile tile ID from action 1 set
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   610
 * @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
   611
 * @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
   612
 * @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
   613
 */
6745
f45a41940079 (svn r10783) [NewGRF_ports] -Feature: Added placing FSMport in any of up to 4 different orientations. GUI now has a preview image for each orientation - not interactive, just a screenshot stored.
richk
parents: 6743
diff changeset
   614
bool DrawFSMportsTile(int x, int y, byte tile, FSMportsClassID sclass, uint FSMports)
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   615
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   616
	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
   617
	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
   618
	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
   619
	SpriteID relocation;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   620
	SpriteID image;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   621
	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
   622
6745
f45a41940079 (svn r10783) [NewGRF_ports] -Feature: Added placing FSMport in any of up to 4 different orientations. GUI now has a preview image for each orientation - not interactive, just a screenshot stored.
richk
parents: 6743
diff changeset
   623
	fsmportsspec = GetCustomFSMportsSpec(sclass, FSMports);
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   624
	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
   625
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   626
	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
   627
6745
f45a41940079 (svn r10783) [NewGRF_ports] -Feature: Added placing FSMport in any of up to 4 different orientations. GUI now has a preview image for each orientation - not interactive, just a screenshot stored.
richk
parents: 6743
diff changeset
   628
	assert(fsmportsspec->renderdata != NULL);
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   629
6745
f45a41940079 (svn r10783) [NewGRF_ports] -Feature: Added placing FSMport in any of up to 4 different orientations. GUI now has a preview image for each orientation - not interactive, just a screenshot stored.
richk
parents: 6743
diff changeset
   630
	sprites = &fsmportsspec->renderdata[tile];
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   631
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   632
	image = sprites->ground_sprite;
6745
f45a41940079 (svn r10783) [NewGRF_ports] -Feature: Added placing FSMport in any of up to 4 different orientations. GUI now has a preview image for each orientation - not interactive, just a screenshot stored.
richk
parents: 6743
diff changeset
   633
	image += relocation;
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   634
	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
   635
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   636
	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
   637
		Point pt;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   638
		image = seq->image;
6745
f45a41940079 (svn r10783) [NewGRF_ports] -Feature: Added placing FSMport in any of up to 4 different orientations. GUI now has a preview image for each orientation - not interactive, just a screenshot stored.
richk
parents: 6743
diff changeset
   639
		image += relocation;
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   640
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   641
		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
   642
			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
   643
			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
   644
		}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   645
	}
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
	return true;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   648
}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   649
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   650
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   651
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
   652
{
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   653
	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
   654
	uint specindex;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   655
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   656
	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
   657
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   658
	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
   659
	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
   660
	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
   661
}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents:
diff changeset
   662