#pragma once

#include "dk_array.h"
#include "dk_gce_point.h"


//an enum to specify the different tasks.
typedef enum {
    TT_NONE,
    TT_MOVE_TO,
    TT_TURN,
    TT_MOVE_AND_TURN,
} task_type;

class CScriptEntityTask {
public:
    CScriptEntityTask();
    ~CScriptEntityTask();

    void Reset();

    void operator=(const CScriptEntityTask &other);

    void Save(FILE *file) const;
    void Load(FILE *file, int version);

protected:
    //the type of task 
    task_type type;

    //when the task is started.  a time of -1 means that the the task starts as soon as the previous task
    //is completed.
    float time;

    //a point that the entity will move to
    point destination;

    //a direction to face.
    point direction;

public:
    //
    //member access
    //
    task_type Type() const;
    float Time() const;
    const point &Destination() const;
    const point &Direction() const;
    const char *TypeString() const;


    //
    // functions to modify the script.
    //
    //one function for each of the task types.
    void MoveTo(const point &dest);
    void Turn(const point &dir);
    void MoveAndTurn(const point &dest, const point &dir);

    void Time(float time);

};

typedef array<CScriptEntityTask> task_list;

class CScriptEntity {
public:
    CScriptEntity();
    ~CScriptEntity();

    void Reset();

    void operator=(const CScriptEntity &other);

    void Save(FILE *file) const;
    void Load(FILE *file, int version);

protected:
    //the name of the entity.
    buffer16 name;

    //each entity has a list of tasks that it must perform
    task_list tasks;

    //
    //playback vars
    //
    int next_task;
public:
    //
    //member access
    //
    const char *Name() const;
    const task_list &Tasks() const;

    //compare functions used for sorting, etc.
    static int Compare(const CScriptEntity **e1, const CScriptEntity **e2);
    static int Find(const CScriptEntity *entity, const void *identifier);

    //
    //for modifying the entity.
    //
    void Name(const char *name);
    void Add(CScriptEntityTask *task);
    task_list &GetTasks();

    //
    //playback functions
    //
    void PlaybackReset();
    void Playback(int end_time);
    bool Done() const;
};

