------------------------------------------------------------------------------------------------------------------------------------------------
function TalkMobilaExecute()
        aObject = GameObject:Get();
        
        if( not aObject.Params.iRelaxTime or aObject.Params.iRelaxTime==0 )then
        
            aObject.Params.iCurrentRelaxTime = GetRandomValue(aObject.Tasks.talk_telephon.timer);
            aObject.Params.iRelaxTime = aObject.Params.iCurrentRelaxTime;
            CPP_SecondObjAnimState("no_rec");
            CPP_SetAnimState("talk_telephon_1");
            --CPP_OtherObjAnimState("brother","left_stand");
            CPP_OtherObjDoTasks("brother","finish_talk");
        end
        
        if( aObject.Params.iCurrentRelaxTime - aObject.Params.iRelaxTime == 1)then
            CPP_Action("start_telphon_talk");
        end
        
        
        aObject.Params.iRelaxTime = aObject.Params.iRelaxTime-1;
        
        if( aObject.Params.iRelaxTime == 0)then
            --CPP_SecondObjAnimState("normal");           
            CPP_RecursiveRun("lift_handset_brother",0);
            
            return 0;
        end
    return 1;
end
------------------------------------------------------------------------------------------------------------------------------------------------
-- может ли быть выполнен таск с идентификатаром
function isMayByTask(aTask)
    if(aTask == drinking)then
        aObj = GameObject:Get();
        if( aObj.Params.bonus_it ~= 0)then return 0; end;       
    end;
    return 1;
end
------------------------------------------------------------------------------------------------------------------------------------------------
-- обработчик окончания выполнения задачи
function OnEndTask(aName, aTask)
    aObj = GameObject:Get();   
    if( aObj.Params.bonus_it > 0 )then          
        aObj.Params.bonus_it = aObj.Params.bonus_it - 1;
        if(aObj.Params.bonus_it == 0)then
            aObj.Params.speed = aObj.Params.speed / aObj.Params.on_drink;   
            aObj.Params.WorkKoof = 1;           
        end
    end
end
------------------------------------------------------------------------------------------------------------------------------------------------
-- действие "говорить по телефону"
function TalkTelephonExecute()
        aObject = GameObject:Get();
        
        if( not aObject.Params.iRelaxTime or aObject.Params.iRelaxTime==0 )then
        
            aObject.Params.iCurrentRelaxTime = GetRandomValue(aObject.Tasks.talk_telephon.timer);
            aObject.Params.iRelaxTime = aObject.Params.iCurrentRelaxTime;
            CPP_SecondObjAnimState("no_rec");
            CPP_SetAnimState("talk_telephon_1");
            if aObject.Params.TelephonId == nil then
               aObject.Params.TelephonId = CPP_FindObj("telephon");
            end
            CPP_RunStringSubId( aObject.Params.TelephonId, "CPP_StopSound('telephone_ring')");
        end
        
        if( aObject.Params.iCurrentRelaxTime - aObject.Params.iRelaxTime == 1)then
            CPP_Action("start_telphon_talk");
        end
        
        aObject.Params.iRelaxTime = aObject.Params.iRelaxTime-1;
        
        if( aObject.Params.iRelaxTime == 0)then
            CPP_SecondObjAnimState("normal");           
            return 0;
        end
    return 1;
end
------------------------------------------------------------------------------------------------------------------------------------------------
function DefEatingAnimal(aTask, aAnimal)
    aObject = GameObject:Get();
    local tTask = aObject.Params.timerTask;
    if (tTask < 0) then 
        tTask = aObject.Tasks[aTask].timer; 
        CPP_PlaySound("hay",0);
    end
    tTask = tTask - 1;
    aObject.Params.timerTask = tTask;
    if (tTask == 2) then 
        CPP_SecondObjAnimState("eating_"..aAnimal);
    else 
        if (tTask == 1) then 
            CPP_SecondObjAnimState("nasip_seno1");
        else 
            CPP_SecondObjAnimState("nasip_seno2"); 
        end
    end
    if (tTask <= 0) then
        aObject.Params.timerTask = -1;
        CPP_SetAnimState("right_stand");
        OnEndTask("eating",aObject.Tasks[aTask]);
        return 0;
    end
    return 1;
end

