/*
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

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; }
}
