IceDragon200

IEX-Siren (StripMerge)

May 1st, 2011
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 42.94 KB | None | 0 0
  1. # Date Created : 01/28/2011
  2. # Date Modified: 02/07/2011
  3. module IEX
  4.   module SIREN
  5.    
  6.     RECTSIZE          = 64
  7.     TILESET_FRAMESIZE = RECTSIZE
  8.     TILESET_COLUMNS   = 8
  9.     RANGE_TYPE_NUM    = 2
  10.    
  11.     COLORSET = {
  12.     # ID=> Color.new(red, grn, blu),
  13.       0 => Color.new(  0,   0, 255), # Blue
  14.       1 => Color.new(255,   0,   0), # Red
  15.       2 => Color.new(  0, 255,   0), # Green
  16.       3 => Color.new(  0, 128, 255), # Tealish - Allies
  17.       4 => Color.new(128,   0, 198), # Purple - Enemies
  18.       5 => Color.new(255, 255,   0), # Yellow
  19.       6 => Color.new(128, 128, 128), # Grey - Aoe
  20.     } # Do Not Remove
  21.    
  22.     COLORASSIGN = {
  23.       :move   => 0,
  24.       :skill  => 2,
  25.       :attack => 5,
  26.       :aoe    => 6,
  27.     } # Do Not Remove
  28.    
  29.     SIREN_ICONS = {
  30.     # Game
  31.       :move    => 2,
  32.       :terrain => 2,
  33.       :defense => 2,
  34.       :offense => 2,
  35.     # Editor  
  36.       :pencil  => 5184,
  37.       :eraser  => 5186,
  38.       :fill    => 5185,
  39.       :eyedrop => 5187,
  40.       :save    => 5188,
  41.       :chngts  => 5178,
  42.       :vewpass => 5180,
  43.       :startpnt=> 5191,
  44.     } # Do Not Remove
  45.    
  46.     PARTY_START_POINTS = 3
  47.     TROOP_START_POINTS = 3
  48.    
  49.     PERMOVE_FRMS = 15
  50.    
  51.     STAT_AFFECTS = ['atk', 'def', 'spi', 'agi', 'dex', 'res']
  52.   end  
  53. end
  54.  
  55. module IEX
  56.   module SIREN
  57.     module EDITOR
  58.       SIREN_MAPNAME= "SirenBattlemap"
  59.       CURSOR_FRMRTE= 5
  60.       PLACE_SOUND  = RPG::SE.new("SIREN-PlacementSound", 100, 100)
  61.       FLOOD_SOUND  = RPG::SE.new("021-Dive01", 90, 100)
  62.       REMOVE_SOUND = RPG::SE.new("Booby Trap_hit", 90, 100)
  63.       CHANGE_SOUND = RPG::SE.new("016-Jump02", 70, 100)
  64.       SAMPLE_SOUND = RPG::SE.new("SIREN-RemoveSound", 100, 100)
  65.       NOMOVE_SOUND = RPG::SE.new("bump", 100, 100)
  66.       #"385992_dumbstep"
  67.       EDITOR_BGM   = RPG::BGM.new("Templar", 70, 100)
  68.      
  69.       EDITOR_BUTTON_ASSIGN = {
  70.         :accept  => Input::C,
  71.         :pencil  => Input::LETTERS['P'],
  72.         :eraser  => Input::LETTERS['O'],
  73.         :eyedrop => Input::LETTERS['I'],
  74.         :fill    => Input::LETTERS['G'],
  75.         :save    => Input::LETTERS['M'],
  76.       }
  77.       module_function
  78.      
  79.       def save_sirenmap(mapdata, id)
  80.         name = sprintf("#{SIREN_MAPNAME}%04d.rvdata", id)
  81.         save_data(mapdata, name)
  82.         return name
  83.       end
  84.      
  85.     end  
  86.   end
  87. end
  88.  
  89. module IEX
  90.   module SIREN
  91.     module BATTLEMAP
  92.      
  93.       # Passage
  94.       # 0 - Unpassable
  95.       # 1 - Passable
  96.       # 2 - Damaged and Passable
  97.       # 7 - Only Down
  98.       # 8 - Only Left
  99.       # 9 - Only Right
  100.       # 10- Only Up
  101.       # 11- Vertical Only
  102.       # 12- Horizontal Only
  103.       TILECHIP_SETTINGS = { }
  104.       TILECHIP_SETTINGS["INDOOR"] = { }
  105.       TILECHIP_SETTINGS["INDOOR"][:tileset] = "IndoorBattleBackset"
  106.       TILECHIP_SETTINGS["INDOOR"][:passage] = [
  107.       # 1, 2, 3, 4, 5, 6, 7, 8
  108.         0, 1, 1, 2, 2, 0, 0, 0,
  109.         0, 1, 1, 2, 2, 0, 0, 0,
  110.         1, 0,11,12, 0, 0, 0, 0,
  111.         1, 1, 1, 1, 1, 1, 1, 1,
  112.         1, 1, 1, 1, 1, 1, 1, 1,
  113.       ]
  114.       # Effects
  115.       # "" - No Effect
  116.       # 1 - Defense +5%
  117.       # 2 - Defense +10%
  118.       # 3 - Defense -5%
  119.       # 4 - Defense -10%
  120.       # 5 - Offense +5%
  121.       # 6 - Offense +10%
  122.       # 7 - Offense -5%
  123.       # 8 - Offense -10%
  124.       # 9 - MP-Regen
  125.       # 10- HP-Regen
  126.       # 11- Party Start Point
  127.       # 12- Troop Start Point
  128.       TILECHIP_SETTINGS["INDOOR"][:effects] = [
  129.       # 1, 2, 3, 4, 5, 6, 7, 8
  130.         [""], [""], [""], ["DEF-10%"], ["DEF-5%"], [""], [""], [""],
  131.         [""], [""], [""], [""], [""], [""], [""], [""],
  132.         [""], [""], [""], [""], [""], [""], [""], [""],
  133.         ["PSP"],["TSP"], ["MPREG+5%"],["HPREG+5%"], ["DEF+10%"], ["DEF+5%"], ["DEF+10%"], ["DEF+5%"],
  134.         [""], [""], [""], [""], [""], [""], [""], [""],
  135.       ]
  136.       module_function
  137.      
  138.       def create_siren_pos(coord, offset, type=nil)
  139.         offset = offset.to_i
  140.         offset += 8 if type == :ytype
  141.         return coord * IEX::SIREN::RECTSIZE + offset
  142.       end
  143.      
  144.       def siren_fullrange
  145.         result = []
  146.         for x in 0...$game_battlemap.data.xsize
  147.           for y in 0...$game_battlemap.data.ysize
  148.             result.push([x, y]) unless result.include?([x, y])
  149.           end
  150.         end  
  151.         return result
  152.       end
  153.      
  154.       def siren_truerange(x, y, oldranges)
  155.         result = []
  156.         for rng in oldranges
  157.           result << [rng[0]+x, rng[1]+y]
  158.         end  
  159.         return result
  160.       end
  161.      
  162.     end
  163.   end
  164. end
  165.  
  166. class Game_BattleMap
  167.  
  168.   def terrain_effects(x, y)
  169.     data = tile_effects(x, y)
  170.     result = {}
  171.     for ef in data
  172.       case ef
  173.       when /(HP|MP)REG([\+\-](?:\d+))([%%])/i
  174.         case $1.to_s.upcase
  175.         when "HP"
  176.           result["HPREGEN"] = $2.to_i
  177.         when "MP"  
  178.           result["MPREGEN"] = $2.to_i
  179.         end  
  180.       when /(\w+)([\+\-](?:\d+))([%%])/i  
  181.         result[$1.to_s.upcase] = [0, 0] if result[$1.to_s.upcase].nil?
  182.         result[$1.to_s.upcase][0] = $2.to_i
  183.       when /(\w+)([\+\-](?:\d+))/i
  184.         result[$1.to_s.upcase] = [0, 0] if result[$1.to_s.upcase].nil?
  185.         result[$1.to_s.upcase][1] = $2.to_i
  186.       end
  187.     end  
  188.     return result
  189.   end
  190.  
  191. end  
  192.  
  193. class Game_Battler
  194.    
  195.   def apply_terrain_changes(val, stat)
  196.     result = val
  197.     return result unless $game_temp.in_battle
  198.     effects = $game_battlemap.terrain_effect_at(siren_x, siren_y) #terrain_effects(siren_x, siren_y)
  199.     stas = stat.to_s.upcase
  200.     unless effects[stas].nil?
  201.       result += effects[stas][1].to_i
  202.       result += IEX::IMath.cal_percent(effects[stas][0].to_i, result)
  203.     end  
  204.     return result
  205.   end
  206.  
  207. end
  208.  
  209. class Window_BattleStatus < Window_Selectable
  210.  
  211. #~   def prevent_left_right?
  212. #~     return true
  213. #~   end  
  214.  
  215. end
  216.  
  217. class ActorCommand_Help < Window_Base
  218.  
  219.  
  220. end  
  221. #===============================================================================
  222. # Window_ActorCommand
  223. #===============================================================================
  224. class Window_ActorCommand < Window_Selectable #Window_Command
  225.    
  226.   include ICY_Window_MiniCommand
  227.  
  228.   attr_accessor :actor
  229.  
  230.   #--------------------------------------------------------------------------
  231.   # alias method: initialize
  232.   #--------------------------------------------------------------------------
  233.   alias iex_sr0_initialize initialize unless $@
  234.   def initialize
  235.     @disable_empty_commands = YEM::BATTLE_ENGINE::DISABLE_EMPTY_COMMANDS
  236.     iex_sr0_initialize
  237.   end
  238.  
  239.   #--------------------------------------------------------------------------
  240.   # new method: item
  241.   #--------------------------------------------------------------------------
  242.   def item; return @data[self.index]; end
  243.  
  244.   #--------------------------------------------------------------------------
  245.   # new method: skill
  246.   #--------------------------------------------------------------------------
  247.   def skill; return $data_skills[@skills[item]]; end
  248.    
  249.   def display_mode ; return 1 end
  250.   #--------------------------------------------------------------------------
  251.   # overwrite method: setup
  252.   #--------------------------------------------------------------------------
  253.   def setup(actor)
  254.     @last_setup = :standard
  255.     @column_max = 1
  256.     @column_max = 3 if display_mode == 1
  257.     @actor = actor
  258.     @data = []; @commands = []; @skills = {}
  259.     data_set = actor.class.id
  260.     data_set = 0 if !YEM::BATTLE_ENGINE::CLASS_COMMANDS.include?(actor.class.id)
  261.     #---
  262.     for item in YEM::BATTLE_ENGINE::CLASS_COMMANDS[data_set]
  263.       case item
  264.       when :attack; @commands.push(actor.attack_vocab)
  265.       when :skill;  @commands.push(actor.skill_vocab)
  266.       when :guard;  @commands.push(actor.guard_vocab)
  267.       when :item;   @commands.push(Vocab.item)
  268.       when :equip;  @commands.push(YEM::BATTLE_ENGINE::EQUIP_VOCAB)
  269.       when :escape
  270.         next unless $game_troop.can_escape
  271.         @commands.push(Vocab.escape)
  272.       else
  273.         valid = false
  274.         if YEM::BATTLE_ENGINE::SKILL_COMMANDS.include?(item)
  275.           @skills[item] = YEM::BATTLE_ENGINE::SKILL_COMMANDS[item][0]
  276.           @commands.push(YEM::BATTLE_ENGINE::SKILL_COMMANDS[item][1])
  277.           valid = true
  278.         end
  279.         next unless valid
  280.       end
  281.       @data.push(item)
  282.     end
  283.     #---
  284.     @commands.push("Move")
  285.     @data.push(:move)
  286.     @commands = @data
  287.     @item_max = @commands.size
  288.     refresh
  289.     self.index = 0
  290.   end
  291.  
  292.   def update_command_text ; end
  293.  
  294.   #--------------------------------------------------------------------------
  295.   # new method: update
  296.   #--------------------------------------------------------------------------
  297.   def update
  298.     return unless $scene.is_a?(Scene_Battle)
  299.     super unless Input.trigger?(Input::L) or Input.trigger?(Input::R)
  300.     if @last_index != self.index
  301.       update_command_text if display_mode == 1
  302.     end
  303.     return unless @actor == $scene.status_window.actor
  304.     refresh if @actor != nil and @actor.update_commands
  305.   end
  306.  
  307.   #--------------------------------------------------------------------------
  308.   # new method: refresh
  309.   #--------------------------------------------------------------------------
  310.   alias iex_sr0_refresh refresh unless $@
  311.   def refresh
  312.     @actor.update_commands = false if @actor != nil
  313.     iex_sr0_refresh
  314.   end
  315.  
  316.   #--------------------------------------------------------------------------#
  317.   # * new method :get_icon
  318.   #--------------------------------------------------------------------------#
  319.   def get_icon(obj) ; return iex_get_icon(obj) end
  320.   #--------------------------------------------------------------------------#
  321.   # * new method :get_vocab
  322.   #--------------------------------------------------------------------------#  
  323.   def get_vocab(obj); return iex_get_vocab(obj) end  
  324.   #--------------------------------------------------------------------------#
  325.   # * new method :lastindex_command
  326.   #--------------------------------------------------------------------------#    
  327.   def lastindex_command ; return :nil end  
  328.   #--------------------------------------------------------------------------#
  329.   # * new method :set_lastcommand
  330.   #--------------------------------------------------------------------------#        
  331.   def set_lastcommand ; end #@actor.last_command = command unless @actor.nil? end
  332.    
  333.   def iex_get_icon(command)
  334.     case command
  335.     # Default Commands
  336.     when :attack
  337.       unless @actor.weapons[0].nil?
  338.         return @actor.weapons[0].icon_index
  339.       else
  340.         return 2
  341.       end  
  342.     when :skill
  343.       return 132
  344.     when :guard
  345.       return 53
  346.     when :item
  347.       return 144
  348.     when :equip
  349.       return 32
  350.     when :escape
  351.       return 48
  352.     # Special Commands  
  353.     when :link  
  354.       return $data_skills[5].icon_index
  355.     when :sup
  356.       return $data_skills[7].icon_index
  357.     when :move
  358.       return 5177
  359.     else
  360.       return 0
  361.     end  
  362.   end
  363.  
  364.   def iex_get_vocab(command)
  365.     case command
  366.     when :attack; return @actor.nil? ? Vocab.attack : @actor.attack_vocab
  367.     when :skill;  return @actor.nil? ? Vocab.skill : @actor.skill_vocab
  368.     when :guard;  return @actor.nil? ? Vocab.guard : @actor.guard_vocab
  369.     when :item;   return Vocab.item
  370.     when :equip;  return YEM::BATTLE_ENGINE::EQUIP_VOCAB
  371.     when :escape; return Vocab.escape
  372.     else
  373.       if YEM::BATTLE_ENGINE::SKILL_COMMANDS.include?(command)
  374.         return YEM::BATTLE_ENGINE::SKILL_COMMANDS[item][1]
  375.       end
  376.     end
  377.   end
  378.  
  379.   #--------------------------------------------------------------------------
  380.   # new method: enabled?
  381.   #--------------------------------------------------------------------------
  382.   def enabled?(obj = nil)
  383.     return false unless @actor.actor?
  384.     if @actor.auto_battle
  385.       return true if obj == :equip and @actor.equip_cooldown.to_i <= 0
  386.       return true if obj == :escape and $game_troop.can_escape
  387.       return false
  388.     end
  389.     return false unless @actor.inputable?
  390.     return false if obj == nil
  391.     return false if obj == :equip and @actor.equip_cooldown.to_i > 0
  392.     if @disable_empty_commands
  393.       return false if obj == :skill and @actor.skills.size <= 0
  394.       return false if obj == :item and $game_party.battle_item_size <= 0
  395.     end
  396.     if @skills.include?(obj)
  397.       skill = $data_skills[@skills[obj]]
  398.       return @actor.skill_can_use?(skill)
  399.     end
  400.     return true
  401.   end unless method_defined? :enabled?
  402.  
  403.   #--------------------------------------------------------------------------
  404.   # new method: enabled?
  405.   #--------------------------------------------------------------------------
  406.   alias iex_sirenset_wac_enabled? enabled? unless $@
  407.   def enabled?(obj = nil)
  408.     if obj == :move && !@actor.nil?
  409.       return false unless @actor.siren_canmove?
  410.     end
  411.     iex_sirenset_wac_enabled?(obj)
  412.   end
  413.  
  414. end
  415.  
  416.  
  417. module IEX
  418.   module SIREN
  419.    
  420.     module_function
  421.    
  422.     def get_atk_direction(hx, hy, tx, ty)
  423.       if tx > hx && ty == hy
  424.         return 6
  425.       elsif tx < hx && ty == hy  
  426.         return 4
  427.       elsif tx == hx && ty > hy  
  428.         return 2
  429.       elsif tx == hx && ty < hy    
  430.         return 8
  431.       end
  432.       return 0
  433.     end  
  434.    
  435.     # 0 - Diamond   < >
  436.     # 1 - Linear     +
  437.     # 2 - X          x
  438.     # 3 - Breath     <
  439.     # 4 - SnowFlake  *
  440.     # 5 - Block     [ ]
  441.     # 6 - Directional Line ->
  442.     def create_range_data(rng, minrng=0, type=0, direction=2)
  443.       result = []
  444.       case type
  445.       when 0 # Normal - Diamond <>
  446.         for x in 0..rng
  447.           for y in 0..rng
  448.             next if x+y > rng
  449.             next if x+y < minrng
  450.             result << [ x,  y] unless result.include?([ x,  y])
  451.             result << [-x,  y] unless result.include?([-x,  y])
  452.             result << [ x, -y] unless result.include?([ x, -y])
  453.             result << [-x, -y] unless result.include?([-x, -y])
  454.           end
  455.         end
  456.       when 1 # Linear +
  457.         for x in 0..rng
  458.           for y in 0..rng
  459.             next if x+y > rng
  460.             next if x+y < minrng
  461.             result << [ x,  0] unless result.include?([ x,  0])
  462.             result << [-x,  0] unless result.include?([-x,  0])
  463.             result << [ 0, -y] unless result.include?([ 0, -y])
  464.             result << [ 0,  y] unless result.include?([ 0,  y])
  465.           end
  466.         end
  467.       when 2 # X - x
  468.         for x in 0..rng
  469.           for y in 0..rng
  470.             next if x+y > rng
  471.             next if x+y < minrng
  472.             result << [ x,  x] unless result.include?([ x,  x])
  473.             result << [-x, -x] unless result.include?([-x, -x])
  474.             result << [-y,  y] unless result.include?([-y,  y])
  475.             result << [ y, -y] unless result.include?([ y, -y])
  476.           end
  477.         end
  478.       when 3 # Breath <
  479.         for x in 0..rng
  480.           for y in 0..rng
  481.             next if x+y > rng
  482.             next if x+y < minrng
  483.             case direction
  484.             when 2  
  485.               result << [ x,  y] unless result.include?([ x,  y])
  486.               result << [-x,  y] unless result.include?([-x,  y])
  487.             when 4
  488.               result << [-x,  y] unless result.include?([-x,  y])
  489.               result << [-x, -y] unless result.include?([-x, -y])
  490.             when 6
  491.               result << [ x,  y] unless result.include?([ x,  y])
  492.               result << [ x, -y] unless result.include?([ x, -y])
  493.             when 8
  494.               result << [ x, -y] unless result.include?([ x, -y])
  495.               result << [-x, -y] unless result.include?([-x, -y])
  496.             end  
  497.           end
  498.         end
  499.       when 4 # Snow Flake *
  500.         for x in 0..rng
  501.           next if x < minrng
  502.           result << [ 0,  x] unless result.include?([ 0,  x])
  503.           result << [ x,  0] unless result.include?([ x,  0])
  504.           result << [ 0, -x] unless result.include?([ 0, -x])
  505.           result << [-x,  0] unless result.include?([-x,  0])
  506.           result << [ x,  x] unless result.include?([ x,  x])
  507.           result << [-x,  x] unless result.include?([-x,  x])
  508.           result << [ x, -x] unless result.include?([ x, -x])
  509.           result << [-x, -x] unless result.include?([-x, -x])
  510.         end  
  511.       when 5 # Block []
  512.         for x in 0..rng
  513.           for y in 0..rng
  514.             next if x+y < minrng
  515.             result << [ x,  y] unless result.include?([ x,  y])
  516.             result << [-x,  y] unless result.include?([-x,  y])
  517.             result << [ x, -y] unless result.include?([ x, -y])
  518.             result << [-x, -y] unless result.include?([-x, -y])
  519.           end
  520.         end  
  521.       when 6 # Directional Line <-
  522.         for x in 0..rng
  523.           for y in 0..rng
  524.             next if x+y > rng
  525.             next if x+y < minrng
  526.             case direction
  527.             when 2  
  528.               result << [ 0,  y] unless result.include?([ 0,  y])
  529.             when 4
  530.               result << [-x,  0] unless result.include?([-x,  0])
  531.             when 6
  532.               result << [ x,  0] unless result.include?([ x,  0])
  533.             when 8
  534.               result << [ 0, -y] unless result.include?([ 0,  -y])
  535.             end  
  536.           end
  537.         end
  538.       end
  539.       return result
  540.     end
  541.    
  542.   end
  543. end
  544.  
  545. module IEX
  546.   module REGEX
  547.    
  548.     module BASEITEM
  549.       RANGE = /<RANGE:[ ](\d+)[ ]*,[ ]*(\d+)[ ]*,[ ]*(\d+)>/i
  550.       AOE   = /<AOE:[ ](\d+)[ ]*,[ ]*(\d+)[ ]*,[ ]*(\d+)>/i
  551.     end
  552.    
  553.     module ITEM
  554.     end  
  555.    
  556.     module WEAPON
  557.     end
  558.    
  559.     module ARMOR
  560.     end
  561.    
  562.     module SKILL
  563.     end  
  564.    
  565.     module STATE
  566.     end
  567.    
  568.     module ENEMY
  569.       ATTACK_RANGE = /<(?:ATK|ATTACK)(?:RANGE|_RANGE| RANGE):[ ](\d+)[ ]*,[ ]*(\d+)[ ]*,[ ]*(\d+)>/i
  570.       ATTACK_AOE   = /<(?:ATK|ATTACK)(?:AOE|_AOE| AOE):[ ](\d+)[ ]*,[ ]*(\d+)[ ]*,[ ]*(\d+)>/i
  571.       MOVE_RANGE   = /<(?:MV|MOVE)(?:RANGE|_RANGE| RANGE):[ ](\d+)[ ]*,[ ]*(\d+)[ ]*,[ ]*(\d+)>/i
  572.     end
  573.  
  574.   end
  575. end
  576.  
  577. class RPG::BaseItem
  578.  
  579.   attr_accessor :range
  580.   attr_accessor :aoe
  581.  
  582.   def iex_siren_bsi_cache
  583.     # Range Types
  584.     # 0 - Diamond   < >
  585.     # 1 - Linear     +
  586.     # 2 - X          x
  587.     # 3 - Breath     <
  588.     # 4 - SnowFlake  *
  589.     # 5 - Block     [ ]
  590.     #        [rng, minrng, type]
  591.     @range = [1,   0,      0   ]
  592.     @aoe   = [0,   0,      0   ]
  593.     self.note.split(/[\r\n]+/).each { |line|
  594.       case line
  595.       when IEX::REGEX::BASEITEM::RANGE
  596.         @range = [$1.to_i, $2.to_i, $3.to_i]
  597.       when IEX::REGEX::BASEITEM::AOE  
  598.         @aoe = [$1.to_i, $2.to_i, $3.to_i]
  599.       end
  600.     }
  601.   end
  602.  
  603. end
  604.  
  605. class RPG::Item
  606.  
  607.   def iex_siren_ite_cache
  608. #~     self.note.split(/[\r\n]+/).each { |line|
  609. #~       case line
  610. #~       when
  611. #~       end
  612. #~     }
  613.   end
  614.  
  615. end
  616.  
  617. class RPG::Weapon
  618.  
  619.   def iex_siren_wep_cache
  620. #~     self.note.split(/[\r\n]+/).each { |line|
  621. #~       case line
  622. #~       when
  623. #~       end
  624. #~     }
  625.   end
  626.  
  627. end
  628.  
  629. class RPG::Armor
  630.  
  631.   def iex_siren_arm_cache
  632. #~     self.note.split(/[\r\n]+/).each { |line|
  633. #~       case line
  634. #~       when
  635. #~       end
  636. #~     }
  637.   end
  638.    
  639. end
  640.  
  641. class RPG::Skill
  642.  
  643.   def iex_siren_ski_cache
  644. #~     self.note.split(/[\r\n]+/).each { |line|
  645. #~       case line
  646. #~       when
  647. #~       end
  648. #~     }
  649.   end
  650.    
  651. end
  652.  
  653. class RPG::State
  654.  
  655.   def iex_siren_ste_cache
  656. #~     self.note.split(/[\r\n]+/).each { |line|
  657. #~       case line
  658. #~       when
  659. #~       end
  660. #~     }
  661.   end
  662.    
  663. end
  664.  
  665. class RPG::Enemy
  666.  
  667.   attr_accessor :attackrange
  668.   attr_accessor :attackaoe
  669.   attr_accessor :moverange
  670.  
  671.   def iex_siren_eny_cache
  672.     @attackrange = [1, 0, 0]
  673.     @attackaoe   = [0, 0, 0]
  674.     @moverange   = [3, 0, 0]
  675.     self.note.split(/[\r\n]+/).each { |line|
  676.       case line
  677.       when IEX::REGEX::ENEMY::ATTACK_RANGE
  678.         @attackrange = [$1.to_i, $2.to_i, $3.to_i]
  679.       when IEX::REGEX::ENEMY::ATTACK_AOE
  680.         @attackaoe   = [$1.to_i, $2.to_i, $3.to_i]
  681.       when IEX::REGEX::ENEMY::MOVE_RANGE
  682.         @moverange   = [$1.to_i, $2.to_i, $3.to_i]
  683.       end
  684.     }
  685.   end
  686.    
  687. end
  688.  
  689. class SirenMap
  690.  
  691.   attr_accessor :id
  692.   attr_accessor :name
  693.   attr_accessor :data
  694.   attr_accessor :tileset
  695.   attr_accessor :tilechip
  696.   attr_accessor :start_points
  697.  
  698.   def initialize
  699.     @name     = ""
  700.     @id       = 0
  701.     @data     = Table.new(1, 1, 2)
  702.     @tileset  = ""
  703.     @tilechip = ""
  704.     @start_points = {}
  705.     @start_points[:troop] = {}
  706.     @start_points[:party] = {}
  707.   end
  708.  
  709.   class StartPoint
  710.     attr_accessor :x
  711.     attr_accessor :y
  712.    
  713.     def initialize(x, y)
  714.       @x = x
  715.       @y = y
  716.     end
  717.    
  718.   end
  719.  
  720. end
  721.  
  722. class Game_BattleMap
  723.  
  724.   include IEX::SIREN
  725.   include IEX::SIREN::EDITOR
  726.   include IEX::SIREN::BATTLEMAP
  727.  
  728.   def initialize
  729.     @map_data = Table.new(1, 1, 2)
  730.     @map = SirenMap.new
  731.   end
  732.  
  733.   def setup(map_id)
  734.     if map_id.nil?
  735.       w = Graphics.width  / RECTSIZE
  736.       h = Graphics.height / RECTSIZE
  737.       @map = SirenMap.new
  738.       @map.data = Table.new(w, h, 2)
  739.       for x in 0...@map.data.xsize
  740.         for y in 0...@map.data.ysize
  741.           @map.data[x, y, 0] = 0
  742.         end
  743.       end
  744.     else
  745.       load = load_data(sprintf("#{SIREN_MAPNAME}%04d.rvdata", map_id))
  746.       if load.is_a?(Table)
  747.         @map = SirenMap.new
  748.         @map.data = load
  749.       else
  750.         @map = load
  751.       end  
  752.     end  
  753.     @terrain_effect_table = IEX::ITable.new(@map.data.xsize, @map.data.ysize, 1, {})
  754.     for x in 0...@map.data.xsize
  755.       for y in 0...@map.data.ysize
  756.         @terrain_effect_table[x, y, 0] = terrain_effects(x, y)
  757.       end
  758.     end
  759.   end
  760.  
  761.   def change_tile(x, y, z, newtileid)
  762.     @map.data[x, y, z] = newtileid
  763.     @terrain_effect_table[x, y, z] = terrain_effects(x, y)
  764.   end
  765.  
  766.   def terrain_effect_at(x, y)
  767.     return @terrain_effect_table[x, y, 0]
  768.   end
  769.  
  770.   def get_start_points(party, index)
  771.     return @map.start_points[party.siren_group][index]
  772.   end
  773.  
  774.   def map ; return @map end
  775.    
  776.   def current_tilechip
  777.     return @map.tilechip
  778.   end
  779.  
  780.   def data
  781.     return @map.data
  782.   end
  783.  
  784.   def passable?(x, y, obj = nil)
  785.     data = TILECHIP_SETTINGS[current_tilechip][:passage]
  786.     tid = @map.data[x, y, 0].to_i
  787.     case data[tid]
  788.     when 0 ; return false
  789.     when 1 ; return true
  790.     when 2 ; return true  
  791.     when 11
  792.       return true if obj.nil?
  793.       return true if y != obj.y and x == obj.x  
  794.     when 12
  795.       return true if obj.nil?
  796.       return true if y == obj.y and x != obj.x
  797.     end
  798.     return false  
  799.   end
  800.  
  801.   def tile_effects(x, y)
  802.     return [] if TILECHIP_SETTINGS[current_tilechip].nil?
  803.     data = TILECHIP_SETTINGS[current_tilechip][:effects]
  804.     tid = @map.data[x, y, 0].to_i
  805.     return data[tid]
  806.   end
  807.  
  808.   def get_battlers_xy(x, y)
  809.     result = []
  810.     for bat in $game_troop.members + $game_party.members
  811.       result << bat if bat.siren_xy?(x, y)
  812.     end  
  813.     return result
  814.   end
  815.  
  816. end
  817.  
  818. class Game_Battler
  819.  
  820.   def siren_canmove?
  821.     return @move_pnt > 0
  822.   end
  823.  
  824.   def set_siren_xy(nx, ny)
  825.     @siren_x = nx
  826.     @siren_y = ny
  827.   end
  828.  
  829.   def siren_x ; return @siren_x end
  830.   def siren_y ; return @siren_y end
  831.   def siren_x=(val) ; @siren_x = val end  
  832.   def siren_y=(val) ; @siren_y = val end
  833.   def siren_xy?(sx, sy) ; return (@siren_x == sx && @siren_y == sy) end
  834.  
  835.   def siren_origin_x
  836.     mx = @siren_x.to_i    
  837.     hx = IEX::SIREN::RECTSIZE/2      
  838.     x  = IEX::SIREN::BATTLEMAP.create_siren_pos(mx, hx)    
  839.     return x
  840.   end  
  841.  
  842.   def siren_origin_y
  843.     my = @siren_y.to_i
  844.     hy = IEX::SIREN::RECTSIZE/2
  845.     y  = IEX::SIREN::BATTLEMAP.create_siren_pos(my, hy, :ytype)
  846.     return y
  847.   end
  848.  
  849.   def attack_range
  850.     return [1, 0, 0]
  851.   end
  852.  
  853.   def attack_aoe
  854.     return [0, 0, 0]
  855.   end
  856.  
  857.   def move_range
  858.     return @move_pnt
  859.   end
  860.  
  861.   def skill_range(skill)
  862.     return skill.range
  863.   end
  864.  
  865.   def skill_aoe(skill)
  866.     return skill.aoe
  867.   end
  868.  
  869.   IEX::SIREN::STAT_AFFECTS.each { |meth|
  870.   meth = meth.to_s.downcase
  871.   mStr = %Q(
  872.     alias iex_sirencore_gmb_#{meth} #{meth} unless $@
  873.     def #{meth}
  874.       stat = iex_sirencore_gmb_#{meth}
  875.       stat = apply_terrain_changes(stat, '#{meth}')
  876.       return Integer(stat)
  877.     end  
  878.   )
  879.   module_eval(mStr)
  880.   }
  881. end
  882.  
  883. class Game_Enemy < Game_Battler
  884.  
  885.   def attack_range
  886.     return enemy.attackrange
  887.   end
  888.  
  889.   def attack_aoe
  890.     return enemy.attackaoe
  891.   end
  892.  
  893.   def skill_range(skill)
  894.     return skill.range
  895.   end
  896.  
  897.   def skill_aoe(skill)
  898.     return skill.aoe
  899.   end
  900.  
  901.   def origin_x    
  902.     return siren_origin_x
  903.   end  
  904.  
  905.   def origin_y
  906.     return siren_origin_y
  907.   end
  908.  
  909. end
  910.  
  911. class Game_Actor < Game_Battler
  912.  
  913.   def attack_range
  914.     return weapons[0].range
  915.   end
  916.  
  917.   def attack_aoe
  918.     return weapons[0].aoe
  919.   end
  920.  
  921.   def skill_range(skill)
  922.     return skill.range
  923.   end
  924.  
  925.   def skill_aoe(skill)
  926.     return skill.aoe
  927.   end
  928.  
  929.   def origin_x    
  930.     return siren_origin_x
  931.   end  
  932.  
  933.   def origin_y
  934.     return siren_origin_y
  935.   end
  936.  
  937. end
  938.  
  939. class Game_Troop < Game_Unit
  940.  
  941.   def home_y
  942.     hx = IEX::SIREN::RECTSIZE/2 ;  hy = IEX::SIREN::RECTSIZE/2
  943.     gw = Graphics.width ; gh = Graphics.height
  944.     result = gh / IEX::SIREN::RECTSIZE
  945.     result -= members.size
  946.     result = result.abs
  947.     result /= 2
  948.     return result
  949.   end
  950.  
  951.   def home_x ; return 1 end
  952.  
  953.   def siren_group ; return :troop end
  954.    
  955. end
  956.  
  957. class Game_Party < Game_Unit
  958.  
  959.   def home_y
  960.     hx = IEX::SIREN::RECTSIZE/2 ;  hy = IEX::SIREN::RECTSIZE/2
  961.     gw = Graphics.width ; gh = Graphics.height
  962.     result = gh / IEX::SIREN::RECTSIZE
  963.     result -= members.size
  964.     result = result.abs
  965.     result /= 2
  966.     return result
  967.   end  
  968.  
  969.   def home_x ; return 8 end
  970.  
  971.   def siren_group ; return :party end
  972.    
  973. end
  974.  
  975. class Siren_CursorRect < Rect
  976.  
  977.   include IEX::SIREN
  978.   include IEX::SIREN::EDITOR
  979.  
  980.   attr_accessor :rngdata
  981.  
  982.   def initialize(x, y, width, height)
  983.     super(x, y, width, height)
  984.     @rngdata = []
  985.     @rngcursor_rect = self
  986.   end
  987.  
  988.   def update
  989.     update_cursor
  990.   end
  991.  
  992.   def update_cursor
  993.     cx = @rngcursor_rect.x
  994.     cy = @rngcursor_rect.y
  995.     if Input.repeat?(Input::RIGHT)
  996.       if @rngdata.include?([cx+1, cy])
  997.         Sound.play_cursor
  998.         @rngcursor_rect.x = cx + 1
  999.       else
  1000.         NOMOVE_SOUND.play
  1001.       end  
  1002.     elsif Input.repeat?(Input::LEFT)
  1003.       if @rngdata.include?([cx-1, cy])
  1004.         Sound.play_cursor
  1005.         @rngcursor_rect.x = cx - 1
  1006.       else
  1007.         NOMOVE_SOUND.play
  1008.       end
  1009.     elsif Input.repeat?(Input::UP)
  1010.       if @rngdata.include?([cx, cy-1])
  1011.         Sound.play_cursor
  1012.         @rngcursor_rect.y = cy - 1
  1013.       else
  1014.         NOMOVE_SOUND.play
  1015.       end
  1016.     elsif Input.repeat?(Input::DOWN)
  1017.       if @rngdata.include?([cx, cy+1])
  1018.         Sound.play_cursor
  1019.         @rngcursor_rect.y = cy + 1
  1020.       else
  1021.         NOMOVE_SOUND.play
  1022.       end
  1023.     end
  1024.   end
  1025.  
  1026. end
  1027.  
  1028. class Spriteset_BattleMap < Sprite
  1029.  
  1030.   include IEX::SIREN
  1031.  
  1032.   attr_accessor :forced_update
  1033.  
  1034.   def initialize(map, viewport=nil)
  1035.     super(viewport)
  1036.     self.x = 0 ; self.y = 0
  1037.     self.bitmap = Bitmap.new(Graphics.width, Graphics.height)
  1038.     @forced_update = false
  1039.     @battlemap = map
  1040.     @tileset = []
  1041.     @tileset[0] = Cache.picture(@battlemap.map.tileset)
  1042.     @tilechip = @battlemap.map.tilechip
  1043.     @do_tile_update = false
  1044.     for x in 0...@battlemap.data.xsize
  1045.       for y in 0...@battlemap.data.ysize
  1046.         place_tile(@tileset[0], x, y, @battlemap.data[x, y, 0])
  1047.       end
  1048.     end  
  1049.     @stored_data = @battlemap.data.dup
  1050.   end
  1051.  
  1052.   def place_tile(tileset, x, y, tindex, clear = false)
  1053.     tfs = TILESET_FRAMESIZE ; tc  = TILESET_COLUMNS
  1054.     tindex = tindex.to_i
  1055.     rect = Rect.new(x*tfs, y*tfs, tfs, tfs)
  1056.     brect= Rect.new(tindex % tc * tfs, tindex / tc * tfs, tfs, tfs)
  1057.     self.bitmap.clear_rect(rect) if clear
  1058.     self.bitmap.blt(rect.x, rect.y, tileset, brect)
  1059.   end
  1060.  
  1061.   def update
  1062.     super
  1063.     if @tilechip != @battlemap.map.tilechip
  1064.       self.bitmap.clear
  1065.       @stored_data = Table.new(@battlemap.data.xsize, @battlemap.data.ysize, @battlemap.data.zsize)
  1066.       @tileset[0] = Cache.picture(@battlemap.map.tileset)
  1067.       @tilechip = @battlemap.map.tilechip
  1068.     end
  1069.     tile_change = false
  1070.     if @do_tile_update
  1071.       for x in 0...@battlemap.data.xsize
  1072.         for y in 0...@battlemap.data.ysize
  1073.           next if @stored_data[x, y, 0] == @battlemap.data[x, y, 0] and !@forced_update
  1074.           place_tile(@tileset[0], x, y, @battlemap.data[x, y, 0], true)
  1075.           tile_change = true
  1076.         end
  1077.       end
  1078.     end  
  1079.     Graphics.frame_reset if tile_change
  1080.     @stored_data = @battlemap.data.clone
  1081.     @forced_update = false
  1082.   end
  1083.  
  1084. end
  1085.  
  1086. class Siren_BattleCursor < Sprite_Base
  1087.  
  1088.   include IEX::SIREN
  1089.  
  1090.   attr_accessor :intern_rect
  1091.  
  1092.   def initialize(viewport, color=nil)
  1093.     super(viewport)
  1094.     color = Color.new(128, 20, 20) if color.nil?
  1095.     x = RECTSIZE / 8 ; y = RECTSIZE / 8
  1096.     w = RECTSIZE - x ; h = RECTSIZE - y
  1097.     x /= 2 ; y /= 2
  1098.     pre_rect = Rect.new(0, 0, RECTSIZE, RECTSIZE)
  1099.     self.bitmap = Bitmap.new(RECTSIZE, RECTSIZE)
  1100.     self.bitmap.fill_rect(pre_rect, color)
  1101.     crect = pre_rect.dup
  1102.     crect.x = x ; crect.y = y ; crect.width = w ; crect.height = h
  1103.     self.bitmap.clear_rect(crect)
  1104.     self.z = 6
  1105.     self.blend_type = 1
  1106.     @intern_rect = Rect.new(0, 0, 0, 0)
  1107.   end
  1108.  
  1109.   def update
  1110.     super
  1111.     update_move_to
  1112.   end  
  1113.  
  1114.   #--------------------------------------------------------------------------
  1115.   # new method: create_move_to
  1116.   #--------------------------------------------------------------------------
  1117.   def create_move_to(destination_x, destination_y, total_frames = 60)
  1118.     den = [total_frames, 1].max
  1119.     if destination_x != nil
  1120.       @move_to_x = Integer(destination_x)
  1121.       @move_rate_x = [RECTSIZE.abs/den, 2].max
  1122.     end
  1123.     if destination_y != nil
  1124.       @move_to_y = Integer(destination_y)
  1125.       @move_rate_y = [RECTSIZE.abs/den, 2].max
  1126.     end
  1127.     return if @character_sprite == nil
  1128.   end
  1129.  
  1130.   #--------------------------------------------------------------------------
  1131.   # new method: update_move_to
  1132.   #--------------------------------------------------------------------------
  1133.   def update_move_to
  1134.     if @move_to_x != nil
  1135.       value = [(self.x - @move_to_x).abs, @move_rate_x].min
  1136.       self.x += (@move_to_x > self.x) ? value : -value
  1137.       @move_to_x = nil if self.x == @move_to_x
  1138.     end
  1139.     if @move_to_y != nil
  1140.       value = [(self.y - @move_to_y).abs, @move_rate_y].min
  1141.       self.y += (@move_to_y > self.y) ? value : -value
  1142.       @move_to_y = nil if self.y == @move_to_y
  1143.     end
  1144.   end
  1145.  
  1146. end  
  1147.  
  1148. class Siren_PositionSprite < Sprite
  1149.  
  1150.   def initialize(viewport)
  1151.     super(viewport)
  1152.     @old_pos = []
  1153.     self.bitmap = Bitmap.new(320, 96)
  1154.     self.bitmap.font.size = 36
  1155.     update_pos(0, 0)
  1156.   end
  1157.  
  1158.   def update_pos(newx, newy)
  1159.     if @old_pos[0] != newx || @old_pos[1] != newy
  1160.       self.bitmap.clear
  1161.       self.bitmap.draw_text(0, 0, 300, 56, "#{newx},#{newy}", 2)
  1162.       @old_pos = [newx, newy]
  1163.     end  
  1164.   end
  1165.  
  1166. end  
  1167.  
  1168. class Siren_TileWindow < Window_Base
  1169.  
  1170.   include IEX::SIREN
  1171.  
  1172.   def initialize(tileset, width, height)
  1173.     super(0, 0, width, height)
  1174.     @tileindex = 0
  1175.     @tileset = tileset
  1176.     refresh
  1177.   end
  1178.  
  1179.   def tileindex_limit
  1180.     bitmap = Cache.picture(@tileset)
  1181.     result = bitmap.rect.height / TILESET_FRAMESIZE
  1182.     result *= TILESET_COLUMNS
  1183.     return result
  1184.   end
  1185.  
  1186.   def current_tileindex ; return @tileindex end
  1187.   def current_tileset ; return @tileset end
  1188.  
  1189.   def update_tilset(new_tileset)
  1190.     if @tileset != new_tileset
  1191.       change_tileset(new_tileset)
  1192.     end  
  1193.   end
  1194.  
  1195.   def change_tileset(new_tileset)
  1196.     @tileset = new_tileset
  1197.     refresh
  1198.   end
  1199.  
  1200.   def update_tileindex(new_tileindex)
  1201.     if @tileindex != new_tileindex
  1202.       @tileindex = new_tileindex
  1203.       refresh
  1204.     end  
  1205.   end  
  1206.  
  1207.   def refresh
  1208.     @item_max = (self.width-32) / TILESET_FRAMESIZE
  1209.     targ_index = @tileindex - (@item_max/2)
  1210.     for i in 0...@item_max
  1211.       draw_tile(i, 0, targ_index+i, targ_index+i == @tileindex ? 255 : 128)
  1212.     end
  1213.   end  
  1214.  
  1215.   def draw_tile(x, y, index, opac=255)
  1216.     bitmap = Cache.picture(@tileset)
  1217.     tfs = TILESET_FRAMESIZE ; tc  = TILESET_COLUMNS
  1218.     tindex = index
  1219.     rect = Rect.new(x*tfs, y*tfs, tfs, tfs)
  1220.     brect= Rect.new(tindex % tc * tfs, tindex / tc * tfs, tfs, tfs)
  1221.     self.contents.clear_rect(rect)
  1222.     self.contents.blt(rect.x, rect.y, bitmap, brect, opac)
  1223.   end
  1224.  
  1225. end
  1226.  
  1227. class Siren_IconWindow < Window_Base
  1228.  
  1229.   def change_icon(new_icon)
  1230.     @old_icon = 0 if @old_icon.nil?
  1231.     if @old_icon != new_icon.to_i
  1232.       self.contents.clear
  1233.       draw_icon(new_icon.to_i, 0, 0)
  1234.       @old_icon = new_icon.to_i
  1235.     end  
  1236.   end
  1237.  
  1238.   def update_icon(new_icon)
  1239.     change_icon(new_icon)
  1240.   end
  1241.  
  1242. end
  1243.  
  1244. class Siren_Window_Terrain < Window_Base
  1245.  
  1246.   def initialize(x, y)
  1247.     super(x, y, 128, 56)
  1248.   end
  1249.  
  1250.   def update_tileid(x, y)
  1251.     $game_battlemap.data[x, y, 0]
  1252.   end
  1253.  
  1254. end  
  1255.  
  1256. class Scene_BattleMap_Editor < Scene_Base
  1257.  
  1258.   include IEX::SIREN
  1259.   include IEX::SIREN::EDITOR
  1260.   include IEX::SIREN::BATTLEMAP
  1261.  
  1262.   def initialize
  1263.     RPG::BGM.fade(1000)
  1264.     super
  1265.     @tilechip = TILECHIP_SETTINGS.keys[0]
  1266.     $game_battlemap.setup(nil)
  1267.     $game_battlemap.map.tilechip = @tilechip
  1268.     $game_battlemap.map.tileset  = TILECHIP_SETTINGS[@tilechip][:tileset]
  1269.     @windows = {}
  1270.     @viewport1   = Viewport.new(0, 0, Graphics.width, Graphics.height)
  1271.     @viewport2   = Viewport.new(0, 0, Graphics.width, Graphics.height)
  1272.     @viewport2.z = 50
  1273.     @spriteset   = Spriteset_BattleMap.new($game_battlemap, @viewport1)
  1274.     @spriteset.forced_update = true
  1275.     @spriteset.z = 3
  1276.     @spriteset.visible = true
  1277.     @tileindex   = 0
  1278.     @rngdata     = []
  1279.     @rngdata = siren_fullrange
  1280.     create_cursor
  1281.     @posprite      = Siren_PositionSprite.new(@viewport2)
  1282.     @posprite.x    = Graphics.width - @posprite.bitmap.width
  1283.     @posprite.y    = Graphics.height - @posprite.bitmap.height
  1284.     @indexsprite   = Siren_PositionSprite.new(@viewport2)
  1285.     @indexsprite.x = Graphics.width - @posprite.bitmap.width
  1286.     @indexsprite.y = Graphics.height - @posprite.bitmap.height
  1287.     @indexsprite.y -= 64
  1288.     @rngcursor_rect.rngdata = @rngdata
  1289.     @mapcount = Dir.glob("#{SIREN_MAPNAME}*.rvdata").size + 1
  1290.    
  1291.     @start_points = {}
  1292.     @start_points[:troop] = {}
  1293.     @start_points[:party] = {}
  1294.     for i in 0...PARTY_START_POINTS
  1295.       @start_points[:party][i] = Siren_BattleCursor.new(@viewport1, COLORSET[3])
  1296.       @start_points[:party][i].z = 10
  1297.       @start_points[:party][i].visible = false
  1298.       @start_points[:party][i].bitmap.font.size = RECTSIZE - (RECTSIZE/8)
  1299.       @start_points[:party][i].bitmap.draw_text(0, 0, RECTSIZE, RECTSIZE, i, 1)
  1300.     end  
  1301.     for i in 0...TROOP_START_POINTS
  1302.       @start_points[:troop][i] = Siren_BattleCursor.new(@viewport1, COLORSET[4])
  1303.       @start_points[:troop][i].z = 10
  1304.       @start_points[:troop][i].visible = false
  1305.       @start_points[:troop][i].bitmap.font.size = RECTSIZE - (RECTSIZE/8)
  1306.       @start_points[:troop][i].bitmap.draw_text(0, 0, RECTSIZE, RECTSIZE, i, 1)
  1307.     end  
  1308.   end
  1309.  
  1310.   def start
  1311.     super
  1312.     @windows["Tile"] = Siren_TileWindow.new($game_battlemap.map.tileset,
  1313.       RECTSIZE*5+32, RECTSIZE+32)
  1314.     #@windows["Tile"].opacity = 128  
  1315.     @windows["Tile"].x = 10
  1316.     @windows["Tile"].y = Graphics.height - @windows["Tile"].height - 10
  1317.     @windows["Save"] = Window_Base.new(0, 0, 360, 56)
  1318.     @windows["Save"].x = (Graphics.width - @windows["Save"].width) / 2
  1319.     @windows["Save"].y = (Graphics.height - @windows["Save"].height) / 2
  1320.     @windows["Save"].openness = 0
  1321.     @windows["Tool"] = Siren_IconWindow.new(0, 0, 56, 56)
  1322.     @windows["Tool"].x = Graphics.width - @windows["Tool"].width
  1323.     commands = ["Return", "Leave Map Editor", "Setup Start points", "LoadMap"]
  1324.     @windows["Command"] = Window_Command.new(172, commands)
  1325.     @windows["Command"].x = (Graphics.width - @windows["Command"].width) / 2
  1326.     @windows["Command"].y = (Graphics.height - @windows["Command"].height) / 2
  1327.     @windows["Command"].active = false
  1328.     @windows["Command"].openness = 0
  1329.     @current_tool = :pencil
  1330.     EDITOR_BGM.play
  1331.   end
  1332.  
  1333.   def terminate
  1334.     super
  1335.     @viewport1.dispose    unless @viewport1.nil?
  1336.     @viewport2.dispose    unless @viewport2.nil?
  1337.     @spriteset.dispose    unless @spriteset.nil?
  1338.     @posprite.dispose     unless @posprite.nil?
  1339.     @indexsprite.dispose  unless @indexsprite.nil?
  1340.     @range_cursor.dispose unless @range_cursor.nil?
  1341.     for win in @windows.values
  1342.       next if win.nil?
  1343.       win.dispose
  1344.     end
  1345.     @windows.clear
  1346.   end
  1347.  
  1348.   def return_scene
  1349.     $game_map.autoplay
  1350.     $scene = Scene_Map.new
  1351.     GC.start
  1352.   end
  1353.  
  1354.   def create_cursor
  1355.     @rngcursor_rect = Siren_CursorRect.new(0, 0, 0, 0)
  1356.     @range_cursor = Siren_BattleCursor.new(@viewport1)
  1357.     @range_cursor.visible = true
  1358.   end
  1359.  
  1360.   def update_basic
  1361.     Graphics.update
  1362.     Input.update
  1363.     @viewport1.update
  1364.     @viewport2.update
  1365.   end
  1366.  
  1367.   def update
  1368.     super
  1369.     @viewport1.update
  1370.     @viewport2.update
  1371.     update_user_input
  1372.     update_cursor
  1373.     @range_cursor.update
  1374.     for win in @windows.values
  1375.       next if win.nil?
  1376.       win.update if win.active
  1377.     end  
  1378.     @windows["Tile"].update_tilset($game_battlemap.map.tileset)
  1379.     @windows["Tile"].update_tileindex(@tileindex)
  1380.     @windows["Tool"].update_icon(SIREN_ICONS[@current_tool])
  1381.     update_range_cursor(@rngcursor_rect.x, @rngcursor_rect.y)
  1382.     @posprite.update_pos(@rngcursor_rect.x, @rngcursor_rect.y)
  1383.     ati = $game_battlemap.data[@rngcursor_rect.x, @rngcursor_rect.y, 0]
  1384.     @indexsprite.update_pos(ati, @mapcount)
  1385.     @spriteset.update
  1386.   end
  1387.  
  1388.   def update_user_input      
  1389.     if Input.trigger?(Input::B)
  1390.       Sound.play_cancel
  1391.       @windows["Command"].open
  1392.       closing = false
  1393.       loop do
  1394.         update_basic
  1395.         @windows["Command"].update
  1396.         if @windows["Command"].openness == 255
  1397.           @windows["Command"].active = true
  1398.           if Input.trigger?(Input::C)
  1399.             case @windows["Command"].index.to_i
  1400.             when 0
  1401.               Sound.play_decision
  1402.               closing = true
  1403.               @windows["Command"].close
  1404.             when 1
  1405.               Sound.play_decision
  1406.               return_scene
  1407.               break
  1408.             when 2
  1409.               Sound.play_decision
  1410.               closing = true
  1411.               @windows["Command"].close
  1412.               @windows["Command"].openness = 0
  1413.               @windows["Command"].active = false
  1414.               update_set_start_points
  1415.             end  
  1416.           elsif Input.trigger?(Input::B)
  1417.             Sound.play_cancel
  1418.             closing = true
  1419.             @windows["Command"].close
  1420.           end  
  1421.         end  
  1422.         break if closing && @windows["Command"].openness == 0
  1423.       end  
  1424.       @windows["Command"].active = false
  1425.     elsif Input.trigger?(Input::C)
  1426.       tool_action(@current_tool)
  1427.     elsif Input.trigger?(Input::X)
  1428.       tool_action(:eraser)
  1429.     elsif Input.trigger?(Input::Y)    
  1430.       tool_action(:eyedrop)
  1431.     elsif Input.trigger?(Input::Z)    
  1432.       tool_action(:fill)
  1433.     elsif Input.repeat?(Input::L)
  1434.       CHANGE_SOUND.play
  1435.       @tileindex = (@tileindex-1) % @windows["Tile"].tileindex_limit
  1436.     elsif Input.repeat?(Input::R)    
  1437.       CHANGE_SOUND.play
  1438.       @tileindex = (@tileindex+1) % @windows["Tile"].tileindex_limit
  1439.     elsif Input.trigger?(EDITOR_BUTTON_ASSIGN[:save])  
  1440.       Sound.play_save
  1441.       name = save_sirenmap($game_battlemap.map, @mapcount)
  1442.       @windows["Save"].contents.clear
  1443.       @windows["Save"].contents.draw_text(0, 0, 320, 24, "Save Complete", 1)
  1444.       @windows["Save"].open
  1445.       @windows["Save"].openness = 1
  1446.       clos = false
  1447.       loop do
  1448.         update_basic
  1449.         @windows["Save"].update
  1450.         if Input.trigger?(Input::C)
  1451.           clos = true
  1452.           @windows["Save"].close
  1453.         end  
  1454.         break if @windows["Save"].openness == 0
  1455.       end  
  1456.       @mapcount += 1
  1457.     elsif Input.trigger?(EDITOR_BUTTON_ASSIGN[:pencil])
  1458.       CHANGE_SOUND.play ; @current_tool = :pencil
  1459.     elsif Input.trigger?(EDITOR_BUTTON_ASSIGN[:eraser])
  1460.       CHANGE_SOUND.play ; @current_tool = :eraser  
  1461.     elsif Input.trigger?(EDITOR_BUTTON_ASSIGN[:eyedrop])
  1462.       CHANGE_SOUND.play ; @current_tool = :eyedrop
  1463.     elsif Input.trigger?(EDITOR_BUTTON_ASSIGN[:fill])
  1464.       CHANGE_SOUND.play ; @current_tool = :fill  
  1465.     elsif Input.trigger?(Input::LETTERS['H'])  
  1466.       @windows["Tile"].active = true
  1467.       if @windows["Tile"].openness == 255
  1468.         @windows["Tile"].close
  1469.       else
  1470.         @windows["Tile"].open
  1471.       end  
  1472.     end  
  1473.   end
  1474.  
  1475.   def tool_action(tool)
  1476.     case tool
  1477.     when :pencil
  1478.       PLACE_SOUND.play
  1479.       $game_battlemap.data[@rngcursor_rect.x, @rngcursor_rect.y, 0] = @windows["Tile"].current_tileindex.to_i
  1480.     when :eraser
  1481.       REMOVE_SOUND.play
  1482.       $game_battlemap.data[@rngcursor_rect.x, @rngcursor_rect.y, 0] = 0
  1483.     when :eyedrop
  1484.       SAMPLE_SOUND.play
  1485.       @tileindex = $game_battlemap.data[@rngcursor_rect.x, @rngcursor_rect.y, 0]
  1486.     when :fill
  1487.       FLOOD_SOUND.play
  1488.       current = $game_battlemap.data[@rngcursor_rect.x, @rngcursor_rect.y, 0]
  1489.       for x in 0...$game_battlemap.data.xsize
  1490.         for y in 0...$game_battlemap.data.ysize
  1491.           next unless $game_battlemap.data[x, y, 0] == current
  1492.           $game_battlemap.data[x, y, 0] = @windows["Tile"].current_tileindex.to_i
  1493.         end
  1494.       end
  1495.     end
  1496.   end
  1497.  
  1498.   def set_start_points
  1499.     for i in 0...PARTY_START_POINTS
  1500.       rect = @start_points[:party][i].intern_rect
  1501.       $game_battlemap.map.start_points[:party][i] = SirenMap::StartPoint.new(rect.x, rect.y)
  1502.     end  
  1503.     for i in 0...TROOP_START_POINTS
  1504.       rect = @start_points[:troop][i].intern_rect
  1505.       $game_battlemap.map.start_points[:troop][i] = SirenMap::StartPoint.new(rect.x, rect.y)
  1506.     end
  1507.   end
  1508.  
  1509.   def update_set_start_points
  1510.     @active_point = nil
  1511.     for i in 0...PARTY_START_POINTS
  1512.       @active_point = @start_points[:party][i]
  1513.       update_active_point
  1514.     end  
  1515.     for i in 0...TROOP_START_POINTS
  1516.       @active_point = @start_points[:troop][i]
  1517.       update_active_point
  1518.     end
  1519.     set_start_points
  1520.   end
  1521.  
  1522.   def update_active_point
  1523.     @rngcursor_rect.x = 0
  1524.     @rngcursor_rect.y = 0
  1525.     @active_point.visible = true
  1526.     loop do
  1527.       @rngcursor_rect.update_cursor
  1528.       update_spec_cursor(@active_point, @rngcursor_rect.x, @rngcursor_rect.y)
  1529.       @active_point.intern_rect.x = @rngcursor_rect.x
  1530.       @active_point.intern_rect.y = @rngcursor_rect.y
  1531.       #@active_point.update
  1532.       for spr in @start_points[:party].values + @start_points[:troop].values
  1533.         spr.update
  1534.       end  
  1535.       update_basic
  1536.       break if Input.trigger?(Input::C)
  1537.     end  
  1538.   end
  1539.  
  1540.   def update_cursor ; @rngcursor_rect.update_cursor end
  1541.  
  1542.   def update_range_cursor(px, py, rng=[])
  1543.     update_spec_cursor(@range_cursor, px, py, rng)
  1544.   end
  1545.  
  1546.   def update_spec_cursor(cursor, px, py, rng=[])
  1547.     if rng.empty?
  1548.       sx = px ; sy = py
  1549.     else  
  1550.       sx = rng[0]+px ; sy = rng[1]+py
  1551.     end  
  1552.     sx *= RECTSIZE ; sy *= RECTSIZE
  1553.     cursor.create_move_to(sx, sy, CURSOR_FRMRTE)
  1554.   end
  1555.  
  1556. end
Advertisement
Add Comment
Please, Sign In to add comment