Universal Recovery Script

Been meaning to check this script out for a while, and finally had the chance to play with it yesterday. It's awesome! This is a significant step up from mafia's automatic restore capability.

I did have two very minor "UI"-type qualms:
1) Massive amount of comments at the top is actually a bit confusing. At least keep the version history in the thread rather than the script.
2) Between combats it tends to print the restore settings... twice. I would personally prefer a cleaner CLI. Perhaps only print that message when restoring is necessary.

Major kudos, Bale.
 
Been meaning to check this script out for a while, and finally had the chance to play with it yesterday. It's awesome! This is a significant step up from mafia's automatic restore capability.
Thank you very much. I really appreciate the praise, considering my own respect for your skills.

2) Between combats it tends to print the restore settings... twice. I would personally prefer a cleaner CLI. Perhaps only print that message when restoring is necessary.
It actually prints once each time it is called by mafia. First mafia calls it for restoring HP, then mafia calls it a second time to restore MP.

It is a worthwhile point that it might be better to only comment when it is actually restoring HP/MP. It actually used to be even more verbose, but as it has become more reliable, the need for feedback is decreasing. I suppose optimally it would become as quiet as mafia is so that you can ignore its existence...

In the meantime, you can feel free to delete those print commands. (lines 1165, 1166, 1172 and 1184 can be safely deleted.)
 
Last edited:
Regarding use of moth in birdform. I was expecting the script to use it only if it restores a major amount of MP. I was down 15 MP, and had plenty of other options (Mountain Stream soda, access to white citadel, access to the lab) and still it used my precious moth.

This might relate to a bigger issue. If you have an item that can restore a large amount, and you only need a small amount, would it be used?
 
This was actually a difficult design decision. The moth and grub are exceptions to the rule of never using items that can restore large amounts to heal small amounts. (Another exception is the nuns--for obvious reasons.)

In my early testing of the script I found that it was burning a lot of meat to heal my MP while moths were piling up. Quite simply the moths weren't being used as often as I'd like. Eventually I settled on the simple solution of always using moths first if you are in birdform and the moth is available. Since I spend a comparatively small amount of time in birdform it seemed a good idea to use the moths when they were usable.

I've been pretty comfortable with the solution, but if you have a better one I'd be glad to make use of it. How would you decide when to use a moth? Would you wait until you were at least 40 MP down? Note that this would sometimes make it impossible to use moths while building up roc feathers to use when you reach level 4. (And I really need those mp to get those precious feathers.) Or would you want to base your decision to use moths on your maximum MP, so if it is low, then you'll be more permissive about using them. If you've got a solution that I never thought of I'd be overjoyed.

Similarly, what about grubs? Please remember that both of these items have a narrow window of time to use them so if you don't use them while in birdform they'll just be wasted.
 
I like that it uses my moths and grubs. I usually have 5-6 left of grubs at the end of my ascension anyway, they'd just go to waste otherwise. In moxie/myst runs, you will almost never have enough hp to make grubs worthwhile until level 11/12. By then, you will certainly have better options/ more meat for conventional healing. Spending them in the early game conserves precious early resources.

As for moths, I'd be fine either way. Once again, moths conserve precious early resources. If you cast mojo, you usually don't even overflow much, so I don't see a problem. I would see how it would bother some people though.

Would it be possible to have a couple of global variables that the user can edit in the beginning of the script that turn settings on/off? That would enable some options, so the people that would rather use their moths/grubs immediately could keep that functionality, but those that don't want waste could turn it off. It would also work well with the SGEEA issue as well, allowing you to set whether it saves one or not, even if the teleport potion has been identified. Just an idea.
 
I'm just throwing an idea here, but it seems to me that if you are 5/25 MP a moth is a good use but at 45/55 it's a bad use. So maybe it also has to do with your max MP.

Same for grub, 10/50 HP is good, 80/100 HP isn't.
 
What would you say the minimum level for using a moth is? 5/25? 7/28? 10/30? I could program it not to use one unless below 1/5 or 1/4 or 1/3 of maxhp if it would be partially wasted.
 
I'm in the always use grubs and moths camp myself. If mafia's restoring at 45/55, you're restore settings are probably wrong.

I'm still running into issues where the script is buying more expensive restoratives than it needs for some reason. This is an example that just happened:

Using cached search results for ancient Magi-Wipes...
Purchasing ancient Magi-Wipes (2 @ 170)...
You acquire ancient Magi-Wipes (2)
Purchases complete.
Using 2 ancient Magi-Wipes...
You gain 111 hit points
You gain 111 Muscularity Points
Finished using 2 ancient Magi-Wipes.
Using cached search results for palm frond...
Purchasing palm frond (2 @ 100)...
You acquire palm frond (2)
Purchases complete.
Using 2 palm frond...
You acquire an item: palm-frond fan
Finished using 2 palm frond.
Using 1 palm-frond fan...
You gain 42 hit points
You gain 39 Muscularity Points
Finished using 1 palm-frond fan.

There are plenty of ancient Magi-Wipes in the mall at 170, the palm-frond fan at 200 for less restoration was glaringly odd here.
 
I'm in the always use grubs and moths camp myself. If mafia's restoring at 45/55, you're restore settings are probably wrong.

Unless I was clicking on the MP link in the relay browser, which I was. I had something like 35/45, and I was going to go to the Knob Shaft to get 9 quick shots. That's what I do if I realize I have spent 10 bird adventures and got only 5 hits. So first thing, I click on the MP link in relay.
 
