equal
deleted
inserted
replaced
1693 if ( (v->u.road.slot_age++ <= 0) && (v->u.road.slot != NULL)) { |
1693 if ( (v->u.road.slot_age++ <= 0) && (v->u.road.slot != NULL)) { |
1694 ClearSlot(v, v->u.road.slot); |
1694 ClearSlot(v, v->u.road.slot); |
1695 } |
1695 } |
1696 |
1696 |
1697 //We do not have a slot, so make one |
1697 //We do not have a slot, so make one |
1698 if (v->u.road.slot == NULL) { |
1698 if (v->u.road.slot == NULL && rs != NULL) { |
1699 //first we need to find out how far our stations are away. |
1699 //first we need to find out how far our stations are away. |
1700 if ( rs == NULL ) { |
|
1701 free(firststop); |
|
1702 firststop = stop = NULL; |
|
1703 goto no_stop; |
|
1704 } |
|
1705 |
1700 |
1706 DEBUG(ms, 2) ("Multistop: Attempting to obtain a slot for vehicle %d at station %d (0x%x)", v->unitnumber, st->index, st->xy); |
1701 DEBUG(ms, 2) ("Multistop: Attempting to obtain a slot for vehicle %d at station %d (0x%x)", v->unitnumber, st->index, st->xy); |
1707 do { |
1702 do { |
1708 stop->dist = 0xFFFFFFFF; |
1703 stop->dist = 0xFFFFFFFF; |
1709 |
1704 |
1727 bubblesort(firststop, num, sizeof(StopStruct), dist_compare); |
1722 bubblesort(firststop, num, sizeof(StopStruct), dist_compare); |
1728 |
1723 |
1729 stop = firststop; |
1724 stop = firststop; |
1730 for (k = 0; k < num; k++) { |
1725 for (k = 0; k < num; k++) { |
1731 int i; |
1726 int i; |
|
1727 bool br = false; |
1732 for (i = 0; i < NUM_SLOTS; i++) { |
1728 for (i = 0; i < NUM_SLOTS; i++) { |
1733 if ((stop->rs->slot[i] == INVALID_SLOT) && (stop->dist < 120)) { |
1729 if ((stop->rs->slot[i] == INVALID_SLOT) && (stop->dist < 120)) { |
1734 |
1730 |
1735 //Hooray we found a free slot. Assign it |
1731 //Hooray we found a free slot. Assign it |
1736 DEBUG(ms, 1) ("Multistop: Slot %d at 0x%x assigned to vehicle %d", i, stop->rs->xy, v->unitnumber); |
1732 DEBUG(ms, 1) ("Multistop: Slot %d at 0x%x assigned to vehicle %d", i, stop->rs->xy, v->unitnumber); |
1739 |
1735 |
1740 v->dest_tile = stop->rs->xy; |
1736 v->dest_tile = stop->rs->xy; |
1741 v->u.road.slot_age = -30; |
1737 v->u.road.slot_age = -30; |
1742 v->u.road.slotindex = i; |
1738 v->u.road.slotindex = i; |
1743 |
1739 |
1744 goto have_slot; //jump out of BOTH loops |
1740 br = true; |
|
1741 break; |
1745 |
1742 |
1746 } |
1743 } |
1747 } |
1744 } |
1748 stop++; |
1745 stop++; |
|
1746 if (br) break; |
1749 } |
1747 } |
1750 } |
1748 } |
1751 |
1749 |
1752 have_slot: |
|
1753 //now we couldn't assign a slot for one reason or another. |
1750 //now we couldn't assign a slot for one reason or another. |
1754 //so we just go to the nearest station |
1751 //so we just go to the nearest station |
1755 if (v->u.road.slot == NULL) { |
1752 if (v->u.road.slot == NULL) { |
1756 DEBUG(ms, 1) ("Multistop: No free slot found for vehicle %d, going to default station", v->unitnumber); |
1753 DEBUG(ms, 1) ("Multistop: No free slot found for vehicle %d, going to default station", v->unitnumber); |
1757 v->dest_tile = firststop->rs->xy; |
1754 v->dest_tile = firststop->rs->xy; |
1760 |
1757 |
1761 free(firststop); |
1758 free(firststop); |
1762 firststop = stop = NULL; |
1759 firststop = stop = NULL; |
1763 } |
1760 } |
1764 |
1761 |
1765 no_stop: |
|
1766 if (v->vehstatus & VS_STOPPED) |
1762 if (v->vehstatus & VS_STOPPED) |
1767 return; |
1763 return; |
1768 |
1764 |
1769 cost = RoadVehInfo(v->engine_type)->running_cost * _price.roadveh_running / 364; |
1765 cost = RoadVehInfo(v->engine_type)->running_cost * _price.roadveh_running / 364; |
1770 |
1766 |