Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Teleport to event (Debugging purposes)

Hey guys, as some of you may know, Dungeon Crawler has random maps. This makes an event system I created somewhat difficult to test. What I need is a script that teleports me to the tile next to an event. This event will be decided by a comment in the event itself, preferably just "tele". Specific tile not need.

To sum it up:
I need a script that will teleport me the tile next to an event specified with "tele", or something similar, in a comment in the event.

Thanks in advance.
 
So.. you need it to look through all the events and find the one with the name: "tele" and port you to it? Which side of it? Should it matter, or should we actually check the surrounding tiles for passability?

This should do the trick.

Code:
 

class Game_Event < Game_Character

  def name

    return @event.name

  end

end

class Interpreter

  def transfer_to_tele_event

    for event in $game_map.events.values

      if event.name.include?("tele")

        x,y = event.x, event.y

        

        #check below

        if $game_map.passable?(x,y+1,0)

          $game_player.moveto(x,y+1)

          return true

        end

        #check right

        if $game_map.passable?(x+1, y,0)

          $game_player.moveto(x+1,y)

          return true

        end

        #check left

        if $game_map.passable?(x-1, y,0)

          $game_player.moveto(x-1,y)

          return true

        end

        #check above

        if $game_map.passable?(x, y-1,0)

          $game_player.moveto(x, y-1)

          return true

        end

      end

    end

    return false

  end

end 
 
You can use it as a call script. Just open any event, then type in "transfer_to_tele_event" in the call script box and BAM! you will be teleported to the current maps tele event. (first one it finds)
 
Thanks gubid, script works like a charm. One last thing, is it possible to extract just the teleport to nearest passable tile part? I only ask as during testing of the event the player sometimes spawns on an impassable tile. Having a button that puts the player on the nearest passable tile should be an adequate fix.

Thanks in advance.
 
Put the player on the nearest tile in which is passable from their current location? or what?

If you have the x,y of the position you want them to go to , then you can use what I did in order to determine the closet place. This is the code I used. $game_map.passable?(x,y,0) does the check to determine if it is or not.

Code:
 

         #check below

         if $game_map.passable?(x,y+1,0)

           $game_player.moveto(x,y+1)

           return true

         end

         #check right

         if $game_map.passable?(x+1, y,0)

           $game_player.moveto(x+1,y)

           return true

         end

         #check left

         if $game_map.passable?(x-1, y,0)

           $game_player.moveto(x-1,y)

           return true

         end

         #check above

         if $game_map.passable?(x, y-1,0)

           $game_player.moveto(x, y-1)

           return true

         end

 
 
I need the closest passable tile from the players x,y location.

That may not make sense so I shall rephrase:
The x,y for where I want the player to go will be the x,y cords of the closest passable tile compared to the players current x,y.

Example:
The players x,y was 19,20 which is an impassable tile, and the closest passable tile's x,y is 17,13. 17,13 is where I want the player to teleport to.

Does that make sense?
 

MarkR

Member

This code should work:

Code:
 

class Game_Character

  #--------------------------------------------------------------------------

  # * Find nearest passable tile

  #--------------------------------------------------------------------------

  def get_nearest_tile(source_x, source_y)

    return [source_x, source_y] if $game_map.passable?(source_x, source_y, 0)

    i = 1

    tile = nil

    while tile.nil?

      # Top or bottom

      for x in (source_x - i)...(source_x + i)

        break unless tile.nil?

        tile = [x, source_y - i] if $game_map.passable?(x, source_y - i, 0)

        tile = [x, source_y + i] if $game_map.passable?(x, source_y + i, 0)

      end

      # Right or left                   

      for y in (source_y - i + 1)...(source_x + i - 1)

        break unless tile.nil?

        tile = [source_x + 1, y] if $game_map.passable?(source_x + 1, y, 0) 

        tile = [source_x - 1, y] if $game_map.passable?(source_x + 1, y, 0)

      end

      # Check if search is still within the map

      return false unless $game_map.valid?(source_x - i, source_y - i) and

                          $game_map.valid?(source_x + i, source_y + i)

      i += 1

    end

    return tile

  end

  #--------------------------------------------------------------------------

  # * Move to nearest passable tile

  #--------------------------------------------------------------------------

  def move_to_nearest_tile(x, y)

    tile = get_nearest_tile(x, y)

    $game_player.moveto(tile[0], tile[1]) unless tile.nil?

  end

end

class Interpreter

  def transfer_to_tele_event

    for event in $game_map.events.values

      if event.name.include?("tele")

        $game_player.move_to_nearest_tile(event.x, event.y) 

      end

    end

  end

end

 

It will check all passable tiles one the map and if it can't find any passable map, it won't move the player.
You can still use "transfer_to_tele_event" in the call script box. ;)
 

MarkR

Member

If you add the code I posted, you can use "transfer_to_tele_event" in a call script and it will move the player to the nearest 'tele' event.
I didn't saw you asked for the closest passable tile from the players x,y location, but you could also do by using this code in a call script:
Code:
 

x = $game_player.x

y = $game_player.y

$game_player.move_to_nearest_tile(x, y)

 
 

MarkR

Member

It will need the script I posted. ;)
I just modified the script a bit, if you replace my old script with this code, then you can still use Gubid's code to move to the tele event and use my code to move the player to the nearest passable tile.
Code:
 

class Game_Character

  #--------------------------------------------------------------------------

  # * Find nearest passable tile

  #--------------------------------------------------------------------------

  def get_nearest_tile(source_x, source_y)

    return [source_x, source_y] if $game_map.passable?(source_x, source_y, 0)

    i = 1

    tile = nil

    while tile.nil?

      # Top or bottom

      for x in (source_x - i)...(source_x + i)

        break unless tile.nil?

        tile = [x, source_y - i] if $game_map.passable?(x, source_y - i, 0)

        tile = [x, source_y + i] if $game_map.passable?(x, source_y + i, 0)

      end

      # Right or left                  

      for y in (source_y - i + 1)...(source_x + i - 1)

        break unless tile.nil?

        tile = [source_x + 1, y] if $game_map.passable?(source_x + 1, y, 0)

        tile = [source_x - 1, y] if $game_map.passable?(source_x + 1, y, 0)

      end

      # Check if search is still within the map

      return false unless $game_map.valid?(source_x - i, source_y - i) and

                          $game_map.valid?(source_x + i, source_y + i)

      i += 1

    end

    return tile

  end

  #--------------------------------------------------------------------------

  # * Move to nearest passable tile

  #--------------------------------------------------------------------------

  def move_to_nearest_tile(x = @x, y = @y)

    tile = get_nearest_tile(x, y)

    self.moveto(tile[0], tile[1]) unless tile.nil?

  end

end

 

After inserting this script, you can use the following code in a call script:
Code:
$game_player.move_to_nearest_tile
 
Thanks for the assist there MarkR. Although, shouldn't your method be part of the Game_Player class rather than Game_Character? It just seems that why would you create a method in the super class for a class that may or may not exist hypothetically.
 

MarkR

Member

I made it part of the Game_Character class so it will also be possible to move events to the nearest passable tile. ;)

Oh, I now understand what you mean with "for a class that may or may not exist hypothetically", after reading the script again. :P
The move_to_nearest_tile method should use self.moveto(tile[0], tile[1]) instead of $game_player.moveto(tile[0], tile[1]) or wasn't that what you meant?
 
MarkR, I am getting this error message from the script:

Script ' ' Line35: NoMethodError occured

undefined method [] for false: FalseClass


The weird thing is, it only occurs during random map generation and player placement. Not when I place the player on an impassable tile.

I think it has something to do with Tonbi's script. If you want to see it here it is:

Code:
#==============================================================================

#     Random Map Generator Script v0.80   by tonbi            (January 2, 2006)

#------------------------------------------------------------------------------

#     This script automatically creates random maps.

#==============================================================================

#

#     Place this script under Scene_Debug and above Main for use.

#

#     Because of the 'light weight conversion system'(abridged edition) already

#     installed, do not use with the Light Weight Conversion script.

#

#==============================================================================

#

#     ** How to use 

#

#     This system uses a three-stage creation process:

#

#     1) It requires  that random maps  have a properly defined name  that uses 

#        the word 'random'  followed by  a series  of values to assist  in it's 

#        creation.

#

#     2) The maps themselves  must contain  one or more  sets of  tile patterns

#        which are used by the generator to draw the map itself.

#

#     3) The custom events  within the  generated map  should be tagged  with a

#        special flag  in either the event's name  or in a comment in the first

#        page of the event.

#

#------------------------------------------------------------------------------

#

#     == Map Creation / Map Name and Tiles ==

#

#     When crafting  a randomly generated map,  you must have  an appropriately

#     created map map and name your random map with the following syntax:

#

#                       mapname, random, YYY, ZZZ

#     

#     1) The very first parameter is the traditional map name.

#     2) The second parameter is the key word 'Random'.   This informs the sys-

#        tem that this will be a randomly generate map.

#     3) The third patameter is the YYY value.  It indicates how many formation

#        patterns are available  in the map's tileset (see formation patterns).

#     4) And the fourth parameter is the ZZZ value.   It indicates how many ob-

#        stacles and/or tiles are drawn in the generated map (see random ob-

#        stacles).

#

#

#------------------------------------------------------------------------------

#

#     == Formation Patterns ==

#

#     The upper left corner  of your map  contains a series  of tiles used when

#     drawing the randomly created map.   Below is the layout  of the tiles and

#     how they will appear  when you're  readying them for  generating a random 

#     map.

#

#     +---+

#     |   | <----- Floor Tile

#     +---+---+

#     |/     \|

#     |       | <--- Ceilings (corners)

#     |\     /|

#     +---+---+---+

#     | /-------\ |

#     ||  +---+  ||

#     ||  |   |  || <---Ceiling (visible ledge borders w/ center ceiling tile)

#     ||  +---+  ||

#     | \-------/ |

#     +---+---+---+

#     |           |

#     |           | <---Walls

#     |           |

#     +---+---+---+

#

#     The floor tile  is the basic tile  your character can walk upon.   As you

#         walk on the floor tile,  it must be  a 1st layer graphic...  and thus

#         drawm in the 1st layer of your map.

#

#     The ceiling tiles (corners followed by borders)  are the area your player

#         will not be  able to walk upon.   However,  the top layer of 'Ceiling

#         border' may be set  to passable  with a priority of '1' so it can ap-

#         pear the player  is walking 'under' the ledge.   Still,  nearly every

#         ceiling tile must be drawn in the 2nd layer  of your map with the ex-

#         ception of the CENTER ceiling tile.

#

#   And the wall tiles are last, and set up to be impassable.  Like the ceiling

#         tiles, they must be drawn in the 2nd layer of your map.

#

#     . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

#

#

#     You can create maps that have two different sets of map tiles like...

#

#     +-+

#     | |  <---- Floor

#     +-+-+

