1
0
mirror of https://github.com/OpenTTD/OpenTTD.git synced 2025-08-19 04:29:09 +00:00

(svn r3353) Simplify the automatic length adjustment algorithm for replacing trains: Use the length of the train before the replacement as reference length

This commit is contained in:
tron
2005-12-29 12:42:59 +00:00
parent 1ffc700797
commit 246c126d25
24 changed files with 22 additions and 83 deletions

View File

@@ -2759,7 +2759,6 @@ STR_REPLACE_HELP_RAILTYPE :{BLACK}Seleccio
STR_REPLACE_HELP_REPLACE_INFO_TAB :{BLACK}Exibe o tipo de motor que substituir<69> o que est<73> seleccionado <20> esquerda, se algum
STR_REPLACE_HELP :{BLACK}Permite a substiui<75><69>o de um tipo de motor por outro, quando comboios do tipo original entram num dep<65>sito
STR_REPLACE_REMOVE_WAGON :{BLACK}Remo<6D><6F>o de vag<61>es: {ORANGE}{SKIP}{STRING}
STR_REPLACE_REMOVE_WAGON_HELP :{BLACK}Ativar essa op<6F><70>o far<61> com que a auto-reposi<73><69>o remova vag<61>es dos trens, para que eles tenham o comprimento da menor esta<74><61>o em sua rota{}Ela remover<65> quantos vag<61>es forem necess<73>rios, come<6D>ando pelo da frente
STR_SHORT_DATE :{WHITE}{DATE_TINY}
STR_SIGN_LIST_CAPTION :{WHITE}Lista de sinais - {COMMA} Sinais

View File

@@ -2757,7 +2757,6 @@ STR_REPLACE_HELP_RAILTYPE :{BLACK}Tria el
STR_REPLACE_HELP_REPLACE_INFO_TAB :{BLACK}Mosyta quin motor dels seleccionats a l'esquerra es reempla<6C>a, si hi ha
STR_REPLACE_HELP :{BLACK}Et permet reempla<6C>ar un tipus de motor amb un altre, quan els trens del tipus original entrin a cotxeres
STR_REPLACE_REMOVE_WAGON :{BLACK}Treure vagons: {ORANGE}{SKIP}{STRING}
STR_REPLACE_REMOVE_WAGON_HELP :{BLACK}Establint aix<69> a "On" far<61> que l'automodificaci<63> tregui vagons dels trens per evitar que excedeixi la seva llarg<72>ria de la de l'estaci<63> m<>s curta que es trobi a les seves ordres.{}Es treur<75>n tants vagons com es necessiti comen<65>ant per davant
STR_SHORT_DATE :{WHITE}{DATE_TINY}
STR_SIGN_LIST_CAPTION :{WHITE}Llista de senyals - {COMMA} Senyals

View File

@@ -2812,7 +2812,6 @@ STR_REPLACE_HELP_RAILTYPE :{BLACK}Vyber ty
STR_REPLACE_HELP_REPLACE_INFO_TAB :{BLACK}Tady je zobrazeno, za jakou lokomotivu se ta v lev<65>m seznamu vymenuje
STR_REPLACE_HELP :{BLACK}Tato mo<6D>nost hry ti umoznuje vybrat typ lokomotivy, kter<65> nech<63> vymenit za jin<69>. To se bude automaticky provadet, kdy<64> lokomotiva zajede do depa.
STR_REPLACE_REMOVE_WAGON :{BLACK}Odeb<65>r<EFBFBD>n<EFBFBD> vagonu: {ORANGE}{SKIP}{STRING}
STR_REPLACE_REMOVE_WAGON_HELP :{BLACK}Nastaven<65>m na "zapnuto" zacne funkce automatick<63>ho vymenovani odstranovat vagony z vlaku, kdyby se neve<76>ly do nejkrat<61><74> stanice ve sv<73>m j<>zdn<64>m radu.{}Bude od zacatku vlaku odstranovat tolik vagonu, kolik potrebuje.
STR_SHORT_DATE :{WHITE}{DATE_TINY}
STR_SIGN_LIST_CAPTION :{WHITE}Seznam popisku - {COMMA} popis{P ek ky ku}

View File

