<commit_before>package wge3.game.ai;

import com.badlogic.gdx.math.MathUtils;
import static com.badlogic.gdx.math.MathUtils.PI;
import static com.badlogic.gdx.math.MathUtils.random;
import static com.badlogic.gdx.math.MathUtils.randomBoolean;
import static java.lang.Integer.signum;
import wge3.entity.character.Creature;
import wge3.entity.character.NonPlayer;
import wge3.world.Tile;

public class AI {

    protected NonPlayer NPC; // the controlled creature
    protected AITask currentTask;

    public AI(NonPlayer creature) {
        this.NPC = creature;
        currentTask = new WaitTask(0); // dummy task
    }
    
    public void update() {
        if (!isAttacking()) {
            checkForEnemies();
        }
        
        if (!currentTask.isFinished()) {
            currentTask.execute();
            return;
        }
        
        if (randomBoolean(2/3f)) {
            currentTask = new MoveTask(NPC, NPC.getNewMovementDestination());
        } else {
            currentTask = new WaitTask(random(3000));
        }
    }

    public void checkForEnemies() {
        for (Creature dude : NPC.getEnemiesWithinFOV()) {
            // If dude is located in an OK move destination, attack:
            if (dude.getTile().isAnOKMoveDestinationFor(NPC)) {
                currentTask = new AttackTask(NPC, dude);
                return;
            }
            
            // Else, dude is in a not-OK move destination,
            // so try to find nearest OK move destination:
            Tile nearestOKTile = getNearestOKMoveDestination(dude);
            if (nearestOKTile != null) {
                currentTask = new MoveTask(NPC, nearestOKTile);
            }
            
            // If nearestOKTile was null, ignore enemy.
        }
    }

    public boolean isAttacking() {
        return currentTask.getClass() == AttackTask.class;
    }
    
    public Tile getTileBeforeObstacle(Creature enemy) {
        float startX = NPC.getX();
        float startY = NPC.getY();
        float dx = enemy.getX() - startX;
        float dy = enemy.getY() - startY;
        float distance = (float) (Math.sqrt(dx*dx + dy*dy) / Tile.size);
        
        for (int i = 1; i <= distance; i++) {
            if (NPC.getArea().hasLocation(startX + i*(dx*Tile.size), startY + i*(dy*Tile.size))) {
                Tile currentTile = NPC.getArea().getTileAt(startX + i*(dx*Tile.size), startY + i*(dy*Tile.size));
                if (!currentTile.isPassable() || currentTile.drainsHP()) {
                    return NPC.getArea().getTileAt(startX + (i-1)*(dx*Tile.size), startY + (i-1)*(dy*Tile.size));
                }
            }
        }
        return null;
    }

    public Tile getAlternativeDestinationTile(int i) {
        float angle = NPC.getDirection();
        angle += PI/2 * signum(i);
        float dx = MathUtils.cos(angle);
        float dy = MathUtils.sin(angle);
        
        float tileX = i*dx*Tile.size;
        float tileY = i*dy*Tile.size;
        
        if (NPC.getArea().hasLocation(tileX, tileY)) {
            return NPC.getArea().getTileAt(tileX, tileY);
        }
        
        return null;
    }
<commit_msg>Removed class name identifiers.<commit_after>package wge3.game.ai;

import static com.badlogic.gdx.math.MathUtils.PI;
import static com.badlogic.gdx.math.MathUtils.cos;
import static com.badlogic.gdx.math.MathUtils.random;
import static com.badlogic.gdx.math.MathUtils.randomBoolean;
import static com.badlogic.gdx.math.MathUtils.sin;
import static java.lang.Integer.signum;
import wge3.entity.character.Creature;
import wge3.entity.character.NonPlayer;
import wge3.world.Tile;

public class AI {

    protected NonPlayer NPC; // the controlled creature
    protected AITask currentTask;

    public AI(NonPlayer creature) {
        this.NPC = creature;
        currentTask = new WaitTask(0); // dummy task
    }
    
    public void update() {
        if (!isAttacking()) {
            checkForEnemies();
        }
        
        if (!currentTask.isFinished()) {
            currentTask.execute();
            return;
        }
        
        if (randomBoolean(2/3f)) {
            currentTask = new MoveTask(NPC, NPC.getNewMovementDestination());
        } else {
            currentTask = new WaitTask(random(3000));
        }
    }

    public void checkForEnemies() {
        for (Creature dude : NPC.getEnemiesWithinFOV()) {
            // If dude is located in an OK move destination, attack:
            if (dude.getTile().isAnOKMoveDestinationFor(NPC)) {
                currentTask = new AttackTask(NPC, dude);
                return;
            }
            
            // Else, dude is in a not-OK move destination,
            // so try to find nearest OK move destination:
            Tile nearestOKTile = getNearestOKMoveDestination(dude);
            if (nearestOKTile != null) {
                currentTask = new MoveTask(NPC, nearestOKTile);
            }
            
            // If nearestOKTile was null, ignore enemy.
        }
    }

    public boolean isAttacking() {
        return currentTask.getClass() == AttackTask.class;
    }
    
    public Tile getTileBeforeObstacle(Creature enemy) {
        float startX = NPC.getX();
        float startY = NPC.getY();
        float dx = enemy.getX() - startX;
        float dy = enemy.getY() - startY;
        float distance = (float) (Math.sqrt(dx*dx + dy*dy) / Tile.size);
        
        for (int i = 1; i <= distance; i++) {
            if (NPC.getArea().hasLocation(startX + i*(dx*Tile.size), startY + i*(dy*Tile.size))) {
                Tile currentTile = NPC.getArea().getTileAt(startX + i*(dx*Tile.size), startY + i*(dy*Tile.size));
                if (!currentTile.isPassable() || currentTile.drainsHP()) {
                    return NPC.getArea().getTileAt(startX + (i-1)*(dx*Tile.size), startY + (i-1)*(dy*Tile.size));
                }
            }
        }
        return null;
    }

    public Tile getAlternativeDestinationTile(int i) {
        float angle = NPC.getDirection();
        angle += PI/2 * signum(i);
        float dx = cos(angle);
        float dy = sin(angle);
        
        float tileX = i*dx*Tile.size;
        float tileY = i*dy*Tile.size;
        
        if (NPC.getArea().hasLocation(tileX, tileY)) {
            return NPC.getArea().getTileAt(tileX, tileY);
        }
        
        return null;
    }

{'fraction_non_alphanumeric': 0.11753673022819631, 'fraction_numerical': 0.004688965301656768, 'mean_word_length': 1.9420689655172414, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '2108403', 'n_tokens_mistral': 1968, 'n_tokens_neox': 1899, 'n_words': 423}