ZLib -- Zarqon's useful function library

kain

Member
So I've been having strange and intermittent problems (I usually only notice it on the L11 quest, since most of the rest of the scripts I use are home-grown and don't use zilb) with the obtain() function.

It seems to me that occasionally obtain() fails to recognize when it successfully pulls an item from storage.

I have modified my obtain() function with a whole mess of print statements thusly:
Code:
// gets n (-existing) of cond, either by purchasing, pulling from Hangk's, or
// adventuring at the given location.  also works with choiceadvs
boolean obtain(int n, string cond, location locale) {
vprint("Function obtain() ... Int: " + n + " condition: " + cond + " Locale: " + locale, "green", 2);
   if (cond == "choiceadv") cli_execute("conditions clear; conditions add "+n+" choiceadv");
   else {
      if (retrieve_item(n, to_item(cond))) return vprint("You have " +n+ " " +cond+ ", no adventuring necessary.", "green", 2);
      if (!in_hardcore() && storage_amount(to_item(cond)) > 0 && take_storage(n-have_item(cond),to_item(cond)))
         return vprint("You have taken your needed items from storage.", "green", 2);
      cli_execute("conditions clear");
      add_item_condition(n - have_item(cond), to_item(cond));
   }
   set_location(locale);
   vprint("Adventuring in " + locale + " now, in search of " + (n - have_item(cond)) + " " + cond, "green", 2);
   if (adventure(my_adventures(), locale)) return vprint("Out of adventures.",-1);
   if (cond == "choiceadv") return (my_adventures() > 0);
   return (have_item(cond) >= n);
}
Observe the 'Stone Rose/Drum Machine' portion of the Macguffin quest:
Code:
Request 3 of 148 (Beach: Desert (Ultrahydrated)) in progress...

[558] Desert (Ultrahydrated)
Encounter: A Sietch in Time

A Sietch in Time

Now finding a stone rose.
Function obtain() ... Int: 1 condition: stone rose Locale: Oasis in the Desert
You need 1 more stone rose to continue.
Conditions list cleared.
Condition added: stone rose
stone rose
Adventuring in Oasis in the Desert now, in search of 1 stone rose

Request 1 of 144 (Beach: Oasis in the Desert) in progress...

[559] Oasis in the Desert
Encounter: All Across the Sands
You acquire an item: stone rose

Conditions satisfied after 1 adventures.
Now fetching a drum machine.
Function obtain() ... Int: 1 condition: drum machine Locale: Oasis in the Desert
You need 1 more drum machine to continue.
Pulling items from storage...
14 pulls remaining,0 budgeted for automatic use.
Conditions list cleared.
Adventuring in Oasis in the Desert now, in search of 0 drum machine

Request 1 of 143 (Beach: Oasis in the Desert) in progress...

[560] Oasis in the Desert
Encounter: oasis monster
Strategy: kain.ccs [default]
>>combat<<
You gain 15 Beefiness
You gain 25 Wizardliness
You gain a Mysticality point!
You gain 11 Sarcasm
You're on your own, partner.

Perhaps it is a problem with mafia's pull code itself?
 
Last edited:

slyz

Developer
Could it be possible to be able to append something to a zlib variable, rather than reset it ? LIke this:

Code:
void main(string setval) {
   if (setval == "vars") { foreach key,val in vars vprint("zlib "+key+" = "+val,1); return; }
   if (!setval.contains_text(" = ") && !setval.contains_text(" += ") )
       vprint("Proper syntax is settingname = value, or settingname += value",0);
   
   boolean append = setval.contains_text(" += ");
   if ( append ) string n = substring(setval,0,index_of(setval," += "));
   else string n = substring(setval,0,index_of(setval," = "));
   
   if (!(vars contains n)) { vprint("No setting named '"+n+"' exists.","olive",-2); return; }
   
   if ( append ) v = vars[n]+substring(setval,index_of(setval," += ")+4);
   else string v = substring(setval,index_of(setval," = ")+3);
   
   print("Previous value of "+n+": "+vars[n]);
   if (vars[n] == v) return;
   if (n == "threshold" && !append) {
	  if (v == "up") v = to_string(to_int(vars["threshold"])+1);
	  if (v == "down") v = to_string(to_int(vars["threshold"])-1);
   }
   vars[n] = v;
   updatevars("action=entry&varname="+url_encode(n)+"&value="+url_encode(v));
   print("Changed to "+vars[n]+".");
}

This would mean the USER would had to be carefull, doing things like zlib ftf_olfact += , C. H. U. M. . Would it be worth it ?
 

kain

Member
It's definitely happening when items get pulled from hagnks to fulfill obtain()

Code:
[616] Knob Goblin Laboratory
Encounter: Mr. Alarm

Mr. Alarm

Mr. Alarm discovered.
Pulling items from storage...
13 pulls remaining,0 budgeted for automatic use.
Function obtain() ... Int: 1 condition: stunt nuts Locale: Palindome
You need 1 more stunt nuts to continue.
Pulling items from storage...
12 pulls remaining,0 budgeted for automatic use.
Conditions list cleared.
Adventuring in Palindome now, in search of 0 stunt nuts

Request 1 of 86 (Plains: Palindome) in progress...

[617] Palindome
Encounter: Taco Cat

But it multi-pulls the wine just fine ...
Code:
wine #1 : dusty bottle of Zinfandel
Function obtain() ... Int: 1 condition: dusty bottle of Zinfandel Locale: Haunted Wine Cellar (automatic)
You need 1 more dusty bottle of Zinfandel to continue.
Pulling items from storage...
11 pulls remaining,0 budgeted for automatic use.
You have taken your needed items from storage.
wine #2 : dusty bottle of Pinot Noir
Function obtain() ... Int: 1 condition: dusty bottle of Pinot Noir Locale: Haunted Wine Cellar (automatic)
You need 1 more dusty bottle of Pinot Noir to continue.
Pulling items from storage...
10 pulls remaining,0 budgeted for automatic use.
You have taken your needed items from storage.
wine #3 : dusty bottle of Merlot
Function obtain() ... Int: 1 condition: dusty bottle of Merlot Locale: Haunted Wine Cellar (automatic)
You need 1 more dusty bottle of Merlot to continue.
Pulling items from storage...
9 pulls remaining,0 budgeted for automatic use.
You have taken your needed items from storage.
 
Last edited:

zarqon

Well-known member
@kain: Sounds like it might be a problem with the return value of take_storage(). I'm at work and don't have the code in front of me -- does the wines part use the return value of take_storage() or use an item_amount() after the fact?

@slyz: I'd recommend an alias. Something like this ought to do you nicely:

alias olfact => ashq import <zlib.ash> if ("%%" == "") abort("Currently olfacting: "+vars["ftf_olfact"]); string m = to_lower_case(to_string(to_monster("%%"))); if (m == "none") abort("%% is not a monster."); if (contains_text(vars["ftf_olfact"],m)) abort("Already olfacting "+m); vars["ftf_olfact"] = vars["ftf_olfact"]+", "+m; updatevars("action=entry&varname=ftf_olfact&value="+url_encode(vars["ftf_olfact"]));
 

Bale

Minion
alias olfact => ashq import <zlib.ash> if ("%%" == "") abort("Currently olfacting: "+vars["ftf_olfact"]); string m = to_lower_case(to_string(to_monster("%%"))); if (m == "none") abort("%% is not a monster."); if (contains_text(vars["ftf_olfact"],m)) abort("Already olfacting "+m); vars["ftf_olfact"] = vars["ftf_olfact"]+", "+m; updatevars("action=entry&varname=ftf_olfact&value="+url_encode(vars["ftf_olfact"]));

Y'know... That would be the answer dj_d was looking for to add olfaction support to his make.meat.fast script. Except for aborts of course. SmartStasis is a very powerful tool.
 

slyz

Developer
Nice, thanks!

EDIT: CLI already has an olfact command, better name the alias zolfact or something
 
Last edited:

kain

Member
I wondered if wines were being pulled in a different manner, too. They are, in fact, being pulled via obtain()

Code:
      for i from 1 to 3 {
         wines[i] = get_this_wine(to_int(substring(blar[i],0,1)));
         vprint("wine #" +i+ " : " + wines[i],3);
         obtain(1,wines[i],$location[haunted wine cellar (automatic)]);
      }

stunt nuts uses the same call ...
Code:
         obtain(1,"stunt nuts",$location[palindome]);

I dunno, I might tweak the obtain() function to do some additional checking ...
 

zarqon

Well-known member
It really seems as though take_storage() is the culprit here.

In the meantime, this is easily worked around by adding a have_item() check after the storage bit -- I've thrown that in to the first post but not bumped the version number. I had to do similar things in my AutoClub script due to functions like hermit() not having predictable return values. One of these days I'll get around to testing the unreliable functions and writing up those bug reports, but since it can be worked around, and it seems like everyone still has plenty on their plates, I'll hold off on that for the nonce. :)
 
I'm trying to change the settings in OCW, but whenever I try to use "zlib ocw_m_*anything* = *mood*" it gives me "No setting named 'ocw_m_*anything*' exists."
Can I fix that somehow?
 

tgetgel

Member
I'm trying to change the settings in OCW, but whenever I try to use "zlib ocw_m_*anything* = *mood*" it gives me "No setting named 'ocw_m_*anything*' exists."
Can I fix that somehow?

Exit mafia. Go to the data folder under mafia. find the file var_<name>.txt and search for ocw. Manually change the line, save the file, and restart mafia.

I have not run OCW of late, so I have no ocw_m settings in my data file. I imagine that I will once I get to that point again. You check under the OCW thread for more info on ocw_m.
 
Last edited:

zarqon

Well-known member
Yeah, I noticed a while ago that apparently when you assign an empty string to a key in a string[string] map, then write the map to file using map_to_file(), then read the map using file_to_map(), keys that point to empty strings are not included. I hadn't tested it to confirm, but I just did:

