src/timetable_cmd.cpp
branchnoai
changeset 9722 ebf0ece7d8f6
parent 9629 66dde6412125
child 6872 1c4a4a609f85
child 9723 eee46cb39750
equal deleted inserted replaced
9721:9a27928bcd5e 9722:ebf0ece7d8f6
    21 		order->travel_time = time;
    21 		order->travel_time = time;
    22 	} else {
    22 	} else {
    23 		order->wait_time = time;
    23 		order->wait_time = time;
    24 	}
    24 	}
    25 
    25 
    26 	if (v->cur_order_index == order_number && HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS)) {
    26 	if (v->cur_order_index == order_number && HasBit(v->current_order.flags, OFB_PART_OF_ORDERS)) {
    27 		if (is_journey) {
    27 		if (is_journey) {
    28 			v->current_order.travel_time = time;
    28 			v->current_order.travel_time = time;
    29 		} else {
    29 		} else {
    30 			v->current_order.wait_time = time;
    30 			v->current_order.wait_time = time;
    31 		}
    31 		}
    32 	}
    32 	}
    33 
    33 
    34 	InvalidateWindow(WC_VEHICLE_TIMETABLE, v->index);
    34 	for (v = GetFirstVehicleFromSharedList(v); v != NULL; v = v->next_shared) {
       
    35 		InvalidateWindow(WC_VEHICLE_TIMETABLE, v->index);
       
    36 	}
    35 }
    37 }
    36 
    38 
    37 /**
    39 /**
    38  * Add or remove waiting times from an order.
    40  * Add or remove waiting times from an order.
    39  * @param tile Not used.
    41  * @param tile Not used.
    57 
    59 
    58 	VehicleOrderID order_number = GB(p1, 16, 8);
    60 	VehicleOrderID order_number = GB(p1, 16, 8);
    59 	Order *order = GetVehicleOrder(v, order_number);
    61 	Order *order = GetVehicleOrder(v, order_number);
    60 	if (order == NULL) return CMD_ERROR;
    62 	if (order == NULL) return CMD_ERROR;
    61 
    63 
    62 	bool is_journey = HASBIT(p1, 24);
    64 	bool is_journey = HasBit(p1, 24);
    63 	if (!is_journey) {
    65 	if (!is_journey) {
    64 		if (order->type != OT_GOTO_STATION) return_cmd_error(STR_TIMETABLE_ONLY_WAIT_AT_STATIONS);
    66 		if (order->type != OT_GOTO_STATION) return_cmd_error(STR_TIMETABLE_ONLY_WAIT_AT_STATIONS);
    65 		if (_patches.new_nonstop && (order->flags & OF_NON_STOP)) return_cmd_error(STR_TIMETABLE_NOT_STOPPING_HERE);
    67 		if (_patches.new_nonstop && (order->flags & OF_NON_STOP)) return_cmd_error(STR_TIMETABLE_NOT_STOPPING_HERE);
    66 	}
    68 	}
    67 
    69 
   117 
   119 
   118 	if (flags & DC_EXEC) {
   120 	if (flags & DC_EXEC) {
   119 		if (p2 == 1) {
   121 		if (p2 == 1) {
   120 			/* Start autofilling the timetable, which clears all the current
   122 			/* Start autofilling the timetable, which clears all the current
   121 			 * timings and clears the "timetable has started" bit. */
   123 			 * timings and clears the "timetable has started" bit. */
   122 			SETBIT(v->vehicle_flags, VF_AUTOFILL_TIMETABLE);
   124 			SetBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE);
   123 			CLRBIT(v->vehicle_flags, VF_TIMETABLE_STARTED);
   125 			ClrBit(v->vehicle_flags, VF_TIMETABLE_STARTED);
   124 
   126 
   125 			for (Order *order = GetVehicleOrder(v, 0); order != NULL; order = order->next) {
   127 			for (Order *order = GetVehicleOrder(v, 0); order != NULL; order = order->next) {
   126 				order->wait_time = 0;
   128 				order->wait_time = 0;
   127 				order->travel_time = 0;
   129 				order->travel_time = 0;
   128 			}
   130 			}
   129 
   131 
   130 			v->current_order.wait_time = 0;
   132 			v->current_order.wait_time = 0;
   131 			v->current_order.travel_time = 0;
   133 			v->current_order.travel_time = 0;
   132 		} else {
   134 		} else {
   133 			CLRBIT(v->vehicle_flags, VF_AUTOFILL_TIMETABLE);
   135 			ClrBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE);
   134 		}
   136 		}
       
   137 	}
       
   138 
       
   139 	for (v = GetFirstVehicleFromSharedList(v); v != NULL; v = v->next_shared) {
       
   140 		InvalidateWindow(WC_VEHICLE_TIMETABLE, v->index);
   135 	}
   141 	}
   136 
   142 
   137 	return CommandCost();
   143 	return CommandCost();
   138 }
   144 }
   139 
   145 
   146 
   152 
   147 	if (!_patches.timetabling) return;
   153 	if (!_patches.timetabling) return;
   148 
   154 
   149 	/* Make sure the timetable only starts when the vehicle reaches the first
   155 	/* Make sure the timetable only starts when the vehicle reaches the first
   150  	 * order, not when travelling from the depot to the first station. */
   156  	 * order, not when travelling from the depot to the first station. */
   151  	if (v->cur_order_index == 0 && !HASBIT(v->vehicle_flags, VF_TIMETABLE_STARTED)) {
   157  	if (v->cur_order_index == 0 && !HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED)) {
   152  		SETBIT(v->vehicle_flags, VF_TIMETABLE_STARTED);
   158  		SetBit(v->vehicle_flags, VF_TIMETABLE_STARTED);
   153  		return;
   159  		return;
   154  	}
   160  	}
   155 
   161 
   156 	if (!HASBIT(v->vehicle_flags, VF_TIMETABLE_STARTED)) return;
   162 	if (!HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED)) return;
   157 
   163 
   158  	if (HASBIT(v->vehicle_flags, VF_AUTOFILL_TIMETABLE)) {
   164  	if (HasBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE)) {
   159 		if (timetabled == 0) {
   165 		if (timetabled == 0) {
   160 			/* Round the time taken up to the nearest day, as this will avoid
   166 			/* Round the time taken up to the nearest day, as this will avoid
   161 			 * confusion for people who are timetabling in days, and can be
   167 			 * confusion for people who are timetabling in days, and can be
   162 			 * adjusted later by people who aren't. */
   168 			 * adjusted later by people who aren't. */
   163 			time_taken = (((time_taken - 1) / DAY_TICKS) + 1) * DAY_TICKS;
   169 			time_taken = (((time_taken - 1) / DAY_TICKS) + 1) * DAY_TICKS;
   165 			ChangeTimetable(v, v->cur_order_index, time_taken, travelling);
   171 			ChangeTimetable(v, v->cur_order_index, time_taken, travelling);
   166 			return;
   172 			return;
   167 		} else if (v->cur_order_index == 0) {
   173 		} else if (v->cur_order_index == 0) {
   168 			/* Otherwise if we're at the beginning and it already has a value,
   174 			/* Otherwise if we're at the beginning and it already has a value,
   169 			 * assume that autofill is finished and turn it off again. */
   175 			 * assume that autofill is finished and turn it off again. */
   170 			CLRBIT(v->vehicle_flags, VF_AUTOFILL_TIMETABLE);
   176 			ClrBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE);
   171 		}
   177 		}
   172  	}
   178  	}
   173 
   179 
   174 	/* Vehicles will wait at stations if they arrive early even if they are not
   180 	/* Vehicles will wait at stations if they arrive early even if they are not
   175 	 * timetabled to wait there, so make sure the lateness counter is updated
   181 	 * timetabled to wait there, so make sure the lateness counter is updated
   176 	 * when this happens. */
   182 	 * when this happens. */
   177 	if (timetabled == 0 && (travelling || v->lateness_counter >= 0)) return;
   183 	if (timetabled == 0 && (travelling || v->lateness_counter >= 0)) return;
   178 
   184 
   179 	v->lateness_counter -= (timetabled - time_taken);
   185 	v->lateness_counter -= (timetabled - time_taken);
   180 
   186 
   181 	InvalidateWindow(WC_VEHICLE_TIMETABLE, v->index);
   187 	for (v = GetFirstVehicleFromSharedList(v); v != NULL; v = v->next_shared) {
       
   188 		InvalidateWindow(WC_VEHICLE_TIMETABLE, v->index);
       
   189 	}
   182 }
   190 }