@@ -2753,7 +2753,6 @@ STR_REPLACE_HELP_RAILTYPE :{BLACK}V
STR_REPLACE_HELP_REPLACE_INFO_TAB :{BLACK}Viser hvilket k<>ret<65>j at det valgte k<>ret<65>j til venstre bliver udskiftet med, hvis det bliver udskiftet
STR_REPLACE_HELP :{BLACK}Dette giver dig mulighed for at udskifte en k<>ret<65>jstype med en anden, n<>r et k<>ret<65>j af den oprindelige type k<>rer i depot
STR_REPLACE_REMOVE_WAGON :{BLACK}Fjern vogn: {ORANGE}{SKIP}{STRING}
STR_REPLACE_REMOVE_WAGON_HELP :{BLACK}Ved at s<>tte dette til "Til" vil f<> autoreplace til at fjerne vogne fra tog for at f<> dem til at beholde deres l<>ngde hvis de overskrider l<>ngden af den korteste station i deres ordre{}Det vil fjerne s<> mange vogne som der er behov for, startende med de forreste
STR_SHORT_DATE :{WHITE}{DATE_TINY}
STR_SIGN_LIST_CAPTION :{WHITE}Liste of skilte - {COMMA} Skilte

View File

@@ -2756,7 +2756,6 @@ STR_REPLACE_HELP_RAILTYPE :{BLACK}Selectee
STR_REPLACE_HELP_REPLACE_INFO_TAB :{BLACK}Dit geeft weer waarmee de aan de linkerkant geselecteerde locomotief mee vervangen wordt
STR_REPLACE_HELP :{BLACK}Deze optie stelt je in staat om een type locomotief te selecteren en die te vervangen door een andere. Dit zal automatisch gebeuren zodra de voertuigen een depot inrijden
STR_REPLACE_REMOVE_WAGON :{BLACK}Wagons verwijderen: {ORANGE}{SKIP}{STRING}
STR_REPLACE_REMOVE_WAGON_HELP :{BLACK}Deze optie "Aan" zetten zorgt ervoor dat de autoreplace functie wagons van je trein afhaalt zodat ze in je korste station passen in hun orders lijst,{}waarbij wordt begonnen bij de eerste wagons
STR_SHORT_DATE :{WHITE}{DATE_TINY}
STR_SIGN_LIST_CAPTION :{WHITE}Bordjes lijst - {COMMA} Bordjes

View File

@@ -2759,7 +2759,7 @@ STR_REPLACE_HELP_RAILTYPE :{BLACK}Choose t
STR_REPLACE_HELP_REPLACE_INFO_TAB :{BLACK}Displays which engine the left selected engine is being replaced with, if any
STR_REPLACE_HELP :{BLACK}This allows you to replace one engine type with another type, when trains of the original type enter a depot
STR_REPLACE_REMOVE_WAGON :{BLACK}Wagon removal: {ORANGE}{SKIP}{STRING}
STR_REPLACE_REMOVE_WAGON_HELP :{BLACK}Setting this to "On" will make autoreplace remove wagons from trains to make them keep their length if they exceed length of the shortest station in their orders.{}It will remove as many wagons as needed starting from the front
STR_REPLACE_REMOVE_WAGON_HELP :{BLACK}Make autoreplace keep the length of a train the same by removing wagons (starting at the front), if replacing the engine would make the train longer.
STR_SHORT_DATE :{WHITE}{DATE_TINY}
STR_SIGN_LIST_CAPTION :{WHITE}Sign List - {COMMA} Sign{P "" s}

View File

@@ -2760,7 +2760,6 @@ STR_REPLACE_HELP_RAILTYPE :{BLACK}Choisir
STR_REPLACE_HELP_REPLACE_INFO_TAB :{BLACK}Ceci affiche par quelle locomotive celle qui est s<>lectionn<6E>e <20> gauche sera remplac<61>e
STR_REPLACE_HELP :{BLACK}Cette caract<63>ristique permet de choisir un type de locomotive et de le remplacer par un autre. Ceci sera fait automatiquement quand le v<>hicule rentre dans un d<>p<EFBFBD>t
STR_REPLACE_REMOVE_WAGON :{BLACK}Retrait de wagon: {ORANGE}{SKIP}{STRING}
STR_REPLACE_REMOVE_WAGON_HELP :{BLACK}Activer ce param<61>tre permettra <20> l'autoremplacement de retirer des wagons d'un trains, ajustant ainsi sa longueur sur la plus courte station c<>dul<75>e, advenant le cas d'une longueur exc<78>dentaire.{}Autant de wagons que requis seront retir<69>s du train, en commencant par celui de t<>te.
STR_SHORT_DATE :{WHITE}{DATE_TINY}
STR_SIGN_LIST_CAPTION :{WHITE}Liste des panneaux - {COMMA} panneau{P "" x}

