ZLib -- Zarqon's useful function library

Thanks Bale! Tightened it up a bit, and added it locally. Only thing missing is a server-hit-less method of checking to see if Beelzebozo has already been defeated. Will be in the next release.

PHP:
int get_safemox(location wear) {
   int high = 0;
   foreach i,m in get_monsters(wear)
      switch(m) {
         case $monster[dr. awkward]:
         case $monster[ancient protector spirit]:
         case $monster[ol scratch]:
         case $monster[frosty]:
         case $monster[oscus]:
         case $monster[zombo]:
         case $monster[chester]:
         case $monster[hodgman, the hoboverlord]: continue;
         case $monster[clownlord beelzebozo]: if (get_property("choiceAdventure151") != "1") continue;
         case $monster[conjoined zmombie]: if (get_property("choiceAdventure154") != "1") continue;
         case $monster[giant skeelton]: if (get_property("choiceAdventure156") != "1") continue;
         case $monster[gargantulihc]: if (get_property("choiceAdventure158") != "1") continue;
         case $monster[huge ghuol]: if (get_property("choiceAdventure160") != "1") continue;
         default: high = max(monster_attack(m),high);
      }
   if (high == 0 || high == monster_level_adjustment()) return 0;
   return high + 7 - current_mcd();
}

Also it's a relief to not feel so bloated anymore. Phew. Can you imagine if I had to deal with that every month?
 
I can tell it's been tough on you. Glad you're finally off your period. :rolleyes:

Nice bit with the code. Yeah, "continue". That does make it much tighter.
 
Oops. That won't work, since execution will fall through to unrelated choiceadv checks. Meh.

EDIT: Guess this will have to do:

PHP:
int get_safemox(location wear) {
   int high;
   foreach i,m in get_monsters(wear)
      switch(m) {
         case $monster[dr. awkward]:
         case $monster[ancient protector spirit]:
         case $monster[ol scratch]:
         case $monster[frosty]:
         case $monster[oscus]:
         case $monster[zombo]:
         case $monster[chester]:
         case $monster[hodgman, the hoboverlord]: continue;
         case $monster[clownlord beelzebozo]: if (get_property("choiceAdventure151") != "1") continue;
            high = max(monster_attack(m),high); break;
         case $monster[conjoined zmombie]: if (get_property("choiceAdventure154") != "1") continue;
            high = max(monster_attack(m),high); break;
         case $monster[giant skeelton]: if (get_property("choiceAdventure156") != "1") continue;
            high = max(monster_attack(m),high); break;
         case $monster[gargantulihc]: if (get_property("choiceAdventure158") != "1") continue;
            high = max(monster_attack(m),high); break;
         case $monster[huge ghuol]: if (get_property("choiceAdventure160") != "1") continue;
         default: high = max(monster_attack(m),high);
      }
   if (high == 0 || high == monster_level_adjustment()) return 0;
   return high + 7 - current_mcd();
}
 
Last edited:
PHP:
if (high == 0 || high == monster_level_adjustment()) return 0;
Is the first condition necessary (the "high==0" part)?
 
If this function returns 0, it means a) the location has no monsters (the first condition), or b) the location has monsters with unknown ML (the second condition). Both are necessary.
 
this said i had version 17 needing to update to version 5 every time zlib is called.. worked when i changed the .ash version to 5 ..
 
First post of this thread said:
Note: if you upgrade and get a strange message about upgrading to a lower version number, type "set _version_zlib =" in the CLI and the problem will go away forever.
 
Aha.

PHP:
int get_safemox(location wear) {
   int high;
   foreach i,m in get_monsters(wear) {
      switch(m) {
         case $monster[dr. awkward]:
         case $monster[ancient protector spirit]:
         case $monster[ol scratch]:
         case $monster[frosty]:
         case $monster[oscus]:
         case $monster[zombo]:
         case $monster[chester]:
         case $monster[hodgman, the hoboverlord]: continue;
         case $monster[clownlord beelzebozo]: if (get_property("choiceAdventure151") != "1") continue; break;
         case $monster[conjoined zmombie]: if (get_property("choiceAdventure154") != "1") continue; break;
         case $monster[giant skeelton]: if (get_property("choiceAdventure156") != "1") continue; break;
         case $monster[gargantulihc]: if (get_property("choiceAdventure158") != "1") continue; break;
         case $monster[huge ghuol]: if (get_property("choiceAdventure160") != "1") continue;
      }
      high = max(monster_attack(m),high);
   }
   if (high == 0 || high == monster_level_adjustment()) return 0;
   return high + 7 - current_mcd();
}

That's acceptable.
 
Could we have a check_version for Relay scripts? It could return a string that could be printed at the top of the page with a link directly to the thread, in addition to (or instead of) printing output in the gCLI.
 
Huh. Looks to me like it should work (Tested with the following function, modified slightly from check_version):
PHP:
void relay_version(buffer page, string soft, string prop, string thisver, int thread) {
   switch (get_property("_version_"+prop)) {
      case thisver: return;
      case "": vprint("Checking for updates (running "+soft+" ver. "+thisver+")...",1);
         matcher find_ver = create_matcher("<b>"+soft+" (.+?)</b>",visit_url("http://kolmafia.us/showthread.php?t="+thread));
         if (!find_ver.find()) { vprint("Unable to load current version info.",-1); return; }
         set_property("_version_"+prop,find_ver.group(1));
         if (find_ver.group(1) == thisver) { vprint("You have a current version of "+soft+".",1); return; }
      default:
         vprint_html("<big><font color=red><b>New Version of "+soft+" Available: "+get_property("_version_"+prop)+"</b></font></big>",1);
         page.insert(0,"<big><font color=red><b>New Version of "+soft+" Available: "+get_property("_version_"+prop)+"</b></font></big><br />Upgrade "+soft+" from "+thisver+" to "+get_property("_version_"+prop)+" here: http://kolmafia.us/showthread.php?t="+thread+"<br /><br />");
         vprint("Upgrade "+soft+" from "+thisver+" to "+get_property("_version_"+prop)+" here: http://kolmafia.us/showthread.php?t="+thread,"blue",1);
   }
}

Called, of course, after appending the page to the buffer.
PHP:
import <zlib.ash>

void main() {
	buffer results;
	results.append(visit_url());
	relay_version(results, "scriptname", "varname", "1.0", 2072);
	//stuff
}
 
The sample relay script does, in fact, import ZLib and call several ZLib functions (I actually tested that this works, for once!), so importing ZLib and calling functions from it shouldn't be a problem, right? (For what it's worth, I spliced that function into ZLib at some point during testing, and the test script worked just fine.)

(Sorry, I'm totally lost. Not totally understanding why version-checking for relay scripts and ZLib wouldn't play nicely.)
 
Last edited:
Eh??? I had been under the impression that you couldn't have top-level code in relay override scripts. Has this changed?
 
Heeheehee: you should add an actual link to the thread, and we're golden.
Zarqon: yup, I import htmlform.ash and use top level script.
 
It's not an actual thread, per se, but a little sample that's provided a few posts up detailing how to use it. Basically, it's exactly the same as check_version() except with an additional parameter. Now that I think about it, you don't really have to wait until appending visit_url(); you just have to declare the buffer. Oh well, should still work the same. [If you want to test it for yourself, you could pretty much copy the check_version() from some other script and fix it up to work with this function...]
 
Back
Top