------------------------------------------------------------------------------------------------------------------------------------------------
-- выполнить вторую часьтTask EATING над внешним обьектом и вернуть true если выполнилась
function endEatingCowExecute()
    return DefEatingAnimal("eating_cow_end", "cow");
end
------------------------------------------------------------------------------------------------------------------------------------------------
-- выполнить вторую часьтTask EATING над внешним обьектом и вернуть true если выполнилась
function endEatingSheepExecute()
    return DefEatingAnimal("eating_sheep_end", "sheep");
end
------------------------------------------------------------------------------------------------------------------------------------------------


function DefEndWateringExecute(aTask)
    aObject = GameObject:Get();
    local tTask = aObject.Params.timerTask;
    if (tTask < 0) then 
        tTask = aObject.Tasks[aTask].timer;        
        CPP_PlaySound("water_pour",0);
    end
    
    tTask = tTask - 1;
    aObject.Params.timerTask = tTask;
    if (tTask <= 0) then
        aObject.Params.timerTask = -1;
        CPP_SetAnimState("up_stand");
        OnEndTask("watering",aObject.Tasks[aTask]);
        return 0;
    end
    return 1;
end
------------------------------------------------------------------------------------------------------------------------------------------------
function DefWateringAnimal(aTask, aAnimal)
    aObject = GameObject:Get();
    local tTask = aObject.Params.timerTask;
    if (tTask < 0) then 
        tTask = aObject.Tasks[aTask].timer; 
        CPP_SecondObjAnimState("watering_"..aAnimal);
        CPP_PlaySound("water_pour",0);        
    end
    tTask = tTask - 1;
    aObject.Params.timerTask = tTask;
    if (tTask <= 0) then
        aObject.Params.timerTask = -1;
        OnEndTask("watering",aObject.Tasks[aTask]);                                       
        CPP_SetAnimState("right_stand");
        return 0;
    end
    return 1;
end
------------------------------------------------------------------------------------------------------------------------------------------------
-- выполнить вторую часть Task WATERING  над внешним обьектом и вернуть true если выполнилась
function endWateringCowExecute()
    return DefWateringAnimal("watering_cow_end", "cow");
end
------------------------------------------------------------------------------------------------------------------------------------------------
-- выполнить вторую часть Task WATERING  над внешним обьектом и вернуть true если выполнилась
function endWateringSheepExecute()
    return DefWateringAnimal("watering_sheep_end", "sheep");
end
------------------------------------------------------------------------------------------------------------------------------------------------
function DefEndToolsExecute(aTask)
    aObject = GameObject:Get();
    local tTask = aObject.Params.timerTask;
    if (tTask < 0) then 
        tTask = aObject.Tasks[aTask].timer;        
        CPP_PlaySound("fertilizer",0);
    end
    
    tTask = tTask - 1;
    aObject.Params.timerTask = tTask;
    if (tTask <= 0) then
        aObject.Params.timerTask = -1;
        CPP_SetAnimState("up_stand");
        OnEndTask("tools",aObject.Tasks[aTask]);                                             
        return 0;
    end
    return 1;
end
------------------------------------------------------------------------------------------------------------------------------------------------
function DefWeedingExecute(aTask)
    aObject = GameObject:Get();
    local tTask = aObject.Params.timerTask;
    if (tTask < 0) then 
        tTask = aObject.Tasks[aTask].timer; 
        CPP_PlaySound("weeding",1);
    end
    tTask = tTask - 1;
    aObject.Params.timerTask = tTask;
    
    if (tTask <= 0) then
        aObject.Params.timerTask = -1;
        CPP_SetAnimState("selected");
        CPP_SetAnimState("right_stand");
        OnEndTask("weeding",aObject.Tasks[aTask]);
        CPP_StopSound("weeding");
        return 0;
    end
    return 1;
end
------------------------------------------------------------------------------------------------------------------------------------------------
function DefCollectionExecute(aTask, Product)
    aObject = GameObject:Get();
    local tTask = aObject.Params.timerTask;
    if (tTask < 0) then 
        tTask = aObject.Tasks[aTask].timer; 
        CPP_SecondObjChildAnimState(Product,Product,1,0);
        CPP_PlaySound("vegies",0);        
    end
    tTask = tTask - 1;
    aObject.Params.timerTask = tTask;
    if (tTask == 2) then 
        CPP_SecondObjChildAnimState(Product,Product,2,0);
    end
    if (tTask <= 0) then
        CPP_SecondObjChildAnimState(Product,Product,3,0);
        aObject.Params.timerTask = -1;
        CPP_SetAnimState("selected");
        CPP_SetAnimState("right_stand");
        CPP_SecondObjAnimState("small");
        OnEndTask("collection",aObject.Tasks[aTask]);                             
        return 0;
    end
    return 1;
