1511 assert(cur_stop != NULL); |
1511 assert(cur_stop != NULL); |
1512 |
1512 |
1513 if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
1513 if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
1514 |
1514 |
1515 if (flags & DC_EXEC) { |
1515 if (flags & DC_EXEC) { |
1516 Vehicle* v; |
|
1517 |
|
1518 /* Clear the slot assignment of all vehicles heading for this road stop */ |
|
1519 if (cur_stop->num_vehicles != 0) { |
|
1520 FOR_ALL_VEHICLES(v) { |
|
1521 if (v->type == VEH_Road && v->u.road.slot == cur_stop) { |
|
1522 ClearSlot(v); |
|
1523 } |
|
1524 } |
|
1525 } |
|
1526 assert(cur_stop->num_vehicles == 0); |
|
1527 |
|
1528 DoClearSquare(tile); |
|
1529 |
|
1530 cur_stop->used = false; |
|
1531 if (cur_stop->prev != NULL) cur_stop->prev->next = cur_stop->next; |
|
1532 if (cur_stop->next != NULL) cur_stop->next->prev = cur_stop->prev; |
|
1533 |
|
1534 //we only had one stop left |
1516 //we only had one stop left |
1535 if (cur_stop->next == NULL && cur_stop->prev == NULL) { |
1517 if (cur_stop->next == NULL && cur_stop->prev == NULL) { |
1536 //so we remove ALL stops |
1518 //so we remove ALL stops |
1537 *primary_stop = NULL; |
1519 *primary_stop = NULL; |
1538 st->facilities &= (is_truck) ? ~FACIL_TRUCK_STOP : ~FACIL_BUS_STOP; |
1520 st->facilities &= (is_truck) ? ~FACIL_TRUCK_STOP : ~FACIL_BUS_STOP; |
1539 } else if (cur_stop == *primary_stop) { |
1521 } else if (cur_stop == *primary_stop) { |
1540 //removed the first stop in the list |
1522 //removed the first stop in the list |
1541 //need to set the primary element to the next stop |
1523 //need to set the primary element to the next stop |
1542 *primary_stop = (*primary_stop)->next; |
1524 *primary_stop = (*primary_stop)->next; |
1543 } |
1525 } |
|
1526 |
|
1527 DeleteRoadStop(cur_stop); |
|
1528 DoClearSquare(tile); |
1544 |
1529 |
1545 UpdateStationVirtCoordDirty(st); |
1530 UpdateStationVirtCoordDirty(st); |
1546 DeleteStationIfEmpty(st); |
1531 DeleteStationIfEmpty(st); |
1547 } |
1532 } |
1548 |
1533 |
2387 } |
2372 } |
2388 |
2373 |
2389 return 0; |
2374 return 0; |
2390 } |
2375 } |
2391 |
2376 |
2392 /** Removes a station from the list. |
2377 /** |
2393 * This is done by setting the .xy property to 0, |
2378 * Cleanup a RoadStop. Make sure no vehicles try to go to this roadstop. |
2394 * and doing some maintenance, especially clearing vehicle orders. |
2379 */ |
|
2380 void DestroyRoadStop(RoadStop* rs) |
|
2381 { |
|
2382 Vehicle *v; |
|
2383 |
|
2384 /* Clear the slot assignment of all vehicles heading for this road stop */ |
|
2385 if (rs->num_vehicles != 0) { |
|
2386 FOR_ALL_VEHICLES(v) { |
|
2387 if (v->type == VEH_Road && v->u.road.slot == rs) { |
|
2388 ClearSlot(v); |
|
2389 } |
|
2390 } |
|
2391 } |
|
2392 assert(rs->num_vehicles == 0); |
|
2393 |
|
2394 if (rs->prev != NULL) rs->prev->next = rs->next; |
|
2395 if (rs->next != NULL) rs->next->prev = rs->prev; |
|
2396 } |
|
2397 |
|
2398 /** |
|
2399 * Clean up a station by clearing vehicle orders and invalidating windows. |
2395 * Aircraft-Hangar orders need special treatment here, as the hangars are |
2400 * Aircraft-Hangar orders need special treatment here, as the hangars are |
2396 * actually part of a station (tiletype is STATION), but the order type |
2401 * actually part of a station (tiletype is STATION), but the order type |
2397 * is OT_GOTO_DEPOT. |
2402 * is OT_GOTO_DEPOT. |
2398 * @param st Station to be deleted |
2403 * @param st Station to be deleted |
2399 */ |
2404 */ |
2400 static void DeleteStation(Station *st) |
2405 void DestroyStation(Station *st) |
2401 { |
2406 { |
2402 DestinationID dest; |
2407 DestinationID dest; |
2403 StationID index; |
2408 StationID index; |
2404 Vehicle *v; |
2409 Vehicle *v; |
2405 st->xy = 0; |
2410 |
|
2411 index = st->index; |
2406 |
2412 |
2407 DeleteName(st->string_id); |
2413 DeleteName(st->string_id); |
2408 MarkStationDirty(st); |
2414 MarkStationDirty(st); |
2409 RebuildStationLists(); |
2415 RebuildStationLists(); |
2410 InvalidateWindowClasses(WC_STATION_LIST); |
2416 InvalidateWindowClasses(WC_STATION_LIST); |
2411 |
2417 |
2412 index = st->index; |
|
2413 DeleteWindowById(WC_STATION_VIEW, index); |
2418 DeleteWindowById(WC_STATION_VIEW, index); |
2414 |
2419 |
2415 /* Now delete all orders that go to the station */ |
2420 /* Now delete all orders that go to the station */ |
2416 dest.station = index; |
2421 dest.station = index; |
2417 RemoveOrderFromAllVehicles(OT_GOTO_STATION, dest); |
2422 RemoveOrderFromAllVehicles(OT_GOTO_STATION, dest); |