设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
楼主: 六百木
打印 上一主题 下一主题

[RMVA发布] [S.TECH]分层地图编辑 v0.9

[复制链接]

Lv2.观梦者

梦石
0
星屑
743
在线时间
2064 小时
注册时间
2011-10-3
帖子
1686
11
发表于 2013-10-3 23:22:35 | 只看该作者
好东西,收了
以前某个分层脚本因为和区域扩充冲突,所以才不得放弃,终于遇到没有冲突的了
回复 支持 反对

使用道具 举报

Lv2.观梦者 (暗夜天使)

梦石
0
星屑
266
在线时间
2355 小时
注册时间
2009-3-13
帖子
2309

贵宾

12
发表于 2013-10-8 19:09:00 | 只看该作者
非常好的。
楼主能不能告诉一下VA这个自动元件和活动元件的 id 计算方法。

点评

难道您打算做一个地图沉降脚本吗?其实我觉得这个脚本就能把操作变简单:把如果地图第二层没有图块而第三层有,那么第三层挪到第二层,  发表于 2014-3-7 16:21
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
145
在线时间
151 小时
注册时间
2013-1-1
帖子
53
13
 楼主| 发表于 2013-10-9 02:15:07 | 只看该作者
本帖最后由 六百木 于 2013-10-9 06:49 编辑
Sion 发表于 2013-10-8 19:09
非常好的。
楼主能不能告诉一下VA这个自动元件和活动元件的 id 计算方法。 ...


这个东西的实现不需要自动元件算法了..毕竟只是复制整合地图数据。不过下面是6R上关于自动元件的参考资料:

胃的自动元件说明文档:
http://ftp.66rpg.com/WEB_PLUS/UP ... %AF%B4%E6%98%8E.doc

yangff的RM VX/ACE 自动元件算法分析与讨论:
http://rpg.blue/forum.php?mod=viewthread&tid=222020

