#==============================================================================
# ** :::Josh::: or Rafael_Drake on RMK - Basic Fog System
# Version 1.0.0
#------------------------------------------------------------------------------
# This script will display up to three fogs of your choosing. I wrote it
# for my game more or less cause I didn't need that many. But I figured someone
# else may need it.
#==============================================================================
# ** Import Hash
($imported ||= {}) = true
#==============================================================================
# ** Add-Ons
# If you want me to add a feature to this script let me know, I won't
# do the impossible or the unnecessary though. Compatibility patches is
# all on you.
#==============================================================================
# ** Warning
# This script is created and designed for RPG Maker VXA, RPG Maker VX will
# need some heavy modification for it to work. I do not even want to think
# about XP.
#==============================================================================
# ** Usage
# Feel free to use in any kind of project, but with credit given please.
# As with this special permission, please do not share my work across other
# forums or sites. I would like it to stay at the topic page on/or the Official
# Forums Site. I also want to inform you that you can not sell this script
# itself. It must be part of a finished project. Last but not least, don't
# post up modification versions of it. If you have any questions please ask!
#==============================================================================
# ** Tutorial
# Use the note box on any map and add up to 3 fogs.
# Here is an Example: Replace the Letter with A, B, or C
# <A Name: ""> (name of your fog graphic - found in your pictures folder)
# <A Speed: x, y> (speed and direction of your fog)
# <A Opacity: 255> (the opacity of the fog graphic)
# <A Priority: 50> (the Z-Height value of the fog - 0 is under the map -)
# <A Color: R, G, B, A> (R = Red, G = Green, B = Blue, A = Alpha - amounts)
#==============================================================================

#==============================================================================
# ** RPG::Map
#------------------------------------------------------------------------------
# This is the super class of Game_Map.
#==============================================================================
class RPG::Map

#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :first_name ; attr_reader :second_name
attr_reader :third_name ; attr_reader :first_opacity
attr_reader :second_opacity ; attr_reader :third_opacity
attr_reader :first_speed ; attr_reader :second_speed
attr_reader :third_speed ; attr_reader :first_priority
attr_reader :second_priority ; attr_reader :third_priority
attr_reader :first_color ; attr_reader :second_color
attr_reader :third_color ; attr_reader :fog_active
#--------------------------------------------------------------------------
# * Get Fog Settings
#--------------------------------------------------------------------------
def fog_settings
@fog_active = false ; @first_name = ""
@second_name = "" ; @third_name = ""
@first_opacity = 255 ; @second_opacity = 255
@third_opacity = 255 ; @first_speed =
@second_speed = ; @third_speed =
@first_priority = 255 ; @second_priority = 254
@third_priority = 253 ; @first_color = nil
@second_color = nil ; @third_color = nil
self.note.split(/+/).each { |line|
case line
when /<A Name: (.*)/i ; @fog_active = true ; @first_name = $1.to_s
when /<B Name: (.*)/i ; @fog_active = true ; @second_name = $1.to_s
when /<C Name: (.*)/i ; @fog_active = true ; @third_name = $1.to_s
when /<A Opacity: (.*)/i ; @first_opacity = $1.to_i
when /<B Opacity: (.*)/i ; @second_opacity = $1.to_i
when /<C Opacity: (.*)/i ; @third_opacity = $1.to_i
when /<A Speed: (.*), (.*)>/i ; @first_speed =
when /<B Speed: (.*), (.*)>/i ; @second_speed =
when /<C Speed: (.*), (.*)>/i ; @third_speed =
when /<A Priority: (.*)/i ; @first_priority = $1.to_i
when /<B Priority: (.*)/i ; @second_priority = $1.to_i
when /<C Priority: (.*)/i ; @third_priority = $1.to_i
when /<A Color: (.*),(.*),(.*),(.*)>/im
@first_color = Color.new($1.to_i, $2.to_i, $3.to_i, $4.to_i)
when /<B Color: (.*),(.*),(.*),(.*)>/im
@second_color = Color.new($1.to_i, $2.to_i, $3.to_i, $4.to_i)
when /<C Color: (.*),(.*),(.*),(.*)>/im
@third_color = Color.new($1.to_i, $2.to_i, $3.to_i, $4.to_i)
end
}
end
end

#==============================================================================
# ** Game_Map
#------------------------------------------------------------------------------
# This class handles maps. It includes scrolling and passage determination
# functions. The instance of this class is referenced by $game_map.
#==============================================================================
class Game_Map

