--- a/src/order_cmd.cpp Thu Sep 06 19:42:48 2007 +0000
+++ b/src/order_cmd.cpp Sat Oct 06 21:16:00 2007 +0000
@@ -19,6 +19,7 @@
#include "vehicle_gui.h"
#include "cargotype.h"
#include "strings.h"
+#include "aircraft.h"
DEFINE_OLD_POOL_GENERIC(Order, Order)
@@ -198,7 +199,9 @@
break;
case VEH_AIRCRAFT:
- if (!(st->facilities & FACIL_AIRPORT)) return CMD_ERROR;
+ if (!(st->facilities & FACIL_AIRPORT) || !CanAircraftUseStation(v->engine_type, st)) {
+ return CMD_ERROR;
+ }
break;
default: return CMD_ERROR;
@@ -239,7 +242,8 @@
if (!CheckOwnership(st->owner) ||
!(st->facilities & FACIL_AIRPORT) ||
- st->Airport()->num_depots == 0) {
+ st->Airport()->num_depots == 0 ||
+ !CanAircraftUseStation(v->engine_type, st)) {
return CMD_ERROR;
}
} else {
@@ -317,10 +321,6 @@
if (!HasOrderPoolFree(1)) return_cmd_error(STR_8831_NO_MORE_SPACE_FOR_ORDERS);
- /* XXX - This limit is only here because the backuppedorders can't
- * handle any more then this.. */
- if (v->num_orders >= MAX_BACKUP_ORDER_COUNT) return_cmd_error(STR_8832_TOO_MANY_ORDERS);
-
if (v->type == VEH_SHIP &&
IsHumanPlayer(v->owner) &&
!_patches.new_pathfinding_all) {
@@ -920,6 +920,10 @@
*/
void BackupVehicleOrders(const Vehicle *v, BackuppedOrders *bak)
{
+ /* Make sure we always have freed the stuff */
+ free(bak->order);
+ bak->order = NULL;
+
/* Save general info */
bak->orderindex = v->cur_order_index;
bak->service_interval = v->service_interval;
@@ -939,13 +943,21 @@
bak->clone = u->index;
} else {
/* Else copy the orders */
- Order *order, *dest;
-
- dest = bak->order;
/* We do not have shared orders */
bak->clone = INVALID_VEHICLE;
+
+ /* Count the number of orders */
+ uint cnt = 0;
+ const Order *order;
+ FOR_VEHICLE_ORDERS(v, order) cnt++;
+
+ /* Allocate memory for the orders plus an end-of-orders marker */
+ bak->order = MallocT<Order>(cnt + 1);
+
+ Order *dest = bak->order;
+
/* Copy the orders */
FOR_VEHICLE_ORDERS(v, order) {
*dest = *order;
@@ -961,12 +973,10 @@
* Restore vehicle orders that are backupped via BackupVehicleOrders
*
*/
-void RestoreVehicleOrders(const Vehicle* v, const BackuppedOrders* bak)
+void RestoreVehicleOrders(const Vehicle *v, const BackuppedOrders *bak)
{
- uint i;
-
/* If we have a custom name, process that */
- if (bak->name[0] != 0) {
+ if (!StrEmpty(bak->name)) {
_cmd_text = bak->name;
DoCommandP(0, v->index, 0, NULL, CMD_NAME_VEHICLE);
}
@@ -981,7 +991,7 @@
* order number is one more than the current amount of orders, and because
* in network the commands are queued before send, the second insert always
* fails in test mode. By bypassing the test-mode, that no longer is a problem. */
- for (i = 0; bak->order[i].IsValid(); i++) {
+ for (uint i = 0; bak->order[i].IsValid(); i++) {
if (!DoCommandP(0, v->index + (i << 16), PackOrder(&bak->order[i]), NULL, CMD_INSERT_ORDER | CMD_NO_TEST_IF_IN_NETWORK))
break;
}
@@ -1032,7 +1042,7 @@
switch (v->type) {
default: NOT_REACHED();
case VEH_TRAIN: return st->train_tile;
- case VEH_AIRCRAFT: return st->airport_tile;
+ case VEH_AIRCRAFT: return CanAircraftUseStation(v->engine_type, st) ? st->airport_tile : 0;
case VEH_SHIP: return st->dock_tile;
case VEH_ROAD:
if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) {