package macampcorp.macamp.game.scheduler;

import java.io.Serializable;

import macampcorp.macamp.activities.HostActivity;
import macampcorp.macamp.game.Game;

public abstract class Task implements Serializable {
    public final static int TASK_NONE=0;
    public final static int TASK_CHALLENGE=1;
    public final static int TASK_EVENT=2;
    public final static int TASK_RESOURCE=3;
    public final static int TASK_SPECIAL=4;
    public final static int TASK_WAIT=5;

    protected int mType;
    protected Task mNext=null;

    public Task(int type){ mType=type;}

    public abstract int exec(Scheduler s, HostActivity cd, Game g);


    public Task end()
    {
        Task t = this;
        while(t.mNext!=null) t=t.mNext;
        return t;
    }

    public void insertAfter(Task t)
    {
        Task tt = mNext;
        mNext=t;
        Task e = mNext.end();
        e.mNext=tt;
    }

    public void enqueue(Task t)
    {
        Task e = end();
        e.insertAfter(t);
    }

    public Task next()
    {
        return mNext;
    }

    public int type() { return mType; }
}
