author | tron |
Tue, 15 Nov 2005 11:46:49 +0000 | |
changeset 2648 | 72973ab76048 |
parent 2625 | 66b3d632dcd2 |
permissions | -rw-r--r-- |
2625
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
1 |
/* $Id$ */ |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
2 |
|
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
3 |
/** @file station_newgrf.c Functions for dealing with station classes and custom stations. */ |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
4 |
|
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
5 |
#include "stdafx.h" |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
6 |
#include "openttd.h" |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
7 |
#include "debug.h" |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
8 |
#include "sprite.h" |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
9 |
#include "station_newgrf.h" |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
10 |
|
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
11 |
static StationClass station_classes[STAT_CLASS_MAX]; |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
12 |
|
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
13 |
/** |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
14 |
* Reset station classes to their default state. |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
15 |
* This includes initialising the Default and Waypoint classes with an empty |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
16 |
* entry, for standard stations and waypoints. |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
17 |
*/ |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
18 |
void ResetStationClasses(void) |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
19 |
{ |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
20 |
StationClassID i; |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
21 |
for (i = 0; i < STAT_CLASS_MAX; i++) { |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
22 |
station_classes[i].id = 0; |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
23 |
|
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
24 |
free(station_classes[i].name); |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
25 |
station_classes[i].name = NULL; |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
26 |
|
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
27 |
station_classes[i].stations = 0; |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
28 |
|
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
29 |
free(station_classes[i].spec); |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
30 |
station_classes[i].spec = NULL; |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
31 |
} |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
32 |
|
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
33 |
// Set up initial data |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
34 |
station_classes[0].id = 'DFLT'; |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
35 |
station_classes[0].name = strdup("Default"); |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
36 |
station_classes[0].stations = 1; |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
37 |
station_classes[0].spec = malloc(sizeof(*station_classes[0].spec)); |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
38 |
station_classes[0].spec[0] = NULL; |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
39 |
|
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
40 |
station_classes[1].id = 'WAYP'; |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
41 |
station_classes[1].name = strdup("Waypoints"); |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
42 |
station_classes[1].stations = 1; |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
43 |
station_classes[1].spec = malloc(sizeof(*station_classes[1].spec)); |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
44 |
station_classes[1].spec[0] = NULL; |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
45 |
} |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
46 |
|
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
47 |
/** |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
48 |
* Allocate a station class for the given class id. |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
49 |
* @param classid A 32 bit value identifying the class. |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
50 |
* @return Index into station_classes of allocated class. |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
51 |
*/ |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
52 |
StationClassID AllocateStationClass(uint32 class) |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
53 |
{ |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
54 |
StationClassID i; |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
55 |
|
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
56 |
for (i = 0; i < STAT_CLASS_MAX; i++) { |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
57 |
if (station_classes[i].id == class) { |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
58 |
// ClassID is already allocated, so reuse it. |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
59 |
return i; |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
60 |
} else if (station_classes[i].id == 0) { |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
61 |
// This class is empty, so allocate it to the ClassID. |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
62 |
station_classes[i].id = class; |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
63 |
return i; |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
64 |
} |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
65 |
} |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
66 |
|
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
67 |
DEBUG(grf, 2)("StationClassAllocate: Already allocated %d classes, using default.", STAT_CLASS_MAX); |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
68 |
return STAT_CLASS_DFLT; |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
69 |
} |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
70 |
|
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
71 |
/** |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
72 |
* Return the number of stations for the given station class. |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
73 |
* @param sclass Index of the station class. |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
74 |
* @return Number of stations in the class. |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
75 |
*/ |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
76 |
uint GetNumCustomStations(StationClassID sclass) |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
77 |
{ |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
78 |
assert(sclass < STAT_CLASS_MAX); |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
79 |
return station_classes[sclass].stations; |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
80 |
} |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
81 |
|
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
82 |
/** |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
83 |
* Tie a station spec to its station class. |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
84 |
* @param spec The station spec. |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
85 |
*/ |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
86 |
void SetCustomStation(StationSpec *spec) |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
87 |
{ |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
88 |
StationClass *station_class; |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
89 |
int i; |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
90 |
|
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
91 |
assert(spec->sclass < STAT_CLASS_MAX); |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
92 |
station_class = &station_classes[spec->sclass]; |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
93 |
|
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
94 |
i = station_class->stations++; |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
95 |
station_class->spec = realloc(station_class->spec, station_class->stations * sizeof(*station_class->spec)); |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
96 |
|
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
97 |
station_class->spec[i] = spec; |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
98 |
} |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
99 |
|
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
100 |
/** |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
101 |
* Retrieve a station spec from a class. |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
102 |
* @param sclass Index of the station class. |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
103 |
* @param station The station index with the class. |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
104 |
* @return The station spec. |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
105 |
*/ |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
106 |
const StationSpec *GetCustomStation(StationClassID sclass, uint station) |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
107 |
{ |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
108 |
assert(sclass < STAT_CLASS_MAX); |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
109 |
if (station < station_classes[sclass].stations) |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
110 |
return station_classes[sclass].spec[station]; |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
111 |
|
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
112 |
// If the custom station isn't defined any more, then the GRF file |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
113 |
// probably was not loaded. |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
114 |
return NULL; |
66b3d632dcd2
(svn r3167) - NewGRF: Start moving custom station code to separate files.
peter1138
parents:
diff
changeset
|
115 |
} |