summaryrefslogtreecommitdiff
path: root/waypoint.c
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2005-11-16 22:20:15 +0000
committerpeter1138 <peter1138@openttd.org>2005-11-16 22:20:15 +0000
commit754d26407e8cda101f04c93a94c60bc0625f540c (patch)
tree981b72e2eee14dca280a68f1b688ab83202c9f73 /waypoint.c
parent5cb9de35d114cf1f7b92945924c9fc05fa117d47 (diff)
downloadopenttd-754d26407e8cda101f04c93a94c60bc0625f540c.tar.xz
(svn r3212) - Waypoints/Depots: Store waypoint index in m2 for waypoints. This moves the ground type bits from m2 to m4 for waypoints and depots (leaving room for depot index in m2 in future), and moves the custom graphics ID to the waypoint struct.
- Waypoints: Until now stat_id was saved but never assigned to. Instead we now save the GRFID/local index of the custom graphics so that GRF file changes can leave graphics intact.
Diffstat (limited to 'waypoint.c')
-rw-r--r--waypoint.c68
1 files changed, 46 insertions, 22 deletions
diff --git a/waypoint.c b/waypoint.c
index 60b6c8735..53844a609 100644
--- a/waypoint.c
+++ b/waypoint.c
@@ -63,19 +63,6 @@ Waypoint *AllocateWaypoint(void)
return NULL;
}
-/* Fetch a waypoint by tile */
-Waypoint *GetWaypointByTile(TileIndex tile)
-{
- Waypoint *wp;
-
- FOR_ALL_WAYPOINTS(wp) {
- if (wp->xy == tile)
- return wp;
- }
-
- return NULL;
-}
-
/* Update the sign for the waypoint */
void UpdateWaypointSign(Waypoint *wp)
{
@@ -151,6 +138,29 @@ static Waypoint *FindDeletedWaypointCloseTo(TileIndex tile)
return best;
}
+/**
+ * Update waypoint graphics id against saved GRFID/localidx.
+ * This is to ensure the chosen graphics are correct if GRF files are changed.
+ */
+void UpdateAllWaypointCustomGraphics(void)
+{
+ Waypoint *wp;
+
+ FOR_ALL_WAYPOINTS(wp) {
+ uint i;
+
+ if (wp->grfid == 0) continue;
+
+ for (i = 0; i < GetNumCustomStations(STAT_CLASS_WAYP); i++) {
+ const StationSpec *spec = GetCustomStation(STAT_CLASS_WAYP, i);
+ if (spec != NULL && spec->grfid == wp->grfid && spec->localidx == wp->localidx) {
+ wp->stat_id = i;
+ break;
+ }
+ }
+ }
+}
+
/** Convert existing rail to waypoint. Eg build a waypoint station over
* piece of rail
* @param x,y coordinates where waypoint will be built
@@ -198,13 +208,26 @@ int32 CmdBuildTrainWaypoint(int x, int y, uint32 flags, uint32 p1, uint32 p2)
}
if (flags & DC_EXEC) {
+ const StationSpec *spec = NULL;
bool reserved = PBSTileReserved(tile) != 0;
- ModifyTile(tile, MP_MAP5, RAIL_TYPE_WAYPOINT | dir);
- if (p1 > 0) { // waypoint type 0 uses default graphics
- // custom graphics
- _m[tile].m3 |= 16;
- _m[tile].m4 = (p1 - 1) & 0xff;
+ ModifyTile(tile, MP_MAP2 | MP_MAP5, wp->index, RAIL_TYPE_WAYPOINT | dir);
+
+ if (GB(p1, 0, 8) < GetNumCustomStations(STAT_CLASS_WAYP))
+ spec = GetCustomStation(STAT_CLASS_WAYP, GB(p1, 0, 8));
+
+ if (spec != NULL) {
+ SETBIT(_m[tile].m3, 4);
+ wp->stat_id = GB(p1, 0, 8);
+ wp->grfid = spec->grfid;
+ wp->localidx = spec->localidx;
+ } else {
+ // Specified custom graphics do not exist, so use default.
+ CLRBIT(_m[tile].m3, 4);
+ wp->stat_id = 0;
+ wp->grfid = 0;
+ wp->localidx = 0;
}
+
if (reserved) {
PBSReserveTrack(tile, dir);
} else {
@@ -280,8 +303,8 @@ int32 RemoveTrainWaypoint(TileIndex tile, uint32 flags, bool justremove)
if (justremove) {
bool reserved = PBSTileReserved(tile) != 0;
- ModifyTile(tile, MP_MAP5, 1<<direction);
- _m[tile].m3 &= ~16;
+ ModifyTile(tile, MP_MAP2_CLEAR | MP_MAP5, 1<<direction);
+ CLRBIT(_m[tile].m3, 4);
_m[tile].m4 = 0;
if (reserved) {
PBSReserveTrack(tile, direction);
@@ -446,8 +469,9 @@ static const SaveLoad _waypoint_desc[] = {
SLE_VAR(Waypoint, string, SLE_UINT16),
SLE_VAR(Waypoint, deleted, SLE_UINT8),
- SLE_CONDVAR(Waypoint, build_date, SLE_UINT16, 3, 255),
- SLE_CONDVAR(Waypoint, stat_id, SLE_UINT8, 3, 255),
+ SLE_CONDVAR(Waypoint, build_date, SLE_UINT16, 3, 255),
+ SLE_CONDVAR(Waypoint, localidx, SLE_UINT8, 3, 255),
+ SLE_CONDVAR(Waypoint, grfid, SLE_UINT32, 17, 255),
SLE_END()
};