之前写的一个设置自动元件ID的脚本,未经大量测试并且有重复代码:
(本来分层编辑是想直接做一个编辑器的,不过工作量太大,还是利用默认编辑器这种笨方法比较实际)
  1. #encoding:utf-8
  2. #==============================================================================
  3. # ■ Tile
  4. #------------------------------------------------------------------------------
  5. #  代表地图元件
  6. #==============================================================================

  7. class Tile
  8.   #--------------------------------------------------------------------------
  9.   # ● 类方法:组、序号、形状=>ID
  10.   #--------------------------------------------------------------------------
  11.   def self.set_to_tile_id(set, index, shape = 0)
  12.     case set
  13.     when :A1
  14.       return 2048 + index * 48 + shape
  15.     when :A2
  16.       return 2816 + index * 48 + shape
  17.     when :A3
  18.       return 4352 + index * 48 + shape
  19.     when :A4
  20.       return 5888 + index * 48 + shape
  21.     when :A5
  22.       return 1536 + index
  23.     when :B
  24.       return index
  25.     when :C
  26.       return 256 + index
  27.     when :D
  28.       return 512 + index
  29.     when :E
  30.       return 768 + index
  31.     end
  32.     return 0
  33.   end
  34.   #--------------------------------------------------------------------------
  35.   # ● 类方法:ID=>组、序号、形状
  36.   #--------------------------------------------------------------------------
  37.   def self.tile_id_to_set(id)
  38.     if id < 256
  39.       return :B, id, 0
  40.     elsif id < 512
  41.       return :C, id - 256, 0
  42.     elsif id < 768
  43.       return :D, id - 512, 0
  44.     elsif id < 1024
  45.       return :E, id - 768, 0
  46.     elsif id >= 1536 && id < 1664
  47.       return :A5, id - 1536, 0
  48.     elsif id >= 2048 && id < 2816
  49.       return :A1, (id - 2048) / 48, (id - 2048) % 48
  50.     elsif id >= 2816 && id < 4352
  51.       return :A2, (id - 2816) / 48, (id - 2816) % 48
  52.     elsif id >= 4352 && id < 5888
  53.       return :A3, (id - 4352) / 48, (id - 4352) % 48
  54.     elsif id >= 5888
  55.       return :A4, (id - 5888) / 48, (id - 5888) % 48
  56.     end
  57.     p "WARNING: Invalid id: #{id}"
  58.     return :B, 0, 0
  59.   end
  60.   #--------------------------------------------------------------------------
  61.   # ● 类方法:转换成Tile对象
  62.   #--------------------------------------------------------------------------
  63.   def self.to_tile(t)
  64.     if t.is_a?(Tile)
  65.       return t
  66.     else
  67.       return Tile.new(t)
  68.     end
  69.   end
  70.   #--------------------------------------------------------------------------
  71.   # ● 类方法:转换成tile_id
  72.   #--------------------------------------------------------------------------
  73.   def self.to_tile_id(t)
  74.     if t.is_a?(Tile)
  75.       return t.tile_id
  76.     else
  77.       return t
  78.     end
  79.   end
  80.   #--------------------------------------------------------------------------
  81.   # ● 类方法:返回图块组中的图块数量
  82.   #--------------------------------------------------------------------------
  83.   def self.tile_count(set)
  84.     case set
  85.     when :A1
  86.       return 16
  87.     when :A2
  88.       return 32
  89.     when :A3
  90.       return 32
  91.     when :A4
  92.       return 24
  93.     when :A5
  94.       return 128
  95.     when :B, :C, :D, :E
  96.       return 256
  97.     end
  98.     p "WARNING: cannot find tile number for #{set}"
  99.     return 0
  100.   end
  101.   #--------------------------------------------------------------------------
  102.   # ● 初始化
  103.   #   参数为tile_id或set,index[,shape]
  104.   #   参数为空的话tile_id为0
  105.   #--------------------------------------------------------------------------
  106.   def initialize(*args)
  107.     if args.size == 0
  108.       self.tile_id = 0
  109.     elsif args.size == 1
  110.       self.tile_id = args.first
  111.     elsif args.size == 2
  112.       @set, [url=home.php?mod=space&uid=370741]@Index[/url] = *args
  113.       @shape = 0
  114.       @tile_id = Tile.set_to_tile_id(@set, @index, @shape)
  115.     elsif args.size == 3
  116.       @set, @index, @shape = *args
  117.       @shape = sample_shape if @shape == :sample
  118.       @tile_id = Tile.set_to_tile_id(@set, @index, @shape)
  119.     else
  120.       raise ArgumentError
  121.     end
  122.   end
  123.   #--------------------------------------------------------------------------
  124.   # ● 属性
  125.   #--------------------------------------------------------------------------
  126.   attr_reader :set, :index, :shape, :tile_id
  127.   def set=(n)
  128.     @set = n
  129.     @tile_id = Tile.set_to_tile_id(@set, @index, @shape)
  130.   end
  131.   def index=(n)
  132.     @index = n
  133.     @tile_id = Tile.set_to_tile_id(@set, @index, @shape)
  134.   end
  135.   def shape=(n)
  136.     @shape = n
  137.     @tile_id = Tile.set_to_tile_id(@set, @index, @shape)
  138.   end
  139.   def tile_id=(n)
  140.     @tile_id = n
  141.     @set, @index, @shape = Tile.tile_id_to_set(@tile_id)
  142.   end
  143.   #--------------------------------------------------------------------------
  144.   # ● 元件类型
  145.   #   :type_2x3 :type_2x2 :type_2x1
  146.   #--------------------------------------------------------------------------
  147.   def type
  148.     case @set
  149.     when :A1
  150.       if @index <= 3
  151.         return :type_2x3
  152.       else
  153.         if @index % 2 == 0
  154.           return :type_2x3
  155.         else
  156.           return :type_2x1
  157.         end
  158.       end
  159.     when :A2
  160.       return :type_2x3
  161.     when :A3
  162.       return :type_2x2
  163.     when :A4
  164.       if (@index / 8) % 2 == 0
  165.         return :type_2x3
  166.       else
  167.         return :type_2x2
  168.       end
  169.     end
  170.     return :type_1x1
  171.   end
  172.   #--------------------------------------------------------------------------
  173.   # ● 是否属于同一个元件
  174.   #-------------------------------------------------------------------------
  175.   def same_tile?(other)
  176.     return @set == other.set && @index == other.index
  177.   end
  178.   #--------------------------------------------------------------------------
  179.   # ● 计算形状
  180.   #-------------------------------------------------------------------------
  181.   def calculate_shape(surround)
  182.     case type
  183.     when :type_2x3
  184.       return autotile_2x3_shape(surround)
  185.     when :type_2x2
  186.       return autotile_2x2_shape(surround)
  187.     when :type_2x1
  188.       return autotile_2x1_shape(surround)
  189.     when :type_1x1
  190.       return 0
  191.     end
  192.     p "WARNING: cannot find shape for set #{@set} index #{@index} surround 0b#{surround.to_s(2)}"
  193.     return 0
  194.   end
  195.   #--------------------------------------------------------------------------
  196.   # ● 返回图块缩略图形状
  197.   #--------------------------------------------------------------------------
  198.   def sample_shape
  199.     case type
  200.     when :type_2x3
  201.       return 46
  202.     when :type_2x2
  203.       return 15
  204.     when :type_2x1
  205.       return 3
  206.     end
  207.     return 0
  208.   end
  209.   #--------------------------------------------------------------------------
  210.   # ● 辅佐方法
  211.   #--------------------------------------------------------------------------
  212.   protected
  213.   #--------------------------------------------------------------------------
  214.   # ● 2x3自动元件形状
  215.   #--------------------------------------------------------------------------
  216.   def autotile_2x3_shape(surround)
  217.     # 如果上、下、左或右方向没有相邻同样图块的话,无视对应方向的两个角
  218.     surround &= 0b01011111 if surround | 0b10111111 == 0b10111111
  219.     surround &= 0b01111011 if surround | 0b11101111 == 0b11101111
  220.     surround &= 0b11011110 if surround | 0b11110111 == 0b11110111
  221.     surround &= 0b11111010 if surround | 0b11111101 == 0b11111101
  222.     return AUTOTILE_2X3_SHAPES[surround]
  223.   end
  224.   #--------------------------------------------------------------------------
  225.   # ● 2x2自动元件形状
  226.   #--------------------------------------------------------------------------
  227.   def autotile_2x2_shape(surround)
  228.     # 削去四个角
  229.     surround &= 0b01011010
  230.     return AUTOTILE_2X2_SHAPES[surround]
  231.   end
  232.   #--------------------------------------------------------------------------
  233.   # ● 2x1自动元件形状
  234.   #--------------------------------------------------------------------------
  235.   def autotile_2x1_shape(surround)
  236.     # 削去上下两条边
  237.     surround &= 0b00011000
  238.     return AUTOTILE_2X1_SHAPES[surround]
  239.   end
  240.   #--------------------------------------------------------------------------
  241.   # ● 辅佐常量
  242.   #--------------------------------------------------------------------------
  243.   #--------------------------------------------------------------------------
  244.   # ● 2x3自动元件形状
  245.   #--------------------------------------------------------------------------
  246.   AUTOTILE_2X3_SHAPES = {
  247.     0b11111111 => 0,
  248.     0b01111111 => 1,
  249.     0b11011111 => 2,
  250.     0b01011111 => 3,
  251.     0b11111110 => 4,
  252.     0b01111110 => 5,
  253.     0b11011110 => 6,
  254.     0b01011110 => 7,
  255.     0b11111011 => 8,
  256.     0b01111011 => 9,
  257.     0b11011011 => 10,
  258.     0b01011011 => 11,
  259.     0b11111010 => 12,
  260.     0b01111010 => 13,
  261.     0b11011010 => 14,
  262.     0b01011010 => 15,
  263.     0b01101011 => 16, #16 左 8, 9, 4, 5
  264.     0b01001011 => 17, #17 右上+左 8, 17, 4, 5
  265.     0b01101010 => 18, #18 右下+左 8, 9, 4, 19
  266.     0b01001010 => 19, #19 左+右上+右下 8, 17, 4, 19
  267.     0b00011111 => 20, #20 上 2, 1, 6, 5
  268.     0b00011110 => 21, #21 右下+上 2, 1, 6, 19
  269.     0b00011011 => 22, #22 左下+上 2, 1, 18, 5
  270.     0b00011010 => 23, #23 上+左下+右下 2, 1, 18, 19
  271.     0b11010110 => 24, #24 右 10, 11, 6, 7
  272.     0b11010010 => 25, #25 左下+右 10, 11, 18, 7
  273.     0b01010110 => 26, #26 左上+右 16, 11, 6, 7
  274.     0b01010010 => 27, #27 右+左上+左下 16, 11, 18, 7
  275.     0b11111000 => 28, #28 下 10, 9, 14, 13
  276.     0b01111000 => 29, #29 左上+下 16, 9, 14, 13
  277.     0b11011000 => 30, #30 右上+下 10, 17, 14, 13
  278.     0b01011000 => 31, #31 下+左上+右上 16, 17, 14, 13
  279.     0b01000010 => 32, #32 右+左 8, 11, 4, 7
  280.     0b00011000 => 33, #33 上+下 2, 1, 14, 13
  281.     0b00001011 => 34, #34 上+左 0, 1, 4, 5
  282.     0b00001010 => 35, #35 右下+上+左 0, 1, 4, 19
  283.     0b00010110 => 36, #36 上+右 2, 3, 6, 7
  284.     0b00010010 => 37, #37 左下+上+右 2, 3, 18, 7
  285.     0b11010000 => 38, #38 右+下 10, 11, 14, 15
  286.     0b01010000 => 39, #39 左上+右+下 16, 11, 14, 15
  287.     0b01101000 => 40, #40 下+左 8, 9, 12, 13
  288.     0b01001000 => 41, #41 右上+左+下 8, 17, 12, 13
  289.     0b00000010 => 42, #42 -下 0, 3, 8, 11
  290.     0b00001000 => 43, #43 -右 0, 1, 12, 13
  291.     0b01000000 => 44, #44 -上 4, 7, 12, 15
  292.     0b00010000 => 45, #45 -左 2, 3, 14, 15
  293.     0b00000000 => 46, #46 all 0, 3, 12, 15
  294.   }
  295.   AUTOTILE_2X3_SHAPES.default = 0
  296.   #--------------------------------------------------------------------------
  297.   # ● 2x1自动元件形状
  298.   #--------------------------------------------------------------------------
  299.   AUTOTILE_2X1_SHAPES = {
  300.     0b00011000 => 0, #0 -all 2, 1, 6, 5
  301.     0b00001000 => 1, #1 左 0, 1, 4, 5
  302.     0b00010000 => 2, #2 右 2, 3, 6, 7
  303.     0b00000000 => 3, #3 all 0, 3, 4, 7
  304.   }
  305.   AUTOTILE_2X1_SHAPES.default = 0
  306.   #--------------------------------------------------------------------------
  307.   # ● 2x2自动元件形状
  308.   #--------------------------------------------------------------------------
  309.   AUTOTILE_2X2_SHAPES = {
  310.     0b01011010 => 0, #0 -all 10, 9, 6, 5
  311.     0b01001010 => 1, #1 左 8, 9, 4, 5
  312.     0b00011010 => 2, #2 上 2, 1, 6, 5
  313.     0b00001010 => 3, #3 左+上 0, 1, 4, 5
  314.     0b01010010 => 4, #4 右 10, 11, 6, 7
  315.     0b01000010 => 5, #5 左+右 8, 11, 4, 7
  316.     0b00010010 => 6, #6 上+右 2, 3, 6, 7
  317.     0b00000010 => 7, #7 左+上+右 0, 3, 8, 11
  318.     0b01011000 => 8, #8 下 10, 9, 14, 13
  319.     0b01001000 => 9, #9 左+下 8, 9, 12, 13
  320.     0b00011000 => 10, #10 上+下 2, 1, 14, 13
  321.     0b00001000 => 11, #11 上+左+下 0, 1, 12, 13
  322.     0b01010000 => 12, #12 右+下 10, 11, 14, 15
  323.     0b01000000 => 13, #13 左+右+下 4, 7, 12, 15
  324.     0b00010000 => 14, #14 上+右+下 2, 3, 14, 15
  325.     0b00000000 => 15, #15 all 0, 3, 12, 15
  326.   }
  327.   AUTOTILE_2X2_SHAPES.default = 0
  328. end


  329. #==============================================================================
  330. # ■ TileTable
  331. #------------------------------------------------------------------------------
  332. #  地图操作模块,include到Table
  333. #==============================================================================

  334. module TileTable
  335.   #--------------------------------------------------------------------------
  336.   # ● 写入自动元件
  337.   #   tile可以是Tile实例或整数ID
  338.   #   z 0~2为层1~3,3为阴影层和区域,见def region_id
  339.   #   :out_of_map_as_neighbor 超出地图范围视为同类自动元件,默认true
  340.   #   :update_surround 是否更新周围自动元件的形状,默认true
  341.   #--------------------------------------------------------------------------
  342.   def set_autotile(x, y, z, tile, options={})
  343.     return if !in_map?(x, y)
  344.     set_default_options(options)
  345.     # 转换
  346.     tile = Tile.to_tile(tile)
  347.     # 获取第一部分需要更新的元件
  348.     if options[:update_surround]
  349.       coords_to_update = get_related_coords(x, y, z, get_tile(x, y, z))
  350.     else
  351.       coords_to_update = [[x, y]]
  352.     end
  353.     # 写入元件(形状未调整)
  354.     set_tile(x, y, z, tile)
  355.     # 获取第二部分需要更新的元件
  356.     if options[:update_surround]
  357.       coords_to_update |= get_related_coords(x, y, z, tile)
  358.     end
  359.     # 更新列表中的所有元件
  360.     coords_to_update.each do |xy|
  361.       update_autotile_shape(*xy, z, options)
  362.     end
  363.   end
  364.   #--------------------------------------------------------------------------
  365.   # ● 批量写入自动元件
  366.   #--------------------------------------------------------------------------
  367.   def set_autotiles(coords, z, tile, options=Hash.new(true))
  368.     set_default_options(options)
  369.     # 转换
  370.     tile = Tile.to_tile(tile)
  371.     # 获取第一部分需要更新的元件
  372.     coords_to_update = []
  373.     coords.each do |xy|
  374.       next if !in_map?(*xy)
  375.       coords_to_update |= get_related_coords(*xy, z, get_tile(*xy, z))
  376.     end
  377.     # 写入元件(形状未调整)
  378.     set_tiles(coords, z, tile)
  379.     # 获取第二部分需要更新的元件
  380.     coords.each do |xy|
  381.       next if !in_map?(*xy)
  382.       coords_to_update |= get_related_coords(*xy, z, tile)
  383.     end
  384.     # 更新列表中的所有元件
  385.     coords_to_update.each do |xy|
  386.       update_autotile_shape(*xy, z, options)
  387.     end
  388.   end
  389.   #--------------------------------------------------------------------------
  390.   # ● 写入元件
  391.   #--------------------------------------------------------------------------
  392.   def set_tile(x, y, z, tile)
  393.     return if !in_map?(x, y)
  394.     self[x, y, z] = Tile.to_tile_id(tile)
  395.   end
  396.   #--------------------------------------------------------------------------
  397.   # ● 批量写入元件
  398.   #--------------------------------------------------------------------------
  399.   def set_tiles(coords, z, tile)
  400.     coords.each {|xy| set_tile(*xy, z, tile)}
  401.   end
  402.   #--------------------------------------------------------------------------
  403.   # ● 取得元件
  404.   #--------------------------------------------------------------------------
  405.   def get_tile(x, y, z)
  406.     return if !in_map?(x, y)
  407.     return Tile.new(self[x, y, z])
  408.   end
  409.   #--------------------------------------------------------------------------
  410.   # ● 坐标是否在地图范围内
  411.   #--------------------------------------------------------------------------
  412.   def in_map?(x, y)
  413.     return x >= 0 && x < xsize && y >= 0 && y < ysize
  414.   end
  415.   #--------------------------------------------------------------------------
  416.   # ● 辅佐方法
  417.   #--------------------------------------------------------------------------
  418.   protected
  419.   #--------------------------------------------------------------------------
  420.   # ● 设置默认选项
  421.   #--------------------------------------------------------------------------
  422.   def set_default_options(options)
  423.     if options[:out_of_map_as_neighbor] == nil
  424.       options[:out_of_map_as_neighbor] = true
  425.     end
  426.     if options[:update_surround] == nil
  427.       options[:update_surround] = true
  428.     end
  429.   end
  430.   #--------------------------------------------------------------------------
  431.   # ● 返回相关坐标
  432.   #--------------------------------------------------------------------------
  433.   def get_related_coords(x, y, z, tile)
  434.     coords = []
  435.     case tile.type
  436.     when :type_2x3 # 正方形
  437.       for _x in x - 1..x + 1
  438.         for _y in y - 1..y + 1
  439.           coords.push([_x, _y]) if same_tile?(_x, _y, z, tile)
  440.         end
  441.       end
  442.     when :type_2x2 # 需要扩展整片墙壁
  443.       expand_coords(x, y, z, tile, coords)
  444.     when :type_2x1 # 十字形
  445.       [[x, y], [x-1, y], [x+1, y], [x, y-1], [x, y+1]].each do |xy|
  446.         coords.push(xy) if same_tile?(*xy, z, tile)
  447.       end
  448.     end
  449.     return coords
  450.   end
  451.   #--------------------------------------------------------------------------
  452.   # ● 是否同一个元件
  453.   #--------------------------------------------------------------------------
  454.   def same_tile?(x, y, z, tile)
  455.     if (target = get_tile(x, y, z)) == nil
  456.       return false
  457.     end
  458.     return target.same_tile?(tile)
  459.   end
  460.   #--------------------------------------------------------------------------
  461.   # ● 是否相邻
  462.   #   超出地图范围也视为相邻
  463.   #--------------------------------------------------------------------------
  464.   def neighbor?(x, y, z, tile)
  465.     if (target = get_tile(x, y, z)) == nil
  466.       return true
  467.     end
  468.     return target.same_tile?(tile)
  469.   end
  470.   #--------------------------------------------------------------------------
  471.   # ● 递归扩展坐标
  472.   #--------------------------------------------------------------------------
  473.   def expand_coords(x, y, z, tile, coords)
  474.     return if !same_tile?(x, y, z, tile)
  475.     return if coords.include?([x, y])
  476.     coords.push([x, y])
  477.     [[x-1, y], [x+1, y], [x, y-1], [x, y+1]].each do |xy|
  478.       expand_coords(*xy, z, tile, coords)
  479.     end
  480.   end
  481.   #--------------------------------------------------------------------------
  482.   # ● 更新自动元件形状
  483.   #--------------------------------------------------------------------------
  484.   def update_autotile_shape(x, y, z, options = {})
  485.     return if !in_map?(x, y)
  486.     tile = get_tile(x, y, z)
  487.     surround = get_surround(tile, x, y, z, options)
  488.     tile.shape = tile.calculate_shape(surround)
  489.     set_tile(x, y, z, tile)
  490.   end
  491.   #--------------------------------------------------------------------------
  492.   # ● 返回周边情况
  493.   #-------------------------------------------------------------------------
  494.   def get_surround(tile, x, y, z, options = {})
  495.     result = 0
  496.     if tile.type == :type_2x1 || tile.type == :type_2x3
  497.       if options[:out_of_map_as_neighbor]
  498.         m = method(:neighbor?)
  499.       else
  500.         m = method(:same_tile?)
  501.       end
  502.       # ⑧方向
  503.       result |= 0b10000000 if m.call(x - 1, y - 1, z, tile)
  504.       result |= 0b01000000 if m.call(x, y - 1, z, tile)
  505.       result |= 0b00100000 if m.call(x + 1, y - 1, z, tile)
  506.       result |= 0b00010000 if m.call(x - 1, y, z, tile)
  507.       result |= 0b00001000 if m.call(x + 1, y, z, tile)
  508.       result |= 0b00000100 if m.call(x - 1, y + 1, z, tile)
  509.       result |= 0b00000010 if m.call(x, y + 1, z, tile)
  510.       result |= 0b00000001 if m.call(x + 1, y + 1, z, tile)
  511.     elsif tile.type == :type_2x2 #todo
  512.       # 上
  513.       # 超出地图范围的话视为没有邻接
  514.       result |= 0b01000000 if same_autotile?(tile, x, y - 1, z)
  515.       # 左和右
  516.       # 本列最上面的元件决定邻接情况
  517.       top_y = get_top_y(data, x, y, z)
  518.       result |= 0b00010000 if neighbor?(tile, x - 1, top_y, z)
  519.       result |= 0b00001000 if neighbor?(tile, x + 1, top_y, z)
  520.       # 下
  521.       # 不位于这面墙最下面的话视为有邻接
  522.       # 超出地图范围的话视为没有邻接
  523.       if in_map?(data, x, y + 1)
  524.         if same_autotile?(tile, x, y + 1, z)
  525.           result |= 0b00000010
  526.         else
  527.           bottom_y = y
  528.           _x = x - 1 # 检查左边
  529.           while same_autotile?(tile, _x, y, z) &&
  530.               get_top_y(data, _x, y, z) == top_y
  531.             _bottom_y = get_bottom_y(data, _x, y, z)
  532.             bottom_y = _bottom_y if _bottom_y > bottom_y
  533.             _x -= 1
  534.           end
  535.           _x = x + 1 # 检查右边
  536.           while same_autotile?(tile, _x, y, z) &&
  537.               get_top_y(data, _x, y, z) == top_y
  538.             _bottom_y = get_bottom_y(data, _x, y, z)
  539.             bottom_y = _bottom_y if _bottom_y > bottom_y
  540.             _x += 1
  541.           end
  542.           result |= 0b00000010 if bottom_y > y
  543.         end
  544.       end
  545.     end
  546.     return result
  547.   end
  548. end

  549. class Table
  550.   include TileTable
  551. end


  552. module Tileset
  553.   #--------------------------------------------------------------------------
  554.   # ● 返回图块组中的图块数量
  555.   #--------------------------------------------------------------------------
  556.   def self.tile_count(set)
  557.     case set
  558.     when :A1
  559.       return 16
  560.     when :A2
  561.       return 32
  562.     when :A3
  563.       return 32
  564.     when :A4
  565.       return 24
  566.     when :A5
  567.       return 128
  568.     when :B, :C, :D, :E
  569.       return 256
  570.     end
  571.     p "WARNING: cannot find tile number for #{set}"
  572.     return 0
  573.   end
  574.   #--------------------------------------------------------------------------
  575.   # ● 返回图块缩略图形状
  576.   #--------------------------------------------------------------------------
  577.   def self.sample_shape(set, index)
  578.     type = autotile_type(set, index)
  579.     case type
  580.     when :type_2x3
  581.       return 46
  582.     when :type_2x2
  583.       return 15
  584.     when :type_2x1
  585.       return 3
  586.     end
  587.     return 0
  588.   end
  589.   #--------------------------------------------------------------------------
  590.   # ● 辅佐方法
  591.   #--------------------------------------------------------------------------
  592.   #--------------------------------------------------------------------------
  593.   # ● 更新自动元件形状
  594.   #--------------------------------------------------------------------------
  595.   def self.update_autotile_shape(data, x, y, z)
  596.     return if !in_map?(data, x, y)
  597.     set, index = id_to_set(data[x, y, z])
  598.     surround = get_surround(data, set, index, x, y, z)
  599.     shape = get_shape(set, index, surround)
  600.     data[x, y, z] = set_to_id(set, index, shape)
  601.   end
  602.   #--------------------------------------------------------------------------
  603.   # ● 更新自动元件形状
  604.   #--------------------------------------------------------------------------
  605.   def self.update_select_autotile_shape(data, x, y, z)
  606.     return if !in_map?(data, x, y)
  607.     set, index = id_to_set(data[x, y, z])
  608.     surround = get_select_surround(data, set, index, x, y, z)
  609.     shape = get_shape(set, index, surround)
  610.     data[x, y, z] = set_to_id(set, index, shape)
  611.   end
  612.   #--------------------------------------------------------------------------
  613.   # ● 根据周围的自动元件获得形状
  614.   #--------------------------------------------------------------------------
  615.   def self.get_shape(set, index, surround)
  616.     type = autotile_type(set, index)
  617.     case type
  618.     when :type_2x3
  619.       return autotile_2x3_shape(surround)
  620.     when :type_2x2
  621.       return autotile_2x2_shape(surround)
  622.     when :type_2x1
  623.       return autotile_2x1_shape(surround)
  624.     when :not_autotile
  625.       return 0
  626.     end
  627.     p "WARNING: cannot find shape for set #{set} index #{index} surround 0b#{surround.to_s(2)}"
  628.     return 0
  629.   end
  630.   #--------------------------------------------------------------------------
  631.   # ● 是否自动元件
  632.   #--------------------------------------------------------------------------
  633.   def self.autotile?(id)
  634.     return autotile_id_type(id) != :not_autotile
  635.   end
  636.   #--------------------------------------------------------------------------
  637.   # ● 根据id返回自动元件类型
  638.   #   :type_2x3 :type_2x2 :type_2x1
  639.   #--------------------------------------------------------------------------
  640.   def self.autotile_id_type(id)
  641.     set, index = id_to_set(id)
  642.     return autotile_type(set, index)
  643.   end
  644.   #--------------------------------------------------------------------------
  645.   # ● 返回自动元件类型
  646.   #   :type_2x3 :type_2x2 :type_2x1
  647.   #--------------------------------------------------------------------------
  648.   def self.autotile_type(set, index)
  649.     case set
  650.     when :A1
  651.       if index <= 3
  652.         return :type_2x3
  653.       else
  654.         if index % 2 == 0
  655.           return :type_2x3
  656.         else
  657.           return :type_2x1
  658.         end
  659.       end
  660.     when :A2
  661.       return :type_2x3
  662.     when :A3
  663.       return :type_2x2
  664.     when :A4
  665.       if (index / 8) % 2 == 0
  666.         return :type_2x3
  667.       else
  668.         return :type_2x2
  669.       end
  670.     end
  671.     return :not_autotile
  672.   end
  673.   #--------------------------------------------------------------------------
  674.   # ● 返回周边情况
  675.   #-------------------------------------------------------------------------
  676.   def self.get_surround(data, set, index, x, y, z)
  677.     result = 0
  678.     type = autotile_type(set, index)
  679.     if type == :type_2x1 || type == :type_2x3
  680.       # ⑧方向
  681.       result |= 0b10000000 if neighbor?(data, set, index, x - 1, y - 1, z)
  682.       result |= 0b01000000 if neighbor?(data, set, index, x, y - 1, z)
  683.       result |= 0b00100000 if neighbor?(data, set, index, x + 1, y - 1, z)
  684.       result |= 0b00010000 if neighbor?(data, set, index, x - 1, y, z)
  685.       result |= 0b00001000 if neighbor?(data, set, index, x + 1, y, z)
  686.       result |= 0b00000100 if neighbor?(data, set, index, x - 1, y + 1, z)
  687.       result |= 0b00000010 if neighbor?(data, set, index, x, y + 1, z)
  688.       result |= 0b00000001 if neighbor?(data, set, index, x + 1, y + 1, z)
  689.     elsif type == :type_2x2
  690.       # 上
  691.       # 超出地图范围的话视为没有邻接
  692.       result |= 0b01000000 if same_autotile?(data, set, index, x, y - 1, z)
  693.       # 左和右
  694.       # 本列最上面的元件决定邻接情况
  695.       top_y = get_top_y(data, x, y, z)
  696.       result |= 0b00010000 if neighbor?(data, set, index, x - 1, top_y, z)
  697.       result |= 0b00001000 if neighbor?(data, set, index, x + 1, top_y, z)
  698.       # 下
  699.       # 不位于这面墙最下面的话视为有邻接
  700.       # 超出地图范围的话视为没有邻接
  701.       if in_map?(data, x, y + 1)
  702.         if same_autotile?(data, set, index, x, y + 1, z)
  703.           result |= 0b00000010
  704.         else
  705.           bottom_y = y
  706.           _x = x - 1 # 检查左边
  707.           while same_autotile?(data, set, index, _x, y, z) &&
  708.               get_top_y(data, _x, y, z) == top_y
  709.             _bottom_y = get_bottom_y(data, _x, y, z)
  710.             bottom_y = _bottom_y if _bottom_y > bottom_y
  711.             _x -= 1
  712.           end
  713.           _x = x + 1 # 检查右边
  714.           while same_autotile?(data, set, index, _x, y, z) &&
  715.               get_top_y(data, _x, y, z) == top_y
  716.             _bottom_y = get_bottom_y(data, _x, y, z)
  717.             bottom_y = _bottom_y if _bottom_y > bottom_y
  718.             _x += 1
  719.           end
  720.           result |= 0b00000010 if bottom_y > y
  721.         end
  722.       end
  723.     end
  724.     return result
  725.   end
  726.   #--------------------------------------------------------------------------
  727.   # ● 返回周边情况
  728.   #-------------------------------------------------------------------------
  729.   def self.get_select_surround(data, set, index, x, y, z)
  730.     result = 0
  731.     type = autotile_type(set, index)
  732.     if type == :type_2x1 || type == :type_2x3
  733.       # ⑧方向
  734.       result |= 0b10000000 if same_autotile?(data, set, index, x - 1, y - 1, z)
  735.       result |= 0b01000000 if same_autotile?(data, set, index, x, y - 1, z)
  736.       result |= 0b00100000 if same_autotile?(data, set, index, x + 1, y - 1, z)
  737.       result |= 0b00010000 if same_autotile?(data, set, index, x - 1, y, z)
  738.       result |= 0b00001000 if same_autotile?(data, set, index, x + 1, y, z)
  739.       result |= 0b00000100 if same_autotile?(data, set, index, x - 1, y + 1, z)
  740.       result |= 0b00000010 if same_autotile?(data, set, index, x, y + 1, z)
  741.       result |= 0b00000001 if same_autotile?(data, set, index, x + 1, y + 1, z)
  742.       return result
  743.     else
  744.       return get_surround(data, set, index, x, y, z)
  745.     end
  746.   end
  747.   #--------------------------------------------------------------------------
  748.   # ● 返回2x2元件列最上面的元件的y坐标
  749.   #-------------------------------------------------------------------------
  750.   def self.get_top_y(data, x, y, z)
  751.     set, index = id_to_set(data[x, y, z])
  752.     top_y = y
  753.     top_y -= 1 while same_autotile?(data, set, index, x, top_y - 1, z)
  754.     return top_y
  755.   end
  756.   #--------------------------------------------------------------------------
  757.   # ● 返回2x2元件列最下面的元件的y坐标
  758.   #-------------------------------------------------------------------------
  759.   def self.get_bottom_y(data, x, y, z)
  760.     set, index = id_to_set(data[x, y, z])
  761.     bottom_y = y
  762.     bottom_y += 1 while same_autotile?(data, set, index, x, bottom_y + 1, z)
  763.     return bottom_y
  764.   end
  765.   #--------------------------------------------------------------------------
  766.   # ● 邻接
  767.   #   超出地图范围的话视为邻接自动元件
  768.   #-------------------------------------------------------------------------
  769.   def self.neighbor?(data, set, index, x, y, z)
  770.     if !in_map?(data, x, y)
  771.       return true
  772.     end
  773.     return same_autotile?(data, set, index, x, y, z)
  774.   end
  775.   #--------------------------------------------------------------------------
  776.   # ● 坐标是否属于同一个自动元件
  777.   #-------------------------------------------------------------------------
  778.   def self.same_autotile?(data, set, index, x, y, z)
  779.     if !in_map?(data, x, y)
  780.       return false
  781.     end
  782.     set2, index2 = Tileset.id_to_set(data[x, y, z])
  783.     return set == set2 && index == index2
  784.   end
  785.   #--------------------------------------------------------------------------
  786.   # ● 坐标是否在地图范围内
  787.   #--------------------------------------------------------------------------
  788.   def self.in_map?(data, x, y)
  789.     return x >= 0 && x < data.xsize && y >= 0 && y < data.ysize
  790.   end
  791. end

  792. module RPG
  793.   class Tileset
  794.     def sets_in_use
  795.       sets = [:A1,:A2,:A3,:A4,:A5,:B,:C,:D,:E]
  796.       in_use = []
  797.       self.tileset_names.each_with_index do |name, i|
  798.         in_use.push(sets[i]) if !name.empty?
  799.       end
  800.       return in_use
  801.     end
  802.   end
  803. end
复制代码

评分

参与人数 2星屑 +105 收起 理由
3106345123 + 5 精品文章
Sion + 100 谢谢

查看全部评分

回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
740
在线时间
6 小时
注册时间
2013-10-11
帖子
2
14
发表于 2013-10-11 08:57:40 | 只看该作者
这个文件能打开,但是怎么用在别的文件呢,哎不会用诶
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
145
在线时间
151 小时
注册时间
2013-1-1
帖子
53
15
 楼主| 发表于 2013-10-12 01:05:55 | 只看该作者
huayicomics 发表于 2013-10-11 08:57
这个文件能打开,但是怎么用在别的文件呢,哎不会用诶

复制范例里的所有新增脚本到你的工程里面

或者

在范例里画好地图后把地图复制到你的工程里面
回复 支持 反对

使用道具 举报

Lv5.捕梦者

梦石
0
星屑
21957
在线时间
8567 小时
注册时间
2011-12-31
帖子
3362
16
发表于 2013-10-19 01:40:49 | 只看该作者
其實VA有分层地图的脚本
レイヤーシステムforAce Ver1.23(最大5層)
http://librpg.zatunen.com/ace.html
マルチレイヤーシステム(最大無限層,レイヤーシステム的拡張版)
http://canarialt.blog.fc2.com/blog-entry-57.html

