2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2005-03-24 17:03:37 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2005-03-24 17:03:37 +00:00
|
|
|
|
|
|
|
#include "command.h"
|
2005-07-22 07:02:20 +00:00
|
|
|
#include "functions.h"
|
2005-03-24 17:03:37 +00:00
|
|
|
#include "gfx.h"
|
|
|
|
#include "map.h"
|
|
|
|
#include "order.h"
|
2006-03-01 08:56:38 +00:00
|
|
|
#include "rail_map.h"
|
2005-03-24 17:03:37 +00:00
|
|
|
#include "saveload.h"
|
|
|
|
#include "station.h"
|
|
|
|
#include "tile.h"
|
|
|
|
#include "town.h"
|
|
|
|
#include "waypoint.h"
|
2005-07-21 22:15:02 +00:00
|
|
|
#include "variables.h"
|
2005-03-24 17:03:37 +00:00
|
|
|
#include "table/strings.h"
|
2006-04-18 06:42:14 +00:00
|
|
|
#include "vehicle.h"
|
2006-05-27 16:12:16 +00:00
|
|
|
#include "yapf/yapf.h"
|
2005-03-24 17:03:37 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
/* Max waypoints: 64000 (8 * 8000) */
|
|
|
|
WAYPOINT_POOL_BLOCK_SIZE_BITS = 3, /* In bits, so (1 << 3) == 8 */
|
|
|
|
WAYPOINT_POOL_MAX_BLOCKS = 8000,
|
|
|
|
|
|
|
|
MAX_WAYPOINTS_PER_TOWN = 64,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called if a new block is added to the waypoint-pool
|
|
|
|
*/
|
|
|
|
static void WaypointPoolNewBlock(uint start_item)
|
|
|
|
{
|
|
|
|
Waypoint *wp;
|
|
|
|
|
2006-06-27 21:25:53 +00:00
|
|
|
FOR_ALL_WAYPOINTS_FROM(wp, start_item) wp->index = start_item++;
|
2005-03-24 17:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the town-pool */
|
2006-04-18 18:48:50 +00:00
|
|
|
MemoryPool _waypoint_pool = { "Waypoints", WAYPOINT_POOL_MAX_BLOCKS, WAYPOINT_POOL_BLOCK_SIZE_BITS, sizeof(Waypoint), &WaypointPoolNewBlock, NULL, 0, 0, NULL };
|
2005-03-24 17:03:37 +00:00
|
|
|
|
|
|
|
/* Create a new waypoint */
|
2005-12-14 06:20:23 +00:00
|
|
|
static Waypoint* AllocateWaypoint(void)
|
2005-03-24 17:03:37 +00:00
|
|
|
{
|
|
|
|
Waypoint *wp;
|
|
|
|
|
|
|
|
FOR_ALL_WAYPOINTS(wp) {
|
|
|
|
if (wp->xy == 0) {
|
|
|
|
uint index = wp->index;
|
|
|
|
|
2006-06-27 21:25:53 +00:00
|
|
|
memset(wp, 0, sizeof(*wp));
|
2005-03-24 17:03:37 +00:00
|
|
|
wp->index = index;
|
|
|
|
|
|
|
|
return wp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if we can add a block to the pool */
|
2006-06-27 21:25:53 +00:00
|
|
|
if (AddBlockToPool(&_waypoint_pool)) return AllocateWaypoint();
|
2005-03-24 17:03:37 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update the sign for the waypoint */
|
2006-01-05 12:40:50 +00:00
|
|
|
static void UpdateWaypointSign(Waypoint* wp)
|
2005-03-24 17:03:37 +00:00
|
|
|
{
|
2006-04-03 09:07:21 +00:00
|
|
|
Point pt = RemapCoords2(TileX(wp->xy) * TILE_SIZE, TileY(wp->xy) * TILE_SIZE);
|
2005-03-24 17:03:37 +00:00
|
|
|
SetDParam(0, wp->index);
|
|
|
|
UpdateViewportSignPos(&wp->sign, pt.x, pt.y - 0x20, STR_WAYPOINT_VIEWPORT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Redraw the sign of a waypoint */
|
2005-12-14 06:20:23 +00:00
|
|
|
static void RedrawWaypointSign(const Waypoint* wp)
|
2005-03-24 17:03:37 +00:00
|
|
|
{
|
|
|
|
MarkAllViewportsDirty(
|
|
|
|
wp->sign.left - 6,
|
|
|
|
wp->sign.top,
|
|
|
|
wp->sign.left + (wp->sign.width_1 << 2) + 12,
|
|
|
|
wp->sign.top + 48);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update all signs */
|
|
|
|
void UpdateAllWaypointSigns(void)
|
|
|
|
{
|
|
|
|
Waypoint *wp;
|
|
|
|
|
|
|
|
FOR_ALL_WAYPOINTS(wp) {
|
2006-06-27 21:25:53 +00:00
|
|
|
if (wp->xy != 0) UpdateWaypointSign(wp);
|
2005-03-24 17:03:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the default name for a waypoint */
|
2005-12-14 06:20:23 +00:00
|
|
|
static void MakeDefaultWaypointName(Waypoint* wp)
|
2005-03-24 17:03:37 +00:00
|
|
|
{
|
|
|
|
Waypoint *local_wp;
|
|
|
|
bool used_waypoint[MAX_WAYPOINTS_PER_TOWN];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
wp->town_index = ClosestTownFromTile(wp->xy, (uint)-1)->index;
|
|
|
|
|
|
|
|
memset(used_waypoint, 0, sizeof(used_waypoint));
|
|
|
|
|
|
|
|
/* Find an unused waypoint number belonging to this town */
|
|
|
|
FOR_ALL_WAYPOINTS(local_wp) {
|
2006-06-27 21:25:53 +00:00
|
|
|
if (wp == local_wp) continue;
|
2005-03-24 17:03:37 +00:00
|
|
|
|
|
|
|
if (local_wp->xy && local_wp->string == STR_NULL && local_wp->town_index == wp->town_index)
|
|
|
|
used_waypoint[local_wp->town_cn] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find an empty spot */
|
|
|
|
for (i = 0; used_waypoint[i] && i < MAX_WAYPOINTS_PER_TOWN; i++) {}
|
|
|
|
|
|
|
|
wp->string = STR_NULL;
|
|
|
|
wp->town_cn = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find a deleted waypoint close to a tile. */
|
2005-06-24 12:38:35 +00:00
|
|
|
static Waypoint *FindDeletedWaypointCloseTo(TileIndex tile)
|
2005-03-24 17:03:37 +00:00
|
|
|
{
|
|
|
|
Waypoint *wp, *best = NULL;
|
2006-06-27 21:25:53 +00:00
|
|
|
uint thres = 8;
|
2005-03-24 17:03:37 +00:00
|
|
|
|
|
|
|
FOR_ALL_WAYPOINTS(wp) {
|
2006-06-27 21:25:53 +00:00
|
|
|
if (wp->deleted && wp->xy != 0) {
|
|
|
|
uint cur_dist = DistanceManhattan(tile, wp->xy);
|
|
|
|
|
2005-03-24 17:03:37 +00:00
|
|
|
if (cur_dist < thres) {
|
|
|
|
thres = cur_dist;
|
|
|
|
best = wp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return best;
|
|
|
|
}
|
|
|
|
|
2005-11-16 22:20:15 +00:00
|
|
|
/**
|
|
|
|
* 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++) {
|
2006-04-27 18:28:56 +00:00
|
|
|
const StationSpec *statspec = GetCustomStationSpec(STAT_CLASS_WAYP, i);
|
|
|
|
if (statspec != NULL && statspec->grfid == wp->grfid && statspec->localidx == wp->localidx) {
|
2005-11-16 22:20:15 +00:00
|
|
|
wp->stat_id = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-09 16:37:40 +00:00
|
|
|
/** Convert existing rail to waypoint. Eg build a waypoint station over
|
|
|
|
* piece of rail
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile tile where waypoint will be built
|
2005-11-12 00:19:34 +00:00
|
|
|
* @param p1 graphics for waypoint type, 0 indicates standard graphics
|
2005-05-09 16:37:40 +00:00
|
|
|
* @param p2 unused
|
2005-07-16 23:47:37 +00:00
|
|
|
*
|
|
|
|
* @todo When checking for the tile slope,
|
|
|
|
* distingush between "Flat land required" and "land sloped in wrong direction"
|
2005-05-09 16:37:40 +00:00
|
|
|
*/
|
2006-04-10 07:15:58 +00:00
|
|
|
int32 CmdBuildTrainWaypoint(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2005-03-24 17:03:37 +00:00
|
|
|
{
|
|
|
|
Waypoint *wp;
|
2006-04-23 13:48:16 +00:00
|
|
|
Slope tileh;
|
2006-03-01 08:56:38 +00:00
|
|
|
Axis axis;
|
2005-03-24 17:03:37 +00:00
|
|
|
|
|
|
|
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
|
|
|
|
|
2005-05-09 16:37:40 +00:00
|
|
|
/* if custom gfx are used, make sure it is within bounds */
|
2005-11-12 00:19:34 +00:00
|
|
|
if (p1 >= GetNumCustomStations(STAT_CLASS_WAYP)) return CMD_ERROR;
|
2005-05-09 16:37:40 +00:00
|
|
|
|
2006-03-19 12:06:12 +00:00
|
|
|
if (!IsTileType(tile, MP_RAILWAY) ||
|
2006-05-09 08:17:33 +00:00
|
|
|
GetRailTileType(tile) != RAIL_TILE_NORMAL || (
|
2006-03-19 12:06:12 +00:00
|
|
|
(axis = AXIS_X, GetTrackBits(tile) != TRACK_BIT_X) &&
|
|
|
|
(axis = AXIS_Y, GetTrackBits(tile) != TRACK_BIT_Y)
|
2006-03-01 08:56:38 +00:00
|
|
|
)) {
|
2005-03-24 17:03:37 +00:00
|
|
|
return_cmd_error(STR_1005_NO_SUITABLE_RAILROAD_TRACK);
|
2006-03-01 08:56:38 +00:00
|
|
|
}
|
2005-03-24 17:03:37 +00:00
|
|
|
|
2006-06-27 21:25:53 +00:00
|
|
|
if (!CheckTileOwnership(tile)) return CMD_ERROR;
|
2005-03-24 17:03:37 +00:00
|
|
|
if (!EnsureNoVehicle(tile)) return CMD_ERROR;
|
|
|
|
|
|
|
|
tileh = GetTileSlope(tile, NULL);
|
2006-06-27 21:25:53 +00:00
|
|
|
if (tileh != SLOPE_FLAT &&
|
|
|
|
(!_patches.build_on_slopes || IsSteepSlope(tileh) || !(tileh & (0x3 << axis)) || !(tileh & ~(0x3 << axis)))) {
|
|
|
|
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
|
2005-03-24 17:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if there is an already existing, deleted, waypoint close to us that we can reuse. */
|
|
|
|
wp = FindDeletedWaypointCloseTo(tile);
|
|
|
|
if (wp == NULL) {
|
|
|
|
wp = AllocateWaypoint();
|
2005-05-09 16:37:40 +00:00
|
|
|
if (wp == NULL) return CMD_ERROR;
|
2005-03-24 17:03:37 +00:00
|
|
|
|
|
|
|
wp->town_index = 0;
|
|
|
|
wp->string = STR_NULL;
|
|
|
|
wp->town_cn = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
2006-06-21 11:13:02 +00:00
|
|
|
const StationSpec* statspec;
|
|
|
|
|
2006-03-17 10:10:31 +00:00
|
|
|
MakeRailWaypoint(tile, GetTileOwner(tile), axis, GetRailType(tile), wp->index);
|
2006-03-01 08:56:38 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
2005-11-16 22:20:15 +00:00
|
|
|
|
2006-06-21 11:13:02 +00:00
|
|
|
statspec = GetCustomStationSpec(STAT_CLASS_WAYP, p1);
|
2005-11-16 22:20:15 +00:00
|
|
|
|
2006-04-27 18:28:56 +00:00
|
|
|
if (statspec != NULL) {
|
2006-06-21 11:13:02 +00:00
|
|
|
wp->stat_id = p1;
|
2006-04-27 18:28:56 +00:00
|
|
|
wp->grfid = statspec->grfid;
|
|
|
|
wp->localidx = statspec->localidx;
|
2005-11-16 22:20:15 +00:00
|
|
|
} else {
|
|
|
|
// Specified custom graphics do not exist, so use default.
|
|
|
|
wp->stat_id = 0;
|
|
|
|
wp->grfid = 0;
|
|
|
|
wp->localidx = 0;
|
2005-03-24 17:03:37 +00:00
|
|
|
}
|
2005-11-16 22:20:15 +00:00
|
|
|
|
2005-03-24 17:03:37 +00:00
|
|
|
wp->deleted = 0;
|
|
|
|
wp->xy = tile;
|
|
|
|
wp->build_date = _date;
|
|
|
|
|
2006-06-10 08:37:41 +00:00
|
|
|
if (wp->town_index == 0) MakeDefaultWaypointName(wp);
|
2005-03-24 17:03:37 +00:00
|
|
|
|
|
|
|
UpdateWaypointSign(wp);
|
|
|
|
RedrawWaypointSign(wp);
|
|
|
|
}
|
|
|
|
|
|
|
|
return _price.build_train_depot;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Internal handler to delete a waypoint */
|
|
|
|
static void DoDeleteWaypoint(Waypoint *wp)
|
|
|
|
{
|
|
|
|
Order order;
|
|
|
|
|
|
|
|
wp->xy = 0;
|
|
|
|
|
|
|
|
order.type = OT_GOTO_WAYPOINT;
|
|
|
|
order.station = wp->index;
|
|
|
|
DeleteDestinationFromVehicleOrder(order);
|
|
|
|
|
2006-06-27 21:25:53 +00:00
|
|
|
if (wp->string != STR_NULL) DeleteName(wp->string);
|
2005-03-24 17:03:37 +00:00
|
|
|
|
|
|
|
RedrawWaypointSign(wp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Daily loop for waypoints */
|
|
|
|
void WaypointsDailyLoop(void)
|
|
|
|
{
|
|
|
|
Waypoint *wp;
|
|
|
|
|
|
|
|
/* Check if we need to delete a waypoint */
|
|
|
|
FOR_ALL_WAYPOINTS(wp) {
|
2006-06-27 21:25:53 +00:00
|
|
|
if (wp->deleted != 0 && --wp->deleted == 0) DoDeleteWaypoint(wp);
|
2005-03-24 17:03:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove a waypoint */
|
2005-06-24 12:38:35 +00:00
|
|
|
int32 RemoveTrainWaypoint(TileIndex tile, uint32 flags, bool justremove)
|
2005-03-24 17:03:37 +00:00
|
|
|
{
|
|
|
|
Waypoint *wp;
|
|
|
|
|
|
|
|
/* Make sure it's a waypoint */
|
2006-06-27 21:25:53 +00:00
|
|
|
if (!IsTileType(tile, MP_RAILWAY) ||
|
|
|
|
!IsRailWaypoint(tile) ||
|
|
|
|
(!CheckTileOwnership(tile) && _current_player != OWNER_WATER) ||
|
|
|
|
!EnsureNoVehicle(tile)) {
|
2005-03-24 17:03:37 +00:00
|
|
|
return CMD_ERROR;
|
2006-06-27 21:25:53 +00:00
|
|
|
}
|
2005-03-24 17:03:37 +00:00
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
wp = GetWaypointByTile(tile);
|
|
|
|
|
|
|
|
wp->deleted = 30; // let it live for this many days before we do the actual deletion.
|
|
|
|
RedrawWaypointSign(wp);
|
|
|
|
|
|
|
|
if (justremove) {
|
2006-03-17 10:10:31 +00:00
|
|
|
MakeRailNormal(tile, GetTileOwner(tile), GetRailWaypointBits(tile), GetRailType(tile));
|
2006-03-01 08:56:38 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
2005-03-24 17:03:37 +00:00
|
|
|
} else {
|
|
|
|
DoClearSquare(tile);
|
2006-04-05 05:22:42 +00:00
|
|
|
SetSignalsOnBothDir(tile, GetRailWaypointTrack(tile));
|
2006-05-27 16:12:16 +00:00
|
|
|
YapfNotifyTrackLayoutChange(tile, GetRailWaypointTrack(tile));
|
2005-03-24 17:03:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return _price.remove_train_depot;
|
|
|
|
}
|
|
|
|
|
2005-05-09 16:37:40 +00:00
|
|
|
/** Delete a waypoint
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile tile where waypoint is to be deleted
|
2005-05-09 16:37:40 +00:00
|
|
|
* @param p1 unused
|
|
|
|
* @param p2 unused
|
|
|
|
*/
|
2006-04-10 07:15:58 +00:00
|
|
|
int32 CmdRemoveTrainWaypoint(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2005-03-24 17:03:37 +00:00
|
|
|
{
|
|
|
|
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
|
|
|
|
return RemoveTrainWaypoint(tile, flags, true);
|
|
|
|
}
|
|
|
|
|
2005-05-09 16:37:40 +00:00
|
|
|
/** Rename a waypoint.
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile unused
|
2005-05-09 16:37:40 +00:00
|
|
|
* @param p1 id of waypoint
|
|
|
|
* @param p2 unused
|
|
|
|
*/
|
2006-04-10 07:15:58 +00:00
|
|
|
int32 CmdRenameWaypoint(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2005-03-24 17:03:37 +00:00
|
|
|
{
|
|
|
|
Waypoint *wp;
|
|
|
|
|
2005-05-09 16:37:40 +00:00
|
|
|
if (!IsWaypointIndex(p1)) return CMD_ERROR;
|
|
|
|
|
2005-05-15 18:50:55 +00:00
|
|
|
if (_cmd_text[0] != '\0') {
|
2006-06-27 21:25:53 +00:00
|
|
|
StringID str = AllocateNameUnique(_cmd_text, 0);
|
|
|
|
|
|
|
|
if (str == 0) return CMD_ERROR;
|
2005-03-24 17:03:37 +00:00
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
wp = GetWaypoint(p1);
|
2006-06-27 21:25:53 +00:00
|
|
|
if (wp->string != STR_NULL) DeleteName(wp->string);
|
2005-03-24 17:03:37 +00:00
|
|
|
|
|
|
|
wp->string = str;
|
|
|
|
wp->town_cn = 0;
|
|
|
|
|
|
|
|
UpdateWaypointSign(wp);
|
|
|
|
MarkWholeScreenDirty();
|
|
|
|
} else {
|
|
|
|
DeleteName(str);
|
|
|
|
}
|
2005-07-08 22:25:24 +00:00
|
|
|
} else {
|
2005-03-24 17:03:37 +00:00
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
wp = GetWaypoint(p1);
|
2006-06-27 21:25:53 +00:00
|
|
|
if (wp->string != STR_NULL) DeleteName(wp->string);
|
2005-03-24 17:03:37 +00:00
|
|
|
|
|
|
|
MakeDefaultWaypointName(wp);
|
|
|
|
UpdateWaypointSign(wp);
|
|
|
|
MarkWholeScreenDirty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This hacks together some dummy one-shot Station structure for a waypoint. */
|
2005-06-24 12:38:35 +00:00
|
|
|
Station *ComposeWaypointStation(TileIndex tile)
|
2005-03-24 17:03:37 +00:00
|
|
|
{
|
|
|
|
Waypoint *wp = GetWaypointByTile(tile);
|
|
|
|
static Station stat;
|
|
|
|
|
|
|
|
stat.train_tile = stat.xy = wp->xy;
|
|
|
|
stat.town = GetTown(wp->town_index);
|
|
|
|
stat.string_id = wp->string == STR_NULL ? /* FIXME? */ 0 : wp->string;
|
|
|
|
stat.build_date = wp->build_date;
|
|
|
|
|
|
|
|
return &stat;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw a waypoint */
|
2005-10-16 09:13:04 +00:00
|
|
|
void DrawWaypointSprite(int x, int y, int stat_id, RailType railtype)
|
2005-03-24 17:03:37 +00:00
|
|
|
{
|
|
|
|
x += 33;
|
|
|
|
y += 17;
|
|
|
|
|
2006-05-06 20:48:40 +00:00
|
|
|
if (!DrawStationTile(x, y, railtype, AXIS_X, STAT_CLASS_WAYP, stat_id)) {
|
2005-08-01 16:31:19 +00:00
|
|
|
DrawDefaultWaypointSprite(x, y, railtype);
|
2005-03-24 17:03:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fix savegames which stored waypoints in their old format */
|
|
|
|
void FixOldWaypoints(void)
|
|
|
|
{
|
|
|
|
Waypoint *wp;
|
|
|
|
|
|
|
|
/* Convert the old 'town_or_string', to 'string' / 'town' / 'town_cn' */
|
|
|
|
FOR_ALL_WAYPOINTS(wp) {
|
2006-06-27 21:25:53 +00:00
|
|
|
if (wp->xy == 0) continue;
|
2005-03-24 17:03:37 +00:00
|
|
|
|
|
|
|
wp->town_index = ClosestTownFromTile(wp->xy, (uint)-1)->index;
|
|
|
|
wp->town_cn = 0;
|
|
|
|
if (wp->string & 0xC000) {
|
|
|
|
wp->town_cn = wp->string & 0x3F;
|
|
|
|
wp->string = STR_NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InitializeWaypoints(void)
|
|
|
|
{
|
|
|
|
CleanPool(&_waypoint_pool);
|
|
|
|
AddBlockToPool(&_waypoint_pool);
|
|
|
|
}
|
|
|
|
|
2005-05-30 22:16:05 +00:00
|
|
|
static const SaveLoad _waypoint_desc[] = {
|
2005-03-24 17:03:37 +00:00
|
|
|
SLE_CONDVAR(Waypoint, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
|
2006-02-20 19:43:26 +00:00
|
|
|
SLE_CONDVAR(Waypoint, xy, SLE_UINT32, 6, SL_MAX_VERSION),
|
|
|
|
SLE_CONDVAR(Waypoint, town_index, SLE_UINT16, 12, SL_MAX_VERSION),
|
|
|
|
SLE_CONDVAR(Waypoint, town_cn, SLE_UINT8, 12, SL_MAX_VERSION),
|
2005-07-08 22:25:24 +00:00
|
|
|
SLE_VAR(Waypoint, string, SLE_UINT16),
|
|
|
|
SLE_VAR(Waypoint, deleted, SLE_UINT8),
|
2005-03-24 17:03:37 +00:00
|
|
|
|
2006-02-20 19:43:26 +00:00
|
|
|
SLE_CONDVAR(Waypoint, build_date, SLE_UINT16, 3, SL_MAX_VERSION),
|
|
|
|
SLE_CONDVAR(Waypoint, localidx, SLE_UINT8, 3, SL_MAX_VERSION),
|
|
|
|
SLE_CONDVAR(Waypoint, grfid, SLE_UINT32, 17, SL_MAX_VERSION),
|
2005-03-24 17:03:37 +00:00
|
|
|
|
|
|
|
SLE_END()
|
|
|
|
};
|
|
|
|
|
|
|
|
static void Save_WAYP(void)
|
|
|
|
{
|
|
|
|
Waypoint *wp;
|
|
|
|
|
|
|
|
FOR_ALL_WAYPOINTS(wp) {
|
|
|
|
if (wp->xy != 0) {
|
|
|
|
SlSetArrayIndex(wp->index);
|
|
|
|
SlObject(wp, _waypoint_desc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Load_WAYP(void)
|
|
|
|
{
|
|
|
|
int index;
|
|
|
|
|
|
|
|
while ((index = SlIterateArray()) != -1) {
|
|
|
|
Waypoint *wp;
|
|
|
|
|
|
|
|
if (!AddBlockIfNeeded(&_waypoint_pool, index))
|
|
|
|
error("Waypoints: failed loading savegame: too many waypoints");
|
|
|
|
|
|
|
|
wp = GetWaypoint(index);
|
|
|
|
SlObject(wp, _waypoint_desc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const ChunkHandler _waypoint_chunk_handlers[] = {
|
|
|
|
{ 'CHKP', Save_WAYP, Load_WAYP, CH_ARRAY | CH_LAST},
|
|
|
|
};
|