Code:
#===============================================================
# ? [XP] ? Multiple Fogs ? ?
# * Use unlimited layers of fog *
#--------------------------------------------------------------
# ? by Woratana [woratana@hotmail.com]
# ? Thaiware RPG Maker Community
# ? Released on: 02/05/2008
# ? Version: 1.0
#--------------------------------------------------------------
#===============================================================
# ** HOW TO USE
#--------------------------------------------------------------
# [ENGLISH]
# ? Same as default fog, you can control multiple fogs by event command:
# 'Change Map Settings...'
# 'Change Fog Color Tone...'
# 'Change Fog Opacity...'
# ? Before you use above event command, you have to choose ID of multiple fog
# you are going to control, by call script:
# $fog_id = (positive number)
# for example, $fog_id = 2
# ? You can control default fog by call script: $fog_id = 0
#
# ? You can clear all created multiple fogs by call script:
# $game_map.clear_mulfog
#
#--------------------------------------------------------------
# [THAI]
# ? ในการควบคุมหมอกพิเศษก็เหมือนกับการควบคุมหมอกธรรมดา คือสามารถใช้คำสั่งอีเว้นท์เหล่านี้:
# 'Change Map Settings...' หรือ 'เปลี่ยนสภาพแผนที่...'
# 'Change Fog Color Tone...' หรือ 'เปลี่ยนสีหมอก...'
# 'Change Fog Opacity...' หรือ 'เปลี่ยนความโปร่งใสหมอก...'
# ? ก่อนที่จะใช้คำสั่งอีเว้นท์ข้างต้น ให้เลือก ID ของหมอกที่เราต้องการควบคุมก่อน
# โดยใช้คำสั่งอีเว้นท์ 'Script...' หรือ 'เรียกใช้สคริปต์...':
# $fog_id = (ตัวเลขที่มากกว่า 0)
# เช่น $fog_id = 2
# ? สามารถควบคุมหมอกธรรมดาได้ โดยเรียกใช้สคริปต์:
# $fog_id = 0
#
# ? สามารถสั่งลบหมอกพิเศษทั้งหมด โดยเรียกใช้สคริปต์:
# $game_map.clear_mulfog
#
#===============================================================
class Interpreter
#==================================================================
# ** MULTIPLE FOG SETUP
#--------------------------------------------------------------
Auto_Reset_Fog_ID = false # (true or false)
# Automatically change $fog_id back to 0 (default fog) after
# using event command to control fog.
# เปลี่ยนค่าตัวแปร $fog_id เป็น 0 (สำหรับควบคุมหมอกธรรมดา) อัตโนมัติหลังจากใช้คำสั่งอีเว้นท์
# สำหรับควบคุมหมอก
Auto_Clear_Fog_when_Teleport = false # (true or false)
# Automatically clear all multiple fogs when teleport
# ลบหมอกพิเศษทั้งหมดโดยอัตโนมัติ หลังจากใช้คำสั่งเทเลพอร์ต
#==================================================================
alias wora_mulfog_interpret_com204 command_204
alias wora_mulfog_interpret_com205 command_205
alias wora_mulfog_interpret_com206 command_206
alias wora_mulfog_interpret_com201 command_201
#--------------------------------------------------------------------------
# * Change Map Settings
#--------------------------------------------------------------------------
def command_204
if @parameters[0] == 1 and !$fog_id.nil? and $fog_id > 0
$game_map.mulfog_name[$fog_id] = @parameters[1]
$game_map.mulfog_hue[$fog_id] = @parameters[2]
$game_map.mulfog_opacity[$fog_id] = @parameters[3]
$game_map.mulfog_blend_type[$fog_id] = @parameters[4]
$game_map.mulfog_zoom[$fog_id] = @parameters[5]
$game_map.mulfog_sx[$fog_id] = @parameters[6]
$game_map.mulfog_sy[$fog_id] = @parameters[7]
$game_map.mulfog_ox[$fog_id] = 0
$game_map.mulfog_oy[$fog_id] = 0
$game_map.mulfog_tone[$fog_id] = Tone.new(0, 0, 0, 0)
$game_map.mulfog_tone_target[$fog_id] = Tone.new(0, 0, 0, 0)
$game_map.mulfog_tone_duration[$fog_id] = 0
$game_map.mulfog_opacity_duration[$fog_id] = 0
$game_map.mulfog_opacity_target[$fog_id] = 0
$fog_id = 0 if Auto_Reset_Fog_ID
return true
else
wora_mulfog_interpret_com204
end
end
#--------------------------------------------------------------------------
# * Change Fog Color Tone
#--------------------------------------------------------------------------
def command_205
if !$fog_id.nil? and $fog_id > 0
$game_map.start_mulfog_tone_change($fog_id, @parameters[0], @parameters[1] * 2)
$fog_id = 0 if Auto_Reset_Fog_ID
return true
else
wora_mulfog_interpret_com205
end
end
#--------------------------------------------------------------------------
# * Change Fog Opacity
#--------------------------------------------------------------------------
def command_206
if !$fog_id.nil? and $fog_id > 0
$game_map.start_mulfog_opacity_change($fog_id, @parameters[0], @parameters[1] * 2)
$fog_id = 0 if Auto_Reset_Fog_ID
return true
else
wora_mulfog_interpret_com206
end
end
#--------------------------------------------------------------------------
# * Transfer Player
#--------------------------------------------------------------------------
def command_201
if Auto_Clear_Fog_when_Teleport
unless $game_temp.player_transferring or
$game_temp.message_window_showing or
$game_temp.transition_processing
if @parameters[0] == 0; id_map = @parameters[1]
else; id_map = $game_variables[@parameters[1]]
end
$game_map.clear_mulfog if id_map != @map_id
end
end
wora_mulfog_interpret_com201
end
end
class Game_Map
attr_accessor :mulfog_name # mulfog file name
attr_accessor :mulfog_hue # mulfog hue
attr_accessor :mulfog_opacity # mulfog opacity level
attr_accessor :mulfog_blend_type # mulfog blending method
attr_accessor :mulfog_zoom # mulfog zoom rate
attr_accessor :mulfog_sx # mulfog sx
attr_accessor :mulfog_sy # mulfog sy
attr_accessor :mulfog_ox # mulfog x-coordinate starting point
attr_accessor :mulfog_oy # mulfog y-coordinate starting point
attr_accessor :mulfog_tone # mulfog color tone
attr_accessor :mulfog_tone_target
attr_accessor :mulfog_tone_duration
attr_accessor :mulfog_opacity_duration
attr_accessor :mulfog_opacity_target
alias wora_mulfog_gammap_ini initialize
alias wora_mulfog_gammap_upd update
def initialize
wora_mulfog_gammap_ini
@mulfog_name = []
@mulfog_hue = []
@mulfog_opacity = []
@mulfog_blend_type = []
@mulfog_zoom = []
@mulfog_sx = []
@mulfog_sy = []
@mulfog_ox = []
@mulfog_oy = []
@mulfog_tone = []
@mulfog_tone_target = []
@mulfog_tone_duration = []
@mulfog_opacity_duration = []
@mulfog_opacity_target = []
end
def update
wora_mulfog_gammap_upd
@mulfog_name.each_index do |i|
next if @mulfog_name[i].nil? or @mulfog_name[i] == ''
# Manage fog scrolling
@mulfog_ox[i] -= @mulfog_sx[i] / 8.0
@mulfog_oy[i] -= @mulfog_sy[i] / 8.0
# Manage change in fog color tone
if @mulfog_tone_duration[i] >= 1
d = @mulfog_tone_duration[i]
target = @mulfog_tone_target[i]
@mulfog_tone[i].red = (@mulfog_tone[i].red * (d - 1) + target.red) / d
@mulfog_tone[i].green = (@mulfog_tone[i].green * (d - 1) + target.green) / d
@mulfog_tone[i].blue = (@mulfog_tone[i].blue * (d - 1) + target.blue) / d
@mulfog_tone[i].gray = (@mulfog_tone[i].gray * (d - 1) + target.gray) / d
@mulfog_tone_duration[i] -= 1
end
# Manage change in fog opacity level
if @mulfog_opacity_duration[i] >= 1
d = @mulfog_opacity_duration[i]
@mulfog_opacity[i] = (@mulfog_opacity[i] * (d - 1) + @mulfog_opacity_target[i]) / d
@mulfog_opacity_duration[i] -= 1
end
end
end
#--------------------------------------------------------------------------
# * Start Changing Fog Color Tone
#--------------------------------------------------------------------------
def start_mulfog_tone_change(i, tone, duration)
@mulfog_tone_target[i] = tone.clone
@mulfog_tone_duration[i] = duration
if @mulfog_tone_duration[i] == 0
@mulfog_tone[i] = @mulfog_tone_target[i].clone
end
end
#--------------------------------------------------------------------------
# * Start Changing Fog Opacity Level
#--------------------------------------------------------------------------
def start_mulfog_opacity_change(i, opacity, duration)
@mulfog_opacity_target[i] = opacity * 1.0
@mulfog_opacity_duration[i] = duration
if @mulfog_opacity_duration[i] == 0
@mulfog_opacity[i] = @mulfog_opacity_target[i]
end
end
def clear_mulfog
@mulfog_name.each_index {|i| @mulfog_name[i] = '' }
end
end
$worale = {} if !$worale
$worale['MutipleFog'] = true
$fog_id = 0
class Spriteset_Map
alias wora_mulfog_sprmap_ini initialize
alias wora_mulfog_sprmap_upd update
alias wora_mulfog_sprmap_dispos dispose
def initialize
@mulfog = []
@mulfog_name = []
@mulfog_hue = []
wora_mulfog_sprmap_ini
end
def update
wora_mulfog_sprmap_upd
$game_map.mulfog_name.each_index do |i|
next if $game_map.mulfog_name[i].nil?
# If fog is different than current fog
if @mulfog_name[i] != $game_map.mulfog_name[i] or @mulfog_hue[i] != $game_map.mulfog_hue[i]
@mulfog_name[i] = $game_map.mulfog_name[i]
@mulfog_hue[i] = $game_map.mulfog_hue[i]
if @mulfog[i].nil?
@mulfog[i] = Plane.new(@viewport1)
@mulfog[i].z = 3000
end
if @mulfog[i].bitmap != nil
@mulfog[i].bitmap.dispose
@mulfog[i].bitmap = nil
end
if @mulfog_name[i] != ''
@mulfog[i].bitmap = RPG::Cache.fog(@mulfog_name[i], @mulfog_hue[i])
end
Graphics.frame_reset
end
next if @mulfog_name[i] == ''
# Update fog plane
@mulfog[i].zoom_x = $game_map.mulfog_zoom[i] / 100.0
@mulfog[i].zoom_y = $game_map.mulfog_zoom[i] / 100.0
@mulfog[i].opacity = $game_map.mulfog_opacity[i]
@mulfog[i].blend_type = $game_map.mulfog_blend_type[i]
@mulfog[i].ox = $game_map.display_x / 4 + $game_map.mulfog_ox[i]
@mulfog[i].oy = $game_map.display_y / 4 + $game_map.mulfog_oy[i]
@mulfog[i].tone = $game_map.mulfog_tone[i]
end
end
def dispose
@mulfog.each_index do |i|
next if @mulfog[i].nil?
@mulfog[i].bitmap.dispose if !@mulfog[i].bitmap.nil?
@mulfog[i].dispose
end
wora_mulfog_sprmap_dispos
end
end
#==================================================================
# [END] XP Multiple Fog by Woratana [woratana@hotmail.com]
#==================================================================