<commit_before>// DXAI_Objectives.cs
// Objectives for the AI system
// Copyright (c) 2014 <NAME>

//----------------------------------------------------------------------
// The AIVisualAcuity task is a complementary task for the AI grunt systems
// to perform better at recognizing things visually with reasonably
// Human perception capabilities.
// ---------------------------------------------------------------------

function AIVisualAcuity::initFromObjective(%task, %objective, %client)
{
    // Called to initialize from an objective object
}

function AIVisualAcuity::assume(%task, %client)
{
    // Called when the bot starts the task
}

function AIVisualAcuity::retire(%task, %client)
{
    // Called when the bot stops the task
}

function AIVisualAcuity::weight(%task, %client)
{
    %task.setWeight(999);
}

function AIConnection::visualAcuityUpdate(%this)
{
    // Called when the bot is performing the task
    if (%this.enableVisualDebug)
    {
        if (!isObject(%this.originMarker))
        {
            %this.originMarker = new Waypoint(){ datablock = "WaypointMarker"; team = %this.team; name = %this.namebase SPC " Origin"; };
            %this.clockwiseMarker = new Waypoint(){ datablock = "WaypointMarker"; team = %this.team; name = %this.namebase SPC " Clockwise"; };
            %this.counterClockwiseMarker = new Waypoint(){ datablock = "WaypointMarker"; team = %this.team; name = %this.namebase SPC " Counter Clockwise"; };
            %this.upperMarker = new Waypoint(){ datablock = "WaypointMarker"; team = %this.team; name = %this.namebase SPC " Upper"; };
            %this.lowerMarker = new Waypoint(){ datablock = "WaypointMarker"; team = %this.team; name = %this.namebase SPC " Lower"; };
        }
            
        %viewCone = %this.calculateViewCone();
        %coneOrigin = getWords(%viewCone, 0, 2);
        %viewConeClockwiseVector = getWords(%viewCone, 3, 5);
        %viewConeCounterClockwiseVector = getWords(%viewCone, 6, 8);
        
        %viewConeUpperVector = getWords(%viewCone, 9, 11);
        %viewConeLowerVector = getWords(%viewCone, 12, 14);
        
        // Update all the markers
        %this.clockwiseMarker.setPosition(%viewConeClockwiseVector);
        %this.counterClockwiseMarker.setPosition(%viewConeCounterClockwiseVector);
        %this.upperMarker.setPosition(%viewConeUpperVector);
        %this.lowerMarker.setPosition(%viewConeLowerVector);
        %this.originMarker.setPosition(%coneOrigin);
    }
    else if (isObject(%this.originMarker))
    {
        %this.originMarker.delete();
        %this.clockwiseMarker.delete();
        %this.counterClockwiseMarker.delete();
        %this.upperMarker.delete();
        %this.lowerMarker.delete();
    }
    
    %result = %this.getObjectsInViewcone($TypeMasks::ProjectileObjectType | $TypeMasks::PlayerObjectType, %this.viewDistance, true);
    
    // What can we see?
    for (%i = 0; %i < %result.getCount(); %i++)
    {
        %current = %result.getObject(%i);
        %this.awarenessTicks[%current]++;
        
        if (%current.getType() & $TypeMasks::ProjectileObjectType)
        {   
            // Did we "notice" the object yet?
            // We pick a random notice time between 700ms and 1200 ms
            // Obviously this timer runs on a 32ms tick, but it should help provide a little unpredictability
            %noticeTime = getRandom(700, 1200);
            if (%this.awarenessTicks[%current] < (%noticeTime / 32))
                continue;
            
            %className = %current.getClassName();
            
            // LinearFlareProjectile and LinearProjectile have linear properties, so we can easily determine if a dodge is necessary
            if (%className $= "LinearFlareProjectile" || %className $= "LinearProjectile")
            {
                //%this.setDangerLocation(%current.getPosition(), 20);
                
                // Perform a raycast to determine a hitpoint
                %currentPosition = %current.getPosition();
                %rayCast = containerRayCast(%currentPosition, vectorAdd(%currentPosition, vectorScale(%current.initialDirection, 200)), -1, 0);     
                %hitObject = getWord(%raycast, 0);
                                
                // We're set for a direct hit on us!
                if (%hitObject == %this.player)
                {
                    %this.setDangerLocation(%current.getPosition(), 30);
                    continue;
                }
                
                // If there is no radius damage, don't worry about it now
                if (!%current.getDatablock().hasDamageRadius)
                    continue;
                
                // How close is the hit loc?
                %hitLocation = getWords(%rayCast, 1, 3);
                %hitDistance = vectorDist(%this.player.getPosition(), %hitLocation);
                
                // Is it within the radius damage of this thing?
                if (%hitDistance <= %current.getDatablock().damageRadius)
                    %this.setDangerLocation(%current.getPosition(), 30);
            }
            // A little bit harder to detect.
            else if (%className $= "GrenadeProjectile")
            {
                
            }
        }
        // See a player?
        else if (%current.getType() & $TypeMasks::PlayerObjectType)
        {
            // ... if the moron is right there in our LOS then we probably should see them
            %start = %this.player.getPosition();
            %end = vectorAdd(%start, vectorScale(%this.player.getEyeVector(), %this.viewDistance));
            
            %rayCast = containerRayCast(%start, %end, -1, %this.player);     
            %hitObject = getWord(%raycast, 0);
            
            echo(%hitObject);
            echo(%current);
            if (%hitObject == %current)
                %this.stepEngage(%current);
        }
    }
    
    %result.delete();
}

