src/order_cmd.cpp
changeset 8881 ad608e8305ad
parent 8874 db064c1eb143
child 8883 baee554a9449
equal deleted inserted replaced
8880:5b12cb0d9819 8881:ad608e8305ad
    39 TileIndex _backup_orders_tile;
    39 TileIndex _backup_orders_tile;
    40 BackuppedOrders _backup_orders_data;
    40 BackuppedOrders _backup_orders_data;
    41 
    41 
    42 DEFINE_OLD_POOL_GENERIC(Order, Order);
    42 DEFINE_OLD_POOL_GENERIC(Order, Order);
    43 
    43 
    44 OrderLoadFlags Order::GetLoadType() const
       
    45 {
       
    46 	if ((this->flags & OLFB_FULL_LOAD) == 0) return OLF_LOAD_IF_POSSIBLE;
       
    47 	return _patches.full_load_any ? OLF_FULL_LOAD_ANY : OLFB_FULL_LOAD;
       
    48 }
       
    49 
       
    50 OrderNonStopFlags Order::GetNonStopType() const
       
    51 {
       
    52 	if (_patches.new_nonstop) {
       
    53 		return (this->flags & 0x08) ? ONSF_NO_STOP_AT_ANY_STATION : ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS;
       
    54 	}
       
    55 
       
    56 	return (this->flags & 0x08) ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE;
       
    57 }
       
    58 
       
    59 void Order::Free()
    44 void Order::Free()
    60 {
    45 {
    61 	this->type  = OT_NOTHING;
    46 	this->type  = OT_NOTHING;
    62 	this->flags = 0;
    47 	this->flags = 0;
    63 	this->dest  = 0;
    48 	this->dest  = 0;
   153 	this->next    = NULL;
   138 	this->next    = NULL;
   154 	this->refit_cargo   = CT_NO_REFIT;
   139 	this->refit_cargo   = CT_NO_REFIT;
   155 	this->refit_subtype = 0;
   140 	this->refit_subtype = 0;
   156 	this->wait_time     = 0;
   141 	this->wait_time     = 0;
   157 	this->travel_time   = 0;
   142 	this->travel_time   = 0;
       
   143 }
       
   144 
       
   145 void Order::ConvertFromOldSavegame()
       
   146 {
       
   147 	/* First handle non-stop, because those bits are going to be reused. */
       
   148 	if (_patches.sg_new_nonstop) {
       
   149 		this->SetNonStopType((this->flags & 0x08) ? ONSF_NO_STOP_AT_ANY_STATION : ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
       
   150 	} else {
       
   151 		this->SetNonStopType((this->flags & 0x08) ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
       
   152 	}
       
   153 
       
   154 	switch (this->GetType()) {
       
   155 		/* Only a few types need the other savegame conversions. */
       
   156 		case OT_GOTO_DEPOT: case OT_GOTO_STATION: case OT_LOADING: break;
       
   157 		default: return;
       
   158 	}
       
   159 
       
   160 	/* Then the load/depot action flags because those bits are going to be reused too
       
   161 	 * and they reuse the non-stop bits. */
       
   162 	if (this->GetType() != OT_GOTO_DEPOT) {
       
   163 		if ((this->flags & 4) == 0) {
       
   164 			this->SetLoadType(OLF_LOAD_IF_POSSIBLE);
       
   165 		} else {
       
   166 			this->SetLoadType(_patches.sg_full_load_any ? OLF_FULL_LOAD_ANY : OLFB_FULL_LOAD);
       
   167 		}
       
   168 	} else {
       
   169 		this->SetDepotActionType(((this->flags & 6) == 4) ? ODATFB_HALT : ODATF_SERVICE_ONLY);
       
   170 	}
       
   171 
       
   172 	/* Finally fix the unload/depot type flags. */
       
   173 	if (this->GetType() != OT_GOTO_DEPOT) {
       
   174 		uint t = ((this->flags & 1) == 0) ? OUF_UNLOAD_IF_POSSIBLE : OUFB_TRANSFER;
       
   175 		if ((this->flags & 2) != 0) t |= OUFB_UNLOAD;
       
   176 		this->SetUnloadType((OrderUnloadFlags)t);
       
   177 	} else {
       
   178 		uint t = ((this->flags & 6) == 6) ? ODTFB_SERVICE : ODTF_MANUAL;
       
   179 		if ((this->flags & 2) != 0) t |= ODTFB_PART_OF_ORDERS;
       
   180 		this->SetDepotOrderType((OrderDepotTypeFlags)t);
       
   181 	}
   158 }
   182 }
   159 
   183 
   160 /**
   184 /**
   161  *
   185  *
   162  * Unpacks a order from savegames with version 4 and lower
   186  * Unpacks a order from savegames with version 4 and lower
   320 
   344 
   321 				default: return CMD_ERROR;
   345 				default: return CMD_ERROR;
   322 			}
   346 			}
   323 
   347 
   324 			/* Non stop not allowed for non-trains. */
   348 			/* Non stop not allowed for non-trains. */
   325 			// TODO: implement properly once savegame bump is done. if ((new_order.GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) != 0 && v->type != VEH_TRAIN) return CMD_ERROR;
   349 			if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && v->type != VEH_TRAIN) return CMD_ERROR;
   326 
   350 
   327 			/* Full load and unload are mutual exclusive. */
   351 			/* Full load and unload are mutual exclusive. */
   328 			if ((new_order.GetLoadType() & OLFB_FULL_LOAD) && (new_order.GetUnloadType() & OUFB_UNLOAD)) return CMD_ERROR;
   352 			if ((new_order.GetLoadType() & OLFB_FULL_LOAD) && (new_order.GetUnloadType() & OUFB_UNLOAD)) return CMD_ERROR;
   329 
   353 
   330 			/* Filter invalid load/unload types. */
   354 			/* Filter invalid load/unload types. */
   370 
   394 
   371 					default: return CMD_ERROR;
   395 					default: return CMD_ERROR;
   372 				}
   396 				}
   373 			}
   397 			}
   374 
   398 
   375 			// TODO: implement properly once savegame bump is done. if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && v->type != VEH_TRAIN) return CMD_ERROR;
   399 			if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && v->type != VEH_TRAIN) return CMD_ERROR;
   376 			if (new_order.GetDepotOrderType() & ~ODTFB_PART_OF_ORDERS) return CMD_ERROR;
   400 			if (new_order.GetDepotOrderType() & ~ODTFB_PART_OF_ORDERS) return CMD_ERROR;
   377 			if (new_order.GetDepotActionType() & ~ODATFB_HALT) return CMD_ERROR;
   401 			if (new_order.GetDepotActionType() & ~ODATFB_HALT) return CMD_ERROR;
   378 			break;
   402 			break;
   379 		}
   403 		}
   380 
   404 
   388 			if (!CheckOwnership(GetTileOwner(wp->xy))) return CMD_ERROR;
   412 			if (!CheckOwnership(GetTileOwner(wp->xy))) return CMD_ERROR;
   389 
   413 
   390 			/* Order flags can be any of the following for waypoints:
   414 			/* Order flags can be any of the following for waypoints:
   391 			 * [non-stop]
   415 			 * [non-stop]
   392 			 * non-stop orders (if any) are only valid for trains */
   416 			 * non-stop orders (if any) are only valid for trains */
   393 			// TODO: implement properly once savegame bump is done. if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && v->type != VEH_TRAIN) return CMD_ERROR;
   417 			if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && v->type != VEH_TRAIN) return CMD_ERROR;
   394 
       
   395 			break;
   418 			break;
   396 		}
   419 		}
   397 
   420 
   398 		default: return CMD_ERROR;
   421 		default: return CMD_ERROR;
   399 	}
   422 	}
   776 			if ((data & ~(OUFB_UNLOAD | OUFB_TRANSFER)) != 0) return CMD_ERROR;
   799 			if ((data & ~(OUFB_UNLOAD | OUFB_TRANSFER)) != 0) return CMD_ERROR;
   777 			if (data == order->GetUnloadType()) return CMD_ERROR;
   800 			if (data == order->GetUnloadType()) return CMD_ERROR;
   778 			break;
   801 			break;
   779 
   802 
   780 		case MOF_LOAD:
   803 		case MOF_LOAD:
   781 			if ((data & ~OLFB_FULL_LOAD) != 0) return CMD_ERROR;
   804 			if (data > OLF_FULL_LOAD_ANY || data == 1) return CMD_ERROR;
   782 			if (data == order->GetLoadType()) return CMD_ERROR;
   805 			if (data == order->GetLoadType()) return CMD_ERROR;
   783 			break;
   806 			break;
   784 
   807 
   785 		case MOF_DEPOT_ACTION:
   808 		case MOF_DEPOT_ACTION:
   786 			if (data != 0) return CMD_ERROR;
   809 			if (data != 0) return CMD_ERROR;