CanAdv -- check whether you can adventure at a given location

zarqon

Well-known member
[size=+1]The CanAdv Project[/size]

What is it?
CanAdv is designed as a tool for scripters, meant to be imported into their scripts. After importing, you simply call can_adv(location, prep), and the function will return true or false depending on whether or not you are able to adventure in a given location.

"Wait, what's prep?"

The second parameter is a boolean that decides whether or not to actually prepare you for going into the zone. If you call can_adv(location, true) it will equip necessary items, etc. If you call can_adv(location, false) it will only check to see that you have the necessary items, and so forth. Generally, unless you plan on actually adventuring in the given location you should use false.

How to use it:
  • Install it by pasting this into your CLI:
    Code:
    svn checkout https://svn.code.sf.net/p/therazekolmafia/canadv/code/
  • When writing a script, type "import <canadv.ash>" at the top of the script (without quotes). Also, ZLib will be imported along with CanAdv so you don't need to explicitly import it again.
  • Enjoy using boolean can_adv( location where, boolean prep ) as an ASH function.

NOTE: Special thanks to Theraze for helpfully assuming de facto responsibility for this script while I was almost entirely focused on my combat scripts.

Changelog
6.4.09 - alpha 0.1 posted. Let the collaboration begin!
6.7.09 - 0.2 changes: included resist() function, added "prep" parameter to canadv(), added four missing visit_url() calls, relocated El Vibrato, check for adventures and drunkenness.
6.17.09 - 0.3 changes: move resist() out -- script requires ZLib. Fixes for bat zones. Added equipped item and outfit checking minifuncs and integrated them. Detect St. Sneaky Pete's Day.
9.01.09 - 0.4 changes: a crapton!
9.04.09 - 0.5 changes: added Post-War Sonofa Beach.
11.17.09 - 0.6 changes: added ALL missing zones and step one of Sea zone detection. Fixed detection of completed Boss Bat's Lair.
12.30.09 - 0.62 changes: added Crimbo '09 zones as unadventurable. Use ZLib's new vprint().
10.25.10 - 0.7 changes: fixes to Boss Bat and Hippy/Frat camps (thanks psly4mne and FN Ninja!). Removed sewer, replaced old tavern with new. Added all currently missing zones -- mainly nemesis zones and Uncle P's maps.
1.28.11 - 0.71: Friar's Gate is no longer a zone. Added new Friar zones and other tweaks by Theraze.
2.16.11 - 0.72: New names for Knob zones. Limerick Dungeon checks mainstat.
2.16.11 - 0.73: Ugh. Correct URL for new Knob. Bumped nearly all verbosity settings up from 4 to 6.


Further changes are recorded below -- and on the script's SourceForge changelog.
 
Last edited:
Currently Maintaining CanAdv

[size=+1]The CanAdv Project 0.90[/size]

Please download the latest CanAdv from this post.

Changelog
02.13.12 - 0.74: Added version checking. Also added checking for familiars and underwater adventuring.
02.19.12 - 0.75: Added class checking for guild unlocking.
02.27.12 - 0.76: Added quest tracking awareness for locked-guild characters. Added variable to keep the guild locked.
02.29.12 - 0.77: Cleaned up locked-guild to never adventure if you've told it to stop. Moved two holiday zones to former event section.
03.01.12 - 0.78: Changed default to not unlocking guild. Added location-only no-prep overloaded can_adv function.
05.16.12 - 0.79: Added initial Bugbear Invasion zones, marked as not available if you aren't in a bugrun. Pete's Stupor takes 26 drunk.
05.24.12 - 0.80: Added additional Bugbear Invasion zones, still marked as not available if you aren't in a bugrun.
06.08.12 - 0.81: Now using biodata properties to know if a Bugbear Invasion zone is unlocked.
07.16.12 - 0.82: Adds closed fire event locations, holiday detection for 4, always checking when prepping, and quest properties for Bat Hole.
08.07.12 - 0.83: Trapper, not Tr4pz0r, for the Icy Peak.
09.02.12 - 0.84: McLargeHuge gif names had changed in revamp.
10.20.12 - 0.85: Random mining and underwater zones which I've had since 9/5 have finally been noticed as missing by other people.
11.26.12 - 0.86: Added in the new Level 9 locations.
12.02.12 - 0.87: Fixed the Orc Chasm check to work, since it was broken, and now without needing a server hit.
12.03.12 - 0.88: Added the skeletal skiff as an alternative to the dingy dinghy.
02.02.13 - 0.89: Hopefully added the new zones for the jars.
02.21.13 - 0.90: Giant's Castle is now 3 zones. Basic/wrong check for if they're unlocked, but it makes the script run.
 

Attachments

Last edited:
Neat! What are your thoughts on adding a try_adv, which would go one step further and actually adventure once, then report the success or failure of that? That's the approach levelup.ash uses (just tries to adventure everywhere, checking to see if an adventure is used). That would allow a second level of verification before you commit to burning a bunch of turns.
 
@mredge: Nope, that's a non-snarfblat area that needs to be added.

@dj_d: you'll notice that currently the script only detects whether you are capable of entering an area -- for example, if you have a necessary outfit, it returns true but doesn't equip the outfit. For maximum flexibility, I would like this script to avoid using items as much as possible. Adventuring is fully outside the scope of the script -- the whole point is to figure out if you can adventure somewhere before you actually do.

That said, there is room for a second function prep_adv() which would equip necessary gear or use necessary items, so that if (prep_adv(place)) adventure(place) would always work. As usual, I'll go with what the community decides.
 
@Zarqon: Depends on if you see this as a set of utilities for "enabling adventurement" (evaluate, prep, try) or just the first of those three stages. I personally see value in all 3 stages but appreciate that you've done anything at all. :)
 
@edge: Not quite... the summoning chamber would have its own set of checks. The easiest way would probably be a level check, followed by a few item checks (i.e. the diary), followed by a visit_url() check which looks for the image.

@dj_d: Correct me if I'm wrong, but try_adv() would be nothing more than this:

Code:
try_adv(location where) {
   return adventure(1,where);
}

Since adventure returns true if you spend the number of adventures specified, that ought to work. Doesn't seem like it's worth importing a separate script for that.
 
Firstly, excellent idea, and I am as always in awe of your coding style!

zarqon said:
Any other improvements you can think of.

zarqon said:
CanAdv is designed as a tool for scripters, meant to be imported into their scripts. After importing, you simply call can_adv(location), and the function will return true or false depending on whether or not you are able to adventure in a given location.

Perhaps i'm thinking about the usage of this all wrong, but if I am reading the above statement right, should it also check if you are drunk, have enough adventures to adventure somewhere and arn't currently beaten up ?

also before I go attempting to help to much, an example of the kind of question I will be asking!

Code:
   case $location[Guano Junction]: return (levelcheck(4));

this also requires some kind of stench resistance, so what should the suggested fix be?

check for stench resistance (as well as level):
Code:
case $location[Guano Junction]: return ((levelcheck(4)==true) && (elemental_resistance($element[stench])>0));

which would assume you need to be wearing the correct outfit before checking you can get there,

or should it check for the most likely item which would give you the required resistance?
Code:
case $location[Guano Junction]: return ((levelcheck(4)==true) && (item_check($item[Pine-Fresh air freshener]==true)));
 
