mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
-Codechange: DestroyStation/DestroyRoadStop is called by DeleteStation/DeleteRoadStop to remove all things where a station/RoadStop depends on. Last 2 changes to prepare for new pool system. Not pretty now, will be soon.
This commit is contained in:
parent
587b2a8826
commit
d417827516
16
station.h
16
station.h
|
@ -184,6 +184,14 @@ static inline bool IsValidStationID(StationID index)
|
||||||
return index < GetStationPoolSize() && IsValidStation(GetStation(index));
|
return index < GetStationPoolSize() && IsValidStation(GetStation(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DestroyStation(Station *st);
|
||||||
|
|
||||||
|
static inline void DeleteStation(Station *st)
|
||||||
|
{
|
||||||
|
DestroyStation(st);
|
||||||
|
st->xy = 0;
|
||||||
|
}
|
||||||
|
|
||||||
#define FOR_ALL_STATIONS_FROM(st, start) for (st = GetStation(start); st != NULL; st = (st->index + 1 < GetStationPoolSize()) ? GetStation(st->index + 1) : NULL) if (IsValidStation(st))
|
#define FOR_ALL_STATIONS_FROM(st, start) for (st = GetStation(start); st != NULL; st = (st->index + 1 < GetStationPoolSize()) ? GetStation(st->index + 1) : NULL) if (IsValidStation(st))
|
||||||
#define FOR_ALL_STATIONS(st) FOR_ALL_STATIONS_FROM(st, 0)
|
#define FOR_ALL_STATIONS(st) FOR_ALL_STATIONS_FROM(st, 0)
|
||||||
|
|
||||||
|
@ -216,6 +224,14 @@ static inline bool IsValidRoadStop(const RoadStop *rs)
|
||||||
return rs->used;
|
return rs->used;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DestroyRoadStop(RoadStop* rs);
|
||||||
|
|
||||||
|
static inline void DeleteRoadStop(RoadStop *rs)
|
||||||
|
{
|
||||||
|
DestroyRoadStop(rs);
|
||||||
|
rs->used = false;
|
||||||
|
}
|
||||||
|
|
||||||
#define FOR_ALL_ROADSTOPS_FROM(rs, start) for (rs = GetRoadStop(start); rs != NULL; rs = (rs->index + 1 < GetRoadStopPoolSize()) ? GetRoadStop(rs->index + 1) : NULL) if (IsValidRoadStop(rs))
|
#define FOR_ALL_ROADSTOPS_FROM(rs, start) for (rs = GetRoadStop(start); rs != NULL; rs = (rs->index + 1 < GetRoadStopPoolSize()) ? GetRoadStop(rs->index + 1) : NULL) if (IsValidRoadStop(rs))
|
||||||
#define FOR_ALL_ROADSTOPS(rs) FOR_ALL_ROADSTOPS_FROM(rs, 0)
|
#define FOR_ALL_ROADSTOPS(rs) FOR_ALL_ROADSTOPS_FROM(rs, 0)
|
||||||
|
|
||||||
|
|
|
@ -1513,24 +1513,6 @@ static int32 RemoveRoadStop(Station *st, uint32 flags, TileIndex tile)
|
||||||
if (!EnsureNoVehicle(tile)) return CMD_ERROR;
|
if (!EnsureNoVehicle(tile)) return CMD_ERROR;
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
Vehicle* v;
|
|
||||||
|
|
||||||
/* Clear the slot assignment of all vehicles heading for this road stop */
|
|
||||||
if (cur_stop->num_vehicles != 0) {
|
|
||||||
FOR_ALL_VEHICLES(v) {
|
|
||||||
if (v->type == VEH_Road && v->u.road.slot == cur_stop) {
|
|
||||||
ClearSlot(v);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
assert(cur_stop->num_vehicles == 0);
|
|
||||||
|
|
||||||
DoClearSquare(tile);
|
|
||||||
|
|
||||||
cur_stop->used = false;
|
|
||||||
if (cur_stop->prev != NULL) cur_stop->prev->next = cur_stop->next;
|
|
||||||
if (cur_stop->next != NULL) cur_stop->next->prev = cur_stop->prev;
|
|
||||||
|
|
||||||
//we only had one stop left
|
//we only had one stop left
|
||||||
if (cur_stop->next == NULL && cur_stop->prev == NULL) {
|
if (cur_stop->next == NULL && cur_stop->prev == NULL) {
|
||||||
//so we remove ALL stops
|
//so we remove ALL stops
|
||||||
|
@ -1542,6 +1524,9 @@ static int32 RemoveRoadStop(Station *st, uint32 flags, TileIndex tile)
|
||||||
*primary_stop = (*primary_stop)->next;
|
*primary_stop = (*primary_stop)->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DeleteRoadStop(cur_stop);
|
||||||
|
DoClearSquare(tile);
|
||||||
|
|
||||||
UpdateStationVirtCoordDirty(st);
|
UpdateStationVirtCoordDirty(st);
|
||||||
DeleteStationIfEmpty(st);
|
DeleteStationIfEmpty(st);
|
||||||
}
|
}
|
||||||
|
@ -2389,27 +2374,47 @@ static uint32 VehicleEnter_Station(Vehicle *v, TileIndex tile, int x, int y)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Removes a station from the list.
|
/**
|
||||||
* This is done by setting the .xy property to 0,
|
* Cleanup a RoadStop. Make sure no vehicles try to go to this roadstop.
|
||||||
* and doing some maintenance, especially clearing vehicle orders.
|
*/
|
||||||
|
void DestroyRoadStop(RoadStop* rs)
|
||||||
|
{
|
||||||
|
Vehicle *v;
|
||||||
|
|
||||||
|
/* Clear the slot assignment of all vehicles heading for this road stop */
|
||||||
|
if (rs->num_vehicles != 0) {
|
||||||
|
FOR_ALL_VEHICLES(v) {
|
||||||
|
if (v->type == VEH_Road && v->u.road.slot == rs) {
|
||||||
|
ClearSlot(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert(rs->num_vehicles == 0);
|
||||||
|
|
||||||
|
if (rs->prev != NULL) rs->prev->next = rs->next;
|
||||||
|
if (rs->next != NULL) rs->next->prev = rs->prev;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clean up a station by clearing vehicle orders and invalidating windows.
|
||||||
* Aircraft-Hangar orders need special treatment here, as the hangars are
|
* Aircraft-Hangar orders need special treatment here, as the hangars are
|
||||||
* actually part of a station (tiletype is STATION), but the order type
|
* actually part of a station (tiletype is STATION), but the order type
|
||||||
* is OT_GOTO_DEPOT.
|
* is OT_GOTO_DEPOT.
|
||||||
* @param st Station to be deleted
|
* @param st Station to be deleted
|
||||||
*/
|
*/
|
||||||
static void DeleteStation(Station *st)
|
void DestroyStation(Station *st)
|
||||||
{
|
{
|
||||||
DestinationID dest;
|
DestinationID dest;
|
||||||
StationID index;
|
StationID index;
|
||||||
Vehicle *v;
|
Vehicle *v;
|
||||||
st->xy = 0;
|
|
||||||
|
index = st->index;
|
||||||
|
|
||||||
DeleteName(st->string_id);
|
DeleteName(st->string_id);
|
||||||
MarkStationDirty(st);
|
MarkStationDirty(st);
|
||||||
RebuildStationLists();
|
RebuildStationLists();
|
||||||
InvalidateWindowClasses(WC_STATION_LIST);
|
InvalidateWindowClasses(WC_STATION_LIST);
|
||||||
|
|
||||||
index = st->index;
|
|
||||||
DeleteWindowById(WC_STATION_VIEW, index);
|
DeleteWindowById(WC_STATION_VIEW, index);
|
||||||
|
|
||||||
/* Now delete all orders that go to the station */
|
/* Now delete all orders that go to the station */
|
||||||
|
@ -2435,6 +2440,8 @@ static void DeleteStation(Station *st)
|
||||||
|
|
||||||
//Subsidies need removal as well
|
//Subsidies need removal as well
|
||||||
DeleteSubsidyWithStation(index);
|
DeleteSubsidyWithStation(index);
|
||||||
|
|
||||||
|
free(st->speclist);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeleteAllPlayerStations(void)
|
void DeleteAllPlayerStations(void)
|
||||||
|
|
Loading…
Reference in New Issue