• Anmelden

1

Sonntag, 19. Februar 2012, 14:07

Map updater für Random Autotiles

Mahlzeit ^^

Also.. Abt hat mir vor längerer zeit ein kleines Script geschrieben, das die Map updatet um Autotiles per zufall zu setzen:

Ruby Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#==============================================================================
# ** Map_refresh / V0.1
#==============================================================================
# ** @ Abt Ploutôn / http://www.rmxp.de
#------------------------------------------------------------------------------
# use Code of
# Random Map Generator - version 0.51 by Wachunga, 
# based on Jamis Buck's D&D dungeon generator
#------------------------------------------------------------------------------
# Refresh the Mapdata
# $game_map.map_data_refresh
#==============================================================================
# ** Game_Map Addon
#------------------------------------------------------------------------------
#  This class handles the map. It includes scrolling and passable determining
#  functions. Refer to "$game_map" for the instance of this class.
#==============================================================================
 
class Game_Map
  #-----------------------------------------------------------------------------
  # * refresh the map data
  #-----------------------------------------------------------------------------
  def map_data_refresh
    for x in 0...@map.data.xsize
      for y in 0...@map.data.ysize
        for z in 0...@map.data.zsize
          # skip passages
          tileid = @map.data[x,y,z]
          if tileid < 384
          # calculate adjacent walls
            adj = ''
            if (x == 0)
              adj << '147'
            else
              adj << '1' if (y == 0) or (map_data_check(tileid,x-1,y-1,z) and (map_data_check(tileid,x-1,y,z) or map_data_check(tileid,x,y-1,z)))
              adj << '4'  if (map_data_check(tileid,x-1,y,z))
              adj << '7' if (y == @map.height-1) or (map_data_check(tileid,x-1,y+1,z) and (map_data_check(tileid,x-1,y,z) or map_data_check(tileid,x,y+1,z)))
            end
            if (x == @map.width-1)
              adj << '369'
            else
              adj << '3' if (y == 0) or (map_data_check(tileid,x+1,y-1,z) and (map_data_check(tileid,x,y-1,z) or map_data_check(tileid,x+1,y,z)))
              adj << '6' if (map_data_check(tileid,x+1,y,z)) 
              adj << '9' if (y == @map.height-1) or (map_data_check(tileid,x+1,y+1,z) and (map_data_check(tileid,x+1,y,z) or map_data_check(tileid,x,y+1,z)))
            end
            adj << '2' if (y == 0) or (map_data_check(tileid,x,y-1,z))
            adj << '8' if (y == @map.height-1) or (map_data_check(tileid,x,y+1,z))
            # if no adjacent walls, set it as 0
            adj = '0' if (adj == '') 
            # convert to an array, sort, and then back to a string
            adj = adj.split(//).sort.join
            adj = ((tileid/48)*48)+Tile.setzen(adj.to_i)
            # change it?
            @map.data[x,y,z] = adj if @map.data[x,y,z] != adj
          end # if
        end # for
      end # for 
    end # for 
  end # def
  #-----------------------------------------------------------------------------
  # * check the field, help method
  #-----------------------------------------------------------------------------
  def map_data_check(tileid,x=0,y=0,z=0)
    # if a autotile?
    if tileid < 384 and @map.data[x,y,z] < 384
      # same autotile?
      return true if tileid / 48 == @map.data[x,y,z] / 48
    end
    return false
  end # def
end # class
 
 
module Tile
 
  # to be extended with others to make maps "pretty", e.g. random ground features
 
=begin
    The following array lists systematic keys which are based on adjacent
    walls (where 'W' is the wall itself):
    1 2 3
    4 W 6
    7 8 9
    e.g. 268 is the key that will be used to refer to the autotile
    which has adjacent walls north, east, and south.  For the Castle Prison
    tileset (autotile #1), this is 67.
 
    (It's a bit unwieldy, but it works.)
=end   
 
  Autotile_Keys = {
  12346789=>0,  2346789=>1,  1246789=>2,  246789=>3,  1234678=>4,
  234678=>5,  124678=>6,  24678=>7,  1234689=>8,  234689=>9,
  124689=>10,  24689=>11,  123468=>12,  23468=>13,  12468=>14,
  2468=>15,  23689=>16,  2689=>17,  2678=>18,  268=>19,  46789=>20,
  4678=>21,  4689=>22,  468=>23,  12478=>24,  1248=>25,  2478=>26,
  248=>27,  12346=>28,  2346=>29,  1246=>30,  246=>31,  28=>32,
  46=>33,  689=>34,  68=>35,  478=>36,  48=>37,  124=>38,  24=>39,
  236=>40,  26=>41,  8=>42,  6=>43,  2=>44,  4=>45,  0=>46
  }
 
  # many autotiles handle multiple situations
  # this hash keeps track of which keys are identical
  # to ones already defined above
  Duplicate_Keys = {
  123689 => 23689,  236789 => 23689,  1236789 => 23689,  34689 => 4689,
  14689 => 4689,  134689 => 4689,  14678 => 4678,  34678 => 4678,
  134678 => 4678,  146789 => 46789,  346789 => 46789,  1346789 => 46789,
  23467 => 2346,  23469 => 2346,  234679 => 2346,  123467 => 12346,
  123469 => 12346,  1234679 => 12346,  12467 => 1246,  12469 => 1246,
  124679 => 1246,   124789 => 12478,  123478 => 12478,  1234789 => 12478,
  146 => 46,  346 => 46,   467 => 46,   469 => 46,  1346 => 46,   1467 => 46,
  1469 => 46,   3467 => 46,   3469 => 46,   4679 => 46,   13467 => 46,   13469 => 46, 
  14679 => 46,   34679 => 46,   134679 => 46,  128 => 28,   238 => 28,   278 => 28, 
  289 => 28,   1238 => 28,   1278 => 28,  1289 => 28,   2378 => 28,   2389 => 28, 
  2789 => 28,   12378 => 28,   12389 => 28,   12789 => 28,   23789 => 28, 
  123789 => 28,  1247 => 124,  2369 => 236,  147 => 4,  247 => 24,  14 => 4,
  47 => 4,  1478 => 478,  3478 => 478,  4789 => 478,  134789 => 478,
  14789 => 478,    13478 => 478,  34789 => 478,  1234 => 124,  1247 => 124,
  1249 => 124,  12347 => 124,  12349 => 124,  12479 => 124,  123479 => 124,
  1236 => 236,  2367 => 236,  2369 => 236,  12367 => 236,  12369 => 236,
  23679 => 236,  123679 => 236,  12368 => 2368,  23678 => 2368,  
  123678 => 2368,  12348 => 1248,  12489 => 1248,  123489 => 1248,
  1689 => 689,  3689 => 689,  6789 => 689,  13689 => 689,  16789 => 689,
  36789 => 689,  136789 => 689,  12689 => 2689,  26789 => 2689,  
  126789 => 2689,  23478 => 2478,  24789 => 2478,  234789 => 2478,
  36=>6,  89=>8,  369=>6,  389=>8,  69=>6,  368=>68,  78=>8,  12=>2,
  269=>26,  148=>48,  789=>8,  123=>2,  126=>26,  23=>2,  2469=>246,  
  1489=>48,  489=>48,  1269=>26,  234=>24,  2347=>24,  2489=>248,
  2467=>246,  24679=>246,  23489=>248,  678=>68, 13468=>468,
  12678 => 2678, 12368 => 2368, 1468 => 468, 3678 => 68, 2368 => 23689,
  23678 => 2678, 2348 => 248, 3468 => 468, 1268 => 268, 123678 => 2678,
  12368 => 23689, 
  }   
 
  def self.setzen(wert)
    temp = Duplicate_Keys[wert]
    temp = wert if temp == nil
    temp = Autotile_Keys[temp]
 
    if temp == nil
      p wert
      temp = 0
    end
    return temp
  end
end


Das funzt auch ganz gut - jedoch nicht für parent-child autotiles

D.h. 4 Ozean-Autotiles, die eigentlich zusammenpassen, werden abgekapselt voneinander gemappt..

Wie es sein SOLLTE:
Bild

Wie es aktuell IST:
Bild

Der unterschied fällt hoffentlich auf ^^


Alsooo.. kann mir wer das Script so umschreiben, dass auch parent-child systeme unterstützt werden?
There was a Cave,
below a Silent's Grave.
Tunnels, extending far, running wide,
going deep into the World on the other Side.
Poor little Child, that was to brave,
died painfully deep down, in the Devil's Cave.

Ähnliche Themen

Social Bookmarks