View File

@@ -2760,7 +2760,6 @@ STR_REPLACE_HELP_RAILTYPE :{BLACK}W
STR_REPLACE_HELP_REPLACE_INFO_TAB :{BLACK}Hier wird angezeigt, gegen welches Fahrzeug das auf der linken Seite gew<65>hlte ersetzt wird
STR_REPLACE_HELP :{BLACK}Dieses Feature erm<72>glicht es, einen Fahrzeugtyp auszuw<75>hlen und ihn durch einen anderen ersetzen zu lassen. Dies geschieht automatisch, wenn das Fahrzeug regul<75>r das Depot besucht.
STR_REPLACE_REMOVE_WAGON :{BLACK}Waggon-Entfernung: {ORANGE}{SKIP}{STRING}
STR_REPLACE_REMOVE_WAGON_HELP :{BLACK}Diesen Schalter auf "An" schalten bewirkt das Entfernen von Waggons aus dem Zug, damit er nie l<>nger wird als der k<>rzeste Bahnsteig im Fahrplan.{}Die Waggons werden am Anfang des Zuges entfernt, bis die L<>nge ausreichend ist.
STR_SHORT_DATE :{WHITE}{DATE_TINY}
STR_SIGN_LIST_CAPTION :{WHITE}Schilderliste - {COMMA} Schild{P "" er}

View File

@@ -2758,7 +2758,6 @@ STR_REPLACE_HELP_RAILTYPE :{BLACK}Selezion
STR_REPLACE_HELP_REPLACE_INFO_TAB :{BLACK}Mostra con quale locomotore verr<72> rimpiazzato il tipo selezionato a sinistra, se alcuno
STR_REPLACE_HELP :{BLACK}Permette di rimpiazzare un locomotere con uno di un'altro tipo, quando il treno entra in un deposito
STR_REPLACE_REMOVE_WAGON :{BLACK}Rimuovi vagoni: {ORANGE}{SKIP}{STRING}
STR_REPLACE_REMOVE_WAGON_HELP :{BLACK}Impostando "SI", quando viene eseguita la sostituzione automatica dei treni verranno rimossi i vagoni fino a raggiungere la lunghezza necessaria al treno per entrare nella stazione pi<70> corta presente nella lista ordini. I vagoni verranno rimossi partendo dalla testa del treno.
STR_SHORT_DATE :{WHITE}{DATE_TINY}
STR_SIGN_LIST_CAPTION :{WHITE}Lista dei Cartelli - {COMMA} Cartelli

View File

@@ -2754,7 +2754,6 @@ STR_REPLACE_HELP_RAILTYPE :{BLACK}Velg jer
STR_REPLACE_HELP_REPLACE_INFO_TAB :{BLACK}Dette viser hvilket lokomotiv som overtar for det valgte lokomotivet p<> venstresiden
STR_REPLACE_HELP :{BLACK}Dette verkt<6B>yet lar deg bytte ut en type lokomotiv med en annen. Dette blir gjort neste gang lokomotivet er innom et depot.
STR_REPLACE_REMOVE_WAGON :{BLACK}Vognfjerning: {ORANGE}{SKIP}{STRING}
STR_REPLACE_REMOVE_WAGON_HELP :{BLACK}Ved <20> sette denne til "P<>" gj<67>r du slik at auto-erstatt fjerner vogner fra tog slik at de beholder lengden hvis det er lenger enn den korteste stasjonen p<> ruten sin.{}Det vil fjerne s<> mange stasjoner som n<>dvending, og starter fra fronten jobber seg bakover
STR_SHORT_DATE :{WHITE}{DATE_TINY}
STR_SIGN_LIST_CAPTION :{WHITE}Skiltliste - {COMMA} Skilt

