----------------------------------
-- made by xStream 03.2008
----------------------------------
local excluded_npcs={
	bar_barman=true,
	bar_arena_manager=true,
	bar_dolg_leader=true,
	bar_dolg_petrenko=true,
	bar_freedom_attacker_commander=true,
	escape_trader=true,
	mil_freedom_member0012=true,
	mil_freedom_member0021=true,
	yantar_ecolog_general=true
}

local convert_npc = {}

local upgrade_delta = 720
local upgrade_exp = 270
local upgrade_phase = 0
local stalkers = {}
local upgrade_steps={
	[0]={
		npc_num = 15,
		prb = 0.6
	},
	[1]={
		npc_num = 11,
		prb = 0.5
	},
	[2]={
		npc_num = 10,
		prb = 0.4
	},
	[3]={
		npc_num = 8,
		prb = 0.4
	}
}
local auto_upgrades = true
local visible_auto_upgrades = false
local upgrade_top_lvl={
	l01_escape = 2,
	l02_garbage = 2,
	l03_agroprom = 2,
	l03u_agr_underground=1,
	l04_darkvalley=2,
	l04u_labx18=2,
	l05_bar=3,
	l06_rostok=3,
	l07_military=4,
	l08_yantar=3,
	l08u_brainlab=3,
	l10_radar=4,
	l10u_bunker=4,
	l11_pripyat=4,
	l12_stancia=4,
	l12_stancia_2=4,
	l12u_control_monolith=4,
	l12u_sarcofag=4
}
local upgrade_over_top_chance = 0.1

local armors_by_visuals = {
	bandit = {
		stalker_bandit_3 = 1,
		stalker_bandit_8 = 2,
		stalker_bandit_veteran = 3,
		stalker_bandit_master = 4
	},
	dolg = {
		stalker_do_mask_1 = 1,
		stalker_do_balon_8 = 1,
		stalker_do_antigas = 2,
		stalker_do_nauchniy = 3,
		stalker_do_exoskeleton = 4
	},
	ecolog = {
		stalker_ecolog = 3,
		stalker_ecolog_military = 3
	},
	hero = {
		stalker_commander = 2,
		stalker_soldier = 2,
		stalker_ecolog = 3,
		stalker_chemical = 3,
		stalker_specops = 3,
		stalker_scien = 3,
		stalker_exoskeleton = 4
	},
	killer = {
		stalker_ki_mask = 1,
		stalker_ki_antigas = 2,
		stalker_ki_nauchniy = 3,
		stalker_ki_exoskeleton = 4
	},
	militari = {
		stalker_militari_antigas_1 = 3,
		stalker_militari_antigas_2 = 3,
		stalker_militari_1 = 3,
		stalker_militari_2 = 3
	},
	monolit = {
		stalker_mo_hood_9 = 2,
		stalker_mo_mask = 1,
		stalker_mo_nauchniy = 3,
		stalker_mo_exo = 4
	},
	neytral = {
		--stalker_bar_security = 1,
		stalker_neytral_balon_8 = 1,
		stalker_neytral_hood_9 = 2,
		stalker_neytral_nauchniy = 3,
		stalker_neytral_exoskeleton = 4
	},
	novice = {
		green_stalker_2 = 0,
		green_stalker_10 = 0,
		green_stalker_antigas = 1
	},
	soldier = {
		soldier_mask = 1,
		soldier_antigas = 2,
		stalker_military_black = 3,
		stalker_military_green = 3
	},
	svoboda = {
		stalker_sv_rukzak_1_1 = 1,
		stalker_sv_hood_9 = 2,
		stalker_sv_hood_91 = 2,
		stalker_sv_nauchniy = 3,
		stalker_sv_exoskeleton = 4
	}
}

