boolean eat_muffin()
{
item available_muffin()
{
foreach muffin in valid_muffins {
if ( available_amount( muffin ) > 0 ) {
retrieve_item( 1, muffin );
return muffin;
}
}
return NO_ITEM;
}
int monorail_index( string text )
{
foreach n, button in available_choice_options() {
if ( button == text ) {
return n;
}
}
return 0;
}
void visit_breakfast_counter()
{
int index = monorail_index( "Visit the Breakfast Counter" );
run_choice( index );
}
void order_next_muffin( item previous )
{
item next_muffin = muffin_to_order;
if ( next_muffin == NO_ITEM ) {
switch ( previous ) {
case BLUEBERRY_MUFFIN:
next_muffin = BRAN_MUFFIN;
break;
case BRAN_MUFFIN:
next_muffin = CHOCOLATE_CHIP_MUFFIN;
break;
case CHOCOLATE_CHIP_MUFFIN:
case NO_ITEM:
next_muffin = BLUEBERRY_MUFFIN;
break;
}
}
// We have to search for the correct option; apparently, some
// times you are also offered the chance to buy another muffin tin.
int index = monorail_index( "Order a " + next_muffin );
run_choice( index );
}
void return_to_platform()
{
int index = monorail_index( "Back to the Platform!" );
run_choice( index );
}
void leave_platform()
{
int index = monorail_index( "Nevermind" );
run_choice( index );
}
item last_muffin = NO_ITEM;
item available = available_muffin();
// Eat a muffin
while ( true ) {
// If we have a muffin, eat it now
if ( available != NO_ITEM ) {
eat_food( 1, available );
last_muffin = available;
break;
}
// No muffin in inventory. Make sure we have a muffin tin in
// inventory, if possible, in case we need to order a muffin.
if ( available_amount( MUFFIN_TIN ) > 0 ) {
retrieve_item( 1, MUFFIN_TIN );
}
// Visit Breakfast Counter to pick up our order, if any.
visit_url( "place.php?whichplace=monorail&action=monorail_downtown" );
visit_breakfast_counter();
// If we got a muffin, exit the breakfast counter and eat it.
available = available_muffin();
if ( available != NO_ITEM ) {
return_to_platform();
leave_platform();
continue;
}
// We did not have a muffin waiting. We can't eat today.
if ( available_amount( MUFFIN_TIN ) > 0 &&
get_property( "muffinOnOrder" ) == "none" ) {
// Order a muffin for tomorrow
order_next_muffin( NO_ITEM );
}
// Exit the Breakfast Counter. We're done here.
return_to_platform();
leave_platform();
return false;
}
// We've eaten a muffin and have a muffin tin in inventory.
// Order a new muffin
visit_url( "place.php?whichplace=monorail&action=monorail_downtown" );
visit_breakfast_counter();
// We might have already ordered a muffin today
if ( get_property( "muffinOnOrder" ) == "none" ) {
order_next_muffin( last_muffin );
}
return_to_platform();
leave_platform();
return true;
}