View File

@@ -2759,7 +2759,6 @@ STR_REPLACE_HELP_RAILTYPE :{BLACK}Wybierz
STR_REPLACE_HELP_REPLACE_INFO_TAB :{BLACK}Wyswietla typ pojazdu na jaki bedzie zastapiony pojazd zaznaczony po lewej stronie
STR_REPLACE_HELP :{BLACK}Ta funkcja pozwala wybrac typ pojazdu i zastapic go innym. Bedzie sie to odbywac w momencie gdy pociag zjedzie do zajezdni
STR_REPLACE_REMOVE_WAGON :{BLACK}Usuniecie pojazdu: {ORANGE}{SKIP}{STRING}
STR_REPLACE_REMOVE_WAGON_HELP :{BLACK}Ustawienie na "Wla" spowoduje ze tryb autowymiany usunie wagony z pociagu by utrzymac jego dlugosc jaka jest potrzebna do najkrotszej stacji w swoim rozkladzie.{}Usuniete beda wagony poczawszy od poczatku pociagu
STR_SHORT_DATE :{WHITE}{DATE_TINY}
STR_SIGN_LIST_CAPTION :{WHITE}Lista tablic - {COMMA} Tablice

View File

@@ -2759,7 +2759,6 @@ STR_REPLACE_HELP_RAILTYPE :{BLACK}Seleccio
STR_REPLACE_HELP_REPLACE_INFO_TAB :{BLACK}Exibe o tipo de motor que substituir<69> o que est<73> seleccionado <20> esquerda, se algum
STR_REPLACE_HELP :{BLACK}Permite a substiui<75><69>o de um tipo de motor por outro, quando comboios do tipo original entram num dep<65>sito
STR_REPLACE_REMOVE_WAGON :{BLACK}Remover vag<61>es: {ORANGE}{SKIP}{STRING}
STR_REPLACE_REMOVE_WAGON_HELP :{BLACK}Ligar esta op<6F><70>o far<61> com que a funcionalidade de substitui<75><69>o autom<6F>tica remova vag<61>es aos comboios, obrigando-os a manter o seu comprimento igual ao da menor esta<74><61>o presente nas ordens.{}Ser<65>o removidos tantos vag<61>es quantos necess<73>rios, a come<6D>ar pela frente.
STR_SHORT_DATE :{WHITE}{DATE_TINY}
STR_SIGN_LIST_CAPTION :{WHITE}Lista de sinais - {COMMA} Sinais

View File

@@ -2756,7 +2756,6 @@ STR_REPLACE_HELP_RAILTYPE :{BLACK}Alege un
STR_REPLACE_HELP_REPLACE_INFO_TAB :{BLACK}Afiseaza cu ce model vor fi inlocuite vehiculele din stanga
STR_REPLACE_HELP :{BLACK}Aceasta functie iti permite sa selectezi un model de vehicul si sa-l inlocuiesti cu altul. Schimbarea se va efectua automat la intrarea vehiculului intr-un depou.
STR_REPLACE_REMOVE_WAGON :{BLACK}Retragere vagoane: {ORANGE}{SKIP}{STRING}
STR_REPLACE_REMOVE_WAGON_HELP :{BLACK}Prin comutarea acestui buton autoinlocuirea va sterge vagoane din componenta unui tren pentru a nu depasi marimea celei mai mici statii de pe traseu.{}Vor fi sterse toate vagoanele necesare incepand de la locomotiva
STR_SHORT_DATE :{WHITE}{DATE_TINY}
STR_SIGN_LIST_CAPTION :{WHITE}Lista de semne - {COMMA} Semne

View File

