roadveh_cmd.c
changeset 3236 004a4e2bf30c
parent 3186 4317b5b295c4
child 3315 c9d989783c55
equal deleted inserted replaced
3235:a4c6479870ae 3236:004a4e2bf30c
   378 
   378 
   379 	dep = FindClosestRoadDepot(v);
   379 	dep = FindClosestRoadDepot(v);
   380 	if (dep == NULL) return_cmd_error(STR_9019_UNABLE_TO_FIND_LOCAL_DEPOT);
   380 	if (dep == NULL) return_cmd_error(STR_9019_UNABLE_TO_FIND_LOCAL_DEPOT);
   381 
   381 
   382 	if (flags & DC_EXEC) {
   382 	if (flags & DC_EXEC) {
       
   383 		ClearSlot(v);
       
   384 		v->vehstatus &= ~VS_WAIT_FOR_SLOT;
   383 		v->current_order.type = OT_GOTO_DEPOT;
   385 		v->current_order.type = OT_GOTO_DEPOT;
   384 		v->current_order.flags = OF_NON_STOP | OF_HALT_IN_DEPOT;
   386 		v->current_order.flags = OF_NON_STOP | OF_HALT_IN_DEPOT;
   385 		v->current_order.station = dep->index;
   387 		v->current_order.station = dep->index;
   386 		v->dest_tile = dep->xy;
   388 		v->dest_tile = dep->xy;
   387 		InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
   389 		InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
   403 
   405 
   404 	v = GetVehicle(p1);
   406 	v = GetVehicle(p1);
   405 
   407 
   406 	if (v->type != VEH_Road || !CheckOwnership(v->owner)) return CMD_ERROR;
   408 	if (v->type != VEH_Road || !CheckOwnership(v->owner)) return CMD_ERROR;
   407 
   409 
   408 	if (v->vehstatus & (VS_HIDDEN | VS_STOPPED) ||
   410 	if (v->vehstatus & (VS_HIDDEN | VS_STOPPED | VS_WAIT_FOR_SLOT) ||
   409 			v->u.road.crashed_ctr != 0 ||
   411 			v->u.road.crashed_ctr != 0 ||
   410 			v->breakdown_ctr != 0 ||
   412 			v->breakdown_ctr != 0 ||
   411 			v->u.road.overtaking != 0 ||
   413 			v->u.road.overtaking != 0 ||
   412 			v->cur_speed < 5) {
   414 			v->cur_speed < 5) {
   413 		return CMD_ERROR;
   415 		return CMD_ERROR;
   536 {
   538 {
   537 	uint16 pass;
   539 	uint16 pass;
   538 
   540 
   539 	v->u.road.crashed_ctr++;
   541 	v->u.road.crashed_ctr++;
   540 	v->vehstatus |= VS_CRASHED;
   542 	v->vehstatus |= VS_CRASHED;
       
   543 	ClearSlot(v);
   541 
   544 
   542 	InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
   545 	InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
   543 
   546 
   544 	pass = 1;
   547 	pass = 1;
   545 	if (v->cargo_type == CT_PASSENGERS) pass += v->cargo_count;
   548 	if (v->cargo_type == CT_PASSENGERS) pass += v->cargo_count;
   627 	if (order == NULL) {
   630 	if (order == NULL) {
   628 		v->current_order.type = OT_NOTHING;
   631 		v->current_order.type = OT_NOTHING;
   629 		v->current_order.flags = 0;
   632 		v->current_order.flags = 0;
   630 		v->dest_tile = 0;
   633 		v->dest_tile = 0;
   631 		ClearSlot(v);
   634 		ClearSlot(v);
       
   635 		v->vehstatus &= ~VS_WAIT_FOR_SLOT;
   632 		return;
   636 		return;
   633 	}
   637 	}
   634 
   638 
   635 	if (order->type    == v->current_order.type &&
   639 	if (order->type    == v->current_order.type &&
   636 			order->flags   == v->current_order.flags &&
   640 			order->flags   == v->current_order.flags &&
   638 		return;
   642 		return;
   639 	}
   643 	}
   640 
   644 
   641 	v->current_order = *order;
   645 	v->current_order = *order;
   642 	v->dest_tile = 0;
   646 	v->dest_tile = 0;
       
   647 	/* We have changed the destination STATION, so resume movement */
       
   648 	v->vehstatus &= ~VS_WAIT_FOR_SLOT;
   643 
   649 
   644 	if (order->type == OT_GOTO_STATION) {
   650 	if (order->type == OT_GOTO_STATION) {
   645 		const Station* st = GetStation(order->station);
   651 		const Station* st = GetStation(order->station);
   646 		const RoadStop* rs;
   652 		const RoadStop* rs;
   647 		TileIndex dest;
   653 		TileIndex dest;
   898 
   904 
   899 	od.v = v;
   905 	od.v = v;
   900 	od.u = u;
   906 	od.u = u;
   901 
   907 
   902 	if (u->max_speed >= v->max_speed &&
   908 	if (u->max_speed >= v->max_speed &&
   903 			!(u->vehstatus & VS_STOPPED) &&
   909 			!(u->vehstatus & (VS_STOPPED | VS_WAIT_FOR_SLOT)) &&
   904 			u->cur_speed != 0) {
   910 			u->cur_speed != 0) {
   905 		return;
   911 		return;
   906 	}
   912 	}
   907 
   913 
   908 	if (v->direction != u->direction || !(v->direction & 1)) return;
   914 	if (v->direction != u->direction || !(v->direction & 1)) return;
   920 	if (FindRoadVehToOvertake(&od)) return;
   926 	if (FindRoadVehToOvertake(&od)) return;
   921 
   927 
   922 	od.tile = v->tile + TileOffsByDir(DirToDiagDir(v->direction));
   928 	od.tile = v->tile + TileOffsByDir(DirToDiagDir(v->direction));
   923 	if (FindRoadVehToOvertake(&od)) return;
   929 	if (FindRoadVehToOvertake(&od)) return;
   924 
   930 
   925 	if (od.u->cur_speed == 0 || od.u->vehstatus&VS_STOPPED) {
   931 	if (od.u->cur_speed == 0 || od.u->vehstatus& (VS_STOPPED | VS_WAIT_FOR_SLOT)) {
   926 		v->u.road.overtaking_ctr = 0x11;
   932 		v->u.road.overtaking_ctr = 0x11;
   927 		v->u.road.overtaking = 0x10;
   933 		v->u.road.overtaking = 0x10;
   928 	} else {
   934 	} else {
   929 //		if (FindRoadVehToOvertake(&od)) return;
   935 //		if (FindRoadVehToOvertake(&od)) return;
   930 		v->u.road.overtaking_ctr = 0;
   936 		v->u.road.overtaking_ctr = 0;
  1183 			return;
  1189 			return;
  1184 		}
  1190 		}
  1185 		v->breakdown_ctr--;
  1191 		v->breakdown_ctr--;
  1186 	}
  1192 	}
  1187 
  1193 
  1188 	if (v->vehstatus & VS_STOPPED) return;
  1194 	if (v->vehstatus & (VS_STOPPED | VS_WAIT_FOR_SLOT)) return;
  1189 
  1195 
  1190 	ProcessRoadVehOrder(v);
  1196 	ProcessRoadVehOrder(v);
  1191 	HandleRoadVehLoading(v);
  1197 	HandleRoadVehLoading(v);
  1192 
  1198 
  1193 	if (v->current_order.type == OT_LOADING) return;
  1199 	if (v->current_order.type == OT_LOADING) return;
  1446 				return;
  1452 				return;
  1447 			}
  1453 			}
  1448 			v->current_order.type = OT_NOTHING;
  1454 			v->current_order.type = OT_NOTHING;
  1449 			v->current_order.flags = 0;
  1455 			v->current_order.flags = 0;
  1450 			ClearSlot(v);
  1456 			ClearSlot(v);
       
  1457 			v->vehstatus &= ~VS_WAIT_FOR_SLOT;
  1451 		}
  1458 		}
  1452 		SETBIT(rs->status, 7);
  1459 		SETBIT(rs->status, 7);
  1453 
  1460 
  1454 		if (rs == v->u.road.slot) {
  1461 		if (rs == v->u.road.slot) {
  1455 			//we have arrived at the correct station
  1462 			//we have arrived at the correct station
  1551 {
  1558 {
  1552 	const Depot* depot;
  1559 	const Depot* depot;
  1553 
  1560 
  1554 	if (_patches.servint_roadveh == 0) return;
  1561 	if (_patches.servint_roadveh == 0) return;
  1555 	if (!VehicleNeedsService(v)) return;
  1562 	if (!VehicleNeedsService(v)) return;
  1556 	if (v->vehstatus & VS_STOPPED) return;
  1563 	if (v->vehstatus & (VS_STOPPED | VS_WAIT_FOR_SLOT)) return;
  1557 	if (_patches.gotodepot && VehicleHasDepotOrders(v)) return;
  1564 	if (_patches.gotodepot && VehicleHasDepotOrders(v)) return;
  1558 
  1565 
  1559 	// Don't interfere with a depot visit scheduled by the user, or a
  1566 	// Don't interfere with a depot visit scheduled by the user, or a
  1560 	// depot visit by the order list.
  1567 	// depot visit by the order list.
  1561 	if (v->current_order.type == OT_GOTO_DEPOT &&
  1568 	if (v->current_order.type == OT_GOTO_DEPOT &&
  1608 			v->u.road.slotindex, v->unitnumber, v->index, v->u.road.slot->xy
  1615 			v->u.road.slotindex, v->unitnumber, v->index, v->u.road.slot->xy
  1609 		);
  1616 		);
  1610 		ClearSlot(v);
  1617 		ClearSlot(v);
  1611 	}
  1618 	}
  1612 
  1619 
       
  1620 	if (v->vehstatus & VS_STOPPED) return;
       
  1621 
  1613 	/* update destination */
  1622 	/* update destination */
  1614 	if (v->current_order.type == OT_GOTO_STATION &&
  1623 	if (v->current_order.type == OT_GOTO_STATION &&
  1615 			v->u.road.slot == NULL &&
  1624 			v->u.road.slot == NULL &&
  1616 			!(v->vehstatus & VS_CRASHED) &&
  1625 			!IsLevelCrossing(v->tile) &&
  1617 			!((v->vehstatus & (VS_STOPPED | VS_WAIT_FOR_SLOT)) == VS_STOPPED)) {
  1626 			v->u.road.overtaking == 0 &&
       
  1627 			!(v->vehstatus & VS_CRASHED)) {
  1618 		RoadStopType type = (v->cargo_type == CT_PASSENGERS) ? RS_BUS : RS_TRUCK;
  1628 		RoadStopType type = (v->cargo_type == CT_PASSENGERS) ? RS_BUS : RS_TRUCK;
  1619 		RoadStop *rs;
  1629 		RoadStop *rs;
  1620 		uint mindist = 0xFFFFFFFF;
  1630 		uint mindist = 0xFFFFFFFF;
  1621 		int i;
  1631 		int i;
  1622 		RoadStop *nearest = NULL;
  1632 		RoadStop *nearest = NULL;
  1665 					v->u.road.slot = nearest;
  1675 					v->u.road.slot = nearest;
  1666 					v->dest_tile = nearest->xy;
  1676 					v->dest_tile = nearest->xy;
  1667 					v->u.road.slot_age = 14;
  1677 					v->u.road.slot_age = 14;
  1668 					v->u.road.slotindex = new_slot;
  1678 					v->u.road.slotindex = new_slot;
  1669 
  1679 
  1670 					if (v->vehstatus & VS_STOPPED) {
  1680 					if (v->vehstatus & VS_WAIT_FOR_SLOT) {
  1671 						DEBUG(ms, 4) ("Multistop: ---- stopped vehicle got a slot. resuming movement");
  1681 						DEBUG(ms, 4) ("Multistop: ---- stopped vehicle got a slot. resuming movement");
  1672 						v->vehstatus &= ~(VS_STOPPED | VS_WAIT_FOR_SLOT);
  1682 						v->vehstatus &= ~VS_WAIT_FOR_SLOT;
  1673 						InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
  1683 						InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
  1674 					}
  1684 					}
  1675 				} else {
  1685 				} else {
  1676 					DEBUG(ms, 2) ("Multistop -- No free slot at station. Waiting");
  1686 					DEBUG(ms, 2) ("Multistop -- No free slot at station. Waiting");
  1677 					v->vehstatus |= (VS_STOPPED | VS_WAIT_FOR_SLOT);
  1687 					v->vehstatus |= VS_WAIT_FOR_SLOT;
  1678 					InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
  1688 					InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
  1679 				}
  1689 				}
  1680 			} else {
  1690 			} else {
  1681 				DEBUG(ms, 5) ("Multistop: --- Distance from station too far. Postponing slotting for vehicle %d (index %d) at station %d, (0x%x)",
  1691 				DEBUG(ms, 5) ("Multistop: --- Distance from station too far. Postponing slotting for vehicle %d (index %d) at station %d, (0x%x)",
  1682 						v->unitnumber, v->index, st->index, st->xy);
  1692 						v->unitnumber, v->index, st->index, st->xy);
  1685 			DEBUG(ms, 4) ("Multistop: No road stop for vehicle %d (index %d) at station %d (0x%x)",
  1695 			DEBUG(ms, 4) ("Multistop: No road stop for vehicle %d (index %d) at station %d (0x%x)",
  1686 					v->unitnumber, v->index, st->index, st->xy);
  1696 					v->unitnumber, v->index, st->index, st->xy);
  1687 		}
  1697 		}
  1688 	}
  1698 	}
  1689 
  1699 
  1690 	if (v->vehstatus & VS_STOPPED) return;
       
  1691 
       
  1692 	cost = RoadVehInfo(v->engine_type)->running_cost * _price.roadveh_running / 364;
  1700 	cost = RoadVehInfo(v->engine_type)->running_cost * _price.roadveh_running / 364;
  1693 
  1701 
  1694 	v->profit_this_year -= cost >> 8;
  1702 	v->profit_this_year -= cost >> 8;
  1695 
  1703 
  1696 	SET_EXPENSES_TYPE(EXPENSES_ROADVEH_RUN);
  1704 	SET_EXPENSES_TYPE(EXPENSES_ROADVEH_RUN);