# # Yoann Guillot 04/2005 # require 'libpng' class Demange def carte_fillroutes # routes # [1, 1, 1] : 458806 -> rien # [51, 51, 51] : 10942 -> route rapide (.3) # [154, 154, 154]: 10851 -> route lente (.5) # get_carte unless @http_client.cache['/img/plans/calques/plan_geo_1.png'] img = Png.new(@http_client.cache['/img/plans/calques/plan_geo_1.png'].content) h = Hash.new h[0] = 1.0 mv = 0 600.times { |y| xs = img.lines[y] 800.times { |x| idx = xs[x] mv = h[idx] if not mv case img.palette[idx] when [51, 51, 51] mv = h[idx] = 0.3 when [154, 154, 154] mv = h[idx] = 0.5 else puts "unknown route color at #{x}, #{y}: #{img.palette[idx].inspect}" next end end @vue[1][x, 600 - y].mv = mv if @vue[1][x, 600-y] } } end def carte_fillpers # pp = palette persos pp = Hash.new pp[[204, 51, 0]] = ['D', 'Démon'] pp[[51, 204, 0]] = ['h', 'humain'] pp[[51, 153, 204]] = ['A', 'Ange'] pp[[0, 153, 0]] = ['H', 'Héro humain'] pp[[153, 102, 51]] = ['c', 'chien/chat'] # 154 pp[[255, 0, 0]] = ['d', 'diablotin'] # 128 pp[[255, 255, 255]] = ['C', 'cherubin'] # 61 #[51, 153, 255] => 37 #[255, 51, 102] => 24 #[173, 91, 87] => 20 #[153, 204, 0] => 19 #[153, 255, 255] => 19 #[210, 168, 20] => 14 #[116, 134, 242] => 13 #[153, 51, 204] => 13 #[153, 51, 153] => 10 #[255, 5, 76] => 8 #[67, 67, 67] => 8 #[255, 102, 0] => 8 #[78, 78, 78] => 8 #[216, 102, 0] => 6 #[51, 102, 153] => 6 #[0, 255, 0] => 4 #[51, 255, 255] => 4 #[0, 110, 0] => 4 #[0, 51, 255] => 3 #[51, 153, 153] => 2 #[204, 204, 153] => 2 #[102, 51, 0] => 2 #[137, 110, 3] => 2 #[153, 0, 0] => 1 #[255, 51, 153] => 1 #[226, 223, 222] => 1 #[223, 41, 41] => 1 #[153, 204, 255] => 1 #[247, 250, 0] => 1 #[255, 153, 102] => 1 #[255, 85, 1] => 1 get_carte unless @http_client.cache['/img/plans/calques/plan_persos_1.png'] img = Png.new(@http_client.cache['/img/plans/calques/plan_persos_1.png'].content) h = Hash.new h[0] = nil race = nil 600.times { |y| xs = img.lines[y] 800.times { |x| idx = xs[x] if idx > 0 c = img.palette[idx] case pp[c] when Array @vue[1][x, 600-y].race = pp[c][0] when true @vue[1][x, 600-y].race = c.join(',') else puts "unknown race color at #{x}, #{y}: #{c.inspect}" @vue[1][x, 600-y].race = c.join(',') pp[c] = true end end @vue[1][x, 600 - y].mat = 0 if race } } end end