@@ -2758,7 +2758,6 @@ STR_REPLACE_HELP_RAILTYPE :{BLACK}Vyber ty
STR_REPLACE_HELP_REPLACE_INFO_TAB :{BLACK}Tu sa zobrazuje, za ktoru lokomotiva sa lokomotiva v lavom zozname zamenuje
STR_REPLACE_HELP :{BLACK}Umoznuje vybrat typ lokomotivy, ktory automaticky sa zameni za iny typ, ak vlaky s takouto lokomotivou sa zastavia v depe
STR_REPLACE_REMOVE_WAGON :{BLACK}Odstranenie vagonu: {ORANGE}{SKIP}{STRING}
STR_REPLACE_REMOVE_WAGON_HELP :{BLACK}Pri nastaveni na "On" odstani vagony z vlakov, aby sa vosli do najkratsej stanice zo stanic v jeho prikazoch.{}Odstrani to pozadovany pocet vagonov, pocinajuc prvym
STR_SHORT_DATE :{WHITE}{DATE_TINY}
STR_SIGN_LIST_CAPTION :{WHITE}Zoznam popisov - {COMMA} popisov

View File

@@ -2756,7 +2756,6 @@ STR_REPLACE_HELP_RAILTYPE :{BLACK}Seleccio
STR_REPLACE_HELP_REPLACE_INFO_TAB :{BLACK}Muestra que locomotora ser<65> reemplazada
STR_REPLACE_HELP :{BLACK}Esta funci<63>n permite seleccionar un tipo de locomotora y reemplazarla por otra. El cambio se realizar<61> cuando el veh<65>culo llegue al dep<65>sito
STR_REPLACE_REMOVE_WAGON :{BLACK}Quitar vag<61>n: {ORANGE}{SKIP}{STRING}
STR_REPLACE_REMOVE_WAGON_HELP :{BLACK}Activar esta opci<63>n permite eliminar los vagones necesarios para que los trenes entren en las estaciones m<>s cortas que est<73>n marcadas en sus ordenes. Se eliminar<61>n los vagones necesarios empezando por delante
STR_SHORT_DATE :{WHITE}{DATE_TINY}
STR_SIGN_LIST_CAPTION :{WHITE}Lista de se<73>ales - {COMMA} Se<53>ales

View File

@@ -2759,7 +2759,6 @@ STR_REPLACE_HELP_RAILTYPE :{BLACK}Lokomati
STR_REPLACE_HELP_REPLACE_INFO_TAB :{BLACK}Soldaki degistiriliyorsa neyle degistirildigini g<>ster
STR_REPLACE_HELP :{BLACK}Tren gara girdiginde se<73>ilen t<>rle degistirilir
STR_REPLACE_REMOVE_WAGON :{BLACK}Vagon kaldirma: {ORANGE}{SKIP}{STRING}
STR_REPLACE_REMOVE_WAGON_HELP :{BLACK}Bu ayari "a<>ik" yaparsaniz ara<72>lari degistirme isleminde eger trenin talimatlarindaki duraklardan birine sigmayacak kadar uzuyorsa tren uzunlugu korunacaktir.{}Fazla vagonlar <20>nden baslayarak satilacaktir
STR_SHORT_DATE :{WHITE}{DATE_TINY}
STR_SIGN_LIST_CAPTION :{WHITE}Tabela Listesi - {COMMA} Tabela

View File

@@ -1263,21 +1263,13 @@ bool AfterLoadGame(uint version)
}
}
/* In version 16.1 of the savegame, trains became aware of station lengths
need to initialized to the invalid state
players needs to set renew_keep_length too */
/* In version 16.1 of the savegame a player can decide if trains, which get
* replaced, shall keep their old length. In all prior versions, just default
* to false */
if (CheckSavegameVersionOldStyle(16, 1)) {
Vehicle *v;
FOR_ALL_PLAYERS(p) {
p->renew_keep_length = false;
}
FOR_ALL_VEHICLES(v) {
if (v->type == VEH_Train) {
v->u.rail.shortest_platform[0] = 255;
v->u.rail.shortest_platform[1] = 0;
}
}
}
/* In version 17, ground type is moved from m2 to m4 for depots and

View File

@@ -386,7 +386,6 @@ int32 CmdInsertOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2)
}
/* Update any possible open window of the vehicle */
InvalidateVehicleOrder(u);
if (u->type == VEH_Train) u->u.rail.shortest_platform[1] = 0; // we changed the orders so we invalidate the station length collector
u = u->next_shared;
}
@@ -517,7 +516,6 @@ int32 CmdSkipOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (v->current_order.type == OT_LOADING && HASBIT(v->current_order.flags, OFB_NON_STOP))
v->current_order.flags = 0;
if (v->type == VEH_Train) v->u.rail.shortest_platform[1] = 0; // we changed the orders so we invalidate the station length collector
InvalidateVehicleOrder(v);
}
@@ -660,7 +658,6 @@ int32 CmdCloneOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2)
InvalidateVehicleOrder(src);
RebuildVehicleLists();
if (dst->type == VEH_Train) dst->u.rail.shortest_platform[1] = 0; // we changed the orders so we invalidate the station length collector
}
} break;
@@ -720,7 +717,6 @@ int32 CmdCloneOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2)
InvalidateVehicleOrder(dst);
RebuildVehicleLists();
if (dst->type == VEH_Train) dst->u.rail.shortest_platform[1] = 0; // we changed the orders so we invalidate the station length collector
}
} break;

View File

@@ -248,11 +248,6 @@ static inline bool IsBuoyTile(TileIndex tile)
return IsTileType(tile, MP_STATION) && _m[tile].m5 == 0x52;
}
static inline bool TileBelongsToRailStation(const Station *st, TileIndex tile)
{
return IsTileType(tile, MP_STATION) && _m[tile].m2 == st->index && _m[tile].m5 < 8;
}
/* Get's the direction the station exit points towards. Ie, returns 0 for a
* station with the exit NE. */
static inline byte GetRoadStationDir(TileIndex tile)

View File

@@ -1065,6 +1065,11 @@ int32 CmdBuildRailroadStation(int x, int y, uint32 flags, uint32 p1, uint32 p2)
return cost;
}
static bool TileBelongsToRailStation(const Station *st, TileIndex tile)
{
return IsTileType(tile, MP_STATION) && _m[tile].m2 == st->index && _m[tile].m5 < 8;
}
static void MakeRailwayStationAreaSmaller(Station *st)
{
uint w = st->trainst_w;

View File

@@ -755,9 +755,6 @@ int32 CmdBuildRailVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2)
SetFrontEngine(v);
SetTrainEngine(v);
v->u.rail.shortest_platform[0] = 255;
v->u.rail.shortest_platform[1] = 0;
VehiclePositionChanged(v);
if (rvi->flags & RVI_MULTIHEAD) {
@@ -2427,27 +2424,6 @@ static bool ProcessTrainOrder(Vehicle *v)
v->dest_tile = 0;
// store the station length if no shorter station was visited this order round
if (v->cur_order_index == 0) {
if (v->u.rail.shortest_platform[1] != 0 && v->u.rail.shortest_platform[1] != 255) {
// we went though a whole round of orders without interruptions, so we store the length of the shortest station
v->u.rail.shortest_platform[0] = v->u.rail.shortest_platform[1];
}
// all platforms are shorter than 255, so now we can find the shortest in the next order round. They might have changed size
v->u.rail.shortest_platform[1] = 255;
}
if (v->last_station_visited != INVALID_STATION) {
Station *st = GetStation(v->last_station_visited);
if (TileBelongsToRailStation(st, v->tile)) {
byte length = GetStationPlatforms(st, v->tile);
if (length < v->u.rail.shortest_platform[1]) {
v->u.rail.shortest_platform[1] = length;
}
}
}
result = false;
switch (order->type) {
case OT_GOTO_STATION:

View File

@@ -1656,8 +1656,6 @@ static int32 ReplaceVehicle(Vehicle **w, byte flags)
if (GetNextVehicle(old_v) != NULL) {
DoCommand(0, 0, (new_v->index << 16) | GetNextVehicle(old_v)->index, 1, DC_EXEC, CMD_MOVE_RAIL_VEHICLE);
}
new_v->u.rail.shortest_platform[0] = old_v->u.rail.shortest_platform[0];
new_v->u.rail.shortest_platform[1] = old_v->u.rail.shortest_platform[1];
}
}
/* We are done setting up the new vehicle. Now we move the cargo from the old one to the new one */
@@ -1701,7 +1699,10 @@ static void MaybeReplaceVehicle(Vehicle *v)
byte flags = 0;
int32 cost, temp_cost = 0;
bool stopped = false;
bool train_fits_in_station = false;
/* Remember the length in case we need to trim train later on
* If it's not a train, the value is unused */
uint16 old_total_length = (v->type == VEH_Train) ? v->u.rail.cached_total_length : -1;
_current_player = v->owner;
@@ -1715,11 +1716,6 @@ static void MaybeReplaceVehicle(Vehicle *v)
stopped = true;
}
if (v->type == VEH_Train && v->u.rail.shortest_platform[0]*16 <= v->u.rail.cached_total_length && GetPlayer(v->owner)->renew_keep_length) {
// the train is not too long for the stations it visits. We should try to keep it that way if we change anything
train_fits_in_station = true;
}
for (;;) {
cost = 0;
w = v;
@@ -1781,11 +1777,12 @@ static void MaybeReplaceVehicle(Vehicle *v)
flags |= DC_EXEC;
}
if (train_fits_in_station) {
// the train fitted in the stations it got in it's orders, so we should make sure that it still do
/* If setting is on to try not to exceed the old length of the train with the replacement */
if (v->type == VEH_Train && p->renew_keep_length) {
Vehicle *temp;
w = v;
while (v->u.rail.shortest_platform[0]*16 < v->u.rail.cached_total_length) {
while (v->u.rail.cached_total_length > old_total_length) {
// the train is too long. We will remove cars one by one from the start of the train until it's short enough
while (w != NULL && !(RailVehInfo(w->engine_type)->flags&RVI_WAGON) ) {
w = GetNextVehicle(w);
@@ -2094,8 +2091,9 @@ static const SaveLoad _train_desc[] = {
SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleRail,pbs_status), SLE_UINT8, 2, 255),
SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleRail,pbs_end_tile), SLE_UINT32, 2, 255),
SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleRail,pbs_end_trackdir), SLE_UINT8, 2, 255),
SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleRail,shortest_platform[0]), SLE_UINT8, 2, 255), // added with 16.1, but was blank since 2
SLE_CONDVARX(offsetof(Vehicle,u)+offsetof(VehicleRail,shortest_platform[1]), SLE_UINT8, 2, 255), // added with 16.1, but was blank since 2
SLE_CONDARR(NullStruct, null, SLE_FILE_U8 | SLE_VAR_NULL, 2, 2, 255),
SLE_CONDREFX(offsetof(Vehicle,u)+offsetof(VehicleRail,other_multiheaded_part), REF_VEHICLE, 2, 255), // added with 17.1, but was blank since 2
// reserve extra space in savegame here. (currently 3 bytes)
SLE_CONDARR(NullStruct,null,SLE_FILE_U8 | SLE_VAR_NULL, 3, 2, 255),

