func void pc_sleep_random(var int hour,var int minute)
{
	var int hitheal;
	var int hitmana;
	var int hit;
	var int hitmax;
	var int hitdelta;
	var int hithealhit;
	var int staminares;
	var int rnd_scream;
	AI_StopProcessInfos(self);
	player_mobsi_production = MOBSI_NONE;
	self.aivar[AIV_INVINCIBLE] = FALSE;
	hit = hero.attribute[ATR_HITPOINTS];
	hitmax = hero.attribute[ATR_HITPOINTS_MAX];
	hitdelta = hitmax - hit;
	hitheal = hitmax / sleepdis;
	if(hitheal <= 0)
	{
		hitheal = 1;
	};
	Wld_StopEffect("DEMENTOR_FX");
	if(SC_IsObsessed == TRUE)
	{
		PrintScreen(PRINT_SleepOverObsessed,-1,-1,FONT_Screen,2);
		rnd_scream = Hlp_Random(100);
		if(rnd_scream >= 60)
		{
			Snd_Play("ZOM_DIE");
		}
		else if(rnd_scream >= 30)
		{
			Snd_Play("ZOM_DIE_A1");
		}
		else
		{
			Snd_Play("ZOM_DIE_A2");
		};
	}
	else if(poisoned == TRUE)
	{
		PrintScreen(PRINT_SLEEPOVERPOISONED,-1,-1,FONT_Screen,2);
		rnd_scream = Hlp_Random(100);
		if(rnd_scream >= 60)
		{
		}
		else if(rnd_scream >= 30)
		{
		}
		else
		{
		};
	}
	else
	{
		if((hour != 0) || (minute != 0))
		{
			rnd_scream = Hlp_Random(4);
			if(rnd_scream == 0)
			{
			}
			else if(rnd_scream == 1)
			{
			}
			else if(rnd_scream == 2)
			{
			}
			else
			{
			};
			hithealhit = hour * hitheal;
			hithealhit = hithealhit + hit;
			if(sbmode == TRUE)
			{
				if(hithealhit >= hero.attribute[ATR_HITPOINTS_MAX])
				{
					hero.attribute[ATR_HITPOINTS] = hero.attribute[ATR_HITPOINTS_MAX];
				}
				else
				{
					hero.attribute[ATR_HITPOINTS] = hithealhit;
				};
			}
			else
			{
				hero.attribute[ATR_HITPOINTS] = hero.attribute[ATR_HITPOINTS_MAX];
			};
			if(sbmode == TRUE)
			{
				staminares = (atr_stamina_max * 10) / 5;
				atr_stamina = atr_stamina + (staminares * hour);
			}
			else
			{
				atr_stamina = atr_stamina_max * 10;
			};
			if(atr_stamina > (atr_stamina_max * 10))
			{
				atr_stamina = atr_stamina_max * 10;
			};
			if((hero.guild == GIL_KDF) || (hero.guild == GIL_KDW) || (hero.guild == GIL_KDM) || (hero.guild == GIL_GUR))
			{
				hit = hero.attribute[ATR_MANA];
				hitmax = hero.attribute[ATR_MANA_MAX];
				hitdelta = hitmax - hit;
				hitheal = hitmax / sleepdis;
				if(hitheal <= 0)
				{
					hitheal = 1;
				};
				hithealhit = hour * hitheal;
				hithealhit = hithealhit + hit;
				if(hithealhit >= hero.attribute[ATR_MANA_MAX])
				{
					hero.attribute[ATR_MANA] = hero.attribute[ATR_MANA_MAX];
				}
				else
				{
					hero.attribute[ATR_MANA] = hithealhit;
				};
			};
			if(sleeponground == TRUE)
			{
				AI_PlayAni(hero,"T_SLEEPGROUND_2_STAND");
				sleeponground = FALSE;
			};
			print_percent_bar(atr_stamina,atr_stamina_max * 10,"Выносливость",42,97);
			PrintGlobals(PD_ITEM_MOBSI);
			Npc_SendPassivePerc(hero,PERC_ASSESSENTERROOM,NULL,hero);
			if(TORCHISON == FALSE)
			{
				Mdl_RemoveOverlayMds(hero,"HUMANS_NEWTORCH.MDS");
			};
			return;
		};
		if(sleepdis == 24)
		{
			if(timestosl2 == 5)
			{
				timestosl2 = 0;
				pc_sleep_daydelt.hour2 = hourrnd + hour1;
				pc_sleep_random(hourrnd,0);
				Wld_SetTime(pc_sleep_daydelt.hour2,0);
			}
			else if(timestosl1 == 5)
			{
				if(hour1 < 5)
				{
					hourrnd = 5 - hour1;
					pc_sleep_random(hourrnd,0);
					Wld_SetTime(5,0);
				}
				else
				{
					hourrnd = (24 - hour1) + 5;
					pc_sleep_random(hourrnd,0);
					Wld_SetTime(29,0);
				};
			}
			else if(timestosl1 == 8)
			{
				if(hour1 < 8)
				{
					hourrnd = 8 - hour1;
					pc_sleep_random(hourrnd,0);
					Wld_SetTime(8,0);
				}
				else
				{
					hourrnd = (24 - hour1) + 8;
					pc_sleep_random(hourrnd,0);
					Wld_SetTime(32,0);
				};
			}
			else if(timestosl1 == 12)
			{
				if(hour1 < 12)
				{
					hourrnd = 12 - hour1;
					pc_sleep_random(hourrnd,0);
					Wld_SetTime(12,0);
				}
				else
				{
					hourrnd = (24 - hour1) + 12;
					pc_sleep_random(hourrnd,0);
					Wld_SetTime(36,0);
				};
			}
			else if(timestosl1 == 21)
			{
				if(hour1 < 21)
				{
					hourrnd = 21 - hour1;
					pc_sleep_random(hourrnd,0);
					Wld_SetTime(21,0);
				}
				else
				{
					hourrnd = (24 - hour1) + 21;
					pc_sleep_random(hourrnd,0);
					Wld_SetTime(45,0);
				};
			}
			else if(timestosl1 == 24)
			{
				hourrnd = 24 - hour1;
				pc_sleep_random(hourrnd,0);
				Wld_SetTime(24,0);
			};
			timestosl1 = 0;
			sleephour += hourrnd;
		}
		else if(daysleep != Wld_GetDay())
		{
			daysleep = Wld_GetDay();
			daysleephour = 0;
			if(timestosl2 == 5)
			{
				timestosl2 = 0;
				pc_sleep_daydelt.hour2 = hourrnd + hour1;
				if(sleepdis == 24)
				{
					pc_sleep_random(hourrnd,0);
					Wld_SetTime(pc_sleep_daydelt.hour2,0);
				}
				else
				{
					if(hourrnd > 9)
					{
						hourrnd = 9;
						pc_sleep_daydelt.hour2 = hourrnd + hour1;
					};
					if(pc_sleep_daydelt.hour2 <= 24)
					{
						daysleephour = hourrnd;
					}
					else
					{
						daysleephour = pc_sleep_daydelt.hour2 - 24;
						daysleep = Wld_GetDay() + 1;
					};
					pc_sleep_random(hourrnd,0);
					Wld_SetTime(pc_sleep_daydelt.hour2,0);
				};
				sleephour += hourrnd;
			}
			else if(timestosl1 == 5)
			{
				timestosl1 = 0;
				if(Wld_IsTime(16,0,23,59))
				{
					pc_sleep_daydelt.hour2 = hour1 + 9;
					pc_sleep_daydelt.hour3 = (hour1 + 9) - 24;
					daysleep = Wld_GetDay() + 1;
					daysleephour = pc_sleep_daydelt.hour3;
					pc_sleep_random(9,0);
					Wld_SetTime(pc_sleep_daydelt.hour2,0);
				}
				else if(Wld_IsTime(0,0,4,59))
				{
					pc_sleep_daydelt.hour2 = 5 - hour1;
					daysleephour = pc_sleep_daydelt.hour2;
					pc_sleep_random(pc_sleep_daydelt.hour2,0);
					Wld_SetTime(5,0);
				}
				else if(Wld_IsTime(15,0,15,59))
				{
					daysleephour = 0;
					pc_sleep_random(9,0);
					Wld_SetTime(24,0);
				}
				else if((hour1 + 9) < 24)
				{
					hour1 += 9;
					daysleephour = 9;
					pc_sleep_random(9,0);
					Wld_SetTime(hour1,0);
				};
				sleephour += daysleephour;
			}
			else if(timestosl1 == 8)
			{
				timestosl1 = 0;
				if(Wld_IsTime(16,0,23,59))
				{
					pc_sleep_daydelt.hour2 = hour1 + 9;
					pc_sleep_daydelt.hour3 = (hour1 + 9) - 24;
					daysleep = Wld_GetDay() + 1;
					daysleephour = pc_sleep_daydelt.hour3;
					pc_sleep_random(9,0);
					Wld_SetTime(pc_sleep_daydelt.hour2,0);
				}
				else if(Wld_IsTime(0,0,7,59))
				{
					pc_sleep_daydelt.hour2 = 8 - hour1;
					pc_sleep_random(pc_sleep_daydelt.hour2,0);
					daysleephour = pc_sleep_daydelt.hour2;
					Wld_SetTime(8,0);
				}
				else if(Wld_IsTime(15,0,15,59))
				{
					daysleephour = 0;
					pc_sleep_random(9,0);
					Wld_SetTime(24,0);
				}
				else if((hour1 + 9) < 24)
				{
					hour1 += 9;
					daysleephour = 9;
					pc_sleep_random(9,0);
					Wld_SetTime(hour1,0);
				};
				sleephour += daysleephour;
			}
			else if(timestosl1 == 12)
			{
				timestosl1 = 0;
				if(Wld_IsTime(16,0,23,59))
				{
					pc_sleep_daydelt.hour2 = hour1 + 9;
					pc_sleep_random(9,0);
					pc_sleep_daydelt.hour3 = (hour1 + 9) - 24;
					daysleep = Wld_GetDay() + 1;
					daysleephour = pc_sleep_daydelt.hour3;
					Wld_SetTime(pc_sleep_daydelt.hour2,0);
				}
				else if(Wld_IsTime(0,0,11,59))
				{
					pc_sleep_daydelt.hour2 = 12 - hour1;
					pc_sleep_random(pc_sleep_daydelt.hour2,0);
					daysleephour = pc_sleep_daydelt.hour2;
					Wld_SetTime(12,0);
				}
				else if(Wld_IsTime(15,0,15,59))
				{
					daysleephour = 0;
					pc_sleep_random(9,0);
					Wld_SetTime(24,0);
				}
				else if((hour1 + 9) < 24)
				{
					hour1 += 9;
					daysleephour = 9;
					pc_sleep_random(9,0);
					Wld_SetTime(hour1,0);
				};
				sleephour += daysleephour;
			}
			else
			{
				if(timestosl1 == 21)
				{
					timestosl1 = 0;
					if(Wld_IsTime(12,0,20,59))
					{
						pc_sleep_daydelt.hour2 = 21 - hour1;
						daysleephour = pc_sleep_daydelt.hour2;
						pc_sleep_random(pc_sleep_daydelt.hour2,0);
						Wld_SetTime(21,0);
					}
					else if(Wld_IsTime(21,0,23,59))
					{
						pc_sleep_daydelt.hour2 = hour1 + 9;
						pc_sleep_daydelt.hour3 = (hour1 + 9) - 24;
						daysleep = Wld_GetDay() + 1;
						daysleephour = pc_sleep_daydelt.hour3;
						pc_sleep_random(9,0);
						Wld_SetTime(pc_sleep_daydelt.hour2,0);
					}
					else if((hour1 + 9) < 24)
					{
						hour1 += 9;
						daysleephour = 9;
						pc_sleep_random(9,0);
						Wld_SetTime(hour1,0);
					};
					sleephour += daysleephour;
				};
				if(timestosl1 == 24)
				{
					timestosl1 = 0;
					if(Wld_IsTime(15,0,23,59))
					{
						pc_sleep_daydelt.hour2 = 24 - hour1;
						pc_sleep_random(pc_sleep_daydelt.hour2,0);
						daysleephour = pc_sleep_daydelt.hour2;
						Wld_SetTime(24,0);
					}
					else if((hour1 + 9) < 24)
					{
						hour1 += 9;
						daysleephour = 9;
						pc_sleep_random(9,0);
						Wld_SetTime(hour1,0);
					};
					sleephour += daysleephour;
				};
			};
		}
		else if(daysleephour >= 9)
		{
			PrintScreen("Вы не хотите спать!",-1,30,FONT_Screen,2);
			pc_sleep_random(0,0);
		}
		else if((daysleephour < 9) && (daysleep == Wld_GetDay()))
		{
			if((9 - daysleephour) >= 0)
			{
				if(timestosl1 == 5)
				{
					timestosl1 = 0;
					hour1delt = 9 - daysleephour;
					if(((hour1delt + hour1) >= 5) && (hour1 < 5))
					{
						hour1delt = 5 - hour1;
						daysleephour += hour1delt;
						pc_sleep_random(hour1delt,0);
						Wld_SetTime(5,0);
						if(daysleephour <= 9)
						{
							PrintScreen("Вы хорошо выспались!",-1,50,FONT_Screen,2);
						};
					}
					else if(((hour1delt + hour1) < 5) && (hour1 < 5))
					{
						pc_sleep_daydelt.hour2 = hour1delt + hour1;
						daysleephour += hour1delt;
						pc_sleep_random(hour1delt,0);
						Wld_SetTime(pc_sleep_daydelt.hour2,0);
					}
					else if((hour1delt + hour1) >= 24)
					{
						hour1delt = (24 - hour1) + 5;
						daysleep = Wld_GetDay() + 1;
						daysleephour = 5;
						pc_sleep_random(hour1delt,0);
						Wld_SetTime(29,0);
					}
					else
					{
						daysleephour += hour1delt;
						hour1 += hour1delt;
						pc_sleep_random(hour1delt,0);
						Wld_SetTime(hour1,0);
						PrintScreen("Нет времени спать...",-1,50,FONT_Screen,2);
					};
					sleephour += hour1delt;
				}
				else if(timestosl1 == 8)
				{
					timestosl1 = 0;
					hour1delt = 9 - daysleephour;
					if(((hour1delt + hour1) >= 8) && (hour1 < 8))
					{
						hour1delt = 8 - hour1;
						daysleephour += hour1delt;
						pc_sleep_random(hour1delt,0);
						Wld_SetTime(8,0);
						if(daysleephour <= 9)
						{
							PrintScreen("Вы хорошо выспались!",-1,50,FONT_Screen,2);
						};
					}
					else if(((hour1delt + hour1) < 8) && (hour1 < 8))
					{
						pc_sleep_daydelt.hour2 = hour1delt + hour1;
						daysleephour += hour1delt;
						pc_sleep_random(hour1delt,0);
						Wld_SetTime(pc_sleep_daydelt.hour2,0);
					}
					else if((hour1delt + hour1) >= 24)
					{
						hour1delt = (24 - hour1) + 8;
						daysleep = Wld_GetDay() + 1;
						daysleephour = 8;
						pc_sleep_random(hour1delt,0);
						Wld_SetTime(32,0);
					}
					else
					{
						daysleephour += hour1delt;
						hour1 += hour1delt;
						pc_sleep_random(hour1delt,0);
						Wld_SetTime(hour1,0);
						PrintScreen("Нет времени спать...",-1,50,FONT_Screen,2);
					};
					sleephour += hour1delt;
				}
				else if(timestosl1 == 12)
				{
					timestosl1 = 0;
					hour1delt = 9 - daysleephour;
					if(((hour1delt + hour1) >= 12) && (hour1 < 12))
					{
						hour1delt = 12 - hour1;
						daysleephour += hour1delt;
						pc_sleep_random(hour1delt,0);
						Wld_SetTime(12,0);
						if(daysleephour <= 9)
						{
							PrintScreen("Вы хорошо выспались!",-1,50,FONT_Screen,2);
						};
					}
					else if(((hour1delt + hour1) < 12) && (hour1 < 12))
					{
						pc_sleep_daydelt.hour2 = hour1delt + hour1;
						daysleephour += hour1delt;
						pc_sleep_random(hour1delt,0);
						Wld_SetTime(pc_sleep_daydelt.hour2,0);
					}
					else if((hour1delt + hour1) >= 24)
					{
						hour1delt = (24 - hour1) + 9;
						daysleep = Wld_GetDay() + 1;
						daysleephour = 9;
						pc_sleep_random(hour1delt,0);
						Wld_SetTime(33,0);
					}
					else
					{
						daysleephour += hour1delt;
						hour1 += hour1delt;
						pc_sleep_random(hour1delt,0);
						Wld_SetTime(hour1,0);
						PrintScreen("Нет времени спать...",-1,50,FONT_Screen,2);
					};
					sleephour += hour1delt;
				}
				else if(timestosl1 == 21)
				{
					timestosl1 = 0;
					hour1delt = 9 - daysleephour;
					if(((hour1delt + hour1) >= 21) && (hour1 < 21))
					{
						hour1delt = 21 - hour1;
						daysleephour += hour1delt;
						pc_sleep_random(hour1delt,0);
						Wld_SetTime(21,0);
						if(daysleephour <= 9)
						{
							PrintScreen("Вы хорошо выспались!",-1,50,FONT_Screen,2);
						};
					}
					else if(((hour1delt + hour1) < 21) && (hour1 < 21))
					{
						pc_sleep_daydelt.hour2 = hour1delt + hour1;
						daysleephour += hour1delt;
						pc_sleep_random(hour1delt,0);
						Wld_SetTime(pc_sleep_daydelt.hour2,0);
					}
					else if((hour1delt + hour1) >= 24)
					{
						hour1delt = (24 - hour1) + 9;
						daysleephour = 9;
						daysleep = Wld_GetDay() + 1;
						pc_sleep_random(hour1delt,0);
						Wld_SetTime(33,0);
					}
					else
					{
						daysleephour += hour1delt;
						hour1 += hour1delt;
						pc_sleep_random(hour1delt,0);
						Wld_SetTime(hour1,0);
						PrintScreen("Нет времени спать...",-1,50,FONT_Screen,2);
					};
					sleephour += hour1delt;
				}
				else if(timestosl1 == 24)
				{
					timestosl1 = 0;
					hour1delt = 9 - daysleephour;
					if(((hour1delt + hour1) >= 24) && (hour1 < 24))
					{
						hour1delt = 24 - hour1;
						daysleephour += hour1delt;
						pc_sleep_random(hour1delt,0);
						Wld_SetTime(24,0);
						if(daysleephour <= 9)
						{
							PrintScreen("Вы хорошо выспались!",-1,50,FONT_Screen,2);
						};
					}
					else if(((hour1delt + hour1) < 24) && (hour1 < 24))
					{
						pc_sleep_daydelt.hour2 = hour1delt + hour1;
						daysleephour += hour1delt;
						pc_sleep_random(hour1delt,0);
						Wld_SetTime(pc_sleep_daydelt.hour2,0);
					}
					else
					{
						daysleephour += hour1delt;
						hour1 += hour1delt;
						pc_sleep_random(hour1delt,0);
						Wld_SetTime(hour1,0);
						PrintScreen("Нет времени спать...",-1,50,FONT_Screen,2);
					};
					sleephour += hour1delt;
				}
				else if(timestosl2 == 5)
				{
					timestosl2 = 0;
					if((hourrnd + daysleephour) > 9)
					{
						hourrnd = 9 - daysleephour;
						pc_sleep_daydelt.hour2 = hourrnd + hour1;
						PrintScreen("Нет времени спать...",-1,50,FONT_Screen,2);
					}
					else
					{
						pc_sleep_daydelt.hour2 = hourrnd + hour1;
					};
					if((hourrnd + hour1) <= 24)
					{
						daysleephour += hourrnd;
					}
					else
					{
						daysleephour = pc_sleep_daydelt.hour2 - 24;
						daysleep = Wld_GetDay() + 1;
					};
					pc_sleep_random(hourrnd,0);
					Wld_SetTime(pc_sleep_daydelt.hour2,0);
					sleephour += hourrnd;
				};
			}
			else
			{
				PrintScreen("Вы не хотите спать!",-1,30,FONT_Screen,2);
				pc_sleep_random(0,0);
			};
		};
		return;
	};
	C_Info.npc = PC_Hero;
	C_Info.nr = 999;
	C_Info.condition = PC_NoSleep_Condition;
	C_Info.information = PC_NoSleep_Info;
	C_Info.important = FALSE;
	C_Info.permanent = TRUE;
	C_Info.description = DIALOG_ENDE_WORK;
	return;
	if(player_mobsi_production == MOBSI_SleepAbit)
	{
		TRUE;
		return;
	};
};