#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :first_name ; attr_reader :second_name
attr_reader :third_name ; attr_reader :first_opacity
attr_reader :second_opacity ; attr_reader :third_opacity
attr_reader :first_speed ; attr_reader :second_speed
attr_reader :third_speed ; attr_reader :first_priority
attr_reader :second_priority ; attr_reader :third_priority
attr_reader :first_color ; attr_reader :second_color
attr_reader :third_color ; attr_reader :fog_used
#--------------------------------------------------------------------------
# * Alias Methods
#--------------------------------------------------------------------------
alias basic_fog_setup setup
alias basic_fog_position set_display_pos
alias basic_fog_down scroll_down
alias basic_fog_left scroll_left
alias basic_fog_right scroll_right
alias basic_fog_up scroll_up
alias basic_fog_update update_parallax
#--------------------------------------------------------------------------
# * Setup
#--------------------------------------------------------------------------
def setup(map_id)
basic_fog_setup(map_id)
@map.fog_settings
@fog_used = @map.fog_active
create_first_fog
create_second_fog
create_third_fog
end
#--------------------------------------------------------------------------
# * Create First Fog
#--------------------------------------------------------------------------
def create_first_fog
@first_name = @map.first_name ; @first_opacity = @map.first_opacity
@first_speed = @map.first_speed ; @first_priority = @map.first_priority
@first_color = @map.first_color
@first_loopx = @first_speed != 0 ? true : false
@first_loopy = @first_speed != 0 ? true : false
@first_sx = @first_speed ; @first_sy = @first_speed
@first_x = 0 ; @first_y = 0
end
#--------------------------------------------------------------------------
# * Create Second Fog
#--------------------------------------------------------------------------
def create_second_fog
@second_name = @map.second_name ; @second_opacity = @map.second_opacity
@second_speed = @map.second_speed ; @second_priority = @map.second_priority
@second_color = @map.second_color
@second_loopx = @second_speed != 0 ? true : false
@second_loopy = @second_speed != 0 ? true : false
@second_sx = @second_speed ; @second_sy = @second_speed
@second_x = 0 ; @second_y = 0
end
#--------------------------------------------------------------------------
# * Create Third Fog
#--------------------------------------------------------------------------
def create_third_fog
@third_name = @map.third_name ; @third_opacity = @map.third_opacity
@third_speed = @map.third_speed ; @third_priority = @map.third_priority
@third_color = @map.third_color
@third_loopx = @third_speed != 0 ? true : false
@third_loopy = @third_speed != 0 ? true : false
@third_sx = @third_speed ; @third_sy = @third_speed
@third_x = 0 ; @third_y = 0
end
#--------------------------------------------------------------------------
# * Set Display Position
#--------------------------------------------------------------------------
def set_display_pos(x, y)
basic_fog_position(x, y)
@first_x = x ; @second_x = x
@third_x = x ; @first_y = y
@second_y = y ; @third_y = y
end
#--------------------------------------------------------------------------
# * Scroll Down
#--------------------------------------------------------------------------
def scroll_down(distance)
last_y = @display_y
basic_fog_down(distance)
move_fog_down(distance, last_y)
end
#--------------------------------------------------------------------------
# * Move Fog Down
#--------------------------------------------------------------------------
def move_fog_down(distance, last_y)
value = loop_vertical? ? distance : @display_y - last_y
@first_y += value ; @second_y += value ; @third_y += value
end
#--------------------------------------------------------------------------
# * Scroll Left
#--------------------------------------------------------------------------
def scroll_left(distance)
last_x = @display_x
basic_fog_left(distance)
move_fog_left(distance, last_x)
end
#--------------------------------------------------------------------------
# * Move Fog Left
#--------------------------------------------------------------------------
def move_fog_left(distance, last_x)
value = loop_horizontal? ? -distance : @display_x - last_x
@first_x += value ; @second_x += value ; @third_x += value
end
#--------------------------------------------------------------------------
# * Scroll Right
#--------------------------------------------------------------------------
def scroll_right(distance)
last_x = @display_x
basic_fog_right(distance)
move_fog_right(distance, last_x)
end
#--------------------------------------------------------------------------
# * Move Fog Right
#--------------------------------------------------------------------------
def move_fog_right(distance, last_x)
value = loop_horizontal? ? distance : @display_x - last_x
@first_x += value ; @second_x += value ; @third_x += value
end
#--------------------------------------------------------------------------
# * Scroll Up
#--------------------------------------------------------------------------
def scroll_up(distance)
last_y = @display_y
basic_fog_up(distance)
move_fog_up(distance, last_y)
end
#--------------------------------------------------------------------------
# * Move Fog Up
#--------------------------------------------------------------------------
def move_fog_up(distance, last_y)
value = loop_vertical? ? -distance : @display_y - last_y
@first_y += value ; @second_y += value ; @third_y += value
end
#--------------------------------------------------------------------------
# * Update Parallax
#--------------------------------------------------------------------------
def update_parallax ; basic_fog_update ; update_basic_fog end
#--------------------------------------------------------------------------
# * Update Basic Fog
#--------------------------------------------------------------------------
def update_basic_fog
@first_x += @first_sx / 128.0 if @first_loopx
@second_x += @second_sx / 128.0 if @second_loopx
@third_x += @third_sx / 128.0 if @third_loopx
@first_y += @first_sy / 128.0 if @first_loopy
@second_y += @second_sy / 128.0 if @second_loopy
@third_y += @third_sy / 128.0 if @third_loopy
end
#--------------------------------------------------------------------------
# * Fog X and Y Setup
#--------------------------------------------------------------------------
def first_x ; @first_x end ; def second_x ; @second_x end
def third_x ; @third_x end ; def first_y ; @first_y end
def second_y ; @second_y end ; def third_y ; @third_y end
end

