# waypoint_sl.cpp

Go to the documentation of this file.

    00001 /* $Id: waypoint_sl.cpp 15903 2009-03-30 23:15:05Z rubidium $ */
    00002
    00005 #include "../stdafx.h"
    00006 #include "../waypoint.h"
    00007 #include "../newgrf_station.h"
    00008 #include "../town.h"
    00009
    00010 #include "table/strings.h"
    00011
    00012 #include "saveload.h"
    00013
    00018 void AfterLoadWaypoints()
    00019 {
    00020   Waypoint *wp;
    00021
    00022   FOR_ALL_WAYPOINTS(wp) {
    00023     uint i;
    00024
    00025     if (wp->grfid == 0) continue;
    00026
    00027     for (i = 0; i < GetNumCustomStations(STAT_CLASS_WAYP); i++) {
    00028       const StationSpec *statspec = GetCustomStationSpec(STAT_CLASS_WAYP, i);
    00029       if (statspec != NULL && statspec->grffile->grfid == wp->grfid && statspec->localidx == wp->localidx) {
    00030         wp->stat_id = i;
    00031         break;
    00032       }
    00033     }
    00034   }
    00035 }
    00036
    00040 void FixOldWaypoints()
    00041 {
    00042   Waypoint *wp;
    00043
    00044   /* Convert the old 'town_or_string', to 'string' / 'town' / 'town_cn' */
    00045   FOR_ALL_WAYPOINTS(wp) {
    00046     wp->town_index = ClosestTownFromTile(wp->xy, UINT_MAX)->index;
    00047     wp->town_cn = 0;
    00048     if (wp->string & 0xC000) {
    00049       wp->town_cn = wp->string & 0x3F;
    00050       wp->string = STR_NULL;
    00051     }
    00052   }
    00053 }
    00054
    00055 static const SaveLoad _waypoint_desc[] = {
    00056   SLE_CONDVAR(Waypoint, xy,         SLE_FILE_U16 | SLE_VAR_U32,  0, 5),
    00057   SLE_CONDVAR(Waypoint, xy,         SLE_UINT32,                  6, SL_MAX_VERSION),
    00058   SLE_CONDVAR(Waypoint, town_index, SLE_UINT16,                 12, SL_MAX_VERSION),
    00059   SLE_CONDVAR(Waypoint, town_cn,    SLE_FILE_U8 | SLE_VAR_U16,  12, 88),
    00060   SLE_CONDVAR(Waypoint, town_cn,    SLE_UINT16,                 89, SL_MAX_VERSION),
    00061   SLE_CONDVAR(Waypoint, string,     SLE_STRINGID,                0, 83),
    00062   SLE_CONDSTR(Waypoint, name,       SLE_STR, 0,                 84, SL_MAX_VERSION),
    00063       SLE_VAR(Waypoint, deleted,    SLE_UINT8),
    00064
    00065   SLE_CONDVAR(Waypoint, build_date, SLE_FILE_U16 | SLE_VAR_I32,  3, 30),
    00066   SLE_CONDVAR(Waypoint, build_date, SLE_INT32,                  31, SL_MAX_VERSION),
    00067   SLE_CONDVAR(Waypoint, localidx,   SLE_UINT8,                   3, SL_MAX_VERSION),
    00068   SLE_CONDVAR(Waypoint, grfid,      SLE_UINT32,                 17, SL_MAX_VERSION),
    00069   SLE_CONDVAR(Waypoint, owner,      SLE_UINT8,                 101, SL_MAX_VERSION),
    00070
    00071   SLE_END()
    00072 };
    00073
    00074 static void Save_WAYP()
    00075 {
    00076   Waypoint *wp;
    00077
    00078   FOR_ALL_WAYPOINTS(wp) {
    00079     SlSetArrayIndex(wp->index);
    00080     SlObject(wp, _waypoint_desc);
    00081   }
    00082 }
    00083
    00084 static void Load_WAYP()
    00085 {
    00086   int index;
    00087
    00088   while ((index = SlIterateArray()) != -1) {
    00089     Waypoint *wp = new (index) Waypoint();
    00090     SlObject(wp, _waypoint_desc);
    00091   }
    00092 }
    00093
    00094 extern const ChunkHandler _waypoint_chunk_handlers[] = {
    00095   { 'CHKP', Save_WAYP, Load_WAYP, CH_ARRAY | CH_LAST},
    00096 };