MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / ChangeTileOwner_Object

Function ChangeTileOwner_Object

src/object_cmd.cpp:868–902  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

866}
867
868static void ChangeTileOwner_Object(TileIndex tile, Owner old_owner, Owner new_owner)
869{
870 if (!IsTileOwner(tile, old_owner)) return;
871
872 bool do_clear = false;
873
874 ObjectType type = GetObjectType(tile);
875 if ((type == OBJECT_OWNED_LAND || type >= NEW_OBJECT_OFFSET) && new_owner != INVALID_OWNER) {
876 SetTileOwner(tile, new_owner);
877 if (GetWaterClass(tile) == WaterClass::Canal) {
878 Company::Get(old_owner)->infrastructure.water--;
879 Company::Get(new_owner)->infrastructure.water++;
880 }
881 } else if (type == OBJECT_STATUE) {
882 Town *t = Object::GetByTile(tile)->town;
883 t->statues.Reset(old_owner);
884 if (new_owner != INVALID_OWNER && !t->statues.Test(new_owner)) {
885 /* Transfer ownership to the new company */
886 t->statues.Set(new_owner);
887 SetTileOwner(tile, new_owner);
888 } else {
889 do_clear = true;
890 }
891
892 SetWindowDirty(WC_TOWN_AUTHORITY, t->index);
893 } else {
894 do_clear = true;
895 }
896
897 if (do_clear) {
898 ReallyClearObjectTile(Object::GetByTile(tile));
899 /* When clearing objects, they may turn into canal, which may require transferring ownership. */
900 ChangeTileOwner(tile, old_owner, new_owner);
901 }
902}
903
904static CommandCost TerraformTile_Object(TileIndex tile, DoCommandFlags flags, int z_new, Slope tileh_new)
905{

Callers

nothing calls this directly

Calls 10

IsTileOwnerFunction · 0.85
GetObjectTypeFunction · 0.85
SetTileOwnerFunction · 0.85
GetWaterClassFunction · 0.85
SetWindowDirtyFunction · 0.85
ReallyClearObjectTileFunction · 0.85
ChangeTileOwnerFunction · 0.85
TestMethod · 0.80
ResetMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected