<commit_before>package fr.leomoldo.android.bunkerwar;


import android.os.AsyncTask;
import android.util.Log;

import fr.leomoldo.android.bunkerwar.drawer.Landscape;
import fr.leomoldo.android.bunkerwar.sdk.ViewCoordinates;

/**
 * Created by leomoldo on 19/05/2016.
 */
public class BombshellAnimatorAsyncTask extends AsyncTask<BombshellPathComputer, ViewCoordinates, Boolean> {

    private static final String LOG_TAG = BombshellAnimatorAsyncTask.class.getSimpleName();

    private final static int ITERATION_WAITING_TIME = 10;
    private final static float BUNKER_HITBOX_EXPANSION_RATIO = 2f;

    private TwoPlayerGameView mGameView;
    private int mViewHeight;
    private int mViewWidth;
    private ViewCoordinates mTargetBunkerVC;
    private Landscape mLandscape;

    public BombshellAnimatorAsyncTask(TwoPlayerGameView gameView, Landscape landscape, ViewCoordinates targetBunkerVC) {
        mGameView = gameView;
        mLandscape = landscape;
        mViewHeight = mGameView.getHeight();
        mViewWidth = mGameView.getWidth();
        mTargetBunkerVC = targetBunkerVC;

        /*
        Log.d(LOG_TAG, "View Width : " + mViewWidth);
        Log.d(LOG_TAG, "View Height : " + mViewHeight);
        */
    }

