From 15b7ae4c36a861a9de5ff937d56ade5288980e21 Mon Sep 17 00:00:00 2001 From: MewMew <=> Date: Thu, 6 Dec 2018 20:08:56 +0100 Subject: [PATCH] updates --- control.lua | 4 +- maps/biter_battles.lua | 12 ++- maps/fish_defender.lua | 164 ++++++++++++++++++++++--------- maps/fish_defender_changelog.txt | 3 + maps/labyrinth.lua | 49 ++++----- maps/labyrinth_changelog.txt | 5 + maps/spooky_forest.lua | 10 +- maps/tools/hunger.lua | 102 +++++++++++++++++++ 8 files changed, 272 insertions(+), 77 deletions(-) create mode 100644 maps/tools/hunger.lua diff --git a/control.lua b/control.lua index a1071c7d..cf3b3127 100644 --- a/control.lua +++ b/control.lua @@ -16,10 +16,10 @@ require "maps.tools.cheat_mode" --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" +--require "maps.fish_defender" --require "maps.crossing" --require "maps.spooky_forest" --require "maps.empty_map" diff --git a/maps/biter_battles.lua b/maps/biter_battles.lua index c7a4e72d..907d1d49 100644 --- a/maps/biter_battles.lua +++ b/maps/biter_battles.lua @@ -791,8 +791,16 @@ end local function on_entity_died(event) if not global.rocket_silo_destroyed then - if event.entity == global.rocket_silo["south"] or event.entity == global.rocket_silo["north"] then - if event.entity == global.rocket_silo["south"] then global.rocket_silo_destroyed = "North Team Won!" else global.rocket_silo_destroyed = "South Team Won!" end + if event.entity == global.rocket_silo["south"] or event.entity == global.rocket_silo["north"] then + + if event.entity == global.rocket_silo["south"] then + global.rocket_silo_destroyed = "North Team Won!" + print("team$north" + else + global.rocket_silo_destroyed = "South Team Won!" + print("team$south" + end + for _, player in pairs(game.connected_players) do player.play_sound{path="utility/game_won", volume_modifier=1} end diff --git a/maps/fish_defender.lua b/maps/fish_defender.lua index 439091f4..915031c5 100644 --- a/maps/fish_defender.lua +++ b/maps/fish_defender.lua @@ -12,12 +12,14 @@ local boss_waves = { [50] = {{name = "big-biter", count = 3}}, [100] = {{name = "behemoth-biter", count = 1}}, [150] = {{name = "behemoth-spitter", count = 4}, {name = "big-spitter", count = 16}}, - [200] = {{name = "behemoth-biter", count = 4}, {name = "behemoth-spitter", count = 2}}, - [250] = {{name = "behemoth-biter", count = 8}, {name = "behemoth-spitter", count = 4}}, - [300] = {{name = "behemoth-biter", count = 12}, {name = "behemoth-spitter", count = 6}}, - [350] = {{name = "behemoth-biter", count = 16}, {name = "behemoth-spitter", count = 8}}, - [400] = {{name = "behemoth-biter", count = 20}, {name = "behemoth-spitter", count = 10}}, - [450] = {{name = "behemoth-biter", count = 24}, {name = "behemoth-spitter", count = 12}} + [200] = {{name = "behemoth-biter", count = 4}, {name = "behemoth-spitter", count = 2}, {name = "big-biter", count = 32}}, + [250] = {{name = "behemoth-biter", count = 8}, {name = "behemoth-spitter", count = 4}, {name = "big-spitter", count = 32}}, + [300] = {{name = "behemoth-biter", count = 16}, {name = "behemoth-spitter", count = 8}}, + [350] = {{name = "behemoth-biter", count = 24}, {name = "behemoth-spitter", count = 12}}, + [400] = {{name = "behemoth-biter", count = 32}, {name = "behemoth-spitter", count = 16}}, + [450] = {{name = "behemoth-biter", count = 40}, {name = "behemoth-spitter", count = 20}}, + [500] = {{name = "behemoth-biter", count = 48}, {name = "behemoth-spitter", count = 24}}, + [550] = {{name = "behemoth-biter", count = 56}, {name = "behemoth-spitter", count = 28}} } local function shuffle(tbl) @@ -243,17 +245,63 @@ end local function clear_corpses(surface) local area = {{x = -256, y = -256}, {x = 256, y = 256}} for _, entity in pairs(surface.find_entities_filtered{area = area, type = "corpse"}) do - if math_random(1,2) == 1 then + if math_random(1, 3) == 1 then entity.destroy() end end end +local boss_wave_names = { + [50] = "The Big Biter Gang", + [100] = "Biterzilla", + [150] = "The Spitter Squad", + [200] = "Wall Nibblers", + [250] = "Conveyor Munchers", + [350] = "Cable Chewers", + [400] = "Turret Devourers", + [450] = "Assembler Annihilators", + [500] = "Inserter Crunchers", + [550] = "Engineer Eaters", + [600] = "Belt Unbalancers", + [650] = "Power Pole Thieves", + [700] = "Pipe Perforators", + [750] = "Desync Bros", + [800] = "Ratio Randomizers", + [850] = "Wire Chompers", + [900] = "The Bus Mixers", + [950] = "Roundabout Deadlockers", + [1000] = "Happy Tree Friends", + [1050] = "Uranium Digesters", + [1100] = "Bot Banishers", + [1150] = "Furnace Freezers", + [1200] = "Cargo Wagon Scratchers", + [1250] = "Transport Belt Surfers", + [1300] = "Pumpjack Pulverizers", + [1350] = "Radar Ravagers", + [1400] = "Mall Deconstrutors", + [1450] = "Lamp Dimmers", + [1500] = "Roboport Disablers", + [1550] = "Chest Crushers", + [1600] = "Brick Tramplers", + [1650] = "Drill Destroyers", + [1700] = "Gearwheel Grinders", + [1750] = "Silo Seekers", + [1800] = "Circuit Breakers", + [1850] = "Bullet Absorbers", + [1900] = "Oil Guzzlers", + [1950] = "Signal Spammers", + [2000] = "Bluescreen Factor" +} + local function spawn_boss_units(surface) - if not boss_waves[global.wave_count] then return end - if global.wave_count == 50 then game.print("The Big Biter Gang", {r = 0.7, g = 0.1, b = 0.1}) end - if global.wave_count == 100 then game.print("Biterzilla", {r = 0.7, g = 0.1, b = 0.1}) end - if global.wave_count == 150 then game.print("The Spitter Squad", {r = 0.7, g = 0.1, b = 0.1}) end + if boss_wave_names[global.wave_count] then + game.print("Boss Wave " .. global.wave_count .. " - - " .. boss_wave_names[global.wave_count], {r = 0.8, g = 0.1, b = 0.1}) + else + game.print("Boss Wave " .. global.wave_count, {r = 0.8, g = 0.1, b = 0.1}) + end + + if not boss_waves[global.wave_count] then return end + local position = {x = 216, y = 0} local biter_group = surface.create_unit_group({position = position}) for _, entry in pairs(boss_waves[global.wave_count]) do @@ -354,8 +402,7 @@ local function biter_attack_wave() global.wave_count = global.wave_count + 1 end - if global.wave_count % 50 == 0 then - game.print("Boss Wave " .. global.wave_count, {r = 0.7, g = 0.1, b = 0.1}) + if global.wave_count % 50 == 0 then global.attack_wave_threat = global.wave_count * 10 spawn_boss_units(surface) else @@ -515,7 +562,7 @@ local function refresh_market_offers() {price = {{"coin", 125}}, offer = {type = 'give-item', item = 'rocket-launcher', count = 1}}, {price = {{"coin", 2}}, offer = {type = 'give-item', item = 'rocket', count = 1}}, {price = {{"coin", 7}}, offer = {type = 'give-item', item = 'explosive-rocket', count = 1}}, - {price = {{"coin", 5000}}, offer = {type = 'give-item', item = 'atomic-bomb', count = 1}}, + {price = {{"coin", 7500}}, offer = {type = 'give-item', item = 'atomic-bomb', count = 1}}, {price = {{"coin", 90}}, offer = {type = 'give-item', item = 'railgun', count = 1}}, {price = {{"coin", 5}}, offer = {type = 'give-item', item = 'railgun-dart', count = 1}}, {price = {{"coin", 40}}, offer = {type = 'give-item', item = 'poison-capsule', count = 1}}, @@ -761,20 +808,28 @@ local function on_entity_died(event) end if event.entity.name == "behemoth-biter" then - local spawn_entity = false - if global.endgame_modifier then - if global.endgame_modifier > 500 then - spawn_entity = "big-worm-turret" - else - spawn_entity = "medium-worm-turret" - end - end - - if spawn_entity then - local surface = event.entity.surface - if surface.count_entities_filtered({area = {{event.entity.position.x - 5, event.entity.position.y - 5},{event.entity.position.x + 5, event.entity.position.y + 5}}, name = spawn_entity}) == 0 then - surface.create_entity({name = "blood-explosion-huge", position = event.entity.position}) - surface.create_entity({name = spawn_entity, position = event.entity.position}) + local surface = event.entity.surface + + if math_random(1, 2) ~= 1 then + local count = math_random(2, 4) + for i = 1, count, 1 do + local p = surface.find_non_colliding_position("medium-biter", event.entity.position, 3, 0.5) + if p then surface.create_entity {name = "medium-biter", position = p} end + end + else + local spawn_entity = false + if global.endgame_modifier then + if global.endgame_modifier > 500 then + spawn_entity = "big-worm-turret" + else + spawn_entity = "medium-worm-turret" + end + end + if spawn_entity then + if surface.count_entities_filtered({area = {{event.entity.position.x - 5, event.entity.position.y - 5},{event.entity.position.x + 5, event.entity.position.y + 5}}, name = spawn_entity}) == 0 then + surface.create_entity({name = "blood-explosion-huge", position = event.entity.position}) + surface.create_entity({name = spawn_entity, position = event.entity.position}) + end end end end @@ -861,8 +916,7 @@ local function on_player_joined_game(event) game.map_settings.enemy_evolution.destroy_factor = 0 game.map_settings.enemy_evolution.time_factor = 0 game.map_settings.enemy_evolution.pollution_factor = 0 - - --game.forces["player"].set_turret_attack_modifier("flamethrower-turret", -0.5) + game.forces["player"].technologies["flamethrower-damage-1"].enabled = false game.forces["player"].technologies["flamethrower-damage-2"].enabled = false game.forces["player"].technologies["flamethrower-damage-3"].enabled = false @@ -870,23 +924,25 @@ local function on_player_joined_game(event) game.forces["player"].technologies["flamethrower-damage-5"].enabled = false game.forces["player"].technologies["flamethrower-damage-6"].enabled = false game.forces["player"].technologies["flamethrower-damage-7"].enabled = false - game.forces["player"].technologies["gun-turret-damage-1"].enabled = false - game.forces["player"].technologies["gun-turret-damage-2"].enabled = false - game.forces["player"].technologies["gun-turret-damage-3"].enabled = false - game.forces["player"].technologies["gun-turret-damage-4"].enabled = false - game.forces["player"].technologies["gun-turret-damage-5"].enabled = false - game.forces["player"].technologies["gun-turret-damage-6"].enabled = false - game.forces["player"].technologies["gun-turret-damage-7"].enabled = false - game.forces["player"].technologies["laser-turret-speed-6"].enabled = false - game.forces["player"].technologies["laser-turret-speed-7"].enabled = false + --game.forces["player"].technologies["gun-turret-damage-1"].enabled = false + --game.forces["player"].technologies["gun-turret-damage-2"].enabled = false + --game.forces["player"].technologies["gun-turret-damage-3"].enabled = false + --game.forces["player"].technologies["gun-turret-damage-4"].enabled = false + --game.forces["player"].technologies["gun-turret-damage-5"].enabled = false + --game.forces["player"].technologies["gun-turret-damage-6"].enabled = false + --game.forces["player"].technologies["gun-turret-damage-7"].enabled = false + --game.forces["player"].technologies["laser-turret-speed-6"].enabled = false + --game.forces["player"].technologies["laser-turret-speed-7"].enabled = false + --game.forces["player"].technologies["atomic-bomb"].enabled = false game.forces.player.set_ammo_damage_modifier("shotgun-shell", 0.5) + game.forces.player.set_turret_attack_modifier("flamethrower-turret", -0.5) global.entity_limits = { ["gun-turret"] = {placed = 1, limit = 1, str = "gun turret", slot_price = 100}, ["laser-turret"] = {placed = 0, limit = 1, str = "laser turret", slot_price = 300}, ["artillery-turret"] = {placed = 0, limit = 1, str = "artillery turret", slot_price = 500}, - ["flamethrower-turret"] = {placed = 0, limit = 0, str = "flamethrower turret", slot_price = 35000}, + ["flamethrower-turret"] = {placed = 0, limit = 0, str = "flamethrower turret", slot_price = 15000}, ["land-mine"] = {placed = 0, limit = 1, str = "mine", slot_price = 1} } @@ -949,7 +1005,13 @@ local function on_chunk_generated(event) entity.destroy() end - if left_top.x >= 160 then + if left_top.x <= -196 then + + local search_area = {{left_top.x - 32, left_top.y - 32}, {left_top.x + 32, left_top.y + 32}} + if surface.count_tiles_filtered({name = "water", area = search_area}) == 0 and math_random(1,22) == 1 then + map_functions.draw_noise_tile_circle({x = left_top.x + math_random(1,30), y = left_top.y + math_random(1,30)}, "water", surface, math_random(6, 12)) + end + if not global.spawn_ores_generated then local spawn_position_x = -76 @@ -1012,7 +1074,7 @@ local function on_chunk_generated(event) local area = {{x = -160, y = -96}, {x = 160, y = 96}} for _, tile in pairs(surface.find_tiles_filtered({name = "water", area = area})) do - if math_random(1,16) == 1 then + if math_random(1, 32) == 1 then surface.create_entity({name = "fish", position = tile.position}) end end @@ -1055,7 +1117,13 @@ local function on_chunk_generated(event) surface.set_tiles(tiles, false) - + for _, tile in pairs(surface.find_tiles_filtered({name = "water", area = event.area})) do + if math_random(1, 32) == 1 then + surface.create_entity({name = "fish", position = tile.position}) + end + end + + if left_top.x < 160 then return end local entities = surface.find_entities_filtered({area = area, type = "tree"}) @@ -1091,13 +1159,13 @@ local function on_chunk_generated(event) if pos.x > 296 and pos.x < 312 and math_random(1, 128) == 1 then if surface.can_place_entity({name = "biter-spawner", force = "enemy", position = pos}) then if math_random(1,4) == 1 then - local entity = surface.create_entity({name = "spitter-spawner", force = "player", position = pos}) + local entity = surface.create_entity({name = "spitter-spawner", force = "enemy", position = pos}) entity.active = false - entity.destructible = false + --entity.destructible = false else - local entity = surface.create_entity({name = "biter-spawner", force = "player", position = pos}) + local entity = surface.create_entity({name = "biter-spawner", force = "enemy", position = pos}) entity.active = false - entity.destructible = false + --entity.destructible = false end end end @@ -1113,6 +1181,8 @@ local function on_chunk_generated(event) end end surface.regenerate_decorative(decorative_names, {{x=math.floor(event.area.left_top.x/32),y=math.floor(event.area.left_top.y/32)}}) + + end local function on_built_entity(event) diff --git a/maps/fish_defender_changelog.txt b/maps/fish_defender_changelog.txt index bb8e151c..3229bb1c 100644 --- a/maps/fish_defender_changelog.txt +++ b/maps/fish_defender_changelog.txt @@ -1,3 +1,6 @@ +0.19 +added water ponds to the west + 0.18 artillery tech is no longer available from start researching tanks will grant the artillery tech early diff --git a/maps/labyrinth.lua b/maps/labyrinth.lua index 5f5e259f..977ce975 100644 --- a/maps/labyrinth.lua +++ b/maps/labyrinth.lua @@ -101,7 +101,13 @@ 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_raffle = {"sand-rock-big","sand-rock-big", "rock-big","rock-big","rock-big","rock-big","rock-big","rock-big","rock-big","rock-big","rock-big","rock-big","rock-big","rock-big","rock-big","rock-huge"} +local rock_weights = {{"sand-rock-big", 8}, {"rock-big", 32}, {"rock-huge", 1}} +local rock_raffle = {} +for _, t in pairs (rock_weights) do + for x = 1, t[2], 1 do + table.insert(rock_raffle, t[1]) + end +end local ore_spawn_raffle = {"iron-ore","iron-ore","iron-ore","iron-ore","iron-ore","copper-ore","copper-ore","copper-ore","coal","coal","stone","stone","uranium-ore","crude-oil"} local room_layouts = {"quad_rocks", "single_center_rock", "three_horizontal_rocks", "three_vertical_rocks", "tree_and_lake", "forest", "forest_fence"} local biter_raffle = { @@ -633,20 +639,14 @@ local function spawn_infinity_chest(pos, surface) local math_random = math.random local infinity_chests = { {"raw-wood", math_random(1,3)}, - {"coal", 1}, - {"coal", 1}, - {"stone", math_random(1,3)}, - {"stone", math_random(1,3)}, - {"iron-ore", 1}, - {"iron-ore", 1}, - {"iron-ore", 1}, - {"copper-ore", 1}, - {"copper-ore", 1}, - {"iron-plate", 1}, - {"copper-plate", 1}, - {"stone-brick", 1}, - {"iron-gear-wheel", 1}, - {"copper-cable", math_random(1,4)} + {"coal", 1}, + {"stone", math_random(2,4)}, + {"stone", math_random(2,4)}, + {"stone", math_random(2,4)}, + {"stone", math_random(2,4)}, + {"stone", math_random(2,4)}, + {"iron-ore", 1}, + {"copper-ore", 1}, } local x = math_random(1, #infinity_chests) local e = surface.create_entity {name = "infinity-chest", position = pos, force = "player"} @@ -684,8 +684,8 @@ local entity_drop_amount = { ['biter-spawner'] = {low = 50, high = 100}, ['spitter-spawner'] = {low = 50, high = 100} } -local ore_spill_raffle = {"iron-ore","iron-ore","iron-ore","iron-ore","iron-ore","copper-ore","copper-ore","copper-ore","coal","coal","stone","uranium-ore", "landfill", "landfill", "landfill"} -local ore_spawn_raffle = {"iron-ore","iron-ore","iron-ore","iron-ore","copper-ore","copper-ore","copper-ore","coal","coal","stone","uranium-ore","crude-oil","crude-oil"} +local ore_spill_raffle = {"iron-ore","iron-ore","iron-ore","copper-ore","copper-ore","coal","coal","stone", "landfill"} +local ore_spawn_raffle = {"iron-ore","iron-ore","iron-ore","iron-ore","copper-ore","copper-ore","copper-ore","coal","coal","stone","uranium-ore","crude-oil"} local function on_entity_died(event) for _, fragment in pairs(biter_fragmentation) do @@ -711,8 +711,11 @@ local function on_entity_died(event) if entity_drop_amount[event.entity.name] then if game.forces.enemy.evolution_factor < 0.5 then - local amount = math.ceil(math.random(entity_drop_amount[event.entity.name].low, entity_drop_amount[event.entity.name].high) * (0.5 - game.forces.enemy.evolution_factor) * 2, 0) - event.entity.surface.spill_item_stack(event.entity.position,{name = ore_spill_raffle[math.random(1,#ore_spill_raffle)], count = amount},true) + local evolution_drop_modifier = (0.1 - game.forces.enemy.evolution_factor) * 10 + if evolution_drop_modifier > 0 then + local amount = math.ceil(math.random(entity_drop_amount[event.entity.name].low, entity_drop_amount[event.entity.name].high) * evolution_drop_modifier) + event.entity.surface.spill_item_stack(event.entity.position,{name = ore_spill_raffle[math.random(1,#ore_spill_raffle)], count = amount},true) + end end return end @@ -724,11 +727,13 @@ local function on_entity_died(event) if event.entity.name == "rock-big" then treasure_chest(pos, surface) end if event.entity.name == "sand-rock-big" then local n = ore_spawn_raffle[math.random(1,#ore_spawn_raffle)] - local amount_modifier = 1 + ((global.labyrinth_size / labyrinth_difficulty_curve) * 10) + --local amount_modifier = 1 + ((global.labyrinth_size / labyrinth_difficulty_curve) * 10) + 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) else - map_functions.draw_smoothed_out_ore_circle(pos, n, surface, 10, 750 * amount_modifier) + map_functions.draw_smoothed_out_ore_circle(pos, n, surface, 9 + amount_modifier, 200 * amount_modifier) end end event.entity.destroy() @@ -1037,7 +1042,7 @@ local attack_messages = { local function on_tick(event) if game.tick % 4600 == 0 then - if math.random(1, 4) ~= 1 then return end + if math.random(1, 6) ~= 1 then return end local surface = game.surfaces["labyrinth"] local area = {{-10000, -10000}, {10000, 0}} local biters = surface.find_entities_filtered({type = "unit", force = "enemy", area = area}) diff --git a/maps/labyrinth_changelog.txt b/maps/labyrinth_changelog.txt index 5aee8f16..7bf543ad 100644 --- a/maps/labyrinth_changelog.txt +++ b/maps/labyrinth_changelog.txt @@ -1,3 +1,8 @@ +0.03 +drops from enemies will stop more soon +infinity chests have been nerfed +more ore patches + 0.02 anti-turret creep things diff --git a/maps/spooky_forest.lua b/maps/spooky_forest.lua index 53d7f98f..a7ba438f 100644 --- a/maps/spooky_forest.lua +++ b/maps/spooky_forest.lua @@ -286,18 +286,19 @@ local function on_entity_died(event) if p then surface.create_entity {name=t[1], position=p} end end end - if math_random(1, 4) == 1 then + --if math_random(1, 4) == 1 then local name = ore_spawn_raffle[math.random(1,#ore_spawn_raffle)] local pos = {x = event.entity.position.x, y = event.entity.position.y} - local amount_modifier = 1 + game.forces.enemy.evolution_factor * 10 + local amount_modifier = 1 + game.forces.enemy.evolution_factor * 15 if name == "crude-oil" then map_functions.draw_oil_circle(pos, name, surface, 5, math.ceil(100000 * amount_modifier)) else - map_functions.draw_smoothed_out_ore_circle(pos, name, surface, 7, math.ceil(600 * amount_modifier)) + map_functions.draw_smoothed_out_ore_circle(pos, name, surface, 5, math.ceil(500 * amount_modifier)) end - end + --end end + --[[ if entity_drop_amount[event.entity.name] then if game.forces.enemy.evolution_factor < 0.5 then local amount = math.ceil(math.random(entity_drop_amount[event.entity.name].low, entity_drop_amount[event.entity.name].high)) @@ -305,6 +306,7 @@ local function on_entity_died(event) end return end + ]] if event.entity.type == "tree" then --if math_random(1, 2) == 1 then return end diff --git a/maps/tools/hunger.lua b/maps/tools/hunger.lua new file mode 100644 index 00000000..4076b0a6 --- /dev/null +++ b/maps/tools/hunger.lua @@ -0,0 +1,102 @@ +-- hunger module by mewmew -- + +local player_hunger_fish_food_value = 10 +local player_hunger_spawn_value = 80 +local player_hunger_stages = {} +for x = 1, 200, 1 do + if x <= 200 then player_hunger_stages[x] = "Obese" end + if x <= 179 then player_hunger_stages[x] = "Stuffed" end + if x <= 150 then player_hunger_stages[x] = "Bloated" end + if x <= 130 then player_hunger_stages[x] = "Sated" end + if x <= 110 then player_hunger_stages[x] = "Well Fed" end + if x <= 89 then player_hunger_stages[x] = "Nourished" end + if x <= 70 then player_hunger_stages[x] = "Hungry" end + if x <= 35 then player_hunger_stages[x] = "Starving" end +end + +local player_hunger_color_list = {} +for x = 1, 50, 1 do + player_hunger_color_list[x] = {r = 0.5 + x*0.01, g = x*0.01, b = x*0.005} + player_hunger_color_list[50+x] = {r = 1 - x*0.02, g = 0.5 + x*0.01, b = 0.25} + player_hunger_color_list[100+x] = {r = 0 + x*0.02, g = 1 - x*0.01, b = 0.25} + player_hunger_color_list[150+x] = {r = 1 - x*0.01, g = 0.5 - x*0.01, b = 0.25 - x*0.005} +end + +local player_hunger_buff = {} +local buff_top_value = 0.70 +for x = 1, 200, 1 do + player_hunger_buff[x] = buff_top_value +end +local y = 1 +for x = 89, 1, -1 do + player_hunger_buff[x] = buff_top_value - y * 0.015 + y = y + 1 +end +local y = 1 +for x = 111, 200, 1 do + player_hunger_buff[x] = buff_top_value - y * 0.015 + y = y + 1 +end + +local function create_hunger_gui(player) + if player.gui.top["hunger_frame"] then player.gui.top["hunger_frame"].destroy() end + + local frame = player.gui.top.add { type = "frame", name = "hunger_frame"} + + local str = tostring(global.player_hunger[player.name]) + str = str .. "% " + str = str .. player_hunger_stages[global.player_hunger[player.name]] + local caption_hunger = frame.add { type = "label", caption = str } + caption_hunger.style.font = "default-bold" + caption_hunger.style.font_color = player_hunger_color_list[global.player_hunger[player.name]] + caption_hunger.style.top_padding = 2 +end + +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] + global.player_hunger[player.name] = global.player_hunger[player.name] + food_value + if global.player_hunger[player.name] > 200 then global.player_hunger[player.name] = 200 end + + if past_hunger == 200 and global.player_hunger[player.name] + food_value > 200 then + global.player_hunger[player.name] = player_hunger_spawn_value + 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."} + 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 + 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}) + end + + if player.character then + if player_hunger_stages[global.player_hunger[player.name]] ~= player_hunger_stages[past_hunger] then + local print_message = "You feel " .. player_hunger_stages[global.player_hunger[player.name]] .. "." + if player_hunger_stages[global.player_hunger[player.name]] == "Obese" then + print_message = "You have become " .. player_hunger_stages[global.player_hunger[player.name]] .. "." + end + if player_hunger_stages[global.player_hunger[player.name]] == "Starving" then + print_message = "You are starving!" + end + player.print(print_message, player_hunger_color_list[global.player_hunger[player.name]]) + end + end + + 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]] +end + +local function on_player_joined_game(event) + local player = game.players[event.player_index] + if not global.player_hunger then global.player_hunger = {} end + if player.online_time < 2 then + global.player_hunger[player.name] = player_hunger_spawn_value + hunger_update(player, 0) + end + create_hunger_gui(player) +end \ No newline at end of file