end
------------------------------------------------------------------------------------------------------------------------------------------------
function DefTakeExecute(aTask)
    aObject = GameObject:Get();
    local tTask = aObject.Params.timerTask;
    if (tTask < 0) then tTask = aObject.Tasks[aTask].timer; end
    tTask = tTask - 1;
    aObject.Params.timerTask = tTask;
    if (tTask <= 0) then
        aObject.Params.timerTask = -1;
        CPP_SetAnimState("right_stand");
        CPP_AddRemittedTasks(aObject.Params.ID,"redbarn","","");   
        return 0;
    end
    return 1;
end
------------------------------------------------------------------------------------------------------------------------------------------------
function DefRelaxTask(aName)
    aObject = GameObject:Get();
    local tTask = aObject.Params.timerTask;
    if (tTask < 0) then tTask = aObject.Tasks.relax_kreslo.timer; end
    tTask = tTask - 1;
    aObject.Params.timerTask = tTask;
    CPP_SecondObjAnimState(aName);
    CPP_SetAnimState("invisible");   
    if (tTask <= 0) then
        aObject.Params.timerTask = -1;
        CPP_SecondObjAnimState("normal");        
        CPP_SetAnimState("right_stand");
        local aTrigger = aObject.Triggers.need_relax;
        aObject.Params.speed = aObject.Params.speed * aTrigger.delta_speed;
        aTrigger.under_task = 0;
        aTrigger.amount = aTrigger.amount - 1;
        return 0;
    end
    return 1;
end

-----------------------------------------------------------------------------------------------------       
function LemonadIsReady()
    aObject = GameObject:Get();
    if( not aObject.Params.iDrinkTime)then
        CPP_PutOnTopExpectedTasks( "drink_lemonad");
        --CPP_WantSelect(1);
    end    
end       
-----------------------------------------------------------------------------------------------------
function DrinkLemonadExecute()
    aObject = GameObject:Get();
    local tTask = aObject.Params.timerTask;
    if (tTask < 0) then 
        tTask = aObject.Tasks.drink_lemonad.timer; 
        CPP_PlaySound("lemonade_drinking",0);
    end
    tTask = tTask - 1;
    aObject.Params.timerTask = tTask;

    
    if (tTask <= 0) then
        aObject.Params.timerTask = -1;
        
        --if( aObject.Triggers.need_relax.under_task==1)then
        --    return 0;
        --end    

        if( aObject.Params.iDrinkTime == nil)then
            aObject.Params.iDrinkTime = aObject.Params.lemonad_time;
            aObject.Params.speed = aObject.Params.speed * aObject.Params.drink_speed_bonus;            
        else
            aObject.Params.iDrinkTime = aObject.Params.iDrinkTime + aObject.Params.lemonad_time;
        end        
        return 0;
    end
    return 1;
end
-----------------------------------------------------------------------------------------------------
function DrinkTriger()
    local aObject = GameObject:Get();
    
    if( aObject.Params.iDrinkTime ~= nil)then
        aObject.Params.iDrinkTime = aObject.Params.iDrinkTime - 1;
        if aObject.Params.iDrinkTime <= 0 then
            aObject.Params.iDrinkTime = nil;
            aObject.Params.speed = aObject.Params.speed / aObject.Params.drink_speed_bonus;
            LemonadIsReady();            
        end
    end
end
------------------------------------------------------------------------------------------------------------------------------------
-- не удалять используется в брате
function RestoreAfterTrashIfAsObj()
end

-- ОТНОС ПРОДУКТОВ
function defKeepingRedbarnExecute()
    aObject = GameObject:Get();
    aObject.Params.timerTask = -1;
    CPP_SetAnimState("right_stand");
    CPP_RunStringParent("WhereCarryProduct('"..GameObject.Params.LastProd.."');");
    GameObject.Params.LastProd = '';
    return 0;
end
