Advertisement
bombar

crimboMiningSpecial.ash

Dec 11th, 2014
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.35 KB | None | 0 0
  1. script "crimboMining.ash";
  2. notify bombar;
  3. since r15029;
  4.  
  5. string version = "1.10";
  6.  
  7. 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
  8. int maxCaves = 200; //Max caves to check against, mainly to solve for infinite loops just in case
  9. boolean requireFreeMining = true; //Whether to force no turn used
  10. boolean useDynamite = true;//Whether to use minin' dynamite
  11.  
  12. 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)
  13.  
  14. boolean useMafiaRestore = false;//Whether to use kol's healing script, if set to false will attempt custom logic to heal a point
  15.  
  16. //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
  17. skill healingSkill = $skill[none];//Note only used if useMafiaRestore = false;
  18. //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
  19. //$skill[saucy salve], $skill[lasagna bandages], $skill[tongue of the walrus], $skill[cannelloni cocoon], $skill[shake it off]
  20.  
  21. boolean finishedMining = false;
  22.  
  23. record Spot {
  24. int row;
  25. int col;
  26. int counter;
  27. boolean isInteresting;
  28. boolean checkedForChain;
  29. int numDirects;
  30. int costToGetTo;
  31. boolean isCaveIn;
  32. string shortestRoute;
  33. boolean mined;
  34. };
  35.  
  36. record Chain {
  37. int numSpotsInChain;
  38. Spot[int] spotsInChain;
  39. Spot entryPoint;
  40. };
  41.  
  42. record Mine {
  43. Chain currentLongestChain;
  44. Spot[int] interestingSpots;
  45. Spot[int][int] spots;
  46. int nuggetsFound;
  47. int tailingsFound;
  48. Spot[int] tailingSpotsChecked;
  49. };
  50.  
  51. record MiningOperation {
  52. int startingNumNuggets;
  53. int startingNumTailings;
  54. int numCavesSkipped;
  55. int numCavesFullyExplored;
  56. int numCaveIns;
  57. int numOilyLegsAtStart;
  58. int startTime;
  59. };
  60.  
  61. Spot newSpot(int counter, int col, int row) {
  62. Spot result = new Spot();
  63. result.col = col;
  64. result.row = row;
  65. result.counter = counter;
  66. result.isInteresting = false;
  67. result.numDirects = 0;
  68. result.costToGetTo = 10000;
  69. result.isCaveIn = false;
  70. result.checkedForChain = false;
  71. result.shortestRoute = "";
  72. result.mined = false;
  73. return result;
  74. }
  75.  
  76. Chain newChain() {
  77. Chain newChain = new Chain();
  78. newChain.numSpotsInChain = 0;
  79. clear(newChain.spotsInChain);
  80. return newChain;
  81. }
  82.  
  83.  
  84. Mine newMine() {
  85. Mine result = new Mine();
  86. result.currentLongestChain = newChain();
  87. clear(result.interestingSpots);
  88. clear(result.spots);
  89. result.nuggetsFound = 0;
  90. result.tailingsFound = 0;
  91. return result;
  92. }
  93.  
  94. Mine currentMine;
  95. MiningOperation currentOperation;
  96.  
  97. string printSpot(Spot currentSpot) {
  98. buffer result;
  99. result.append("(");
  100. result.append(currentSpot.col);
  101. result.append(",");
  102. result.append(currentSpot.row);
  103. result.append(")");
  104. return result;
  105. }
  106.  
  107. void restoreMinHP() {
  108. if (useMafiaRestore) {
  109. restore_hp(1);
  110. } else if (healingSkill != $skill[none]) {
  111. //Attempt to use skill
  112. if (my_mp() > mp_cost(healingSkill))
  113. use_skill(healingSkill);
  114. }
  115.  
  116. if (my_hp() == 0) {
  117. if (my_meat() < 10)
  118. abort("Don't have enought meat to heal");
  119.  
  120. cli_execute("galaktik hp 1"); //Thanks to Ezandora for pointing this out.
  121. }
  122. }
  123.  
  124. void restore_outfit(){
  125. outfit("Backup");
  126. }
  127.  
  128. void endMiningOperation() {
  129. restore_outfit();
  130. int numNuggets = item_amount($item[nugget of Crimbonium]) - currentOperation.startingNumNuggets;
  131. int numTailings = item_amount($item[peppermint tailings]) - currentOperation.startingNumTailings;
  132.  
  133. int numMSTaken = gametime_to_int() - currentOperation.startTime;
  134. float numSecondsTaken = numMSTaken / 1000;
  135.  
  136. print("Number of Fully Explored Caves: " + currentOperation.numCavesFullyExplored, "blue");
  137. print("Number of Caves Skipped because chain to large: " + currentOperation.numCavesSkipped, "blue");
  138. print("Number of Cave Ins that occurred: " + currentOperation.numCaveIns, "blue");
  139. print("Number of " + $item[peppermint tailings] + " found: " + numTailings, "blue");
  140. print("Number of " + $item[nugget of Crimbonium] + " found: " + numNuggets, "blue");
  141. print("Number of seconds it took: " + numSecondsTaken, "blue");
  142. }
  143.  
  144. void abortMining(string reason) {
  145. endMiningOperation();
  146. print(reason);
  147. finishedMining = true;
  148. }
  149. void processSpotForChain(Chain currentChain, Spot currentSpot) {
  150. //Add to chain, marked off as being checked
  151. int numInChain = count(currentChain.spotsInChain);
  152. currentChain.spotsInChain[numInChain] = currentSpot;
  153. currentSpot.checkedForChain = true;
  154.  
  155. int row = currentSpot.row;
  156. int col = currentSpot.col;
  157.  
  158. //Check Left
  159. if (col != 1) {
  160. Spot checkSpot = currentMine.spots[col - 1][row];
  161. if (checkSpot.isInteresting) {
  162. currentSpot.numDirects += 1;
  163. if (!checkSpot.checkedForChain)
  164. processSpotForChain(currentChain, checkSpot);
  165. }
  166. }
  167.  
  168. //Check Right
  169. if (col != 6) {
  170. Spot checkSpot = currentMine.spots[col + 1][row];
  171. if (checkSpot.isInteresting) {
  172. currentSpot.numDirects += 1;
  173. if (!checkSpot.checkedForChain)
  174. processSpotForChain(currentChain, checkSpot);
  175. }
  176. }
  177.  
  178. //Check Above
  179. if (row != 1) {
  180. Spot checkSpot = currentMine.spots[col][row - 1];
  181. if (checkSpot.isInteresting) {
  182. currentSpot.numDirects += 1;
  183. if (!checkSpot.checkedForChain)
  184. processSpotForChain(currentChain, checkSpot);
  185. }
  186. }
  187.  
  188. //Check Below
  189. if (row != 6) {
  190. Spot checkSpot = currentMine.spots[col][row + 1];
  191. if (checkSpot.isInteresting) {
  192. currentSpot.numDirects += 1;
  193. if (!checkSpot.checkedForChain)
  194. processSpotForChain(currentChain, checkSpot);
  195. }
  196. }
  197.  
  198.  
  199. }
  200.  
  201. void calculateLongestChain() {
  202. Chain currentChain = newChain();
  203. Spot currentSpot;
  204. foreach spotNdx in currentMine.interestingSpots {
  205. currentSpot = currentMine.interestingSpots[spotNdx];
  206. if (currentSpot.isInteresting && !currentSpot.checkedForChain) {
  207. processSpotForChain(currentChain, currentSpot);
  208. }
  209.  
  210. if (count(currentChain.spotsInChain) >= 6) // Found the chain we need, only chains 6 and longer here are the ones we are looking for
  211. break;
  212. else {
  213. foreach tmpSpotNdx in currentChain.spotsInChain {
  214. Spot tmpSpot = currentChain.spotsInChain[tmpSpotNdx];
  215. tmpSpot.isCaveIn = true;
  216. }
  217. }
  218. }
  219.  
  220. currentMine.currentLongestChain = currentChain;
  221.  
  222. foreach spotNdx in currentMine.interestingSpots {
  223. currentSpot = currentMine.interestingSpots[spotNdx];
  224. if (currentSpot.isInteresting && !currentSpot.checkedForChain)
  225. currentSpot.isCaveIn = true;
  226. }
  227. }
  228.  
  229. void parseMine() {
  230. //string page = visit_url("place.php?whichplace=desertbeach&action=db_crimbo14mine");
  231. buffer page = visit_url("mining.php?mine=5");
  232. if (page.contains_text("<table cellpadding=0 cellspacing=0 border=0 background=")) {
  233. page.substring(page.index_of("<table cellpadding=0 cellspacing=0 border=0 background="));
  234. for counter from 0 to 54 {
  235. int rowNdx = counter / 8;
  236. int colNdx = counter % 8;
  237. if (rowNdx > 0 && rowNdx < 7) {
  238. if (colNdx > 0 && colNdx < 7) {
  239. Spot newSpot = newSpot(counter, colNdx, rowNdx);
  240. currentMine.spots[colNdx][rowNdx] = newSpot;
  241.  
  242. if (page.contains_text("Promising Chunk of Wall (" + colNdx + "," + rowNdx + ")")) {
  243. currentMine.interestingSpots[count(currentMine.interestingSpots)] = newSpot;
  244. newSpot.isInteresting = true;
  245. if (rowNdx >= 5)
  246. newSpot.isCaveIn = true;
  247. }
  248. }
  249. }
  250. }
  251. }
  252. }
  253.  
  254. void figureRoute() {
  255. int cheapestPath = 100000;
  256. Spot firstSpot;
  257.  
  258. foreach spotNdx in currentMine.currentLongestChain.spotsInChain {
  259. Spot currentSpot = currentMine.currentLongestChain.spotsInChain[spotNdx];
  260. if (currentSpot.costToGetTo < cheapestPath){
  261. cheapestPath = currentSpot.costToGetTo;
  262. firstSpot = currentSpot;
  263. currentMine.currentLongestChain.entryPoint = currentSpot;
  264. }
  265. }
  266.  
  267. //print("Starting point will be: " + printSpot(firstSpot) + " path: " + firstSpot.shortestRoute);
  268. }
  269.  
  270. void printMine() {
  271. for rowNdx from 1 to 6 {
  272. if (rowNdx == 1)
  273. print("=======================================");
  274. else
  275. print("----------------------------------------");
  276. buffer row;
  277. row.append("| ");
  278.  
  279. for colNdx from 1 to 6 {
  280. if (currentMine.spots[colNdx][rowNdx].isCaveIn)
  281. row.append(" c ");
  282. else if (currentMine.spots[colNdx][rowNdx].isInteresting)
  283. row.append(" " + currentMine.spots[colNdx][rowNdx].numDirects + " ");
  284. else
  285. row.append(" X ");
  286. row.append(" |");
  287. }
  288. print(row);
  289.  
  290. }
  291. }
  292.  
  293. void printPaths() {
  294. for rowNdx from 1 to 6 {
  295. if (rowNdx == 1)
  296. print("=======================================");
  297. else
  298. print("----------------------------------------");
  299. buffer row;
  300. row.append("| ");
  301.  
  302. for colNdx from 1 to 6 {
  303. row.append(" " + currentMine.spots[colNdx][rowNdx].costToGetTo + " ");
  304. row.append(" |");
  305. }
  306. print(row);
  307.  
  308. }
  309.  
  310. }
  311.  
  312. void calcPathsFromSpot(Spot currentSpot, string pathSoFar, int lengthSoFar) {
  313. int increment = 1;
  314. if (currentSpot.isCaveIn)
  315. increment = 6;
  316.  
  317. int tmpLength = lengthSoFar + increment;
  318. if (tmpLength < currentSpot.costToGetTo) {
  319. currentSpot.costToGetTo = tmpLength;
  320. pathSoFar = pathSoFar + currentSpot.counter + ";";
  321. currentSpot.shortestRoute = pathSoFar;
  322. if (currentSpot.col > 1)
  323. calcPathsFromSpot(currentMine.spots[currentSpot.col - 1][currentSpot.row], pathSoFar, currentSpot.costToGetTo);
  324. if (currentSpot.row > 1)
  325. calcPathsFromSpot(currentMine.spots[currentSpot.col][currentSpot.row - 1], pathSoFar, currentSpot.costToGetTo);
  326. if (currentSpot.col < 6)
  327. calcPathsFromSpot(currentMine.spots[currentSpot.col + 1][currentSpot.row], pathSoFar, currentSpot.costToGetTo);
  328. }
  329. }
  330.  
  331. void calcShortestPathsToAllSpots() {
  332. for colNdx from 1 to 6 by 1 {
  333. Spot startSpot = currentMine.spots[colNdx][6];
  334. calcPathsFromSpot(startSpot, "", 0);
  335. }
  336. }
  337.  
  338.  
  339. void gotoNextMine() {
  340. visit_url("mining.php?mine=5&reset=1&pwd");
  341. currentMine = newMine();
  342. }
  343.  
  344. void mineSpot(Spot spotToMine) {
  345.  
  346. if (my_hp() == 0) {
  347. restoreMinHP();
  348. }
  349.  
  350. int numDynamite = item_amount($item[minin' dynamite]);
  351. int numTurnsOilyLegs = have_effect($effect[oily legs]);
  352.  
  353. if (requireFreeMining && numDynamite == 0 && numTurnsOilyLegs == 0) {
  354. abortMining("Currently no free mining attempts left, stopping script");
  355. }
  356.  
  357. if (requireFreeMining && spotToMine.isInteresting && numTurnsOilyLegs == 0) {
  358. abortMining("No turns remaining of Oily Legs, and you have specified to only use free mining");
  359. }
  360.  
  361. if (finishedMining)
  362. return;
  363.  
  364. string result = visit_url("mining.php?mine=5&which=" + spotToMine.counter + "&pwd");
  365. int[item] itemsFound = extract_items(result);
  366. if (count(itemsFound) > 0) {
  367. foreach itemFound in itemsFound {
  368. if (itemFound == $item[nugget of Crimbonium])
  369. currentMine.nuggetsFound += 1;
  370. if (itemFound == $item[peppermint tailings])
  371. currentMine.tailingsFound += 1;
  372. }
  373. } else {
  374. currentOperation.numCaveIns += 1;
  375. }
  376.  
  377.  
  378. spotToMine.mined = true;
  379. }
  380.  
  381. void mineChainSpot(Spot spotToMine) {
  382. if (finishedMining)
  383. return;
  384.  
  385. if (spotToMine.mined)
  386. return;
  387. if (!spotToMine.isInteresting)
  388. return;
  389. if (currentMine.nuggetsFound >= 6)
  390. return;//Already found 6 nuggets here so rest of chain is cave ins
  391.  
  392. if (spotToMine.isInteresting) {
  393. if (!spotToMine.mined)
  394. mineSpot(spotToMine);
  395. if (spotToMine.row != 1 && !finishedMining)
  396. mineChainSpot(currentMine.spots[spotToMine.col][spotToMine.row - 1]);
  397. if (spotToMine.col != 1 && !finishedMining)
  398. mineChainSpot(currentMine.spots[spotToMine.col - 1][spotToMine.row]);
  399. if (spotToMine.col != 6 && !finishedMining)
  400. mineChainSpot(currentMine.spots[spotToMine.col + 1][spotToMine.row]);
  401. if (spotToMine.row != 4 && !finishedMining)
  402. mineChainSpot(currentMine.spots[spotToMine.col][spotToMine.row + 1]);
  403. }
  404.  
  405. }
  406.  
  407. Spot findSpotByCounter(string counterString) {
  408. int counter = to_int(counterString);
  409. int row = counter / 8;
  410. int col = counter % 8;
  411.  
  412. return currentMine.spots[col][row];
  413. }
  414.  
  415. void handleRoute() {
  416. Spot entryPoint = currentMine.currentLongestChain.entryPoint;
  417. string routeToEntry = entryPoint.shortestRoute;
  418. string[int] spots = split_string(routeToEntry, ";");
  419. foreach ndx in spots {
  420. if (finishedMining)
  421. return;
  422.  
  423. if (entryPoint.counter != to_int(spots[ndx]))
  424. mineSpot(findSpotByCounter(spots[ndx]));
  425.  
  426. }
  427.  
  428. mineChainSpot(entryPoint);
  429. }
  430. /*
  431. void useTestMine(int testMineNumber) {
  432. int ndxISpots = 0;
  433. buffer testMineBuffer;
  434. switch (testMineNumber) {
  435. case 1:
  436. testMineBuffer.append("WWWWWWWW");
  437. testMineBuffer.append("W00IIIIW");
  438. testMineBuffer.append("W00000IW");
  439. testMineBuffer.append("W00000IW");
  440. testMineBuffer.append("W000II0W");
  441. testMineBuffer.append("W000000W");
  442. testMineBuffer.append("W0000IIW");
  443. break;
  444. default:
  445. testMineBuffer.append("WWWWWWWW");
  446. testMineBuffer.append("WIIII00W");
  447. testMineBuffer.append("W0II000W");
  448. testMineBuffer.append("W00I000W");
  449. testMineBuffer.append("W000000W");
  450. testMineBuffer.append("W00000IW");
  451. testMineBuffer.append("W000II0W");
  452. break;
  453. }
  454. for counter from 0 to 54 {
  455. int rowNdx = counter / 8;
  456. int colNdx = counter % 8;
  457. if (rowNdx > 0 && rowNdx < 7) {
  458. if (colNdx > 0 && colNdx < 7) {
  459. Spot newSpot = newSpot(counter, colNdx, rowNdx);
  460. currentMine.spots[colNdx][rowNdx] = newSpot;
  461. if (testMineBuffer.char_at(counter) == 'I') {
  462. currentMine.interestingSpots[ndxISpots] = newSpot;
  463. newSpot.isInteresting = true;
  464. ndxISpots += 1;
  465. if (rowNdx >= 5)
  466. newSpot.isCaveIn = true;
  467. }
  468. }
  469. }
  470. }
  471. }
  472. */
  473.  
  474. void mineSingleSpot() {
  475. if (finishedMining)
  476. return;
  477.  
  478. Spot singleSpot = currentMine.spots[1][6];
  479. while (singleSpot.isCaveIn) {
  480. singleSpot = currentMine.spots[singleSpot.col + 1][6];
  481. }
  482. mineSpot(singleSpot);
  483. }
  484.  
  485.  
  486. void mineTailingSpot(Spot currentSpot) {
  487. if (finishedMining)
  488. return;
  489.  
  490. if (!currentSpot.mined && !currentSpot.isInteresting) {
  491. mineSpot(currentSpot);
  492. }
  493.  
  494. currentMine.tailingSpotsChecked[currentSpot.counter] = currentSpot;
  495.  
  496. if (currentSpot.mined) {
  497. Spot nextSpot;
  498. if (currentMine.tailingsFound < minNumberTailingsPerCave && currentSpot.col != 1) {
  499. nextSpot = currentMine.spots[currentSpot.col - 1][currentSpot.row];
  500. if (!(currentMine.tailingSpotsChecked contains nextSpot.counter))
  501. mineTailingSpot(nextSpot);
  502. }
  503.  
  504. if (finishedMining)
  505. return;
  506.  
  507. if (currentMine.tailingsFound < minNumberTailingsPerCave && currentSpot.row != 1) {
  508. nextSpot = currentMine.spots[currentSpot.col][currentSpot.row - 1];
  509. if (!(currentMine.tailingSpotsChecked contains nextSpot.counter))
  510. mineTailingSpot(nextSpot);
  511. }
  512.  
  513. if (finishedMining)
  514. return;
  515.  
  516. if (currentMine.tailingsFound < minNumberTailingsPerCave && currentSpot.col != 6) {
  517. nextSpot = currentMine.spots[currentSpot.col + 1][currentSpot.row];
  518. if (!(currentMine.tailingSpotsChecked contains nextSpot.counter))
  519. mineTailingSpot(nextSpot);
  520. }
  521. }
  522. }
  523.  
  524. void mineTailings() {
  525. Spot startSpot = currentMine.spots[1][6];
  526.  
  527. while (startSpot.isCaveIn) {
  528. startSpot = currentMine.spots[startSpot.col + 1][6];
  529. }
  530. int colCounter = startSpot.col;
  531. while (colCounter <= 6 && currentMine.tailingsFound < minNumberTailingsPerCave) {
  532. mineTailingSpot(startSpot);
  533.  
  534. if (colCounter != 6)
  535. startSpot = currentMine.spots[startSpot.col + 1][6];
  536.  
  537. colCounter += 1;
  538. }
  539. }
  540.  
  541. void handleCurrentMine() {
  542. if (have_effect($effect[Crimbonar]) == 0 && have_effect($effect[object detection]) == 0) {
  543. abortMining("This script requires that you have the " + $effect[Crimbonar] + " or " + $effect[object detection] + " effect active while starting the mining process");
  544. }
  545.  
  546. parseMine(); //First thing to do is parse the mine
  547. //useTestMine(0);
  548. calculateLongestChain(); //Then calculate longest chain
  549.  
  550. //printMine();
  551.  
  552. int numAllowedAttempts = 6 + maxFailsAllowed;
  553. if (count(currentMine.currentLongestChain.spotsInChain) > numAllowedAttempts || count(currentMine.currentLongestChain.spotsInChain) < 6 ) {
  554. print("Would fail too many times on this mine, need to go to next");
  555. mineSingleSpot();
  556. currentOperation.numCavesSkipped += 1;
  557. } else {
  558. calcShortestPathsToAllSpots();
  559. //Figure route to mine
  560. figureRoute();
  561. handleRoute();
  562. currentOperation.numCavesFullyExplored += 1;
  563.  
  564. if (currentMine.tailingsFound < minNumberTailingsPerCave) {
  565. mineTailings();
  566. }
  567. }
  568. }
  569.  
  570. void initMiningOperations() {
  571. cli_execute("outfit save Backup");
  572. outfit("High-Radiation Mining Gear");
  573.  
  574. if (item_amount($item[Xiblaxian holo-wrist-puter]) > 0) {
  575. equip($slot[acc2], $item[Xiblaxian holo-wrist-puter]);
  576. }
  577.  
  578. currentOperation = new MiningOperation();
  579. currentOperation.startingNumNuggets = item_amount($item[nugget of Crimbonium]);
  580. currentOperation.startingNumTailings = item_amount($item[peppermint tailings]);
  581. currentOperation.numCaveIns = 0;
  582. currentOperation.numCavesSkipped = 0;
  583. currentOperation.numCavesFullyExplored = 0;
  584. currentOperation.startTime = gametime_to_int();
  585.  
  586. if (!useDynamite) {
  587. put_closet(item_amount($item[minin' dynamite]), $item[minin' dynamite]);
  588. }
  589. }
  590.  
  591. boolean specialMining() {
  592. main();
  593. }
  594.  
  595. void main() {
  596. initMiningOperations();
  597.  
  598. int counter = 0;
  599.  
  600. while(counter < maxCaves && !finishedMining) {
  601. gotoNextMine();
  602. handleCurrentMine();
  603. counter += 1;
  604. }
  605. endMiningOperation();
  606. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement