Advertisement
Zeriab

[RGSS][Extract] Check map transfers

Jan 15th, 2017
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.26 KB | None | 0 0
  1. #__END__
  2. ##
  3. # This script was made under the assumptions for the map transfers
  4. # - No scripted map transfers
  5. # - Only exists in a map event (no common events)
  6. # - Direction appointments only
  7. #
  8. # Do not expect an accurate picture if these properties are not fulfilled
  9. #
  10. ##
  11. # Copyright (c) 2017 Zeriab
  12. #
  13. # This software is provided 'as-is', without any express or implied
  14. # warranty. In no event will the authors be held liable for any damages
  15. # arising from the use of this software.
  16. #
  17. # Permission is granted to anyone to use this software for any purpose,
  18. # including commercial applications, and to alter it and redistribute it
  19. # freely, subject to the following restrictions:
  20. #
  21. # 1. The origin of this software must not be misrepresented; you must not
  22. #    claim that you wrote the original software. If you use this software
  23. #    in a product, an acknowledgement in the product documentation would be
  24. #    appreciated but is not required.
  25. # 2. Altered source versions must be plainly marked as such, and must not be
  26. #    misrepresented as being the original software.
  27. # 3. This notice may not be removed or altered from any source distribution.
  28. #
  29.  
  30. def update_sprite
  31.   if @sprite.nil?
  32.     @sprite = Sprite.new
  33.     @sprite.bitmap = Bitmap.new(640, 120)
  34.   end
  35.   current = $current
  36.   unless current == $last
  37.     $last = current
  38.     @sprite.bitmap.clear
  39.     unless current.nil?
  40.       @sprite.bitmap.draw_text(8,4,600,32,$last.map)
  41.       @sprite.bitmap.draw_text(8,40,600,32,$last.event)
  42.     end
  43.   end
  44. end
  45.  
  46. ##
  47. # A separate thread that will run and make sure the Graphics.update is updated
  48. # every now and then.
  49. #
  50. Thread.new {
  51.   loop do
  52.     # Lets the thread sleep for a while to minimize CPU usage
  53.     sleep 0.1
  54.     # Update the sprite
  55.     update_sprite
  56.     # Update the graphics
  57.     Graphics.update
  58.   end
  59. }
  60.  
  61. Current = Struct.new(:map, :event)
  62. $current = nil
  63.  
  64. Map = Struct.new(:name, :map_id, :events)
  65. Event = Struct.new(:name, :event_id, :pages)
  66. Page = Struct.new(:number, :list)
  67. ListElement = Struct.new(:message, :type)
  68.  
  69. ######
  70. ######
  71.  
  72. class Map
  73.   def write_to_stream(io)
  74.     io.print "\r\n########################################"
  75.     io.print "\r\n# Map #{map_id} ~ #{name}  (#{events.size} events)\r\n"
  76.     io.print "########################################\r\n"
  77.     for event in events
  78.       event.write_to_stream(io)
  79.     end
  80.   end
  81. end
  82.  
  83. class Event
  84.   def write_to_stream(io)
  85.     io.print "\r\n-= Event #{event_id} - #{name} =-\r\n"
  86.     for page in pages
  87.       page.write_to_stream(io)
  88.     end
  89.   end
  90. end
  91.  
  92. class Page
  93.   def write_to_stream(io)
  94.     io.print "Page #{number}:\r\n"
  95.     for element in list
  96.       element.write_to_stream(io)
  97.       io.print "\r\n"
  98.     end
  99.   end
  100. end
  101.  
  102. class ListElement
  103.   def write_to_stream(io)
  104.     io.print message
  105.   end
  106. end
  107.  
  108. $map = Hash.new {|h, k| h[k] = []}
  109. ######
  110. def process_list(list)
  111.   # Go through the event commands in the list
  112.   rlist = [] # resulting list
  113.   command_index = 0
  114.   while command_index < list.size
  115.     command = list[command_index]
  116.     if command.code == 201 && command.parameters[0] != nil
  117.       param = command.parameters
  118.       if $origin.nil? || $origin == 0
  119.         p 'Only supports transfers in map events atm.'
  120.         exit
  121.       end
  122.       $map[$origin] << param[1]
  123.       message = "Transfer to map #{param[1]} on (#{param[2]}, #{param[3]})"
  124.       if param[0] != 0
  125.         $variable_based = true
  126.         message = "Variable based transfer to map var(#{param[1]}) on (var(#{param[2]}), var(#{param[3]}))"
  127.       end
  128.       rlist << ListElement.new(message, 'text')
  129.     end
  130.     command_index += 1
  131.   end
  132.   return rlist
  133. end
  134. ######
  135.  
  136. class CommonEvent < Struct.new(:name, :event_id, :list)
  137.   def write_to_stream(io)
  138.     io.print "\r\n-= Common Event #{event_id} - #{name} =-\r\n"
  139.     for element in list
  140.       element.write_to_stream(io)
  141.       io.print "\r\n"
  142.     end
  143.   end
  144. end
  145.  
  146. common_events = load_data('Data/CommonEvents.rxdata')
  147. ces = []
  148. for ce in common_events.compact
  149.   # Look at which event is currently processing
  150.   cur = Current.new("Processing common events...",
  151.                     "Common event #{ce.id} - #{ce.name}")
  152.   $current = cur
  153.   # Process the list
  154.   $origin = 0
  155.   list = process_list(ce.list)
  156.   unless list.empty?
  157.     # Create struct
  158.     current_ce = CommonEvent.new(ce.name, ce.id, list)
  159.     ces << current_ce
  160.   end
  161. end
  162.  
  163. ######
  164. ######
  165.  
  166. class Troop < Event
  167.   def write_to_stream(io)
  168.     io.print "\r\n-= Troop #{event_id} - #{name} =-\r\n"
  169.     for page in pages
  170.       page.write_to_stream(io)
  171.     end
  172.   end
  173. end
  174.  
  175. troops = load_data('Data\Troops.rxdata')
  176.  
  177. battle_events = []
  178. for event in troops.compact
  179.   # Look at which event is currently processing
  180.   cur = Current.new("Processing battle events...",
  181.                     "Troop " + event.id.to_s + " - " + event.name)
  182.   $current = cur
  183.   # Create the event struct
  184.   current_event = Troop.new(event.name, event.id, [])
  185.   # Create pages
  186.   event.pages.each_with_index do |page, page_index|
  187.     list = process_list(page.list)
  188.     unless list.empty?
  189.       current_page = Page.new(page_index+1, list)
  190.       current_event.pages << current_page
  191.     end
  192.   end
  193.   # Let's disregard useless events
  194.   battle_events << current_event unless current_event.pages.empty?
  195. end
  196.  
  197. ######
  198. ######
  199.  
  200. infos = load_data('Data\MapInfos.rxdata')
  201.  
  202. p infos[235]
  203. exit
  204.  
  205. map_map = {}
  206. maps = []
  207. for map_id, map_info in infos.sort
  208.   map_map[map_id] = map_info
  209.   $origin = map_id
  210.   # Create map struct
  211.   current_map = Map.new(map_info.name, map_id, [])
  212.   maps << current_map
  213.   map = load_data(sprintf("Data/Map%03d.rxdata", map_id))
  214.   # Create event structs
  215.   for event_id, event in map.events.sort
  216.     # Look at which event is currently processing
  217.     cur = Current.new("Map " + map_id.to_s + " - " + map_info.name,
  218.                       "Event " + event_id.to_s + " - " + event.name)
  219.     $current = cur
  220.     # Create the event struct
  221.     current_event = Event.new(event.name, event_id, [])
  222.     # Create pages
  223.     event.pages.each_with_index do |page, page_index|
  224.       list = process_list(page.list)
  225.       unless list.empty?
  226.         current_page = Page.new(page_index+1, list)
  227.         # Let's disregard useless pages
  228.         current_event.pages << current_page
  229.       end
  230.     end
  231.     # Let's disregard useless events
  232.     current_map.events << current_event unless current_event.pages.empty?
  233.   end
  234. end
  235.  
  236. # Update status info
  237. cur = Current.new("All maps have been processed",
  238.                   "Writing to a text file")
  239. $current = cur
  240.  
  241. File.open('Transfers_Map.txt', 'wb') {|f|
  242.   f.print "THIS FILE CONTAINS THE DIALOGUE EXTRACTED FROM THE MAPS\r\n\r\n"
  243.   for map in maps
  244.     map.write_to_stream(f)
  245.   end
  246. }
  247.  
  248. File.open('Transfers_Common.txt', 'wb') {|f|
  249.   f.print "THIS FILE CONTAINS THE DIALOGUE EXTRACTED FROM THE COMMON EVENTS\r\n\r\n"
  250.   for ce in ces
  251.     ce.write_to_stream(f)
  252.   end
  253. }
  254.  
  255. File.open('Transfers_Battle.txt', 'wb') {|f|
  256.   f.print "THIS FILE CONTAINS THE DIALOGUE EXTRACTED FROM THE BATTLE EVENTS\r\n\r\n"
  257.   for be in battle_events
  258.     be.write_to_stream(f)
  259.   end
  260. }
  261.  
  262.  
  263. $data_system = load_data("Data/System.rxdata")
  264. start_map_id = $data_system.start_map_id
  265. marked = {}
  266. marked[start_map_id] = true
  267. pending = [start_map_id]
  268. until pending.empty?
  269.   map_id = pending.pop
  270.   for new_id in $map[map_id]
  271.     unless marked[new_id]
  272.       marked[new_id] = true
  273.       pending << new_id
  274.     end
  275.   end
  276. end
  277.  
  278.  
  279. reachable = (marked.keys).sort
  280. unreachable = ($map.keys - marked.keys).sort
  281. not_editable = (marked.keys - $map.keys).sort
  282.  
  283. File.open('Transfers.txt', 'wb') {|f|
  284.   f.print "THIS FILE CONTAINS INFORMATION ABOUT REACHABLE MAPS THROUGH TRANSFERS\r\n\r\n"
  285.  
  286.   f.print "Reachable through map transfer events (#{reachable.size} maps)\r\n"
  287.   for map_id in reachable
  288.     f.print "Map " + map_id.to_s + " - " + map_map[map_id].name + "\r\n"
  289.   end
  290.  
  291.   f.print "\r\nUnreachable through map transfer events (#{unreachable.size} maps)\r\n"
  292.   for map_id in unreachable
  293.     f.print "Map " + map_id.to_s + " - " + map_map[map_id].name + "\r\n"
  294.   end
  295.  
  296.   f.print "\r\Not editable in the map editor yet reachable through map transfer events (#{not_editable.size} maps)\r\n"
  297.   for map_id in not_editable
  298.     f.print "Map " + map_id.to_s + " - " + map_map[map_id].name + "\r\n"
  299.   end
  300. }
  301.  
  302. exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement