--- a/src/autoreplace_cmd.cpp Mon Apr 14 20:32:36 2008 +0000
+++ b/src/autoreplace_cmd.cpp Tue Apr 15 00:47:19 2008 +0000
@@ -4,9 +4,8 @@
#include "openttd.h"
#include "roadveh.h"
#include "ship.h"
-#include "news.h"
+#include "news_func.h"
#include "player_func.h"
-#include "engine.h"
#include "debug.h"
#include "vehicle_gui.h"
#include "depot.h"
@@ -14,7 +13,6 @@
#include "aircraft.h"
#include "cargotype.h"
#include "group.h"
-#include "order.h"
#include "strings_func.h"
#include "command_func.h"
#include "vehicle_func.h"
@@ -73,9 +71,9 @@
}
FOR_VEHICLE_ORDERS(u, o) {
- if (!(o->refit_cargo < NUM_CARGO)) continue;
- if (!CanRefitTo(v->engine_type, o->refit_cargo)) continue;
- if (!CanRefitTo(engine_type, o->refit_cargo)) return false;
+ if (!o->IsRefit()) continue;
+ if (!CanRefitTo(v->engine_type, o->GetRefitCargo())) continue;
+ if (!CanRefitTo(engine_type, o->GetRefitCargo())) return false;
}
return true;
@@ -199,12 +197,21 @@
*/
/* Get the vehicle in front of the one we move out */
Vehicle *front = old_v->Previous();
- /* If the vehicle in front is the rear end of a dualheaded engine, then we need to use the one in front of that one */
- if (IsRearDualheaded(front)) front = front->Previous();
- /* Now we move the old one out of the train */
- DoCommand(0, (INVALID_VEHICLE << 16) | old_v->index, 0, DC_EXEC, CMD_MOVE_RAIL_VEHICLE);
- /* Add the new vehicle */
- DoCommand(0, (front->index << 16) | new_v->index, 1, DC_EXEC, CMD_MOVE_RAIL_VEHICLE);
+ if (front == NULL) {
+ /* It would appear that we have the front wagon of a row of wagons without engines */
+ Vehicle *next = old_v->Next();
+ if (next != NULL) {
+ /* Move the chain to the new front wagon */
+ DoCommand(0, (new_v->index << 16) | next->index, 1, DC_EXEC, CMD_MOVE_RAIL_VEHICLE);
+ }
+ } else {
+ /* If the vehicle in front is the rear end of a dualheaded engine, then we need to use the one in front of that one */
+ if (IsRearDualheaded(front)) front = front->Previous();
+ /* Now we move the old one out of the train */
+ DoCommand(0, (INVALID_VEHICLE << 16) | old_v->index, 0, DC_EXEC, CMD_MOVE_RAIL_VEHICLE);
+ /* Add the new vehicle */
+ DoCommand(0, (front->index << 16) | new_v->index, 1, DC_EXEC, CMD_MOVE_RAIL_VEHICLE);
+ }
} else {
// copy/clone the orders
DoCommand(0, (old_v->index << 16) | new_v->index, old_v->IsOrderListShared() ? CO_SHARE : CO_COPY, DC_EXEC, CMD_CLONE_ORDER);
@@ -368,7 +375,7 @@
default: NOT_REACHED(); message = 0; break;
}
- AddNewsItem(message, NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), v->index, 0);
+ AddNewsItem(message, NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, DNC_NONE, v->index, 0);
}
if (stopped) v->vehstatus &= ~VS_STOPPED;
if (display_costs) _current_player = OWNER_NONE;
@@ -399,7 +406,7 @@
if (w == NULL) {
// we failed to make the train short enough
SetDParam(0, v->unitnumber);
- AddNewsItem(STR_TRAIN_TOO_LONG_AFTER_REPLACEMENT, NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), v->index, 0);
+ AddNewsItem(STR_TRAIN_TOO_LONG_AFTER_REPLACEMENT, NM_SMALL, NF_VIEWPORT | NF_VEHICLE, NT_ADVICE, DNC_NONE, v->index, 0);
break;
}
temp = w;