order_cmd.c
changeset 3491 35d747bb5e82
parent 3222 6de22e06a1e9
child 3585 43461f26b729
equal deleted inserted replaced
3490:d53bc3e794bd 3491:35d747bb5e82
   158 	DeleteVehicleNews(v->index, STR_TRAIN_HAS_INVALID_ENTRY   + (v->type - VEH_Train) * 4);
   158 	DeleteVehicleNews(v->index, STR_TRAIN_HAS_INVALID_ENTRY   + (v->type - VEH_Train) * 4);
   159 }
   159 }
   160 
   160 
   161 
   161 
   162 /** Add an order to the orderlist of a vehicle.
   162 /** Add an order to the orderlist of a vehicle.
   163  * @param x,y unused
   163  * @param tile unused
   164  * @param p1 various bitstuffed elements
   164  * @param p1 various bitstuffed elements
   165  * - p1 = (bit  0 - 15) - ID of the vehicle
   165  * - p1 = (bit  0 - 15) - ID of the vehicle
   166  * - p1 = (bit 16 - 31) - the selected order (if any). If the last order is given,
   166  * - p1 = (bit 16 - 31) - the selected order (if any). If the last order is given,
   167  *                        the order will be inserted before that one
   167  *                        the order will be inserted before that one
   168  *                        only the first 8 bits used currently (bit 16 - 23) (max 255)
   168  *                        only the first 8 bits used currently (bit 16 - 23) (max 255)
   169  * @param p2 packed order to insert
   169  * @param p2 packed order to insert
   170  */
   170  */
   171 int32 CmdInsertOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2)
   171 int32 CmdInsertOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   172 {
   172 {
   173 	Vehicle *v;
   173 	Vehicle *v;
   174 	VehicleID veh   = GB(p1,  0, 16);
   174 	VehicleID veh   = GB(p1,  0, 16);
   175 	OrderID sel_ord = GB(p1, 16, 16);
   175 	OrderID sel_ord = GB(p1, 16, 16);
   176 	Order new_order = UnpackOrder(p2);
   176 	Order new_order = UnpackOrder(p2);
   425 	}
   425 	}
   426 	return 0;
   426 	return 0;
   427 }
   427 }
   428 
   428 
   429 /** Delete an order from the orderlist of a vehicle.
   429 /** Delete an order from the orderlist of a vehicle.
   430  * @param x,y unused
   430  * @param tile unused
   431  * @param p1 the ID of the vehicle
   431  * @param p1 the ID of the vehicle
   432  * @param p2 the order to delete (max 255)
   432  * @param p2 the order to delete (max 255)
   433  */
   433  */
   434 int32 CmdDeleteOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2)
   434 int32 CmdDeleteOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   435 {
   435 {
   436 	Vehicle *v, *u;
   436 	Vehicle *v, *u;
   437 	VehicleID veh_id = p1;
   437 	VehicleID veh_id = p1;
   438 	OrderID sel_ord = p2;
   438 	OrderID sel_ord = p2;
   439 	Order *order;
   439 	Order *order;
   499 
   499 
   500 	return 0;
   500 	return 0;
   501 }
   501 }
   502 
   502 
   503 /** Goto next order of order-list.
   503 /** Goto next order of order-list.
   504  * @param x,y unused
   504  * @param tile unused
   505  * @param p1 The ID of the vehicle which order is skipped
   505  * @param p1 The ID of the vehicle which order is skipped
   506  * @param p2 unused
   506  * @param p2 unused
   507  */
   507  */
   508 int32 CmdSkipOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2)
   508 int32 CmdSkipOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   509 {
   509 {
   510 	Vehicle *v;
   510 	Vehicle *v;
   511 	VehicleID veh_id = p1;
   511 	VehicleID veh_id = p1;
   512 
   512 
   513 	if (!IsVehicleIndex(veh_id)) return CMD_ERROR;
   513 	if (!IsVehicleIndex(veh_id)) return CMD_ERROR;
   540 	return 0;
   540 	return 0;
   541 }
   541 }
   542 
   542 
   543 
   543 
   544 /** Modify an order in the orderlist of a vehicle.
   544 /** Modify an order in the orderlist of a vehicle.
   545  * @param x,y unused
   545  * @param tile unused
   546  * @param p1 various bitstuffed elements
   546  * @param p1 various bitstuffed elements
   547  * - p1 = (bit  0 - 15) - ID of the vehicle
   547  * - p1 = (bit  0 - 15) - ID of the vehicle
   548  * - p1 = (bit 16 - 31) - the selected order (if any). If the last order is given,
   548  * - p1 = (bit 16 - 31) - the selected order (if any). If the last order is given,
   549  *                        the order will be inserted before that one
   549  *                        the order will be inserted before that one
   550  *                        only the first 8 bits used currently (bit 16 - 23) (max 255)
   550  *                        only the first 8 bits used currently (bit 16 - 23) (max 255)
   551  * @param p2 mode to change the order to (always set)
   551  * @param p2 mode to change the order to (always set)
   552  */
   552  */
   553 int32 CmdModifyOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2)
   553 int32 CmdModifyOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   554 {
   554 {
   555 	Vehicle *v;
   555 	Vehicle *v;
   556 	Order *order;
   556 	Order *order;
   557 	OrderID sel_ord = GB(p1, 16, 16); // XXX - automatically truncated to 8 bits.
   557 	OrderID sel_ord = GB(p1, 16, 16); // XXX - automatically truncated to 8 bits.
   558 	VehicleID veh   = GB(p1,  0, 16);
   558 	VehicleID veh   = GB(p1,  0, 16);
   615  * @param p1 various bitstuffed elements
   615  * @param p1 various bitstuffed elements
   616  * - p1 = (bit  0-15) - destination vehicle to clone orders to (p1 & 0xFFFF)
   616  * - p1 = (bit  0-15) - destination vehicle to clone orders to (p1 & 0xFFFF)
   617  * - p1 = (bit 16-31) - source vehicle to clone orders from, if any (none for CO_UNSHARE)
   617  * - p1 = (bit 16-31) - source vehicle to clone orders from, if any (none for CO_UNSHARE)
   618  * @param p2 mode of cloning: CO_SHARE, CO_COPY, or CO_UNSHARE
   618  * @param p2 mode of cloning: CO_SHARE, CO_COPY, or CO_UNSHARE
   619  */
   619  */
   620 int32 CmdCloneOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2)
   620 int32 CmdCloneOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   621 {
   621 {
   622 	Vehicle *dst;
   622 	Vehicle *dst;
   623 	VehicleID veh_src = GB(p1, 16, 16);
   623 	VehicleID veh_src = GB(p1, 16, 16);
   624 	VehicleID veh_dst = GB(p1,  0, 16);
   624 	VehicleID veh_dst = GB(p1,  0, 16);
   625 
   625 
   819 	/* Restore vehicle order-index and service interval */
   819 	/* Restore vehicle order-index and service interval */
   820 	DoCommandP(0, v->index, bak->orderindex | (bak->service_interval << 16) , NULL, CMD_RESTORE_ORDER_INDEX);
   820 	DoCommandP(0, v->index, bak->orderindex | (bak->service_interval << 16) , NULL, CMD_RESTORE_ORDER_INDEX);
   821 }
   821 }
   822 
   822 
   823 /** Restore the current order-index of a vehicle and sets service-interval.
   823 /** Restore the current order-index of a vehicle and sets service-interval.
   824  * @param x,y unused
   824  * @param tile unused
   825  * @param p1 the ID of the vehicle
   825  * @param p1 the ID of the vehicle
   826  * @param p2 various bistuffed elements
   826  * @param p2 various bistuffed elements
   827  * - p2 = (bit  0-15) - current order-index (p2 & 0xFFFF)
   827  * - p2 = (bit  0-15) - current order-index (p2 & 0xFFFF)
   828  * - p2 = (bit 16-31) - service interval (p2 >> 16)
   828  * - p2 = (bit 16-31) - service interval (p2 >> 16)
   829  * @todo Unfortunately you cannot safely restore the unitnumber or the old vehicle
   829  * @todo Unfortunately you cannot safely restore the unitnumber or the old vehicle
   831  * but we have no way of seeing it has been tampered with or not, as we have no
   831  * but we have no way of seeing it has been tampered with or not, as we have no
   832  * legit way of knowing what that ID was.@n
   832  * legit way of knowing what that ID was.@n
   833  * If we do want to backup/restore it, just add UnitID uid to BackuppedOrders, and
   833  * If we do want to backup/restore it, just add UnitID uid to BackuppedOrders, and
   834  * restore it as parameter 'y' (ugly hack I know) for example. "v->unitnumber = y;"
   834  * restore it as parameter 'y' (ugly hack I know) for example. "v->unitnumber = y;"
   835  */
   835  */
   836 int32 CmdRestoreOrderIndex(int x, int y, uint32 flags, uint32 p1, uint32 p2)
   836 int32 CmdRestoreOrderIndex(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   837 {
   837 {
   838 	Vehicle *v;
   838 	Vehicle *v;
   839 	OrderID cur_ord = GB(p2,  0, 16);
   839 	OrderID cur_ord = GB(p2,  0, 16);
   840 	uint16 serv_int = GB(p2, 16, 16);
   840 	uint16 serv_int = GB(p2, 16, 16);
   841 
   841