Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # // 05/01/2011
- # // 05/08/2011
- # // Sub-Routine Engine
- #==============================================================================#
- # ** ISS
- #==============================================================================#
- module ISS
- #==============================================================================#
- # ** SRE
- #==============================================================================#
- module SRE ; end
- #==============================================================================#
- # ** SRE::Script # A dumpable proc like class XD
- #==============================================================================#
- class SRE::Script
- attr_accessor :script
- def initialize( script ) ; @script = script end
- def get_script() ; return @script end
- end
- #==============================================================================#
- # ** SRE::ObjectHandler
- #==============================================================================#
- class SRE::ObjectHandler
- attr_accessor :character
- attr_accessor :resource
- def initialize( character )
- @character = character
- @resource = ::ISS::SRE::ResourceHandler.new()
- @resource.max = 10
- end
- def gather( n )
- @resource.increase_value( n )
- end
- def ungather( n )
- @resource.decrease_value( n )
- end
- def update()
- end
- end
- #==============================================================================#
- # ** SRE::ResourceHandler
- #==============================================================================#
- class SRE::ResourceHandler
- attr_accessor :value
- attr_accessor :max
- attr_accessor :type
- def initialize( )
- @type = :nil
- @minimum = 0
- @value = 0
- @max = 0
- end
- def cap_value() ; return [[@value, @max].min, @minimum].max end
- def cap_value!() ; @value = cap_value end
- def increase_value( n ) ; @value += n ; cap_value!() end
- def decrease_value( n ) ; increase_value( -n ) end
- def maxed?() ; return @value >= @max end
- def max?() ; return maxed?() end
- def min?() ; return @value <= @minimum end
- end
- #==============================================================================#
- # ** SRE::ActionCommand
- #==============================================================================#
- class SRE::ActionCommand
- attr_accessor :parameters
- attr_accessor :type
- def initialize( type = "", paramters = [] )
- @type = type
- @parameters = paramters
- end
- end
- #==============================================================================#
- # ** SRE::ActionCommandSet
- #==============================================================================#
- class SRE::ActionCommandSet
- attr_accessor :type
- attr_accessor :skip_procs # // Used for loop sets
- attr_accessor :break_procs # // Used for loop sets
- attr_accessor :end_procs # //
- attr_accessor :proc_order
- attr_accessor :list
- attr_accessor :name
- def initialize( )
- @name = ""
- @type = :one_shot
- @skip_procs = []
- @break_procs = []
- @end_procs = []
- @list = []
- @proc_order = [:break, :skip]
- end
- def break?( character )
- @break_procs.each { |p|
- case p
- #when ::Proc # // Proc support has been removed
- #return true if p.call( character )
- when ::ISS::SRE::Script
- return true if eval( p.get_script )
- end
- }
- return false
- end
- def skip?( character )
- @skip_procs.each { |p|
- case p
- #when ::Proc # // Proc support has been removed
- #return true if p.call( character )
- when ::ISS::SRE::Script
- return true if eval( p.get_script )
- end
- }
- return false
- end
- end
- #==============================================================================#
- # ** SRE::ActionCommandRef
- #==============================================================================#
- class SRE::ActionCommandRef
- attr_accessor :phase_actions
- attr_accessor :phase_size
- attr_accessor :type
- def initialize( )
- @type = :one_shot
- @phase_actions = []
- @phase_size = 0
- end
- def get_actionlist( n ) ;
- return nil if @phase_actions[n].nil?()
- return @phase_actions[n].clone()
- end
- end
- #==============================================================================#
- # ** SRE::ActionCommandEngine
- #==============================================================================#
- class SRE::ActionCommandEngine
- attr_accessor :action_ref
- attr_accessor :action_list
- attr_accessor :action_phase
- attr_accessor :action_set
- attr_accessor :character
- def sre_debug? ; return false end
- def initialize( character = nil )
- @character = character
- @action_ref = ::ISS::SRE::ActionCommandRef.new()
- @action_list = [] # Full action list, each set, is shifted off until its empty
- @action_set = nil # Current action set
- @action_loop = false
- @action_phase = 0 # // 0 - Start, 1 - Loop, 2 - End
- @wait_count = 0
- end
- def update()
- @wait_count -= 1 unless @wait_count == 0
- return unless @wait_count == 0
- update_actions()
- end
- def update_actions()
- unless @action_loop
- if @action_list.empty?()
- s = @action_ref.get_actionlist(@action_phase)
- @action_list << s unless s.nil?
- end
- return if @action_list.empty?()
- a = @action_list.shift()
- @action_set = a
- @action_loop = a.nil?() ? false : a.type == :loop
- p a.name if sre_debug?
- end
- return if @action_set.nil?()
- @action_set.proc_order.each { |t|
- case t
- when :break
- if @action_set.break?( @character )
- @action_phase += 1
- @action_phase %= @action_ref.phase_size
- return @action_loop = false
- else ; @action_loop = true ; end
- when :skip ; return if @action_set.skip?( @character )
- end
- }
- @action_set.list.each { |c|
- break if perform_command(c.type, c.parameters) == 2}
- end
- def perform_command( command, parameters )
- case command.upcase
- when "ANIMATION"
- action_animation( command, parameters )
- when "MOVE"
- action_move( command, parameters )
- when "GATHER"
- action_gather( command, parameters )
- when "DROPOFF", "UNGATHER"
- action_ungather( command, parameters )
- when "CHANGEPHASE"
- action_phase( command, parameters )
- when "SCRIPT"
- action_script( command, parameters )
- when "WAIT"
- action_wait( command, parameters )
- return 2
- end
- return 0
- end
- def action_animation( action, parameters )
- @character.animation_id = parameters[0].to_i
- end
- def action_move( action, parameters )
- case parameters[0].upcase()
- when "TO"
- target_x, target_y =*parameters[1] # // [x, y] integer array
- diagonal = parameters[2] # // boolean
- max_iterations = parameters[3] # // integer
- #@character.move_toward_xy( target_x, target_y )
- @character.force_path ( target_x, target_y, diagonal, max_iterations )
- when "SCRIPT_TO"
- data = []
- 5.times { |i| data[i] = eval( parameters[1] ) }
- data[1][1] += 1 # // y+
- data[2][1] -= 1 # // y-
- data[3][0] -= 1 # // x-
- data[4][0] += 1 # // x+
- #@character.find_path( *data )
- 5.times { |i| return if @character.force_path ( *data[i] ) }
- end
- end
- def action_gather( action, parameters )
- @character.rts_object.gather( 1 )
- end
- def action_ungather( action, parameters )
- @character.rts_object.ungather( 1 )
- end
- def action_phase( action, parameters )
- case parameters[0].to_s().upcase()
- when "FORWARD" ; @action_phase += 1
- when "BACKWARD" ; @action_phase -= 1
- else ; @action_phase = parameters[0].to_i
- end
- end
- def action_script( action, parameters )
- character = @character
- eval( parameters[0] )
- end
- def action_wait( action, parameters )
- @wait_count = parameters[0]
- end
- end
- #==============================================================================#
- # ** SRE
- #==============================================================================#
- module SRE
- SCR = ::ISS::SRE::Script
- DEFSCRIPTS = {
- "TRUE" => SCR.new( "true" ),
- "FALSE" => SCR.new( "false" ),
- "MOVING"=> SCR.new( "character.moving?()" ),
- }
- module_function
- def get_defScript( name ) return DEFSCRIPTS[name].clone end
- def create_Moveto_set( tx, ty, diagonol = true, mi = 0 )
- comm = ::ISS::SRE::ActionCommand.new( "MOVE", ["TO", [tx, ty], diagonol, mi] )
- set = ::ISS::SRE::ActionCommandSet.new()
- set.list << comm
- set.skip_procs << get_defScript("MOVING")
- set.break_procs << SCR.new( "character.pos?(#{tx}, #{ty})" )
- set.type = :loop
- return set
- end
- def create_ScriptMoveto_set( script )
- comm = ::ISS::SRE::ActionCommand.new( "MOVE", ["SCRIPT_TO", script] )
- set = ::ISS::SRE::ActionCommandSet.new()
- set.list << comm
- set.skip_procs << get_defScript("MOVING")
- str = %Q(
- data = character.dungeon_obj.get_next_tile()
- data = [-1, -1] if data.nil?
- character.pos?(data[0], data[1])
- )
- set.break_procs << SCR.new( str )
- set.type = :loop
- return set
- end
- def create_Gather_set( max )
- set = ::ISS::SRE::ActionCommandSet.new()
- set.list << ::ISS::SRE::ActionCommand.new( "ANIMATION", [3] )
- set.list << ::ISS::SRE::ActionCommand.new( "GATHER", [max] )
- set.list << ::ISS::SRE::ActionCommand.new( "WAIT", [12] )
- set.skip_procs << get_defScript("FALSE")
- set.break_procs << SCR.new( "character.rts_object.resource.maxed?()" )
- set.type = :loop
- return set
- end
- def create_Drop_set( max )
- scomm= ::ISS::SRE::ActionCommand.new( "SCRIPT",
- ["$game_variables[20] = [$game_variables[20] + 1, $game_variables[19]].min"] )
- set = ::ISS::SRE::ActionCommandSet.new()
- set.list << ::ISS::SRE::ActionCommand.new( "ANIMATION", [2] )
- set.list << ::ISS::SRE::ActionCommand.new( "UNGATHER", [max] )
- set.list << scomm
- set.list << ::ISS::SRE::ActionCommand.new( "WAIT", [12] )
- set.skip_procs << get_defScript("FALSE")
- set.break_procs << SCR.new( "character.rts_object.resource.min?()" )
- set.type = :loop
- return set
- end
- def create_ChangeTile_set()
- scomm= ::ISS::SRE::ActionCommand.new( "SCRIPT",
- ["character.dungeon_obj.change_tile"])
- set = ::ISS::SRE::ActionCommandSet.new()
- set.list << ::ISS::SRE::ActionCommand.new( "ANIMATION", [2] )
- set.list << scomm
- set.list << ::ISS::SRE::ActionCommand.new( "WAIT", [12] )
- set.skip_procs << get_defScript("FALSE")
- set.break_procs << SCR.new( '$game_map.data[character.x, character.y, 0] == 1568' )
- set.type = :one_shot
- return set
- end
- def create_gather_ref( max, trg = [0, 0], ret = [0, 0] )
- ref = ::ISS::SRE::ActionCommandRef.new()
- mvset1 = create_Moveto_set( trg[0], trg[1], false )
- mvset2 = create_Moveto_set( ret[0], ret[1], false )
- gthr = create_Gather_set( max )
- drp = create_Drop_set ( max )
- mvset1.name = "MoveToTarget"
- mvset2.name = "Return"
- gthr.name = "Gather"
- drp.name = "Dropoff"
- ref.phase_actions = [mvset1, gthr, mvset2, drp]
- ref.phase_size = 4
- ref.type = :loop
- return ref
- end
- def create_Marktile_set( script )
- comm = ::ISS::SRE::ActionCommand.new( "SCRIPT", [script] )
- set = ::ISS::SRE::ActionCommandSet.new()
- set.list << comm
- set.skip_procs << get_defScript("FALSE")
- str = %Q(
- data = character.dungeon_obj.get_next_tile()
- data = [-1, -1] if data.nil?
- $game_map.data[data[0], data[1], 1] == 1538
- )
- set.break_procs << SCR.new( str )
- set.type = :one_shot
- return set
- end
- def create_wallremove_ref()
- ref = ::ISS::SRE::ActionCommandRef.new()
- mvset1 = create_ScriptMoveto_set( "character.dungeon_obj.get_next_tile()" )
- mvset1.skip_procs.unshift( SCR.new( '$tile_markers.empty?()' ) )
- mvset1.name = "MoveToTarget"
- chng = create_ChangeTile_set()
- chng.name = "ChangeTile"
- mark = create_Marktile_set( %Q(
- data = character.dungeon_obj.get_next_tile()
- data = [-1, -1] if data.nil?
- $game_map.data[data[0], data[1], 1] = 1538) )
- mark.name = "MarkNextTile"
- retn = create_ScriptMoveto_set( "character.dungeon_obj.home_xy" )
- retn.break_procs.clear
- retn.break_procs << SCR.new( '!$tile_markers.empty?()' )
- retn.name = "ReturnHome"
- ref.phase_actions = [mark, mvset1, chng, retn]
- ref.phase_size = 4
- ref.type = :loop
- return ref
- end
- def setup_gather_event(event, targ_xy, ret_xy)
- event.setup_rts()
- r = create_gather_ref(event.rts_object.resource.max, targ_xy, ret_xy)
- event.rts_engine.action_ref = r
- end
- def setup_digger_event(event)
- event.setup_rts() ; event.setup_dungeon()
- r = create_wallremove_ref() ; event.rts_engine.action_ref = r
- end
- end
- end
- #==============================================================================#
- # ** Game_Character
- #==============================================================================#
- class Game_Character
- attr_accessor :sre_object
- attr_accessor :sre_engine
- # // For compat
- ref_accessor :rts_object, :sre_object
- ref_accessor :rts_engine, :sre_engine
- ref_reader :setup_rts, :setup_sre
- def setup_sre()
- @sre_object = ::ISS::SRE::ObjectHandler.new( self )
- @sre_engine = ::ISS::SRE::ActionCommandEngine.new( self )
- end
- def iss_posarray() ; return [self.x, self.y] end
- def pos_array() ; return iss_posarray() end
- alias iss005_gc_update update unless $@
- def update()
- iss005_gc_update()
- @rts_object.update() unless @sre_object.nil?()
- @rts_engine.update() unless @sre_engine.nil?()
- end
- end
- #=*==========================================================================*=#
- # ** END OF FILE
- #=*==========================================================================*=#
Advertisement
Add Comment
Please, Sign In to add comment