I have it figured out. I tested it in the Spooky Forest, which has a choice chain which leads to fighting a spooky vampire.
OK. We already had an alternate version of run_choice() which did what the ASH script needs.
string run_choice( int option )
string run_choice( int option, boolean automateFIghts )
The first version calls run_choice( option, true )
Therefore, if the choice redirects to a fight, we run the fight before that call to run_choice() returns.
Now, if you call run_choice( -1 ), you are saying "go to goal" - follow a sequence of choices. If that ends in a fight, we automate it.
But if you KNOW the choice you are submitting ends in a fight, if you call run_choice ( X, false ), it will return after getting the redirection and taking it - getting the Round 0 fight page.
run_choice() then returns.
I added fight_follows_choice() for this case, and you can then call run_combat().
Or, if you kicked this off with adv1() or adventure() and your choiceAdventureScript() handled the choices, adv1() or adventure() will automate the fight.
I modified my ChoiceAdventureTest.ash to do this in the spooky forest.
Test 1: Spooky Forest (with choiceAdventureScript), goal = 1 choice, 10 turns:
Code:
[1082813] The Spooky Forest
Encounter: Arboreal Respite
> In choice adventure 502
Took choice 502/2: gain mosquito larva or spooky mushrooms, skip adventure, get stats or fight a vampire
choice.php?whichchoice=502&option=2&pwd
Encounter: Consciousness of a Stream
> Done!
> In choice adventure 505
Took choice 505/3: fight a spooky vampire
choice.php?whichchoice=505&option=3&pwd
Encounter: An Interesting Choice
> Done!
> In choice adventure 46
Took choice 46/3: vampire heart
choice.php?whichchoice=46&option=3&pwd
Encounter: spooky vampire
Round 0: Chondara wins initiative!
> Heading into a fight...
> Done!
Round 1: Chondara executes a macro!
Round 1: Chondara attacks!
Round 2: spooky vampire takes 4402 damage.
Round 2: Silence climbs up and sits on your shoulder, and hands you some Meat. Huh, where did he find that?
You gain 57 Meat.
Round 2: Chondara wins the fight!
After Battle: Silence sits on your fallen opponent's body, blows a smoke ring, and winks at you.
You gain 36 Meat
After Battle: You gain 2 Wizardliness
After Battle: You gain 2 Smarm
Notice that my choceAdventureScript was called 3 times - choice 502, 505, 46. For 46, after it submitted the choice, fight_follows_choice() was true. My script exited, adventuring finished off the fight, and the goal was met.
I then set auto-attack to "attack" to see what happens when the fight was fought and won immediately.
Code:
[1082819] The Spooky Forest
Encounter: Arboreal Respite
> In choice adventure 502
Took choice 502/2: gain mosquito larva or spooky mushrooms, skip adventure, get stats or fight a vampire
choice.php?whichchoice=502&option=2&pwd
Encounter: Consciousness of a Stream
> Done!
> In choice adventure 505
Took choice 505/3: fight a spooky vampire
choice.php?whichchoice=505&option=3&pwd
Encounter: An Interesting Choice
> Done!
> In choice adventure 46
Took choice 46/3: vampire heart
choice.php?whichchoice=46&option=3&pwd
Encounter: spooky vampire
Round 0: Chondara wins initiative!
Round 0: Chondara attacks! (auto-attack)
Round 1: spooky vampire takes 4390 damage.
Round 1: Chondara wins the fight!
After Battle: Silence sits on your fallen opponent's body, blows a smoke ring, and winks at you.
You gain 17 Meat
After Battle: You gain 1 Beefiness
After Battle: You gain 2 Enchantedness
> Done!
Notice that my script submitted run_choice(), which redirected to the fight, which was instantly over. fight_follows_choice() was NOT true, and the choiceAdventureScript exited after the fight was over.
I just tested this with The Gourd! and it worked fine. I adjusted my ChoiceAdventureScript so that all the various stages that led to a fight called run_choice( X, false). I told the GUI to adventure for 1 turn in The Gourd! and it did the whole thing, just as before.
Revision 19953 has this. Your change is to NOT do run_combat() in your choiceAdventureScript after you tell it to return to the fight. Instead, call run_choice( 1, false ) and let adv1 resume the fight for you. Hopefully, that will work even if Ed dies again in the second and third fights.
FYI, here is my modified test script.
Code:
void main( int choice, string page )
{
// code to handle the choice, using available_choice_options(), run_choice(), etc.
print( "In choice adventure " + choice );
int option = 0;
boolean fight = false;
switch ( choice ) {
// The Spooky Forest
case 26: // A Three-Tined Fork
// 1 => 27, 2 => 28, 3 => 29
option = 2;
break;
case 27: // Footprints
// 1 => Seal Clubber, 2 => Turtle Tamer
option = 2;
break;
case 28: // A Pair of Craters
// 1 => Pastamancer, 2 => Sauceror
option = 2;
break;
case 29: // The Road Less Visible
// 1 => Disco Bandit, 2 => Accordion Thief
option = 2;
break;
case 46: // An Interesting Choice
// 1 => mysticality, 2 => Muscle, 3 => fight
option = 3;
fight = true;
break;
case 47: // Have a Heart
// 1 => give hearts, 2 => exit choice
option = 1;
break;
case 502: // Arboreal Respite
// 1 => 503, 2 => 505, 3 => 506
option = 2;
break;
case 503: // The Road Less Traveled
// 1 => Meat, 2 => wooden stakes or 47, 3 => 504
option = 1;
break;
case 504: // Tree's Last Stand
// 1, 2, 3 => (buy or sell) and stay in 504, 4 => exit choice
option = 4;
break;
case 505: // Consciousness of a Stream
// 1 => mosquito larva or 3 spooky mushrooms, 2 => tree-holed coin or nothing, 3 => 46
option = 3;
break;
case 506: // Through Thicket and Thinnet
// 1 => 26, 2 => Spooky-Gro fertilizer, 3 => 507
option = 1;
break;
case 507: // O Lith, Mon
// 1 => Spooy Temple map, 2 => exit choice, 3 => exit choice
option = 1;
break;
// The Gourd!
case 619: // To Meet a Gourd
case 620: // A Blow is Struck!
case 621: // Hold the Line!
case 622: // The Moment of Truth
// The following occur if you leave the battle and return
case 623: // Return To the Fray!
case 624: // Returning to Action
// All of the above lead to a fight
fight = true;
case 634: // Goodbye Fnord
option = 1;
break;
// The Haunted Bedroom
case 876: // One Simple Nightstand
case 877: // One Mahogany Nightstand
case 878: // One Ornate Nightstand
case 879: // One Rustic Nightstand
option = 1;
break;
case 880: // One Elegant Nightstand
option = 2;
break;
default:
print( "not handling " + choice );
return;
}
// Argument 2 is "should automate fights" We don't want to do that
// inside this script; follow the redirect and leave it to outer
// automation.
run_choice( option, !fight );
if ( fight_follows_choice() ) {
print( "Heading into a fight..." );
}
print( "Done!" );
}