    @Override
    protected Boolean doInBackground(BombshellPathComputer... bombshellPathComputers) {
        Boolean shouldHalt = false;
        while (!shouldHalt) {
            bombshellPathComputers[0].incrementCoordinates();
            publishProgress(bombshellPathComputers[0].getCurrentCoordinates());
            /*
            Log.d(LOG_TAG, "timeCounter : " + bombshellPathComputers[0].getTimeCounter());
            Log.d(LOG_TAG, "currentBombshellX : " + bombshellPathComputers[0].getCurrentCoordinates().getX());
            Log.d(LOG_TAG, "currentBombshellY : " + bombshellPathComputers[0].getCurrentCoordinates().getY());
            */
            try {
                Thread.sleep(ITERATION_WAITING_TIME);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            // TODO We must prevent the playing bunker from hitting itself when firing (don't check when timecounter is to low).
            // Check if bombshell dit hit player one bunker.
            /*
            if ( Math.abs(bombshellPathComputers[0].getCurrentCoordinates().getX() - mBunkerPlayerOneCoordinates.getX()) < GameView.BUNKER_RADIUS &&
                    Math.abs(bombshellPathComputers[0].getCurrentCoordinates().getY() - mBunkerPlayerOneCoordinates.getY()) < GameView.BUNKER_RADIUS) {
                Log.d(LOG_TAG, "Bombshell collided with player ONE.");
                shouldHalt = true;
            }
            */

            // Check if bombshell dit hit target bunker.
            if (Math.abs(bombshellPathComputers[0].getCurrentCoordinates().getX() - mTargetBunkerVC.getX()) < TwoPlayerGameView.BUNKER_RADIUS * BUNKER_HITBOX_EXPANSION_RATIO &&
                    Math.abs(bombshellPathComputers[0].getCurrentCoordinates().getY() - mTargetBunkerVC.getY()) < TwoPlayerGameView.BUNKER_RADIUS * BUNKER_HITBOX_EXPANSION_RATIO) {
                Log.d(LOG_TAG, "Bombshell collided with target Bunker.");
                shouldHalt = true;
            }

            // Check that bombshell did not collide landscape.
            if (bombshellPathComputers[0].getCurrentCoordinates().getY() > getLandscapeHeightForX(bombshellPathComputers[0].getCurrentCoordinates().getX())) {

                Log.d(LOG_TAG, "Bombshell collided with landscape.");
                /*
                Log.d(LOG_TAG, "Bombshell X : " + bombshellPathComputers[0].getCurrentCoordinates().getX());
                Log.d(LOG_TAG, "Bombshell Y : " + bombshellPathComputers[0].getCurrentCoordinates().getY());
                */
                shouldHalt = true;
            }

            // Check that bombshell did not left the screen from right of left side (+ bottom but is it really useful?).<commit_msg>Minor code cleaning, now ready for big refactor.<commit_after>package fr.leomoldo.android.bunkerwar;


import android.os.AsyncTask;
import android.util.Log;

import fr.leomoldo.android.bunkerwar.drawer.Landscape;
import fr.leomoldo.android.bunkerwar.sdk.ViewCoordinates;

/**
 * Created by leomoldo on 19/05/2016.
 */
public class BombshellAnimatorAsyncTask extends AsyncTask<BombshellPathComputer, ViewCoordinates, Boolean> {

    private static final String LOG_TAG = BombshellAnimatorAsyncTask.class.getSimpleName();

    private final static int ITERATION_WAITING_TIME = 10;
    private final static float BUNKER_HITBOX_EXPANSION_RATIO = 2f;

    private TwoPlayerGameView mGameView;
    private int mViewHeight;
    private int mViewWidth;
    private ViewCoordinates mTargetBunkerVC;
    private Landscape mLandscape;

    public BombshellAnimatorAsyncTask(TwoPlayerGameView gameView, Landscape landscape, ViewCoordinates targetBunkerVC) {
        mGameView = gameView;
        mLandscape = landscape;
        mViewHeight = mGameView.getHeight();
        mViewWidth = mGameView.getWidth();
        mTargetBunkerVC = targetBunkerVC;

        /*
        Log.d(LOG_TAG, "View Width : " + mViewWidth);
        Log.d(LOG_TAG, "View Height : " + mViewHeight);
        */
    }

    @Override
    protected Boolean doInBackground(BombshellPathComputer... bombshellPathComputers) {
        Boolean shouldHalt = false;
        while (!shouldHalt) {
            bombshellPathComputers[0].incrementCoordinates();
            publishProgress(bombshellPathComputers[0].getCurrentCoordinates());
            /*
            Log.d(LOG_TAG, "timeCounter : " + bombshellPathComputers[0].getTimeCounter());
            Log.d(LOG_TAG, "currentBombshellX : " + bombshellPathComputers[0].getCurrentCoordinates().getX());
            Log.d(LOG_TAG, "currentBombshellY : " + bombshellPathComputers[0].getCurrentCoordinates().getY());
            */
            try {
                Thread.sleep(ITERATION_WAITING_TIME);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            // We must prevent the playing bunker from hitting itself when firing (don't check when timecounter is to low).
            // Check if bombshell dit hit player one bunker.
            /*
            if ( Math.abs(bombshellPathComputers[0].getCurrentCoordinates().getX() - mBunkerPlayerOneCoordinates.getX()) < GameView.BUNKER_RADIUS &&
                    Math.abs(bombshellPathComputers[0].getCurrentCoordinates().getY() - mBunkerPlayerOneCoordinates.getY()) < GameView.BUNKER_RADIUS) {
                Log.d(LOG_TAG, "Bombshell collided with player ONE.");
                shouldHalt = true;
            }
            */

            // Check if bombshell dit hit target bunker.
            if (Math.abs(bombshellPathComputers[0].getCurrentCoordinates().getX() - mTargetBunkerVC.getX()) < TwoPlayerGameView.BUNKER_RADIUS * BUNKER_HITBOX_EXPANSION_RATIO &&
                    Math.abs(bombshellPathComputers[0].getCurrentCoordinates().getY() - mTargetBunkerVC.getY()) < TwoPlayerGameView.BUNKER_RADIUS * BUNKER_HITBOX_EXPANSION_RATIO) {
                Log.d(LOG_TAG, "Bombshell collided with target Bunker.");
                shouldHalt = true;
            }

            // Check that bombshell did not collide landscape.
            if (bombshellPathComputers[0].getCurrentCoordinates().getY() > getLandscapeHeightForX(bombshellPathComputers[0].getCurrentCoordinates().getX())) {

                Log.d(LOG_TAG, "Bombshell collided with landscape.");
                /*
                Log.d(LOG_TAG, "Bombshell X : " + bombshellPathComputers[0].getCurrentCoordinates().getX());
                Log.d(LOG_TAG, "Bombshell Y : " + bombshellPathComputers[0].getCurrentCoordinates().getY());
                */
                shouldHalt = true;
            }

            // Check that bombshell did not left the screen from right of left side (+ bottom but is it really useful?).
{'fraction_non_alphanumeric': 0.09819186338523356, 'fraction_numerical': 0.006027122049221497, 'mean_word_length': 2.7359287054409007, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 7, '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': '3526216', 'n_tokens_mistral': 2414, 'n_tokens_neox': 2357, 'n_words': 439}