public static void AddToFavorites(InstanceID MyInstanceID)           //Toggler for family panel
        {
            if (MyInstanceID.IsEmpty)
            {
                return;
            }

            object L = GetPrivateVariable <object>(InstanceManager.instance, "m_lock");

            do
            {
            }while (!Monitor.TryEnter(L, SimulationManager.SYNCHRONIZE_TIMEOUT));

            try
            {
                InstanceManager MyInstance = Singleton <InstanceManager> .instance;
                CitizenManager  MyCitizen  = Singleton <CitizenManager> .instance;

                uint   citizen   = MyInstanceID.Citizen;
                string Name      = MyCitizen.GetCitizenName(citizen);
                int    citizenID = (int)((UIntPtr)citizen);

                if (Name != null && Name.Length > 0)
                {
                    if (!FavCimsCore.RowID.ContainsKey(citizenID))
                    {
                        if (!FavoriteCimsMainPanel.RowsAlreadyExist(MyInstanceID))
                        {
                            try {
                                MyInstance.SetName(MyInstanceID, Name);
                                CitizenRow FavCimsCitizenSingleRowPanel = FavoriteCimsMainPanel.FavCimsCitizenRowsPanel.AddUIComponent(typeof(CitizenRow)) as CitizenRow;
                                if (FavCimsCitizenSingleRowPanel != null)
                                {
                                    FavCimsCitizenSingleRowPanel.MyInstanceID    = MyInstanceID;
                                    FavCimsCitizenSingleRowPanel.MyInstancedName = Name;
                                }
                            }catch (Exception e) {
                                Debug.Error("Add To Favorites Fail : " + e.ToString());
                            }
                        }
                        else
                        {
                            return;
                        }
                    }
                    else
                    {
                        RemoveRowAndRemoveFav(MyInstanceID, citizenID);
                    }
                }
            }
            finally
            {
                Monitor.Exit(L);
            }
            return;
        }
        /// <summary>
        /// Building Service requests wrapper
        /// </summary>
        public static bool IsBuildingTransferAllowed(ushort buildingID, ref Building data,
                                                     TransferManager.TransferReason reason, TransferManager.TransferOffer offer,
                                                     bool summarizedLog = false)
        {
            DistrictManager districtManager = Singleton <DistrictManager> .instance;
            BuildingManager buildingManager = Singleton <BuildingManager> .instance;
            CitizenManager  citizenManager  = Singleton <CitizenManager> .instance;
            Building        srcBuilding     = buildingManager.m_buildings.m_buffer[(int)buildingID];
            Building        dstBuilding     = buildingManager.m_buildings.m_buffer[(int)offer.Building];
            ushort          dstBuildingId   = offer.Building;

            //fix for services based on resident instead of building:
            if (offer.Building == 0 && offer.Citizen != 0)
            {
                dstBuildingId = citizenManager.m_citizens.m_buffer[offer.Citizen].GetBuildingByLocation();
                dstBuilding   = buildingManager.m_buildings.m_buffer[dstBuildingId];

                //still no building -> citizen out in the wild (e.g. waiting for taxi)
                if (dstBuildingId == 0)
                {
                    var instid = citizenManager.m_citizens.m_buffer[offer.Citizen].m_instance;
                    dstBuilding.m_position = citizenManager.m_instances.m_buffer[instid].GetLastFramePosition(); //pass by value, overwrite OK
                }
            }

            string srcBuildingName = buildingManager.GetBuildingName(buildingID, InstanceID.Empty);
            string dstBuildingName = buildingManager.GetBuildingName(dstBuildingId, InstanceID.Empty);
            string dstCitizenName  = citizenManager.GetCitizenName(offer.Citizen);
            string srcDistrictName = FindDistrictName(srcBuilding.m_position);
            string dstDistrictName = FindDistrictName(dstBuilding.m_position);

            bool allowed = DistrictChecker.IsTransferAllowed(data.m_position, dstBuilding.m_position, buildingID, dstBuildingId, reason, false);

            if (summarizedLog)
            {
                Utils.LogBuilding(String.Format("   - Building #{0} queried (allowed: {1})", buildingID, allowed));
            }
            else
            {
                Utils.LogBuilding("------------------------------------------------------------"
                                  + String.Format("\nBuilding #{0} queried (allowed: {1})", buildingID, allowed)
                                  + String.Format("\n - Transfer: reason={0}, offer={1}", reason, Utils.ToString(offer))
                                  + String.Format("\n - Origin: {0}", srcBuildingName)
                                  + String.Format("\n - Destination: building='{0}', citizen='{1}'", dstBuildingName, dstCitizenName)
                                  + String.Format("\n - District: {0} -> {1}", srcDistrictName, dstDistrictName));
            }

            return(allowed);
        }
        public override string GetSenderName()
        {
            CitizenManager instance = Singleton <CitizenManager> .instance;

            return(instance.GetCitizenName(m_senderID) ?? instance.GetDefaultCitizenName(m_senderID));
        }
        public override void Update()
        {
            if (FavCimsMainClass.UnLoading)
            {
                return;
            }

            if (this.isVisible)
            {
                if (!HumanWorldInfoPanel.GetCurrentInstanceID().IsEmpty)
                {
                    ThisHuman = HumanWorldInfoPanel.GetCurrentInstanceID();
                    int    citizenID   = (int)((UIntPtr)ThisHuman.Citizen);
                    string CitizenName = MyInstance.GetName(ThisHuman);

                    if (CitizenName != null && CitizenName.Length > 0)
                    {
                        this.tooltip        = FavCimsLang.text("FavStarButton_disable_tooltip");
                        this.normalBgSprite = "icon_fav_subscribed";

                        if (!FavCimsCore.RowID.ContainsKey(citizenID) && !FavoriteCimsMainPanel.RowsAlreadyExist(ThisHuman))
                        {
                            object L = FavCimsCore.GetPrivateVariable <object>(InstanceManager.instance, "m_lock");
                            do
                            {
                            }while (!Monitor.TryEnter(L, SimulationManager.SYNCHRONIZE_TIMEOUT));

                            try
                            {
                                CitizenRow FavCimsCitizenSingleRowPanel = FavoriteCimsMainPanel.FavCimsCitizenRowsPanel.AddUIComponent(typeof(CitizenRow)) as CitizenRow;
                                if (FavCimsCitizenSingleRowPanel != null)
                                {
                                    FavCimsCitizenSingleRowPanel.MyInstanceID    = ThisHuman;
                                    FavCimsCitizenSingleRowPanel.MyInstancedName = CitizenName;
                                }
                            }
                            finally
                            {
                                Monitor.Exit(L);
                            }
                        }

                        return;
                    }
                    else
                    {
                        if (citizenID != 0 && FavCimsCore.RowID.ContainsKey(citizenID))
                        {
                            MyInstance.SetName(ThisHuman, MyCitizen.GetCitizenName(ThisHuman.Citizen));
                            this.tooltip        = FavCimsLang.text("FavStarButton_disable_tooltip");
                            this.normalBgSprite = "icon_fav_subscribed";
                        }
                        else
                        {
                            this.tooltip        = FavCimsLang.text("FavStarButton_enable_tooltip");
                            this.normalBgSprite = "icon_fav_unsubscribed";
                        }
                    }
                }
            }
        }