function AIConnection::enhancedLogicUpdate(%this)
{
    cancel(%this.enhancedLogicHandle);
    
    //if (!isObject(%this.))
    
    if (!isObject(%this.player))
    {
        %this.enhancedLogicHandle = %this.schedule(32, "enhancedLogicUpdate");
        return;
    }
    
    %this.visualAcuityUpdate();
    %this.enhancedLogicHandle = %this.schedule(32, "enhancedLogicUpdate");
}

function AIVisualAcuity::monitor(%task, %client)
{
    return;
    
 
}<commit_msg>Back to using the inbuilt AI Task system; fixed the monitor freq<commit_after>// DXAI_Objectives.cs
// Objectives for the AI system
// Copyright (c) 2014 <NAME>

//----------------------------------------------------------------------
// The AIVisualAcuity task is a complementary task for the AI grunt systems
// to perform better at recognizing things visually with reasonably
// Human perception capabilities.
// ---------------------------------------------------------------------

function AIVisualAcuity::initFromObjective(%task, %objective, %client)
{
    // Called to initialize from an objective object
}

function AIVisualAcuity::assume(%task, %client)
{
    // Called when the bot starts the task
    %task.setMonitorFreq(32);
}

function AIVisualAcuity::retire(%task, %client)
{
    // Called when the bot stops the task
}

function AIVisualAcuity::weight(%task, %client)
{
    %task.setWeight(999);
}

