dofile("Scripts/Init/units.lua");

min_fire_distance = 4;		-- if distance to target < this number then unit will not fire
move_distance = 16;		-- single move distance
last_time_scatter = 0;
last_attack_time = 0;		-- unit's last fire time 
voice_attack_delay = 40	-- if unit start firing after this amount of seconds, it will shout
last_time_enemy_seen = 0;	-- no comments
voice_see_enemy_delay = 32;	-- if unit got enemy in sight after this amount of seconds, it will shout
last_wound_time = 0;		-- this time will be stored, when soldier has hit (each time)
voice_underattack_delay = 24;	-- if unit was unhurted for this amount of seconds, it will shout when attacked
-- when soldier has hit by HE damage greater then this:
damage_step = 12 + object.RandomInt(12);
-- ...he go sit/prone and stand back after this amount of seconds:
wound_recovery_time = 1 + object.RandomInt(1);
unconscious = false;
-- All Soldiers are regenerating this health amount:
regen_health = 0;
-- ...per this time:
regen_timeout = 48;
blood_line = 25;		--if soldier's heath drops below this value, soldier starts bleeding
				--(when it reach the value - soldier will stop bleeding)
bleeding = false;
bleed_interval = 6;		-- once per this interval(in epoch) bleeding soldiers will drop blood on ground

stand_damage_multiplier = 1;	-- received_damage = received_damage * move_mode_damage_multiplier
crouch_damage_multiplier = 0.5;
prone_damage_multiplier = 0.2;

-- % chances to fire each MicroAIOrderer() round while MAI is in one of its actions:
fire_chance = {50, 90, 20, 40}		-- attack,defence,retreat,scatter
-- % chances to move each MicroAIOrderer() round while MAI is in one of its actions:
move_chance = {90, 10, 75, 100}		-- attack,defence,retreat,scatter
-- (from 0(=0deg) to 1(=360deg)) spread for move direction (chtoby soldat bejal ne pryamo, a zigzagami)
move_spread = {0.2, 0.6, 0.4, 0.8}	-- attack,defence,retreat,scatter
-- % chances to crouch (instead of standing) each MoveMan() round, while MAI is in one of its actions:
crouch_chance = {50, 90, 50, 50}	-- attack,defence,retreat,scatter

grenade_dead_range = 5;

-- microAI mode:
mai_behaviour = BEH_NORMAL;	-- CAREFUL, NORMAL, AGRESSIVE
mai_action = ACTION_DEFENSE;	-- RETREAT, DEFENSE, ATTACK, SCATTER
mai_fire_order = ORDER_NONE;	-- ORDER_NONE, ORDER_ACTION
mai_move_order = ORDER_NONE;	-- ORDER_NONE, ORDER_ACTION
mai_fire_state = STATE_IDLE;	-- STATE_IDLE, STATE_ACTION
mai_move_state = STATE_IDLE;	-- STATE_IDLE, STATE_ACTION
mai_target = nil;
prev_target_id = nil;
player_move_mode = unit.Stand;	-- unit.Prone, unit.Stand, unit.Crouch

check_state_timeout = 10;
fire_timeout = 40;
move_timeout = 40;
mai_timeout = 100;
mai_orderer_timeout = 40;
move_man_timeout = 96;
eventman_timeout = 48;
mai_log_timeout = 16;
idle_timeout = 200;

stand_modes = { };

function Initialize()
	local dz;

	dz = object.GetDamageZoneId("damagezone_stand");
	if dz < 0 then log("Soldier: damagezone_stand not defined!") end;
	stand_modes[unit.Stand] = {
		damage_zone = dz,
		damage_multiplier = stand_damage_multiplier,
	};

	dz = object.GetDamageZoneId("damagezone_crouch");
	if dz < 0 then log("Soldier: damagezone_crouch not defined!") end;
	stand_modes[unit.Crouch] = {
		damage_zone = dz,
		damage_multiplier = crouch_damage_multiplier,
	};

	dz = object.GetDamageZoneId("damagezone_prone");
	if dz < 0 then log("Soldier: damagezone_prone not defined!") end;
	stand_modes[unit.Prone] = {
		damage_zone = dz,
		damage_multiplier = prone_damage_multiplier,
	};
	stand_modes.active = unit.Stand;
	stand_mode = stand_modes[stand_modes.active];

	BasicInit();
	
--	AIparts:AddPeriodic("MoveMan", move_man_timeout, MoveMan);
	AIparts:AddPeriodic("Regen", regen_timeout, Regen, object.RandomInt(regen_timeout));
--	AIparts:AddPeriodic("MicroAILog", mai_log_timeout, MicroAILog);
	AIparts:AddPeriodic("Idle", idle_timeout, Idle, object.RandomInt(idle_timeout));
end
