boolean bcascMining() {
if (checkStage("mining")) return true;
string trapper = visit_url("trapper.php");
if (my_level() >= 8 && !contains_text(trapper, "I reckon 3 chunks")) {
print("Looks like we're done mining.", "purple");
checkStage("mining", true);
return true;
}
string goalString = get_property("trapperOre");
item goal = to_item(goalString);
if (goal != $item[asbestos ore] && goal != $item[chrome ore] && goal != $item[linoleum ore])
abort("Can't figure out which ore to look for.");
// Seed ore locations with what mafia knows about.
int[int] oreLocations;
string mineLayout = get_property("mineLayout1");
int start = 0;
while (true) {
int num_start = index_of(mineLayout, '#', start);
if (num_start == -1) break;
int num_end = index_of(mineLayout, '<', num_start);
if (num_end == -1) break;
int end = index_of(mineLayout, '>', num_end);
if (end == -1) break;
if (contains_text(substring(mineLayout, num_end, end), goalString)) {
int spot = to_int(substring(mineLayout, num_start + 1, num_end));
oreLocations[count(oreLocations)] = spot;
}
start = end;
}
boolean rowContainsEmpty(string mine, int y)
{
for x from 1 to 6 {
if (contains_text(mine, "Open Cavern (" + x + "," + y + ")"))
return true;
}
return false;
}
boolean canMine(string mine, int x, int y, boolean onlySparkly)
{
if (x < 0 || x > 7 || y < 0 || y > 7)
return false;
int index = x + y * 8;
boolean clickable = (index_of(mine, "mining.php?mine=1&which=" + index + "&") != -1);
if (!clickable || !onlySparkly)
return clickable;
return contains_text(mine, "Promising Chunk of Wall (" + x + "," + y + ")");
}
int adjacentSparkly(string mine, int index)
{
int x = index % 8;
int y = index / 8;
if (canMine(mine, x, y - 1, true))
return index - 8;
if (canMine(mine, x - 1, y, true))
return index - 1;
if (canMine(mine, x + 1, y, true))
return index + 1;
if (canMine(mine, x, y + 1, true))
return index + 8;
return - 1;
}
int findSpot(string mine, boolean[int] rows, boolean[int] cols) {
foreach sparkly in $booleans[true, false] {
foreach y in cols {
foreach x in rows {
if (canMine(mine, x, y, sparkly))
return x + y * 8;
}
}
}
return -1;
}
cli_execute("outfit mining");
while (item_amount(goal) < 3) {
if (my_hp() == 0) cli_execute("restore hp");
string mine = visit_url("mining.php?intro=1&mine=1");
if (contains_text(mine, "You can't mine without the proper equipment."))
abort("Couldn't equip mining gear.");
boolean willCostAdventure = contains_text(mine, "takes one Adventure.");
if (have_skill($skill[Unaccompanied Miner]) && willCostAdventure && have_effect($effect[Teleportitis]) == 0 && my_level() < 12) {
print("BCC: No more mining today. I'll come back later.", "purple");
return false;
}
if (my_adventures() == 0 && willCostAdventure) abort("No Adventures");
int choice = -1;
string why = "Mining around found ore";
// Ore is always coincident, so look nearby if we've aleady found some.
if (count(oreLocations) > 0) {
foreach key in oreLocations {
choice = adjacentSparkly(mine, oreLocations[key]);
if (choice != -1)
break;
}
}
// Prefer mining the middle first. It leaves more options.
boolean[int] rows = $ints[3, 4, 2, 5, 1, 6];
// First, try to mine up to the top four rows if we haven't yet.
if (choice == -1 && !rowContainsEmpty(mine, 6)) {
choice = findSpot(mine, rows, $ints[6]);
why = "Mining upwards";
}
if (choice == -1 && !rowContainsEmpty(mine, 5)) {
choice = findSpot(mine, rows, $ints[5]);
why = "Mining upwards";
}
// Top three rows contain most ore. Fourth row may contain ore.
// Prefer second row and digging towards the middle because it
// opens up the most potential options. This could be more
// optimal, but it's not a bad heuristic.
if (choice == -1) {
choice = findSpot(mine, rows, $ints[2, 3, 1, 4]);
why = "Mining top four rows";
}
// There's only four pieces of the same ore in each mine.
// Maybe you accidentally auto-sold them or something?
if (choice == -1 || count(oreLocations) == 4) {
print("BCC: Resetting mine!", "purple");
visit_url("mining.php?mine=1&reset=1&pwd");
oreLocations.clear();
continue;
}
print(why + ": " + (choice % 8) + ", " + (choice / 8) + ".", "purple");
string result = visit_url("mining.php?mine=1&which=" + choice + "&pwd");
if (index_of(result, goalString) != -1) {
oreLocations[count(oreLocations)] = choice;
}
}
if (have_effect($effect[Beaten Up]) > 0) cli_execute("unaffect beaten up");
visit_url("trapper.php");
checkStage("mining", true);
return true;
}