Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- script "crimboMining.ash";
- notify bombar;
- since r15029;
- string version = "1.10";
- int maxFailsAllowed = 1; //How much bigger a set of continout interesting points can be more then 6, if you were to explore all in bigger chains, you are guarnteed a cave in
- int maxCaves = 200; //Max caves to check against, mainly to solve for infinite loops just in case
- boolean requireFreeMining = true; //Whether to force no turn used
- boolean useDynamite = true;//Whether to use minin' dynamite
- int minNumberTailingsPerCave = 2;//Number of tailing you want to get from each cave at a mininum, set to 26 if you want to get all of them (6 nuggets, 4 cave ins, 26 tailings per cave)
- boolean useMafiaRestore = false;//Whether to use kol's healing script, if set to false will attempt custom logic to heal a point
- //Determines if you will use a healing skill or just go to docs, a value of $skill[none] means goto doc, otherwise attempt to use skill provided, if that doesn't work then it will still go to docs
- skill healingSkill = $skill[none];//Note only used if useMafiaRestore = false;
- //copy and paste one of these skills over $skill[none] to try to use that skill before heading to docs, should work with non-listed skills just adding them for ease of use
- //$skill[saucy salve], $skill[lasagna bandages], $skill[tongue of the walrus], $skill[cannelloni cocoon], $skill[shake it off]
- boolean finishedMining = false;
- record Spot {
- int row;
- int col;
- int counter;
- boolean isInteresting;
- boolean checkedForChain;
- int numDirects;
- int costToGetTo;
- boolean isCaveIn;
- string shortestRoute;
- boolean mined;
- };
- record Chain {
- int numSpotsInChain;
- Spot[int] spotsInChain;
- Spot entryPoint;
- };
- record Mine {
- Chain currentLongestChain;
- Spot[int] interestingSpots;
- Spot[int][int] spots;
- int nuggetsFound;
- int tailingsFound;
- Spot[int] tailingSpotsChecked;
- };
- record MiningOperation {
- int startingNumNuggets;
- int startingNumTailings;
- int numCavesSkipped;
- int numCavesFullyExplored;
- int numCaveIns;
- int numOilyLegsAtStart;
- int startTime;
- };
- Spot newSpot(int counter, int col, int row) {
- Spot result = new Spot();
- result.col = col;
- result.row = row;
- result.counter = counter;
- result.isInteresting = false;
- result.numDirects = 0;
- result.costToGetTo = 10000;
- result.isCaveIn = false;
- result.checkedForChain = false;
- result.shortestRoute = "";
- result.mined = false;
- return result;
- }
- Chain newChain() {
- Chain newChain = new Chain();
- newChain.numSpotsInChain = 0;
- clear(newChain.spotsInChain);
- return newChain;
- }
- Mine newMine() {
- Mine result = new Mine();
- result.currentLongestChain = newChain();
- clear(result.interestingSpots);
- clear(result.spots);
- result.nuggetsFound = 0;
- result.tailingsFound = 0;
- return result;
- }
- Mine currentMine;
- MiningOperation currentOperation;
- string printSpot(Spot currentSpot) {
- buffer result;
- result.append("(");
- result.append(currentSpot.col);
- result.append(",");
- result.append(currentSpot.row);
- result.append(")");
- return result;
- }
- void restoreMinHP() {
- if (useMafiaRestore) {
- restore_hp(1);
- } else if (healingSkill != $skill[none]) {
- //Attempt to use skill
- if (my_mp() > mp_cost(healingSkill))
- use_skill(healingSkill);
- }
- if (my_hp() == 0) {
- if (my_meat() < 10)
- abort("Don't have enought meat to heal");
- cli_execute("galaktik hp 1"); //Thanks to Ezandora for pointing this out.
- }
- }
- void restore_outfit(){
- outfit("Backup");
- }
- void endMiningOperation() {
- restore_outfit();
- int numNuggets = item_amount($item[nugget of Crimbonium]) - currentOperation.startingNumNuggets;
- int numTailings = item_amount($item[peppermint tailings]) - currentOperation.startingNumTailings;
- int numMSTaken = gametime_to_int() - currentOperation.startTime;
- float numSecondsTaken = numMSTaken / 1000;
- print("Number of Fully Explored Caves: " + currentOperation.numCavesFullyExplored, "blue");
- print("Number of Caves Skipped because chain to large: " + currentOperation.numCavesSkipped, "blue");
- print("Number of Cave Ins that occurred: " + currentOperation.numCaveIns, "blue");
- print("Number of " + $item[peppermint tailings] + " found: " + numTailings, "blue");
- print("Number of " + $item[nugget of Crimbonium] + " found: " + numNuggets, "blue");
- print("Number of seconds it took: " + numSecondsTaken, "blue");
- }
- void abortMining(string reason) {
- endMiningOperation();
- print(reason);
- finishedMining = true;
- }
- void processSpotForChain(Chain currentChain, Spot currentSpot) {
- //Add to chain, marked off as being checked
- int numInChain = count(currentChain.spotsInChain);
- currentChain.spotsInChain[numInChain] = currentSpot;
- currentSpot.checkedForChain = true;
- int row = currentSpot.row;
- int col = currentSpot.col;
- //Check Left
- if (col != 1) {
- Spot checkSpot = currentMine.spots[col - 1][row];
- if (checkSpot.isInteresting) {
- currentSpot.numDirects += 1;
- if (!checkSpot.checkedForChain)
- processSpotForChain(currentChain, checkSpot);
- }
- }
- //Check Right
- if (col != 6) {
- Spot checkSpot = currentMine.spots[col + 1][row];
- if (checkSpot.isInteresting) {
- currentSpot.numDirects += 1;
- if (!checkSpot.checkedForChain)
- processSpotForChain(currentChain, checkSpot);
- }
- }
- //Check Above
- if (row != 1) {
- Spot checkSpot = currentMine.spots[col][row - 1];
- if (checkSpot.isInteresting) {
- currentSpot.numDirects += 1;
- if (!checkSpot.checkedForChain)
- processSpotForChain(currentChain, checkSpot);
- }
- }
- //Check Below
- if (row != 6) {
- Spot checkSpot = currentMine.spots[col][row + 1];
- if (checkSpot.isInteresting) {
- currentSpot.numDirects += 1;
- if (!checkSpot.checkedForChain)
- processSpotForChain(currentChain, checkSpot);
- }
- }
- }
- void calculateLongestChain() {
- Chain currentChain = newChain();
- Spot currentSpot;
- foreach spotNdx in currentMine.interestingSpots {
- currentSpot = currentMine.interestingSpots[spotNdx];
- if (currentSpot.isInteresting && !currentSpot.checkedForChain) {
- processSpotForChain(currentChain, currentSpot);
- }
- if (count(currentChain.spotsInChain) >= 6) // Found the chain we need, only chains 6 and longer here are the ones we are looking for
- break;
- else {
- foreach tmpSpotNdx in currentChain.spotsInChain {
- Spot tmpSpot = currentChain.spotsInChain[tmpSpotNdx];
- tmpSpot.isCaveIn = true;
- }
- }
- }
- currentMine.currentLongestChain = currentChain;
- foreach spotNdx in currentMine.interestingSpots {
- currentSpot = currentMine.interestingSpots[spotNdx];
- if (currentSpot.isInteresting && !currentSpot.checkedForChain)
- currentSpot.isCaveIn = true;
- }
- }
- void parseMine() {
- //string page = visit_url("place.php?whichplace=desertbeach&action=db_crimbo14mine");
- buffer page = visit_url("mining.php?mine=5");
- if (page.contains_text("<table cellpadding=0 cellspacing=0 border=0 background=")) {
- page.substring(page.index_of("<table cellpadding=0 cellspacing=0 border=0 background="));
- for counter from 0 to 54 {
- int rowNdx = counter / 8;
- int colNdx = counter % 8;
- if (rowNdx > 0 && rowNdx < 7) {
- if (colNdx > 0 && colNdx < 7) {
- Spot newSpot = newSpot(counter, colNdx, rowNdx);
- currentMine.spots[colNdx][rowNdx] = newSpot;
- if (page.contains_text("Promising Chunk of Wall (" + colNdx + "," + rowNdx + ")")) {
- currentMine.interestingSpots[count(currentMine.interestingSpots)] = newSpot;
- newSpot.isInteresting = true;
- if (rowNdx >= 5)
- newSpot.isCaveIn = true;
- }
- }
- }
- }
- }
- }
- void figureRoute() {
- int cheapestPath = 100000;
- Spot firstSpot;
- foreach spotNdx in currentMine.currentLongestChain.spotsInChain {
- Spot currentSpot = currentMine.currentLongestChain.spotsInChain[spotNdx];
- if (currentSpot.costToGetTo < cheapestPath){
- cheapestPath = currentSpot.costToGetTo;
- firstSpot = currentSpot;
- currentMine.currentLongestChain.entryPoint = currentSpot;
- }
- }
- //print("Starting point will be: " + printSpot(firstSpot) + " path: " + firstSpot.shortestRoute);
- }
- void printMine() {
- for rowNdx from 1 to 6 {
- if (rowNdx == 1)
- print("=======================================");
- else
- print("----------------------------------------");
- buffer row;
- row.append("| ");
- for colNdx from 1 to 6 {
- if (currentMine.spots[colNdx][rowNdx].isCaveIn)
- row.append(" c ");
- else if (currentMine.spots[colNdx][rowNdx].isInteresting)
- row.append(" " + currentMine.spots[colNdx][rowNdx].numDirects + " ");
- else
- row.append(" X ");
- row.append(" |");
- }
- print(row);
- }
- }
- void printPaths() {
- for rowNdx from 1 to 6 {
- if (rowNdx == 1)
- print("=======================================");
- else
- print("----------------------------------------");
- buffer row;
- row.append("| ");
- for colNdx from 1 to 6 {
- row.append(" " + currentMine.spots[colNdx][rowNdx].costToGetTo + " ");
- row.append(" |");
- }
- print(row);
- }
- }
- void calcPathsFromSpot(Spot currentSpot, string pathSoFar, int lengthSoFar) {
- int increment = 1;
- if (currentSpot.isCaveIn)
- increment = 6;
- int tmpLength = lengthSoFar + increment;
- if (tmpLength < currentSpot.costToGetTo) {
- currentSpot.costToGetTo = tmpLength;
- pathSoFar = pathSoFar + currentSpot.counter + ";";
- currentSpot.shortestRoute = pathSoFar;
- if (currentSpot.col > 1)
- calcPathsFromSpot(currentMine.spots[currentSpot.col - 1][currentSpot.row], pathSoFar, currentSpot.costToGetTo);
- if (currentSpot.row > 1)
- calcPathsFromSpot(currentMine.spots[currentSpot.col][currentSpot.row - 1], pathSoFar, currentSpot.costToGetTo);
- if (currentSpot.col < 6)
- calcPathsFromSpot(currentMine.spots[currentSpot.col + 1][currentSpot.row], pathSoFar, currentSpot.costToGetTo);
- }
- }
- void calcShortestPathsToAllSpots() {
- for colNdx from 1 to 6 by 1 {
- Spot startSpot = currentMine.spots[colNdx][6];
- calcPathsFromSpot(startSpot, "", 0);
- }
- }
- void gotoNextMine() {
- visit_url("mining.php?mine=5&reset=1&pwd");
- currentMine = newMine();
- }
- void mineSpot(Spot spotToMine) {
- if (my_hp() == 0) {
- restoreMinHP();
- }
- int numDynamite = item_amount($item[minin' dynamite]);
- int numTurnsOilyLegs = have_effect($effect[oily legs]);
- if (requireFreeMining && numDynamite == 0 && numTurnsOilyLegs == 0) {
- abortMining("Currently no free mining attempts left, stopping script");
- }
- if (requireFreeMining && spotToMine.isInteresting && numTurnsOilyLegs == 0) {
- abortMining("No turns remaining of Oily Legs, and you have specified to only use free mining");
- }
- if (finishedMining)
- return;
- string result = visit_url("mining.php?mine=5&which=" + spotToMine.counter + "&pwd");
- int[item] itemsFound = extract_items(result);
- if (count(itemsFound) > 0) {
- foreach itemFound in itemsFound {
- if (itemFound == $item[nugget of Crimbonium])
- currentMine.nuggetsFound += 1;
- if (itemFound == $item[peppermint tailings])
- currentMine.tailingsFound += 1;
- }
- } else {
- currentOperation.numCaveIns += 1;
- }
- spotToMine.mined = true;
- }
- void mineChainSpot(Spot spotToMine) {
- if (finishedMining)
- return;
- if (spotToMine.mined)
- return;
- if (!spotToMine.isInteresting)
- return;
- if (currentMine.nuggetsFound >= 6)
- return;//Already found 6 nuggets here so rest of chain is cave ins
- if (spotToMine.isInteresting) {
- if (!spotToMine.mined)
- mineSpot(spotToMine);
- if (spotToMine.row != 1 && !finishedMining)
- mineChainSpot(currentMine.spots[spotToMine.col][spotToMine.row - 1]);
- if (spotToMine.col != 1 && !finishedMining)
- mineChainSpot(currentMine.spots[spotToMine.col - 1][spotToMine.row]);
- if (spotToMine.col != 6 && !finishedMining)
- mineChainSpot(currentMine.spots[spotToMine.col + 1][spotToMine.row]);
- if (spotToMine.row != 4 && !finishedMining)
- mineChainSpot(currentMine.spots[spotToMine.col][spotToMine.row + 1]);
- }
- }
- Spot findSpotByCounter(string counterString) {
- int counter = to_int(counterString);
- int row = counter / 8;
- int col = counter % 8;
- return currentMine.spots[col][row];
- }
- void handleRoute() {
- Spot entryPoint = currentMine.currentLongestChain.entryPoint;
- string routeToEntry = entryPoint.shortestRoute;
- string[int] spots = split_string(routeToEntry, ";");
- foreach ndx in spots {
- if (finishedMining)
- return;
- if (entryPoint.counter != to_int(spots[ndx]))
- mineSpot(findSpotByCounter(spots[ndx]));
- }
- mineChainSpot(entryPoint);
- }
- /*
- void useTestMine(int testMineNumber) {
- int ndxISpots = 0;
- buffer testMineBuffer;
- switch (testMineNumber) {
- case 1:
- testMineBuffer.append("WWWWWWWW");
- testMineBuffer.append("W00IIIIW");
- testMineBuffer.append("W00000IW");
- testMineBuffer.append("W00000IW");
- testMineBuffer.append("W000II0W");
- testMineBuffer.append("W000000W");
- testMineBuffer.append("W0000IIW");
- break;
- default:
- testMineBuffer.append("WWWWWWWW");
- testMineBuffer.append("WIIII00W");
- testMineBuffer.append("W0II000W");
- testMineBuffer.append("W00I000W");
- testMineBuffer.append("W000000W");
- testMineBuffer.append("W00000IW");
- testMineBuffer.append("W000II0W");
- break;
- }
- for counter from 0 to 54 {
- int rowNdx = counter / 8;
- int colNdx = counter % 8;
- if (rowNdx > 0 && rowNdx < 7) {
- if (colNdx > 0 && colNdx < 7) {
- Spot newSpot = newSpot(counter, colNdx, rowNdx);
- currentMine.spots[colNdx][rowNdx] = newSpot;
- if (testMineBuffer.char_at(counter) == 'I') {
- currentMine.interestingSpots[ndxISpots] = newSpot;
- newSpot.isInteresting = true;
- ndxISpots += 1;
- if (rowNdx >= 5)
- newSpot.isCaveIn = true;
- }
- }
- }
- }
- }
- */
- void mineSingleSpot() {
- if (finishedMining)
- return;
- Spot singleSpot = currentMine.spots[1][6];
- while (singleSpot.isCaveIn) {
- singleSpot = currentMine.spots[singleSpot.col + 1][6];
- }
- mineSpot(singleSpot);
- }
- void mineTailingSpot(Spot currentSpot) {
- if (finishedMining)
- return;
- if (!currentSpot.mined && !currentSpot.isInteresting) {
- mineSpot(currentSpot);
- }
- currentMine.tailingSpotsChecked[currentSpot.counter] = currentSpot;
- if (currentSpot.mined) {
- Spot nextSpot;
- if (currentMine.tailingsFound < minNumberTailingsPerCave && currentSpot.col != 1) {
- nextSpot = currentMine.spots[currentSpot.col - 1][currentSpot.row];
- if (!(currentMine.tailingSpotsChecked contains nextSpot.counter))
- mineTailingSpot(nextSpot);
- }
- if (finishedMining)
- return;
- if (currentMine.tailingsFound < minNumberTailingsPerCave && currentSpot.row != 1) {
- nextSpot = currentMine.spots[currentSpot.col][currentSpot.row - 1];
- if (!(currentMine.tailingSpotsChecked contains nextSpot.counter))
- mineTailingSpot(nextSpot);
- }
- if (finishedMining)
- return;
- if (currentMine.tailingsFound < minNumberTailingsPerCave && currentSpot.col != 6) {
- nextSpot = currentMine.spots[currentSpot.col + 1][currentSpot.row];
- if (!(currentMine.tailingSpotsChecked contains nextSpot.counter))
- mineTailingSpot(nextSpot);
- }
- }
- }
- void mineTailings() {
- Spot startSpot = currentMine.spots[1][6];
- while (startSpot.isCaveIn) {
- startSpot = currentMine.spots[startSpot.col + 1][6];
- }
- int colCounter = startSpot.col;
- while (colCounter <= 6 && currentMine.tailingsFound < minNumberTailingsPerCave) {
- mineTailingSpot(startSpot);
- if (colCounter != 6)
- startSpot = currentMine.spots[startSpot.col + 1][6];
- colCounter += 1;
- }
- }
- void handleCurrentMine() {
- if (have_effect($effect[Crimbonar]) == 0 && have_effect($effect[object detection]) == 0) {
- abortMining("This script requires that you have the " + $effect[Crimbonar] + " or " + $effect[object detection] + " effect active while starting the mining process");
- }
- parseMine(); //First thing to do is parse the mine
- //useTestMine(0);
- calculateLongestChain(); //Then calculate longest chain
- //printMine();
- int numAllowedAttempts = 6 + maxFailsAllowed;
- if (count(currentMine.currentLongestChain.spotsInChain) > numAllowedAttempts || count(currentMine.currentLongestChain.spotsInChain) < 6 ) {
- print("Would fail too many times on this mine, need to go to next");
- mineSingleSpot();
- currentOperation.numCavesSkipped += 1;
- } else {
- calcShortestPathsToAllSpots();
- //Figure route to mine
- figureRoute();
- handleRoute();
- currentOperation.numCavesFullyExplored += 1;
- if (currentMine.tailingsFound < minNumberTailingsPerCave) {
- mineTailings();
- }
- }
- }
- void initMiningOperations() {
- cli_execute("outfit save Backup");
- outfit("High-Radiation Mining Gear");
- if (item_amount($item[Xiblaxian holo-wrist-puter]) > 0) {
- equip($slot[acc2], $item[Xiblaxian holo-wrist-puter]);
- }
- currentOperation = new MiningOperation();
- currentOperation.startingNumNuggets = item_amount($item[nugget of Crimbonium]);
- currentOperation.startingNumTailings = item_amount($item[peppermint tailings]);
- currentOperation.numCaveIns = 0;
- currentOperation.numCavesSkipped = 0;
- currentOperation.numCavesFullyExplored = 0;
- currentOperation.startTime = gametime_to_int();
- if (!useDynamite) {
- put_closet(item_amount($item[minin' dynamite]), $item[minin' dynamite]);
- }
- }
- boolean specialMining() {
- main();
- }
- void main() {
- initMiningOperations();
- int counter = 0;
- while(counter < maxCaves && !finishedMining) {
- gotoNextMine();
- handleCurrentMine();
- counter += 1;
- }
- endMiningOperation();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement