From c2fc083ba0f57e753d60c64b7fe3dc2f097b80ec Mon Sep 17 00:00:00 2001 From: Bruno Date: Wed, 14 Feb 2018 12:02:23 -0200 Subject: [PATCH] mountain grass --- .../mountain_grass_component.lua | 31 ++++ data/biome/swamp_generation.json | 34 +++-- data/effects/fog_effect/fog_effect.json | 2 +- .../particles/firefly/firefly.cubemitter.json | 144 +++++++++++------- .../shaman_workbench/fire.cubemitter.json | 110 ++++++------- entities/plants/fern/fern.json | 4 + entities/plants/mushroom/mushroom.json | 4 + .../mushroom_medium/mushroom_medium.json | 4 + .../plants/mushroom_small/mushroom_small.json | 4 + .../mountain_grass/mountain_grass.json | 15 ++ entities/trees/cypress/cypress.json | 4 + .../recipes/plate_of_mushrooms_recipe.json | 2 +- manifest.json | 5 +- .../swimming/custom_swimming_service.lua | 4 +- .../server/world_generation/custom_biome.lua | 90 ++++++++++- .../custom_height_map_renderer.lua | 4 +- swamp_goblins_client.lua | 6 +- 17 files changed, 328 insertions(+), 139 deletions(-) create mode 100644 components/mountain_grass/mountain_grass_component.lua create mode 100644 entities/terrain/mountain_grass/mountain_grass.json diff --git a/components/mountain_grass/mountain_grass_component.lua b/components/mountain_grass/mountain_grass_component.lua new file mode 100644 index 0000000..6aac6fc --- /dev/null +++ b/components/mountain_grass/mountain_grass_component.lua @@ -0,0 +1,31 @@ +-- local log = radiant.log.create_logger('MountainGrass') +local MountainGrass = class() +local Point3 = _radiant.csg.Point3 +local Cube3 = _radiant.csg.Cube3 +local Region3 = _radiant.csg.Region3 + +function MountainGrass:post_activate() + local json = radiant.entities.get_json(self) + self.radius = json.radius or 8 + self.block_type = json.block_type or "grass" + self.priority = json.priority or 10 --less = higher priority + + self.timer = stonehearth.calendar:set_timer('replacing rocks with grass', self.priority, function() + local location = radiant.entities.get_world_grid_location(self._entity) + if location and location.y > 50 then + local block_type = radiant.terrain.get_block_types()[self.block_type] + local cube = Cube3( + location + Point3(-self.radius,-1,-self.radius), + location + Point3( self.radius, 0, self.radius) + ) + local grass_region = radiant.terrain.intersect_cube(cube) + for cube in grass_region:each_cube() do + radiant.terrain.add_cube(Cube3(cube.min,cube.max,block_type)) + end + end + self.timer = nil + self._entity:remove_component('swamp_goblins:mountain_grass') + end) +end + +return MountainGrass \ No newline at end of file diff --git a/data/biome/swamp_generation.json b/data/biome/swamp_generation.json index 32a864d..c7534f2 100644 --- a/data/biome/swamp_generation.json +++ b/data/biome/swamp_generation.json @@ -74,7 +74,7 @@ "step_count": 2 }, "foothills": { - "step_size": 5, + "step_size": 3, "step_count": 1 }, "mountains": { @@ -105,7 +105,7 @@ "octaves": 4, "persistence_ratio": 0.2, "amplitude": 2.5, - "layer_thickness": 1, + "layer_thickness": 2, "layer_count": 2, "unit_length": 8 }, @@ -113,7 +113,7 @@ "octaves": 4, "persistence_ratio": 0.1, "amplitude": 2.5, - "layer_thickness": 1, + "layer_thickness": 2, "unit_length": 10 } }, @@ -132,6 +132,10 @@ "landscape": { "has_grass": true, "placement_table" : { + "swamp_goblins:terrain:mountain_grass" : { + "placement_type" : "single", + "parameters" : { "ground_radius" : 1, "exclusion_radius" : 6 } + }, "swamp_goblins:trees:cypress:small" : { "placement_type" : "single", "parameters" : { "ground_radius" : 2, "exclusion_radius" : 3 } @@ -174,6 +178,14 @@ "grid_multiple": 4, "item_density": 0.18, "exclusion_radius": 1 + }, + "mountains": { + "placement_type": "dense", + "parameters": { + "grid_multiple": 3, + "item_density": 0.18, + "exclusion_radius": 1 + } } }, "swamp_goblins:plants:giant_flower": { @@ -258,9 +270,7 @@ }, "mountains": { "1": { - "swamp_goblins:trees:bogger": 1, - "swamp_goblins:trees:cypress": 1, - "swamp_goblins:trees:swirl": 1 + "swamp_goblins:trees:cypress": 1 } } }, @@ -291,7 +301,7 @@ }, "mountains": { "1": { - "mean": -100, + "mean": 0, "std_dev": 0, "density": 0 } @@ -346,7 +356,9 @@ }, "mountains": { "1": { - "swamp_goblins:plants:fern": 2, + "swamp_goblins:terrain:mountain_grass": 2, + "swamp_goblins:trees:cypress:small":1, + "swamp_goblins:plants:fern": 1, "swamp_goblins:plants:mushroom": 1 } } @@ -371,8 +383,8 @@ }, "mountains": { "1": { - "probability": 0.1, - "density": 0.4 + "probability": 0.75, + "density": 0.3 } } } @@ -400,7 +412,7 @@ }, "mountains": { "1": { - "probability": 0.1, + "probability": 0.2, "density": 0.1 } } diff --git a/data/effects/fog_effect/fog_effect.json b/data/effects/fog_effect/fog_effect.json index 90cf5ae..37d5c5b 100644 --- a/data/effects/fog_effect/fog_effect.json +++ b/data/effects/fog_effect/fog_effect.json @@ -12,4 +12,4 @@ } } } -} +} \ No newline at end of file diff --git a/data/horde/particles/firefly/firefly.cubemitter.json b/data/horde/particles/firefly/firefly.cubemitter.json index a11957a..6fbc602 100644 --- a/data/horde/particles/firefly/firefly.cubemitter.json +++ b/data/horde/particles/firefly/firefly.cubemitter.json @@ -1,60 +1,88 @@ { - "name": "firefly", - "duration": 20000, - "particle": { - "lifetime": { - "start": { - "kind": "RANDOM_BETWEEN", - "values": [9000, 10000] - } - }, - "speed": { - "start": { - "kind": "RANDOM_BETWEEN", - "values": [0.4, 0.5] - } - }, - - "color": { - "start": { - "kind": "RANDOM_BETWEEN", - "values": [ - [0.4, 0.5, 0.0, 1.0], - [0.0, 0.6, 0.3, 1.0] - ] - }, - "over_lifetime_a": { - "kind": "CURVE", - "values": [ - [0.0, 0.0], [0.02, 1.0], [0.1, 1.0], [0.12, 0.0], - [0.2, 0.0], [0.22, 1.0], [0.3, 1.0], [0.32, 0.0], - [0.4, 0.0], [0.42, 1.0], [0.5, 1.0], [0.52, 0.0], - [0.6, 0.0], [0.62, 1.0], [0.7, 1.0], [0.72, 0.0], - [0.8, 0.0], [0.82, 1.0], [0.9, 1.0], [0.92, 0.0] - ] - } - }, - "scale": { - "start": { - "kind": "RANDOM_BETWEEN", - "values": [0.1, 0.2] - } - }, - "velocity": { - } - }, - "emission": { - "rate": { - "kind": "CONSTANT", - "values": [3] - }, - "origin": { - "surface": "RECTANGLE", - "values": [8, 8] - }, - "angle": { - "kind": "RANDOM_BETWEEN", - "values": [0,360] - } - } + "name": "firefly", + "duration": 20000, + "material": "materials/cubemitter.material.json", + "loops": true, + "emission": { + "rate": { + "kind": "CONSTANT", + "values": [3] + }, + "angle": { + "kind": "CONSTANT", + "values": [0] + }, + "origin": { + "surface": "SPHERE", + "values": [4, 0, 360] + } + }, + "particle": { + "lifetime": { + "start": { + "kind": "RANDOM_BETWEEN", + "values": [9000, 10000] + } + }, + "speed": { + "start": { + "kind": "CONSTANT", + "values": [0] + } + }, + "velocity": { + "over_lifetime_x": { + "kind": "RANDOM_BETWEEN", + "values": [-0.3, 0.3] + }, + "over_lifetime_y": { + "kind": "RANDOM_BETWEEN", + "values": [-0.3, 0.3] + }, + "over_lifetime_z": { + "kind": "RANDOM_BETWEEN", + "values": [-0.3, 0.3] + } + }, + "scale": { + "start": { + "kind": "RANDOM_BETWEEN", + "values": [0.1, 0.2] + } + }, + "color": { + "start": { + "kind": "RANDOM_BETWEEN", + "values": [ + [0.4, 0.5, 0, 1], + [0, 0.6, 0.3, 1] + ] + }, + "over_lifetime_a": { + "kind": "CURVE", + "values": [ + [0, 0], + [0.02, 1], + [0.1, 1], + [0.12, 0], + [0.2, 0], + [0.22, 1], + [0.3, 1], + [0.32, 0], + [0.4, 0], + [0.42, 1], + [0.5, 1], + [0.52, 0], + [0.6, 0], + [0.62, 1], + [0.7, 1], + [0.72, 0], + [0.8, 0], + [0.82, 1], + [0.9, 1], + [0.92, 0] + ] + } + } + } } \ No newline at end of file diff --git a/data/horde/particles/shaman_workbench/fire.cubemitter.json b/data/horde/particles/shaman_workbench/fire.cubemitter.json index 35edc63..64626cf 100644 --- a/data/horde/particles/shaman_workbench/fire.cubemitter.json +++ b/data/horde/particles/shaman_workbench/fire.cubemitter.json @@ -1,57 +1,57 @@ { - "name": "firefly", - "duration": 20000, - "particle": { - "lifetime": { - "start": { - "kind": "RANDOM_BETWEEN", - "values": [500, 1000] - } - }, - "speed": { - "start": { - "kind": "RANDOM_BETWEEN", - "values": [0.2, 0.9] - } - }, - - "color": { - "start": { - "kind": "RANDOM_BETWEEN", - "values": [ - [0.8, 0.1, 0.1, 0.8], - [1.0, 0.5, 0.0, 1] - ] - }, - "over_lifetime_a": { - "kind": "CURVE", - "values": [ - [0.0, 1], [0.8, 0.2], [1.0, 0.0] - ] - } - }, - "scale": { - "start": { - "kind": "RANDOM_BETWEEN", - "values": [0.01, 0.15] - } - }, - "velocity": { - } - }, - "emission": { - "rate": { - "kind": "CONSTANT", - "values": [100] - }, - "origin": { - "surface": "RECTANGLE", - "values": [1, 1.5] - }, - "angle": { - "kind": "CONSTANT", - "values": [30] - } - }, - "material": "materials/cubemitter_bloom.material.json" + "name": "firefly", + "duration": 20000, + "material": "materials/cubemitter_bloom.material.json", + "loops": true, + "emission": { + "rate": { + "kind": "CONSTANT", + "values": [100] + }, + "angle": { + "kind": "CONSTANT", + "values": [30] + }, + "origin": { + "surface": "RECTANGLE", + "values": [1, 1.5, 0, 0] + } + }, + "particle": { + "lifetime": { + "start": { + "kind": "RANDOM_BETWEEN", + "values": [500, 1000] + } + }, + "speed": { + "start": { + "kind": "RANDOM_BETWEEN", + "values": [0.2, 0.9] + } + }, + "velocity": {}, + "scale": { + "start": { + "kind": "RANDOM_BETWEEN", + "values": [0.01, 0.15] + } + }, + "color": { + "start": { + "kind": "RANDOM_BETWEEN", + "values": [ + [0.8, 0.1, 0.1, 0.8], + [1, 0.5, 0, 1] + ] + }, + "over_lifetime_a": { + "kind": "CURVE", + "values": [ + [0, 1], + [1, 0] + ] + } + } + } } \ No newline at end of file diff --git a/entities/plants/fern/fern.json b/entities/plants/fern/fern.json index e237b1f..74a6d25 100644 --- a/entities/plants/fern/fern.json +++ b/entities/plants/fern/fern.json @@ -2,6 +2,10 @@ "type": "entity", "mixins": "file(fern_ghost.json)", "components": { + "swamp_goblins:mountain_grass": { + "radius": 8, + "block_type": "grass_hills_edge_2" + }, "model_variants": { "depleted": { "models": [ diff --git a/entities/plants/mushroom/mushroom.json b/entities/plants/mushroom/mushroom.json index 1b25bbc..ff44571 100644 --- a/entities/plants/mushroom/mushroom.json +++ b/entities/plants/mushroom/mushroom.json @@ -2,6 +2,10 @@ "type": "entity", "mixins": "file(mushroom_ghost.json)", "components": { + "swamp_goblins:mountain_grass": { + "radius": 8, + "block_type": "grass_hills_edge_2" + }, "model_variants": { "depleted": { "models": [ diff --git a/entities/plants/mushroom_medium/mushroom_medium.json b/entities/plants/mushroom_medium/mushroom_medium.json index 90f5afb..2b6924f 100644 --- a/entities/plants/mushroom_medium/mushroom_medium.json +++ b/entities/plants/mushroom_medium/mushroom_medium.json @@ -2,6 +2,10 @@ "type": "entity", "mixins": "file(mushroom_ghost.json)", "components": { + "swamp_goblins:mountain_grass": { + "radius": 6, + "block_type": "grass_hills_edge_2" + }, "model_variants": { "depleted": { "models": [ diff --git a/entities/plants/mushroom_small/mushroom_small.json b/entities/plants/mushroom_small/mushroom_small.json index 4d8f078..742e49e 100644 --- a/entities/plants/mushroom_small/mushroom_small.json +++ b/entities/plants/mushroom_small/mushroom_small.json @@ -2,6 +2,10 @@ "type": "entity", "mixins": "file(mushroom_ghost.json)", "components": { + "swamp_goblins:mountain_grass": { + "radius": 6, + "block_type": "grass_hills_edge_2" + }, "model_variants": { "depleted": { "models": [ diff --git a/entities/terrain/mountain_grass/mountain_grass.json b/entities/terrain/mountain_grass/mountain_grass.json new file mode 100644 index 0000000..5a02560 --- /dev/null +++ b/entities/terrain/mountain_grass/mountain_grass.json @@ -0,0 +1,15 @@ +{ + "type": "entity", + "mixins": "stonehearth:mixins:placed_object", + "components": { + "swamp_goblins:mountain_grass": { + "radius": 16, + "block_type": "grass_hills_edge_1", + "priority":1 + }, + "mob": { + "model_origin": { "x": 0, "y": 0, "z": 0 }, + "mob_collision_type": "clutter" + } + } +} \ No newline at end of file diff --git a/entities/trees/cypress/cypress.json b/entities/trees/cypress/cypress.json index 9f2a14d..c0f37c1 100644 --- a/entities/trees/cypress/cypress.json +++ b/entities/trees/cypress/cypress.json @@ -2,6 +2,10 @@ "mixins": "stonehearth:mixins:tree", "type": "entity", "components": { + "swamp_goblins:mountain_grass": { + "radius": 8, + "block_type": "grass_hills_edge_2" + }, "mob": { "model_origin": {"x": -0.5, "y": 0, "z": 0.5 }, "region_origin": {"x": 0.5, "y": 0, "z": 0.5 } diff --git a/jobs/shaman/recipes/plate_of_mushrooms_recipe.json b/jobs/shaman/recipes/plate_of_mushrooms_recipe.json index a73f426..cfb19dc 100644 --- a/jobs/shaman/recipes/plate_of_mushrooms_recipe.json +++ b/jobs/shaman/recipes/plate_of_mushrooms_recipe.json @@ -8,7 +8,7 @@ "workshop": "swamp_goblins:shaman:workbench", "ingredients": [ { - "uri": "swamp_goblins:food:white_mushroom", + "uri": "swamp_goblins:food:mushroom", "count": 1 } ], diff --git a/manifest.json b/manifest.json index 08efa5e..5b0fde4 100644 --- a/manifest.json +++ b/manifest.json @@ -103,6 +103,8 @@ "shaman:talisman": "file(jobs/shaman/shaman_staff/shaman_staff_talisman.json)", "shaman:workbench": "file(jobs/shaman/shaman_workbench)", + "terrain:mountain_grass":"file(entities/terrain/mountain_grass)", + "trees:bogger:small": "file(entities/trees/bogger)", "trees:swirl:small": "file(entities/trees/swirl)", "trees:swirl:medium": "file(entities/trees/swirl/swirl_medium.json)", @@ -138,7 +140,8 @@ "stonehearth:playable_kingdom_index": "file(data/playable_kingdom_index.json)" }, "components": { - "firefly":"file(components/firefly/firefly_component.lua)" + "firefly":"file(components/firefly/firefly_component.lua)", + "mountain_grass":"file(components/mountain_grass/mountain_grass_component.lua)" }, "controllers": { "class:spirit_walker": "file(jobs/spirit_walker/spirit_walker.lua)", diff --git a/services/server/swimming/custom_swimming_service.lua b/services/server/swimming/custom_swimming_service.lua index eb881dc..4a05300 100644 --- a/services/server/swimming/custom_swimming_service.lua +++ b/services/server/swimming/custom_swimming_service.lua @@ -10,10 +10,10 @@ function CustomSwimmingService:_is_swimming(entity) if self[fn] ~= nil then --found a function for the biome being used, named: -- self:_is_swimming_(args,...) - self[fn](self, entity) + return self[fn](self, entity) else --there is no function for this specific biome, so call a copy of the original from stonehearth - self:_is_swimming_original(entity) + return self:_is_swimming_original(entity) end end diff --git a/services/server/world_generation/custom_biome.lua b/services/server/world_generation/custom_biome.lua index da5ca6c..3600678 100644 --- a/services/server/world_generation/custom_biome.lua +++ b/services/server/world_generation/custom_biome.lua @@ -1,13 +1,91 @@ local CustomBiome = class() +function CustomBiome:_generate_terrain_info(json) + local biome_name = stonehearth.world_generation:get_biome_alias() + local colon_position = string.find (biome_name, ":", 1, true) or -1 + local mod_name_containing_the_biome = string.sub (biome_name, 1, colon_position-1) + local fn = "_generate_terrain_info_" .. mod_name_containing_the_biome + if self[fn] ~= nil then + --found a function for the biome being used, named: + -- self:_add_soil_strata_to_region_(args,...) + return self[fn](self, json) + else + --there is no function for this specific biome, so call a copy of the original from stonehearth + return self:_generate_terrain_info_original(json) + end +end + +function CustomBiome:_generate_terrain_info_original(json) + -- yikes, should really clone this first + local terrain_info = json.terrain + local slice_size = self._slice_size + + assert(terrain_info.foothills.step_size % slice_size == 0) + assert(terrain_info.mountains.step_size % slice_size == 0) + + -- compute terrain elevations + local prev_terrain_type + for i, terrain_type in ipairs(self._terrain_types) do + local base + if terrain_type == 'plains' then + base = terrain_info.height_base + else + base = terrain_info[prev_terrain_type].height_max + end + terrain_info[terrain_type].height_base = base + terrain_info[terrain_type].height_max = base + terrain_info[terrain_type].step_size * terrain_info[terrain_type].step_count + prev_terrain_type = terrain_type + end + + terrain_info.plains.height_valley = terrain_info.height_base + terrain_info.plains.valley_count * terrain_info.plains.step_size + assert(terrain_info.plains.height_max % slice_size == 0) + terrain_info.height_min = terrain_info.plains.height_valley + terrain_info.height_max = terrain_info.mountains.height_max + + return terrain_info +end + +function CustomBiome:_generate_terrain_info_swamp_goblins(json) + -- yikes, should really clone this first + local terrain_info = json.terrain + local slice_size = self._slice_size + + -- assert(terrain_info.foothills.step_size % slice_size == 0) + assert(terrain_info.mountains.step_size % slice_size == 0) + + -- compute terrain elevations + local prev_terrain_type + for i, terrain_type in ipairs(self._terrain_types) do + local base + if terrain_type == 'plains' then + base = terrain_info.height_base + else + base = terrain_info[prev_terrain_type].height_max + end + terrain_info[terrain_type].height_base = base + terrain_info[terrain_type].height_max = base + terrain_info[terrain_type].step_size * terrain_info[terrain_type].step_count + prev_terrain_type = terrain_type + end + + terrain_info.plains.height_valley = terrain_info.height_base + terrain_info.plains.valley_count * terrain_info.plains.step_size + assert(terrain_info.plains.height_max % slice_size == 0) + terrain_info.height_min = terrain_info.plains.height_valley + terrain_info.height_max = terrain_info.mountains.height_max + + return terrain_info +end + function CustomBiome:_generate_color_map() - local mod_name = stonehearth.world_generation:get_biome_alias() - --mod_name is the mod that has the current biome - local colon_pos = string.find (mod_name, ":", 1, true) or -1 - mod_name = "_generate_color_map_" .. string.sub (mod_name, 1, colon_pos-1) - if self[mod_name]~=nil then - self[mod_name](self) + local biome_name = stonehearth.world_generation:get_biome_alias() + local colon_position = string.find (biome_name, ":", 1, true) or -1 + local mod_name_containing_the_biome = string.sub (biome_name, 1, colon_position-1) + local fn = "_generate_color_map_" .. mod_name_containing_the_biome + if self[fn] ~= nil then + --found a function for the biome being used, named: + -- self:_add_soil_strata_to_region_(args,...) + self[fn](self) else + --there is no function for this specific biome, so call a copy of the original from stonehearth self:_generate_color_map_original() end end diff --git a/services/server/world_generation/custom_height_map_renderer.lua b/services/server/world_generation/custom_height_map_renderer.lua index d6d3036..9c9f53e 100644 --- a/services/server/world_generation/custom_height_map_renderer.lua +++ b/services/server/world_generation/custom_height_map_renderer.lua @@ -107,7 +107,7 @@ function CustomHeightMapRenderer:_add_mountains_to_region_swamp_goblins(region3, block_min = 0 - local max_foothills_height = 35 + local max_foothills_height = 33 --hardcoded value for i=1, num_rock_layers do if (i == num_rock_layers) or (height <= rock_layers[i].max_height) then @@ -117,7 +117,7 @@ function CustomHeightMapRenderer:_add_mountains_to_region_swamp_goblins(region3, block_max = rock_layers[i].max_height end - local has_grass = stop and block_max > max_foothills_height and block_max <60 + local has_grass = stop and block_max > max_foothills_height and block_max <58 --hardcoded value local rock_top = has_grass and block_max-1 or block_max if has_grass then diff --git a/swamp_goblins_client.lua b/swamp_goblins_client.lua index 05b321e..c2f6367 100644 --- a/swamp_goblins_client.lua +++ b/swamp_goblins_client.lua @@ -6,7 +6,7 @@ local player_service_trace = nil local function check_override_ui(players, player_id) -- Load ui mod if not player_id then - player_id = 'player_1' -- TODO(Yshan) client should know what player id it is + player_id = _radiant.client.get_player_id() end local client_player = players[player_id] @@ -31,7 +31,9 @@ local function trace_player_service() end radiant.events.listen(swamp_goblins, 'radiant:init', function() - trace_player_service() + radiant.events.listen(radiant, 'radiant:client:server_ready', function() + trace_player_service() + end) end) return swamp_goblins