Update to 14.0-beta1

This commit is contained in:
dP
2024-02-04 02:18:17 +05:30
parent 79037e2c65
commit 33ef333b57
1325 changed files with 138465 additions and 70987 deletions

View File

@@ -17,10 +17,12 @@
#include "newgrf_engine.h"
#include "newgrf_sound.h"
#include "spritecache.h"
#include "error_func.h"
#include "strings_func.h"
#include "command_func.h"
#include "window_func.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 "cheat_type.h"
@@ -99,7 +101,7 @@ static const SpriteID _aircraft_sprite[] = {
};
template <>
bool IsValidImageIndex<VEH_AIRCRAFT>(uint8 image_index)
bool IsValidImageIndex<VEH_AIRCRAFT>(uint8_t image_index)
{
return image_index < lengthof(_aircraft_sprite);
}
@@ -171,7 +173,7 @@ static StationID FindNearestHangar(const Aircraft *v)
void Aircraft::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, image_type, result);
@@ -201,7 +203,7 @@ void GetRotorImage(const Aircraft *v, EngineImageType image_type, VehicleSpriteS
static void GetAircraftIcon(EngineID engine, EngineImageType image_type, VehicleSpriteSeq *result)
{
const Engine *e = Engine::Get(engine);
uint8 spritenum = e->u.air.image_index;
uint8_t spritenum = e->u.air.image_index;
if (is_custom_sprite(spritenum)) {
GetCustomVehicleIcon(engine, DIR_W, image_type, result);
@@ -337,14 +339,15 @@ CommandCost CmdBuildAircraft(DoCommandFlag flags, TileIndex tile, const Engine *
v->SetServiceInterval(Company::Get(_current_company)->settings.vehicle.servint_aircraft);
v->date_of_last_service = _date;
v->build_year = u->build_year = _cur_year;
v->date_of_last_service = TimerGameEconomy::date;
v->date_of_last_service_newgrf = TimerGameCalendar::date;
v->build_year = u->build_year = TimerGameCalendar::year;
v->sprite_cache.sprite_seq.Set(SPR_IMG_QUERY);
u->sprite_cache.sprite_seq.Set(SPR_IMG_QUERY);
v->random_bits = VehicleRandomBits();
u->random_bits = VehicleRandomBits();
v->random_bits = Random();
u->random_bits = Random();
v->vehicle_flags = 0;
if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SetBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
@@ -374,7 +377,7 @@ CommandCost CmdBuildAircraft(DoCommandFlag flags, TileIndex tile, const Engine *
w->spritenum = 0xFF;
w->subtype = AIR_ROTOR;
w->sprite_cache.sprite_seq.Set(SPR_ROTOR_STOPPED);
w->random_bits = VehicleRandomBits();
w->random_bits = Random();
/* Use rotor's air.state to store the rotor animation frame */
w->state = HRS_ROTOR_STOPPED;
w->UpdateDeltaXY();
@@ -388,7 +391,7 @@ CommandCost CmdBuildAircraft(DoCommandFlag flags, TileIndex tile, const Engine *
}
bool Aircraft::FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse)
ClosestDepot Aircraft::FindClosestDepot()
{
const Station *st = GetTargetAirportIfValid(this);
/* If the station is not a valid airport or if it has no hangars */
@@ -396,15 +399,12 @@ bool Aircraft::FindClosestDepot(TileIndex *location, DestinationID *destination,
/* the aircraft has to search for a hangar on its own */
StationID station = FindNearestHangar(this);
if (station == INVALID_STATION) return false;
if (station == INVALID_STATION) return ClosestDepot();
st = Station::Get(station);
}
if (location != nullptr) *location = st->xy;
if (destination != nullptr) *destination = st->index;
return true;
return ClosestDepot(st->xy, st->index);
}
static void CheckIfAircraftNeedsService(Aircraft *v)
@@ -440,7 +440,15 @@ Money Aircraft::GetRunningCost() const
return GetPrice(PR_RUNNING_AIRCRAFT, cost_factor, e->GetGRF());
}
void Aircraft::OnNewDay()
/** Calendar day handler */
void Aircraft::OnNewCalendarDay()
{
if (!this->IsNormalAircraft()) return;
AgeVehicle(this);
}
/** Economy day handler */
void Aircraft::OnNewEconomyDay()
{
if (!this->IsNormalAircraft()) return;
@@ -449,12 +457,11 @@ void Aircraft::OnNewDay()
CheckOrders(this);
CheckVehicleBreakdown(this);
AgeVehicle(this);
CheckIfAircraftNeedsService(this);
if (this->running_ticks == 0) return;
CommandCost cost(EXPENSES_AIRCRAFT_RUN, this->GetRunningCost() * this->running_ticks / (DAYS_IN_YEAR * DAY_TICKS));
CommandCost cost(EXPENSES_AIRCRAFT_RUN, this->GetRunningCost() * this->running_ticks / (CalendarTime::DAYS_IN_YEAR * Ticks::DAY_TICKS));
this->profit_this_year -= cost.GetCost();
this->running_ticks = 0;
@@ -532,12 +539,12 @@ void SetAircraftPosition(Aircraft *v, int x, int y, int z)
Aircraft *u = v->Next();
int safe_x = Clamp(x, 0, MapMaxX() * TILE_SIZE);
int safe_y = Clamp(y - 1, 0, MapMaxY() * TILE_SIZE);
int safe_x = Clamp(x, 0, Map::MaxX() * TILE_SIZE);
int safe_y = Clamp(y - 1, 0, Map::MaxY() * TILE_SIZE);
u->x_pos = x;
u->y_pos = y - ((v->z_pos - GetSlopePixelZ(safe_x, safe_y)) >> 3);
safe_y = Clamp(u->y_pos, 0, MapMaxY() * TILE_SIZE);
safe_y = Clamp(u->y_pos, 0, Map::MaxY() * TILE_SIZE);
u->z_pos = GetSlopePixelZ(safe_x, safe_y);
u->sprite_cache.sprite_seq.CopyWithoutPalette(v->sprite_cache.sprite_seq); // the shadow is never coloured
@@ -699,8 +706,8 @@ static int UpdateAircraftSpeed(Aircraft *v, uint speed_limit = SPEED_LIMIT_NONE,
*/
int GetTileHeightBelowAircraft(const Vehicle *v)
{
int safe_x = Clamp(v->x_pos, 0, MapMaxX() * TILE_SIZE);
int safe_y = Clamp(v->y_pos, 0, MapMaxY() * TILE_SIZE);
int safe_x = Clamp(v->x_pos, 0, Map::MaxX() * TILE_SIZE);
int safe_y = Clamp(v->y_pos, 0, Map::MaxY() * TILE_SIZE);
return TileHeight(TileVirtXY(safe_x, safe_y)) * TILE_HEIGHT;
}
@@ -1167,7 +1174,7 @@ static bool HandleCrashedAircraft(Aircraft *v)
/* make aircraft crash down to the ground */
if (v->crashed_counter < 500 && st == nullptr && ((v->crashed_counter % 3) == 0) ) {
int z = GetSlopePixelZ(Clamp(v->x_pos, 0, MapMaxX() * TILE_SIZE), Clamp(v->y_pos, 0, MapMaxY() * TILE_SIZE));
int z = GetSlopePixelZ(Clamp(v->x_pos, 0, Map::MaxX() * TILE_SIZE), Clamp(v->y_pos, 0, Map::MaxY() * TILE_SIZE));
v->z_pos -= 1;
if (v->z_pos == z) {
v->crashed_counter = 500;
@@ -1176,7 +1183,7 @@ static bool HandleCrashedAircraft(Aircraft *v)
}
if (v->crashed_counter < 650) {
uint32 r;
uint32_t r;
if (Chance16R(1, 32, r)) {
static const DirDiff delta[] = {
DIRDIFF_45LEFT, DIRDIFF_SAME, DIRDIFF_SAME, DIRDIFF_45RIGHT
@@ -1220,8 +1227,8 @@ static bool HandleCrashedAircraft(Aircraft *v)
static void HandleAircraftSmoke(Aircraft *v, bool mode)
{
static const struct {
int8 x;
int8 y;
int8_t x;
int8_t y;
} smoke_pos[] = {
{ 5, 5 },
{ 6, 0 },
@@ -1283,7 +1290,7 @@ void HandleMissingAircraftOrders(Aircraft *v)
}
TileIndex Aircraft::GetOrderStationLocation(StationID station)
TileIndex Aircraft::GetOrderStationLocation(StationID)
{
/* Orders are changed in flight, ensure going to the right station. */
if (this->state == FLYING) {
@@ -1327,14 +1334,12 @@ static void CrashAirplane(Aircraft *v)
v->Next()->cargo.Truncate();
const Station *st = GetTargetAirportIfValid(v);
StringID newsitem;
TileIndex vt;
TileIndex vt = TileVirtXY(v->x_pos, v->y_pos);
if (st == nullptr) {
newsitem = STR_NEWS_PLANE_CRASH_OUT_OF_FUEL;
vt = TileVirtXY(v->x_pos, v->y_pos);
} else {
SetDParam(1, st->index);
newsitem = STR_NEWS_AIRCRAFT_CRASH;
vt = v->tile;
}
AI::NewEvent(v->owner, new ScriptEventVehicleCrashed(v->index, vt, st == nullptr ? ScriptEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT : ScriptEventVehicleCrashed::CRASH_PLANE_LANDING));
@@ -1360,7 +1365,7 @@ static void MaybeCrashAirplane(Aircraft *v)
Station *st = Station::Get(v->targetairport);
uint32 prob;
uint32_t prob;
if ((st->airport.GetFTA()->flags & AirportFTAClass::SHORT_STRIP) &&
(AircraftVehInfo(v->engine_type)->subtype & AIR_FAST) &&
!_cheats.no_jetcrash.value) {
@@ -1373,9 +1378,9 @@ static void MaybeCrashAirplane(Aircraft *v)
if (GB(Random(), 0, 22) > prob) return;
/* Crash the airplane. Remove all goods stored at the station. */
for (CargoID i = 0; i < NUM_CARGO; i++) {
st->goods[i].rating = 1;
st->goods[i].cargo.Truncate();
for (GoodsEntry &ge : st->goods) {
ge.rating = 1;
ge.cargo.Truncate();
}
CrashAirplane(v);
@@ -1472,6 +1477,7 @@ void AircraftLeaveHangar(Aircraft *v, Direction exit_dir)
}
VehicleServiceInDepot(v);
v->LeaveUnbunchingDepot();
SetAircraftPosition(v, v->x_pos, v->y_pos, v->z_pos);
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
SetWindowClassesDirty(WC_AIRCRAFT_LIST);
@@ -1516,6 +1522,9 @@ static void AircraftEventHandler_InHangar(Aircraft *v, const AirportFTAClass *ap
return;
}
/* Check if we should wait here for unbunching. */
if (v->IsWaitingForUnbunching()) return;
if (!v->current_order.IsType(OT_GOTO_STATION) &&
!v->current_order.IsType(OT_GOTO_DEPOT))
return;
@@ -1558,7 +1567,8 @@ static void AircraftEventHandler_AtTerminal(Aircraft *v, const AirportFTAClass *
if (_settings_game.order.serviceathelipad) {
if (v->subtype == AIR_HELICOPTER && apc->num_helipads > 0) {
/* an excerpt of ServiceAircraft, without the invisibility stuff */
v->date_of_last_service = _date;
v->date_of_last_service = TimerGameEconomy::date;
v->date_of_last_service_newgrf = TimerGameCalendar::date;
v->breakdowns_since_last_service = 0;
v->reliability = v->GetEngine()->reliability;
SetWindowDirty(WC_VEHICLE_DETAILS, v->index);
@@ -1589,7 +1599,7 @@ static void AircraftEventHandler_AtTerminal(Aircraft *v, const AirportFTAClass *
return;
default: // orders have been deleted (no orders), goto depot and don't bother us
v->current_order.Free();
go_to_hangar = Station::Get(v->targetairport)->airport.HasHangar();
go_to_hangar = true;
}
if (go_to_hangar && Station::Get(v->targetairport)->airport.HasHangar()) {
@@ -1601,31 +1611,31 @@ static void AircraftEventHandler_AtTerminal(Aircraft *v, const AirportFTAClass *
AirportMove(v, apc);
}
static void AircraftEventHandler_General(Aircraft *v, const AirportFTAClass *apc)
static void AircraftEventHandler_General(Aircraft *, const AirportFTAClass *)
{
error("OK, you shouldn't be here, check your Airport Scheme!");
FatalError("OK, you shouldn't be here, check your Airport Scheme!");
}
static void AircraftEventHandler_TakeOff(Aircraft *v, const AirportFTAClass *apc)
static void AircraftEventHandler_TakeOff(Aircraft *v, const AirportFTAClass *)
{
PlayAircraftSound(v); // play takeoffsound for airplanes
v->state = STARTTAKEOFF;
}
static void AircraftEventHandler_StartTakeOff(Aircraft *v, const AirportFTAClass *apc)
static void AircraftEventHandler_StartTakeOff(Aircraft *v, const AirportFTAClass *)
{
v->state = ENDTAKEOFF;
v->UpdateDeltaXY();
}
static void AircraftEventHandler_EndTakeOff(Aircraft *v, const AirportFTAClass *apc)
static void AircraftEventHandler_EndTakeOff(Aircraft *v, const AirportFTAClass *)
{
v->state = FLYING;
/* get the next position to go to, differs per airport */
AircraftNextAirportPos_and_Order(v);
}
static void AircraftEventHandler_HeliTakeOff(Aircraft *v, const AirportFTAClass *apc)
static void AircraftEventHandler_HeliTakeOff(Aircraft *v, const AirportFTAClass *)
{
v->state = FLYING;
v->UpdateDeltaXY();
@@ -1657,8 +1667,8 @@ static void AircraftEventHandler_Flying(Aircraft *v, const AirportFTAClass *apc)
/* save speed before, since if AirportHasBlock is false, it resets them to 0
* we don't want that for plane in air
* hack for speed thingie */
uint16 tcur_speed = v->cur_speed;
uint16 tsubspeed = v->subspeed;
uint16_t tcur_speed = v->cur_speed;
uint16_t tsubspeed = v->subspeed;
if (!AirportHasBlock(v, current, apc)) {
v->state = landingtype; // LANDING / HELILANDING
if (v->state == HELILANDING) SetBit(v->flags, VAF_HELI_DIRECT_DESCENT);
@@ -1679,7 +1689,7 @@ static void AircraftEventHandler_Flying(Aircraft *v, const AirportFTAClass *apc)
v->pos = apc->layout[v->pos].next_position;
}
static void AircraftEventHandler_Landing(Aircraft *v, const AirportFTAClass *apc)
static void AircraftEventHandler_Landing(Aircraft *v, const AirportFTAClass *)
{
v->state = ENDLANDING;
AircraftLandAirplane(v); // maybe crash airplane
@@ -1692,7 +1702,7 @@ static void AircraftEventHandler_Landing(Aircraft *v, const AirportFTAClass *apc
}
}
static void AircraftEventHandler_HeliLanding(Aircraft *v, const AirportFTAClass *apc)
static void AircraftEventHandler_HeliLanding(Aircraft *v, const AirportFTAClass *)
{
v->state = HELIENDLANDING;
v->UpdateDeltaXY();
@@ -1842,7 +1852,7 @@ static bool AirportHasBlock(Aircraft *v, const AirportFTA *current_pos, const Ai
/* same block, then of course we can move */
if (apc->layout[current_pos->position].block != next->block) {
const Station *st = Station::Get(v->targetairport);
uint64 airport_flags = next->block;
uint64_t airport_flags = next->block;
/* check additional possible extra blocks */
if (current_pos != reference && current_pos->block != NOTHING_block) {
@@ -1872,7 +1882,7 @@ static bool AirportSetBlocks(Aircraft *v, const AirportFTA *current_pos, const A
/* if the next position is in another block, check it and wait until it is free */
if ((apc->layout[current_pos->position].block & next->block) != next->block) {
uint64 airport_flags = next->block;
uint64_t airport_flags = next->block;
/* search for all all elements in the list with the same state, and blocks != N
* this means more blocks should be checked/set */
const AirportFTA *current = current_pos;
@@ -1909,7 +1919,7 @@ static bool AirportSetBlocks(Aircraft *v, const AirportFTA *current_pos, const A
*/
struct MovementTerminalMapping {
AirportMovementStates state; ///< Aircraft movement state when going to this terminal.
uint64 airport_flag; ///< Bitmask in the airport flags that need to be free for this terminal.
uint64_t airport_flag; ///< Bitmask in the airport flags that need to be free for this terminal.
};
/** A list of all valid terminals and their associated blocks. */