commit 193e2ecb650b1fce1305ef713baa5636d59e2027 Author: mrbesen Date: Sun Jul 21 10:32:16 2019 +0200 initial diff --git a/README.md b/README.md new file mode 100644 index 0000000..06c0f84 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# Superhot - Factorio mod + +Time runs as fast as you run. + +This mod is inspired by the game [Superhot](http://superhot.jp) + +If you have problems you can reset the timing in you wold with: +``` +/c game.speed = 1 +``` + +Download the Mod [here](https://mods.factorio.com/mod/Superhot) diff --git a/control.lua b/control.lua new file mode 100644 index 0000000..71664c1 --- /dev/null +++ b/control.lua @@ -0,0 +1,83 @@ +--local movingActive = 673 -- this value is actually not random, but carefully calculated , src value: 0,1484375 +local miningActive = 100 + +function init() + if not global.Superhot then + global.Superhot = {} + end + if not global.Superhot.playermovement then + global.Superhot.playermovement = {} + end +end + +function getDist(mov) + return math.sqrt((mov[1] * mov[1]) + (mov[2] * mov[2])) +end + +-- caps the speed using a logarithmic function, is undefined for x <= 0! +function movementcap(x) + return (75.88 * math.log(x)) + 244 +end + +script.on_event({defines.events.on_tick}, + function (e) + init() -- init variables TODO: do somewhere else! + local activeMax = 0 + local lastplayer -- just for DEBUG + for index,player in pairs(game.connected_players) do --loop through all online players on the server + lastplayer = player + if player.valid and player.connected and player.character then + local active = 0 + -- is mining? + if player.mining_state.mining then + active = miningActive + end + + --is moving + local newpos = player.position + local oldpos = global.Superhot.playermovement[player.index] + local mov = {0,0} + if oldpos ~= nil then + mov = {oldpos.x - newpos.x, oldpos.y - newpos.y} + + local dist = getDist(mov) + if dist > 0 then + active = active + movementcap(dist) + end + end + + --update movement + global.Superhot.playermovement[player.index] = newpos + + --update max + if active > activeMax then + activeMax = active + end + end + end + + local goal = activeMax/100.0 + local diff = goal - game.speed + + -- make acceleration smoother + if diff > 0.2 or diff < -0.2 then + diff = diff / 2.0 + end + goal = game.speed + diff + + --clip to upper and lower bound + if goal < 0.1 then + goal = 0.1 + elseif goal > 10 then + goal = 10 + end + + --actually set it + game.speed = goal + end +) + +-- spped modifyer: game.speed=1 +-- freeze time: game.player.surface.freeze_daytime=true + +-- defines.events.on_pre_player_mined_item diff --git a/info.json b/info.json new file mode 100644 index 0000000..5f84e36 --- /dev/null +++ b/info.json @@ -0,0 +1,11 @@ +{ + "name": "Superhot", + "version": "0.1.0", + "title": "SuperHot", + "author": "MrBesen", + "contact": "https://git.mrbesen.de/mrbesen/superhot/issues", + "homepage": "https://git.mrbesen.de/mrbesen/superhot", + "factorio_version": "0.17", + "dependencies": ["base >= 0.17"], + "description": "Time runs as fast as you run." +} diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..d7b4f28 --- /dev/null +++ b/install.sh @@ -0,0 +1,2 @@ +#!/bin/bash +cd ../ && zip Superhot/Superhot_0.1.0.zip -r Superhot/*.lua Superhot/info.json && cp -f Superhot_0.1.0.zip ~/.factorio/mods/ && echo "Done." diff --git a/movementcap.ods b/movementcap.ods new file mode 100644 index 0000000..6f6b67d Binary files /dev/null and b/movementcap.ods differ