local armors_by_community = {
	stalker={
		"novice","neytral"
	},
	monolith={
		"monolit"
	},
	killer={
		"killer","neytral"
	},
	ecolog={
	},
	dolg={
		"dolg"
	},
	freedom={
		"svoboda"
	},
	bandit={
		"svoboda","dolg","neytral","militari"
	},
	military = {
	}
}

local armor_levels={
	green_stalker_suit = 0,
	novice_suit = 0,
	bandit_suit = 0,
	stalker_killer_suit = 2,
	monolit_suit = 3,
	specnaz_suit = 2,
	specnaz_soldier_suit = 2,
	stalker_suit = 1,
	stalker_scient_suit = 3,
	exoskelet = 4,
	svoboda_light_suit = 1,
	svoboda_heavy_suit = 2,
	dolg_suit = 2,
	stalker_dolg_nauchniy_suit = 3,
	ecolog_suit = 3,
	scientist_suit = 3,
	stalker_military_suit = 3,
	soldier_suit = 1,
	stalker_comander_suit = 3	
}

local suits_to_visuals = {
	stalker={
		green_stalker_suit = {
			[[novice\green_stalker_2]],
			[[novice\green_stalker_10]],
			[[novice\green_stalker_antigas]]
		},
		novice_suit = {
			[[novice\green_stalker_2]],
			[[novice\green_stalker_10]],
			[[novice\green_stalker_antigas]]
		},
		bandit_suit = {
		},
		stalker_killer_suit = {
			[[killer\stalker_ki_mask]],
			[[killer\stalker_ki_antigas]]
		},
		monolit_suit = {
			[[neytral\stalker_bar_security]],
			[[neytral\stalker_neytral_balon_8]],
			[[neytral\stalker_neytral_hood_9]]
		},
		specnaz_suit = {
			[[soldier\soldier_antigas]]
		},
		specnaz_soldier_suit = {
			[[soldier\soldier_antigas]]
		},
		stalker_suit = {
			[[neytral\stalker_bar_security]],
			[[neytral\stalker_neytral_balon_8]],
			[[neytral\stalker_neytral_hood_9]]
		},
		stalker_scient_suit = {
			[[neytral\stalker_neytral_nauchniy]]
		},
		exoskelet = {
			[[neytral\stalker_neytral_exoskeleton]]
		},
		svoboda_light_suit = {
			[[neytral\stalker_bar_security]],
			[[neytral\stalker_neytral_balon_8]]
		},
		svoboda_heavy_suit = {
			[[neytral\stalker_neytral_hood_9]]
		},
		dolg_suit = {
			[[neytral\stalker_neytral_hood_9]]
		},
		stalker_dolg_nauchniy_suit = {
			[[neytral\stalker_neytral_nauchniy]]
		},
		ecolog_suit = {
			[[ecolog\stalker_ecolog]]
		},
		scientist_suit = {
			[[ecolog\stalker_ecolog_military]]
		},
		stalker_military_suit = {
		},
		soldier_suit = {
		},
		stalker_comander_suit = {
			[[militari\stalker_militari_antigas_1]],
			[[militari\stalker_militari_antigas_2]]
		}
	},
	monolith={
		green_stalker_suit = {
		},
		novice_suit = {
		},
		bandit_suit = {
		},
		stalker_killer_suit = {
		},
		monolit_suit = {
		},
		specnaz_suit = {
		},
		specnaz_soldier_suit = {
		},
		stalker_suit = {
		},
		stalker_scient_suit = {
		},
		exoskelet = {
		},
		svoboda_light_suit = {
		},
		svoboda_heavy_suit = {
		},
		dolg_suit = {
		},
		stalker_dolg_nauchniy_suit = {
		},
		ecolog_suit = {
		},
		scientist_suit = {
		},
		stalker_military_suit = {
		},
		soldier_suit = {
		},
		stalker_comander_suit = {
		}	
	},
	killer={
		green_stalker_suit = {
		},
		novice_suit = {
		},
		bandit_suit = {
		},
		stalker_killer_suit = {
			[[killer\stalker_ki_antigas]]
		},
		monolit_suit = {
		},
		specnaz_suit = {
		},
		specnaz_soldier_suit = {
		},
		stalker_suit = {
		},
		stalker_scient_suit = {
		},
		exoskelet = {
		},
		svoboda_light_suit = {
		},
		svoboda_heavy_suit = {
		},
		dolg_suit = {
		},
		stalker_dolg_nauchniy_suit = {
		},
		ecolog_suit = {
		},
		scientist_suit = {
		},
		stalker_military_suit = {
		},
		soldier_suit = {
		},
		stalker_comander_suit = {
		}	
	},
	ecolog={
		green_stalker_suit = {
		},
		novice_suit = {
		},
		bandit_suit = {
		},
		stalker_killer_suit = {
		},
		monolit_suit = {
		},
		specnaz_suit = {
		},
		specnaz_soldier_suit = {
		},
		stalker_suit = {
		},
		stalker_scient_suit = {
		},
		exoskelet = {
		},
		svoboda_light_suit = {
		},
		svoboda_heavy_suit = {
		},
		dolg_suit = {
		},
		stalker_dolg_nauchniy_suit = {
		},
		ecolog_suit = {
			[[ecolog\stalker_ecolog]]
		},
		scientist_suit = {
			[[ecolog\stalker_ecolog_military]]
		},
		stalker_military_suit = {
		},
		soldier_suit = {
		},
		stalker_comander_suit = {
		}	
	},
	dolg={
		green_stalker_suit = {
			[[novice\green_stalker_2]],
			[[novice\green_stalker_10]],
			[[novice\green_stalker_antigas]]
		},
		novice_suit = {
			[[novice\green_stalker_2]],
			[[novice\green_stalker_10]],
			[[novice\green_stalker_antigas]]
		},
		bandit_suit = {
		},
		stalker_killer_suit = {
		},
		monolit_suit = {
		},
		specnaz_suit = {
		},
		specnaz_soldier_suit = {
		},
		stalker_suit = {
			[[dolg\stalker_do_balon_8]],
		},
		stalker_scient_suit = {
			[[neytral\stalker_neytral_nauchniy]]
		},
		exoskelet = {
			[[dolg\stalker_do_exoskeleton]]
		},
		svoboda_light_suit = {
		},
		svoboda_heavy_suit = {
		},
		dolg_suit = {
			[[dolg\stalker_do_antigas]]
		},
		stalker_dolg_nauchniy_suit = {
			[[dolg\stalker_do_nauchniy]]
		},
		ecolog_suit = {
			[[ecolog\stalker_ecolog]]
		},
		scientist_suit = {
			[[ecolog\stalker_ecolog_military]]
		},
		stalker_military_suit = {
		},
		soldier_suit = {
		},
		stalker_comander_suit = {
		}	
	},
	freedom={
		green_stalker_suit = {
			[[novice\green_stalker_2]],
			[[novice\green_stalker_10]],
			[[novice\green_stalker_antigas]]
		},
		novice_suit = {
			[[novice\green_stalker_2]],
			[[novice\green_stalker_10]],
			[[novice\green_stalker_antigas]]
		},
		bandit_suit = {
		},
		stalker_killer_suit = {
		},
		monolit_suit = {
		},
		specnaz_suit = {
		},
		specnaz_soldier_suit = {
		},
		stalker_suit = {
			[[svoboda\stalker_sv_rukzak_1_1]],
		},
		stalker_scient_suit = {
			[[neytral\stalker_neytral_nauchniy]]
		},
		exoskelet = {
			[[svoboda\stalker_sv_exoskeleton]]
		},
		svoboda_light_suit = {
			[[svoboda\stalker_sv_rukzak_1_1]]
		},
		svoboda_heavy_suit = {
			[[svoboda\stalker_sv_hood_9]],
			[[svoboda\stalker_sv_hood_91]]
		},
		dolg_suit = {
		},
		stalker_dolg_nauchniy_suit = {
		},
		ecolog_suit = {
			[[ecolog\stalker_ecolog]]
		},
		scientist_suit = {
			[[ecolog\stalker_ecolog_military]]
		},
		stalker_military_suit = {
		},
		soldier_suit = {
		},
		stalker_comander_suit = {
		}	
	},
	bandit={
		green_stalker_suit = {
			[[novice\green_stalker_2]],
			[[novice\green_stalker_10]],
			[[novice\green_stalker_antigas]]
		},
		novice_suit = {
			[[novice\green_stalker_2]],
			[[novice\green_stalker_10]],
			[[novice\green_stalker_antigas]]
		},
		bandit_suit = {
			[[bandit\stalker_bandit_3]],
			[[bandit\stalker_bandit_8]],
		},
		stalker_killer_suit = {
			[[killer\stalker_ki_mask]],
			[[killer\stalker_ki_antigas]]
		},
		monolit_suit = {
			[[neytral\stalker_bar_security]],
			[[neytral\stalker_neytral_balon_8]],
			[[neytral\stalker_neytral_hood_9]]
		},
		specnaz_suit = {
			[[soldier\soldier_antigas]]
		},
		specnaz_soldier_suit = {
			[[soldier\soldier_antigas]]
		},
		stalker_suit = {
			[[neytral\stalker_bar_security]],
			[[neytral\stalker_neytral_balon_8]],
			[[neytral\stalker_neytral_hood_9]]
		},
		stalker_scient_suit = {
			[[neytral\stalker_neytral_nauchniy]]
		},
		exoskelet = {
			[[neytral\stalker_neytral_exoskeleton]]
		},
		svoboda_light_suit = {
			[[neytral\stalker_bar_security]],
			[[neytral\stalker_neytral_balon_8]]
		},
		svoboda_heavy_suit = {
			[[neytral\stalker_neytral_hood_9]]
		},
		dolg_suit = {
			[[neytral\stalker_neytral_hood_9]]
		},
		stalker_dolg_nauchniy_suit = {
			[[neytral\stalker_neytral_nauchniy]]
		},
		ecolog_suit = {
			[[ecolog\stalker_ecolog]]
		},
		scientist_suit = {
			[[ecolog\stalker_ecolog_military]]
		},
		stalker_military_suit = {
			[[militari\stalker_militari_1]],
			[[militari\stalker_militari_2]]
		},
		soldier_suit = {
			[[soldier\soldier_antigas]]
		},
		stalker_comander_suit = {
			[[militari\stalker_militari_antigas_1]],
			[[militari\stalker_militari_antigas_2]]
		}
	},
	military = {
		green_stalker_suit = {
		},
		novice_suit = {
		},
		bandit_suit = {
		},
		stalker_killer_suit = {
		},
		monolit_suit = {
		},
		specnaz_suit = {
		},
		specnaz_soldier_suit = {
		},
		stalker_suit = {
		},
		stalker_scient_suit = {
		},
		exoskelet = {
		},
		svoboda_light_suit = {
		},
		svoboda_heavy_suit = {
		},
		dolg_suit = {
		},
		stalker_dolg_nauchniy_suit = {
		},
		ecolog_suit = {
		},
		scientist_suit = {
		},
		stalker_military_suit = {
		},
		soldier_suit = {
		},
		stalker_comander_suit = {
		}	
	}
}


