src/ai/api/ai_order.hpp
branchnoai
changeset 11029 776c7cc8bda5
parent 10844 affb2821fb9f
equal deleted inserted replaced
11027:d1ab0da686d1 11029:776c7cc8bda5
    67 
    67 
    68 		/** For marking invalid order flags */
    68 		/** For marking invalid order flags */
    69 		AIOF_INVALID           = 0xFFFF,
    69 		AIOF_INVALID           = 0xFFFF,
    70 	};
    70 	};
    71 
    71 
       
    72 	/** Different constants related to the OrderPosition */
       
    73 	enum OrderPosition {
       
    74 		CURRENT_ORDER = 0xFF, //!< Constant that gets resolved to the current order.
       
    75 		INVALID_ORDER = -1,   //!< An invalid order.
       
    76 	};
       
    77 
    72 	/**
    78 	/**
    73 	 * Checks whether the given order id is valid for the given vehicle.
    79 	 * Checks whether the given order id is valid for the given vehicle.
    74 	 * @param vehicle_id The vehicle to check the order index for.
    80 	 * @param vehicle_id The vehicle to check the order index for.
    75 	 * @param order_id The order index to check.
    81 	 * @param order_position The order index to check.
    76 	 * @pre AIVehicle::IsValidVehicle(vehicle_id).
    82 	 * @pre AIVehicle::IsValidVehicle(vehicle_id).
    77 	 * @return True if and only if the order_id is valid for the given vehicle.
    83 	 * @return True if and only if the order_position is valid for the given vehicle.
    78 	 */
    84 	 */
    79 	static bool IsValidVehicleOrder(VehicleID vehicle_id, uint32 order_id);
    85 	static bool IsValidVehicleOrder(VehicleID vehicle_id, OrderPosition order_position);
       
    86 
       
    87 	/**
       
    88 	 * Resolves the given order index to the correct index for the given vehicle.
       
    89 	 *  If the order index was CURRENT_ORDER it will be resolved to the index of
       
    90 	 *  the current order (as shown in the order list). If the order with the
       
    91 	 *  given index does not exist it will return INVALID_ORDER.
       
    92 	 * @param vehicle_id The vehicle to check the order index for.
       
    93 	 * @param order_position The order index to resolve.
       
    94 	 * @pre AIVehicle::IsValidVehicle(vehicle_id).
       
    95 	 * @return The resolved order index.
       
    96 	 */
       
    97 	static OrderPosition ResolveOrderPosition(VehicleID vehicle_id, OrderPosition order_position);
    80 
    98 
    81 	/**
    99 	/**
    82 	 * Checks whether the given order flags are valid for the given destination.
   100 	 * Checks whether the given order flags are valid for the given destination.
    83 	 * @param destination The destination of the order.
   101 	 * @param destination The destination of the order.
    84 	 * @param order_flags The flags given to the order.
   102 	 * @param order_flags The flags given to the order.
    96 	static int32 GetOrderCount(VehicleID vehicle_id);
   114 	static int32 GetOrderCount(VehicleID vehicle_id);
    97 
   115 
    98 	/**
   116 	/**
    99 	 * Gets the destination of the given order for the given vehicle.
   117 	 * Gets the destination of the given order for the given vehicle.
   100 	 * @param vehicle_id The vehicle to get the destination for.
   118 	 * @param vehicle_id The vehicle to get the destination for.
   101 	 * @param order_id The order to get the destination for.
   119 	 * @param order_position The order to get the destination for.
   102 	 * @pre IsValidVehicleOrder(vehicle_id, order_id).
   120 	 * @pre IsValidVehicleOrder(vehicle_id, order_position).
       
   121 	 * @note Giving CURRENT_ORDER as order_position will give the order that is
       
   122 	 *  currently being executed by the vehicle. This is not necessarily the
       
   123 	 *  current order as given by ResolveOrderPosition (the current index in the
       
   124 	 *  order list) as manual or autoservicing depot orders do not show up
       
   125 	 *  in the orderlist, but they can be the current order of a vehicle.
   103 	 * @return The destination tile of the order.
   126 	 * @return The destination tile of the order.
   104 	 */
   127 	 */
   105 	static TileIndex GetOrderDestination(VehicleID vehicle_id, uint32 order_id);
   128 	static TileIndex GetOrderDestination(VehicleID vehicle_id, OrderPosition order_position);
   106 
   129 
   107 	/**
   130 	/**
   108 	 * Gets the AIOrderFlags of the given order for the given vehicle.
   131 	 * Gets the AIOrderFlags of the given order for the given vehicle.
   109 	 * @param vehicle_id The vehicle to get the destination for.
   132 	 * @param vehicle_id The vehicle to get the destination for.
   110 	 * @param order_id The order to get the destination for.
   133 	 * @param order_position The order to get the destination for.
   111 	 * @pre IsValidVehicleOrder(vehicle_id, order_id).
   134 	 * @pre IsValidVehicleOrder(vehicle_id, order_position).
       
   135 	 * @note Giving CURRENT_ORDER as order_position will give the order that is
       
   136 	 *  currently being executed by the vehicle. This is not necessarily the
       
   137 	 *  current order as given by ResolveOrderPosition (the current index in the
       
   138 	 *  order list) as manual or autoservicing depot orders do not show up
       
   139 	 *  in the orderlist, but they can be the current order of a vehicle.
   112 	 * @return The AIOrderFlags of the order.
   140 	 * @return The AIOrderFlags of the order.
   113 	 */
   141 	 */
   114 	static AIOrderFlags GetOrderFlags(VehicleID vehicle_id, uint32 order_id);
   142 	static AIOrderFlags GetOrderFlags(VehicleID vehicle_id, OrderPosition order_position);
   115 
   143 
   116 	/**
   144 	/**
   117 	 * Appends an order to the end of the vehicle's order list.
   145 	 * Appends an order to the end of the vehicle's order list.
   118 	 * @param vehicle_id The vehicle to append the order to.
   146 	 * @param vehicle_id The vehicle to append the order to.
   119 	 * @param destination The destination of the order.
   147 	 * @param destination The destination of the order.
   126 	 * @return True if and only if the order was appended.
   154 	 * @return True if and only if the order was appended.
   127 	 */
   155 	 */
   128 	static bool AppendOrder(VehicleID vehicle_id, TileIndex destination, AIOrderFlags order_flags);
   156 	static bool AppendOrder(VehicleID vehicle_id, TileIndex destination, AIOrderFlags order_flags);
   129 
   157 
   130 	/**
   158 	/**
   131 	 * Inserts an order before the given order_id into the vehicle's order list.
   159 	 * Inserts an order before the given order_position into the vehicle's order list.
   132 	 * @param vehicle_id The vehicle to add the order to.
   160 	 * @param vehicle_id The vehicle to add the order to.
   133 	 * @param order_id The order to place the new order before.
   161 	 * @param order_position The order to place the new order before.
   134 	 * @param destination The destination of the order.
   162 	 * @param destination The destination of the order.
   135 	 * @param order_flags The flags given to the order.
   163 	 * @param order_flags The flags given to the order.
   136 	 * @pre IsValidVehicleOrder(vehicle_id, order_id).
   164 	 * @pre IsValidVehicleOrder(vehicle_id, order_position).
   137 	 * @pre AreOrderFlagsValid(destination, order_flags).
   165 	 * @pre AreOrderFlagsValid(destination, order_flags).
   138 	 * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY
   166 	 * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY
   139 	 * @exception AIOrder::ERR_ORDER_NO_MORE_SPACE
   167 	 * @exception AIOrder::ERR_ORDER_NO_MORE_SPACE
   140 	 * @exception AIOrder::ERR_ORDER_TOO_FAR_AWAY_FROM_PREVIOUS_DESTINATION
   168 	 * @exception AIOrder::ERR_ORDER_TOO_FAR_AWAY_FROM_PREVIOUS_DESTINATION
   141 	 * @return True if and only if the order was inserted.
   169 	 * @return True if and only if the order was inserted.
   142 	 */
   170 	 */
   143 	static bool InsertOrder(VehicleID vehicle_id, uint32 order_id, TileIndex destination, AIOrderFlags order_flags);
   171 	static bool InsertOrder(VehicleID vehicle_id, OrderPosition order_position, TileIndex destination, AIOrderFlags order_flags);
   144 
   172 
   145 	/**
   173 	/**
   146 	 * Removes an order from the vehicle's order list.
   174 	 * Removes an order from the vehicle's order list.
   147 	 * @param vehicle_id The vehicle to remove the order from.
   175 	 * @param vehicle_id The vehicle to remove the order from.
   148 	 * @param order_id The order to remove from the order list.
   176 	 * @param order_position The order to remove from the order list.
   149 	 * @pre AIVehicle::IsValidVehicleOrder(vehicle_id, order_id).
   177 	 * @pre AIVehicle::IsValidVehicleOrder(vehicle_id, order_position).
   150 	 * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY
   178 	 * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY
   151 	 * @return True if and only if the order was removed.
   179 	 * @return True if and only if the order was removed.
   152 	 */
   180 	 */
   153 	static bool RemoveOrder(VehicleID vehicle_id, uint32 order_id);
   181 	static bool RemoveOrder(VehicleID vehicle_id, OrderPosition order_position);
   154 
   182 
   155 	/**
   183 	/**
   156 	 * Changes the order flags of the given order.
   184 	 * Changes the order flags of the given order.
   157 	 * @param vehicle_id The vehicle to change the order of.
   185 	 * @param vehicle_id The vehicle to change the order of.
   158 	 * @param order_id The order to change.
   186 	 * @param order_position The order to change.
   159 	 * @param order_flags The new flags given to the order.
   187 	 * @param order_flags The new flags given to the order.
   160 	 * @pre IsValidVehicleOrder(vehicle_id, order_id).
   188 	 * @pre IsValidVehicleOrder(vehicle_id, order_position).
   161 	 * @pre AreOrderFlagsValid(GetOrderDestination(vehicle_id, order_id), order_flags).
   189 	 * @pre AreOrderFlagsValid(GetOrderDestination(vehicle_id, order_position), order_flags).
   162 	 * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY
   190 	 * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY
   163 	 * @return True if and only if the order was changed.
   191 	 * @return True if and only if the order was changed.
   164 	 */
   192 	 */
   165 	static bool ChangeOrder(VehicleID vehicle_id, uint32 order_id, AIOrderFlags order_flags);
   193 	static bool ChangeOrder(VehicleID vehicle_id, OrderPosition order_position, AIOrderFlags order_flags);
   166 
   194 
   167 	/**
   195 	/**
   168 	 * Move an order inside the orderlist
   196 	 * Move an order inside the orderlist
   169 	 * @param vehicle_id The vehicle to move the orders.
   197 	 * @param vehicle_id The vehicle to move the orders.
   170 	 * @param order_id_move The order to move.
   198 	 * @param order_position_move The order to move.
   171 	 * @param order_id_target The target order
   199 	 * @param order_position_target The target order
   172 	 * @pre IsValidVehicleOrder(vehicle_id, order_id_move).
   200 	 * @pre IsValidVehicleOrder(vehicle_id, order_position_move).
   173 	 * @pre IsValidVehicleOrder(vehicle_id, order_id_target).
   201 	 * @pre IsValidVehicleOrder(vehicle_id, order_position_target).
   174 	 * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY
   202 	 * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY
   175 	 * @return True if and only if the order was moved.
   203 	 * @return True if and only if the order was moved.
   176 	 * @note If the order is moved to a lower place (e.g. from 7 to 2)
   204 	 * @note If the order is moved to a lower place (e.g. from 7 to 2)
   177 	 *  the target order is moved upwards (e.g. 3). If the order is moved
   205 	 *  the target order is moved upwards (e.g. 3). If the order is moved
   178 	 *  to a higher place (e.g. from 7 to 9) the target will be moved
   206 	 *  to a higher place (e.g. from 7 to 9) the target will be moved
   179 	 *  downwards (e.g. 8).
   207 	 *  downwards (e.g. 8).
   180 	 */
   208 	 */
   181 	static bool MoveOrder(VehicleID vehicle_id, uint32 order_id_move, uint32 order_id_target);
   209 	static bool MoveOrder(VehicleID vehicle_id, OrderPosition order_position_move, OrderPosition order_position_target);
   182 
   210 
   183 	/**
   211 	/**
   184 	 * Copies the orders from another vehicle. The orders of the main vehicle
   212 	 * Copies the orders from another vehicle. The orders of the main vehicle
   185 	 *  are going to be the orders of the changed vehicle.
   213 	 *  are going to be the orders of the changed vehicle.
   186 	 * @param vehicle_id The vehicle to copy the orders to.
   214 	 * @param vehicle_id The vehicle to copy the orders to.