#     +   + <----Ceiling (corners)

#     +-+-+-+

#     |     |

#     |     | <---Ceiling (ledge)

#     +-+-+-+

#     |     | <-- Walls

#     +-+-+-+

#     | | <------ 2nd Floor

#     +-+-+

#     +   + < --- 2nd ceiling (corners)

#     +-+-+-+

#     |     |

#     |     | <--- Etc.

#     +-+-+-+

#     |     |

#     +-+-+-+

#

#     Or even more than two sets of tiles, this number of Formation Patterns is

#     set in the mapname under the YYY value as described above.

#

#------------------------------------------------------------------------------

#

#     == Random Obstacles in the Formation Patterns ==

#     

#     If you were to generate a random map,  you would see  a bare floor with a

#     series of walls  going this way or that.   While the walls may branch out

#     in various directions, the floor itself 'would' be pretty much plain.  It

#     is by setting up some 'random obstacles' that you may have a floor in the

#     generated map that makes it appear less drab.

#

#     The obstacles that are drawn on the map floor come in two varieties, they

#     may be  single tile graphics  or graphics  that are two tiles  in height.

#     The obstacles are defined within the  'Formation Pattern'  tiles as I had

#     described above.   However, when I described the formation pattern tiles,

#     I had not included the obstacles themselves.

#

#     Allow me to present a section of a formation pattern layout  with the ad-

#     dition of map obstacles.

#

#

#        +-------- Floor Tile

#        |  +---------------------- An obstacle (single tile)

#        V  V

#     +---+---+---+

#     |   |   |   | <-------------- An obstacle (single tile)

#     +---+---+---+---+ 

#     |/     \|   | <-------------- An obstacle (two tiles tall)

#     |       |   |   |

#     |\     /|   |   | <-----------An obstacle (two tiles tall)

#     +---+---+---+---+

#        ^

#        +-------- Ceilings (corners)

#

#

#     The very first row in the formation starts off with the floor tile,  just 

#     like before.  But following the floor tiles are the single-tile obstacles

#     like rocks or bushes or anything that is drawn with a single tile.  These

#     tiles may  be passable  or they may block  the player  so he  has to move

#     around the obstacles. Either way, these obstacles are drawn in the second

#     layer so they are drawn (over) the regularly drawn floor tiles.

#

#     The next row(s)  where the first set of ceiling tiles  are drawn is where

#     you define the two-tile tall obstacles. More often, these tiles are drawn

#     with the bottom tile being blocked  while the second tile  being passable 

#     and with a 'priority' setting of 1 so the player appears to be moving be-

#     hind the tile.  These tiles/obstacles are also drawn in the second layer.

#

#     You can set up  a number of  single or two-tile tall  obstacles  in their 

#     defined rows.  There does not seem  to be any set limit to the total num-

#     ber you may create. 

#

#     There are no 'three-tile tall' obstacles.

#

#

#------------------------------------------------------------------------------

#

#     == Map Creation / Special Event Placement ==

#

#     By adding special names or comments to an event, you can applay a special

#     attibute such as fixing it in place, or to alter the way the map is made.

#

#     Names/Codes are as follows:

#

#     . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

#

#     Name of event, Relay”

#     Events that hold the text of 'Relay' (in either the name or in a comment)

#     allows you to set up area generated in which the player/party can wander.

#

#     When with it does, the position by all means becomes the land.

#     Keeping connecting this relay point, to the order of event, ID it makes the map.

#     (With the reason which has tied in the straight line of course it is not)

#     If possible, please make the relay point in both deep waters of the map.

#     In addition, please can be less crowded the deep water a little. (5 tiles) the wall is gone.

#     However, there is no this relay point and the map is drawn up also the [te], once.

#     In addition, when the relay point is increased too much, the wall decreases.

#     Because it is sufficient with several, please pay attention.

#     The recommendation at three is setting in shape of 3 rectangularities

#

#     In the event other than the relay point, those which do not have especially appointment random are moved to land.

#

#     Name of event, "Fixed"

#     Events that hold the text of 'Fixed' (in either the name or in a comment)

#     will be positioned to the closest nearby passable tile.  This allows for

#     you to position one or more events to a general location so you can group

#     like events together and still have a little randomness.

#

#     . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

#

#     Name of event, "P-Fixed"

#     Events that hold the text of 'P-Fixed' (in either the name or the comment)

#     allows you to fix the position of that event on the map.  This is differ-

#     ent from the 'Fixed' variation as this does not force the event to a pas-

#     sable tile but also allows these events to be drawn on walls and ceiling

#     tiles that are normally impassable by the player.

#

#     . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

#

#     Name of event, "Wall"

#     Events that hold the text of 'Wall' within a comment in the first page

#     will move to a random position within a generated wall.  This would be 

#     useful to position random doors or wall decorations like torches within

#     the randomly generated map.

#

#     If the statement is followed by a ',1' ... like "Wall,1" ...then it takes

#     the width and height of the event into consideration when positioning the

#     event.  As such, it is recommended to add the ',1' to the event name.

#

#     . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

#

#     Name of event, "P-Wall"

#     Events that hold the text of 'P-Wall' within a comment in the first page

#     will move to the closest generated wall on the map. This would be useful

#     to position doorways or portals within the randomly generated map.

#

#     If the statement is followed by a ',1' ... like "Wall,1" ...then it takes

#     the width and height of the event into consideration when positioning the

#     event.  As such, it is recommended to add the ',1' to the event name.

#

#     . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

#

#     In addition, it is possible to add additional event calls to the case

#     system if necessary.  'Scripters only.

#'

#

#==============================================================================

#

#     ** How to configure

#

#     == Caterpillar/Train Actor by Fukuyama ==

#     

#     You have  the option  to use  this system  with Fukuyama's famous  'Train

#     Actor' script. For compatability, set the TONBI_USE_TRAIN_ACTOR switch to

#     true, otherwise keep this value set to false.

#

#     . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

#

#     == Clipping/Refresh Range System ==

#

#     This system allows you  to adjust the range  where active sprites  on the

#     map are refreshed rather than having them refresh when out of the party's

#     visual range. By increasing the values stored within the TONBI_DRAWRANGEX

#     and TONBI_DRAWRANGEY values, sprite graphics may refresh further from the

#     party.   On the opposite end of the spectrum,  lowering these values will

#     force the graphics to only refresh when closer to the player.

#

#     If you deal with larger character sets,  you may wish to increase the set

#     values.  Reducing the default values is not recommended.

#

#     . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

#

#     == Map Retention System ==

#     

#     This system stores a copy  of the most recently created random map in the

#     your savegames,  so you can return  to a random map without difficulty...

#     even if you have multiple savegames with random maps each.

#

#     However, you have the option  to create a separate game map  which may be 

#     added/ammended to your project's MapInfos data file.   This can be useful

#     if you wish to create random maps to save and re-use later.

#

#     Initially, Tonbi's original version used a 'true/false' switch to utilize

#     this system,  but this version  has been slightly modified.   Rather than

#     having a preset and hardcoded  MapID of 999  for your generated map (thus

#     creating  'only'  Map999.rxdata),  this version  gives you  the luxury of

#     creating the ID number  of the map yourself.   If you wish  your randomly

#     created map to be Map789.rxdata... you can,  just by setting the modified

#     TONBI_AUTO_MAP_SAVE value to 789.  

#

#     Maps generated  with this system  will be visible  in your  MapInfos.data

#     list in the bottom-left window of your map editor, right under your tiles

#     window.  The name will read  'Random automatic saving(mapname...)'.   The

#     map will use  the same tileset  as the random map itself,  and the events

#     will be copied over with no problem.

#

#     Setting TONBI_AUTO_MAP_SAVE to nil will turn the system off.

#

#==============================================================================

#

#     ** Compatability issues

#

#     This system was created exclusively for RPGMaker XP, an RGSS system.   It

#     is not RMXP SDK compliant  and might not be compatible with other scripts

#     that edit or modify the RMXP mapping/movement system.

#

#     However,  the rewritten sections in this script have been highlighted for

#     the intermediate scripter.  An example of a rewritten line is as follows:

#

#        #########################################################

#        # Modification:  New 'onscreen' array

#        #

#        $onscreen = []

#        #########################################################

#

#     As such,  it should be very easy  to trace all the edits  to the default

#     RGSS system that have been performed.

#

#     Please take note of the methods that have been altered for this system.

#

#     == Methods Aliased ==

#     Game_Temp.initialize, Game_Character.update

#

#

#     == Methods Rewritten ==

#     Spriteset_Map.initialize, Spriteset_Map.dispose, Spriteset_Map.update,

#     Game_Map.setup, RPG::MapInfo.name, RPG::Event.name

#

#

#==============================================================================

 

  

             # ----------------------------------------------- #

             #                                                 #

             #      C  O  N  F  I  G  U  R  A  B  L  E  S      #

             #                                                 #

             # ----------------------------------------------- #

             

             

  TONBI_USE_TRAIN_ACTOR = false   # Set to true if using Fukuyama's Train Actor

                                  # script.  Set to false by default.

                                  

  TONBI_DRAWRANGEX      = 1920    # Used to increase / decrease the range where

  TONBI_DRAWRANGEY      = 1664    # charset graphics are permitted to refresh.

                                  # Recommended:  Do not decrease.

                                  

  TONBI_AUTO_MAP_SAVE   = 999     # The MapID where the generated map is saved.

                                  # Set to nil if it doesn't save the map.

                        

 

                                  

                                  

#==============================================================================

# ** Game_Temp

#------------------------------------------------------------------------------

#  This class handles temporary data that is not included with save data.

#  Refer to "$game_temp" for the instance of this class.

#==============================================================================

 

class Game_Temp

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------  

  alias initialize_tonbi1 initialize

  def initialize

    initialize_tonbi1

    $onscreen = []                        # Flag inside sprite picture

  end

end

 

 

 

#==============================================================================

# ** Game_Character

#------------------------------------------------------------------------------

#  This class deals with characters. It's used as a superclass for the

#  Game_Player and Game_Event classes.

#==============================================================================

 

class Game_Character

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  alias update_tonbi1 update

  def update

    # Position on picture

    sx = @real_x - $game_map.display_x - 1280

    sy = @real_y - $game_map.display_y - 960

    # Absolute value is calculated

    abs_sx = sx > 0 ? sx : -sx

    abs_sy = sy > 0 ? sy-3 : -sy

    # When length or side is left above the TONBI_DRAWRANGE tile,

    if abs_sx > TONBI_DRAWRANGEX or abs_sy > TONBI_DRAWRANGEY

      # It makes sprite non renewal

      $onscreen[@id]=false

    else

      # There is sprite renewal and does

      $onscreen[@id]=true

    end

    # Original Call

    update_tonbi1

  end

end

 

 

 

#==============================================================================

# ** Spriteset_Map

#------------------------------------------------------------------------------

#  This class brings together map screen sprites, tilemaps, etc.

