roadveh_cmd.c
changeset 4527 fa30d19685c2
parent 4526 6d48f07e829e
child 4529 18bd5e7e35aa
equal deleted inserted replaced
4526:6d48f07e829e 4527:fa30d19685c2
   415 	if (flags & DC_EXEC) {
   415 	if (flags & DC_EXEC) {
   416 		ClearSlot(v);
   416 		ClearSlot(v);
   417 		v->current_order.type = OT_GOTO_DEPOT;
   417 		v->current_order.type = OT_GOTO_DEPOT;
   418 		v->current_order.flags = OF_NON_STOP;
   418 		v->current_order.flags = OF_NON_STOP;
   419 		if (!(p2 & DEPOT_SERVICE)) SETBIT(v->current_order.flags, OFB_HALT_IN_DEPOT);
   419 		if (!(p2 & DEPOT_SERVICE)) SETBIT(v->current_order.flags, OFB_HALT_IN_DEPOT);
   420 		v->current_order.dest.depot = dep->index;
   420 		v->current_order.dest = dep->index;
   421 		v->dest_tile = dep->xy;
   421 		v->dest_tile = dep->xy;
   422 		InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
   422 		InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
   423 	}
   423 	}
   424 
   424 
   425 	return 0;
   425 	return 0;
   668 		v->dest_tile = 0;
   668 		v->dest_tile = 0;
   669 		ClearSlot(v);
   669 		ClearSlot(v);
   670 		return;
   670 		return;
   671 	}
   671 	}
   672 
   672 
   673 	if (order->type    == v->current_order.type &&
   673 	if (order->type  == v->current_order.type &&
   674 			order->flags   == v->current_order.flags &&
   674 			order->flags == v->current_order.flags &&
   675 			order->dest.station == v->current_order.dest.station) {
   675 			order->dest  == v->current_order.dest) {
   676 		return;
   676 		return;
   677 	}
   677 	}
   678 
   678 
   679 	v->current_order = *order;
   679 	v->current_order = *order;
   680 
   680 
   681 	switch (order->type) {
   681 	switch (order->type) {
   682 		case OT_GOTO_STATION: {
   682 		case OT_GOTO_STATION: {
   683 			const RoadStop* rs;
   683 			const RoadStop* rs;
   684 
   684 
   685 			if (order->dest.station == v->last_station_visited) {
   685 			if (order->dest == v->last_station_visited) {
   686 				v->last_station_visited = INVALID_STATION;
   686 				v->last_station_visited = INVALID_STATION;
   687 			}
   687 			}
   688 
   688 
   689 			rs = GetPrimaryRoadStop(
   689 			rs = GetPrimaryRoadStop(
   690 				GetStation(order->dest.station),
   690 				GetStation(order->dest),
   691 				v->cargo_type == CT_PASSENGERS ? RS_BUS : RS_TRUCK
   691 				v->cargo_type == CT_PASSENGERS ? RS_BUS : RS_TRUCK
   692 			);
   692 			);
   693 
   693 
   694 			if (rs != NULL) {
   694 			if (rs != NULL) {
   695 				TileIndex dest = rs->xy;
   695 				TileIndex dest = rs->xy;
   711 			}
   711 			}
   712 			break;
   712 			break;
   713 		}
   713 		}
   714 
   714 
   715 		case OT_GOTO_DEPOT:
   715 		case OT_GOTO_DEPOT:
   716 			v->dest_tile = GetDepot(order->dest.depot)->xy;
   716 			v->dest_tile = GetDepot(order->dest)->xy;
   717 			break;
   717 			break;
   718 
   718 
   719 		default:
   719 		default:
   720 			v->dest_tile = 0;
   720 			v->dest_tile = 0;
   721 			break;
   721 			break;
  1499 			old_order = v->current_order;
  1499 			old_order = v->current_order;
  1500 			v->current_order.type = OT_LOADING;
  1500 			v->current_order.type = OT_LOADING;
  1501 			v->current_order.flags = 0;
  1501 			v->current_order.flags = 0;
  1502 
  1502 
  1503 			if (old_order.type == OT_GOTO_STATION &&
  1503 			if (old_order.type == OT_GOTO_STATION &&
  1504 					v->current_order.dest.station == v->last_station_visited) {
  1504 					v->current_order.dest == v->last_station_visited) {
  1505 				v->current_order.flags =
  1505 				v->current_order.flags =
  1506 					(old_order.flags & (OF_FULL_LOAD | OF_UNLOAD | OF_TRANSFER)) | OF_NON_STOP;
  1506 					(old_order.flags & (OF_FULL_LOAD | OF_UNLOAD | OF_TRANSFER)) | OF_NON_STOP;
  1507 			}
  1507 			}
  1508 
  1508 
  1509 			SET_EXPENSES_TYPE(EXPENSES_ROADVEH_INC);
  1509 			SET_EXPENSES_TYPE(EXPENSES_ROADVEH_INC);
  1541 				DEBUG(ms, 0) ("Multistop: -- Stop tile 0x%X is not destination tile 0x%X. Multistop desync", v->u.road.slot->xy, v->dest_tile);
  1541 				DEBUG(ms, 0) ("Multistop: -- Stop tile 0x%X is not destination tile 0x%X. Multistop desync", v->u.road.slot->xy, v->dest_tile);
  1542 			}
  1542 			}
  1543 			if (v->current_order.type != OT_GOTO_STATION) {
  1543 			if (v->current_order.type != OT_GOTO_STATION) {
  1544 				DEBUG(ms, 0) ("Multistop: -- Current order type (%d) is not OT_GOTO_STATION.", v->current_order.type);
  1544 				DEBUG(ms, 0) ("Multistop: -- Current order type (%d) is not OT_GOTO_STATION.", v->current_order.type);
  1545 			} else {
  1545 			} else {
  1546 				if (v->current_order.dest.station != st->index)
  1546 				if (v->current_order.dest != st->index)
  1547 					DEBUG(ms, 0) ("Multistop: -- Current station %d is not target station in current_order.station (%d).",
  1547 					DEBUG(ms, 0) ("Multistop: -- Current station %d is not target station in current_order.station (%d).",
  1548 							st->index, v->current_order.dest.station);
  1548 							st->index, v->current_order.dest);
  1549 			}
  1549 			}
  1550 
  1550 
  1551 			DEBUG(ms, 0) ("           -- Force a slot clearing.");
  1551 			DEBUG(ms, 0) ("           -- Force a slot clearing.");
  1552 			ClearSlot(v);
  1552 			ClearSlot(v);
  1553 		}
  1553 		}
  1658 		return;
  1658 		return;
  1659 	}
  1659 	}
  1660 
  1660 
  1661 	v->current_order.type = OT_GOTO_DEPOT;
  1661 	v->current_order.type = OT_GOTO_DEPOT;
  1662 	v->current_order.flags = OF_NON_STOP;
  1662 	v->current_order.flags = OF_NON_STOP;
  1663 	v->current_order.dest.depot = depot->index;
  1663 	v->current_order.dest = depot->index;
  1664 	v->dest_tile = depot->xy;
  1664 	v->dest_tile = depot->xy;
  1665 	InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
  1665 	InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
  1666 }
  1666 }
  1667 
  1667 
  1668 void OnNewDay_RoadVeh(Vehicle *v)
  1668 void OnNewDay_RoadVeh(Vehicle *v)
  1686 
  1686 
  1687 	if (v->vehstatus & VS_STOPPED) return;
  1687 	if (v->vehstatus & VS_STOPPED) return;
  1688 
  1688 
  1689 	/* update destination */
  1689 	/* update destination */
  1690 	if (v->current_order.type == OT_GOTO_STATION && v->u.road.slot == NULL && !(v->vehstatus & VS_CRASHED)) {
  1690 	if (v->current_order.type == OT_GOTO_STATION && v->u.road.slot == NULL && !(v->vehstatus & VS_CRASHED)) {
  1691 		Station* st = GetStation(v->current_order.dest.station);
  1691 		Station* st = GetStation(v->current_order.dest);
  1692 		RoadStop* rs = GetPrimaryRoadStop(st, v->cargo_type == CT_PASSENGERS ? RS_BUS : RS_TRUCK);
  1692 		RoadStop* rs = GetPrimaryRoadStop(st, v->cargo_type == CT_PASSENGERS ? RS_BUS : RS_TRUCK);
  1693 		RoadStop* best = NULL;
  1693 		RoadStop* best = NULL;
  1694 
  1694 
  1695 		if (rs != NULL) {
  1695 		if (rs != NULL) {
  1696 			if (DistanceManhattan(v->tile, st->xy) < 16) {
  1696 			if (DistanceManhattan(v->tile, st->xy) < 16) {