How about I refuse to use the moth (or grub) unless you can make use of at least 1/2 of their healing power? How does that sound? Should I make it 1/3?
 
I'd go with 1/2 on the moths, but the grubs I'd put in as lower, maybe even 1/5 for the grubs. I'm sitting at lv8 in my current run, and I only have 45 max hp.

Also, sorry for another nit-picky thing, but I'd prefer if the script didn't use my massage oils. I don't usually get them in-run, but I did this time as a mistake. If I do have them, I like saving them for my shadow, or having them as oh-crap combat restoratives for emergencies. I'd rather not use them on regular healing.

EDIT: Oops, I guess you can turn the oils off with the Kolmafia HP/MP menu. Silly me.
EDIT EDIT: However, I guess the HP/MP thing doesn't acually work. I don't have the massage oils box checked, but it used them anyway.
 
Last edited:
I have to disagree on the thresholds here. When I have grubs and moths, I want to be using them instead of other things almost universally. Even so, I still end runs with plenty of grubs left over generally, which is a waste.

At the vary least, make the threshold easily configurable inside the script.
 
Universal recovery v 2.3 released!
This update will require mafia users to update to build 7114 or later as it uses features that don't exist in earlier versions.

Changelog:
Version 2.3 - March 31, 2009
  • Some routines rewritten for greater efficiency under KolMafia revision 7098
  • CLI output reduced. It runs much cleaner now.
  • Use of birdform restoration is now user configurable.
  • Will check user's preference for "Buy items from the mall whenever needed" and stay in hardcore mode if the preference is unchecked.
  • Fixed unseemly preference for palm fronds when healing relatively few MP/HP in mall mode.
  • Configurable variables moved to the top of the script.
  • A few miscellaneous improvements to restoration logic.

I'm still running into issues where the script is buying more expensive restoratives than it needs for some reason. There are plenty of ancient Magi-Wipes in the mall at 170, the palm-frond fan at 200 for less restoration was glaringly odd here.
I finally found the problem!! It was a quirky round off issue that only caused trouble in certain circumstances. In short: to figure out how many fronds would be required, I double the number of fans it would take. That makes sense, but for example, ceil(.4 *2) is 1. Oops! Naturally that gave an unsightly preference to using fans in certain circumstances. It's fixed in this version.

At the vary least, make the threshold easily configurable inside the script.
I hate doing that, but there seems to be a lot of personal preference involved so no one-size-fits-all answer is possible... Sigh... Done. It is now easily configurable. Now I have a variable at the beginning of the script called bird_threshold. If you set it to 0.00 it will always use birdform items regardless of how much might be wasted. If you set it for .30 it will only use them if at least 30% of the items healing will be useful. And if you set it for 1.00, then it won't use any birdform items unless you are guaranteed to use 100% of their restoration. I've set it at 10% as default, although there is only a little difference between that and 0%. I didn't bother to make separate thresholds between moths and grubs because I want to keep it simple and this seems like enough.

EDIT: Oops, I guess you can turn the oils off with the Kolmafia HP/MP menu. Silly me.
EDIT EDIT: However, I guess the HP/MP thing doesn't acually work. I don't have the massage oils box checked, but it used them anyway.
I suggest that you uncheck the box and then check it again since I'm convinced that this should absolutely have worked. Anyway, I've rewritten part of that section of the code to take advantage of a new mafia feature so it would work slightly differently now. Please try it.
 
Last edited:
Hott updates Bale! Very attentive to user feedback. I know I will enjoy the cleaner CLI, and I particularly like the script paying attention to the "buy from the mall" setting.
 
I finally found the problem!! It was a quirky round off issue that only caused trouble in certain circumstances. In short: to figure out how many fronds would be required, I double the number of fans it would take. That makes sense, but for example, ceil(.4 *2) is 1. Oops! Naturally that gave an unsightly preference to using fans in certain circumstances. It's fixed in this version.

That is a subtle bug. I'm not surprised that it got overlooked. Thanks for finally catching it. Thanks again for all your hard work on this.
 
I was glad to respond to everyone's feedback. I think you've all helped me make this as good as it is. Now I've got another issue that I'm not sure how to best deal with, so I'm throwing it open to discussion.

(In hardcore/ronin) I've noticed that when HP target is set to 100%, refusing to over-use a healing item will cause the script to use as many healing items as possible, but leaving a bit of healing left over that is then healed with skills (if they exist) or else healed with Doc. This isn't a really big issue at lower levels, but later on when the main source of healing is gauze garters/filthy poutices, it will refuse to use them for less than 120 HP. That's huge! It is rather troublesome to have lots of gg/fp, see it use a few and then use a Cannelloni Cocoon to heal the last 90 points. If it was gonna use a Cocoon, then why waste gg/fp in the first place?

Obviously I can work around this by reducing HP restoration to 80% when I'm in such a situation. However I consider this a bug and want to fix it. The simplest way would be to allow over-restoring when HP target == max HP. Thoughts? Comments?
 
Just been getting 'Undefined reference to function 'switch' (Universal_recovery.ash, line 208)
Undefined reference to function 'switch' (Universal_recovery.ash, line 208)

Undefined reference to function 'switch' (Universal_recovery.ash, line 208)
'
 
Back
Top