function npc_update(binder)
	if (binder.armor_check_update or 0)<time_global() then
		local npc = binder.object
		if not npc:alive() or npc:critically_wounded() or npc:wounded() or excluded_npcs[npc:name()] then return end
		local com = npc:character_community()
		if suits_to_visuals and suits_to_visuals[com] then
			npc:iterate_inventory(check_armor,npc)
		end
		binder.armor_check_update=time_global()+1000
	end
end

function check_armor(npc, item, just_report)
	local com = npc:character_community()
	local section = item:section()
	local sini = system_ini()
	local vis = utils.cfg_get_string(sini, section, "visual", false, false, false, "")
	if vis ~= "" then
		vis = xrs_utils.str_explode("\\",vis)
		vis = xrs_utils.str_explode(".",vis[2])
		vis = vis[1]
		if suits_to_visuals[com][vis] then
			if just_report then
				if table.getn(suits_to_visuals[com][vis])>0 and get_npc_level(npc:id())<(armor_levels[vis] or 0) then
					return true
				end
			else
				if table.getn(suits_to_visuals[com][vis])>0 and get_npc_level(npc:id())<(armor_levels[vis] or 0) then
					if ((not db.actor:see(npc) and npc:position():distance_to(db.actor:position())>15) or 
						npc:position():distance_to(db.actor:position())>100) then
						
						change_vis(npc:id(),"actors\\"..suits_to_visuals[com][vis][math.random(table.getn(suits_to_visuals[com][vis]))],armor_levels[vis],true)
						alife():release(alife():object(item:id()))
					end
				end
			end
		end
	end
end

function get_npc_level(id)
	local sobj = alife():object(id)
	if sobj and sobj.rank and sobj:rank()~=0 then
		return math.floor(sobj:rank()/upgrade_exp)
	end
	return 0
end
-------------

function change_vis(id, suit_vis, lvl, now)
	
	if look_for_armor(id,suit_vis) then 
		if now then 
			local npc = level.object_by_id(id)
			if npc then
				npc:clear_animations()
			end
			convert_npc[id]="turn_off"
		end
		local sobj = alife():object(id)
		if sobj then
			sobj:set_rank(upgrade_exp*lvl+math.random(1,50))
		end
	end
end

--------------------------

function look_for_armor(id,vis)
	if vis then
		local sobj = alife():object(id)
		if sobj:health()<0.3 then return false end
		local t = xrs_utils.read_stalker_params(sobj)
		t.visual = vis
		xrs_utils.write_stalker_params(t,sobj)
		return true
	end
	return false
end

function update()
	for k,v in pairs(convert_npc) do
		local obj=level.object_by_id(k)
		local sobj=alife():object(k)
		if sobj then
			if obj~=nil and v=="turn_off" then
				obj:stop_talk()
				switch_offline(obj)
				convert_npc[k]="turn_on"
			elseif obj==nil and v=="turn_on" then
				switch_online(k)
				convert_npc[k]=false
			elseif v==false then
				convert_npc[k]=nil
			end
		else
			convert_npc[k]=nil
		end
	end
	
	--armor upgrade part
	if auto_upgrades==true then
	    local time = level.get_time_days()*60*24+level.get_time_hours()*60+level.get_time_minutes()
		if xr_logic.pstor_retrieve(db.actor,"xrs_armor_t",nil)==nil then
			xr_logic.pstor_store(db.actor,"xrs_armor_t", time+upgrade_delta)
		end
		if time>xr_logic.pstor_retrieve(db.actor,"xrs_armor_t",0) then
			local actor_id=db.actor:id()
			stalkers={}
			for a=0,65535 do
				local sobj = alife():object(a)
				if a~=actor_id and sobj and IsStalker(sobj) and sobj:alive() and not sobj.wounded and not excluded_npcs[sobj:name()] then
					if sobj.m_game_vertex_id and game_graph():valid_vertex_id(sobj.m_game_vertex_id) then
						local map = alife():level_name(game_graph():vertex(sobj.m_game_vertex_id):level_id())
						if map and upgrade_top_lvl[map]~=nil then
							local lvl = get_npc_level(a)
							if lvl<upgrade_top_lvl[map] or math.random()<upgrade_over_top_chance then
								if not stalkers[lvl] then 
									stalkers[lvl]={}
								end
								table.insert(stalkers[lvl],a)
							end
						end
					end
				end
			end
			local max_lvl = table.getn(upgrade_steps)-1
			if max_lvl>0 then
				for a=0,max_lvl do
					if upgrade_steps[a]~=nil and upgrade_steps[a].npc_num~=nil and upgrade_steps[a].prb~=nil then
						for b = 1,upgrade_steps[a].npc_num do
							local cnt = table.getn(stalkers[a])
							if cnt>0 then
								local idx=math.random(cnt)
								local npc_id=stalkers[a][idx]
								if math.random()<upgrade_steps[a].prb then
									if select_next_visual(npc_id,visible_auto_upgrades)==true then
										if not stalkers[a+1] then 
											stalkers[a+1]={}
										end
										table.insert(stalkers[a+1],npc_id)
									end
									table.remove(stalkers[a],idx)
								end
							end
						end
					end
				end
			end
			xr_logic.pstor_store(db.actor,"xrs_armor_t",time+upgrade_delta)
		end
	end	
end

function select_next_visual(id,now)
	local sobj=alife():object(id)
	if sobj then
		local level = get_npc_level(id)
		local com = sobj:community()
		if com and armors_by_community[com] and table.getn(armors_by_community[com])>0 then
			local new_vis=""
			local nl=100
			for vname,allowed_armors in pairs(armors_by_community[com]) do
				if armors_by_visuals[allowed_armors] then
					for k,v in pairs(armors_by_visuals[allowed_armors]) do
						if v>level and v<=nl then
							if v<nl then
								new_vis = allowed_armors.."\\"..k
							elseif v==nl and math.random()>0.5 then
								new_vis = allowed_armors.."\\"..k
							end
							nl=v
						end
					end
				end
			end
			
			if new_vis~="" then
				change_vis(id,"actors\\"..new_vis,nl,now)
				return true
			end
		end
	end
	return false
end

-------------------------
--scheme part
-------------------------
evid_armor=18690

actid_armor=evid_armor
exclusions={}
pickupers={}
local pickupdist=2
--evaluator
class "evaluator_see_useful_armor" (property_evaluator)
function evaluator_see_useful_armor:__init(name, storage) super (nil, name)
	self.a = storage
end
function evaluator_see_useful_armor:evaluate()
	local npc=self.object
	if excluded_npcs[npc:name()] then return false end
	if self.a.see_outfit then
		local o = level.object_by_id(self.a.see_outfit)
		if o and o:position():distance_to(npc:position())<pickupdist+0.5 and npc:accessible(o:level_vertex_id()) and level.vertex_position(o:level_vertex_id()):distance_to(o:position())<1 then
			return true
		else
			pickupers[npc:id()]=nil
			self.a.see_outfit=nil
		end
	end
	
	if (self.next_check_time or 0) > time_global() then return false end
	self.next_check_time = time_global() + 5000
	
	local function check_item(obj)
		obj=obj:object()
		if obj==nil or obj.clsid==nil or obj.id==nil then return false end
		if exclusions[npc:id().."_"..obj:id()]==true then return false end
		if obj:clsid()==58 and obj:position():distance_to(npc:position())<pickupdist and npc:accessible(obj:level_vertex_id()) and level.vertex_position(obj:level_vertex_id()):distance_to(obj:position())<1 then
			if check_armor(npc, obj, true)==true then
				return obj:id()
			else
				exclusions[npc:id().."_"..obj:id()]=true
				return false
			end
		end
	end
	local item = false
	for o in npc:memory_visible_objects() do
		item = check_item(o)
		if item then 
			self.a.see_outfit = item
			pickupers[npc:id()]=true
			return true
		end
	end
	return false
