Starships and planets have their own Friendly Code. Starbases always use the same friendly code as the planet they orbit.
Mine fields are controlled by the planet belonging to the owner of the mine field and being located nearest to the mine field center.