diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e43b0f9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..f95a947 --- /dev/null +++ b/.luacheckrc @@ -0,0 +1 @@ +unused_args = false diff --git a/game.conf b/game.conf new file mode 100644 index 0000000..fafd81c --- /dev/null +++ b/game.conf @@ -0,0 +1,7 @@ +title = Tungston's Game +author = TungstonMiner +description = Realism-oriented survival simulation +first_mod = tmg_first +last_mode tmg_last +allowed_mapgens = singlenode +default_mapgen = singlenode diff --git a/minetest.conf b/minetest.conf new file mode 100644 index 0000000..e69de29 diff --git a/mods/tmg_constants/constants.lua b/mods/tmg_constants/constants.lua new file mode 100644 index 0000000..b2b142a --- /dev/null +++ b/mods/tmg_constants/constants.lua @@ -0,0 +1,55 @@ +-- Constants --------------------------------------------------------------------------------------- + +tmg_constants = { -- luacheck: globals tmg_constants + ALTITUDE = { + SKY = 256, + MOUNTAIN = 128, + MOOR = 64, + HILL = 32, + PLAIN = 16, + SURFACE = 0, + SHALLOW = -16, + DEEP = -32, + ABYSS = -64, + BEDROCK = -128, + }, + ANIMATION_TYPE = { + VERTICAL_FRAMES = "vertical_frames", + SHEET_2D = "sheet_2d", + }, + DRAW_TYPE = { + ALL_FACES_OPTIONAL = "allfaces_optional", + FLOWING_LIQUID = "flowingliquid", + LIQUID = "liquid", + MESH = "mesh", + NODE_BOX = "nodebox", + NORMAL = "normal", + PLANT_LIKE = "plantlike", + }, + LIQUID_TYPE = { + NONE = "none", + SOURCE = "source", + FLOWING = "flowing", + }, + TEXTURE_ALPHA = { + OPAQUE = "opaque", + CLIP = "clip", + BLEND = "blend", + }, + VISCOSITY = { + XXX_FAST = 0, + XX_FAST = 1, + X_FAST = 2, + FAST = 3, + SLOW = 4, + X_SLOW = 5, + XX_SLOW = 6, + XXX_SLOW = 7, + }, + WAVING = { + NO = 0, + PLANT_LIKE = 1, + LEAF_LIKE = 2, + LIQUID_LIKE = 3, + }, +} diff --git a/mods/tmg_constants/init.lua b/mods/tmg_constants/init.lua new file mode 100644 index 0000000..48620a2 --- /dev/null +++ b/mods/tmg_constants/init.lua @@ -0,0 +1,6 @@ +-- Imports & Exports ------------------------------------------------------------------------------- + +local core = _G["core"] + +local path = core.get_modpath("tmg_constants") +dofile(path.."/constants.lua") diff --git a/mods/tmg_constants/mod.conf b/mods/tmg_constants/mod.conf new file mode 100644 index 0000000..801ad29 --- /dev/null +++ b/mods/tmg_constants/mod.conf @@ -0,0 +1,4 @@ +name = tmg_constants +title = Tungston's Game / Constants +description = defined shared values across mods +author = tungstonminer diff --git a/mods/tmg_first/init.lua b/mods/tmg_first/init.lua new file mode 100644 index 0000000..10f2291 --- /dev/null +++ b/mods/tmg_first/init.lua @@ -0,0 +1,23 @@ +-- Imports & Exports ------------------------------------------------------------------------------- + +local core = _G["core"] + +tmg_first = {} -- luacheck: globals tmg_first + + +-- Private Functions ------------------------------------------------------------------------------- + +local private = {} + +function private.register_mapgen_aliases() + core.register_alias("mapgen_stone", "tmg_nodes:stone") + core.register_alias("mapgen_water_source", "tmg_nodes:water_source") + core.register_alias("mapgen_river_water_source", "tmg_nodes:water_source") +end + + +-- Script ------------------------------------------------------------------------------------------ + +core.debug("Tungston's Game initializing") + +private.register_mapgen_aliases() diff --git a/mods/tmg_first/mod.conf b/mods/tmg_first/mod.conf new file mode 100644 index 0000000..0d13f11 --- /dev/null +++ b/mods/tmg_first/mod.conf @@ -0,0 +1,4 @@ +name = tmg_first +title = Tungston's Game / First +description = set up game basics +author = tungstonminer diff --git a/mods/tmg_last/init.lua b/mods/tmg_last/init.lua new file mode 100644 index 0000000..671bb56 --- /dev/null +++ b/mods/tmg_last/init.lua @@ -0,0 +1,136 @@ +-- Imports & Exports ------------------------------------------------------------------------------- + +local core = _G["core"] +local dump = _G["dump"] +local C = _G["tmg_constants"] + +-- Constants --------------------------------------------------------------------------------------- + +local SINGLEPLAYER_PRIVS = { + debug = true, + fast = true, + fly = true, + give = true, + interact = true, + noclip = true, + privs = true, + server = true, + settime = true, + teleport = true, +} + + +-- Private Functions ------------------------------------------------------------------------------- + +local private = {} + +--[[ + Find a player with a given name. + + Args: + - player_name:string - the name of the desired player + + Returns: + - an ObjectRef for the requested player if they're logged on, or nil +]]-- +function private.find_player(name) + for _, player in ipairs(core.get_connected_players()) do + if player:get_player_name() == name then + return player + end + end + + return nil +end + +--[[ + Move the indicated player into a safe spawn location. + + We're looking for somewhere which is an air block on top of something walkable. We start with + the player's current position, and examine the current x/z column to find the first air block, + and see if that will do. If not, we pick a new location a short distance away, and repeat. The + process continues to expand outwards until a safe location is found, or we've looked half a km + away without finding anything. + + If this function gets called before the world has finished generating, it will automatically + delay + + Args: + - player:ObjectRef - the player to relocate +]]-- +function private.set_starting_pos(player_name, delays) + delays = delays or 0 + if delays > 10 then + core.log("warning", "Too many delays in finding a safe spawning location: giving up") + return + end + + local player = private.find_player(player_name) + local player_pos = player:get_pos() + local node = core.get_node(player_pos) + if node.name == "unknown" or node.name == "ignore" then + core.log("action", "no map data, delaying player positioning") + core.after(0.1, function() private.set_starting_pos(player_name, delays + 1) end) + return + end + + local pos = { x = player_pos.x, y = player_pos.y, z = player_pos.z } + local distances = { 0, 8, 16, 32, 64, 128, 256, 512 } + for _, distance in ipairs(distances) do + for _, dx in ipairs({ 0, 1, -1 }) do + pos.x = player_pos.x + dx * distance + + for _, dz in ipairs({ 0, 1, -1 }) do + pos.z = player_pos.z + dz * distance + + local floor_node = nil + for y = C.ALTITUDE.BEDROCK, C.ALTITUDE.SKY do + pos.y = y + + node = core.get_node(pos) + if floor_node and node.name == "air" then + local floor_def = core.registered_nodes[floor_node.name] + if floor_def.walkable then + core.log("info", "Moved player to "..dump(pos, "")) + player:set_pos(pos) + return + end + break + end + + floor_node = node + end + end + end + end +end + + +--[[ + Set up privledges and settings for a new player. + + Args: + - player:ObjectRef - the current player +]]-- +function private.setup_player(player) + core.set_player_privs(player:get_player_name(), SINGLEPLAYER_PRIVS) + + local physics = player:get_physics_override() + physics.speed_fast = 10 + player:set_physics_override(physics) +end + + +-- Registrations ----------------------------------------------------------------------------------- + +core.register_on_joinplayer(function(player, last_login) + if last_login then return end + + private.setup_player(player) + private.set_starting_pos(player:get_player_name()) +end) + + +-- Script ------------------------------------------------------------------------------------------ + +core.log("info", "Tungston's Game initialization complete") diff --git a/mods/tmg_last/mod.conf b/mods/tmg_last/mod.conf new file mode 100644 index 0000000..4f0b22f --- /dev/null +++ b/mods/tmg_last/mod.conf @@ -0,0 +1,5 @@ +name = tmg_last +title = Tungston's Game / Last +description = complete game setup +author = tungstonminer +depends = tmg_constants diff --git a/mods/tmg_mapgen/init.lua b/mods/tmg_mapgen/init.lua new file mode 100644 index 0000000..c056675 --- /dev/null +++ b/mods/tmg_mapgen/init.lua @@ -0,0 +1,8 @@ +-- Imports & Exports ------------------------------------------------------------------------------- + +local core = _G["core"] + + +-- Registrations ----------------------------------------------------------------------------------- + +core.register_mapgen_script(core.get_modpath("tmg_mapgen").."/mapenv.lua") diff --git a/mods/tmg_mapgen/mapenv.lua b/mods/tmg_mapgen/mapenv.lua new file mode 100644 index 0000000..1220560 --- /dev/null +++ b/mods/tmg_mapgen/mapenv.lua @@ -0,0 +1,176 @@ +-- Imports & Exports ------------------------------------------------------------------------------- + +local core = _G["core"] +local dump = _G["dump"] +local math = _G["math"] +local VoxelArea = _G["VoxelArea"] + +local tmg_constants_path = core.get_modpath("tmg_constants") +dofile(tmg_constants_path.."/constants.lua") +local C = _G["tmg_constants"] +local A = C.ALTITUDE + + +-- Constants --------------------------------------------------------------------------------------- + +local data = {} + +local TERRAIN_TYPE_NOISE = core.get_value_noise({ + flags = "eased", + lacunarity = 2, + octaves = 1, + offset = 0, + persistence = 0.5, + scale = 1.0, + seed = 8381909047, + spread = { x = 512, y = 512, z = 0 }, +}) + +local TERRAIN_TYPES = { + { name = "ocean_abyss", lowest = A.ABYSS, highest = A.DEEP, noise = nil }, + { name = "ocean_shelf", lowest = A.DEEP, highest = A.SHALLOW, noise = nil }, + { name = "ocean_surface", lowest = A.SHALLOW, highest = A.SURFACE, noise = nil }, + { name = "land_plains", lowest = A.SURFACE, highest = A.PLAIN, noise = nil }, + { name = "land_hills", lowest = A.PLAIN, highest = A.HILL, noise = nil }, + { name = "land_moors", lowest = A.HILL, highest = A.MOOR, noise = nil }, + { name = "land_mountains", lowest = A.MOOR, highest = A.MOUNTAIN, noise = nil }, +} + + +-- Private Functions ------------------------------------------------------------------------------- + +local private = {} + +function private.compute_altitude_at(pos) + local raw_index = (TERRAIN_TYPE_NOISE:get_2d(pos) + 2) / 2 * #TERRAIN_TYPES + raw_index = math.max(1, math.min(#TERRAIN_TYPES, raw_index)) + local result = 0 + + for index, terrain in ipairs(TERRAIN_TYPES) do + if not terrain.noise then + terrain.noise = private.make_noise_in_range(terrain.lowest, terrain.highest) + end + + local factor = math.max(0, math.min(1, 1 - math.abs(raw_index - index))) + result = result + factor * terrain.noise:get_2d(pos) + + if pos.x % 64 == 0 and pos.z % 64 == 0 and factor > 0 then + core.debug("raw_index: "..raw_index..", terrain: "..terrain.name..", factor: "..factor) + end + end + + return math.floor(result) +end + +--[[ + Fill the lowest layer of the world with bedrock nodes. + + Args: + - area:VoxelArea - an area calibrated to the area to fill + - fill_min:vector - the minimal corner of the area to fill + - fill_max:vector - the maximal corner of the area to fill +]]-- +function private.fill_bedrock(area, fill_min, fill_max) + if fill_min.y > A.BEDROCK then return end + + local bedrock_id = core.get_content_id("tmg_nodes:bedrock") + + for x = fill_min.x, fill_max.x do + for z = fill_min.z, fill_max.z do + data[area:index(x, A.BEDROCK, z)] = bedrock_id + end + end +end + +--[[ + Fill in the oceans by replacing air blocks below sea level with water. + + Args: + - area:VoxelArea - an area calibrated to the area to fill + - fill_min:vector - the minimal corner of the area to fill + - fill_max:vector - the maximal corner of the area to fill +]]-- +function private.fill_ocean(area, fill_min, fill_max) + if fill_min.y > A.SURFACE then return end + + local water_id = core.get_content_id("mapgen_water_source") + local y_max = math.min(fill_max.y, A.SURFACE) + local y_min = math.max(fill_min.y, A.BEDROCK) + + for x = fill_min.x, fill_max.x do + for y = y_min, y_max do + for z = fill_min.z, fill_max.z do + local index = area:index(x, y, z) + if data[index] == core.CONTENT_AIR then + data[index] = water_id + end + end + end + end +end + +--[[ + Fill in base stone terrain using altitude noise. + + Args: + - area:VoxelArea - an area calibrated to the area to fill + - fill_min:vector - the minimal corner of the area to fill + - fill_max:vector - the maximal corner of the area to fill +]]-- +function private.fill_terrain(area, fill_min, fill_max) + local pos = { x = 0, y = 0, z = 0 } + local stone_id = core.get_content_id("mapgen_stone") + local y_max = math.min(fill_max.y, A.SKY) + local y_min = math.max(fill_min.y, A.BEDROCK) + + for x = fill_min.x, fill_max.x do + for z = fill_min.z, fill_max.z do + pos.x, pos.y = x, z + local y_terrain = private.compute_altitude_at(pos) + + for y = y_min, math.min(y_max, y_terrain) do + data[area:index(x, y, z)] = stone_id + end + end + end +end + +--[[ + Make a ValueNoise source scaled to a certain altitude range. + + Args: + - highest:int - the highest altitude desired in the range + - lowest:int - the lowest altitude desired in the range + + Return: + - a ValueNoise object +]]-- +function private.make_noise_in_range(lowest, highest) + return core.get_value_noise({ + flags = "eased", + lacunarity = 2, + octaves = 5, + offset = lowest, + persistence = 0.5, + scale = (highest - lowest) / 2, + seed = 16552167, + spread = { x = 128, y = 128, z = 0 }, + }) +end + + +-- Registrations ----------------------------------------------------------------------------------- + +core.register_on_generated(function(voxels, fill_min, fill_max) + local emerged_min, emerged_max = voxels:get_emerged_area() + local area = VoxelArea(emerged_min, emerged_max) + + voxels:get_data(data) + private.fill_terrain(area, fill_min, fill_max) + private.fill_bedrock(area, fill_min, fill_max) + private.fill_ocean(area, fill_min, fill_max) + voxels:set_data(data) + + voxels:calc_lighting() + voxels:update_liquids() +end) diff --git a/mods/tmg_mapgen/mod.conf b/mods/tmg_mapgen/mod.conf new file mode 100644 index 0000000..f8cb1d9 --- /dev/null +++ b/mods/tmg_mapgen/mod.conf @@ -0,0 +1,5 @@ +name = tmg_mapgen +title = Tungston's Game / Map Generation +description = do the work of actually generating the map +author = tungstonminer +depends = tmg_nodes diff --git a/mods/tmg_nodes/earthlike.lua b/mods/tmg_nodes/earthlike.lua new file mode 100644 index 0000000..56cd9f9 --- /dev/null +++ b/mods/tmg_nodes/earthlike.lua @@ -0,0 +1,26 @@ +-- Imports & Exports ------------------------------------------------------------------------------- + +local core = _G["core"] + + +-- Constants --------------------------------------------------------------------------------------- + +local S = core.get_translator("tmg_nodes") + + +-- Registrations ----------------------------------------------------------------------------------- + +core.register_node("tmg_nodes:bedrock", { + description = S("Bedrock"), + drop = "", + is_ground_content = false, + sounds = { footstep = "tmg_nodes_stone" }, + tiles = {"tmg_nodes_bedrock.png"}, +}) + +core.register_node("tmg_nodes:stone", { + description = S("Stone"), + drop = "tmg_nodes:stone", + sounds = { footstep = "tmg_nodes_stone" }, + tiles = {"tmg_nodes_stone.png"}, +}) diff --git a/mods/tmg_nodes/init.lua b/mods/tmg_nodes/init.lua new file mode 100644 index 0000000..0a4d4aa --- /dev/null +++ b/mods/tmg_nodes/init.lua @@ -0,0 +1,10 @@ +-- Imports & Exports ------------------------------------------------------------------------------- + +local core = _G["core"] + + +-- Script ------------------------------------------------------------------------------------------ + +local path = core.get_modpath("tmg_nodes") +dofile(path.."/earthlike.lua") +dofile(path.."/liquid.lua") diff --git a/mods/tmg_nodes/liquid.lua b/mods/tmg_nodes/liquid.lua new file mode 100644 index 0000000..6608626 --- /dev/null +++ b/mods/tmg_nodes/liquid.lua @@ -0,0 +1,78 @@ +-- Imports & Exports ------------------------------------------------------------------------------- + +local core = _G["core"] +local tmg_constants = _G["tmg_constants"] + + +-- Constants --------------------------------------------------------------------------------------- + +local S = core.get_translator("tmg_nodes") + + +-- Registrations ----------------------------------------------------------------------------------- + +core.register_node("tmg_nodes:water_flowing", { + description = S("Flowing Water"), + drawtype = tmg_constants.DRAW_TYPE.FLOWING_LIQUID, + tiles = {{ + name = "tmg_nodes_water_flowing_animated.png", + animation = { + type = tmg_constants.ANIMATION_TYPE.VERTICAL_FRAMES, + aspect_w = 16, + aspect_h = 16, + length = 5.0, + }, + }}, + sounds = { footstep = { name = "tmg_nodes_water_footstep" } }, + is_ground_content = false, + use_texture_alpha = "blend", + paramtype = "light", + paramtype2 = "flowingliquid", + walkable = false, + pointable = false, + diggable = false, + buildable_to = true, + drop = "", + drowning = 4, + liquidtype = tmg_constants.LIQUID_TYPE.FLOWING, + liquid_alternative_flowing = "tmg_nodes:water_flowing", + liquid_alternative_source = "tmg_nodes:water_source", + liquid_viscosity = tmg_constants.VISCOSITY.XX_FAST, + liquid_range = 7, + waving = tmg_constants.WAVING.LIQUID_LIKE, + post_effect_color = "#033C5CCC", + groups = {}, +}) + +core.register_node("tmg_nodes:water_source", { + description = S("Water"), + drawtype = "liquid", + waving = tmg_constants.WAVING.LIQUID_LIKE, + tiles = {{ + name = "tmg_nodes_water_source_animated.png", + animation = { + type = "vertical_frames", + aspect_w = 16, + aspect_h = 16, + length = 5.0, + } + }}, + sounds = { footstep = { name = "tmg_nodes_water_footstep" } }, + is_ground_content = false, + use_texture_alpha = tmg_constants.TEXTURE_ALPHA.BLEND, + paramtype = "light", + walkable = false, + pointable = false, + diggable = false, + buildable_to = true, + drop = "", + drowning = 4, + liquidtype = "source", + liquid_alternative_flowing = "tmg_nodes:water_flowing", + liquid_alternative_source = "tmg_nodes:water_source", + liquid_viscosity = tmg_constants.VISCOSITY.XX_FAST, + liquid_renewable = true, + liquid_range = 7, + post_effect_color = "#033C5CCC", + groups = { }, +}) diff --git a/mods/tmg_nodes/mod.conf b/mods/tmg_nodes/mod.conf new file mode 100644 index 0000000..eb99dc4 --- /dev/null +++ b/mods/tmg_nodes/mod.conf @@ -0,0 +1,5 @@ +name = tmg_nodes +title = Tungston's Game / Nodes +description = define the nodes which make up the world +author = tungstonminer +depends = tmg_constants diff --git a/mods/tmg_nodes/sounds/tmg_nodes_stone_footstep.1.ogg b/mods/tmg_nodes/sounds/tmg_nodes_stone_footstep.1.ogg new file mode 100644 index 0000000..0a08efa Binary files /dev/null and b/mods/tmg_nodes/sounds/tmg_nodes_stone_footstep.1.ogg differ diff --git a/mods/tmg_nodes/sounds/tmg_nodes_stone_footstep.2.ogg b/mods/tmg_nodes/sounds/tmg_nodes_stone_footstep.2.ogg new file mode 100644 index 0000000..be52a87 Binary files /dev/null and b/mods/tmg_nodes/sounds/tmg_nodes_stone_footstep.2.ogg differ diff --git a/mods/tmg_nodes/sounds/tmg_nodes_stone_footstep.3.ogg b/mods/tmg_nodes/sounds/tmg_nodes_stone_footstep.3.ogg new file mode 100644 index 0000000..a342787 Binary files /dev/null and b/mods/tmg_nodes/sounds/tmg_nodes_stone_footstep.3.ogg differ diff --git a/mods/tmg_nodes/sounds/tmg_nodes_water_footstep.1.ogg b/mods/tmg_nodes/sounds/tmg_nodes_water_footstep.1.ogg new file mode 100644 index 0000000..63b9744 Binary files /dev/null and b/mods/tmg_nodes/sounds/tmg_nodes_water_footstep.1.ogg differ diff --git a/mods/tmg_nodes/sounds/tmg_nodes_water_footstep.2.ogg b/mods/tmg_nodes/sounds/tmg_nodes_water_footstep.2.ogg new file mode 100644 index 0000000..8d79c1f Binary files /dev/null and b/mods/tmg_nodes/sounds/tmg_nodes_water_footstep.2.ogg differ diff --git a/mods/tmg_nodes/sounds/tmg_nodes_water_footstep.3.ogg b/mods/tmg_nodes/sounds/tmg_nodes_water_footstep.3.ogg new file mode 100644 index 0000000..f889150 Binary files /dev/null and b/mods/tmg_nodes/sounds/tmg_nodes_water_footstep.3.ogg differ diff --git a/mods/tmg_nodes/textures/tmg_nodes_bedrock.png b/mods/tmg_nodes/textures/tmg_nodes_bedrock.png new file mode 100644 index 0000000..baed9bb Binary files /dev/null and b/mods/tmg_nodes/textures/tmg_nodes_bedrock.png differ diff --git a/mods/tmg_nodes/textures/tmg_nodes_stone.png b/mods/tmg_nodes/textures/tmg_nodes_stone.png new file mode 100644 index 0000000..9e9145a Binary files /dev/null and b/mods/tmg_nodes/textures/tmg_nodes_stone.png differ diff --git a/mods/tmg_nodes/textures/tmg_nodes_water_flowing_animated.png b/mods/tmg_nodes/textures/tmg_nodes_water_flowing_animated.png new file mode 100644 index 0000000..d26c756 Binary files /dev/null and b/mods/tmg_nodes/textures/tmg_nodes_water_flowing_animated.png differ diff --git a/mods/tmg_nodes/textures/tmg_nodes_water_source_animated.png b/mods/tmg_nodes/textures/tmg_nodes_water_source_animated.png new file mode 100644 index 0000000..5d45822 Binary files /dev/null and b/mods/tmg_nodes/textures/tmg_nodes_water_source_animated.png differ diff --git a/settingtypes.txt b/settingtypes.txt new file mode 100644 index 0000000..e69de29