ICT290 / src / scene / AIController / Goals / GoalDodgeSideToSide.cpp
GoalDodgeSideToSide.cpp
Raw
#include "GoalDodgeSideToSide.h"
#include "../GameWorld.h"
#include "../SteeringBehaviours.h"
#include "../Vehicle.h"
#include "GoalSeekToPosition.h"

#include "../Messaging/ArcanistMessaging.h"
#include "../Messaging/Telegram.h"

//#include "debug/DebugConsole.h"
//#include "misc/cgdi.H"

/*
GoalDodgeSideToSide::GoalDodgeSideToSide(Vehicle* Bot):Goal<Vehicle>(Bot,
goal_strafe){

    m_Clockwise = rand() % 2;
    //m_Clockwise(RandBool())
}*/

//------------------------------- Activate ------------------------------------
//-----------------------------------------------------------------------------
void GoalDodgeSideToSide::Activate() {
    m_Status = active;
    markOwnerWithGoal();

    m_Owner->getSteering()->SeekOn();

    if (m_Clockwise) {
        if (m_Owner->canStepRight(m_StrafeTarget)) {
            m_Owner->getSteering()->setTarget(m_StrafeTarget);
            // std::cout << "Bot " << m_Owner->getID() << " step right to " <<
            // m_StrafeTarget.x << " " << m_StrafeTarget.y << std::endl;
        } else {
            // debug_con << "changing" << "";
            m_Clockwise = !m_Clockwise;
            m_Status = inactive;
        }
    }

    else {
        if (m_Owner->canStepLeft(m_StrafeTarget)) {
            m_Owner->getSteering()->setTarget(m_StrafeTarget);
            // std::cout << "Bot " << m_Owner->getID() << " step left to " <<
            // m_StrafeTarget.x << " " << m_StrafeTarget.y << std::endl;
        } else {
            // debug_con << "changing" << "";
            m_Clockwise = !m_Clockwise;
            m_Status = inactive;
        }
    }
}

//-------------------------- Process ------------------------------------------
//-----------------------------------------------------------------------------
int GoalDodgeSideToSide::Process() {
    // if status is inactive, call Activate()
    activateIfInactive();

    // if target goes out of view terminate
    if (!m_Owner->getTargetSys()->isTargetWithinFOV()) {
        m_Status = completed;
    }

    // else if bot reaches the target position set status to inactive so the
    // goal is reactivated on the next update-step
    else if (m_Owner->isAtPosition(m_StrafeTarget)) {
        m_Status = inactive;
    }

    return m_Status;
}

//---------------------------- Terminate --------------------------------------
//-----------------------------------------------------------------------------
void GoalDodgeSideToSide::Terminate() {
    m_Owner->getSteering()->SeekOff();
}