Advertisement
Guest User

Untitled

a guest
Sep 30th, 2015
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.77 KB | None | 0 0
  1. # Globals
  2. ##################################################
  3.  
  4. var screenLines = 14
  5. #var screenLines = 20
  6.  
  7. string gArrayPrefix = "aRR"
  8. array memoryKeyPrefix = "c07_"
  9. array memoryKeyPeopleSorted = memoryKeyPrefix + "people_sorted"
  10. array memoryKeyPeople = memoryKeyPrefix + "people"
  11. array memoryKeyAllRooms = memoryKeyPrefix + "all_rooms"
  12. array memoryKeyAboutToConnect = memoryKeyPrefix + "a2c"
  13. array memoryKeyMakingSlurpSelection = memoryKeyPrefix + "mss"
  14. array gPeopleAsKeys = []
  15. array gAllRooms = []
  16.  
  17. array memoryKeyInvalidHashes = memoryKeyPrefix + "stored_hashes4"
  18. array gStoredHashKeys = []
  19.  
  20. number cUnStored = 0
  21. number cStoredConnectable = 1
  22. number cStoredNotConnectable = 2
  23. number cStoredInvalid = 3
  24.  
  25. # Program
  26. ##################################################
  27.  
  28. ClearText()
  29. loop
  30. Main()
  31. end
  32.  
  33. # Control Functions
  34. ##################################################
  35.  
  36. void Main()
  37. CheckPreviousRunForErrors()
  38.  
  39. var actions = ["Find person", "Slurp"]
  40. MergeSortString(actions)
  41.  
  42. string action = ScreenSelect(screenLines, LeadingText("Choose action"), [], actions)
  43. if action == "Find person"
  44. FindPerson()
  45. else if action == "Slurp"
  46. PickSlurp()
  47. end
  48. end
  49.  
  50. void CheckPreviousRunForErrors()
  51. if (HasAboutToConnect())
  52.  
  53. # Clear lower priority resume flag
  54. ClearMakingSlurpSelection()
  55.  
  56. array previousRun = GetAboutToConnect()
  57. string room = previousRun[0]
  58. string item = previousRun[1]
  59. number hash = previousRun[2]
  60.  
  61. array title = []
  62. Append(title, "Detected previous run failed.")
  63. Append(title, " Room: " + room)
  64. Append(title, " Item: " + item)
  65. Append(title, "")
  66. Append(title, "Would you like to ignore item from now on?")
  67. Append(title, DupString(Longest(title), "-"))
  68.  
  69. string ignoreAndContinueText = "Resume Slurp(), ignoring item"
  70. string forgetAndContinueText = "Resume Slurp(), retrying item"
  71. string ignoreText = "Restart, ignoring item"
  72. string forgetText = "Restart"
  73.  
  74. var actions = [ignoreAndContinueText, forgetAndContinueText, ignoreText, forgetText]
  75.  
  76. string action = ScreenSelect(screenLines, title, [], actions)
  77. ClearAboutToConnect()
  78. if action == ignoreText
  79. StoreRoomItem(room, hash, cStoredInvalid)
  80. else if action == ignoreAndContinueText
  81. StoreRoomItem(room, hash, cStoredInvalid)
  82. SlurpToRoom(room)
  83. else if action == forgetAndContinueText
  84. SlurpToRoom(room)
  85. end
  86. else if (WasMakingSlurpSelection())
  87. string room = SlurpSelectionRoom()
  88. ClearMakingSlurpSelection()
  89.  
  90. Print("Resuming previous slurp selection...")
  91. Sleep(3)
  92.  
  93. SlurpToRoom(room)
  94. end
  95. end
  96.  
  97. var GetPeople(bool sortRequired)
  98. bool sorted = HasMemory(memoryKeyPeopleSorted)
  99. array people = []
  100. if HasMemoryArray(memoryKeyPeople)
  101. people = LoadMemoryArray(memoryKeyPeople)
  102. else
  103. var s = PersonServer()
  104. Print("Retrieving people...")
  105. people = s.GetPeople()
  106. SaveMemoryArray(memoryKeyPeople, people)
  107. Print("People retrieved...")
  108. DisconnectAll()
  109. end
  110. if sortRequired == True && sorted == False
  111. Print("Sorting people(" + Count(people) + ")...")
  112. MergeSortString(people)
  113. SaveMemoryArray(memoryKeyPeople, people)
  114. SaveMemory(memoryKeyPeopleSorted, "y")
  115. end
  116. return people
  117. end
  118.  
  119. array GetPeopleAsKeys()
  120. if (Count(gPeopleAsKeys) == 0)
  121. var people = GetPeople(False)
  122. loop person in people
  123. gPeopleAsKeys[person] = 1
  124. end
  125. end
  126. return gPeopleAsKeys
  127. end
  128.  
  129. var PersonServer()
  130. # GetPeople :: [String]
  131. # GetPosition :: String -> String
  132. # "ROOMNAME, coordinate: (X,Y)
  133. # GetAction :: PersonName -> String
  134. # GetRoom :: PersonName -> String
  135. # GetThingsInRoom :: RoomName -> [String]
  136. # GetAllRooms :: [String]
  137. return Connect("PoliceOfficeInterior_MinistryOfficeWorkstationComputer_1")
  138. end
  139.  
  140. string GetPosition(string person)
  141. var s = PersonServer()
  142. Print("Retrieving position...")
  143. string position = s.GetPosition(person)
  144. Print("Position retrieved...")
  145. DisconnectAll()
  146. return position
  147. end
  148.  
  149. string GetAction(string person)
  150. var s = PersonServer()
  151. Print("Retrieving action...")
  152. string action = s.GetAction(person)
  153. Print("Action retrieved...")
  154. DisconnectAll()
  155. return action
  156. end
  157.  
  158. string GetRoom(string person)
  159. var s = PersonServer()
  160. Print("Retrieving room...")
  161. string room = s.GetRoom(person)
  162. Print("Room retrieved...")
  163. DisconnectAll()
  164. return room
  165. end
  166.  
  167. array GetAllRooms()
  168. if (Count(gAllRooms) == 0)
  169. if HasMemoryArray(memoryKeyAllRooms)
  170. gAllRooms = LoadMemoryArray(memoryKeyAllRooms)
  171. else
  172. var s = PersonServer()
  173. Print("Getting rooms...")
  174. gAllRooms = s.GetAllRooms()
  175. Print("Rooms retrieved...")
  176. DisconnectAll()
  177. SaveMemoryArray(memoryKeyAllRooms, gAllRooms)
  178. end
  179. end
  180. return gAllRooms
  181. end
  182.  
  183. array GetThingsInRoom(string room)
  184. var s = PersonServer()
  185. array things = s.GetThingsInRoom(room)
  186. DisconnectAll()
  187. return things
  188. end
  189.  
  190. void FindPerson()
  191. array people = GetPeople(True)
  192.  
  193. string person = ScreenSelect(screenLines, LeadingText("People"), ["q"], people)
  194. if (person == "q")
  195. return
  196. end
  197.  
  198. array title = []
  199.  
  200. array positionInfo = ParsePosition(GetPosition(person))
  201.  
  202. Append(title, "Person: " + person)
  203. Append(title, " Room: " + positionInfo[0])
  204. Append(title, " Coord: " + positionInfo[1] + ", " + positionInfo[2])
  205. Append(title, " Action: " + GetAction(person))
  206. Append(title, DupString(Longest(title), "-"))
  207.  
  208. array actions = ["Restart", "Slurp to same room"]
  209. string action = ScreenSelect(screenLines, title, [], actions)
  210. if action == "Slurp to same room"
  211. SlurpToRoom(GetRoom(person))
  212. end
  213. end
  214.  
  215. bool IsAllowedRoom(string room)
  216. if (IsSuffixOf("_inventory", room))
  217. return False
  218. end
  219. return True
  220. end
  221.  
  222. void PickSlurp()
  223. array areas = ["BarYvonne", "BurrowsApartments", "BurrowsNorth", "Casino", "DorisGardens", "Factory", "FinanceArea", "Foley", "HarborEast", "HarborNorth", "HarborSouth", "HarborWest", "Hotel", "Internet", "Mines", "Ministry", "PixiesApartment", "Plaza", "PoliceOffice", "PoorDesolateBuilding1", "ShoeStore", "SodaStorage", "TownHall", "YulianApartment"]
  224.  
  225. string area = ScreenSelect(screenLines, LeadingText("Choose area"), ["q"], areas)
  226. if (area == "q")
  227. return
  228. end
  229. array rooms = GetAllRooms()
  230. array selectRooms = []
  231. loop room in rooms
  232. if IsPrefixOf(area, room) && IsAllowedRoom(room)
  233. Append(selectRooms, room)
  234. end
  235. end
  236.  
  237. string selectedRoom = selectRooms[0]
  238. if(Count(selectRooms) > 1)
  239. Print("Sorting rooms(" + Count(selectRooms) + ")...")
  240. MergeSortString(selectRooms)
  241. selectedRoom = ScreenSelect(screenLines, LeadingText("Choose room"), [], selectRooms)
  242. end
  243.  
  244. SlurpToRoom(selectedRoom)
  245. end
  246.  
  247. string MakeNicePrefix(string prefix, string str)
  248. return StripPrefix(":::", StripPrefix("____", StripPrefix(prefix, str)))
  249. end
  250.  
  251. void SlurpToRoom(string selectedRoom)
  252. # Wrap with resume as CPUs have tendency to lock up.
  253. MakingSlurpSelection(selectedRoom)
  254.  
  255. number cDisplayLength = 27
  256. ClearText()
  257. Print("Room: " + selectedRoom)
  258. Print("Retrieving items in room...")
  259. array things = GetThingsInRoom(selectedRoom)
  260. array peopleAsKeys = GetPeopleAsKeys()
  261.  
  262. Print("Culling non-connectable items. (" + Count(things) + ")")
  263. array connectablesByPrefix = []
  264. array thingsByPrefix = []
  265. loop thing in things
  266. number thingHash = CreateRoomItemHash(thing)
  267. number storedHashValue = GetStoredRoomItem(selectedRoom, thingHash)
  268. if (storedHashValue == cStoredConnectable)
  269. connectablesByPrefix[Shorten(cDisplayLength, "*" + MakeNicePrefix(selectedRoom, thing))] = thing
  270. else if (storedHashValue == cStoredNotConnectable)
  271. thingsByPrefix[Shorten(cDisplayLength, MakeNicePrefix(selectedRoom, thing))] = thing
  272. else if (storedHashValue != cStoredInvalid)
  273. if (HasIndex(peopleAsKeys, thing) == False && IsDangerous(thing) == False)
  274. ClearText()
  275. Print("Checking item:")
  276. Print(" " + thing)
  277. Print("")
  278. DisconnectAll()
  279.  
  280. # Some items cause the program to crash. Skip them next time if so.
  281. AboutToConnect(selectedRoom, thing, thingHash)
  282.  
  283. var c = Connect(thing)
  284. if (Count(GetConnections()) > 0)
  285. bool hasNameFunc = c.HasFunction("Name") || c.HasFunction("GetName")
  286. if (c.HasFunction("Connect") && hasNameFunc)
  287. connectablesByPrefix[Shorten(cDisplayLength, "*" + MakeNicePrefix(selectedRoom, thing))] = thing
  288. StoreRoomItem(selectedRoom, thingHash, cStoredConnectable)
  289. else if IsIgnorable(thing) == False
  290. thingsByPrefix[Shorten(cDisplayLength, MakeNicePrefix(selectedRoom, thing))] = thing
  291. StoreRoomItem(selectedRoom, thingHash, cStoredNotConnectable)
  292. else
  293. # Store hash so we skip it next time
  294. StoreRoomItem(selectedRoom, thingHash, cStoredInvalid)
  295. end
  296. end
  297.  
  298. # Program didn't crash :)
  299. ClearAboutToConnect()
  300. end
  301. end
  302. end
  303. DisconnectAll()
  304.  
  305. array thingsByPrefixKeys = GetIndexes(thingsByPrefix)
  306. array connectablesByPrefixKeys = GetIndexes(connectablesByPrefix)
  307.  
  308. if Count(thingsByPrefixKeys) > 150
  309. Print("Skipping sort due to too many items! (" + Count(thingsByPrefixKeys)+ ")")
  310. else
  311. Print("Sorting things(" + Count(thingsByPrefixKeys) + ")...")
  312. MergeSortString(thingsByPrefixKeys)
  313. end
  314. MergeSortString(connectablesByPrefixKeys)
  315.  
  316. ArrayAppend(connectablesByPrefixKeys, thingsByPrefixKeys)
  317.  
  318. string selectedPrefix = ScreenSelect(screenLines, LeadingText("Choose thing in " + selectedRoom), ["q"], connectablesByPrefixKeys)
  319. ClearMakingSlurpSelection()
  320.  
  321. if (selectedPrefix == "q")
  322. return
  323. end
  324.  
  325. string selectedThing
  326. if (HasIndex(thingsByPrefix, selectedPrefix))
  327. selectedThing = thingsByPrefix[selectedPrefix]
  328. else
  329. selectedThing = connectablesByPrefix[selectedPrefix]
  330. end
  331.  
  332. DisconnectAll()
  333. var server = Connect(selectedThing)
  334. if server.HasFunction("Connect")
  335. server.Connect(Name())
  336. end
  337. Slurp()
  338. end
  339.  
  340. string ScreenSelect(number height, array niceLines, array extraOptions, array values)
  341. number niceLinesLength = Count(niceLines)
  342. string selection
  343. number currentPage = 0
  344. array pages = PartitionBy((height - niceLinesLength) - 1, values)
  345. number pagesLength = Count(pages)
  346.  
  347. if (pagesLength == 0)
  348. Input("Nothing to select!")
  349. return ""
  350. end
  351.  
  352. loop
  353. bool firstPage = currentPage == 0
  354. bool lastPage = currentPage == pagesLength - 1
  355. ClearText()
  356. loop line in niceLines
  357. Print(line)
  358. end
  359. array byLineNumber = []
  360. var lineNumber = 1
  361. loop line in pages[currentPage]
  362. byLineNumber[lineNumber+""] = line
  363. Print(lineNumber + ": " + line)
  364. lineNumber += 1
  365. end
  366. selection = Input(FormatSelectionText(currentPage, pagesLength, extraOptions))
  367. if (Elem(selection, extraOptions))
  368. return selection
  369. else if (lastPage == True && selection == "")
  370. currentPage = 0
  371. else if ((selection == "" || selection == "n") && lastPage == False)
  372. currentPage += 1
  373. else if (firstPage == False && selection == "p")
  374. currentPage -= 1
  375. else if (HasIndex(byLineNumber, selection))
  376. return byLineNumber[selection]
  377. end
  378. end
  379. end
  380.  
  381. string FormatSelectionText(number currentPage, number pages, array extraOptions)
  382. bool firstPage = currentPage == 0
  383. bool lastPage = currentPage == pages - 1
  384. string pageDetail = "(" + (currentPage+1) + "/" + pages + ")"
  385.  
  386. string ret = ""
  387.  
  388. if (pages == 1)
  389. ret = "Selection"
  390. else if (firstPage)
  391. ret = pageDetail + " #/n"
  392. else if (lastPage)
  393. ret = pageDetail + " #/p"
  394. else
  395. ret = pageDetail + " #/n/p"
  396. end
  397.  
  398. loop item in extraOptions
  399. ret += "/" + item
  400. end
  401.  
  402. return ret + ": "
  403. end
  404.  
  405. bool IsDangerous(string targetC)
  406. string target = ToLowerCase(targetC)
  407. if (Contains(target, "diskette"))
  408. return true
  409. else if (Contains(target, "memory"))
  410. return true
  411. else
  412. return False
  413. end
  414. end
  415.  
  416. bool IsIgnorable(string targetC)
  417. string target = ToLowerCase(targetC)
  418. if (Contains(target, "beer"))
  419. return true
  420. else if (Contains(target, "glass"))
  421. return true
  422. else if (Contains(target, "trash"))
  423. return true
  424. else if (Contains(target, "seat"))
  425. return true
  426. else if (Contains(target, "toilet"))
  427. return true
  428. else if (Contains(target, "cigar"))
  429. return true
  430. else if (Contains(target, "wellspringsoda"))
  431. return true
  432. else
  433. return False
  434. end
  435. end
  436.  
  437. number CreateRoomItemHash(string str)
  438. return Hash(str, 0, 27, 591749)
  439. end
  440.  
  441. # Helper Functions
  442. ##################################################
  443.  
  444. void PartitionBy(number partionSize, array values)
  445. array ret = []
  446. array current = []
  447. number currentSize = 0
  448. loop val in values
  449. currentSize = currentSize + 1
  450. Append(current, val)
  451.  
  452. if(currentSize == partionSize)
  453. Append(ret, current)
  454. current = []
  455. currentSize = 0
  456. end
  457. end
  458.  
  459. # Get last partition if not empty
  460. if(Count(current) > 0)
  461. Append(ret, current)
  462. end
  463.  
  464. return ret
  465. end
  466.  
  467. var ByIndex(array arr, number index)
  468. number count = 0
  469. loop x in arr
  470. if(count == index)
  471. return x
  472. end
  473. count = count + 1
  474. end
  475. end
  476.  
  477. # String Helper Functions
  478. ##################################################
  479.  
  480. bool Contains(string target, string sub)
  481. number targetLen = Count(target)
  482. number subLen = Count(sub)
  483. if (targetLen < subLen)
  484. return False
  485. end
  486.  
  487. number endPos = targetLen - subLen
  488. loop pos from 0 to endPos
  489. loop subPos from 0 to (subLen - 1)
  490. if target[pos+subPos] != sub[subPos]
  491. break
  492. end
  493. if subPos == (subLen - 1)
  494. return True
  495. end
  496. end
  497. end
  498. return False
  499. end
  500.  
  501. string Shorten(number limit, string str)
  502. string ret
  503. number count = 0
  504. loop c in str
  505. if count >= limit
  506. break
  507. end
  508. ret += c
  509. count += 1
  510. end
  511. return ret
  512. end
  513.  
  514. string StripPrefix(string prefix, string str)
  515. var pos = 0
  516. loop c in prefix
  517. if c != str[pos]
  518. break
  519. end
  520. pos += 1
  521. end
  522. string ret = ""
  523. loop i in Range(pos, Count(str) - 1)
  524. ret += str[i]
  525. end
  526. return ret
  527. end
  528.  
  529. number CompareString(string a_, string b_)
  530. string a = ToLowerCase(a_)
  531. string b = ToLowerCase(b_)
  532. var aLen = Count(a)
  533. var bLen = Count(b)
  534.  
  535. var pos = 0
  536. loop
  537. if pos == aLen && pos == bLen
  538. return 0
  539. else if pos == aLen
  540. return -1
  541. else if pos == bLen
  542. return 1
  543. else
  544. var diff = CharToInt(a[pos]) - CharToInt(b[pos])
  545. if diff != 0
  546. return diff
  547. else
  548. pos += 1
  549. end
  550. end
  551. end
  552. end
  553.  
  554. bool IsUpperCase(var c)
  555. return CharToInt(c) >= -32 && CharToInt(c) <= -7
  556. end
  557.  
  558. string ToLowerCase(var text)
  559. string res = ""
  560. loop c in text
  561. if IsUpperCase(c)
  562. res += IntToChar(CharToInt(c) + 32)
  563. else
  564. res += c
  565. end
  566. end
  567. return res
  568. end
  569.  
  570. string DupString(number times, string str)
  571. string ret = ""
  572. loop i from 1 to times
  573. ret = ret + str
  574. end
  575. return ret
  576. end
  577.  
  578. array LeadingText(string title)
  579. return [title, DupString(Count(title), "-")]
  580. end
  581.  
  582. number Longest(array arr)
  583. var count = 0
  584. loop str in arr
  585. var strCount = Count(str)
  586. if strCount > count
  587. count = strCount
  588. end
  589. end
  590. return count
  591. end
  592.  
  593. bool IsPrefixOf(string prefix, string str)
  594. var prefixSize = Count(prefix)
  595. var strSize = Count(str)
  596. if strSize < prefixSize
  597. return False
  598. end
  599. var i = 0
  600. loop c in prefix
  601. if c != str[i]
  602. return False
  603. end
  604. i += 1
  605. end
  606. return True
  607. end
  608.  
  609. bool IsSuffixOf(string suffix, string str)
  610. var suffixSize = Count(suffix)
  611. var strSize = Count(str)
  612. if strSize < suffixSize
  613. return False
  614. end
  615. var difference = strSize - suffixSize
  616. var i = 0
  617. loop c in suffix
  618. if c != str[i+difference]
  619. return False
  620. end
  621. i += 1
  622. end
  623. return True
  624. end
  625.  
  626. array ParsePosition(string position)
  627. number rule = 1
  628. string working = ""
  629. string room = "Unknown"
  630. number x = -1
  631. number y = -1
  632.  
  633. loop c in position
  634. if rule == 1
  635. if c == ":"
  636. rule = 2
  637. end
  638. else if rule == 2
  639. rule = 3
  640. else if rule == 3
  641. if c == " " or c == ","
  642. rule = 4
  643. room = working
  644. working = ""
  645. else
  646. working = working + c
  647. end
  648. else if rule == 4
  649. if c == "("
  650. rule = 5
  651. end
  652. else if rule == 5
  653. if c == ","
  654. rule = 6
  655. x = working
  656. working = ""
  657. else
  658. working = working + c
  659. end
  660. else if rule == 6
  661. if c == ")"
  662. rule = 7
  663. x = working
  664. working = ""
  665. else
  666. working = working + c
  667. end
  668. end
  669. end
  670. return [room,x,y]
  671. end
  672.  
  673. # To prevent conversion to float maintain a*p < 2^31 - 50
  674. number Hash(string str, number initialVal, number a, number p)
  675. number h = initialVal
  676. number fix = 0 - CharToInt("1")
  677. loop c in str
  678. h = Mod((h*a) + CharToInt(c) + fix, p)
  679. end
  680. return h
  681. end
  682.  
  683. # Function to test if values for a hash are perfect for the array
  684. void TestHash(array strs, number initialVal, number n, number p)
  685. array dups = []
  686. array hashSet = []
  687. number count = 0
  688. loop str in strs
  689. if (HasIndex(dups, str) == False)
  690. dups[str] = 1
  691. Print("Hashing: " + str)
  692. var hash = Hash(str, initialVal, n, p)
  693. Print("Got hash: " + hash)
  694. if (HasIndex(hashSet, hash))
  695. Print("Failure!")
  696. Print(count + " of " + Count(strs))
  697. return
  698. end
  699. hashSet[hash] = 1
  700. count += 1
  701. end
  702. end
  703. Print("Success!")
  704. end
  705.  
  706. # Array Helper Functions
  707. ##################################################
  708.  
  709. void ArrayAppend(array target, array to_append)
  710. loop val in to_append
  711. Append(target, val)
  712. end
  713. end
  714.  
  715. bool Elem(var item, array arr)
  716. loop val in arr
  717. if val == item
  718. return True
  719. end
  720. end
  721. return False
  722. end
  723.  
  724. # Sort Functions
  725. ##################################################
  726.  
  727. void MergeSortString(array arr)
  728. array work = []
  729. if Count(arr) > 0
  730. TopDownSplitMergeString(arr, 0, Count(arr), work)
  731. end
  732. end
  733.  
  734. void TopDownSplitMergeString(array a, number iBegin, number iEnd, array b)
  735. if(iEnd - iBegin < 2)
  736. return
  737. end
  738.  
  739. number iMiddle = Int((iEnd + iBegin) / 2)
  740. TopDownSplitMergeString(a, iBegin, iMiddle, b)
  741. TopDownSplitMergeString(a, iMiddle, iEnd, b)
  742. TopDownMergeString(a, iBegin, iMiddle, iEnd, b)
  743. CopyArray(b, iBegin, iEnd, a)
  744. end
  745.  
  746. void TopDownMergeString(array a, number iBegin, number iMiddle, number iEnd, array b)
  747. var i0 = iBegin
  748. var i1 = iMiddle
  749.  
  750. loop j from iBegin to (iEnd - 1)
  751. # Why split this up? "if" parameters are broken when this was written
  752. var postCheck = i1 >= iEnd;
  753. if postCheck == False
  754. postCheck = CompareString(a[i0], a[i1]) < 1
  755. end
  756. if (i0 < iMiddle && postCheck)
  757. b[j] = a[i0]
  758. i0 += 1
  759. else
  760. b[j] = a[i1]
  761. i1 += 1
  762. end
  763. end
  764. end
  765.  
  766. void CopyArray(array b, number iBegin, number iEnd, array a)
  767. loop k in Range(iBegin, iEnd - 1)
  768. a[k] = b[k]
  769. end
  770. end
  771.  
  772. # Memory Functions
  773. ##################################################
  774.  
  775. bool HasMemoryArray(string key)
  776. return HasMemory(gArrayPrefix + key)
  777. end
  778.  
  779. void SaveMemoryArray(string key, array arr)
  780. string serialized = ""
  781. var i = 0
  782. loop val in arr
  783. if (i == 0)
  784. serialized = val
  785. else
  786. serialized = serialized + "|" + val
  787. end
  788. i += 1
  789. end
  790.  
  791. return SaveMemory(gArrayPrefix + key, serialized)
  792. end
  793.  
  794. array LoadMemoryArray(string key)
  795. string serialized = LoadMemory(gArrayPrefix + key)
  796.  
  797. array ret = []
  798. string current = ""
  799.  
  800. loop c in serialized
  801. if c == "|"
  802. Append(ret, current)
  803. current = ""
  804. else
  805. current = current + c
  806. end
  807. end
  808.  
  809. # Get last
  810. Append(ret, current)
  811.  
  812. return ret
  813. end
  814.  
  815. string StoredRoomItemsMemoryKey(string room)
  816. return memoryKeyInvalidHashes + "_" + room
  817. end
  818.  
  819. array GetStoredRoomItems(string room)
  820. if (HasIndex(gStoredHashKeys, room) == False)
  821. gStoredHashKeys[room] = []
  822. array currentRoom = gStoredHashKeys[room]
  823. string memoryKey = StoredRoomItemsMemoryKey(room)
  824. if HasMemory(memoryKey)
  825. string serialized = LoadMemory(memoryKey)
  826. string tmp = ""
  827. number currentHash
  828. loop c in serialized
  829. if (c == "|")
  830. currentHash = tmp
  831. tmp = ""
  832. else if (c == "&")
  833. number currentValue = tmp
  834. tmp = ""
  835. currentRoom[currentHash] = currentValue
  836. else
  837. tmp += c
  838. end
  839. end
  840. end
  841. end
  842. return gStoredHashKeys[room]
  843. end
  844.  
  845. void StoreRoomItem(string room, number hash_, number value)
  846. number hash = Int(hash_)
  847. GetStoredRoomItems(room)
  848. array currentRoom = gStoredHashKeys[room]
  849. currentRoom[hash] = value
  850.  
  851. string serialized = ""
  852. loop h in GetIndexes(currentRoom)
  853. serialized += (h + "|" + currentRoom[h] + "&")
  854. end
  855. SaveMemory(StoredRoomItemsMemoryKey(room), serialized)
  856. end
  857.  
  858. # For use with CreateRoomItemHash(string str)
  859. number GetStoredRoomItem(string room, number hash_)
  860. number hash = Int(hash_)
  861. array storedHashes = GetStoredRoomItems(room)
  862. if (HasIndex(storedHashes, hash) == False)
  863. return cUnStored
  864. else
  865. return storedHashes[hash]
  866. end
  867. end
  868.  
  869. void AboutToConnect(string room, string item, number hash)
  870. SaveMemory(memoryKeyAboutToConnect, room + "|" + item + "|" + hash)
  871. end
  872.  
  873. void ClearAboutToConnect()
  874. EraseMemory(memoryKeyAboutToConnect)
  875. end
  876.  
  877. bool HasAboutToConnect()
  878. return HasMemory(memoryKeyAboutToConnect)
  879. end
  880.  
  881. array GetAboutToConnect()
  882. string serialized = LoadMemory(memoryKeyAboutToConnect)
  883.  
  884. string room = ""
  885. string item = ""
  886. number hash = 0
  887.  
  888. string tmp = ""
  889.  
  890. number state = 0
  891. loop c in serialized
  892. if (c == "|")
  893. if (state == 0)
  894. room = tmp
  895. else if (state == 1)
  896. item = tmp
  897. end
  898. tmp = ""
  899. state += 1
  900. else
  901. tmp += c
  902. end
  903. end
  904. hash = tmp
  905.  
  906. return [room, item, hash]
  907. end
  908.  
  909. void MakingSlurpSelection(string room)
  910. SaveMemory(memoryKeyMakingSlurpSelection, room)
  911. end
  912.  
  913. void ClearMakingSlurpSelection()
  914. EraseMemory(memoryKeyMakingSlurpSelection)
  915. end
  916.  
  917. bool WasMakingSlurpSelection()
  918. return HasMemory(memoryKeyMakingSlurpSelection)
  919. end
  920.  
  921. array SlurpSelectionRoom()
  922. return LoadMemory(memoryKeyMakingSlurpSelection)
  923. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement