void cScreenCentreManagement::ViewSelectedGirl()
{
	if (selected_girl)
	{
		if (GirlDead(selected_girl)) return;

		//load up the cycle_girls vector with the ordered list of girl IDs
		FillSortedIDList(girllist_id, &cycle_girls, &cycle_pos);
		for (int i = cycle_girls.size(); i-- > 0;)
		{  // no viewing dead girls
			if (g_Centre.GetGirl(g_CurrCentre, cycle_girls[i])->health() <= 0)
				cycle_girls.erase(cycle_girls.begin() + i);
		}

		g_InitWin = true;
		g_WinManager.push("Girl Details");
		return;
	}
}
void cScreenGirlDetails::check_events()
{
	// no events means we can go home
	if (g_InterfaceEvents.GetNumEvents() == 0) return;

	// if it's the back button, pop the window off the stack and we're done
	if (g_InterfaceEvents.CheckButton(back_id))
	{
		g_InitWin = true;
		g_WinManager.Pop();
		return;
	}
	if (g_InterfaceEvents.CheckSlider(houseperc_id))
	{
		g_Girls.SetStat(selected_girl, STAT_HOUSE, SliderValue(houseperc_id));
		ss.str("");
		ss << gettext("House Percentage: ") << SliderValue(houseperc_id) << gettext("%");
		EditTextItem(ss.str(), housepercval_id);
		// Rebelliousness might have changed, so update details
		if (DetailLevel == 0)
		{
			string detail = g_Girls.GetDetailsString(selected_girl);
			EditTextItem(detail, girldesc_id);
		}
		return;
	}
	if (g_InterfaceEvents.CheckButton(more_id))
	{
		if (DetailLevel == 0)		{ DetailLevel = 1; EditTextItem(g_Girls.GetMoreDetailsString(selected_girl), girldesc_id); }
		else if (DetailLevel == 1)	{ DetailLevel = 2; EditTextItem(g_Girls.GetThirdDetailsString(selected_girl), girldesc_id); }
		else						{ DetailLevel = 0; EditTextItem(g_Girls.GetDetailsString(selected_girl), girldesc_id); }
	}
	if (g_InterfaceEvents.CheckButton(day_id))
	{
		DisableButton(day_id, true);
		DisableButton(night_id, false);
		g_InitWin = true;
		Day0Night1 = SHIFT_DAY;
	}
	if (g_InterfaceEvents.CheckButton(night_id))
	{
		DisableButton(day_id, false);
		DisableButton(night_id, true);
		g_InitWin = true;
		Day0Night1 = SHIFT_NIGHT;
	}
	if (g_InterfaceEvents.CheckCheckbox(antipreg_id))
	{
		selected_girl->m_UseAntiPreg = (IsCheckboxOn(antipreg_id));
	}
	if (g_InterfaceEvents.CheckListbox(traitlist_id))
	{
		int selection = GetLastSelectedItemFromList(traitlist_id);
		if (selection != -1)
			EditTextItem(selected_girl->m_Traits[selection]->m_Desc, traitdesc_id);
		else
			EditTextItem("", traitdesc_id);
	}
	if (g_InterfaceEvents.CheckListbox(jobtypelist_id))
	{
		SetJob = true;
		RefreshJobList();
	}
	if (g_InterfaceEvents.CheckListbox(joblist_id))
	{
		bool fulltime = g_CTRLDown;

		int selection = GetSelectedItemFromList(joblist_id);
		if (selection != -1)
		{
			int old_job = (Day0Night1 ? selected_girl->m_NightJob : selected_girl->m_DayJob);
			// handle special job requirements and assign - if HandleSpecialJobs returns true, the job assignment was modified or cancelled
			if (g_Brothels.m_JobManager.HandleSpecialJobs(g_CurrBrothel, selected_girl, selection, old_job, Day0Night1, fulltime))
			{
				selection = (Day0Night1 ? selected_girl->m_NightJob : selected_girl->m_DayJob);
				SetSelectedItemInList(joblist_id, selection, false);
			}
			// refresh job worker counts for former job and current job
			if (old_job != selection)
			{
				SetSelectedItemText(joblist_id, old_job, g_Brothels.m_JobManager.JobDescriptionCount(old_job, g_CurrBrothel, Day0Night1));
				SetSelectedItemText(joblist_id, selection, g_Brothels.m_JobManager.JobDescriptionCount(selection, g_CurrBrothel, Day0Night1));
			}
			RefreshJobList();
		}
	}
	if (g_InterfaceEvents.CheckButton(inventory_id))
	{
		if (selected_girl)
		{
			if (GirlDead(selected_girl)) return;
			g_InitWin = true;
			g_AllTogle = true;
			g_WinManager.push("Item Management");
			return;
		}
	}
	if (g_InterfaceEvents.CheckButton(gallery_id))
	{
		g_WinManager.push("Gallery");
		g_InitWin = true;
		return;
	}


	if (g_InterfaceEvents.CheckSlider(accom_id))
	{
		selected_girl->m_AccLevel = SliderValue(accom_id);
		SliderRange(accom_id, 0, 9, selected_girl->m_AccLevel, 1);
		if (accomval_id != -1)
		{
			stringstream acc;
			acc << "Accommodation: " << g_Girls.Accommodation(SliderValue(accom_id));
			if (cfg.debug.log_extradetails())
			{
				int val = SliderValue(accom_id) - g_Girls.PreferredAccom(selected_girl);
				if (val != 0) acc << "  ( " << (val > 0 ? "+" : "") << val << " )";
			}
			EditTextItem(acc.str(), accomval_id);
		}
		g_InitWin = true;
		return;
	}
	if (g_InterfaceEvents.CheckButton(accomup_id))
	{
		if (selected_girl->m_AccLevel + 1 > 9)
			selected_girl->m_AccLevel = 9;
		else
			selected_girl->m_AccLevel++;
		if (accomval_id != -1) EditTextItem("Accommodation: " + g_Girls.Accommodation(selected_girl->m_AccLevel), accomval_id);

		g_InitWin = true;
		return;
	}
	if (g_InterfaceEvents.CheckButton(accomdown_id))
	{
		if (selected_girl->m_AccLevel - 1 < 0)	selected_girl->m_AccLevel = 0;
		else									selected_girl->m_AccLevel--;
		if (accomval_id != -1) EditTextItem("Accommodation: " + g_Girls.Accommodation(selected_girl->m_AccLevel), accomval_id);

		g_InitWin = true;
		return;
	}
	if (g_InterfaceEvents.CheckButton(takegold_id))
	{
		take_gold(selected_girl);
	}
	if (g_InterfaceEvents.CheckButton(reldungeon_id))
	{
		g_Brothels.GetDungeon()->GetDungeonPos(selected_girl);
		if ((g_Brothels.GetBrothel(g_CurrBrothel)->m_NumRooms - g_Brothels.GetBrothel(g_CurrBrothel)->m_NumGirls) == 0)
		{
			g_MessageQue.AddToQue(gettext("The current brothel has no more room.\nBuy a new one, get rid of some girls, or change the brothel you are currently managing."), 0);
		}
		else
		{
			sGirl* nextGirl = remove_selected_girl();
			sGirl* tempGirl = g_Brothels.GetDungeon()->RemoveGirl(g_Brothels.GetDungeon()->GetGirl(g_Brothels.GetDungeon()->GetGirlPos(selected_girl)));
			g_Brothels.AddGirl(g_CurrBrothel, tempGirl);

			if (g_Brothels.GetDungeon()->GetNumGirls() == 0)
			{
				selected_girl = 0;
				g_WinManager.Pop();
			}
			else
				selected_girl = nextGirl;
		}
		g_InitWin = true;
		return;
	}
	if (g_InterfaceEvents.CheckButton(senddungeon_id))
	{
		ss.str("");
		g_Brothels.GetGirlPos(g_CurrBrothel, selected_girl);

		// does she decide to fight back
		if (g_Brothels.FightsBack(selected_girl))
		{
			bool win = true;
			sGang* gang = g_Gangs.GetGangOnMission(MISS_GUARDING);
			int count = 8;
			while (gang && win && count >= 0)
			{
				win = (g_Gangs.GangCombat(selected_girl, gang));
				if (gang->m_Num == 0) gang = g_Gangs.GetGangOnMission(MISS_GUARDING);
				count--;
				if (count<0) win = true;
			}
			// Calculate combat between goons and girl if she decides to fight back
			if (win)
			{
				ss << gettext("She puts up a fight");
				if (gang && gang->m_Num == 0) ss << gettext(", and the gang is completely wiped out");
				ss << ". ";

				if (g_Brothels.PlayerCombat(selected_girl))				// fight with the player
				{
					// If girl wins she escapes and leaves the brothel
					ss << gettext("After defeating you as well, she escapes to the outside.\n");
					ss << gettext("She will escape for good in 6 weeks if you don't send someone after her.");

					sGirl* nextGirl = remove_selected_girl();
					sGirl* temp = selected_girl;
					if (selected_girl->m_DayJob == JOB_INDUNGEON)	temp = g_Brothels.GetDungeon()->RemoveGirl(selected_girl);
					else if (selected_girl->m_InHouse)	g_House.RemoveGirl(0, selected_girl, false);
					else if (selected_girl->m_InFarm)	g_Farm.RemoveGirl(0, selected_girl, false);
					else if (selected_girl->m_InClinic)	g_Clinic.RemoveGirl(0, selected_girl, false);
					else if (selected_girl->m_InCentre)	g_Centre.RemoveGirl(0, selected_girl, false);
					else if (selected_girl->m_InArena)	g_Arena.RemoveGirl(0, selected_girl, false);
					else if (selected_girl->m_InStudio)	g_Studios.RemoveGirl(0, selected_girl, false);
					else g_Brothels.RemoveGirl(selected_girl->where_is_she, selected_girl, false);

					temp->m_RunAway = 6;
					temp->m_NightJob = temp->m_DayJob = JOB_RUNAWAY;
					g_Brothels.AddGirlToRunaways(temp);

					stringstream smess;
					smess << temp->m_Realname << gettext(" has run away");
					g_MessageQue.AddToQue(smess.str(), 1);

					selected_girl = nextGirl;
					if (selected_girl == 0) g_WinManager.Pop();
				}
				else	// otherwise put her in the dungeon
				{
					int reason = (selected_girl->m_Spotted ? DUNGEON_GIRLSTEAL : DUNGEON_GIRLWHIM);
					sGirl* nextGirl = remove_selected_girl();
					selected_girl->m_DayJob = selected_girl->m_NightJob = JOB_INDUNGEON;

					/* */if (selected_girl->m_InHouse)	g_House.RemoveGirl(0, selected_girl, false);
					else if (selected_girl->m_InFarm)	g_Farm.RemoveGirl(0, selected_girl, false);
					else if (selected_girl->m_InClinic)	g_Clinic.RemoveGirl(0, selected_girl, false);
					else if (selected_girl->m_InCentre)	g_Centre.RemoveGirl(0, selected_girl, false);
					else if (selected_girl->m_InArena)	g_Arena.RemoveGirl(0, selected_girl, false);
					else if (selected_girl->m_InStudio)	g_Studios.RemoveGirl(0, selected_girl, false);
					else g_Brothels.RemoveGirl(selected_girl->where_is_she, selected_girl, false);

					g_Brothels.GetDungeon()->AddGirl(selected_girl, reason);
					ss << gettext("However, you manage to defeat her yourself and place her unconscious body in the dungeon.");

					bool pop = false;
					/* */if (selected_girl->m_InHouse)	if (g_House.GetNumGirls(0) == 0)	pop = true;
					else if (selected_girl->m_InFarm)	if (g_Farm.GetNumGirls(0) == 0)		pop = true;
					else if (selected_girl->m_InClinic)	if (g_Clinic.GetNumGirls(0) == 0)	pop = true;
					else if (selected_girl->m_InCentre)	if (g_Centre.GetNumGirls(0) == 0)	pop = true;
					else if (selected_girl->m_InArena)	if (g_Arena.GetNumGirls(0) == 0)	pop = true;
					else if (selected_girl->m_InStudio)	if (g_Studios.GetNumGirls(0) == 0)	pop = true;
					else if (g_Brothels.GetNumGirls(selected_girl->where_is_she) == 0)		pop = true;

					if (pop)	{ selected_girl = 0; g_WinManager.Pop(); }
					else		selected_girl = nextGirl;
				}
			}
			else	// otherwise put her in the dungeon
			{
				ss << gettext("She puts up a fight ");
				if (gang && gang->m_Num == 0)	ss << gettext("and the gang is wiped out, ");

				ss << gettext("but your goons manage to drag her unconscious to the dungeon.");
				int reason = (selected_girl->m_Spotted ? DUNGEON_GIRLSTEAL : DUNGEON_GIRLWHIM);
				sGirl* nextGirl = remove_selected_girl();

				/* */if (selected_girl->m_InHouse)	g_House.RemoveGirl(0, selected_girl, false);
				else if (selected_girl->m_InFarm)	g_Farm.RemoveGirl(0, selected_girl, false);
				else if (selected_girl->m_InClinic)	g_Clinic.RemoveGirl(0, selected_girl, false);
				else if (selected_girl->m_InCentre)	g_Centre.RemoveGirl(0, selected_girl, false);
				else if (selected_girl->m_InArena)	g_Arena.RemoveGirl(0, selected_girl, false);
				else if (selected_girl->m_InStudio)	g_Studios.RemoveGirl(0, selected_girl, false);
				else g_Brothels.RemoveGirl(selected_girl->where_is_she, selected_girl, false);
				g_Brothels.GetDungeon()->AddGirl(selected_girl, reason);

				bool pop = false;
				/* */if (selected_girl->m_InHouse)	if (g_House.GetNumGirls(0) == 0)	pop = true;
				else if (selected_girl->m_InFarm)	if (g_Farm.GetNumGirls(0) == 0)		pop = true;
				else if (selected_girl->m_InClinic)	if (g_Clinic.GetNumGirls(0) == 0)	pop = true;
				else if (selected_girl->m_InCentre)	if (g_Centre.GetNumGirls(0) == 0)	pop = true;
				else if (selected_girl->m_InArena)	if (g_Arena.GetNumGirls(0) == 0)	pop = true;
				else if (selected_girl->m_InStudio)	if (g_Studios.GetNumGirls(0) == 0)	pop = true;
				else if (g_Brothels.GetNumGirls(selected_girl->where_is_she) == 0)		pop = true;

				if (pop)	{ selected_girl = 0; g_WinManager.Pop(); }
				else		selected_girl = nextGirl;
			}
		}
		else
		{
			int reason = (selected_girl->m_Spotted ? DUNGEON_GIRLSTEAL : DUNGEON_GIRLWHIM);
			sGirl* nextGirl = remove_selected_girl();

			/* */if (selected_girl->m_InHouse)	g_House.RemoveGirl(0, selected_girl, false);
			else if (selected_girl->m_InFarm)	g_Farm.RemoveGirl(0, selected_girl, false);
			else if (selected_girl->m_InClinic)	g_Clinic.RemoveGirl(0, selected_girl, false);
			else if (selected_girl->m_InCentre)	g_Centre.RemoveGirl(0, selected_girl, false);
			else if (selected_girl->m_InArena)	g_Arena.RemoveGirl(0, selected_girl, false);
			else if (selected_girl->m_InStudio)	g_Studios.RemoveGirl(0, selected_girl, false);
			else g_Brothels.RemoveGirl(selected_girl->where_is_she, selected_girl, false);

			g_Brothels.GetDungeon()->AddGirl(selected_girl, reason);
			ss << gettext("She goes quietly with a sullen look on her face.");

			bool pop = false;
			/* */if (selected_girl->m_InHouse)	if (g_House.GetNumGirls(0) == 0)	pop = true;
			else if (selected_girl->m_InFarm)	if (g_Farm.GetNumGirls(0) == 0)		pop = true;
			else if (selected_girl->m_InClinic)	if (g_Clinic.GetNumGirls(0) == 0)	pop = true;
			else if (selected_girl->m_InCentre)	if (g_Centre.GetNumGirls(0) == 0)	pop = true;
			else if (selected_girl->m_InArena)	if (g_Arena.GetNumGirls(0) == 0)	pop = true;
			else if (selected_girl->m_InStudio)	if (g_Studios.GetNumGirls(0) == 0)	pop = true;
			else if (g_Brothels.GetNumGirls(g_CurrBrothel) == 0) /*              */	pop = true;

			if (pop)	{ selected_girl = 0; g_WinManager.Pop(); }
			else		selected_girl = nextGirl;
		}
		g_InitWin = true;
		g_MessageQue.AddToQue(ss.str(), 0);
		return;
	}
	if (g_InterfaceEvents.CheckButton(interact_id))
	{
		if (g_TalkCount > 0)
		{
			DirPath dp;
			eventrunning = true;
			if (selected_girl->m_DayJob != JOB_INDUNGEON)
			{
				int v[2] = { 1, -1 };
				cTrigger* trig = 0;
				if (!(trig = selected_girl->m_Triggers.CheckForScript(TRIGGER_TALK, false, v)))	// trigger any girl specific talk script
				{
					// no, so trigger the default one
					dp = dp << "Resources" << "Scripts" << "DefaultInteractDetails.script";
				}
				else
				{
					// yes, so use that instead
					dp = DirPath(cfg.folders.characters().c_str()) << selected_girl->m_Name << trig->m_Script;
				}
			}
			else
			{
				int v[2] = { 0, -1 };
				cTrigger* trig = 0;
				if (!(trig = selected_girl->m_Triggers.CheckForScript(TRIGGER_TALK, false, v)))	// trigger any girl specific talk script
				{
					// no, so trigger the default one
					dp = dp << "Resources" << "Scripts" << "DefaultInteractDungeon.script";
				}
				else
				{
						dp = DirPath(cfg.folders.characters().c_str()) << selected_girl->m_Name << trig->m_Script;
				}
			}
			cScriptManager script_manager;
			script_manager.Load(dp, selected_girl);
			if (!g_Cheats)
				g_TalkCount--;
		}
		g_InitWin = true;
		return;
	}
	if (g_InterfaceEvents.CheckButton(next_id))
	{
		NextGirl();
	}
	if (g_InterfaceEvents.CheckButton(prev_id))
	{
		PrevGirl();
	}
}
void cScreenCentreManagement::check_events()
{
	// no events means we can go home
	if (g_InterfaceEvents.GetNumEvents() == 0)
		return;

	// if it's the back button, pop the window off the stack and we're done
	if (g_InterfaceEvents.CheckButton(back_id)) {
		g_InitWin = true;
		g_WinManager.Pop();
		return;
	}
	if (g_InterfaceEvents.CheckButton(viewdetails_id))
	{
		ViewSelectedGirl();
	}


	if (g_InterfaceEvents.CheckButton(day_id))
	{
		DisableButton(day_id, true);
		DisableButton(night_id, false);
		Day0Night1 = SHIFT_DAY;
		RefreshSelectedJobType();
	}
	if (g_InterfaceEvents.CheckButton(night_id))
	{
		DisableButton(day_id, false);
		DisableButton(night_id, true);
		Day0Night1 = SHIFT_NIGHT;
		RefreshSelectedJobType();
	}
	if (g_InterfaceEvents.CheckListbox(jobtypelist_id))
	{
		selection = GetSelectedItemFromList(jobtypelist_id);

		if (selection == -1)
			EditTextItem("Nothing Selected", jobtypedesc_id);
		else
		{
			// populate Jobs listbox with jobs in the selected category
			RefreshJobList();
			string jdmessage = g_Centre.m_JobManager.JobFilterDesc[selection];

			if ((g_Centre.GetNumGirlsOnJob(g_CurrCentre, JOB_COUNSELOR, 0) < 1 &&
				g_Centre.GetNumberPatients(0) > 0) ||
				(g_Centre.GetNumGirlsOnJob(g_CurrCentre, JOB_COUNSELOR, 1) < 1 &&
				g_Centre.GetNumberPatients(1) > 0))
			{
				jdmessage += gettext("\n*** A Counselor is required to guide Rehab and Therapy patients. ");
			}
			EditTextItem(jdmessage, jobtypedesc_id);
		}
	}
	if (g_InterfaceEvents.CheckListbox(joblist_id))
	{
		bool fulltime = g_CTRLDown;

		selection = GetSelectedItemFromList(joblist_id);
		if (selection != -1)
		{
			// first handle the descriptions
			EditTextItem(g_Centre.m_JobManager.JobDesc[selection], jobdesc_id);

			// Now assign the job to all the selected girls
			int pos = 0;
			int GSelection = GetNextSelectedItemFromList(girllist_id, 0, pos);
			while (GSelection != -1)
			{
				u_int new_job = selection;
				selected_girl = g_Centre.GetGirl(g_CurrCentre, GSelection);
				if (selected_girl)
				{
					int old_job = (Day0Night1 ? selected_girl->m_NightJob : selected_girl->m_DayJob);

					// handle special job requirements and assign
					// if HandleSpecialJobs returns true, the job assignment was modified or cancelled

					if (g_Centre.m_JobManager.HandleSpecialJobs(g_CurrCentre, selected_girl, new_job, old_job, Day0Night1, fulltime))
					{
						new_job = (Day0Night1 ? selected_girl->m_NightJob : selected_girl->m_DayJob);
						SetSelectedItemInList(joblist_id, new_job, false);
					}

					// update the girl's listing to reflect the job change
					ss.str("");
					ss << g_Centre.m_JobManager.JobName[selected_girl->m_DayJob];
					SetSelectedItemColumnText(girllist_id, GSelection, ss.str(), m_ListBoxes[girllist_id]->DayJobColumn());
					ss.str("");
					ss << g_Centre.m_JobManager.JobName[selected_girl->m_NightJob];
					SetSelectedItemColumnText(girllist_id, GSelection, ss.str(), m_ListBoxes[girllist_id]->NightJobColumn());

					// refresh job worker counts for former job and current job
					SetSelectedItemText(joblist_id, old_job, g_Centre.m_JobManager.JobDescriptionCount(old_job, 0, Day0Night1, false, false, false, true));
					SetSelectedItemText(joblist_id, new_job, g_Centre.m_JobManager.JobDescriptionCount(new_job, 0, Day0Night1, false, false, false, true));
				}
				if (selected_girl->m_DayJob == JOB_REHAB)	// `J` added
				{
					ss.str("");
					ss << g_Centre.m_JobManager.JobName[selected_girl->m_DayJob] << " (" << 3 - selected_girl->m_WorkingDay << ")";
					SetSelectedItemColumnText(girllist_id, GSelection, ss.str(), m_ListBoxes[girllist_id]->DayJobColumn());
				}
				else if (selected_girl->m_YesterDayJob == JOB_REHAB && selected_girl->m_DayJob != JOB_REHAB && ((selected_girl->m_WorkingDay > 0) || selected_girl->m_PrevWorkingDay > 0))
				{
					ss.str("");
					ss << g_Centre.m_JobManager.JobName[selected_girl->m_DayJob] << " **";
					SetSelectedItemColumnText(girllist_id, GSelection, ss.str(), m_ListBoxes[girllist_id]->DayJobColumn());
				}

				if (selected_girl->m_NightJob == JOB_REHAB)	// `J` added
				{
					ss.str("");
					ss << g_Centre.m_JobManager.JobName[selected_girl->m_NightJob] << " (" << 3 - selected_girl->m_WorkingDay << ")";
					SetSelectedItemColumnText(girllist_id, GSelection, ss.str(), m_ListBoxes[girllist_id]->NightJobColumn());
				}
				else if (selected_girl->m_YesterNightJob == JOB_REHAB && selected_girl->m_NightJob != JOB_REHAB && ((selected_girl->m_WorkingDay > 0) || selected_girl->m_PrevWorkingDay > 0))
				{
					ss.str("");
					ss << g_Centre.m_JobManager.JobName[selected_girl->m_NightJob] << " **";
					SetSelectedItemColumnText(girllist_id, GSelection, ss.str(), m_ListBoxes[girllist_id]->NightJobColumn());
				}
				if (selected_girl && selected_girl->m_YesterDayJob == JOB_REHAB && new_job != JOB_REHAB && (selected_girl->m_WorkingDay > 0 || selected_girl->m_PrevWorkingDay > 0))
				{	// `J` added
					EditTextItem(g_Centre.m_JobManager.JobDesc[new_job]
						+ "\n** This girl was in Rehab, if you send her somewhere else, she will have to start her Rehab over."
						, jobdesc_id);
				}
				GSelection = GetNextSelectedItemFromList(girllist_id, pos + 1, pos);
			}
		}
		else	EditTextItem("Nothing Selected", jobdesc_id);
	}

	if (g_InterfaceEvents.CheckListbox(girllist_id))
	{
		selection = GetSelectedItemFromList(girllist_id);
		if (selection != -1)
		{
			selected_girl = g_Centre.GetGirl(g_CurrCentre, selection);
			if (ListDoubleClicked(girllist_id)) ViewSelectedGirl();		// If double-clicked, try to bring up girl details
			DisableButton(freeslave_id, selected_girl->is_free());
			DisableButton(viewdetails_id, false);
			RefreshSelectedJobType();
		}
		else
		{
			DisableButton(freeslave_id, true);
			DisableButton(viewdetails_id, true);
			selected_girl = 0;
			selection = -1;
		}
		lastNum = -2;
		update_image();
		return;
	}
	if (g_InterfaceEvents.CheckButton(freeslave_id))
	{
		if (selected_girl)
		{
			if (IsMultiSelected(girllist_id))
			{  // multiple girls selected
				g_MessageQue.AddToQue("Are you sure you wish to give these girls their freedom?", 0);
				g_ChoiceManager.CreateChoiceBox(224, 112, 352, 384, 0, 2, 32, strlen("Keep as a slaves"));
				g_ChoiceManager.AddChoice(0, "Grant Freedom", 0);
				g_ChoiceManager.AddChoice(0, "Keep as a slaves", 1);
				g_ChoiceManager.SetActive(0);
				FreeGirl = true;
			}
			else  // only one girl selected
			{
				if (GirlDead(selected_girl)) return;
				g_MessageQue.AddToQue("Are you sure you wish to give " + selected_girl->m_Realname + " her freedom?", 0);
				g_ChoiceManager.CreateChoiceBox(224, 112, 352, 384, 0, 2, 32, strlen("Keep as a slave"));
				g_ChoiceManager.AddChoice(0, "Grant Freedom", 0);
				g_ChoiceManager.AddChoice(0, "Keep as a slave", 1);
				g_ChoiceManager.SetActive(0);
				FreeGirl = true;
			}
		}
		return;
	}
	if (g_InterfaceEvents.CheckButton(transfer_id))
	{
		g_InitWin = true;
		g_WinManager.Push(TransferGirls, &g_TransferGirls);
		return;
	}
}
void cScreenCentreManagement::init()
{

	if (FreeGirl)
	{
		if (g_ChoiceManager.GetChoice(0) == 0)
		{
			vector<int> girl_array;
			GetSelectedGirls(&girl_array);  // get and sort array of girls

			for (int i = girl_array.size(); i--> 0;)	// OK, we have the array, now step through it backwards
			{
				selected_girl = g_Centre.GetGirl(g_CurrCentre, girl_array[i]);
				if (GirlDead(selected_girl) || !selected_girl->is_slave()) continue;  // if dead or not a slave, can't free her
				if (selected_girl)
				{
					selected_girl->m_States &= ~(1 << STATUS_SLAVE);
					The_Player->disposition(5);
					g_Girls.UpdateStat(selected_girl, STAT_PCLOVE, 10);
					g_Girls.UpdateStat(selected_girl, STAT_PCFEAR, -20);
					g_Girls.UpdateStat(selected_girl, STAT_PCHATE, -25);
					g_Girls.UpdateStat(selected_girl, STAT_OBEDIENCE, 10);
					g_Girls.UpdateStat(selected_girl, STAT_HAPPINESS, 70);
					
					selected_girl->m_AccLevel = cfg.initial.girls_accom();
					selected_girl->m_Stats[STAT_HOUSE] = cfg.initial.girls_house_perc();
					g_InitWin = true;
				}
			}
		}
		g_ChoiceManager.Free();
		FreeGirl = false;
	}

	g_CurrentScreen = SCREEN_CENTRE;
	if (!g_InitWin) return;

	Focused();
	g_InitWin = false;


	////////////////////

	selection = GetSelectedItemFromList(girllist_id);
	string centre;
	centre += g_Centre.GetName(g_CurrCentre);
	EditTextItem(centre, curcentre_id);

	//selected_girl = 0;

	// clear the lists
	ClearListBox(girllist_id);
	ClearListBox(jobtypelist_id);

	// add the job filters
	//	for(int i=0; i<NUMJOBTYPES; i++)  // loop through all job types
	AddToListBox(jobtypelist_id, JOBFILTER_COMMUNITYCENTRE, g_Centre.m_JobManager.JobFilterName[JOBFILTER_COMMUNITYCENTRE]);
	AddToListBox(jobtypelist_id, JOBFILTER_COUNSELINGCENTRE, g_Centre.m_JobManager.JobFilterName[JOBFILTER_COUNSELINGCENTRE]);
	RefreshJobList();
	SetSelectedItemInList(jobtypelist_id, JOBFILTER_COMMUNITYCENTRE);

	//get a list of all the column names, so we can find which data goes in that column
	vector<string> columnNames;
	m_ListBoxes[girllist_id]->GetColumnNames(columnNames);
	int numColumns = columnNames.size();
	string* Data = new string[numColumns];

	// Add girls to list
	for (int i = 0; i<g_Centre.GetNumGirls(g_CurrCentre); i++)
	{
		sGirl* gir = g_Centre.GetGirl(g_CurrCentre, i);
		if (selected_girl == gir)
			selection = i;

		unsigned int item_color = COLOR_BLUE;
		if (g_Girls.GetStat(gir, STAT_HEALTH) <= 30 || g_Girls.GetStat(gir, STAT_TIREDNESS) >= 80 || g_Girls.GetStat(gir, STAT_HAPPINESS) <= 30)
			item_color = COLOR_RED;

		gir->OutputGirlRow(Data, columnNames);
		AddToListBox(girllist_id, i, Data, numColumns, item_color);
	}
	delete[] Data;

	lastNum = -1;
	g_InitWin = false;

	if (selection >= 0)
	{
		while (selection > GetListBoxSize(girllist_id) && selection != -1)
			selection--;
	}
	if (selection >= 0)
		SetSelectedItemInList(girllist_id, selection);
	else
		SetSelectedItemInList(girllist_id, 0);

	DisableButton(day_id, (Day0Night1 == SHIFT_DAY));
	DisableButton(night_id, (Day0Night1 == SHIFT_NIGHT));

	update_image();
}