#============================================================================
# ** Game_Towns
#----------------------------------------------------------------------------
# This class holds the possible towns that the player can go to. Refer to
# "$game_towns" for the instance of this class.
#============================================================================
class Game_Towns
# If the user has invoked traveling instead of direct travel this will be
# true.
attr_reader :traveling
#--------------------------------------------------------------------------
# * Initialization
#--------------------------------------------------------------------------
def initialize
@towns, @traveling, @send_to = Hash.new, false, nil
end
#--------------------------------------------------------------------------
# * Add Town
# town_name : name of the town you want to change.
# map_id : the id of the map where the town is located.
# x : the x location of where you want to appear on the map.
# y : the y location of where you want to appear on the map.
#--------------------------------------------------------------------------
def add_town(town_name, map_id, x, y)
@towns[town_name] = [map_id,x,y]
end
#--------------------------------------------------------------------------
# * Remove a Town
# town_name : name of the town you want to remove.
#--------------------------------------------------------------------------
def remove_town(town_name)
@towns.delete(town_name)
end
#--------------------------------------------------------------------------
# * Going to
# town_name : name of the town you will eventually travel to.
# t_map_id : the id of the map where you will be sent to before hand.
# t_x : the x location of where you will appear on the traveling map.
# t_y : the y location of where you will appear on the traveling map.
#--------------------------------------------------------------------------
def going_to(town_name, t_map_id, t_x, t_y)
@traveling = true
@send_to = town_name
# Rather than check to see if anything else is nil just check the player.
return if $game_player == nil
# Return if there is no such town by that name.
return if !@towns.has_key?(town_name)
# Reset the frame counter
Graphics.frame_count = 0
# Set up the map and move the player to it.
$game_map.setup(t_map_id)
$game_player.moveto(t_x, t_y)
# Refresh player
$game_player.refresh
# Run automatic change for BGM and BGS set with map
$game_map.autoplay
# Update map (run parallel process event)
$game_map.update
# Switch to map screen
$scene = Scene_Map.new
end
#--------------------------------------------------------------------------
# * Go to a Town
# town_name : name of the town you want to travel to.
#--------------------------------------------------------------------------
def goto_town(town_name = @send_to)
# Rather than check to see if anything else is nil just check the player.
return if $game_player == nil
# Return if there is no such town by that name.
return if !@towns.has_key?(town_name)
@traveling = false if @traveling
# Reset the frame counter
Graphics.frame_count = 0
# Set up the map and move the player to it.
$game_map.setup(@towns[town_name][0])
$game_player.moveto(@towns[town_name][1], @towns[town_name][2])
# Refresh player
$game_player.refresh
# Run automatic change for BGM and BGS set with map
$game_map.autoplay
# Update map (run parallel process event)
$game_map.update
# Switch to map screen
$scene = Scene_Map.new
end
#--------------------------------------------------------------------------
# * Get the Towns
# excluded_name : the name you want excluded from the list of towns.
#--------------------------------------------------------------------------
def get_towns(excluded_name = nil)
# If no allegiance was specified return all the towns.
towns = @towns.keys
towns.delete(excluded_name) if excluded_name
return towns
end
end
#============================================================================
# ** Window_Command
#----------------------------------------------------------------------------
# This window deals with general command choices.
#============================================================================
class Window_Command
attr_reader :commands
end
#============================================================================
# ** Window_Town
#----------------------------------------------------------------------------
# This window deals just shows Town text
#============================================================================
class Window_Town < Window_Base
AVAILABLE_TOWNS = 'Available Towns'
#--------------------------------------------------------------------------
# * Object Initialization
# x : the x coordinate where the window will appear.
# y : the y coordinate where the window will appear.
# width : the width of the window.
# height : the height of the window.
#--------------------------------------------------------------------------
def initialize(x,y,width,height)
super(x,y,width,height)
self.contents = Bitmap.new(width - 32,height - 32)
refresh
end
#--------------------------------------------------------------------------
# * Redraws the window contents.
#--------------------------------------------------------------------------
def refresh
self.contents.clear
self.contents.draw_text(0, 0, width - 32, 32, AVAILABLE_TOWNS, 1)
end
end
#============================================================================
# ** Scene_TownSelection
#----------------------------------------------------------------------------
# This class provides the user with the ability to change the towns.
#============================================================================
class Scene_TownSelection
# The name that will be excluded in the list of towns.
attr_accessor :excluded_name
#--------------------------------------------------------------------------
# * Scene Main
#--------------------------------------------------------------------------
def main
# Create a background.
@background = Spriteset_Map.new
# Create the collection of towns the player can go to.
@towns = Window_Command.new(200,$game_towns.get_towns(excluded_name))
@towns.x = (640 / 2) - (@towns.width / 2)
@towns.y = 100
@towns.opacity = 140
# Create the window that only displays a line of text.
@town = Window_Town.new(@towns.x, @towns.y - 64, @towns.width, 64)
@town.opacity = @towns.opacity
# Graphics.transition to break the last Graphics.freeze
Graphics.transition
loop do
Graphics.update
Input.update
update
break if $scene != self
end
# Create a lead in for the next scene.
Graphics.freeze
# Dispose of the disposables.
@background.dispose
@towns.dispose
@town.dispose
end
#--------------------------------------------------------------------------
# * Traveling
# t_map_id : the id of the map that you will be on while traveling.
# t_x : the x position where the player will start at in the map.
# t_y : the y position where the player will start at in the map.
#--------------------------------------------------------------------------
def travel(t_map_id = 1, t_x = 0, t_y = 0)
@traveling = true
@t_map_id, @t_x, @t_y = t_map_id, t_x, t_y
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Update the window.
@towns.update
# If the user has selected a town send him there.
if Input.trigger?(Input::C)
# If the user called the method, 'travel' assume we are temporarily
# going to another map before traveling to the final destination.
if @traveling
$game_towns.going_to(@towns.commands[@towns.index],@t_map_id,@t_x,@t_y)
@traveling = false
else
$game_towns.goto_town(@towns.commands[@towns.index])
end
end
# Break the scene if the user hits the B key.
@traveling, $scene = false, Scene_Map.new if Input.trigger?(Input::B)
end
end
#============================================================================
# ** Scene_Map
#----------------------------------------------------------------------------
# This class performs map screen processing.
#============================================================================
class Scene_Map
alias_method :old_main, :main
alias_method :old_update, :update
TIME_SPENT_TRAVELING = 50
def main
@time_spent_traveling = 0
old_main
end
def update
if $game_towns.traveling
@time_spent_traveling += 1
if @time_spent_traveling == TIME_SPENT_TRAVELING
$game_towns.goto_town
@time_spent_traveling = 0
end
end
old_update
end
end
#============================================================================
# ** Scene_Title
#----------------------------------------------------------------------------
# This class performs title screen processing.
#============================================================================
class Scene_Title
alias_method :old_main, :main
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# If battle test
if $BTEST
battle_test
return
end
$game_towns = Game_Towns.new
old_main
end
end
#============================================================================
# ** Scene_Save
#----------------------------------------------------------------------------
# This class performs save screen processing.
#============================================================================
class Scene_Save < Scene_File
alias_method :old_write_save_data, :write_save_data
#--------------------------------------------------------------------------
# * Write Save Data
# file : write file object (opened)
#--------------------------------------------------------------------------
def write_save_data(file)
old_write_save_data(file)
# Added this to save the list of towns.
Marshal.dump($game_towns, file)
end
end
#============================================================================
# ** Scene_Load
#----------------------------------------------------------------------------
# This class performs load screen processing.
#============================================================================
class Scene_Load < Scene_File
#--------------------------------------------------------------------------
# * Read Save Data (*!OVERRIDE!*)
# file : file object for reading (opened)
#--------------------------------------------------------------------------
def read_save_data(file)
# Read character data for drawing save file
characters = Marshal.load(file)
# Read frame count for measuring play time
Graphics.frame_count = Marshal.load(file)
# Read each type of game object
$game_system = Marshal.load(file)
$game_switches = Marshal.load(file)
$game_variables = Marshal.load(file)
$game_self_switches = Marshal.load(file)
$game_screen = Marshal.load(file)
$game_actors = Marshal.load(file)
$game_party = Marshal.load(file)
$game_troop = Marshal.load(file)
$game_map = Marshal.load(file)
$game_player = Marshal.load(file)
# Added this line to load towns.
$game_towns = Marshal.load(file)
# If magic number is different from when saving
# (if editing was added with editor)
if $game_system.magic_number != $data_system.magic_number
# Load map
$game_map.setup($game_map.map_id)
$game_player.center($game_player.x, $game_player.y)
end
# Refresh party members
$game_party.refresh
end
end