Changeset - r13755:bf4fbd1c24d2
[Not reviewed]
master
0 1 0
rubidium - 15 years ago 2009-11-25 22:58:28
rubidium@openttd.org
(svn r18290) -Codechange: be more strict about what vehicles may use timetables
1 file changed with 4 insertions and 3 deletions:
0 comments (0 inline, 0 general)
src/timetable_cmd.cpp
Show inline comments
 
@@ -58,25 +58,25 @@ static void ChangeTimetable(Vehicle *v, 
 
 *                      Travelling time if p1 bit 25 is set.
 
 * - p2 = (bit 16-31) - Waiting time if p1 bit 25 is set
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdChangeTimetable(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!_settings_game.order.timetabling) return CMD_ERROR;
 

	
 
	VehicleID veh = GB(p1, 0, 16);
 

	
 
	Vehicle *v = Vehicle::GetIfValid(veh);
 
	if (v == NULL || !CheckOwnership(v->owner)) return CMD_ERROR;
 
	if (v == NULL || !CheckOwnership(v->owner) || !v->IsPrimaryVehicle()) return CMD_ERROR;
 

	
 
	VehicleOrderID order_number = GB(p1, 16, 8);
 
	Order *order = v->GetOrder(order_number);
 
	if (order == NULL) return CMD_ERROR;
 

	
 
	bool packed_time = HasBit(p1, 25);
 
	bool is_journey = HasBit(p1, 24) || packed_time;
 

	
 
	int wait_time   = order->wait_time;
 
	int travel_time = order->travel_time;
 
	if (packed_time) {
 
		travel_time = GB(p2, 0, 16);
 
@@ -118,28 +118,29 @@ CommandCost CmdChangeTimetable(TileIndex
 
 * - p1 = (bit  0-15) - Vehicle with the orders to change.
 
 * @param p2 unused
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdSetVehicleOnTime(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!_settings_game.order.timetabling) return CMD_ERROR;
 

	
 
	VehicleID veh = GB(p1, 0, 16);
 

	
 
	Vehicle *v = Vehicle::GetIfValid(veh);
 
	if (v == NULL || !CheckOwnership(v->owner)) return CMD_ERROR;
 
	if (v == NULL || !CheckOwnership(v->owner) || !v->IsPrimaryVehicle()) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		v->lateness_counter = 0;
 
		SetWindowDirty(WC_VEHICLE_TIMETABLE, v->index);
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Start or stop filling the timetable automatically from the time the vehicle
 
 * actually takes to complete it. When starting to autofill the current times
 
 * are cleared and the timetable will start again from scratch.
 
 * @param tile Not used.
 
 * @param flags Operation to perform.
 
 * @param p1 Vehicle index.
 
@@ -147,25 +148,25 @@ CommandCost CmdSetVehicleOnTime(TileInde
 
 * - p2 = (bit 0) - Set to 1 to enable, 0 to disable autofill.
 
 * - p2 = (bit 1) - Set to 1 to preserve waiting times in non-destructive mode
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdAutofillTimetable(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!_settings_game.order.timetabling) return CMD_ERROR;
 

	
 
	VehicleID veh = GB(p1, 0, 16);
 

	
 
	Vehicle *v = Vehicle::GetIfValid(veh);
 
	if (v == NULL || !CheckOwnership(v->owner)) return CMD_ERROR;
 
	if (v == NULL || !CheckOwnership(v->owner) || !v->IsPrimaryVehicle()) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		if (HasBit(p2, 0)) {
 
			/* Start autofilling the timetable, which clears the
 
			 * "timetable has started" bit. Times are not cleared anymore, but are
 
			 * overwritten when the order is reached now. */
 
			SetBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE);
 
			ClrBit(v->vehicle_flags, VF_TIMETABLE_STARTED);
 

	
 
			/* Overwrite waiting times only if they got longer */
 
			if (HasBit(p2, 1)) SetBit(v->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME);
 

	
0 comments (0 inline, 0 general)