<commit_before>
Class = require "nyaa.class"
images = require "images"
Ground = require "data.ground"

tool = (x,y,z) -> -- Cette fonction sert à générer une carte binaire de perlin noise
	part = 5
	pow = 1/9
	t = 2*love.math.noise(x,y,z)-1
	s = ((math.abs(t))^pow)*t/math.abs(t)+1
	t = (math.floor(s*part/2)/part)
	s = (math.abs(t)^(1/pow))*t/math.abs(t)
	return s
	
noise = (noise,xMax,yMax) ->
	xMax = 400
	yMax = 300
	grid = {}
	for x = 1, xMax
		grid[x] = grid[x] or {}
		for y = 1, yMax
		    grid[x][y] = tool((x+noise)/50,(y+noise)/50,noise)
	return grid
	
Tile = Class "Tile",
	__init: (arg) =>
		@groundChange = arg.groundChange or nil -- permet de savoir si une case est d'origine (générée par le bruit) ou si elle a été modifiée
		@groundType = arg.groundType
		@structure = arg.structure or nil
		@ressources = arg.ressources or nil
	
	crossable: =>
		if @groundType != 0 and not @structure
			return true
		else return false

	__tostring: =>
		"<Tile: #{@groundType}, #{@structure}>"

local Map

Map = Class "Map",
	__init: (arg) =>
		@noises = arg.noises or nil -- FIXME
		@defaultground = arg.defaultGround

		@grid = {}
		@xMax = arg.xMax or 300
		@yMax = arg.yMax or 200
		@zMin = arg.zMin or -3
		@zMax = arg.zMax or 3

		@colonies = arg.colonies or {}

		@frame = 0

	__class: {
		:Tile

		perlinMap: (arg) ->
			self = Map arg
			@noises or= 1 -- FIXME

			mapSource1 = noise(@noises,@xMax,@yMax)		--Height Map
			mapSource2 = noise(@noises+0.1,@xMax,@yMax*2)	--GroundType Map
			for x = 1, @xMax
				@grid[x] = {}
				
				for y = 1, @yMax
					@grid[x][y] = {}
					
					for z = @zMin, mapSource1[x][y]
						@grid[x][y][z] = Tile
							groundType: Ground[mapSource2[x][y]+1]
							
					for z = mapSource1[x][y]+1, @zMax
						@grid[x][y][z] = Ground[3] -- empty ground

			self

		flatMap: (arg) ->
			self = Map arg

			rocks = Ground\getByName "Rocks"
			empty = Ground\getByName "Empty"

			for x = 1, @xMax
				@grid[x] = {}

				for y = 1, @yMax
					@grid[x][y] = {}

					for z = @zMin, @zMax<commit_msg>Ground ain’t a class.<commit_after>
Class = require "nyaa.class"
images = require "images"
ground = require "data.ground"

tool = (x,y,z) -> -- Cette fonction sert à générer une carte binaire de perlin noise
	part = 5
	pow = 1/9
	t = 2*love.math.noise(x,y,z)-1
	s = ((math.abs(t))^pow)*t/math.abs(t)+1
	t = (math.floor(s*part/2)/part)
	s = (math.abs(t)^(1/pow))*t/math.abs(t)
	return s
	
noise = (noise,xMax,yMax) ->
	xMax = 400
	yMax = 300
	grid = {}
	for x = 1, xMax
		grid[x] = grid[x] or {}
		for y = 1, yMax
		    grid[x][y] = tool((x+noise)/50,(y+noise)/50,noise)
	return grid
	
Tile = Class "Tile",
	__init: (arg) =>
		@groundChange = arg.groundChange or nil -- permet de savoir si une case est d'origine (générée par le bruit) ou si elle a été modifiée
		@groundType = arg.groundType
		@structure = arg.structure or nil
		@ressources = arg.ressources or nil
	
	crossable: =>
		if @groundType != 0 and not @structure
			return true
		else return false

	__tostring: =>
		"<Tile: #{@groundType}, #{@structure}>"

local Map

Map = Class "Map",
	__init: (arg) =>
		@noises = arg.noises or nil -- FIXME
		@defaultground = arg.defaultGround

		@grid = {}
		@xMax = arg.xMax or 300
		@yMax = arg.yMax or 200
		@zMin = arg.zMin or -3
		@zMax = arg.zMax or 3

		@colonies = arg.colonies or {}

		@frame = 0

	__class: {
		:Tile

		perlinMap: (arg) ->
			self = Map arg
			@noises or= 1 -- FIXME

			mapSource1 = noise(@noises,@xMax,@yMax)		--Height Map
			mapSource2 = noise(@noises+0.1,@xMax,@yMax*2)	--GroundType Map
			for x = 1, @xMax
				@grid[x] = {}
				
				for y = 1, @yMax
					@grid[x][y] = {}
					
					for z = @zMin, mapSource1[x][y]
						@grid[x][y][z] = Tile
							groundType: ground[mapSource2[x][y]+1]
							
					for z = mapSource1[x][y]+1, @zMax
						@grid[x][y][z] = ground[3] -- empty ground

			self

		flatMap: (arg) ->
			self = Map arg

			rocks = ground\getByName "Rocks"
			empty = ground\getByName "Empty"

			for x = 1, @xMax
				@grid[x] = {}

				for y = 1, @yMax
					@grid[x][y] = {}

					for z = @zMin, @zMax
{'fraction_non_alphanumeric': 0.1678903573176701, 'fraction_numerical': 0.022515907978463045, 'mean_word_length': 2.739249771271729, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2073669', 'n_tokens_mistral': 1986, 'n_tokens_neox': 1675, 'n_words': 440}