import swarm.Globals;
import swarm.objectbase.SwarmImpl;
import swarm.objectbase.Swarm;
import swarm.Selector;
import swarm.activity.Activity;
import swarm.activity.ScheduleImpl;
import swarm.activity.Schedule;
import swarm.defobj.Zone;

public class DropSwarm extends SwarmImpl {
    Schedule schedule;

    DropSwarm (Zone aZone) {
        super (aZone);
    }

    static void main (String args[]) {
        Globals.env.initSwarm ("DropSwarm", "0.0", "bug-swarm@swarm.org",
                               args);
        
        Swarm swarm = new DropSwarm (Globals.env.globalZone);

        swarm.buildObjects ();
        swarm.buildActions ();
        swarm.activateIn (null).run ();
        swarm.drop ();
    }

    public void stepAgent () {
        System.out.println ("stepAgent " + Globals.env.getCurrentTime ());
        getActivity ().terminate ();
    }
    
    public Object buildActions () {
        schedule = new ScheduleImpl (getZone ());

        try {
            Selector sel = new Selector (getClass (), "stepAgent", false);
            
            schedule.at$createActionTo$message (0, this, sel);
            schedule.at$createActionTo$message (1, this, sel);
        } catch (Exception e) {
            e.printStackTrace (System.err);
            System.exit (1);
        }
        return this;
    }
    
    public Activity activateIn (Swarm swarmContext) {
        super.activateIn (swarmContext);

        schedule.activateIn (this);
        return getActivity ();
    }
}

