ship_cmd.c
changeset 4451 66603f0f732e
parent 4412 945e8a9bb89a
child 4463 3a70624c40eb
equal deleted inserted replaced
4450:d64008e0af99 4451:66603f0f732e
   993 }
   993 }
   994 
   994 
   995 /** Send a ship to the depot.
   995 /** Send a ship to the depot.
   996  * @param tile unused
   996  * @param tile unused
   997  * @param p1 vehicle ID to send to the depot
   997  * @param p1 vehicle ID to send to the depot
   998  * @param p2 p2 if bit 0 is set, then the ship will only service at the depot. 0 Makes it stop inside
   998  * @param p2 various bitmasked elements
       
   999  * - p2 bit 0 - if bit 0 is set, then the ship will only service at the depot. 0 Makes it stop inside
       
  1000  * - p2 bit 1 - send all of shared orders to depot
   999  */
  1001  */
  1000 int32 CmdSendShipToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
  1002 int32 CmdSendShipToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
  1001 {
  1003 {
  1002 	Vehicle *v;
  1004 	Vehicle *v;
  1003 	const Depot *dep;
  1005 	const Depot *dep;
  1004 
  1006 	const int32 return_value = HASBIT(p2, 1) ? 0 : CMD_ERROR;
  1005 	if (!IsValidVehicleID(p1)) return CMD_ERROR;
  1007 
       
  1008 	if (!IsValidVehicleID(p1)) return return_value;
  1006 
  1009 
  1007 	v = GetVehicle(p1);
  1010 	v = GetVehicle(p1);
  1008 
  1011 
  1009 	if (v->type != VEH_Ship || !CheckOwnership(v->owner)) return CMD_ERROR;
  1012 	if (v->type != VEH_Ship || !CheckOwnership(v->owner)) return return_value;
  1010 
  1013 
  1011 	if (v->vehstatus & VS_CRASHED) return CMD_ERROR;
  1014 	if (HASBIT(p2, 1) && v->next_shared != NULL) CmdSendShipToDepot(tile, flags, v->next_shared->index, p2);
       
  1015 
       
  1016 	if (v->vehstatus & VS_CRASHED) return return_value;
  1012 
  1017 
  1013 	/* If the current orders are already goto-depot */
  1018 	/* If the current orders are already goto-depot */
  1014 	if (v->current_order.type == OT_GOTO_DEPOT) {
  1019 	if (v->current_order.type == OT_GOTO_DEPOT) {
  1015 		if (flags & DC_EXEC) {
  1020 		if (flags & DC_EXEC) {
       
  1021 			if (HASBIT(p2, 1)) return 0;	// Mass ordering goto depot should not turn goto depot orders off
  1016 			/* If the orders to 'goto depot' are in the orders list (forced servicing),
  1022 			/* If the orders to 'goto depot' are in the orders list (forced servicing),
  1017 			 * then skip to the next order; effectively cancelling this forced service */
  1023 			 * then skip to the next order; effectively cancelling this forced service */
  1018 			if (HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS))
  1024 			if (HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS))
  1019 				v->cur_order_index++;
  1025 				v->cur_order_index++;
  1020 
  1026 
  1024 		}
  1030 		}
  1025 		return 0;
  1031 		return 0;
  1026 	}
  1032 	}
  1027 
  1033 
  1028 	dep = FindClosestShipDepot(v);
  1034 	dep = FindClosestShipDepot(v);
  1029 	if (dep == NULL)
  1035 	if (dep == NULL) {
       
  1036 		if (HASBIT(p2, 1)) return 0;	// Mass ordering goto depot should not return error
  1030 		return_cmd_error(STR_981A_UNABLE_TO_FIND_LOCAL_DEPOT);
  1037 		return_cmd_error(STR_981A_UNABLE_TO_FIND_LOCAL_DEPOT);
       
  1038 	}
  1031 
  1039 
  1032 	if (flags & DC_EXEC) {
  1040 	if (flags & DC_EXEC) {
  1033 		v->dest_tile = dep->xy;
  1041 		v->dest_tile = dep->xy;
  1034 		v->current_order.type = OT_GOTO_DEPOT;
  1042 		v->current_order.type = OT_GOTO_DEPOT;
  1035 		v->current_order.flags = OF_NON_STOP;
  1043 		v->current_order.flags = OF_NON_STOP;