end

--action
class "action_get_useful_armor" (action_base)
function action_get_useful_armor:__init (npc,action_name,storage) super (nil,action_name)
	self.a = storage
end
function action_get_useful_armor:initialize()
	action_base.initialize(self)
	local npc=self.object
	
	npc:set_item(object.idle,nil)
	npc:set_movement_type(move.stand)
	state_mgr.set_state(npc, "walk",nil,nil,{ look_object = level.object_by_id(self.a.see_outfit) }, {animation = true})
	npc:set_desired_position(level.object_by_id(self.a.see_outfit):position())
	npc:set_dest_level_vertex_id(level.object_by_id(self.a.see_outfit):level_vertex_id())
	
	xr_sound.set_sound(npc, nil)
	stop_play_sound(npc)
end
function action_get_useful_armor:execute()
	action_base.execute (self)
	local npc=self.object
	if level.object_by_id(self.a.see_outfit)==nil or not npc:see(level.object_by_id(self.a.see_outfit)) then
		self.a.see_outfit = nil
		pickupers[npc:id()]=nil
		return
	end
	if not self.end_time then
		if level.object_by_id(self.a.see_outfit):position():distance_to(npc:position())<1 then 
			npc:set_desired_position()
			npc:set_desired_direction()
			npc:set_dest_level_vertex_id(npc:level_vertex_id())
			state_mgr.set_state(npc, "dynamite",nil,nil,{ look_object = level.object_by_id(self.a.see_outfit) }, {animation = true})
			if npc:animation_count()==1 then 
				self.end_time = time_global() + 1500
			end
		else
			state_mgr.set_state(npc, "walk")
			npc:set_dest_level_vertex_id(level.object_by_id(self.a.see_outfit):level_vertex_id())
			npc:set_desired_position(level.object_by_id(self.a.see_outfit):position())
			npc:set_desired_direction(level.object_by_id(self.a.see_outfit):position():sub(npc:position()))
		end
	elseif self.end_time<time_global() then
		local o = level.object_by_id(self.a.see_outfit)
		local sect = o:section()
		alife():release(alife():object(self.a.see_outfit))
		alife():create(sect,npc:position(),npc:level_vertex_id(),npc:game_vertex_id(),npc:id())
		npc:clear_animations()
	end
