#include "dk_misc.h"

#include "dk_shared.h"
#include "dk_gce_script.h"
#include "dk_gce_entities.h"



CScriptEntity::CScriptEntity() {
    name = "";
}

CScriptEntity::~CScriptEntity() {

}

void CScriptEntity::Reset() {
    name = "";

    tasks.Reset();
}

void CScriptEntity::operator=(const CScriptEntity &other) {
    name = other.name;

    tasks = other.tasks;
}

const char *CScriptEntity::Name() const {
    return name;
}

const task_list &CScriptEntity::Tasks() const {
    return tasks;
}

void CScriptEntity::Name(const char *name) {
    this->name = name;
}

void CScriptEntity::Add(CScriptEntityTask *task) {
    if (task == NULL) return;

    tasks.Add(task);
}

task_list &CScriptEntity::GetTasks() {
    return tasks;
}

int CScriptEntity::Compare(const CScriptEntity **e1, const CScriptEntity **e2) {
    if (e1 == NULL || e2 == NULL) return 0;
    if (*e1 == NULL || *e2 == NULL) return 0;

    return stricmp((*e1)->Name(), (*e2)->Name());
}

int CScriptEntity::Find(const CScriptEntity *entity, const void *identifier) {
    if (entity == NULL || identifier == NULL) return 0;

    //the identifier is a string.
    const char *name = (const char *)identifier;

    //compare the name with the entity's name.
    int compare = stricmp(name, entity->Name());

    if (compare == 0) return 0;
    if (compare < 0) return -1;
    else return 1;
}



CScriptEntityTask::CScriptEntityTask() {
    time = -1.0f;
    type = TT_NONE;
}

CScriptEntityTask::~CScriptEntityTask() {

}

void CScriptEntityTask::Reset() {
    time = -1.0f;
    type = TT_NONE;
}

void CScriptEntityTask::operator=(const CScriptEntityTask &other) {
    time = other.time;
    type = other.type;

    destination = other.destination;

    direction = other.direction;
}

task_type CScriptEntityTask::Type() const {
    return type;
}

const char *CScriptEntityTask::TypeString() const {
    switch (type) {
        case TT_NONE:
            return "None";
        case TT_MOVE_TO:
            return "Move To";
        case TT_TURN:
            return "Turn";
        case TT_MOVE_AND_TURN:
            return "Move and Turn";
        default:
            return "None";
    }
}

float CScriptEntityTask::Time() const {
    return time;
}

const point &CScriptEntityTask::Destination() const {
    return destination;
}

const point &CScriptEntityTask::Direction() const {
    return direction;
}

void CScriptEntityTask::MoveTo(const point &dest) {
    type = TT_MOVE_TO;

    destination = dest;
}

void CScriptEntityTask::Turn(const point &dir) {
    type = TT_TURN;

    direction = dir;
}

void CScriptEntityTask::MoveAndTurn(const point &dest, const point &dir) {
    type = TT_MOVE_AND_TURN;

    destination = dest;
    direction = dir;
}

void CScriptEntityTask::Time(float time) {
    this->time = time;
}