Last edited:
on another point (possibly i'm not using it right) because not all cases return something I get some interesting answers!

> call canadv el vibrato island

Cannot yet detect Hobopolis zones. Assuming true...
El Vibrato Island is available to your character.

having looked a little closer the zones are groups so it will return something for that zone in the last case element of each zone, dare I suggest that you just perhaps missed the el vibrato island!
 
ok i'm going to stop posting after this one!

lines 123, 145, 146, 155 look like they are missing the visit_url function

Code:
123: case $location[Bugbear Pens]: return (in_muscle_sign() && primecheck(13) && contains_text("woods.php","pen.gif"));
145: case $location[Dark Elbow of the Woods]: return (levelcheck(6) && !have_skill($skill[spleen of steel]) && !contains_text("quests.php?which=2","cleansed the taint"));
146: case $location[Friar's Gate]: return (primecheck(29) && (have_skill($skill[spleen of steel]) || contains_text("quests.php?which=2","cleansed the taint")));
155: case $location[Icy Peak]: return (levelcheck(8) && contains_text("quests.php?which=2","L337 Tr4pz0r"));


suggestion!

The Slime tube: check for the bucket? (unfortunatly requires server hit)
Code:
case $location[The Slime Tube]: return (visit_url("clan_slimetube.php").contains_text("thebucket.gif"));
 
Last edited:
@matt: Lots of excellent ideas!

Perhaps i'm thinking about the usage of this all wrong, but if I am reading the above statement right, should it also check if you are drunk, have enough adventures to adventure somewhere and arn't currently beaten up ?

Duh! I was so caught up on zone availability that I missed some of the basics. So, I've added in a check for adventures. I also moved the checks for Drunken Stupor and St. Pete's Day up to the top, before doing a drunkenness check. I did not, however, add a check for Beaten Up, because there are many places you can still adventure even if Beaten Up. Although I did add in a check for 0 HP.

dare I suggest that you just perhaps missed the el vibrato island!

Yep, missed that. I've moved it up into the bloc with the other miscellaneous zones.

this also requires some kind of stench resistance, so what should the suggested fix be?

Okay -- two ideas incorporated at once here. I've added in the resist() function from the DDD, as well as added a boolean "prep" parameter to can_adv(). The prep parameter specifies whether or not can_adv() will actually prepare you to adventure in the zone. Leaving it false means that it will just check to see if you could possibly adventure somewhere (previous behavior). Since resist() has the same sort of parameter, you can simply check resist(prep) to either check for resistability or actually acquire resistance, depending on the parameter passed to can_adv().

This means that additional functionality will have to be written into many of the zones that would require gear changing or item use.

lines 123, 145, 146, 155 look like they are missing the visit_url function
The Slime tube: check for the bucket?

Those fixes have been added in. Thanks for all the great feedback!
 
nicely done Zarqon!

Is it possible to overload functions in ash? If so then you could use

Code:
boolean equipped_amount(item i, bool equipit) {
	if(equipit==true) {
		// equip relevant item here!
	}
	return equipped_amount(i);
}

if not then I suppose just giving the function another name, and using as a wrapper would work fine.

this can be used exactly the same as resist():

Code:
case $location[Palindome]: return (equipped_amount($item[talisman o'nam],prep) > 0);
 
Hobopolis: (note to self really)

Tunnels, check for "adventure.php?snarfblat=166" in clan_hobopolis.php and ! whatever the link is thats added when you finish tunnels to goto town square

zones, check for each zone image and that the boss hasn't been already killed in dungeon logs (GAH 2 server hits!)
 
Bats again!

Entryway doesn't require stench resistance, so should return it's own value to prevent it using the value returned for the junction!

The Boss Batt's Lair is only available if you havn't killed him!

Also, (and this isn't added yet) each of the 3 require the usage of a sonar biscuit to open up, i've already completed the quest this run, but i'm hoping the quest log will show how many are used, and therefore exactly which ones are available, unfortunatly this means for the Boss Bat Lair it would have to use one server hit to check if its open using sonar, then another to check its not been defeated



lines 119 to 123 (I think, I may have modified it so they arn't accurate!)
Code:
   case $location[Bat Hole Entryway]: return (levelcheck(4));
   case $location[Guano Junction]: return (levelcheck(4) && resist($element[stench],prep));
   case $location[Batrat and Ratbat Burrow]: print("Not sure if you've got the sonar biscuity goodness yet. Just using level check","olive"); return(levelcheck(4));
   case $location[Beanbat Chamber]: print("Not sure if you've got the sonar biscuity goodness yet. Just using level check","olive"); return(levelcheck(4));
   case $location[Boss Bat's Lair]: print("Not sure if you've got the sonar biscuity goodness yet. Just using level check","olive"); return (levelcheck(4) && !visit_url("questlog.php?which=2").contains_text("slain the Boss Bat"));
 
Last edited:
another thought to potentionally reduce server hits, how about using more logic to only use server hits when really needed?

such as:
Code:
case $location[Defiled Nook]: if(levelcheck(7)){(return visit_url("cyrpt.php").contains_text("cyrpt7d.gif");} else {return false;}

which would only check for the crypt image if you were actually of a high enough level.... (which I didn't need to type since your perfectly capable of understanding even my code!)

in fact I'm not sure, but I think that can be refactored a little

Code:
case $location[Defiled Nook]: if(levelcheck(7)){return visit_url("cyrpt.php").contains_text("cyrpt7d.gif");} return false;

sorry for the several posts! must look like i'm talking to myself! i'll wait for your responses before I post any more!
 
Last edited:
Matt! More great thoughts.

1) I love the equipcheck() idea. Added that in, along with outfitcheck(). These will only swap gear if prep is true.

2) For boss zones, often the link to the boss area changes depending on whether the boss is defeated, so detecting whether the area is open and the boss remains undefeated should usually be doable in a single server hit.

3) Bat zones definitely need special handling for the use of sonars. I think the script ought to attempt to use enough sonars to reveal the desired zone, regardless of prep. If done right, the detection for that could be done in a single server hit. The question now becomes how to script that efficiently. For now, I added this after all three sonar-only bat zones, which I think is fairly nice:

Code:
if (!levelcheck(4)) return false;
string bathole = visit_url("bathole.php");
int sonarsneeded = to_int(!contains_text(bathole,"batratroom.gif")) +
to_int(!contains_text(bathole,"batbeanroom.gif")) + to_int(!contains_text(bathole,"batbossroom.gif"));
if (sonarsneeded > 0) {
   use_upto(sonarsneeded,$item[sonar-in-a-biscuit],true);
   bathole = visit_url("bathole.php");
}
return (contains_text(bathole,substring(to_url(where),0,index_of(to_url(where),"&"))));

Note that this will detect whether the Boss Bat has been defeated.

Also note that this uses a function from ZLib. Since this script also needed to use resist(), I simply made it require ZLib. Scripts that want to use both ZLib and CanAdv can now just import CanAdv.

4) That's a good thought, but the existing operators already work that way.

Consider this:

Code:
if (false && true) do something;

ASH, like many languages, handles these comparisons smartly. As soon as it sees the first false, it doesn't even evaluate the second condition, since the final result will be false no matter what the second condition evaluates to.

Likewise,

Code:
if (true || false) do something;

does not evaluate the second condition.

So,

Code:
return (levelcheck(7) && visit_url("cyrpt.php").contains_text("cyrpt6d.gif"));

will first perform the level check. If that returns false, then it will return false and not bother with the visit_url().

I asked about this long ago and was happy to discover that ASH behaves this way. I take advantage of it all the time in my scripts.

Now, if only use() had a useful return value...
 
Last edited:
I asked about this in the other thread, but I'm really worried about it, so I'll be lame and repeat myself:

What about scripts that include other scripts? If you try to include two scripts that each include zlib, mafia will puke, as I understand it. This is a huge potential problem for ascend.ash in particular, since it includes so many other scripts which also need to be run independently (and hence will each need to include zlib).
 
If you try to include two scripts that each include zlib, mafia will puke, as I understand it.

I'm very concerned with mafia's drinking problem. Putting that aside, I guess you could edit the included scripts to remove zlib and putting the include statement in the script that calls them. I understand that you'd rather not edit these other scripts since they were written by someone else and they are subject to someone else's version control, but it might be the only solution unless one of mafia's developers could change this.

Try submitting it as a feature request. (Or a bug fix?)

And I'd suggest locking the liquor cabinet to keep mafia from puking.
 
I asked about this in the other thread, but I'm really worried about it, so I'll be lame and repeat myself:

What about scripts that include other scripts? If you try to include two scripts that each include zlib, mafia will puke, as I understand it. This is a huge potential problem for ascend.ash in particular, since it includes so many other scripts which also need to be run independently (and hence will each need to include zlib).
Really? I have a bunch of scripts that include other scripts, and all the aforementioned scripts include a lib script I wrote and nothing breaks. Have you actually tried, and if so does mafia create an error log?
 
Back
Top