#==============================================================================
# ** Basic_Fog_Plane
#------------------------------------------------------------------------------
# This class handles the Basic Fog System Plane it is refrenced to the Plane
# class.
#==============================================================================

class Basic_Fog_Plane < Plane

#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(fog_name = "", fog_choice)
return unless fog_name != ""
return if $BTEST
super(nil)
self.bitmap = Cache.picture(fog_name)
@fog_choice = fog_choice
initialize_values
update
end
#--------------------------------------------------------------------------
# * Initialize Values
#--------------------------------------------------------------------------
def initialize_values
case @fog_choice
when :first_choice
self.z = $game_map.first_priority
self.opacity = $game_map.first_opacity
self.color = $game_map.first_color if $game_map.first_color != nil
when :second_choice
self.z = $game_map.second_priority
self.opacity = $game_map.second_opacity
self.color = $game_map.second_color if $game_map.second_color != nil
when :third_choice
self.z = $game_map.third_priority
self.opacity = $game_map.third_opacity
self.color = $game_map.third_color if $game_map.third_color != nil
end
end
#--------------------------------------------------------------------------
# * Basic Fog Position Update
#--------------------------------------------------------------------------
def basic_fog_position_update
case @fog_choice
when :first_choice
self.ox = $game_map.first_x * 32 + $game_map.first_speed
self.oy = $game_map.first_y * 32 + $game_map.first_speed
when :second_choice
self.ox = $game_map.second_x * 32 + $game_map.second_speed
self.oy = $game_map.second_y * 32 + $game_map.second_speed
when :third_choice
self.ox = $game_map.third_x * 32 + $game_map.third_speed
self.oy = $game_map.third_y * 32 + $game_map.third_speed
end
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
return if self.disposed?
basic_fog_position_update
case @fog_choice
when :first_choice
self.opacity = $game_map.first_opacity if self.opacity != $game_map.first_opacity
when :second_choice
self.opacity = $game_map.second_opacity if self.opacity != $game_map.second_opacity
when :third_choice
self.opacity = $game_map.third_opacity if self.opacity != $game_map.third_opacity
end
end
end

#==============================================================================
# ** BasicFogSystem
#------------------------------------------------------------------------------
# This module manages the Fog Planes
#==============================================================================
module BasicFogSystem

#--------------------------------------------------------------------------
# * Start Fog
#--------------------------------------------------------------------------
def start_fog
game_map = $game_map
create_first_fog(game_map)
create_second_fog(game_map)
create_third_fog(game_map)
end
#--------------------------------------------------------------------------
# * Create First Fog
#--------------------------------------------------------------------------
def create_first_fog(game_map)
@first = Basic_Fog_Plane.new(game_map.first_name, :first_choice)
@first_name = game_map.first_name
end
#--------------------------------------------------------------------------
# * Create Second Fog
#--------------------------------------------------------------------------
def create_second_fog(game_map)
@second = Basic_Fog_Plane.new(game_map.second_name, :second_choice)
@second_name = game_map.second_name
end
#--------------------------------------------------------------------------
# * Create Third Fog
#--------------------------------------------------------------------------
def create_third_fog(game_map)
@third = Basic_Fog_Plane.new(game_map.third_name, :third_choice)
@third_name = game_map.third_name
end
#--------------------------------------------------------------------------
# * Terminate Fog
#--------------------------------------------------------------------------
def terminate_fog
@first.dispose if @first != nil
@second.dispose if @second != nil
@third.dispose if @third != nil
end
#--------------------------------------------------------------------------
# * Update Fog
#-------------------------------------------------------------------------
def update_fog
if @first_name != $game_map.first_name
@first.dispose if @first != nil
create_first_fog($game_map)
end
if @second_name != $game_map.second_name
@second.dispose if @second != nil
create_second_fog($game_map)
end
if @third_name != $game_map.third_name
@third.dispose if @third != nil
create_third_fog($game_map)
end
@first.update if @first != nil
@second.update if @second != nil
@third.update if @third != nil
end
end

#==============================================================================
# ** Spriteset_Map
#------------------------------------------------------------------------------
# This class brings together map screen sprites, tilemaps, etc. It's used
# within the Scene_Map class.
#==============================================================================

class Spriteset_Map

#--------------------------------------------------------------------------
# * Included Modules
#--------------------------------------------------------------------------
include BasicFogSystem
#--------------------------------------------------------------------------
# * Alias Methods
#--------------------------------------------------------------------------
alias bfs_initialize initialize
alias bfs_dispose dispose
alias bfs_update update
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize ; start_fog ; bfs_initialize end
#--------------------------------------------------------------------------
# * Free
#--------------------------------------------------------------------------
def dispose ; terminate_fog ; bfs_dispose end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update ; update_fog ; bfs_update end
end

#==============================================================================
# ** End of File
#==============================================================================