#  It's used within the Scene_Map class.

#==============================================================================

 

class Spriteset_Map

  #--------------------------------------------------------------------------

  # * Public Instance Variables

  #--------------------------------------------------------------------------

  attr_accessor :character_sprites

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------  

  def initialize

    

    #########################################################

    # Modification:  New 'onscreen' array

    #

    $onscreen = []

    #########################################################

    

    # Make viewports

    @viewport1 = Viewport.new(0, 0, 640, 480)

    @viewport2 = Viewport.new(0, 0, 640, 480)

    @viewport3 = Viewport.new(0, 0, 640, 480)

    @viewport2.z = 200

    @viewport3.z = 5000

    # Make tilemap

    @tilemap = Tilemap.new(@viewport1)

    @tilemap.tileset = RPG::Cache.tileset($game_map.tileset_name)

    for i in 0..6

      autotile_name = $game_map.autotile_names[i]

      @tilemap.autotiles[i] = RPG::Cache.autotile(autotile_name)

    end

    @tilemap.map_data = $game_map.data

    @tilemap.priorities = $game_map.priorities

    # Make panorama plane

    @panorama = Plane.new(@viewport1)

    @panorama.z = -1000

    # Make fog plane

    @fog = Plane.new(@viewport1)

    @fog.z = 3000

    

    #########################################################

    # Modification  Party Sprite array/routines and $onscreen

    #               values were added.

    #               @party_sprites.push now substitutes for 

    #               the original @character_sprites.push line.

    #

    # Drawing up character sprite

    @character_sprites = []

    @party_sprites = []

    for i in $game_map.events.keys.sort

      sprite = Sprite_Character.new(@viewport1, $game_map.events[i])

      @character_sprites[i]=sprite

      $onscreen[i] = true

    end

    @party_sprites.push(Sprite_Character.new(@viewport1, $game_player))

    #########################################################

    

    # Make weather

    @weather = RPG::Weather.new(@viewport1)

    # Make picture sprites

    @picture_sprites = []

    for i in 1..50

      @picture_sprites.push(Sprite_Picture.new(@viewport2, 

        $game_screen.pictures[i]))

    end

    # Make timer sprite

    @timer_sprite = Sprite_Timer.new

    # Frame update

    update

  end

  #--------------------------------------------------------------------------

  # * Dispose

  #--------------------------------------------------------------------------

  def dispose

    # Dispose of tilemap

    @tilemap.tileset.dispose

    for i in 0..6

      @tilemap.autotiles[i].dispose

    end

    @tilemap.dispose

    # Dispose of panorama plane

    @panorama.dispose

    # Dispose of fog plane

    @fog.dispose

    

    ############################################################

    # Modification  Different method for disposing of character

    #               sprites and the new party sprites. Will not

    #               dispose of sprite if sprite value is 'nil'.

    #               System added to prevent crashes.

    #

    # Dispose of character sprites

    for i in @character_sprites

      i.dispose if i != nil

    end

    # Dispose of party sprites

    for i in @party_sprites

      i.dispose if i != nil

    end

    ############################################################

    

    # Dispose of weather

    @weather.dispose

    # Dispose of picture sprites

    for sprite in @picture_sprites

      sprite.dispose

    end

    # Dispose of timer sprite

    @timer_sprite.dispose

    # Dispose of viewports

    @viewport1.dispose

    @viewport2.dispose

    @viewport3.dispose

  end

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  def update

    # If panorama is different from current one

    if @panorama_name != $game_map.panorama_name or

       @panorama_hue != $game_map.panorama_hue

      @panorama_name = $game_map.panorama_name

      @panorama_hue = $game_map.panorama_hue

      if @panorama.bitmap != nil

        @panorama.bitmap.dispose

        @panorama.bitmap = nil

      end

      if @panorama_name != ""

        @panorama.bitmap = RPG::Cache.panorama(@panorama_name, @panorama_hue)

      end

      Graphics.frame_reset

    end

    # If fog is different from current fog

    if @fog_name != $game_map.fog_name or @fog_hue != $game_map.fog_hue

      @fog_name = $game_map.fog_name

      @fog_hue = $game_map.fog_hue

      if @fog.bitmap != nil

        @fog.bitmap.dispose

        @fog.bitmap = nil

      end

      if @fog_name != ""

        @fog.bitmap = RPG::Cache.fog(@fog_name, @fog_hue)

      end

      Graphics.frame_reset

    end

    # Update tilemap

    @tilemap.ox = $game_map.display_x / 4

    @tilemap.oy = $game_map.display_y / 4

    @tilemap.update

    # Update panorama plane

    @panorama.ox = $game_map.display_x / 8

    @panorama.oy = $game_map.display_y / 8

    # Update fog plane

    @fog.zoom_x = $game_map.fog_zoom / 100.0

    @fog.zoom_y = $game_map.fog_zoom / 100.0

    @fog.opacity = $game_map.fog_opacity

    @fog.blend_type = $game_map.fog_blend_type

    @fog.ox = $game_map.display_x / 4 + $game_map.fog_ox

    @fog.oy = $game_map.display_y / 4 + $game_map.fog_oy

    @fog.tone = $game_map.fog_tone

    

    ############################################################

    # Modification  Different method for refresh the character

    #               sprites and the new party sprites. Refresh

    #               the sprites if outside the visual range as

    #               defined with the TONBI_DRAWRANGEX and the

    #               TONBI_DRAWRANGEY values.

    #

    # Update character sprites

    for i in $game_map.events.keys

      @character_sprites[i].update if $onscreen[i]

    end

    # Update party sprites

    for i in @party_sprites

      i.update

    end    

    #####################################################

    

    # Update weather graphic

    @weather.type = $game_screen.weather_type

    @weather.max = $game_screen.weather_max

    @weather.ox = $game_map.display_x / 4

    @weather.oy = $game_map.display_y / 4

    @weather.update

    # Update picture sprites

    for sprite in @picture_sprites

      sprite.update

    end

    # Update timer sprite

    @timer_sprite.update

    # Set screen color tone and shake position

    @viewport1.tone = $game_screen.tone

    @viewport1.ox = $game_screen.shake

    # Set screen flash color

    @viewport3.color = $game_screen.flash_color

    # Update viewports

    @viewport1.update

    @viewport3.update

  end

end

 

 

 

#==============================================================================

# ** Fukuyama's Train-Actor modification

#==============================================================================

if TONBI_USE_TRAIN_ACTOR == true

  module Train_Actor

    module Spriteset_Map_Module

      def setup_actor_character_sprites(characters)

        if !setup_actor_character_sprites?

          for character in characters.reverse

            @party_sprites.unshift(

              Sprite_Character.new(@viewport1, character)

            )

          end

          @setup_actor_character_sprites_flag = true

        end

      end

    end

  end

end

 

 

 

#==============================================================================

# ** Game_Map

#------------------------------------------------------------------------------

#  This class handles the map. It includes scrolling and passable determining

#  functions. Refer to "$game_map" for the instance of this class.

#==============================================================================

 