评分

参与人数 1星屑 +99 收起 理由
eve592370698 + 99 安慰一下,不翻墙进不去

查看全部评分

回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
55
在线时间
144 小时
注册时间
2013-1-11
帖子
101
17
发表于 2013-12-19 14:28:35 | 只看该作者
确实是个好东西,mark一下
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
432
在线时间
4175 小时
注册时间
2010-6-26
帖子
6474
18
发表于 2014-3-7 16:16:36 | 只看该作者
这个工具看来挺实用的。不过好像编辑起来有点麻烦,要来回重启地图吧?
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
120
在线时间
188 小时
注册时间
2014-1-18
帖子
254
19
发表于 2014-3-7 18:26:38 | 只看该作者
提一个比较白痴的发现...

就是用这个图块在第二个[1]中进行清除时,会发生下图这样的情况:
没事的过来瞄一眼,有事的也过来瞄一眼...群组,XAS PS VA
http://rpg.blue/forum.php?mod=group&fid=537
XAS探索目录:http://rpg.blue/home.php?mo ... o=blog&id=12595
如果有人对你说,你如此帅气(美丽),你要分三个角度去想:
1.就像妈妈对你说:“你如此帅气(美丽)。”(安慰)
2.就像女(男)朋友对你说:“你如此帅气(美丽)”(欺瞒)
3.就像乞丐对你说:“你如此帅气(美丽)”(讨好)
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
145
在线时间
151 小时
注册时间
2013-1-1
帖子
53
20
 楼主| 发表于 2014-3-22 08:20:36 | 只看该作者
eve592370698 发表于 2014-3-7 16:16
这个工具看来挺实用的。不过好像编辑起来有点麻烦,要来回重启地图吧?

运行游戏的时候如果编辑器没有选中主地图就不需要重启
例如主地图是“[0]测试”,按三角形运行游戏的时候不要选中这张地图,模块运行成功后关闭游戏回到编辑器,切换到地图到“[0]测试”就会发现数据自动更新了。如果运行游戏的时候选中主地图的话,就需要重启编辑器才能看到数据更新

最后还是主楼那句话,“当然来回编辑分层地图也是十分蛋疼,所以如无必要,不要使用分层编辑。”
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-5-3 01:25

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表