function AIVisualAcuity::monitor(%task, %client)
{
 // Called when the bot is performing the task
    if (%client.enableVisualDebug)
    {
        if (!isObject(%client.originMarker))
        {
            %client.originMarker = new Waypoint(){ datablock = "WaypointMarker"; team = %client.team; name = %client.namebase SPC " Origin"; };
            %client.clockwiseMarker = new Waypoint(){ datablock = "WaypointMarker"; team = %client.team; name = %client.namebase SPC " Clockwise"; };
            %client.counterClockwiseMarker = new Waypoint(){ datablock = "WaypointMarker"; team = %client.team; name = %client.namebase SPC " Counter Clockwise"; };
            %client.upperMarker = new Waypoint(){ datablock = "WaypointMarker"; team = %client.team; name = %client.namebase SPC " Upper"; };
            %client.lowerMarker = new Waypoint(){ datablock = "WaypointMarker"; team = %client.team; name = %client.namebase SPC " Lower"; };
        }
            
        %viewCone = %client.calculateViewCone();
        %coneOrigin = getWords(%viewCone, 0, 2);
        %viewConeClockwiseVector = getWords(%viewCone, 3, 5);
        %viewConeCounterClockwiseVector = getWords(%viewCone, 6, 8);
        
        %viewConeUpperVector = getWords(%viewCone, 9, 11);
        %viewConeLowerVector = getWords(%viewCone, 12, 14);
        
        // Update all the markers
        %client.clockwiseMarker.setPosition(%viewConeClockwiseVector);
        %client.counterClockwiseMarker.setPosition(%viewConeCounterClockwiseVector);
        %client.upperMarker.setPosition(%viewConeUpperVector);
        %client.lowerMarker.setPosition(%viewConeLowerVector);
        %client.originMarker.setPosition(%coneOrigin);
    }
    else if (isObject(%client.originMarker))
    {
        %client.originMarker.delete();
        %client.clockwiseMarker.delete();
        %client.counterClockwiseMarker.delete();
        %client.upperMarker.delete();
        %client.lowerMarker.delete();
    }
    
    %result = %client.getObjectsInViewcone($TypeMasks::ProjectileObjectType | $TypeMasks::PlayerObjectType, %client.viewDistance, true);
    
    // What can we see?
    for (%i = 0; %i < %result.getCount(); %i++)
    {
        %current = %result.getObject(%i);
        %client.awarenessTicks[%current]++;
        
        if (%current.getType() & $TypeMasks::ProjectileObjectType)
        {   
            // Did we "notice" the object yet?
            // We pick a random notice time between 700ms and 1200 ms
            // Obviously this timer runs on a 32ms tick, but it should help provide a little unpredictability
            %noticeTime = getRandom(700, 1200);
            if (%client.awarenessTicks[%current] < (%noticeTime / 32))
                continue;
            
            %className = %current.getClassName();
            
            // LinearFlareProjectile and LinearProjectile have linear properties, so we can easily determine if a dodge is necessary
            if (%className $= "LinearFlareProjectile" || %className $= "LinearProjectile")
            {
                //%this.setDangerLocation(%current.getPosition(), 20);
                
                // Perform a raycast to determine a hitpoint
                %currentPosition = %current.getPosition();
                %rayCast = containerRayCast(%currentPosition, vectorAdd(%currentPosition, vectorScale(%current.initialDirection, 200)), -1, 0);     
                %hitObject = getWord(%raycast, 0);
                                
                // We're set for a direct hit on us!
                if (%hitObject == %client.player)
                {
                    %client.setDangerLocation(%current.getPosition(), 30);
                    continue;
                }
                
                // If there is no radius damage, don't worry about it now
                if (!%current.getDatablock().hasDamageRadius)
                    continue;
                
                // How close is the hit loc?
                %hitLocation = getWords(%rayCast, 1, 3);
                %hitDistance = vectorDist(%client.player.getPosition(), %hitLocation);
                
                // Is it within the radius damage of this thing?
                if (%hitDistance <= %current.getDatablock().damageRadius)
                    %client.setDangerLocation(%current.getPosition(), 30);
            }
            // A little bit harder to detect.
            else if (%className $= "GrenadeProjectile")
            {
                
            }
        }
        // See a player?
        else if (%current.getType() & $TypeMasks::PlayerObjectType)
        {
            // ... if the moron is right there in our LOS then we probably should see them
            %start = %client.player.getPosition();
            %end = vectorAdd(%start, vectorScale(%client.player.getEyeVector(), %client.viewDistance));
            
            %rayCast = containerRayCast(%start, %end, -1, %client.player);     
            %hitObject = getWord(%raycast, 0);
            
            echo(%hitObject);
            echo(%current);
            if (%hitObject == %current)
                %client.stepEngage(%current);
        }
    }
    
    %result.delete();
}
{'fraction_non_alphanumeric': 0.13689907672715695, 'fraction_numerical': 0.009232728430436167, 'mean_word_length': 2.0168067226890756, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5801181', 'n_tokens_mistral': 3518, 'n_tokens_neox': 3306, 'n_words': 818}