Update to 14.0-beta1
This commit is contained in:
+55
-39
@@ -10,6 +10,7 @@
|
||||
#include "stdafx.h"
|
||||
#include "roadveh.h"
|
||||
#include "command_func.h"
|
||||
#include "error_func.h"
|
||||
#include "news_func.h"
|
||||
#include "pathfinder/npf/npf_func.h"
|
||||
#include "station_base.h"
|
||||
@@ -19,7 +20,8 @@
|
||||
#include "pathfinder/yapf/yapf.h"
|
||||
#include "strings_func.h"
|
||||
#include "tunnelbridge_map.h"
|
||||
#include "date_func.h"
|
||||
#include "timer/timer_game_calendar.h"
|
||||
#include "timer/timer_game_economy.h"
|
||||
#include "vehicle_func.h"
|
||||
#include "sound_func.h"
|
||||
#include "ai/ai.hpp"
|
||||
@@ -41,7 +43,7 @@
|
||||
|
||||
#include "safeguards.h"
|
||||
|
||||
static const uint16 _roadveh_images[] = {
|
||||
static const uint16_t _roadveh_images[] = {
|
||||
0xCD4, 0xCDC, 0xCE4, 0xCEC, 0xCF4, 0xCFC, 0xD0C, 0xD14,
|
||||
0xD24, 0xD1C, 0xD2C, 0xD04, 0xD1C, 0xD24, 0xD6C, 0xD74,
|
||||
0xD7C, 0xC14, 0xC1C, 0xC24, 0xC2C, 0xC34, 0xC3C, 0xC4C,
|
||||
@@ -52,7 +54,7 @@ static const uint16 _roadveh_images[] = {
|
||||
0xC5C, 0xC64, 0xC6C, 0xC74, 0xC84, 0xC94, 0xCA4
|
||||
};
|
||||
|
||||
static const uint16 _roadveh_full_adder[] = {
|
||||
static const uint16_t _roadveh_full_adder[] = {
|
||||
0, 88, 0, 0, 0, 0, 48, 48,
|
||||
48, 48, 0, 0, 64, 64, 0, 16,
|
||||
16, 0, 88, 0, 0, 0, 0, 48,
|
||||
@@ -65,7 +67,7 @@ static const uint16 _roadveh_full_adder[] = {
|
||||
static_assert(lengthof(_roadveh_images) == lengthof(_roadveh_full_adder));
|
||||
|
||||
template <>
|
||||
bool IsValidImageIndex<VEH_ROAD>(uint8 image_index)
|
||||
bool IsValidImageIndex<VEH_ROAD>(uint8_t image_index)
|
||||
{
|
||||
return image_index < lengthof(_roadveh_images);
|
||||
}
|
||||
@@ -103,7 +105,7 @@ int RoadVehicle::GetDisplayImageWidth(Point *offset) const
|
||||
static void GetRoadVehIcon(EngineID engine, EngineImageType image_type, VehicleSpriteSeq *result)
|
||||
{
|
||||
const Engine *e = Engine::Get(engine);
|
||||
uint8 spritenum = e->u.road.image_index;
|
||||
uint8_t spritenum = e->u.road.image_index;
|
||||
|
||||
if (is_custom_sprite(spritenum)) {
|
||||
GetCustomVehicleIcon(engine, DIR_W, image_type, result);
|
||||
@@ -118,7 +120,7 @@ static void GetRoadVehIcon(EngineID engine, EngineImageType image_type, VehicleS
|
||||
|
||||
void RoadVehicle::GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const
|
||||
{
|
||||
uint8 spritenum = this->spritenum;
|
||||
uint8_t spritenum = this->spritenum;
|
||||
|
||||
if (is_custom_sprite(spritenum)) {
|
||||
GetCustomVehicleSprite(this, (Direction)(direction + 4 * IS_CUSTOM_SECONDHEAD_SPRITE(spritenum)), image_type, result);
|
||||
@@ -191,7 +193,7 @@ static uint GetRoadVehLength(const RoadVehicle *v)
|
||||
const Engine *e = v->GetEngine();
|
||||
uint length = VEHICLE_LENGTH;
|
||||
|
||||
uint16 veh_len = CALLBACK_FAILED;
|
||||
uint16_t veh_len = CALLBACK_FAILED;
|
||||
if (e->GetGRF() != nullptr && e->GetGRF()->grf_version >= 8) {
|
||||
/* Use callback 36 */
|
||||
veh_len = GetVehicleProperty(v, PROP_ROADVEH_SHORTEN_FACTOR, CALLBACK_FAILED);
|
||||
@@ -277,7 +279,7 @@ CommandCost CmdBuildRoadVehicle(DoCommandFlag flags, TileIndex tile, const Engin
|
||||
int y = TileY(tile) * TILE_SIZE + TILE_SIZE / 2;
|
||||
v->x_pos = x;
|
||||
v->y_pos = y;
|
||||
v->z_pos = GetSlopePixelZ(x, y);
|
||||
v->z_pos = GetSlopePixelZ(x, y, true);
|
||||
|
||||
v->state = RVSB_IN_DEPOT;
|
||||
v->vehstatus = VS_HIDDEN | VS_STOPPED | VS_DEFPAL;
|
||||
@@ -298,11 +300,12 @@ CommandCost CmdBuildRoadVehicle(DoCommandFlag flags, TileIndex tile, const Engin
|
||||
|
||||
v->SetServiceInterval(Company::Get(v->owner)->settings.vehicle.servint_roadveh);
|
||||
|
||||
v->date_of_last_service = _date;
|
||||
v->build_year = _cur_year;
|
||||
v->date_of_last_service = TimerGameEconomy::date;
|
||||
v->date_of_last_service_newgrf = TimerGameCalendar::date;
|
||||
v->build_year = TimerGameCalendar::year;
|
||||
|
||||
v->sprite_cache.sprite_seq.Set(SPR_IMG_QUERY);
|
||||
v->random_bits = VehicleRandomBits();
|
||||
v->random_bits = Random();
|
||||
v->SetFrontEngine();
|
||||
|
||||
v->roadtype = rt;
|
||||
@@ -346,15 +349,12 @@ static FindDepotData FindClosestRoadDepot(const RoadVehicle *v, int max_distance
|
||||
}
|
||||
}
|
||||
|
||||
bool RoadVehicle::FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse)
|
||||
ClosestDepot RoadVehicle::FindClosestDepot()
|
||||
{
|
||||
FindDepotData rfdd = FindClosestRoadDepot(this, 0);
|
||||
if (rfdd.best_length == UINT_MAX) return false;
|
||||
if (rfdd.best_length == UINT_MAX) return ClosestDepot();
|
||||
|
||||
if (location != nullptr) *location = rfdd.tile;
|
||||
if (destination != nullptr) *destination = GetDepotIndex(rfdd.tile);
|
||||
|
||||
return true;
|
||||
return ClosestDepot(rfdd.tile, GetDepotIndex(rfdd.tile));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -387,7 +387,12 @@ CommandCost CmdTurnRoadVeh(DoCommandFlag flags, VehicleID veh_id)
|
||||
|
||||
if (IsTileType(v->tile, MP_TUNNELBRIDGE) && DirToDiagDir(v->direction) == GetTunnelBridgeDirection(v->tile)) return CMD_ERROR;
|
||||
|
||||
if (flags & DC_EXEC) v->reverse_ctr = 180;
|
||||
if (flags & DC_EXEC) {
|
||||
v->reverse_ctr = 180;
|
||||
|
||||
/* Unbunching data is no longer valid. */
|
||||
v->ResetDepotUnbunching();
|
||||
}
|
||||
|
||||
return CommandCost();
|
||||
}
|
||||
@@ -404,7 +409,7 @@ void RoadVehicle::MarkDirty()
|
||||
|
||||
void RoadVehicle::UpdateDeltaXY()
|
||||
{
|
||||
static const int8 _delta_xy_table[8][10] = {
|
||||
static const int8_t _delta_xy_table[8][10] = {
|
||||
/* y_extent, x_extent, y_offs, x_offs, y_bb_offs, x_bb_offs, y_extent_shorten, x_extent_shorten, y_bb_offs_shorten, x_bb_offs_shorten */
|
||||
{3, 3, -1, -1, 0, 0, -1, -1, -1, -1}, // N
|
||||
{3, 7, -1, -3, 0, -1, 0, -1, 0, 0}, // NE
|
||||
@@ -419,7 +424,7 @@ void RoadVehicle::UpdateDeltaXY()
|
||||
int shorten = VEHICLE_LENGTH - this->gcache.cached_veh_length;
|
||||
if (!IsDiagonalDirection(this->direction)) shorten >>= 1;
|
||||
|
||||
const int8 *bb = _delta_xy_table[this->direction];
|
||||
const int8_t *bb = _delta_xy_table[this->direction];
|
||||
this->x_bb_offs = bb[5] + bb[9] * shorten;
|
||||
this->y_bb_offs = bb[4] + bb[8] * shorten;;
|
||||
this->x_offs = bb[3];
|
||||
@@ -482,7 +487,7 @@ static void RoadVehSetRandomDirection(RoadVehicle *v)
|
||||
};
|
||||
|
||||
do {
|
||||
uint32 r = Random();
|
||||
uint32_t r = Random();
|
||||
|
||||
v->direction = ChangeDir(v->direction, delta[r & 3]);
|
||||
v->UpdateViewport(true, true);
|
||||
@@ -616,8 +621,8 @@ struct RoadVehFindData {
|
||||
|
||||
static Vehicle *EnumCheckRoadVehClose(Vehicle *v, void *data)
|
||||
{
|
||||
static const int8 dist_x[] = { -4, -8, -4, -1, 4, 8, 4, 1 };
|
||||
static const int8 dist_y[] = { -4, -1, 4, 8, 4, 1, -4, -8 };
|
||||
static const int8_t dist_x[] = { -4, -8, -4, -1, 4, 8, 4, 1 };
|
||||
static const int8_t dist_y[] = { -4, -1, 4, 8, 4, 1, -4, -8 };
|
||||
|
||||
RoadVehFindData *rvf = (RoadVehFindData*)data;
|
||||
|
||||
@@ -855,7 +860,7 @@ static void RoadZPosAffectSpeed(RoadVehicle *v, int old_z)
|
||||
if (old_z < v->z_pos) {
|
||||
v->cur_speed = v->cur_speed * 232 / 256; // slow down by ~10%
|
||||
} else {
|
||||
uint16 spd = v->cur_speed + 2;
|
||||
uint16_t spd = v->cur_speed + 2;
|
||||
if (spd <= v->gcache.cached_max_track_speed) v->cur_speed = spd;
|
||||
}
|
||||
}
|
||||
@@ -894,7 +899,7 @@ static Trackdir RoadFindPathToDest(RoadVehicle *v, TileIndex tile, DiagDirection
|
||||
/* Road depot owned by another company or with the wrong orientation */
|
||||
trackdirs = TRACKDIR_BIT_NONE;
|
||||
}
|
||||
} else if (IsTileType(tile, MP_STATION) && IsStandardRoadStopTile(tile)) {
|
||||
} else if (IsTileType(tile, MP_STATION) && IsBayRoadStopTile(tile)) {
|
||||
/* Standard road stop (drive-through stops are treated as normal road) */
|
||||
|
||||
if (!IsTileOwner(tile, v->owner) || GetRoadStopDir(tile) == enterdir || v->HasArticulatedPart()) {
|
||||
@@ -909,7 +914,7 @@ static Trackdir RoadFindPathToDest(RoadVehicle *v, TileIndex tile, DiagDirection
|
||||
trackdirs = TRACKDIR_BIT_NONE;
|
||||
} else {
|
||||
/* Proper station type, check if there is free loading bay */
|
||||
if (!_settings_game.pf.roadveh_queue && IsStandardRoadStopTile(tile) &&
|
||||
if (!_settings_game.pf.roadveh_queue && IsBayRoadStopTile(tile) &&
|
||||
!RoadStop::GetByTile(tile, rstype)->HasFreeBay()) {
|
||||
/* Station is full and RV queuing is off */
|
||||
trackdirs = TRACKDIR_BIT_NONE;
|
||||
@@ -961,7 +966,7 @@ static Trackdir RoadFindPathToDest(RoadVehicle *v, TileIndex tile, DiagDirection
|
||||
/* Vehicle expected a choice here, invalidate its path. */
|
||||
v->path.clear();
|
||||
}
|
||||
return_track(FindFirstBit2x64(trackdirs));
|
||||
return_track(FindFirstBit(trackdirs));
|
||||
}
|
||||
|
||||
/* Attempt to follow cached path. */
|
||||
@@ -1030,6 +1035,7 @@ bool RoadVehLeaveDepot(RoadVehicle *v, bool first)
|
||||
if (RoadVehFindCloseTo(v, x, y, v->direction, false) != nullptr) return true;
|
||||
|
||||
VehicleServiceInDepot(v);
|
||||
v->LeaveUnbunchingDepot();
|
||||
|
||||
StartRoadVehSound(v);
|
||||
|
||||
@@ -1208,7 +1214,7 @@ bool IndividualRoadVehicleController(RoadVehicle *v, const RoadVehicle *prev)
|
||||
}
|
||||
|
||||
if (dir == INVALID_TRACKDIR) {
|
||||
if (!v->IsFrontEngine()) error("Disconnecting road vehicle.");
|
||||
if (!v->IsFrontEngine()) FatalError("Disconnecting road vehicle.");
|
||||
v->cur_speed = 0;
|
||||
return false;
|
||||
}
|
||||
@@ -1290,7 +1296,7 @@ again:
|
||||
}
|
||||
}
|
||||
|
||||
uint32 r = VehicleEnterTile(v, tile, x, y);
|
||||
uint32_t r = VehicleEnterTile(v, tile, x, y);
|
||||
if (HasBit(r, VETS_CANNOT_ENTER)) {
|
||||
if (!IsTileType(tile, MP_TUNNELBRIDGE)) {
|
||||
v->cur_speed = 0;
|
||||
@@ -1406,7 +1412,7 @@ again:
|
||||
}
|
||||
}
|
||||
|
||||
uint32 r = VehicleEnterTile(v, v->tile, x, y);
|
||||
uint32_t r = VehicleEnterTile(v, v->tile, x, y);
|
||||
if (HasBit(r, VETS_CANNOT_ENTER)) {
|
||||
v->cur_speed = 0;
|
||||
return false;
|
||||
@@ -1476,7 +1482,7 @@ again:
|
||||
* A vehicle has to spend at least 9 frames on a tile, so the following articulated part can follow.
|
||||
* (The following part may only be one tile behind, and the front part is moved before the following ones.)
|
||||
* The short (inner) curve has 8 frames, this elongates it to 10. */
|
||||
v->UpdateInclination(false, true);
|
||||
v->UpdateViewport(true, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1536,7 +1542,7 @@ again:
|
||||
if (v->current_order.IsType(OT_LEAVESTATION)) v->current_order.Free();
|
||||
}
|
||||
|
||||
if (IsStandardRoadStopTile(v->tile)) rs->SetEntranceBusy(true);
|
||||
if (IsBayRoadStopTile(v->tile)) rs->SetEntranceBusy(true);
|
||||
|
||||
StartRoadVehSound(v);
|
||||
SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP);
|
||||
@@ -1544,7 +1550,7 @@ again:
|
||||
|
||||
/* Check tile position conditions - i.e. stop position in depot,
|
||||
* entry onto bridge or into tunnel */
|
||||
uint32 r = VehicleEnterTile(v, v->tile, x, y);
|
||||
uint32_t r = VehicleEnterTile(v, v->tile, x, y);
|
||||
if (HasBit(r, VETS_CANNOT_ENTER)) {
|
||||
v->cur_speed = 0;
|
||||
return false;
|
||||
@@ -1587,7 +1593,11 @@ static bool RoadVehController(RoadVehicle *v)
|
||||
|
||||
if (v->current_order.IsType(OT_LOADING)) return true;
|
||||
|
||||
if (v->IsInDepot() && RoadVehLeaveDepot(v, true)) return true;
|
||||
if (v->IsInDepot()) {
|
||||
/* Check if we should wait here for unbunching. */
|
||||
if (v->IsWaitingForUnbunching()) return true;
|
||||
if (RoadVehLeaveDepot(v, true)) return true;
|
||||
}
|
||||
|
||||
v->ShowVisualEffect();
|
||||
|
||||
@@ -1706,10 +1716,16 @@ static void CheckIfRoadVehNeedsService(RoadVehicle *v)
|
||||
SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP);
|
||||
}
|
||||
|
||||
void RoadVehicle::OnNewDay()
|
||||
/** Calandar day handler */
|
||||
void RoadVehicle::OnNewCalendarDay()
|
||||
{
|
||||
if (!this->IsFrontEngine()) return;
|
||||
AgeVehicle(this);
|
||||
}
|
||||
|
||||
/** Economy day handler. */
|
||||
void RoadVehicle::OnNewEconomyDay()
|
||||
{
|
||||
if (!this->IsFrontEngine()) return;
|
||||
|
||||
if ((++this->day_counter & 7) == 0) DecreaseVehicleValue(this);
|
||||
@@ -1721,7 +1737,7 @@ void RoadVehicle::OnNewDay()
|
||||
|
||||
if (this->running_ticks == 0) return;
|
||||
|
||||
CommandCost cost(EXPENSES_ROADVEH_RUN, this->GetRunningCost() * this->running_ticks / (DAYS_IN_YEAR * DAY_TICKS));
|
||||
CommandCost cost(EXPENSES_ROADVEH_RUN, this->GetRunningCost() * this->running_ticks / (CalendarTime::DAYS_IN_YEAR * Ticks::DAY_TICKS));
|
||||
|
||||
this->profit_this_year -= cost.GetCost();
|
||||
this->running_ticks = 0;
|
||||
@@ -1741,7 +1757,7 @@ Trackdir RoadVehicle::GetVehicleTrackdir() const
|
||||
return DiagDirToDiagTrackdir(GetRoadDepotDirection(this->tile));
|
||||
}
|
||||
|
||||
if (IsStandardRoadStopTile(this->tile)) {
|
||||
if (IsBayRoadStopTile(this->tile)) {
|
||||
/* We'll assume the road vehicle is facing outwards */
|
||||
return DiagDirToDiagTrackdir(GetRoadStopDir(this->tile)); // Road vehicle in a station
|
||||
}
|
||||
@@ -1754,9 +1770,9 @@ Trackdir RoadVehicle::GetVehicleTrackdir() const
|
||||
return (Trackdir)((IsReversingRoadTrackdir((Trackdir)this->state)) ? (this->state - 6) : this->state);
|
||||
}
|
||||
|
||||
uint16 RoadVehicle::GetMaxWeight() const
|
||||
uint16_t RoadVehicle::GetMaxWeight() const
|
||||
{
|
||||
uint16 weight = CargoSpec::Get(this->cargo_type)->WeightOfNUnits(this->GetEngine()->DetermineCapacity(this));
|
||||
uint16_t weight = CargoSpec::Get(this->cargo_type)->WeightOfNUnits(this->GetEngine()->DetermineCapacity(this));
|
||||
|
||||
/* Vehicle weight is not added for articulated parts. */
|
||||
if (!this->IsArticulatedPart()) {
|
||||
|
||||
Reference in New Issue
Block a user