With a bunch of changes to KoLmafia, this script:
Code:
typedef string[] type_v;
typedef string type_k;
type_v [type_k] quests;
file_to_map( "questslog.txt", quests );
print( "There are " + count( quests ) + " quests." );
int longest_quest = 0;
string key = "";
foreach quest, steps in quests {
if ( count( steps ) > longest_quest ) {
longest_quest = count( steps );
key = quest;
}
}
print( "Quest '" + key + "' has " + longest_quest + " steps." );
type_v steps = quests[ key ];
print( steps );
foreach i, step in steps {
print( i + ": " + step );
}
yields this:
Code:
> Test/questlog.ash
There are 96 quests.
Quest 'questG04Nemesis' has 32 steps.
aggregate string [32]
0: Me and My Nemesis
1: Search the Misspelled Cemetary on the Nearby Plains for the Tomb of the Unknown
2: in the Misspelled Cemetary wants to fight you to test your worthiness.
3: Talk to the Ghost of the Unknown
4: Retrieve the Epic Weapon!
5: You've reclaimed the Epic Weapon! Time to go show it off at your guild.
6: recover the missing piece of the Legendary Epic Weapon.
7: Inform your guild that Beelzebozo has been dispatched.
8: Meatsmith the two parts of the Legendary Epic Weapon back together -- you'll need a tenderizing hammer from the Meatsmith.
9: Take the Legendary Epic Weapon back to your guild.
10: (no quest entry at all!)
11: The hunt for your Nemesis is on! Better check out that cave they sent you to.
12: Figure out how to get into your Nemesis' cave. If you're stumped, maybe your guild can help?
13: The cavern is full of weird mushrooms, but where's your Nemesis?
14: more fizzing spore pods to blow up the blockade in your Nemesis' cave.
15: Take those fizzing spore pods to the rubble!
16: Boom! Time to bring the fight to your stinking Nemesis in that stinking cave!
17: Heck yeah, you beat your Nemesis and got a sweet hat. Better take it back to your guild.
18: You're waiting for your guild's scouts to find out where your Nemesis went.
19: It appears as though some nefarious ne'er-do-well has put a contract on your head!<p>Gee, I wonder who it could be...
20: You handily dispatched some thugs who were trying to collect on your bounty, but something tells you they won't be the last ones to try.
21: Whoever put this hit out on you (like you haven't guessed already) has sent Mob Penguins to do their dirty work. Do you know any polar bears you could hire as bodyguards? No? Looks like you're on your own, then.
22: So much for those mob penguins that were after your head! If whoever put this hit out on you wants you killed (which, presumably, they do) they'll have to find some much more competent thugs.
23: Your suspicious[sic] have been confirmed: your Nemesis has put the order out for you to be hunted down and killed, and now they're sending their own guys instead of contracting out. Good luck!
24: Bam! So much for your Nemesis' assassins! If that's the best they've got, you have nothing at all to worry about.<p>You sure hope that's the best they've got.
25: You had a run-in with some crazy mercenary or assassin or... thing that your Nemesis sent to do you in once and for all. A run-in followed by a run-out, evidently, but you're going to have to deal with this sooner or later.
26: Now that you've dealt with your Nemesis' assassins and found a map to the secret tropical island volcano lair, it's time to take the fight to your foe. Booyah.
27: You've arrived at the secret tropical island volcano lair, and it's time to finally put a stop to this Nemesis nonsense once and for all. As soon as you can find where they're hiding. Maybe you can find someone to ask.
28: got away. Again.
29: Congratulations on solving the lava maze, which is probably the biggest pain-in-the-ass puzzle in the entire game! Hooray! (Unless you cheated, in which case: Boo!)
30: have some sort of crazy powerful and hideous final form? I was, but then I wrote all of this, so, y'know.
31: Okay, now you've defeated your Nemesis once and for all! (Well, probably. Almost definitely.) Nevermore will the members of whichever class you're playing at the moment be hassled by that terrible entity! Way to go!
Issues I found with aggregate literals:
1) They did not work in foreach since they didn't have iterators
2) Given iterators, you couldn't fetch values, since they didn't have aref
[3) They didn't have aset either. Since they are immutable, they should, but should generate a runtime error]
4) count() always returned 0
I fixed all of the above and also modified file_to_map as proposed: if you read into a 0-length array, you get all the remaining fields on the line read as the appropriate data type.
This is backwards-incompatible since if you tried it before, we threw an exception, caught it, and reported a "bad line" in your input file. Which is to say, it never did anything reasonable before and now it does.
As coded, it only works if your type_v is a simple type - one field per value. If you want the remaining fields to be <n> records, each with three fields, thus consuming fields three at a time, no go. I'd have to see an actual use case for this before I'd be inclined to make that work.