> ashq string[string] foo; foo["hey"] = "there"; foo["yomama"] = ""; foreach key,val in foo print(key+": "+val);

hey: there
yomama:

> ashq string[string] foo; foo["hey"] = "there"; foo["yomama"] = ""; map_to_file(foo,"mapthingy.txt"); file_to_map("mapthingy.txt",foo); foreach key,val in foo print(key+": "+val);

hey: there

mapthingy.txt contents:

Code:
hey	there
yomama

I would consider this a bug with file_to_map(). I'll go report it. If it gets fixed, then all the mood settings (empty by default) will properly exist in your ZLib vars.
 

slyz

Developer
You have to run OCW at least once for the settings to appear, I guess (maybe the ones with "" as default aren't added). And no need to close mafia to change the vars_<yourname>.txt file, that's only for the Mafia preference file.

Type zlib vars to see what the file contains, and you could type ashq import <zlib.ash> setvar("ocw_m_nuns", "meatfarming"); in the gCLI to create it.
 
Last edited:
Well, I tried ashq <import zlib> setvar("ocw_m_nuns", "meatfarming"); and I got Script parsing error ().
Any suggestions?
I am using the newest version of zlib.
 

jasonharper

Developer
ashq string[string] foo; foo["hey"] = "there"; foo["yomama"] = ""; foreach key,val in foo print(key+": "+val);
For future reference, that's not the best use of ashq, given that ash will happily print the contents of a map for you - just write its name as the final statement of the script:

ash string[string] foo; foo["hey"] = "there"; foo["yomama"] = ""; foo;
 

zarqon

Well-known member
Jason has now fixed this issue, so users having troubles configuring moods for OCW can run OCW again (you can stop it after it starts, before it does anything), to get all the keys correctly in your vars file. Thanks Jason!
 

Bale

Minion
I'd like to make a suggestion to reduce server hits. Every time I go to the sewer or the beach auto_mcd() notes "Using your 'unknown_ml' value (150)" and changes my MCD to 0. Then when I go back to my previous zone it switches the MCD back again. That's quite a few unnecessary server hits each run. It'd be fairly easy to fix the problem:

Code:
   if (!to_boolean(vars["automcd"]) || my_location() == $location[boss bat's lair] ||
       my_location() == $location[king's chamber] || my_location() == $location[haert of the cyrpt] ||
       my_location() == $location[slime tube][COLOR="Red"] || count(get_monsters(my_location())) == 0[/COLOR]) return true;

or perhaps...

Code:
   if (safemox == 0) {
      [COLOR="Red"]if (count(get_monsters(my_location())) == 0) return true;[/COLOR]
      vprint("MCD: Using your 'unknown_ml' value ("+vars["unknown_ml"]+").","olive",2);
      safemox = to_int(vars["unknown_ml"] + 7);
   }
I think that the big difference between the two solutions is that the first one will prevent a detuned radio from being bought if your first turn is spent sewering, but it seems tidier to me.
 
Last edited:

zarqon

Well-known member
Like it. According to mafia's current knowledge, that means that all of these locations would skip adjusting the MCD:

0 => Pump Up Muscle
1 => Pump Up Mysticality
2 => Pump Up Moxie
3 => Richard's Hobo Mysticality
4 => Richard's Hobo Moxie
5 => Richard's Hobo Muscle
6 => Muscle Vacation
7 => Mysticality Vacation
8 => Moxie Vacation
9 => Desert (Unhydrated)
10 => The Lower Chambers
11 => Goat Party
12 => Pirate Party
13 => Lemon Party
14 => Roulette Tables
15 => Poker Room
16 => Limerick Dungeon
17 => Greater-Than Sign
18 => Unlucky Sewer
19 => Sewer With Clovers
20 => Hidden Temple
21 => Fernswarthy's Basement
22 => Friar Ceremony Location
23 => Frat House In Disguise
24 => Hippy Camp In Disguise
25 => Noob Cave
26 => Mt. Molehill
27 => Mine Foremens' Office
28 => Dwarven Factory Warehouse
29 => The Brooding Grounds
30 => The Outer Compound
31 => The Temple Portico
32 => The Barracks
33 => The Nemesis' Lair
34 => Post-Quest Bugbear Pens
35 => Heartbreaker's Hotel
36 => Trick-or-Treating
37 => Drunken Stupor
38 => St. Sneaky Pete's Day Stupor
39 => Yuletide Bonfire
40 => Arrrboretum
41 => Spectral Salad Factory
42 => Generic Summer Holiday Swimming!
43 => Sinister Dodecahedron
44 => Future Market Square
45 => Mall of the Future
46 => Future Wrong Side of the Tracks
47 => Icy Peak of the Past

Once the Nemesis zones are fully added, I think this will be a significant improvement to ZLib's auto-MCD functionality. Thanks for the idea Bale.
 
Top