#_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_
#_/ ? Tileset Extension - KGC_TilesetExtension ? VX ?
#_/ ? Last Update: 2008/07/13 ?
#_/ ? Translation by Mr. Anonymous ?
#_/ ?
http://ytomy.sakura.ne.jp/ ?
#_/-----------------------------------------------------------------------------
#_/ This script restores some functionanlity pertaining to tilesets that were
#_/ originally included in previous RPG Makers.
#_/
#_/ ? Restored Functions ?
#_/ 1. Tilesets may be changed to different tileset files.
#_/ 2. 4-way Directional Passability
#_/ 3. Terrain tags. (Up to 99!)
#_/
#_/ Note: When the tileset is changed, it DOES NOT appear within the editor.
#_/ You may want to open the image in an external viewer for reference.
#_/-----------------------------------------------------------------------------
#_/ ? 2008/07/13 UPDATE [KGC] ?
#_/ Bugfix relating to loading extra tilesets.
#_/-----------------------------------------------------------------------------
#_/ ? 2008/05/29 UPDATE [MRA] ?
#_/ Added a method to designate a variable within the customization block of
#_/ this script that stores the terrain tag the player is currently standing
#_/ on. This should help a small bit with lag caused by parallel processes.
#_/=============================================================================
#_/ ? Instructions For Usage ?
#_/ To set up the 4-way directional passability properties and the terrain tag
#_/ features on a given tile, use the VXTilesetTool located in the Tileset Tool
#_/ folder of this project.
#_/
#_/ The following tags are to be entered after a map's name.
#_/ [SET "PresetName"]
#_/ Refer to the customization block to understand this feature.
#_/
#_/ [INHERIT]
#_/ Uses the same tileset settings as the parent map.
#_/
#_/ ? Script Commands ?
#_/ These commands are used in the "Script" function in the third page of event
#_/ commands under "Advanced". These commands are all terrain-related.
#_/
#_/ * get_terrain_tag(x, y, variable_id)
#_/ Obtains the terrain tag at the specified x/y coordinates and stores it
#_/ in the designated variable.
#_/
#_/ * get_event_terrain_tag(event_id, variable_id)
#_/ Obtains the terrain tag where a specified event is located and stores
#_/ it in the designated variable.
#_/
#_/ * get_player_terrain_tag(variable_id)
#_/ Obtains the terrain tag where a player is currently located and it in
#_/ the designated variable.
#_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_
#==============================================================================#
# ? Customization ? #
#==============================================================================#
module KGC
module TilesetExtension
# ? Required Text String Prefix ?
# This is the text string the script searches for in regards to tilesets in
# your "Graphics\System" folder.
TILE_IMAGE_PREFIX = "Tile"
# ? Player Terrain Tag Variable ?
# The current terrain tag that the player is standing on is stored here.
PLAYER_TERRAIN_TAG = 1
# ? Tileset Image Preset ?
TILE_PRESET = {} # ? Do not remove or alter this!
# The custom tilesets are defined below.
# In this example, the script would search for images in the system folder
# labeled XN-Castle, and appoints the appropriate tile category by name.
# Where X = Tile Category(A,B,C,D,E) Where N = Sub autotile Number
# Also of note that the text that appears after TILE_PRESET in the brackets []
# is what designates your preset Tile groupings.
# So all the tilesets defined after ["Castle"] in the example are bound to
# the "Castle" tag.
#
# TILE_PRESET["Castle"] = {
# "A1"=>"A1-Castle",
# "A2"=>"A2-Castle",
# "B"=>"B-Castle",
# "D"=>"D-Castle",
# }
#
# By entering [SET Castle] to the end of a map's name (in Map Properties), the
# map would use the tiles defined in the above expression for that particular
# map instead of the default tiles A1, A2, B, and D.
# ? Insert Custom Tileset Presets Below ?
# Note: The following is used as a sample for the Black and White Forest
# section of the KGC library demo. Please alter this to your needs.
TILE_PRESET["BW"] = {
"A1"=>"A1-BW",
"A2"=>"A2-BW",
"A3"=>"A3-BW",
"A4"=>"A4-BW",
"A5"=>"A5-BW",
"B"=>"B-BW",
"C"=>"C-BW",
"D"=>"D-BW",
}
# ? Insert Custom Tileset Presets Above ?
# ? Four-way Direction Passage and Terrain Tag Button ?
# (For debugging only, available in playtesting mode)
# To indicate the four-way directional passage setting of the current tile,
# you'd press this key (F7 by default).
# The terrain features tag is displayed in a popup dialog box.
# This function becomes invalid when setting it to nil.
DEBUG_INFO_BUTTON = Input::F7
end
end
#------------------------------------------------------------------------------#
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * #
# Unless you know what you're doing, it's best not to alter anything beyond #
# this point, as this only affects the tags used for the Map name and how #
# the script sets up the extra Tile sets. #
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * #
$imported = {} if $imported == nil
$imported["TilesetExtension"] = true
if $data_mapinfos == nil
$data_mapinfos = load_data("Data/MapInfos.rvdata")
end
# Direction Flag Module(for four-way directional passability)
module DirectionFlag
DOWN = 0x01
LEFT = 0x02
RIGHT = 0x04
UP = 0x08
end
module KGC::TilesetExtension
# File name of extended tile set data.
EX_RVDATA = "TilesetEx.rvdata"
# Regular Expressions Defined
module Regexp
# Inherit tag string
INHERIT = /\[INHERIT\]/i
# Preset tag string
PRESET = /\[SET ([\w\-]+)\]/i
end
# Default tile set file names
# "File Suffix"=>"Full Filename"
DEFAULT_FILENAME = {
"A1"=>"TileA1", # This is the first and second rows of autotiles
"A2"=>"TileA2", # This is the 3rd-6th rows of autotiles
"A3"=>"TileA3", # This is the 7th-10th rows of autotiles
"A4"=>"TileA4", # This is the 11th-16th of the autotiles.
"A5"=>"TileA5", # This is the rest of the TileA tiles.
"B"=>"TileB", # TileB tiles.
"C"=>"TileC", # TileC tiles.
"D"=>"TileD", # TileD tiles.
"E"=>"TileE" # TileE tiles.
}
@@__filename = DEFAULT_FILENAME.dup
module_function
#--------------------------------------------------------------------------
# ? Initialize Tileset Filename
# map_id : Map ID
#--------------------------------------------------------------------------
def init_tileset_filename(map_id)
@@__filename = get_converted_tileset_filename(map_id)
end
#--------------------------------------------------------------------------
# ? Get Convertered Tileset Filename
# map_id : Map ID
#--------------------------------------------------------------------------
def get_converted_tileset_filename(map_id)
info = $data_mapinfos[map_id]
name = info.original_name
filename = DEFAULT_FILENAME.dup
if name =~ Regexp::INHERIT
# Retrieve parent map ID
parent_id = $data_mapinfos[map_id].parent_id
if parent_id > 0
filename = get_converted_tileset_filename(parent_id)
end
end
# Jump to Convert Tileset Filename method
return convert_tileset_filename(filename, name)
end
#--------------------------------------------------------------------------
# ? Convert Tileset Filename
# filename : Image Filename (Hash)
# map_name : Map Name
#--------------------------------------------------------------------------
def convert_tileset_filename(filename, map_name)
name_buf = filename.dup
# Determine Preset
presets = map_name.scan(Regexp::PRESET)
presets.each { |s|
if TILE_PRESET.has_key?(s[0])
TILE_PRESET[s[0]].each { |k, v|
name_buf[k] = TILE_IMAGE_PREFIX + v
}
end
}
# Convert Map Name
DEFAULT_FILENAME.keys.each { |key|
if map_name =~ /\[#{key} ([\w\-]+)\]/
name_buf[key] = TILE_IMAGE_PREFIX + $1
end
}
return name_buf
end
#--------------------------------------------------------------------------
# ? Get Tileset Filename
#--------------------------------------------------------------------------
def get_tileset_filename
return @@__filename
end
end
#==============================================================================
# ? KGC::Commands
#==============================================================================
module KGC::Commands
module_function
#--------------------------------------------------------------------------
# ? Get Terrain Tag
# x : X Coordinate of Map
# y : Y Coordinate of Map
# variable_id : In-Game Variable ID
#--------------------------------------------------------------------------
def get_terrain_tag(x, y, variable_id = 0)
tag = $game_map.terrain_tag(x, y) # Assign the X/Y coordinate
if variable_id > 0
$game_variables[variable_id] = tag # Assign the tag to the variable
end
return tag
end
#--------------------------------------------------------------------------
# ? Get Event Terrain tag
# event_id : Event ID
# variable_id : In-Game Variable ID
#--------------------------------------------------------------------------
def get_event_terrain_tag(event_id, variable_id = 0)
event = $game_map.events.values.find { |e| e.id == event_id }
if event == nil
# If there is no event, the value is set to 0.
tag = 0
else
tag = $game_map.terrain_tag(event.x, event.y)
end
# If the variable is assigned, the tag is stored there.
if variable_id > 0
$game_variables[variable_id] = tag
end
return tag
end
#--------------------------------------------------------------------------
# ? Get Player Terrain Tag
# variable_id : In-Game Variable ID
#--------------------------------------------------------------------------
def get_player_terrain_tag(variable_id = 0)
tag = $game_map.terrain_tag($game_player.x, $game_player.y)
# If the variable is assigned, the tag is stored there.
if variable_id > 0
$game_variables[variable_id] = tag
end
return tag
end
end
class Game_Interpreter
include KGC::Commands
end
#==============================================================================
# ? RPG::MapInfo
#==============================================================================
class RPG::MapInfo
#--------------------------------------------------------------------------
# ? Map Name
#--------------------------------------------------------------------------
def name
return @name.gsub(/\[.*\]/) { "" }
end
#--------------------------------------------------------------------------
# ? Original Map Name
#--------------------------------------------------------------------------
def original_name
return @name
end
end
#==============================================================================
# ? RPG::Tileset
#------------------------------------------------------------------------------
# Define new properties to the Tileset class
#==============================================================================
class RPG::Tileset
#--------------------------------------------------------------------------
# ? Table Size
#--------------------------------------------------------------------------
TABLE_SIZE = 8192 #
#--------------------------------------------------------------------------
# ? Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :version # Map Version
attr_accessor :passages # 4-Way Directional Passages
attr_accessor :terrain_tags # Terrain Tags
#--------------------------------------------------------------------------
# ? Initialize
#--------------------------------------------------------------------------
def initialize
@version = 1
@passages = Table.new(TABLE_SIZE)
@terrain_tags = Table.new(TABLE_SIZE)
end
end
#==============================================================================
# ? Game_Map
#==============================================================================
class Game_Map
LAYERS = [2, 1, 0]
#--------------------------------------------------------------------------
# ? Setup
# map_id : Map ID
#--------------------------------------------------------------------------
alias setup_KGC_TilesetExtension setup
def setup(map_id)
@map_id = map_id
init_tileset_filename
setup_KGC_TilesetExtension(map_id)
end
#--------------------------------------------------------------------------
# ? Initialize Tileset Filename
#--------------------------------------------------------------------------
def init_tileset_filename
KGC::TilesetExtension.init_tileset_filename(@map_id)
end
#--------------------------------------------------------------------------
# ? Define Passage
# x : X Position
# y : Y Position
#--------------------------------------------------------------------------
def passage(x, y)
LAYERS.each { |i|
tile_id = @map.data[x, y, i]
return 0 if tile_id == nil
return $data_tileset.passages[tile_id]
}
return 0
end
#--------------------------------------------------------------------------
# ? Define Terrain Tag
# x : X Position
# y : Y Position
#--------------------------------------------------------------------------
def terrain_tag(x, y)
LAYERS.each { |i|
tile_id = @map.data[x, y, i] #
ID
return 0 if tile_id == nil #
ID
? :
?
tag = $data_tileset.terrain_tags[tile_id] #
?
return tag if tag > 0 #
}
return 0
end
#--------------------------------------------------------------------------
# ? Define Passable Direction Flag
# x : X Position
# y : Y Position
# d : Direction
#--------------------------------------------------------------------------
def passable_dir?(x, y, d)
# ?? (0,2,4,6,8,10) ??
?? (0,1,2,4,8,0)
flag = (1 << (d / 2 - 1)) & 0x0F
LAYERS.each { |i| #
?
tile_id = @map.data[x, y, i] #
ID
return false if tile_id == nil #
ID
? :
?
pass = $data_tileset.passages[tile_id] #
??
return false if pass & flag != 0x00 #
??
}
return true
end
end
#?
??
#==============================================================================
# ? Game_Character
#==============================================================================
class Game_Character
#--------------------------------------------------------------------------
# ?
# x : X ??
# y : Y ??
# d :
? (
: 10)
#--------------------------------------------------------------------------
def passable?(x, y, d = 10)
nx = moved_x(x, d)
ny = moved_y(y, d)
nx = $game_map.round_x(nx) #
??
ny = $game_map.round_y(ny) #
??
return false unless $game_map.valid?(nx, ny) #
??
return true if @through or debug_through? #
? ON?
return false unless map_passable?(x, y, d) #
?
return false unless map_passable?(nx, ny, 10 - d) #
return false if collide_with_characters?(nx, ny) #
?
return true #
end
#--------------------------------------------------------------------------
# ?
? X
?
# x : X ??
# d :
?
#
? X
??
#--------------------------------------------------------------------------
def moved_x(x, d)
return x + (d == 6 ? 1 : d == 4 ? -1 : 0)
end
#--------------------------------------------------------------------------
# ?
? Y
?
# y : Y ??
# d :
?
#
? Y
??
#--------------------------------------------------------------------------
def moved_y(y, d)
return y + (d == 2 ? 1 : d == 8 ? -1 : 0)
end
#--------------------------------------------------------------------------
# ?
# x : X ??
# y : Y ??
# d :
?
#
??
#--------------------------------------------------------------------------
def map_passable?(x, y, d)
return $game_map.passable?(x, y) && $game_map.passable_dir?(x, y, d)
end
#--------------------------------------------------------------------------
# ?
?
# turn_ok :
#--------------------------------------------------------------------------
def move_down(turn_ok = true)
if passable?(@x, @y, 2) #
?
turn_down
@y = $game_map.round_y(@y+1)
@real_y = (@y-1)*256
increase_steps
@move_failed = false
#------------------------------------------------------------------
# ? Check Player's Terrain Tag
# * Added by Mr. Anonymous 5/29/2008
#------------------------------------------------------------------
tag = $game_map.terrain_tag($game_player.x, $game_player.y)
$game_variables[KGC::TilesetExtension::PLAYER_TERRAIN_TAG] = tag
return tag
else #
??
turn_down if turn_ok
check_event_trigger_touch(@x, @y+1) #
??
@move_failed = true
end
end
#--------------------------------------------------------------------------
# ?
?
# turn_ok :
#--------------------------------------------------------------------------
def move_left(turn_ok = true)
if passable?(@x, @y, 4) #
?
turn_left
@x = $game_map.round_x(@x-1)
@real_x = (@x+1)*256
increase_steps
@move_failed = false
#------------------------------------------------------------------
# ? Check Player's Terrain Tag
# * Added by Mr. Anonymous 5/29/2008
#------------------------------------------------------------------
tag = $game_map.terrain_tag($game_player.x, $game_player.y)
$game_variables[KGC::TilesetExtension::PLAYER_TERRAIN_TAG] = tag
return tag
else #
??
turn_left if turn_ok
check_event_trigger_touch(@x-1, @y) #
??
@move_failed = true
end
end
#--------------------------------------------------------------------------
# ?
?
# turn_ok :
#--------------------------------------------------------------------------
def move_right(turn_ok = true)
if passable?(@x, @y, 6) #
?
turn_right
@x = $game_map.round_x(@x+1)
@real_x = (@x-1)*256
increase_steps
@move_failed = false
#------------------------------------------------------------------
# ? Check Player's Terrain Tag
# * Added by Mr. Anonymous 5/29/2008
#------------------------------------------------------------------
tag = $game_map.terrain_tag($game_player.x, $game_player.y)
$game_variables[KGC::TilesetExtension::PLAYER_TERRAIN_TAG] = tag
return tag
else #
??
turn_right if turn_ok
check_event_trigger_touch(@x+1, @y) #
??
@move_failed = true
end
end
#--------------------------------------------------------------------------
# ?
?
# turn_ok :
#--------------------------------------------------------------------------
def move_up(turn_ok = true)
if passable?(@x, @y,
#
?
turn_up
@y = $game_map.round_y(@y-1)
@real_y = (@y+1)*256
increase_steps
@move_failed = false
#------------------------------------------------------------------
# ? Check Player's Terrain Tag
# * Added by Mr. Anonymous 5/29/2008
#------------------------------------------------------------------
tag = $game_map.terrain_tag($game_player.x, $game_player.y)
$game_variables[KGC::TilesetExtension::PLAYER_TERRAIN_TAG] = tag
return tag
else #
??
turn_up if turn_ok
check_event_trigger_touch(@x, @y-1) #
??
@move_failed = true
end
end
#--------------------------------------------------------------------------
# ?
??
#--------------------------------------------------------------------------
def move_lower_left
unless @direction_fix
@direction = (@direction == 6 ? 4 : @direction == 8 ? 2 : @direction)
end
if (passable?(@x, @y, 2) && passable?(@x, @y+1, 4)) ||
(passable?(@x, @y, 4) && passable?(@x-1, @y, 2))
@x -= 1
@y += 1
increase_steps
@move_failed = false
#------------------------------------------------------------------
# ? Check Player's Terrain Tag
# * Added by Mr. Anonymous 5/29/2008
#------------------------------------------------------------------
tag = $game_map.terrain_tag($game_player.x, $game_player.y)
$game_variables[KGC::TilesetExtension::PLAYER_TERRAIN_TAG] = tag
return tag
else
@move_failed = true
end
end
#--------------------------------------------------------------------------
# ?
??
#--------------------------------------------------------------------------
def move_lower_right
unless @direction_fix
@direction = (@direction == 4 ? 6 : @direction == 8 ? 2 : @direction)
end
if (passable?(@x, @y, 2) && passable?(@x, @y+1, 6)) ||
(passable?(@x, @y, 6) && passable?(@x+1, @y, 2))
@x += 1
@y += 1
increase_steps
@move_failed = false
#------------------------------------------------------------------
# ? Check Player's Terrain Tag
# * Added by Mr. Anonymous 5/29/2008
#------------------------------------------------------------------
tag = $game_map.terrain_tag($game_player.x, $game_player.y)
$game_variables[KGC::TilesetExtension::PLAYER_TERRAIN_TAG] = tag
return tag
else
@move_failed = true
end
end
#--------------------------------------------------------------------------
# ?
??
#--------------------------------------------------------------------------
def move_upper_left
unless @direction_fix
@direction = (@direction == 6 ? 4 : @direction == 2 ? 8 : @direction)
end
if (passable?(@x, @y,
&& passable?(@x, @y-1, 4)) ||
(passable?(@x, @y, 4) && passable?(@x-1, @y,
)
@x -= 1
@y -= 1
increase_steps
@move_failed = false
#------------------------------------------------------------------
# ? Check Player's Terrain Tag
# * Added by Mr. Anonymous 5/29/2008
#------------------------------------------------------------------
tag = $game_map.terrain_tag($game_player.x, $game_player.y)
$game_variables[KGC::TilesetExtension::PLAYER_TERRAIN_TAG] = tag
return tag
else
@move_failed = true
end
end
#--------------------------------------------------------------------------
# ?
??
#--------------------------------------------------------------------------
def move_upper_right
unless @direction_fix
@direction = (@direction == 4 ? 6 : @direction == 2 ? 8 : @direction)
end
if (passable?(@x, @y,
&& passable?(@x, @y-1, 6)) ||
(passable?(@x, @y, 6) && passable?(@x+1, @y,
)
@x += 1
@y -= 1
increase_steps
@move_failed = false
#------------------------------------------------------------------
# ? Check Player's Terrain Tag
# * Added by Mr. Anonymous 5/29/2008
#------------------------------------------------------------------
tag = $game_map.terrain_tag($game_player.x, $game_player.y)
$game_variables[KGC::TilesetExtension::PLAYER_TERRAIN_TAG] = tag
return tag
else
@move_failed = true
end
end
end
#?
??
#==============================================================================
# ? Game_Player
#==============================================================================
class Game_Player < Game_Character
#--------------------------------------------------------------------------
# ?
# x : X ??
# y : Y ??
# d :
?
#
??
#--------------------------------------------------------------------------
alias map_passable_KGC_TilesetExtension? map_passable?
def map_passable?(x, y, d)
return false unless map_passable_KGC_TilesetExtension?(x, y)
return $game_map.passable_dir?(x, y, d)
end
if $TEST && KGC::TilesetExtension::DEBUG_INFO_BUTTON != nil
#--------------------------------------------------------------------------
# ?
#--------------------------------------------------------------------------
alias update_KGC_TilesetExtension update
def update
update_KGC_TilesetExtension
if Input.trigger?(KGC::TilesetExtension::DEBUG_INFO_BUTTON)
show_passage_and_terrain_tag
end
end
#--------------------------------------------------------------------------
# ?
#--------------------------------------------------------------------------
def show_passage_and_terrain_tag
passage = $game_map.passage(x, y)
tag = $game_map.terrain_tag(x, y)
#
??
s = "
?: "
s += "?" if passage & DirectionFlag::DOWN == 0x00
s += "?" if passage & DirectionFlag::LEFT == 0x00
s += "?" if passage & DirectionFlag::RIGHT == 0x00
s += "?" if passage & DirectionFlag::UP == 0x00
s += "
?: #{tag}"
p s
end
end
end
#?
??
#==============================================================================
# ? Sprite_Character
#==============================================================================
class Sprite_Character < Sprite_Base
#--------------------------------------------------------------------------
# ?
# tile_id :
ID
#--------------------------------------------------------------------------
def tileset_bitmap(tile_id)
filename = KGC::TilesetExtension.get_tileset_filename
set_number = tile_id / 256
return Cache.system(filename["B"]) if set_number == 0
return Cache.system(filename["C"]) if set_number == 1
return Cache.system(filename["D"]) if set_number == 2
return Cache.system(filename["E"]) if set_number == 3
return nil
end
end
#?
??
#==============================================================================
# ? Spriteset_Map
#==============================================================================
class Spriteset_Map
#--------------------------------------------------------------------------
# ?
#--------------------------------------------------------------------------
def create_tilemap
filename = KGC::TilesetExtension.get_tileset_filename
@tilemap = Tilemap.new(@viewport1)
@tilemap.bitmaps[0] = Cache.system(filename["A1"])
@tilemap.bitmaps[1] = Cache.system(filename["A2"])
@tilemap.bitmaps[2] = Cache.system(filename["A3"])
@tilemap.bitmaps[3] = Cache.system(filename["A4"])
@tilemap.bitmaps[4] = Cache.system(filename["A5"])
@tilemap.bitmaps[5] = Cache.system(filename["B"])
@tilemap.bitmaps[6] = Cache.system(filename["C"])
@tilemap.bitmaps[7] = Cache.system(filename["D"])
@tilemap.bitmaps[8] = Cache.system(filename["E"])
@tilemap.map_data = $game_map.data
@tilemap.passages = $game_map.passages
end
end
#?
??
#==============================================================================
# ? Scene_Title
#==============================================================================
class Scene_Title < Scene_Base
#--------------------------------------------------------------------------
# ?
?
#--------------------------------------------------------------------------
alias load_database_KGC_TilesetExtension load_database
def load_database
load_database_KGC_TilesetExtension
load_tileset
end
#--------------------------------------------------------------------------
# ?
??
#--------------------------------------------------------------------------
def load_tileset
begin
$data_tileset = load_data("Data/#{KGC::TilesetExtension::EX_RVDATA}")
rescue
$data_tileset = RPG::Tileset.new
end
end
end
#?
??
#==============================================================================
# ? Scene_File
#==============================================================================
class Scene_File < Scene_Base
#--------------------------------------------------------------------------
# ?
??
# file :
(
)
#--------------------------------------------------------------------------
alias read_save_data_KGC_TilesetExtension read_save_data
def read_save_data(file)
read_save_data_KGC_TilesetExtension(file)
$game_map.init_tileset_filename
Graphics.frame_reset
end
end