class Game_Map

  #--------------------------------------------------------------------------

  # * Setup

  #     map_id : map ID

  #--------------------------------------------------------------------------

  def setup(map_id)

    # Put map ID in @map_id memory

    @map_id = map_id

    # Load map from file and set @map

    @map = load_data(sprintf("Data/Map%03d.rxdata", @map_id))

    # set tile set information in opening instance variables

    tileset = $data_tilesets[@map.tileset_id]

    @tileset_name = tileset.tileset_name

    @autotile_names = tileset.autotile_names

    @panorama_name = tileset.panorama_name

    @panorama_hue = tileset.panorama_hue

    @fog_name = tileset.fog_name

    @fog_hue = tileset.fog_hue

    @fog_opacity = tileset.fog_opacity

    @fog_blend_type = tileset.fog_blend_type

    @fog_zoom = tileset.fog_zoom

    @fog_sx = tileset.fog_sx

    @fog_sy = tileset.fog_sy

    @battleback_name = tileset.battleback_name

    @passages = tileset.passages

    @priorities = tileset.priorities

    @terrain_tags = tileset.terrain_tags

    # Initialize displayed coordinates

    @display_x = 0

    @display_y = 0

    

    #########################################################

    # Modification:  New routine to check for 'special' maps

    #

    check_special_map 

    #########################################################

    

    # Clear refresh request flag

    @need_refresh = false

    # Set map event data

    @events = {}

    for i in @map.events.keys

      @events[i] = Game_Event.new(@map_id, @map.events[i])

    end

    # Set common event data

    @common_events = {}

    for i in 1...$data_common_events.size

      @common_events[i] = Game_CommonEvent.new(i)

    end

    # Initialize all fog information

    @fog_ox = 0

    @fog_oy = 0

    @fog_tone = Tone.new(0, 0, 0, 0)

    @fog_tone_target = Tone.new(0, 0, 0, 0)

    @fog_tone_duration = 0

    @fog_opacity_duration = 0

    @fog_opacity_target = 0

    # Initialize scroll information

    @scroll_direction = 2

    @scroll_rest = 0

    @scroll_speed = 4

  end

  #--------------------------------------------------------------------------

  # * Check Special Maps

  #--------------------------------------------------------------------------

  def check_special_map

    # Get Map Information

    mapinfo  = load_data("Data/MapInfos.rxdata")

    # If the 'subname' of map is "Random"

    if mapinfo[@map_id].subname == "Random"      

      if mapinfo[@map_id].subname(3)=="" or mapinfo[@map_id].subname(3) == nil

        p3 = 0

      else

        p3 = mapinfo[@map_id].subname(3).to_i

      end

      if mapinfo[@map_id].subname(4)=="false"

        p4 = false

      end

      make_random_map(2, mapinfo[@map_id].subname(2).to_i, p3, p4)

    end

  end

  #--------------------------------------------------------------------------

  # * Draw the Random Map

  #     wall = Height of wall >> At present time it is invalid

  #     type = Wall production type >> Only 0 making, increases is (also sweat designation method is undecided

  #     thoughplayer = Also does the player include to the relay point??

  #     connect = How to tie the relay point >> true= Continuation false=Independence 2 at a time

  #

  #    * Also it is possible to throw to business under all argument omitting,

  #     ex. make_random_map(2,0,,true)

  #--------------------------------------------------------------------------

  def make_random_map(wall = 2, type = 0, objcnt = 0, connect = true)

    # The measure of parameter abnormality

    wall = 0 if wall == nil

    type = 0 if type == nil

    objcnt = 0 if objcnt == nil

    unless objcnt.is_a?(Numeric)

      objcnt = 0

    end

    if objcnt < 0

      objcnt = 0

    end

    connect = true if connect != false

    # Height data array

    @heightdata = Table.new(@map.width,@map.height)

    # Topographical data array

    @maskdata = Table.new(@map.width,@map.height)

    # Arrangement data array such as event

    @oneventdata = Table.new(@map.width,@map.height)

    # Mask setting data array

    @masksetting = []

    # Production methodological data

    @makedata = []

    # Operation methodological initialization

    @targettype=0

    @chgtype=0

    time = -1

    # Each data initialization

    for i in [email=0...@map.width]0...@map.width[/email]

      for j in [email=0...@map.height]0...@map.height[/email]

        time += 1

        if time%2000 == 0

          Graphics.update

        end

        @heightdata[i,j] = 0

        @maskdata[i,j] = 0

      end

    end

    for i in 0...100

      @masksetting[i] = true

    end

    # Relay point information acquisition

    needposx = []

    needposy = []

    # Adding event the “relay point”

    for i in @map.events.keys.sort

      time += 1

      if time%200 == 0

        Graphics.update

      end

      if event_settype(i) == 1

        if connect == true

          needposx.push(@map.events[i].x)

          needposy.push(@map.events[i].y)

          needposx.push(@map.events[i].x)

          needposy.push(@map.events[i].y)

        else

          needposx.push(@map.events[i].x)

          needposy.push(@map.events[i].y)

        end

      end

    end

    if connect == true

      needposx.shift

      needposy.shift

    end

    loop do

      if needposx.size <= 2

        needposx.push(rand(@map.width))

        needposy.push(rand(@map.height))

      else

        break

      end

    end

    # The production methodological data is set here

    case type

    when 0

      # Type 0  >> 2 layer natural type

      @makedata.push([0,1,0])

      @makedata.push([5,1])

      for i in 0...(needposx.size/2)

        @makedata.push([1,needposx[i*2],needposy[i*2],needposx[i*2+1],needposy[i*2+1]])

        @makedata.push([3,0,-15,4,0])

        @makedata.push([1,1,1,1,1])

        @makedata.push([6,0,needposx[i*2],needposy[i*2]])

        @makedata.push([6,0,needposx[i*2+1],needposy[i*2+1]])

      end

      @makedata.push([4,0,1,1,1])

      @makedata.push([4,0,1,1,1])

      @makedata.push([4,1,1,1,1])

      @makedata.push([0,0,0])

      @makedata.push([2,0,2])

      @makedata.push([5,0])

      @makedata.push([2,1,2])

      @makedata.push([5,1])

    when 1

      # Type 1 >> 2 layer artificial type

      @makedata.push([0,1,0])

      @makedata.push([5,1])

      for i in 0...(needposx.size/2)

        @makedata.push([1,needposx[i*2],needposy[i*2],needposx[i*2+1],needposy[i*2+1]])

        @makedata.push([3,0,-6,4,1,10])

        @makedata.push([1,1,1,1,1])

        @makedata.push([6,0,needposx[i*2],needposy[i*2]])

        @makedata.push([6,0,needposx[i*2+1],needposy[i*2+1]])

      end

      @makedata.push([4,0,2,3,1])

      @makedata.push([4,1,2,2,1])

      @makedata.push([4,0,1,1,1])

      @makedata.push([0,0,0])

      @makedata.push([2,0,2])

      @makedata.push([5,0])

      @makedata.push([2,1,2])

      @makedata.push([5,1])

    when 2

      # Type 2 >> 2 layer natural convex type

      @makedata.push([0,1,0])

      @makedata.push([5,1])

      for i in 0...(needposx.size/2)

        @makedata.push([1,needposx[i*2],needposy[i*2],needposx[i*2+1],needposy[i*2+1]])

        @makedata.push([3,0,-15,4,0])

        @makedata.push([1,1,1,1,1])

        @makedata.push([6,0,needposx[i*2],needposy[i*2]])

        @makedata.push([6,0,needposx[i*2+1],needposy[i*2+1]])

      end

      @makedata.push([4,0,2,2,1])

      @makedata.push([4,1,1,1,1])

      @makedata.push([0,0,0])

      @makedata.push([2,0,2])

      @makedata.push([5,0])

      @makedata.push([2,1,2])

      @makedata.push([5,-1])

    when 3

      # Type 2 >> 2 layer artificial convex type

      @makedata.push([0,1,0])

      @makedata.push([5,1])

      for i in 0...(needposx.size/2)

        @makedata.push([1,needposx[i*2],needposy[i*2],needposx[i*2+1],needposy[i*2+1]])

        @makedata.push([3,0,-15,4,1,10])

        @makedata.push([1,1,1,1,1])

        @makedata.push([6,0,needposx[i*2],needposy[i*2]])

        @makedata.push([6,0,needposx[i*2+1],needposy[i*2+1]])

      end

      @makedata.push([4,0,2,2,1])

      @makedata.push([4,1,1,1,1])

      @makedata.push([0,0,0])

      @makedata.push([2,0,2])

      @makedata.push([5,0])

      @makedata.push([2,1,2])

      @makedata.push([5,-1])

    when 4

      # Type 4 >> 2 layer natural type that 1

      # Topography [0:Hole 1:Land 2:Wall]

      # Basic setting

      @makedata.push([0,1,0])

      @makedata.push([5,0])

      # The wall is put in place

      @makedata.push([1,0,0,-1,0])

      @makedata.push([3,2,-6,1,0])

      @makedata.push([1,-1,0,-1,-1])

      @makedata.push([3,2,-6,1,0])

      @makedata.push([1,-1,-1,0,-1])

      @makedata.push([3,2,-6,1,0])

      @makedata.push([1,0,-1,0,0])

      @makedata.push([3,2,-6,1,0])

      @makedata.push([4,2,2,2,1])

      # The hole is put in place with random

      for i in 0...(rand(12*@map.width*@map.height/40/40)+(5*@map.width*@map.height/40/40))

        @makedata.push([1,3,3,8,8])

        @makedata.push([6,0,rand(@map.width-10)+5,rand(@map.height-10)+5])

      end

      # Around wall compilation

      @makedata.push([7,2])

      @makedata.push([4,2,1,1,1])

      # Road compilation

      for i in 0...(needposx.size/2)

        @makedata.push([1,needposx[i*2],needposy[i*2],needposx[i*2+1],needposy[i*2+1]])

        @makedata.push([3,1,-8,4,0,5])

        @makedata.push([1,1,1,1,1])

        @makedata.push([6,1,needposx[i*2],needposy[i*2]])

        @makedata.push([6,1,needposx[i*2+1],needposy[i*2+1]])

      end

      # Expansion processing

      @makedata.push([4,1,1,1,1])

      @makedata.push([4,1,0,1,1])

      @makedata.push([2,0,0])

      @makedata.push([4,1,1,0,1])

      @makedata.push([2,-1,1])

      @makedata.push([4,2,1,1,1])

      # Height setting

      @makedata.push([0,0,0])

      @makedata.push([2,0,2])

      @makedata.push([5,-1])

      @makedata.push([2,1,2])

      @makedata.push([5,0])

      @makedata.push([2,2,2])

      @makedata.push([5,1])

    when 5

      # Type 5 >> 2 layer artificial type that 1

      # Topography[0:Hole 1:Land 2:Wall]

      # Basic setting

      @makedata.push([0,1,0])

      @makedata.push([5,0])

      # The wall is put in place

      @makedata.push([1,0,0,-1,0])

      @makedata.push([3,2,-6,1,0])

      @makedata.push([1,-1,0,-1,-1])

      @makedata.push([3,2,-6,1,0])

      @makedata.push([1,-1,-1,0,-1])

      @makedata.push([3,2,-6,1,0])

      @makedata.push([1,0,-1,0,0])

      @makedata.push([3,2,-6,1,0])

      @makedata.push([4,2,2,2,1])

      # The hole is put in place with random

      for i in 0...(rand(12*@map.width*@map.height/40/40)+(5*@map.width*@map.height/40/40))

        @makedata.push([1,3,3,8,8])

        @makedata.push([6,0,rand(@map.width-10)+5,rand(@map.height-10)+5])

      end

      # Around wall compilation

      @makedata.push([7,2])

      @makedata.push([4,2,1,1,1])

      # Road compilation

      for i in 0...(needposx.size/2)

        @makedata.push([1,needposx[i*2],needposy[i*2],needposx[i*2+1],needposy[i*2+1]])

        @makedata.push([3,1,-8,4,1,5])

        @makedata.push([1,1,1,1,1])

        @makedata.push([6,1,needposx[i*2],needposy[i*2]])

        @makedata.push([6,1,needposx[i*2+1],needposy[i*2+1]])

      end

      # Expansion processing

      @makedata.push([4,1,1,1,1])

      @makedata.push([4,1,0,1,1])

      @makedata.push([2,0,0])

      @makedata.push([4,1,1,0,1])

      @makedata.push([2,-1,1])

      @makedata.push([4,2,1,1,1])

      # Height setting

      @makedata.push([0,0,0])

      @makedata.push([2,0,2])

      @makedata.push([5,-1])

      @makedata.push([2,1,2])

      @makedata.push([5,0])

      @makedata.push([2,2,2])

      @makedata.push([5,1])

    when 6

      # Type 6 >> 2 layer natural type that 2

      # Topography [0: Hole 1: Land 2: Wall]

      # Basic setting

      @makedata.push([0,1,0])

      @makedata.push([5,0])

      # The wall is put in place

      @makedata.push([1,0,0,-1,0])

      @makedata.push([3,2,-6,1,0])

      @makedata.push([1,-1,0,-1,-1])

      @makedata.push([3,2,-6,1,0])

      @makedata.push([1,-1,-1,0,-1])

      @makedata.push([3,2,-6,1,0])

      @makedata.push([1,0,-1,0,0])

      @makedata.push([3,2,-6,1,0])

      @makedata.push([4,2,2,2,1])

      # The wall is put in place

      for i in 0...(rand(12*@map.width*@map.height/40/40)+(5*@map.width*@map.height/40/40))

        @makedata.push([1,1,1,3,3])

        @makedata.push([6,0,rand(@map.width-10)+5,rand(@map.height-10)+5])

      end

      # Hole enlargement

      @makedata.push([4,0,2,2,0])

      @makedata.push([4,0,1,2,1])

      # Around wall compilation

      @makedata.push([7,2])

      @makedata.push([4,2,1,1,1])

      # Road compilation

      for i in 0...(needposx.size/2)

        @makedata.push([1,needposx[i*2],needposy[i*2],needposx[i*2+1],needposy[i*2+1]])

        @makedata.push([3,1,-15,4,0,5])

        @makedata.push([1,1,1,1,1])

        @makedata.push([6,1,needposx[i*2],needposy[i*2]])

        @makedata.push([6,1,needposx[i*2+1],needposy[i*2+1]])

      end

      # Expansion processing

      @makedata.push([4,1,1,1,1])

      @makedata.push([4,1,0,1,1])

      @makedata.push([2,0,0])

      @makedata.push([4,1,1,0,1])

      @makedata.push([2,-1,1])

      @makedata.push([4,2,1,1,1])

      # Height setting

      @makedata.push([0,0,0])

      @makedata.push([2,0,2])

      @makedata.push([5,-1])

      @makedata.push([2,1,2])

      @makedata.push([5,0])

      @makedata.push([2,2,2])

      @makedata.push([5,1])

    when 7

      # Type 7 >> 2 layer artificial type that 2

      # Topography [0: Hole 1: Land 2: Wall]

      # Basic setting

      @makedata.push([0,1,0])

      @makedata.push([5,0])

      # The wall is put in place

      @makedata.push([1,0,0,-1,0])

      @makedata.push([3,2,-6,1,0])

      @makedata.push([1,-1,0,-1,-1])

      @makedata.push([3,2,-6,1,0])

      @makedata.push([1,-1,-1,0,-1])

      @makedata.push([3,2,-6,1,0])

      @makedata.push([1,0,-1,0,0])

      @makedata.push([3,2,-6,1,0])

      @makedata.push([4,2,2,2,1])

      # The hole is put in place with random

      for i in 0...(rand(12*@map.width*@map.height/40/40)+(5*@map.width*@map.height/40/40))

        @makedata.push([1,1,1,3,3])

        @makedata.push([6,0,rand(@map.width-10)+5,rand(@map.height-10)+5])

      end

      # Hole enlargement

      @makedata.push([4,0,2,2,0])

      @makedata.push([4,0,1,2,1])

      # Around wall compilation

      @makedata.push([7,2])

      @makedata.push([4,2,1,1,1])

      # Road compilation

      for i in 0...(needposx.size/2)

        @makedata.push([1,needposx[i*2],needposy[i*2],needposx[i*2+1],needposy[i*2+1]])

        @makedata.push([3,1,-15,4,1,5])

        @makedata.push([1,1,1,1,1])

        @makedata.push([6,1,needposx[i*2],needposy[i*2]])

        @makedata.push([6,1,needposx[i*2+1],needposy[i*2+1]])

      end

      # Expansion processing

      @makedata.push([4,1,1,1,1])

      @makedata.push([4,1,0,1,1])

      @makedata.push([2,0,0])

      @makedata.push([4,1,1,0,1])

      @makedata.push([2,-1,1])

      @makedata.push([4,2,1,1,1])

      # Height setting

      @makedata.push([0,0,0])

      @makedata.push([2,0,2])

      @makedata.push([5,-1])

      @makedata.push([2,1,2])

      @makedata.push([5,0])

      @makedata.push([2,2,2])

      @makedata.push([5,1])

    end

    # Actually it makes

    for make_stat in @makedata

      time += 1

      if time%2 == 0

        Graphics.update

      end

      case make_stat[0]

      when 0    # Object modification   (p1[0=Height 1=Topography], p2[0=Substitution 1=Addition])

        rndmap_chtarget(make_stat[1],make_stat[2])

      when 1    # Argument setting   (minx, miny, maxz, maxy)

        rndmap_setstat(make_stat[1],make_stat[2],make_stat[3],make_stat[4])

      when 2    # Mask modification (p1[-1:Entirely], p2[ 0=false 1=true 2=onlytrue])

        rndmap_chmask(make_stat[1],make_stat[2])

      when 3    # Road compilation     (Value,Relay score,Deep water guaranty,Type)

        rndmap_mkroad(make_stat[1],make_stat[2],make_stat[3],make_stat[4],make_stat[5])

      when 4    # Expansion       (Object,Vertical width,Breadth,Type)

        rndmap_plus(make_stat[1],make_stat[2],make_stat[3],make_stat[4])

      when 5    # All modification     (Value)

        rndmap_allchg(make_stat[1])

      when 6    # Designated point     (Value, PositionX, PositionY)

        rndmap_putpos(make_stat[1],make_stat[2],make_stat[3])

      when 7    # Around       (Value)

        rndmap_edge(make_stat[1])

      end

    end

    # Use map tile acquisition

    @tilesetting = Table.new(3,40,3)

    for i in [0,1,2]

      for k in 0...40

        for j in [0,1,2]

          @tilesetting[j,k,i] = @map.data[j,k,i]

        end

      end

    end

    # It revises

    time = 0

    for k in [email=0...@map.height]0...@map.height[/email]

      for j in [email=0...@map.width]0...@map.width[/email]

        time += 1

        # Because time it is required, periodic picture renewal

        if time%500 == 0

          Graphics.update

        end

        # If tile under wall hole modification to land

        if @heightdata[j,k] == 1

          if @heightdata[j,k+1]==-1

            @heightdata[j,k+1] = 0

            if @heightdata[j,k+2]==-1 and

              @heightdata[j,k+3] == 0

              @heightdata[j,k+2] = 0

            end

          end

        end

      end

    end

    # Land compilation that one >> It lays temporarily

    time = 0

    for k in [email=0...@map.height]0...@map.height[/email]

      for j in [email=0...@map.width]0...@map.width[/email]

        time += 1

        # Because time it is required, periodic picture renewal

        if time%500 == 0

          Graphics.update

        end

        if @heightdata[j,k] == 0

          if @heightdata[j,k+1] == -1 or

            @heightdata[j,k-1] == -1 or

            @heightdata[j+1,k] == -1 or

            @heightdata[j-1,k] == -1

            set_mapdata2(j,k,0,8)

          else

            set_mapdata2(j,k,0,0)

          end

        elsif @heightdata[j,k] == 1

          if @heightdata[j,k+1] == -1 or

            @heightdata[j,k-1] == -1 or

            @heightdata[j+1,k] == -1 or

            @heightdata[j-1,k] == -1

            set_mapdata2(j,k,0,8)

          elsif @heightdata[j,k+1] == 0 or

            @heightdata[j,k-1] == 0 or

            @heightdata[j+1,k] == 0 or

            @heightdata[j-1,k] == 0

            set_mapdata2(j,k,0,0)

          else

            set_mapdata2(j,k,1,4)

          end

        else

          set_mapdata2(j,k,0,8)

        end

      end

    end

    # Land compilation that two >> [etsuji] compilation of hole

    time = 0

    for k in [email=0...@map.height]0...@map.height[/email]

      for j in [email=0...@map.width]0...@map.width[/email]

        time += 1

        # Because time it is required, periodic picture renewal

        if time%500 == 0

          Graphics.update

        end

        if @heightdata[j,k] == 0

          if @heightdata[j,k+1] == -1

            # Under hole------------------

            if @heightdata[j-1,k] == -1

              # The left hole

              for i in [0,1,2]

                set_mapdata(j,k+i,0,13+i,1)

              end

            elsif @heightdata[j+1,k] == -1

              # The right hole

              for i in [0,1,2]

                set_mapdata(j,k+i,2,13+i,1)

              end

            else

              # Both sides land

              for i in [0,1,2]

                set_mapdata(j,k+i,1,13+i,1)

              end

            end

          elsif @heightdata[j,k-1] == -1

            # On hole------------------

            if @heightdata[j-1,k] == -1 or

            (@heightdata[j-1,k] == 1 and

            @heightdata[j-1,k-1] == -1)

              # The left hole

              set_mapdata(j,k,0,11,2)

            elsif @heightdata[j+1,k] == -1 or

            (@heightdata[j+1,k] == 1 and

            @heightdata[j+1,k-1] == -1)

              # The right hole

              set_mapdata(j,k,2,11,2)

            else

              # Both sides land

              set_mapdata(j,k,1,11,2)

            end

          elsif @heightdata[j-1,k] == -1 or

            (@heightdata[j-1,k] == 1 and

            @heightdata[j-1,k-1] == -1)

            # The left hole------------------

            set_mapdata(j,k,0,12,1)

          elsif @heightdata[j+1,k] == -1 or

            (@heightdata[j+1,k] == 1 and

            @heightdata[j+1,k-1] == -1)

            # The right hole------------------

            set_mapdata(j,k,2,12,1)

          elsif @heightdata[j-1,k-1] == -1

            # With respect to the left hole------------------

            set_mapdata(j,k,0,9,1)

          elsif @heightdata[j-1,k+1] == -1

            # Under the left hole------------------

            set_mapdata(j,k,0,10,1)

          elsif @heightdata[j+1,k-1] == -1

            # With respect to the right hole------------------

            set_mapdata(j,k,1,9,1)

          elsif @heightdata[j+1,k+1] == -1

            # Under the right hole------------------

            set_mapdata(j,k,1,10,1)

          end

        end

        if @heightdata[j,k] == 1 and

          @heightdata[j,k-1] != -1

          if @heightdata[j,k+1] == -1

            # Found a totally non-functional piece of code here

            # It was 'commented' out.

          elsif @heightdata[j,k-1] == -1

            # On hole------------------

            if @heightdata[j-1,k] == -1

              # The left hole

              set_mapdata(j,k,0,11,2)

            elsif @heightdata[j+1,k] == -1

              # The right hole

              set_mapdata(j,k,2,11,2)

            else

              # Both sides land

              set_mapdata(j,k,1,11,2)

            end

          elsif @heightdata[j-1,k] == -1

            # The left hole------------------

            set_mapdata(j,k,0,12,1)

          elsif @heightdata[j+1,k] == -1

            # The right hole------------------

            set_mapdata(j,k,2,12,1)

          elsif @heightdata[j-1,k-1] == -1

            # With respect to the left hole------------------

            set_mapdata(j,k,0,9,1)

          elsif @heightdata[j-1,k+1] == -1

            # Under the left hole------------------

            set_mapdata(j,k,0,10,1)

          elsif @heightdata[j+1,k-1] == -1

            # With respect to the right hole------------------

            set_mapdata(j,k,1,9,1)

          elsif @heightdata[j+1,k+1] == -1

            # Under the right hole------------------

            set_mapdata(j,k,1,10,1)

          end

        end

      end

    end

    # The going/participating of land compilation >> [etsuji] compilation of wall

    time = 0

    for k in [email=0...@map.height]0...@map.height[/email]

      for j in [email=0...@map.width]0...@map.width[/email]

        time += 1

        # Because time it is required, periodic picture renewal

        if time%500 == 0

          Graphics.update

        end

        if @heightdata[j,k] == 1

          if @heightdata[j,k+1] == 0 or

            @heightdata[j,k+1] == -1

            # Under hole------------------

            if @heightdata[j-1,k] == 0 or

              @heightdata[j-1,k] == -1

              # The left hole

              set_mapdata(j,k+0,0,5+0,5)

              set_mapdata(j,k+1,0,5+1,5)

              set_mapdata(j,k+2,0,5+2,4)

              if @heightdata[j,k+3] != 0 and

                @heightdata[j,k+2] != 1 and

                (@heightdata[j,k+2] != 0 or @heightdata[j-1,k+2] != 0)

                set_mapdata(j,k+2,0,16,5)

                for i in [0,1]

                  set_mapdata(j,k+3+i,0,14+i,1)

                  if @heightdata[j,k+3+i] != -1

                    break

                  end

                end

              end

            elsif @heightdata[j+1,k] == 0 or

              @heightdata[j+1,k] == -1

              # The right hole

              set_mapdata(j,k+0,2,5+0,5)

              set_mapdata(j,k+1,2,5+1,5)

              set_mapdata(j,k+2,2,5+2,4)

              if @heightdata[j,k+3] != 0 and

                @heightdata[j,k+2] != 1 and

                (@heightdata[j,k+2] != 0 or @heightdata[j+1,k+2] != 0)

                set_mapdata(j,k+2,2,16,5)

                for i in [0,1]

                  set_mapdata(j,k+3+i,2,14+i,1)

                  if @heightdata[j,k+3+i] != -1

                    break

                  end

                end

              end

            else

              # Both sides land

              set_mapdata(j,k+0,1,5+0,5)

              set_mapdata(j,k+1,1,5+1,5)

              set_mapdata(j,k+2,1,5+2,4)

              if @heightdata[j,k+3] != 0 and

                 @heightdata[j,k+2] != 1

                set_mapdata(j,k+2,1,16,5)

                for i in [0,1]

                  set_mapdata(j,k+3+i,1,14+i,1)

                  if @heightdata[j,k+3+i] != -1

                    break

                  end

                end

              end

            end

          elsif @heightdata[j,k-1] == 0 or

              @heightdata[j,k-1] == -1

            # On hole------------------

            if @heightdata[j-1,k] == 0 or

              @heightdata[j-1,k] == -1

              # The left hole

              set_mapdata(j,k,0,3,4)

            elsif @heightdata[j+1,k] == 0 or

              @heightdata[j+1,k] == -1

              # The right hole

              set_mapdata(j,k,2,3,4)

            else

              # Both sides land

              set_mapdata(j,k,1,3,4)

            end

          elsif @heightdata[j-1,k] == 0 or

              @heightdata[j-1,k] == -1

            # The left hole------------------

            set_mapdata(j,k,0,4,4)

          elsif @heightdata[j+1,k] == 0 or

              @heightdata[j+1,k] == -1

            # The right hole------------------

            set_mapdata(j,k,2,4,4)

          elsif @heightdata[j-1,k-1] == 0 or

              @heightdata[j-1,k-1] == -1

            # With respect to the left hole------------------

            set_mapdata(j,k,0,1,4)

          elsif @heightdata[j-1,k+1] == 0 or

              @heightdata[j-1,k+1] == -1

            # Under the left hole------------------

            set_mapdata(j,k,0,2,4)

          elsif @heightdata[j+1,k-1] == 0 or

              @heightdata[j+1,k-1] == -1

            # With respect to the right hole------------------

            set_mapdata(j,k,1,1,4)

          elsif @heightdata[j+1,k+1] == 0 or

              @heightdata[j+1,k+1] == -1

            # Under the right hole------------------

            set_mapdata(j,k,1,2,4)

          end

        end

      end

    end

    # Adjusting the position of the player

    playerpos_reset($game_temp.player_new_x,$game_temp.player_new_y)

    @oneventdata[$game_temp.player_new_x,$game_temp.player_new_y] = 1

    time = 0

    for i in @map.events.keys.sort

      time += 1

      if time%100 == 0

        Graphics.update

      end

      # Event installation type >> P-Fixed(Highest priority)

      case event_settype(i)

      when 3

        @oneventdata[@map.events[i].x,@map.events[i].y] = 1

      end

    end

    for i in @map.events.keys.sort

      time += 1

      if time%100 == 0

        Graphics.update

      end

      # Event installation type >> Relay point

      case event_settype(i)

      when 1

        set_defeventpos(i,@map.events[i].x,@map.events[i].y)

        @oneventdata[@map.events[i].x,@map.events[i].y] = 1

      end

    end

    # Adjusting the position of the event

    for i in @map.events.keys.sort

      time += 1

      if time%100 == 0

        Graphics.update

      end

      j = event_settype(i)

      case j

      when 0  # Random

        set_defeventpos(i,rand(@map.width-4)+2,rand(@map.width-4)+2)

        @oneventdata[@map.events[i].x,@map.events[i].y] = 1

      when 2  # Fixed

        set_defeventpos(i,@map.events[i].x,@map.events[i].y)

        @oneventdata[@map.events[i].x,@map.events[i].y] = 1

      when 100..199  # Wall installation

        set_defeventpos_wall(i,rand(@map.width-4)+2,rand(@map.width-4)+2,j-100)

        @oneventdata[@map.events[i].x,@map.events[i].y] = 1

        @oneventdata[@map.events[i].x,@map.events[i].y-1] = 1

        for k in 1..(j-100)

          @oneventdata[@map.events[i].x+k,@map.events[i].y] = 1

          @oneventdata[@map.events[i].x+k,@map.events[i].y-1] = 1

          @oneventdata[@map.events[i].x-k,@map.events[i].y] = 1

          @oneventdata[@map.events[i].x-k,@map.events[i].y-1] = 1

        end

      when 200..299  # Wall installation fixing

        set_defeventpos_wall(i,@map.events[i].x,@map.events[i].y,j-200)

        @oneventdata[@map.events[i].x,@map.events[i].y] = 1

        @oneventdata[@map.events[i].x,@map.events[i].y-1] = 1

        for k in 1..(j-200)

          @oneventdata[@map.events[i].x+k,@map.events[i].y] = 1

          @oneventdata[@map.events[i].x+k,@map.events[i].y-1] = 1

          @oneventdata[@map.events[i].x-k,@map.events[i].y] = 1

          @oneventdata[@map.events[i].x-k,@map.events[i].y-1] = 1

        end

      end

    end

    # The obstacle is put in place

    for i in 0...(rand(objcnt)+objcnt/2)

      time += 1

      if time%500 == 0

        Graphics.update

      end

      j = rand(@map.width)

      k = rand(@map.width)

      case rand(10)

      when 0..4

        if standable_newtile?(1,0)

          set_mapdata(j,k,1,0,6) if standable?(j,k)

        else

          set_mapdata(j,k,1,0,6) if standable2?(j,k)

        end

      when 5..7

        if standable_newtile?(2,0)

          set_mapdata(j,k,2,0,6) if standable?(j,k)

        else

          set_mapdata(j,k,2,0,6) if standable2?(j,k)

        end

      when 8..9

        if standable2?(j,k)

          if @map.data[j,k-1,2]==0 and

            (@map.data[j,k,1]==0 or @map.data[j,k,2]==0)

            set_mapdata(j,k,2,2,4)    # 4>6?

            set_mapdata(j,k-1,2,1,4)  # 4>2?

          end

        end

      end

    end

    # Contents opening of variable(It is done now kana?)

    @heightdata.resize(0,0)

    @maskdata.resize(0,0)

    @oneventdata.resize(0,0)

    @masksetting.clear

    @makedata.clear

    @tilesetting.resize(0,0,0)

    # If the map save feature is enabled

    if TONBI_AUTO_MAP_SAVE != nil

      # Retention system

      save_data(@map,sprintf("Data/Map%03d.rxdata", TONBI_AUTO_MAP_SAVE))

      maplist  = load_data("Data/MapInfos.rxdata")

      mapinfo = RPG::MapInfo.new

      mapinfo.name = sprintf("Random automatic saving(%s)", maplist[@map_id].name)

      mapinfo.parent_id = 0

      mapinfo.order = TONBI_AUTO_MAP_SAVE

      mapinfo.expanded = true

      mapinfo.scroll_x = 0

      mapinfo.scroll_y = 0

      

      maplist[TONBI_AUTO_MAP_SAVE]=mapinfo

      save_data(maplist,"Data/MapInfos.rxdata")

    end

  end

  #--------------------------------------------------------------------------

  # * Position type acquisition of event

  #--------------------------------------------------------------------------

  def event_settype(i)

    return 1 if @map.events[i].subname == "Relay"

    return 2 if @map.events[i].subname == "Fixed"

    return 3 if @map.events[i].subname == "P-Fixed"

    for j in 0..1000

      if @map.events[i].pages[0].list[j].code != 108

        break

      end

      # If the relay point it is in comment

      return 1 if @map.events[i].pages[0].list[j].parameters[0].split(/,/)[0] == "Relay"

      # If Fixed it is in comment

      return 2 if @map.events[i].pages[0].list[j].parameters[0].split(/,/)[0] == "Fixed"

      # If P-Fixed it is in comment

      return 3 if @map.events[i].pages[0].list[j].parameters[0].split(/,/)[0] == "P-Fixed"

      # If Wall it is in comment

      if @map.events[i].pages[0].list[j].parameters[0].split(/,/)[0] == "Wall"

        if @map.events[i].pages[0].list[j].parameters[0].split(/,/)[1] == nil

          return 100

        else

          k = @map.events[i].pages[0].list[j].parameters[0].split(/,/)[1]

          k = k.to_i

          return 100+k

        end

      end

      # If P-Wall is in comment

      if @map.events[i].pages[0].list[j].parameters[0].split(/,/)[0] == "P-Wall"

        if @map.events[i].pages[0].list[j].parameters[0].split(/,/)[1] == nil

          return 200

        else

          k = @map.events[i].pages[0].list[j].parameters[0].split(/,/)[1]

          k = k.to_i

          return 200+k

        end

      end

    end

    return 0

  end

  #--------------------------------------------------------------------------

  # * Event installation near designated position

  #--------------------------------------------------------------------------

  def set_defeventpos(id,x,y)

    if standable2?(x,y)

      @map.events[id].x=x

      @map.events[id].y=y

      return

    end

    for i in 1..([@map.width,@map.height].max)

      if standable2?(x,y+i)

        @map.events[id].x=x

        @map.events[id].y=y+i

        return

      end

      for j in 1..i

        if standable2?(x-j,y+i)

          @map.events[id].x=x-j

          @map.events[id].y=y+i

          return

        end

        if standable2?(x+j,y+i)

          @map.events[id].x=x+j

          @map.events[id].y=y+i

          return

        end

        if standable2?(x-j,y-i)

          @map.events[id].x=x-j

          @map.events[id].y=y-i

          return

        end

        if standable2?(x+j,y-i)

          @map.events[id].x=x+j

          @map.events[id].y=y-i

          return

        end

      end

    end

  end

  #--------------------------------------------------------------------------

  # * Event installation to wall near designated position

  #     p4   Width

  #--------------------------------------------------------------------------

  def set_defeventpos_wall(id,x,y,p4)

    if standable3?(x,y,p4)

      @map.events[id].x=x

      @map.events[id].y=y

      return

    end

    for i in 1..([@map.width,@map.height].max)

      if standable3?(x,y+i,p4)

        @map.events[id].x=x

        @map.events[id].y=y+i

        return

      end

      for j in 1..i

        if standable3?(x-j,y+i,p4)

          @map.events[id].x=x-j

          @map.events[id].y=y+i

          return

        end

        if standable3?(x+j,y+i,p4)

          @map.events[id].x=x+j

          @map.events[id].y=y+i

          return

        end

        if standable3?(x-j,y-i,p4)

          @map.events[id].x=x-j

          @map.events[id].y=y-i

          return

        end

        if standable3?(x+j,y-i,p4)

          @map.events[id].x=x+j

          @map.events[id].y=y-i

          return

        end

      end

    end

  end

  #--------------------------------------------------------------------------

  # * Prayer installation near designated position

  #--------------------------------------------------------------------------

  def playerpos_reset(x,y)

    if standable?(x,y)

      $game_temp.player_new_x=x

      $game_temp.player_new_y=y

      return

    end

    for i in 1..([@map.width,@map.height].max)

      if standable?(x,y+i)

        $game_temp.player_new_x=x

        $game_temp.player_new_y=y+i

        return

      end

      for j in 0..i

        if standable?(x-j,y+i)

          $game_temp.player_new_x=x-j

          $game_temp.player_new_y=y+i

          return

        end

        if standable?(x+j,y+i)

          $game_temp.player_new_x=x+j

          $game_temp.player_new_y=y+i

          return

        end

        if standable?(x-j,y-i)

          $game_temp.player_new_x=x-j

          $game_temp.player_new_y=y-i

          return

        end

        if standable?(x+j,y-i)

          $game_temp.player_new_x=x+j

          $game_temp.player_new_y=y-i

          return

        end

      end

    end

  end

  #--------------------------------------------------------------------------

  # * You can pass by your?(Obstacle tile)

  #     p1,p2 Position X,Y

  #--------------------------------------------------------------------------

  def standable_newtile?(p1,p2)

    for i in [2, 1, 0]

      tile_id = @tilesetting[p1, p2, i]

      if tile_id == nil

        return false

      elsif @passages[tile_id] & 0x0f == 0x0f

        return false

      elsif @priorities[tile_id] == 0

        return true

      end

    end

    return true

  end

  #--------------------------------------------------------------------------

  # * It can stand to designated position?

  #     p1,p2 Position X,Y

  #--------------------------------------------------------------------------

  def standable?(p1,p2)

    if @heightdata[p1,p2] != 0

      return false

    end

    if @oneventdata[p1,p2] ==1

      return false

    end

    for i in [2, 1, 0]

      tile_id = @map.data[p1, p2, i]

      if tile_id == nil

        return false

      elsif @passages[tile_id] & 0x0f == 0x0f

        return false

      elsif @priorities[tile_id] == 0

        return true

      end

    end

    return true

  end

  #--------------------------------------------------------------------------

  # * Putting on designated position, all right?(Consideration edition such as event around)

  #     p1,p2 Position X, Y

  #--------------------------------------------------------------------------

  def standable2?(p1,p2)

    # The position decision

    unless standable?(p1,p2)

      return false

    end

    # Event check around (it doesn't become dead end?)

    #It passes through to length, the [re] [ru]?

    if standable?(p1+1,p2-1) == false or

      standable?(p1+1,p2) == false or

      standable?(p1+1,p2+1) == false

      if standable?(p1-1,p2-1) == false or

        standable?(p1-1,p2) == false or

        standable?(p1-1,p2+1) == false

        # Originally when it passes through to length and there is no [re] disregard

        if standable?(p1,p2-1) == true and

          standable?(p1,p2+1) == true

          return false

        end

      end

    end

    # It passes through to side, the [re] [ru]?

    if standable?(p1+1,p2+1) == false or

      standable?(p1,p2+1) == false or

      standable?(p1-1,p2+1) == false

      if standable?(p1+1,p2-1) == false or

        standable?(p1,p2-1) == false or

        standable?(p1-1,p2-1) == false

        # Originally when it passes through to side and there is no [re] disregard

        if standable?(p1-1,p2) == true and

          standable?(p1+1,p2) == true

          return false

        end

      end

    end

    if standable?(p1,p2-1) == false and

      (standable?(p1-1,p2+1) == false or 

      standable?(p1,p2+1) == false or

      standable?(p1+1,p2+1) == false)

      return false

    end

    if standable?(p1,p2+1) == false and

      (standable?(p1-1,p2-1) == false or 

      standable?(p1+1,p2-1) == false or

      standable?(p1+1,p2-1) == false)

      return false

    end

    if standable?(p1-1,p2) == false and

      (standable?(p1+1,p2-1) == false or 

      standable?(p1+1,p2) == false or

      standable?(p1+1,p2+1) == false)

      return false

    end

    if standable?(p1+1,p2) == false and

      (standable?(p1-1,p2-1) == false or 

      standable?(p1-1,p2) == false or

      standable?(p1-1,p2+1) == false)

      return false

    end

    return true

  end

  #--------------------------------------------------------------------------

  # * Putting on wall edition designated position, all right?(Wall edition)

  #     p1,p2 Position X, Y

  #     p3    Width

  #--------------------------------------------------------------------------

  def standable3?(p1,p2,p3)

    # If the bottom cannot stand originally, failure

    unless standable?(p1,p2+1)

      return false

    end

    # The position decision

    if @oneventdata[p1,p2] == 1 or

      @oneventdata[p1,p2-1] == 1 or

      @heightdata[p1,p2-2] != 1 or

      @heightdata[p1,p2-1] == 1 or

      @heightdata[p1,p2+1] != 0

      return false

    end

    for i in 1...p3+1

      if@heightdata[p1+i,p2-2] != 1 or

        @heightdata[p1+i,p2-1] == 1 or

        @heightdata[p1+i,p2+1] != 0

        return false

      end

      if@heightdata[p1-i,p2-2] != 1 or

        @heightdata[p1-i,p2-1] == 1 or

        @heightdata[p1-i,p2+1] != 0

        return false

      end

    end

    for i in 1...p3+1

      if @oneventdata[p1+i,p2] == 1 or

        @oneventdata[p1+i,p2-1] == 1

        return false

      end

      if @oneventdata[p1-i,p2] == 1 or

        @oneventdata[p1-i,p2-1] == 1

        return false

      end

    end

    return true

  end

  #--------------------------------------------------------------------------

  # * Map tile information modification

  #     p1,p2 Position ahead writing out X,Y

  #     p3,p4 Original reference positionX,Y

  #     p5  Insertion method 0:Normality 1:Lower layer 2:Upper layer 3:From under 4:From above 5:Both

  #--------------------------------------------------------------------------

  def set_mapdata(p1,p2,p3,p4,p5 = 0)

    unless self.valid?(p1, p2)

      return

    end

    if @tilesetting[p3,p4,0] != 0 # You put in place the layer 0 normally

      @map.data[p1,p2,0] = @tilesetting[p3,p4,0]

    end

    case p5

    when 0 # Normality

      if @tilesetting[p3,p4,1] != 0

        @map.data[p1,p2,1] = @tilesetting[p3,p4,1]

      end

      if @tilesetting[p3,p4,2] != 0

        @map.data[p1,p2,2] = @tilesetting[p3,p4,2]

      end

    when 1 # You place under

      if @tilesetting[p3,p4,1] != 0

        @map.data[p1,p2,1] = @tilesetting[p3,p4,1]

      end

    when 2 # You place on

      if @tilesetting[p3,p4,1] != 0

        @map.data[p1,p2,2] = @tilesetting[p3,p4,1]

      end

    when 3 # You put from under

      if @tilesetting[p3,p4,1] != 0

        if @map.data[p1,p2,1] != 0

          @map.data[p1,p2,2] = @map.data[p1,p2,1]

        end

        @map.data[p1,p2,1] = @tilesetting[p3,p4,1]

      end

    when 4 # You put from above

      if @tilesetting[p3,p4,1] != 0

        if @map.data[p1,p2,2] != 0

          @map.data[p1,p2,1] = @map.data[p1,p2,2]

        end

        @map.data[p1,p2,2] = @tilesetting[p3,p4,1]

      end

    when 5 # You place in both

      if @tilesetting[p3,p4,1] != 0

        @map.data[p1,p2,1] = @tilesetting[p3,p4,1]

      end

      if @tilesetting[p3,p4,1] != 0

        @map.data[p1,p2,2] = @tilesetting[p3,p4,1]

      end

    when 6 # You can put, if you put

      if @map.data[p1,p2,1] == 0

        @map.data[p1,p2,1] = @tilesetting[p3,p4,1]

      elsif @map.data[p1,p2,2] == 0

        @map.data[p1,p2,2] = @tilesetting[p3,p4,1]

      end

    end

  end

  #--------------------------------------------------------------------------

  # * Map tile information modification 2 >>There is no decision and the like outside the range ver

  #     p1,p2 Position ahead writing out X,Y

  #     p3,p4 Original reference position,Y

  #--------------------------------------------------------------------------

  def set_mapdata2(p1,p2,p3,p4)

    @map.data[p1,p2,0] = @tilesetting[p3,p4,0]

    @map.data[p1,p2,1] = @tilesetting[p3,p4,1]

    @map.data[p1,p2,2] = @tilesetting[p3,p4,2]

  end

  #--------------------------------------------------------------------------

  # * Information modification of designated position

  #     p1,p2 Position X,Y

  #     p3    Value

  #--------------------------------------------------------------------------

  def set_height(p1,p2,p3)

    return if p1<0

    return if p1>=@map.width

    return if p2<0

    return if p2>=@map.height

    @heightdata[p1,p2]=p3

  end

  #--------------------------------------------------------------------------

  # * Information modification of designated position

  #     p1,p2 Position X,Y

  #     p3    Value

  #--------------------------------------------------------------------------

  def set_grounddata(p1,p2,p3)

    return if p1<0

    return if p1>=@map.width

    return if p2<0

    return if p2>=@map.height

    if @masksetting[@maskdata[p1,p2]] == true

      if @targettype==0

        if @chgtype==0

          @heightdata[p1,p2]=p3

        elsif @chgtype==1

          @heightdata[p1,p2]+=p3

        end

      elsif @targettype==1

        if @chgtype==0

          @maskdata[p1,p2]=p3

        elsif @chgtype==1

          @maskdata[p1,p2]+=p3

        end

      end

    end

  end

  #--------------------------------------------------------------------------

  # * Operation methodological appointment

  #     p1  Object   >> =0:Height =1:Topography  (Presently, height 0=Land 1=Wall)

  #     p2  M Method >> =0:Substitution =1:Addition As for topography in only mask decision use

  #--------------------------------------------------------------------------

  def rndmap_chtarget(p1,p2)

    @targettype=p1

    @chgtype=p2

  end

  #--------------------------------------------------------------------------

  # * Set the value used in other commands

  #     p1,p2 Smallest X,Y

  #     p3,p4 Maximum X,Y  You use for the start point and end point set etc of road production

  #--------------------------------------------------------------------------

  def rndmap_setstat(p1,p2,p3,p4)

    @minx=p1

    @miny=p2

    @maxx=p3

    @maxy=p4

  end

  #--------------------------------------------------------------------------

  # * Set the topographical mask

  #     p1 = Object topography  (-1= Entirely)

  #     p2 = Modification value (0= Prohibed  1= Permitted  2=Topography only)

  #--------------------------------------------------------------------------

  def rndmap_chmask(p1,p2)

    if p1>=0

      if p2==0

        @masksetting[p1]=false

      elsif p2 == 1

        @masksetting[p1]=true

      elsif p2 == 2

        for i in 0...100

          @masksetting[i]=false

        end

        @masksetting[p1]=true

      end

    end

    if p1==-1

      if p2==0

        for i in 0...100

          @masksetting[i]=false

        end

      else   

        for i in 0...100

          @masksetting[i]=true

        end

      end

    end

  end

  #--------------------------------------------------------------------------

  # * Make the road connection points

  #     Set starting and end points with the rndmap_setstat method.

  #     p1 = Writing the value which is changed

  #     p2 = If halfway score (0 map size 40*40 in standard relative change)

  #     p3 = The width which is guaranteed in the deep water

  #     p4 = How to tie the halfway point (0=You tie in the straight line  1=Perpendicular line (?)So you tie)

  #     p5 = Distance of the relay point which you ignore

  #--------------------------------------------------------------------------

  def rndmap_mkroad(p1,p2,p3,p4,p5 = 5)

    p5 = 5 if p5 == nil

    localdata = Table.new(@map.width,@map.height)

    aposx = []

    aposy = []

    aflag = []

    for i in [email=0...@map.width]0...@map.width[/email]

      for j in [email=0...@map.height]0...@map.height[/email]

        localdata[i,j] = 0

      end

    end

    p2 = (p2*-1) * @map.width * @map.height / 40 / 40 if p2 < 0    

    aposx[0]=@minx

    aposy[0]=@miny

    aposx[1]=@maxx

    aposy[1]=@maxy

    aposx[0]=@map.width+aposx[0]              if aposx[0]<0

    aposx[0]=@map.width*(aposx[0]-1000)/100   if (aposx[0]>=1000) and (aposx[0]<=1100)

    aposy[0]=@map.height+aposy[0]             if aposy[0]<0

    aposy[0]=@map.height*(aposy[0]-1000)/100  if (aposy[0]>=1000) and (aposy[0]<=1100)

    aposx[1]=@map.width+aposx[1]              if aposx[1]<0

    aposx[1]=@map.width*(aposx[1]-1000)/100   if (aposx[1]>=1000) and (aposx[1]<=1100)

    aposy[1]=@map.height+aposy[1]             if aposy[1]<0

    aposy[1]=@map.height*(aposy[1]-1000)/100  if (aposy[1]>=1000) and (aposy[1]<=1100)

    if p4==0 or p4==1 or p4==2

      i4 = rand(2) if p4 == 2

      aflag[0] = true

      aflag[1] = false

      for i in 2...(p2+2)

        aposx[i] = rand(@map.width-p3*2) + p3

        aposy[i] = rand(@map.height-p3*2) + p3

        aflag[i] = false

      end

      i3=0

      i1=aposx[i3]

      i2=aposy[i3]

      localdata[i1,i2] = 1

      for i in 0...p2+2

        i7=5000000

        for j in 0...p2+2

          if aflag[j] == false

            i4 = aposx[j]-i1

            i4=i4*-1 if i4 < 0

            i5 = aposy[j]-i2

            i5=i5*-1 if i5 < 0

            if (i4**2+i5**2) <=(p5**2) and j != 1

              aflag[j] = true

            elsif i7 > (i4**2+i5**2)

              i7=(i4**2+i5**2)

              i6=j

            end

          end

        end

        #  Starting point ID:i3   End point ID:i6

        if p4==0

          if aposx[i3] > aposx[i6]

            i8 = aposx[i3]

            i9 = aposy[i3]

            i10 = aposx[i6]

            i11 = aposy[i6]

          else

            i8 = aposx[i6]

            i9 = aposy[i6]

            i10 = aposx[i3]

            i11 = aposy[i3]

          end

          if i8!=i10

            for i in 0..(i8-i10)

              localdata[i+i10,(i9-i11)*i/(i8-i10)+i11] = 1

            end

          end

          if aposy[i3] > aposy[i6]

            i8 = aposx[i3]

            i9 = aposy[i3]

            i10 = aposx[i6]

            i11 = aposy[i6]

          else

            i8 = aposx[i6]

            i9 = aposy[i6]

            i10 = aposx[i3]

            i11 = aposy[i3]

          end

          if i9!=i11

            for i in 0..(i9-i11)

              localdata[(i8-i10)*i/(i9-i11)+i10,i+i11] = 1

            end

          end

        end

        if p4==1

          i4 = rand(2)

          if i4==0

            for i in 0..([aposx[i3]-aposx[i6],aposx[i6]-aposx[i3]].max)

              localdata[i+[aposx[i3],aposx[i6]].min,aposy[i3]] = 1

            end

            for i in 0..([aposy[i3]-aposy[i6],aposy[i6]-aposy[i3]].max)

              localdata[aposx[i6],i+[aposy[i3],aposy[i6]].min] = 1

            end

          else

            for i in 0..([aposx[i3]-aposx[i6],aposx[i6]-aposx[i3]].max)

              localdata[i+[aposx[i3],aposx[i6]].min,aposy[i6]] = 1

            end

            for i in 0..([aposy[i3]-aposy[i6],aposy[i6]-aposy[i3]].max)

              localdata[aposx[i3],i+[aposy[i3],aposy[i6]].min] = 1

            end

          end

        end

        i3=i6

        i1=aposx[i3]

        i2=aposy[i3]

        aflag[i3]=true

        break if i3==1

      end

    end

    for i in [email=0...@map.width]0...@map.width[/email]

      for j in [email=0...@map.height]0...@map.height[/email]

        set_grounddata(i,j,p1) if localdata[i,j] == 1

      end

    end

  end

  #--------------------------------------------------------------------------

  # * Expanding the object

  #     p1       Object

  #     p2,p3    The width which it expands X,Y

  #     p4       Extended method (0=Cross  1=Square)

  #--------------------------------------------------------------------------

  def rndmap_plus(p1, p2, p3, p4)

    localdata = Table.new(@map.width,@map.height)

    for i in [email=0...@map.width]0...@map.width[/email]

      for j in [email=0...@map.height]0...@map.height[/email]

        if @targettype==0

          localdata[i,j] = @heightdata[i,j]

        elsif @targettype==1

          localdata[i,j] = @maskdata[i,j]

        end

      end

    end

    if p4 == 0

      for i in [email=0...@map.width]0...@map.width[/email]

        for j in [email=0...@map.height]0...@map.height[/email]

          if p1==localdata[i,j]

            for k in 1..p2

              set_grounddata(i+k,j,p1)

              set_grounddata(i-k,j,p1)

            end

            for k in 1..p3

              set_grounddata(i,j+k,p1)

              set_grounddata(i,j-k,p1)

            end

          end

        end

      end

    elsif p4 == 1

      for i in [email=0...@map.width]0...@map.width[/email]

        for j in [email=0...@map.height]0...@map.height[/email]

          if p1==localdata[i,j]

            for k in (i-p2)..(i+p2)

              for l in (j-p3)..(j+p3)

                set_grounddata(k,l,p1)

              end

            end

          end

        end

      end

    end

  end

  #--------------------------------------------------------------------------

  # * It sets entirely

  #     p1       Value

  #--------------------------------------------------------------------------

  def rndmap_allchg(p1)

    for i in [email=0...@map.width]0...@map.width[/email]

      for j in [email=0...@map.height]0...@map.height[/email]

        set_grounddata(i,j,p1)

      end

    end

  end

  #--------------------------------------------------------------------------

  # * Designated point

  #     p1       Value

  #     p2,p3    Position X,Y

  #--------------------------------------------------------------------------

  def rndmap_putpos(p1, p2, p3)

    i = rand(@maxx-@minx+1)+@minx

    j = rand(@maxy-@miny+1)+@miny

    for k in (p2-i)..(p2+i)

      for l in (p3-j)..(p3+j)

        set_grounddata(k,l,p1)

      end

    end

  end

  #--------------------------------------------------------------------------

  # * Around

  #     p1       Value

  #--------------------------------------------------------------------------

  def rndmap_edge(p1)

    for i in [email=0...@map.width]0...@map.width[/email]

      set_grounddata(i,0,p1)

      set_grounddata(i,@map.height-1,p1)

    end

    for i in [email=0...@map.height]0...@map.height[/email]

      set_grounddata(0,i,p1)

      set_grounddata(@map.width-1,i,p1)

    end

  end