end

function action_get_useful_armor:finalize()
	action_base.finalize (self)
	local npc=self.object
	pickupers[npc:id()]=nil
end

--binder
function add_to_binder(object, ini, scheme, section, storage)

	local operators	= {}
	local properties  = {}

	local manager = object:motivation_action_manager()

	operators["armor"]			= actid_armor

	properties["armor"]			= evid_armor

	local zombi=object:character_community()=="zombied" or object:character_community()=="trader" or
		  object:character_community()=="arena_enemy" or object:name()=="mil_stalker0012" or object:name()=="yantar_ecolog_general"

	if zombi then
		manager:add_evaluator (properties["armor"], property_evaluator_const(false))
	else
		manager:add_evaluator (properties["armor"], evaluator_see_useful_armor("armor", storage))
	end
	
	local action = action_get_useful_armor (object,"armor", storage)
	action:add_precondition(world_property(stalker_ids.property_alive, true))
	action:add_precondition(world_property(stalker_ids.property_enemy, false))
	action:add_precondition(world_property(xr_evaluators_id.sidor_wounded_base, false))
	
	xr_motivator.addCommonPrecondition(action)
	action:remove_precondition(properties["armor"])
	action:add_precondition	(world_property(properties["armor"], true))
	
	action:add_effect (world_property(properties["armor"], false))
	manager:add_action (operators["armor"], action)

	action = manager:action (xr_actions_id.alife)	
	action:add_precondition	(world_property(properties["armor"], false))

end

function set_scheme(npc, ini, scheme, section)
  local st = xr_logic.assign_storage_and_bind(npc, ini, scheme, section)
end

function disable_scheme(npc, scheme)
	local st = db.storage[npc:id()][scheme]
	if st then
		st.enabled = false
	end
end

