Update to 1.10.0-beta1

This commit is contained in:
dP
2019-10-31 22:24:28 +03:00
parent b84a475e14
commit 599ccf0c2b
1470 changed files with 354219 additions and 16795 deletions

View File

@@ -20,6 +20,7 @@
#include "pathfinder/yapf/yapf_cache.h"
#include "strings_func.h"
#include "viewport_func.h"
#include "viewport_kdtree.h"
#include "window_func.h"
#include "date_func.h"
#include "vehicle_func.h"
@@ -46,6 +47,21 @@ void Waypoint::UpdateVirtCoord()
InvalidateWindowData(WC_WAYPOINT_VIEW, this->index);
}
/**
* Move the waypoint main coordinate somewhere else.
* @param new_xy new tile location of the sign
*/
void Waypoint::MoveSign(TileIndex new_xy)
{
if (this->xy == new_xy) return;
_viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeWaypoint(this->index));
this->BaseStation::MoveSign(new_xy);
_viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeWaypoint(this->index));
}
/**
* Find a deleted waypoint close to a tile.
* @param tile to search from
@@ -55,7 +71,7 @@ void Waypoint::UpdateVirtCoord()
*/
static Waypoint *FindDeletedWaypointCloseTo(TileIndex tile, StringID str, CompanyID cid)
{
Waypoint *wp, *best = NULL;
Waypoint *wp, *best = nullptr;
uint thres = 8;
FOR_ALL_WAYPOINTS(wp) {
@@ -107,7 +123,7 @@ static CommandCost IsValidTileForWaypoint(TileIndex tile, Axis axis, StationID *
/* if waypoint is set, then we have special handling to allow building on top of already existing waypoints.
* so waypoint points to INVALID_STATION if we can build on any waypoint.
* Or it points to a waypoint if we're only allowed to build on exactly that waypoint. */
if (waypoint != NULL && IsTileType(tile, MP_STATION)) {
if (waypoint != nullptr && IsTileType(tile, MP_STATION)) {
if (!IsRailWaypoint(tile)) {
return ClearTile_Station(tile, DC_AUTO); // get error message
} else {
@@ -198,16 +214,16 @@ CommandCost CmdBuildRailWaypoint(TileIndex start_tile, DoCommandFlag flags, uint
if (ret.Failed()) return ret;
}
Waypoint *wp = NULL;
TileArea new_location(TileArea(start_tile, width, height));
Waypoint *wp = nullptr;
TileArea new_location(start_tile, width, height);
CommandCost ret = FindJoiningWaypoint(est, station_to_join, adjacent, new_location, &wp);
if (ret.Failed()) return ret;
/* Check if there is an already existing, deleted, waypoint close to us that we can reuse. */
TileIndex center_tile = start_tile + (count / 2) * offset;
if (wp == NULL && reuse) wp = FindDeletedWaypointCloseTo(center_tile, STR_SV_STNAME_WAYPOINT, _current_company);
if (wp == nullptr && reuse) wp = FindDeletedWaypointCloseTo(center_tile, STR_SV_STNAME_WAYPOINT, _current_company);
if (wp != NULL) {
if (wp != nullptr) {
/* Reuse an existing waypoint. */
if (wp->owner != _current_company) return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_WAYPOINT);
@@ -225,11 +241,15 @@ CommandCost CmdBuildRailWaypoint(TileIndex start_tile, DoCommandFlag flags, uint
}
if (flags & DC_EXEC) {
if (wp == NULL) {
bool need_sign_update = false;
if (wp == nullptr) {
wp = new Waypoint(start_tile);
need_sign_update = true;
} else if (!wp->IsInUse()) {
/* Move existing (recently deleted) waypoint to the new location */
_viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeWaypoint(wp->index));
wp->xy = start_tile;
need_sign_update = true;
}
wp->owner = GetTileOwner(start_tile);
@@ -241,13 +261,14 @@ CommandCost CmdBuildRailWaypoint(TileIndex start_tile, DoCommandFlag flags, uint
wp->string_id = STR_SV_STNAME_WAYPOINT;
wp->train_station = new_location;
if (wp->town == NULL) MakeDefaultName(wp);
if (wp->town == nullptr) MakeDefaultName(wp);
wp->UpdateVirtCoord();
if (need_sign_update) _viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeWaypoint(wp->index));
const StationSpec *spec = StationClass::Get(spec_class)->GetSpec(spec_index);
byte *layout_ptr = AllocaM(byte, count);
if (spec == NULL) {
if (spec == nullptr) {
/* The layout must be 0 for the 'normal' waypoints by design. */
memset(layout_ptr, 0, count);
} else {
@@ -296,7 +317,7 @@ CommandCost CmdBuildBuoy(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
/* Check if there is an already existing, deleted, waypoint close to us that we can reuse. */
Waypoint *wp = FindDeletedWaypointCloseTo(tile, STR_SV_STNAME_BUOY, OWNER_NONE);
if (wp == NULL && !Waypoint::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_STATIONS_LOADING);
if (wp == nullptr && !Waypoint::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_STATIONS_LOADING);
CommandCost cost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_WAYPOINT_BUOY]);
if (!IsWaterTile(tile)) {
@@ -306,10 +327,11 @@ CommandCost CmdBuildBuoy(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
}
if (flags & DC_EXEC) {
if (wp == NULL) {
if (wp == nullptr) {
wp = new Waypoint(tile);
} else {
/* Move existing (recently deleted) buoy to the new location */
_viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeWaypoint(wp->index));
wp->xy = tile;
InvalidateWindowData(WC_WAYPOINT_VIEW, wp->index);
}
@@ -322,12 +344,14 @@ CommandCost CmdBuildBuoy(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
wp->build_date = _date;
if (wp->town == NULL) MakeDefaultName(wp);
if (wp->town == nullptr) MakeDefaultName(wp);
MakeBuoy(tile, wp->index, GetWaterClass(tile));
CheckForDockingTile(tile);
MarkTileDirtyByTile(tile);
wp->UpdateVirtCoord();
_viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeWaypoint(wp->index));
InvalidateWindowData(WC_WAYPOINT_VIEW, wp->index);
}
@@ -384,7 +408,7 @@ static bool IsUniqueWaypointName(const char *name)
const Waypoint *wp;
FOR_ALL_WAYPOINTS(wp) {
if (wp->name != NULL && strcmp(wp->name, name) == 0) return false;
if (wp->name != nullptr && strcmp(wp->name, name) == 0) return false;
}
return true;
@@ -402,7 +426,7 @@ static bool IsUniqueWaypointName(const char *name)
CommandCost CmdRenameWaypoint(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
Waypoint *wp = Waypoint::GetIfValid(p1);
if (wp == NULL) return CMD_ERROR;
if (wp == nullptr) return CMD_ERROR;
if (wp->owner != OWNER_NONE) {
CommandCost ret = CheckOwnership(wp->owner);
@@ -418,7 +442,7 @@ CommandCost CmdRenameWaypoint(TileIndex tile, DoCommandFlag flags, uint32 p1, ui
if (flags & DC_EXEC) {
free(wp->name);
wp->name = reset ? NULL : stredup(text);
wp->name = reset ? nullptr : stredup(text);
wp->UpdateVirtCoord();
}