summaryrefslogtreecommitdiff
path: root/worldmap_gen.rb
diff options
context:
space:
mode:
Diffstat (limited to 'worldmap_gen.rb')
-rw-r--r--worldmap_gen.rb88
1 files changed, 52 insertions, 36 deletions
diff --git a/worldmap_gen.rb b/worldmap_gen.rb
index c8013e3..e52eefc 100644
--- a/worldmap_gen.rb
+++ b/worldmap_gen.rb
@@ -1,18 +1,18 @@
require 'rexml/document'
doc = nil
-File::open("TestMap.xml") do |f|
+File::open("#{ARGV[0]}.xml") do |f|
doc = REXML::Document.new(f.read)
end
class Exit
attr_accessor :path
attr_accessor :reverse
-
+
def initialize(element)
@path = element.attribute('to').value
@reverse = false
-
+
unless element.attribute('reverse').nil?
@reverse = true
end
@@ -25,26 +25,26 @@ class Point
attr_accessor :params
attr_accessor :position
attr_reader :id
-
+
def initialize(element)
@exits = {}
@type = ''
@params = [0,0,0,0]
@position = [0,0,0]
-
+
position = element.attribute 'position'
@position = position.value.split(',').collect { |v| v.to_f }
-
+
type = element.attribute 'type'
params = element.attribute 'params'
-
+
@type = type.value unless type.nil?
@params = params.value.split(',').collect { |v| v.to_i } unless params.nil?
-
+
element.each_element 'exit' do |e|
@exits[e.attribute('direction').value] = Exit.new(e)
end
-
+
@id = $point_id
$point_id += 1
end
@@ -59,30 +59,46 @@ class Segment
attr_accessor :direction, :same_dir
attr_reader :id
# todo: actions
-
+
def initialize(element)
- @start_pos = element.attribute('from').value.split(',').collect { |v| v.to_f }
- @end_pos = element.attribute('to').value.split(',').collect { |v| v.to_f }
-
+ from = element.attribute('from').value
+ to = element.attribute('to').value
+
+ if $points.has_key? from
+ @start_pos = $points[from].position
+ puts "From: point #{from} #{@start_pos}"
+ else
+ @start_pos = from.split(',').collect { |v| v.to_f }
+ puts "From: position #{from}"
+ end
+
+ if $points.has_key? to
+ @end_pos = $points[to].position
+ puts "To: point #{to} #{@end_pos}"
+ else
+ @end_pos = to.split(',').collect { |v| v.to_f }
+ puts "To: position #{to}"
+ end
+
@speed = 4.5
speed = element.attribute 'speed'
unless speed.nil?
@speed = speed.value.to_f
end
-
+
@anim = 'run'
@anim_speed = 2.0
-
+
anim = element.attribute 'animation'
unless anim.nil?
@anim = anim.value
end
-
+
anim_speed = element.attribute 'animation_speed'
unless anim_speed.nil?
@anim_speed = anim_speed.value.to_f
end
-
+
@direction = nil
direction = element.attribute 'direction'
unless direction.nil?
@@ -111,12 +127,12 @@ class Segment
@direction *= 180 / Math::PI
end
end
-
+
@same_dir = !(element.attribute('same_dir').nil?)
-
+
@id = $segment_id
$segment_id += 1
-
+
$segments << self
end
end
@@ -127,19 +143,19 @@ class Path
attr_accessor :start_point
attr_accessor :end_point
attr_reader :id
-
+
def initialize(element)
@start_point = element.attribute('start').value
@end_point = element.attribute('end').value
-
+
@segments = []
@segment_ids = []
-
+
element.each_element 'segment' do |e|
@segments << Segment.new(e)
@segment_ids << @segments.last.id
end
-
+
@id = $path_id
$path_id += 1
end
@@ -199,49 +215,49 @@ puts "[[[ Paths done ]]]"
puts "Statistics: #{$points.count} points, #{$paths.count} paths, #{$segments.count} segments"
# now write the file
-File::open("TestMap.wm", "w") do |f|
+File::open("#{ARGV[0]}.wm", "w") do |f|
f << 'NwWM'
-
+
# calculate all this stuff
header_size = 0x24
-
+
path_list_offs = header_size
point_list_offs = path_list_offs + ($paths.count * 4)
segment_list_offs = point_list_offs + ($points.count * 4)
action_list_offs = segment_list_offs + ($segments.count * 4)
data_offset = action_list_offs # + ($actions.count * 4)
-
+
f << [path_list_offs, $paths.count].pack('NN')
f << [point_list_offs, $points.count].pack('NN')
f << [segment_list_offs, $segments.count].pack('NN')
f << [action_list_offs, 0].pack('NN')
-
+
# now work out the offsets for everything
current_offset = data_offset
$paths.each_value do |p|
f << [current_offset].pack('N')
current_offset += 0xC + (p.segments.count * 4)
end
-
+
$points.each_value do |p|
f << [current_offset].pack('N')
current_offset += 0x40
end
-
+
$segments.each do |s|
f << [current_offset].pack('N')
current_offset += 0x2C
end
-
+
# nothing for actions yet!
-
+
# now write the data
$paths.each_value do |p|
f << [$points[p.start_point].id, $points[p.end_point].id].pack('NN')
f << [p.segments.count].pack('N')
f << p.segment_ids.pack('N*')
end
-
+
$points.each_value do |p|
['left', 'right', 'up', 'down'].each do |direction|
if p.exits.include? direction
@@ -252,12 +268,12 @@ File::open("TestMap.wm", "w") do |f|
f << [-1,-1].pack('NN')
end
end
-
+
f << [point_types[p.type]].pack('N')
f << p.params.pack('N*')
f << p.position.pack('g*')
end
-
+
$segments.each do |s|
f << s.start_pos.pack('g*')
f << s.end_pos.pack('g*')