end

 

 

 

#==============================================================================

# ** RPG::MapInfo >> Sub name..","Thing of letter of later subname Acquisition

#==============================================================================

module RPG

  class MapInfo

    #------------------------------------------------------------------------

    # * Name

    #------------------------------------------------------------------------    

    def name

      name = @name.split(/,/)[0]

      return name != nil ? name : ''

    end

    #------------------------------------------------------------------------

    # * Name=

    #     str : string value

    #------------------------------------------------------------------------    

    def name=(str)

      str2 = @name[/^[^,]*(,.*)/, 1]

      @name = str2 != nil ? str + str2 : str

    end

    #------------------------------------------------------------------------

    # * Subname

    #     i : split position integer

    #------------------------------------------------------------------------    

    def subname(i = 1)

      name = @name.split(/,/)[i]

      return name != nil ? name : ""

    end

  end

end

 

 

 

#==============================================================================

# ** RPG::Event >>Sub name. " " Thing of letter of later subname Acquisition

#==============================================================================

module RPG

  class Event

    #------------------------------------------------------------------------

    # * Name

    #------------------------------------------------------------------------    

    def name

      name = @name.split(/,/)[0]

      return name != nil ? name : ''

    end

    #------------------------------------------------------------------------

    # * Name=

    #     str : string value

    #------------------------------------------------------------------------    

    def name=(str)

      str2 = @name[/^[^,]*(,.*)/, 1]

      @name = str2 != nil ? str + str2 : str

    end

    #------------------------------------------------------------------------

    # * Subname

    #     i : split position integer

    #------------------------------------------------------------------------    

    def subname(i = 1)

      name = @name.split(/,/)[i]

      return name != nil ? name : ""

    end

  end

end
 

MarkR

Member

Could you post a demo in which the error occurs? I tried adding the script to a project of mine, but I'm not sure how to activate the script.

You could also use this code and post the messages you get before the error occurs. ;)
Code:
 

class Game_Character

  #--------------------------------------------------------------------------

  # * Move to nearest passable tile

  #--------------------------------------------------------------------------

  def move_to_nearest_tile(x = @x, y = @y)

    tile = get_nearest_tile(x, y)

    p tile

    p tile[0], tile[1]

    self.moveto(tile[0], tile[1]) unless tile.nil?

  end

end

 
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top