Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.
Matthew Pohlmann edited this page Jan 1, 2014 · 1 revision

###Data

Market homeStructure;

List<Delivery> deliveries;

class Delivery { Map<String,Integer> inventory, Structure destination,DeliveryState s, int id};

enum DeliveryState {NotDone,InProgress,Done};

###Messages

public void msgMakeDeliveryRun( Map<String,Integer> inventory, Structure destination, int id)
{
	deliveries.add(new Delivery(inventory,destination,id));
}

###Scheduler

@Override
protected void pickAndExecuteAnAction()
{
	if deliveries.isEmpty() && currentLocation != homeStructure
		returnHome();
	else
		if there exists some Delivery d in deliveries such that
			d.s = Failed
				homeStructure.manager.msgDeliveryFailed(d.id)
			d.s = Done
				deliveries.remove(d);
			d.s = NotDone
				makeDeliveryRun (d);
}

###Actions

private void returnHome()
{
	msgSetDestination (homeStructure);
	doGoToDestination ();
}

private void makeDeliveryRun(Delivery d)
{
	msgSetDestination(homeStructure);
	doGoToDestination();
	
	msgSetDestination(d.destination);
	d.s = InProgress;
	doGoToDestination();
	
	d.destination.msgMakeDelivery(inventory);
	
	if delivery failed
		d.s = Failed
	d.s = Done;
}
Clone this wiki locally