| 4773 | } |
| 4774 | |
| 4775 | static void ChangeTileOwner_Station(TileIndex tile, Owner old_owner, Owner new_owner) |
| 4776 | { |
| 4777 | |
| 4778 | if (IsAnyRoadStopTile(tile)) { |
| 4779 | for (RoadTramType rtt : _roadtramtypes) { |
| 4780 | /* Update all roadtypes, no matter if they are present */ |
| 4781 | if (GetRoadOwner(tile, rtt) == old_owner) { |
| 4782 | RoadType rt = GetRoadType(tile, rtt); |
| 4783 | if (rt != INVALID_ROADTYPE) { |
| 4784 | /* A drive-through road-stop has always two road bits. No need to dirty windows here, we'll redraw the whole screen anyway. */ |
| 4785 | Company::Get(old_owner)->infrastructure.road[rt] -= 2; |
| 4786 | if (new_owner != INVALID_OWNER) Company::Get(new_owner)->infrastructure.road[rt] += 2; |
| 4787 | } |
| 4788 | SetRoadOwner(tile, rtt, new_owner == INVALID_OWNER ? OWNER_NONE : new_owner); |
| 4789 | } |
| 4790 | } |
| 4791 | } |
| 4792 | |
| 4793 | if (!IsTileOwner(tile, old_owner)) return; |
| 4794 | |
| 4795 | if (new_owner != INVALID_OWNER) { |
| 4796 | /* Update company infrastructure counts. Only do it here |
| 4797 | * if the new owner is valid as otherwise the clear |
| 4798 | * command will do it for us. No need to dirty windows |
| 4799 | * here, we'll redraw the whole screen anyway.*/ |
| 4800 | Company *old_company = Company::Get(old_owner); |
| 4801 | Company *new_company = Company::Get(new_owner); |
| 4802 | |
| 4803 | /* Update counts for underlying infrastructure. */ |
| 4804 | switch (GetStationType(tile)) { |
| 4805 | case StationType::Rail: |
| 4806 | case StationType::RailWaypoint: |
| 4807 | if (!IsStationTileBlocked(tile)) { |
| 4808 | old_company->infrastructure.rail[GetRailType(tile)]--; |
| 4809 | new_company->infrastructure.rail[GetRailType(tile)]++; |
| 4810 | } |
| 4811 | break; |
| 4812 | |
| 4813 | case StationType::Bus: |
| 4814 | case StationType::Truck: |
| 4815 | case StationType::RoadWaypoint: |
| 4816 | /* Road stops were already handled above. */ |
| 4817 | break; |
| 4818 | |
| 4819 | case StationType::Buoy: |
| 4820 | case StationType::Dock: |
| 4821 | if (GetWaterClass(tile) == WaterClass::Canal) { |
| 4822 | old_company->infrastructure.water--; |
| 4823 | new_company->infrastructure.water++; |
| 4824 | } |
| 4825 | break; |
| 4826 | |
| 4827 | default: |
| 4828 | break; |
| 4829 | } |
| 4830 | |
| 4831 | /* Update station tile count. */ |
| 4832 | if (!IsBuoy(tile) && !IsAirport(tile)) { |
nothing calls this directly
no test coverage detected