/*
 *  ALLL Plan
 *
 *  2004 - 2011 Frantisek Zboril jr.
 *  Faculty of Information Technology
 *  zborilf@fit.vutbr.cz
 *  http://www.fit.vutbr.cz/~zborilf
 *
 * (C) Brno University of Technology
 * Freeware licence VUT v Brně
 * https://wis.fit.vutbr.cz/FIT/db/dir.php/dr/VZ2007/externiInformace/softwareNaWebu/Priloha2_rozh23.pdf

 */

package jTMass.core.jALLL.jTObjects;

import jTMass.core.jAMass.jActions.TAction;
import jTMass.core.jAMass.TAgent;
import jTMass.core.jAMass.jActions.TEOP;


public class TPlan extends TList{

    @Override
    public TObject substituteRegisters(TAgent agent){
    	super.substituteRegisters(agent);
	return(this);
    }

    @Override
    public TObject cloneObject(){
	TObject clone;

        TPlan plan=new TPlan(this.getType());
	for(int i=0;i<PList.size();i++){
            TObject source=(TObject)PList.get(i);
            clone=source.cloneObject();
            plan.add(clone);
	}
	return(plan);
    }
	
    public TAction popAction(){
        return((TAction)super.popFirst());
    }
	
    public void addFirst(TPlan plan){
	super.addFirst((TList)plan);
    }
	
    public void expandPlan(TPlan plan, TAgent agent){
        if (this.get(0) instanceof TEOP)
            this.popAction().execute(agent);
        
        TPlan newplan=(TPlan)plan.cloneObject();
        newplan.substituteRegisters(agent);
        newplan.matureRegisters();
        super.appendFirst(newplan);
    }
	
    // ===== CONSTRUCTOR =====

    public TPlan(int type){
	super(type);
    }

}