View File

@@ -78,14 +78,6 @@ typedef struct VehicleRail {
TileIndex pbs_end_tile;
Trackdir pbs_end_trackdir;
/**
* stuff to figure out how long a train should be. Used by autoreplace
* first byte holds the length of the shortest station. Updated each time order 0 is reached
* last byte is the shortest station reached this round though the orders. It can be invalidated by
* skip station and alike by setting it to 0. That way we will ensure that a complete loop is used to find the shortest station
*/
byte shortest_platform[2];
// Link between the two ends of a multiheaded engine
Vehicle *other_multiheaded_part;
} VehicleRail;

View File

@@ -747,10 +747,10 @@ static void ReplaceVehicleWndProc(Window *w, WindowEvent *e)
STR_019E_SHIP,
STR_019D_AIRCRAFT
};
const Player *p = GetPlayer(_local_player);
switch (e->event) {
case WE_PAINT: {
const Player *p = GetPlayer(_local_player);
int pos = w->vscroll.pos;
EngineID selected_id[2] = { INVALID_ENGINE, INVALID_ENGINE };
int x = 1;
@@ -934,7 +934,7 @@ static void ReplaceVehicleWndProc(Window *w, WindowEvent *e)
break;
}
case 17: { /* toggle renew_keep_length */
DoCommandP(0, 5, p->renew_keep_length ? 0 : 1, NULL, CMD_REPLACE_VEHICLE);
DoCommandP(0, 5, GetPlayer(_local_player)->renew_keep_length ? 0 : 1, NULL, CMD_REPLACE_VEHICLE);
} break;
case 4: { /* Start replacing */
EngineID veh_from = WP(w, replaceveh_d).sel_engine[0];