From 613201b0594e27df46733afa9e7b9d8a6e83c723 Mon Sep 17 00:00:00 2001 From: MewMew <=> Date: Thu, 6 Dec 2018 23:11:16 +0100 Subject: [PATCH] Hunger Module with respawning Fish --- control.lua | 3 +- maps/labyrinth.lua | 29 ++++++++++++++++--- maps/labyrinth_changelog.txt | 1 + maps/tools/hunger.lua | 55 ++++++++++++++++++++++++++++++++---- 4 files changed, 78 insertions(+), 10 deletions(-) diff --git a/control.lua b/control.lua index cf3b3127..75e6e30f 100644 --- a/control.lua +++ b/control.lua @@ -10,13 +10,14 @@ require "poll" require "score" require "maps.tools.cheat_mode" +require "maps.tools.hunger" ---- enable maps here ---- --require "maps.biter_battles" --require "maps.cave_miner" --require "maps.deep_jungle" --require "maps.lost_desert" -require "maps.labyrinth" +--require "maps.labyrinth" --require "maps.spaghettorio" --require "maps.spiral_troopers" --require "maps.fish_defender" diff --git a/maps/labyrinth.lua b/maps/labyrinth.lua index 977ce975..e645a736 100644 --- a/maps/labyrinth.lua +++ b/maps/labyrinth.lua @@ -10,6 +10,17 @@ local unique_rooms = require "maps.labyrinth_unique_rooms" local labyrinth_difficulty_curve = 400 --- How much size the labyrinth needs to have the highest difficulty. +local threat_values = { + ["small-biter"] = 1, + ["medium-biter"] = 3, + ["big-biter"] = 5, + ["behemoth-biter"] = 10, + ["small-spitter"] = 1, + ["medium-spitter"] = 3, + ["big-spitter"] = 5, + ["behemoth-spitter"] = 10 +} + local function create_labyrinth_difficulty_gui(player) if player.gui.top["labyrinth_difficulty"] then player.gui.top["labyrinth_difficulty"].destroy() end if not global.labyrinth_size then return end @@ -101,7 +112,7 @@ worm_raffle[7] = {"medium-worm-turret", "medium-worm-turret", "medium-worm-turre worm_raffle[8] = {"medium-worm-turret", "medium-worm-turret", "medium-worm-turret", "medium-worm-turret", "big-worm-turret", "big-worm-turret"} worm_raffle[9] = {"medium-worm-turret", "medium-worm-turret", "medium-worm-turret", "big-worm-turret", "big-worm-turret", "big-worm-turret"} worm_raffle[10] = {"medium-worm-turret", "medium-worm-turret", "medium-worm-turret", "big-worm-turret", "big-worm-turret", "big-worm-turret"} -local rock_weights = {{"sand-rock-big", 8}, {"rock-big", 32}, {"rock-huge", 1}} +local rock_weights = {{"sand-rock-big", 9}, {"rock-big", 32}, {"rock-huge", 1}} local rock_raffle = {} for _, t in pairs (rock_weights) do for x = 1, t[2], 1 do @@ -438,17 +449,27 @@ local function grow_cell(chunk_position, surface) if surface.can_place_entity({name = n, position = p}) then surface.create_entity {name = n, position = p} end end + local threat_amount = global.labyrinth_size * 4 + for _, p in pairs(entities_to_place.biters) do local evolution = math.ceil(game.forces.enemy.evolution_factor * 10, 0) local raffle = biter_raffle[evolution] - local n = raffle[math.random(1,#raffle)] + local n = raffle[math.random(1,#raffle)] + if threat_values[n] then + threat_amount = threat_amount - threat_values[n] + if threat_amount < 0 then break end + end if surface.can_place_entity({name = n, position = p}) then surface.create_entity {name = n, position = p} end end for _, p in pairs(entities_to_place.spitters) do local evolution = math.ceil(game.forces.enemy.evolution_factor * 10, 0) local raffle = spitter_raffle[evolution] - local n = raffle[math.random(1,#raffle)] + local n = raffle[math.random(1,#raffle)] + if threat_values[n] then + threat_amount = threat_amount - threat_values[n] + if threat_amount < 0 then break end + end if surface.can_place_entity({name = n, position = p}) then surface.create_entity {name = n, position = p} end end @@ -731,7 +752,7 @@ local function on_entity_died(event) local amount_modifier = math.ceil(1 + game.forces.enemy.evolution_factor * 5) if n == "crude-oil" then - map_functions.draw_oil_circle(pos, n, surface, 10, 100000 * amount_modifier) + map_functions.draw_oil_circle(pos, n, surface, 6, 100000 * amount_modifier) else map_functions.draw_smoothed_out_ore_circle(pos, n, surface, 9 + amount_modifier, 200 * amount_modifier) end diff --git a/maps/labyrinth_changelog.txt b/maps/labyrinth_changelog.txt index 7bf543ad..7dc2df97 100644 --- a/maps/labyrinth_changelog.txt +++ b/maps/labyrinth_changelog.txt @@ -1,4 +1,5 @@ 0.03 +biters will spawn weighted drops from enemies will stop more soon infinity chests have been nerfed more ore patches diff --git a/maps/tools/hunger.lua b/maps/tools/hunger.lua index 4076b0a6..e6ecf0ff 100644 --- a/maps/tools/hunger.lua +++ b/maps/tools/hunger.lua @@ -1,5 +1,9 @@ -- hunger module by mewmew -- +local event = require 'utils.event' +local math_random = math.random + +local respawn_fish = true local player_hunger_fish_food_value = 10 local player_hunger_spawn_value = 80 local player_hunger_stages = {} @@ -52,8 +56,7 @@ local function create_hunger_gui(player) caption_hunger.style.top_padding = 2 end -local function hunger_update(player, food_value) - +local function hunger_update(player, food_value) if food_value == -1 and player.character.driving == true then return end local past_hunger = global.player_hunger[player.name] @@ -62,13 +65,14 @@ local function hunger_update(player, food_value) if past_hunger == 200 and global.player_hunger[player.name] + food_value > 200 then global.player_hunger[player.name] = player_hunger_spawn_value + player.surface.create_entity({name = "big-artillery-explosion", position = player.character.position}) player.character.die("player") - local t = {" ate too much and exploded.", " should have gone on a diet.", " needs to work on their bad eating habbits.", " should have skipped dinner today."} + local t = {" ate too much and exploded.", " needs to work on their bad eating habbits.", " should have skipped dinner today."} game.print(player.name .. t[math.random(1,#t)], { r=0.75, g=0.0, b=0.0}) end if global.player_hunger[player.name] < 1 then - global.player_hunger[player.name] = player_hunger_spawn_value + global.player_hunger[player.name] = player_hunger_spawn_value player.character.die("player") local t = {" ran out of foodstamps.", " starved.", " should not have skipped breakfast today."} game.print(player.name .. t[math.random(1,#t)], { r=0.75, g=0.0, b=0.0}) @@ -89,6 +93,24 @@ local function hunger_update(player, food_value) player.character.character_running_speed_modifier = player_hunger_buff[global.player_hunger[player.name]] * 0.5 player.character.character_mining_speed_modifier = player_hunger_buff[global.player_hunger[player.name]] + + create_hunger_gui(player) +end + +local function respawn_fishes() + for _, surface in pairs(game.surfaces) do + local water_tiles = surface.find_tiles_filtered({name = {"water", "deepwater", "water-green"}}) + for _, tile in pairs(water_tiles) do + local area_entities = {{tile.position.x - 2, tile.position.y - 2},{tile.position.x + 2, tile.position.y + 2}} + local area_tiles = {{tile.position.x - 1, tile.position.y - 1},{tile.position.x + 1, tile.position.y + 1}} + + if surface.count_entities_filtered({area = area_entities, name = "fish"}) == 0 and surface.count_tiles_filtered({area = area_tiles, name = {"water", "deepwater", "water-green"}}) > 3 then + if math_random(1, 32) == 1 then + surface.create_entity({name = "fish", position = tile.position}) + end + end + end + end end local function on_player_joined_game(event) @@ -99,4 +121,27 @@ local function on_player_joined_game(event) hunger_update(player, 0) end create_hunger_gui(player) -end \ No newline at end of file +end + +local function on_player_used_capsule(event) + if event.item.name == "raw-fish" then + local player = game.players[event.player_index] + hunger_update(player, player_hunger_fish_food_value) + player.play_sound{path="utility/armor_insert", volume_modifier=0.75} + end +end + +local function on_tick(event) + if game.tick % 5400 == 2700 then + for _, player in pairs(game.connected_players) do + if player.afk_time < 18000 then hunger_update(player, -1) end + end + if respawn_fish then + respawn_fishes() + end + end +end + +event.add(defines.events.on_tick, on_tick) +event.add(defines.events.on_player_used_capsule, on_player_used_capsule) +event.add(defines.events.on_player_joined_game, on_player_joined_game) \ No newline at end of file