Advertisement
gerkrt

Locations system

Sep 14th, 2011
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 11.75 KB | None | 0 0
  1.  
  2. #==============================================================================
  3. # Locations system
  4. # By gerkrt/gerrtunk
  5. # Version: 2.2
  6. # License: MIT, credits
  7. # Date: 24/01/2011
  8. # IMPORTANT NOTE: to acces the more actualitzed or corrected version of this
  9. # script check here: http://usuarios.multimania.es/kisap/english_list.html
  10. #==============================================================================
  11.  
  12. =begin
  13.  
  14. ------INTRODUCTION------
  15.  
  16. This script adds a entry in the main menu(removing steps window)that shows
  17. your actual place. The interesting thing about it is that it lets configure
  18. about anything with flexibility and new features.
  19.  
  20. Creating locations:
  21.  
  22. -Using the map tree system. You only have to write the name of the parent map
  23. and all the others under it take his description
  24.  
  25. -By map name
  26.  
  27. -By maps groups that share a description
  28.  
  29. Sublocations:
  30.  
  31. -By map name
  32.  
  33. -By maps groups that share a sublocation description
  34.  
  35. Sublocations allow you to add a specification of the actual area,
  36. so: location "Aoha forest" sublocation "Old tree", for example.
  37.  
  38. Also you can combine any of these system or options without a problem.
  39.  
  40.  
  41. -------CONFIGURING LOCATIONS---------
  42.  
  43. Location_type : This variable sets the type of locations:
  44.   Location_type = :map_list           -> use map list
  45.   Location_type = :map_name           -> use map name
  46.   Location_type = :map_tree           -> use map tree
  47.  
  48. -By map name: It will just write the actual map name.  
  49.  
  50. -By map list: Using this you create a group of maps that share a location
  51. description.
  52.    
  53.   Locations_map_id = [
  54.  
  55.     [[1,2,3], 'Ahoha forest'],    # Maps 1,2,3 share Ahoha forest description
  56.     [[4,5,6], 'Sphynx']
  57.  
  58.   ]
  59.  
  60.   Just add lines like this: [[map_id1, map_id2], 'Description'],
  61.  
  62.  
  63. -By map tree: With this you only have to define a parent map and write its name in
  64. the descriptions. All the maps will have the description, including the parent map.
  65.  
  66. The map tree is show under the tileset tool. If you doubleclick to - or + you will
  67. see that the maps are shown in groups that depend in parent maps.
  68.  
  69. Note: I recomend having the maps having the maps ordered and directly relationed with
  70. its parent map to have optimal performance.
  71.  
  72. Use example:
  73.  
  74. Mapamundi - Parent of all
  75.   Forest - Parent of maps 3-7
  76.     Mapa3
  77.     Mapa4
  78.     Mapa5 - Parent of 6,7
  79.       Mapa6
  80.       Mapa7
  81.      
  82.   Pantano del Wep
  83.     Mapa9
  84.    
  85. Configuration it:
  86.  
  87.   Locations_map_tree = {
  88.  
  89.    'Forest' => 'Ahoha forest',
  90.    'Prologue' => 'Sphynx'   # All the maps under the map called Prologue have
  91.    # sphynx description
  92.    
  93.   }
  94.  
  95.   To add new locations add these lines:
  96.   'Basename map name' => 'Description',
  97.  
  98.  
  99. -------CONFIGURING SUBLOCATIONS---------
  100.  
  101. Show_sublocations : These configurates sublocations
  102.  
  103.  
  104. Show_sublocations = :inactive          ---> makes them inactive
  105. Show_sublocations = :map_name         ---> use map name
  106. Show_sublocations = :codes          ---> makes them use map codes
  107.  
  108.  
  109. inactive: if they are inactive you are going to see in the first line the
  110. sublocations word
  111.  
  112. map name: this wall it will simply write the actual map name as a sublocation
  113. description
  114.  
  115. codes: this works like the locations map list, but for sublocations:
  116.  
  117.   Sublocations_codes = [
  118.  
  119.     [[1,2], 'Santuary'],
  120.     [[4,5,6], 'Old tree']
  121.  
  122.   ]
  123.   Just add lines like this: [[map_id1, map_id2], 'Description'],
  124.  
  125.  
  126. ------OTHER THINGS------------
  127.  
  128. Unknown_location_text: This is for maps that dont have a description.
  129. Unknown_sublocation_text: The same but for sublocations.
  130. Sublocations_text : Here you can write a prefix for all sublocations
  131. Locations_text : Here you write the describing word of the locations
  132.  
  133. =end
  134.  
  135.  
  136. module Wep
  137.   Unknown_location_text = '?????'
  138.   Unknown_sublocation_text = 'Unknown'
  139.   Location_type = :map_list
  140.  
  141.   Show_sublocations = :inactive       # :inactive, :map_name, :codes
  142.  
  143.   Sublocations_text = ''
  144.   Locations_text = 'Location'
  145.    
  146.   Locations_map_id = [
  147.  
  148.     [[1,2,3], 'Ahoha forest'],
  149.     [[4,5,6], 'Sphynx']
  150.  
  151.   ]
  152.    
  153.   Sublocations_codes = [
  154.  
  155.     [[1,2], 'Santuary'],
  156.     [[4,5,6], 'Old tree']
  157.  
  158.   ]
  159.  
  160.   Locations_map_tree = {
  161.  
  162.    'Forest' => 'Ahoha forest',
  163.    'Prologue' => 'Sphynx'
  164.    
  165.   }
  166.  
  167. end
  168.  
  169.  
  170. #==============================================================================
  171. # ** Scene_Menu
  172. #------------------------------------------------------------------------------
  173. #  This class performs menu screen processing.
  174. #==============================================================================
  175.  
  176. class Scene_Menu
  177.   #--------------------------------------------------------------------------
  178.   # * Object Initialization
  179.   #     menu_index : command cursor's initial position
  180.   #--------------------------------------------------------------------------
  181.   def initialize(menu_index = 0)
  182.     @menu_index = menu_index
  183.   end
  184.   #--------------------------------------------------------------------------
  185.   # * Main Processing
  186.   #--------------------------------------------------------------------------
  187.   def main
  188.     # Make command window
  189.     s1 = $data_system.words.item
  190.     s2 = $data_system.words.skill
  191.     s3 = $data_system.words.equip
  192.     s4 = "Estado"
  193.     s5 = "Guardar"
  194.     s6 = "Salir"
  195.     @command_window = Window_Command.new(160, [s1, s2, s3, s4, s5, s6])
  196.     @command_window.index = @menu_index
  197.     # If number of party members is 0
  198.     if $game_party.actors.size == 0
  199.       # Disable items, skills, equipment, and status
  200.       @command_window.disable_item(0)
  201.       @command_window.disable_item(1)
  202.       @command_window.disable_item(2)
  203.       @command_window.disable_item(3)
  204.     end
  205.     # If save is forbidden
  206.     if $game_system.save_disabled
  207.       # Disable save
  208.       @command_window.disable_item(4)
  209.     end
  210.     # Make play time window
  211.     @playtime_window = Window_PlayTime.new
  212.     @playtime_window.x = 0
  213.     @playtime_window.y = 224
  214.     # Make steps window
  215.     @location_window = Window_Location.new
  216.     @location_window.x = 0
  217.     @location_window.y = 320
  218.     # Make gold window
  219.     @gold_window = Window_Gold.new
  220.     @gold_window.x = 0
  221.     @gold_window.y = 416
  222.     # Make status window
  223.     @status_window = Window_MenuStatus.new
  224.     @status_window.x = 160
  225.     @status_window.y = 0
  226.     # Execute transition
  227.     Graphics.transition
  228.     # Main loop
  229.     loop do
  230.       # Update game screen
  231.       Graphics.update
  232.       # Update input information
  233.       Input.update
  234.       # Frame update
  235.       update
  236.       # Abort loop if screen is changed
  237.       if $scene != self
  238.         break
  239.       end
  240.     end
  241.     # Prepare for transition
  242.     Graphics.freeze
  243.     # Dispose of windows
  244.     @command_window.dispose
  245.     @playtime_window.dispose
  246.     @location_window.dispose
  247.     @gold_window.dispose
  248.     @status_window.dispose
  249.   end
  250.   #--------------------------------------------------------------------------
  251.   # * Frame Update
  252.   #--------------------------------------------------------------------------
  253.   def update
  254.     # Update windows
  255.     @command_window.update
  256.     @playtime_window.update
  257.     @location_window.update
  258.     @gold_window.update
  259.     @status_window.update
  260.     # If command window is active: call update_command
  261.     if @command_window.active
  262.       update_command
  263.       return
  264.     end
  265.     # If status window is active: call update_status
  266.     if @status_window.active
  267.       update_status
  268.       return
  269.     end
  270.   end
  271. end
  272.  
  273. #==============================================================================
  274. # ** Window_Location
  275. #------------------------------------------------------------------------------
  276. #  Show the places you visit
  277. #==============================================================================
  278.  
  279. class Window_Location < Window_Base
  280.   #--------------------------------------------------------------------------
  281.   # * Object Initialization
  282.   #--------------------------------------------------------------------------
  283.   def initialize
  284.     super(0, 0, 160, 96)
  285.     self.contents = Bitmap.new(width - 32, height - 32)
  286.     refresh
  287.   end
  288.   #--------------------------------------------------------------------------
  289.   # * Refresh
  290.   #--------------------------------------------------------------------------
  291.   def refresh
  292.    
  293.     # Set basic text
  294.     text = Wep::Unknown_location_text
  295.  
  296.     # If uses the complete hash
  297.     if Wep::Location_type == :map_list
  298.       # Extract text from locations
  299.       for location in Wep::Locations_map_id
  300.         if location[0].include? $game_map.map_id
  301.           text = location[1]
  302.           break
  303.         end
  304.       end
  305.    
  306.     # If uses the map name
  307.     elsif Wep::Location_type == :map_name
  308.       # Load mapinfos for map name
  309.       mapinfos = load_data("Data/MapInfos.rxdata")    
  310.       # Make text
  311.       text = mapinfos[$game_map.map_id].name
  312.  
  313.     # If it uses the map tree methods
  314.     else
  315.      
  316.       # Iteraves over all base maps searching for tree of the
  317.       # actual map.
  318.       for locname, locdescription in Wep::Locations_map_tree
  319.          # Search for actual map in a defined map tree
  320.          if $game_party.tree_includes_map? (locname)
  321.            text = locdescription
  322.            break
  323.          end
  324.       end
  325.  
  326.     end
  327.    
  328.     # Draw text
  329.     self.contents.clear
  330.    
  331.     # If sub locations use map names, read mapinfos
  332.     if Wep::Show_sublocations == :map_names
  333.         # Load mapinfos for map name
  334.         mapinfos = load_data("Data/MapInfos.rxdata")    
  335.         # Make text
  336.         subtext = Wep::Sublocations_text + mapinfos[$game_map.map_id].name
  337.         # Draw using classic style
  338.         self.contents.font.color = system_color
  339.         self.contents.draw_text(4, -5, 120, 32, text)
  340.         self.contents.font.color = normal_color
  341.         self.contents.draw_text(4, 32, 120, 32, subtext, 2)
  342.        
  343.     # If sub locations use map codes, iterate sublocations
  344.     elsif Wep::Show_sublocations == :codes
  345.     subtext = Wep::Unknown_sublocation_text
  346.       # Extract text from sublocations
  347.       for sublocation in Wep::Sublocations_codes
  348.         if sublocation[0].include? $game_map.map_id
  349.           subtext = Wep::Sublocations_text + sublocation[1]
  350.           break
  351.         end
  352.       end
  353.       # Draw using classic style
  354.       self.contents.font.color = system_color
  355.       self.contents.draw_text(4, -5, 120, 32, text)
  356.       self.contents.font.color = normal_color
  357.       self.contents.draw_text(4, 32, 120, 32, subtext, 2)
  358.      
  359.     # If not, draw using Locations word    
  360.     else
  361.       self.contents.font.color = system_color
  362.       self.contents.draw_text(4, -5, 120, 32, Wep::Locations_text)
  363.       self.contents.font.color = normal_color
  364.       self.contents.draw_text(4, 32, 120, 32, text, 2)
  365.      
  366.     end
  367.  
  368.   end
  369. end
  370.  
  371. #==============================================================================
  372. # ** Game_Party
  373. #------------------------------------------------------------------------------
  374. # Added method tree includes map
  375. #==============================================================================
  376.  
  377. class Game_Party
  378.   #--------------------------------------------------------------------------
  379.   # * Tree includes map?
  380.   #  look for the name given in actual map tree
  381.   #--------------------------------------------------------------------------
  382.   def tree_includes_map? (name)
  383.     # Load mapinfos for map name
  384.     mapinfos = load_data("Data/MapInfos.rxdata")    
  385.     # If his name is the name searched
  386.     if mapinfos[$game_map.map_id].name == name
  387.         return true
  388.     end
  389.  
  390.     map = $game_map.map_id
  391.    
  392.     # Iterate all parents maps
  393.     while mapinfos[map].parent_id != 0
  394.         if mapinfos[mapinfos[map].parent_id].name == name
  395.           return true
  396.         else
  397.           map = mapinfos[map].parent_id
  398.         end
  399.     end
  400.   end
  401. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement