add pulse checking and tools to help with it

not final
This commit is contained in:
Elkien3 2020-04-13 16:35:50 -05:00
parent 273144471a
commit 1e6f040bc8
12 changed files with 177 additions and 9 deletions

View File

@ -1,4 +1,5 @@
Note: features are subject to change. This mod is WIP and may not be useable in it's current state. Intructions on use will come further in development.
if you wish to help with this project please let me know.
Planned features:

View File

@ -12,18 +12,18 @@ minetest.register_entity("medical:body", {
on_activate = function(self, staticdata, dtime_s)
self.object:set_animation({x=162,y=167}, 1)
self.object:set_armor_groups({immortal = 1})
self.object:set_yaw(math.random(math.pi*-1, math.pi))
self.object:set_yaw(math.random(-math.pi, math.pi))
end,
--[[get_staticdata = function(self)
--return minetest.serialize({owner = self.owner, sleeping = self.sleeping, expiretime = self.time, mesh = self.mesh, textures = self.textures, yaw = self.yaw, inv = serializeContents(self.inv)})
--return
end,--]]
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir)
if not puncher:is_player() then return end
local wielditem = puncher:get_wielded_item()
local wieldname = wielditem:get_name()
local hitloc = medical.gethitloc(self, puncher, tool_capabilities, dir)
local hitloc, local_hitloc = medical.gethitloc(self.object, puncher, tool_capabilities, dir)
if medical.attachedtools[wieldname] then
medical.usedtools[wieldname](self, puncher, wielditem, hitloc)
medical.attachedtools[wieldname](self, puncher, wielditem, hitloc, local_hitloc)
end
-- attach things
end,
@ -31,9 +31,9 @@ minetest.register_entity("medical:body", {
if not clicker:is_player() then return end
local wielditem = clicker:get_wielded_item()
local wieldname = wielditem:get_name()
local hitloc = medical.gethitloc(self, clicker, nil, nil)
if medical.attachedtools[wieldname] then
medical.usedtools[wieldname](self, clicker, wielditem, hitloc)
local hitloc, local_hitloc = medical.gethitloc(self.object, clicker, nil, nil)
if medical.usedtools[wieldname] then
medical.usedtools[wieldname](self, clicker, wielditem, hitloc, local_hitloc)
end
-- use things
end

23
controls.lua Normal file
View File

@ -0,0 +1,23 @@
medical.lookingplayer = {}
medical.registered_on_lookaway = {}
function medical.register_on_lookaway(func)
medical.registered_on_lookaway[#medical.registered_on_lookaway+1] = func
end
minetest.register_globalstep(function(dtime)
for name, table in pairs(medical.lookingplayer) do
originaldir = table.dir
originalpos = table.pos
local player = minetest.get_player_by_name(name)
if not player then medical.lookingplayer[name] = nil return end
local dir = player:get_look_dir()
local pos = player:get_pos()
if vector.distance(originalpos, pos) > .1 or vector.distance(originaldir, dir) > .05 then --gives just a little bit of room that player can look around
for _, func in pairs(medical.registered_on_lookaway) do
func(player, name)
end
medical.lookingplayer[name] = nil
end
end
end)

1
depends.txt Normal file
View File

@ -0,0 +1 @@
controls

View File

@ -76,6 +76,15 @@ function medical.gethitloc(player, hitter, tool_capabilities, dir)
hitpos = pointed.intersection_point
end
end
local playeryaw
if player:is_player() then
playeryaw = player:get_look_horizontal()
else
playeryaw = player:get_yaw()
end
local loc = vector.subtract(hitpos, playerpos)
local x, z = rotateVector(loc.x, loc.z, -playeryaw)
local local_hitpos = {x=x,y=loc.y,z=z}
if DEBUG_WAYPOINT then
local marker = hitter:hud_add({
hud_elem_type = "waypoint",
@ -85,7 +94,24 @@ function medical.gethitloc(player, hitter, tool_capabilities, dir)
})
minetest.after(10, function() hitter:hud_remove(marker) end, hitter, marker)
end
return hitpos
return hitpos, local_hitpos
end
function medical.getclosest(table, local_hitpos)
local distance
local closest
for name, loc in pairs (table) do
if not distance then
distance = vector.distance(loc, local_hitpos)
closest = name
else
if vector.distance(loc, local_hitpos) < distance then
distance = vector.distance(loc, local_hitpos)
closest = name
end
end
end
return distance, closest
end
function medical.getlimb(player, hitter, tool_capabilities, dir, hitloc)

View File

@ -10,6 +10,9 @@ if not medical.data.injuries then medical.data.injuries = {} end
local modpath = minetest.get_modpath(minetest.get_current_modname())
dofile(modpath.."/timers.lua")
dofile(modpath.."/controls.lua")
dofile(modpath.."/vitals.lua")
dofile(modpath.."/hitloc.lua")
dofile(modpath.."/body.lua")
dofile(modpath.."/body.lua")
dofile(modpath.."/tools.lua")

5
license.txt Normal file
View File

@ -0,0 +1,5 @@
sounds:
human-heartbeat-daniel_simon: License: Attribution 3.0 Recorded by Daniel Simion
code: CC-BY-SA
textures: CC-BY-SA

Binary file not shown.

BIN
textures/foundpulse.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

BIN
textures/nopulse.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

46
timers.lua Normal file
View File

@ -0,0 +1,46 @@
medical.timers = {}
function medical.start_timer(name, length, loop, arg, func)
local index
if name then
index = name
else
local i = 0
while true do
if not medical.timers[i] then
index = i
break
end
i = i + 1
end
end
medical.timers[index] = {}
medical.timers[index].length = length
medical.timers[index].timeleft = length
medical.timers[index].loop = loop
medical.timers[index].arg = arg
medical.timers[index].func = func
return index
end
function medical.stop_timer(name, runonce)
local timer = medical.timers[name]
if runonce then
timer.func(timer.arg)
end
medical.timers[name] = nil
end
minetest.register_globalstep(function(dtime)
for index, timer in pairs (medical.timers) do
timer.timeleft = timer.timeleft - dtime
if timer.timeleft <= 0 then
timer.func(timer.arg)
if timer.loop then
medical.start_timer(index, timer.length, timer.loop, timer.arg, timer.func)
else
medical.stoptimer(name)
end
end
end
end)

63
tools.lua Normal file
View File

@ -0,0 +1,63 @@
medical.hud = {}
medical.usedtools[""] = function(self, clicker, wielditem, hitloc, local_hitloc)
local vitalpoints = {}
local playerpos = self.object:get_pos()
vitalpoints.cartoid = {x=0,y=.1,z=-.425}
vitalpoints.radialright = {x=.5,y=.1,z=-.05}
vitalpoints.radialleft = {x=-.5,y=.1,z=-.05}
vitalpoints.pedalright = {x=.20,y=.1,z=.7}
vitalpoints.pedalleft = {x=-.20,y=.1,z=.7}
local distance, hitpart = medical.getclosest(vitalpoints, local_hitloc)
if distance > .15 then return end
local cname = clicker:get_player_name()
if medical.hud[cname] then clicker:hud_remove(medical.hud[cname]) medical.hud[cname] = nil end
if not medical.lookingplayer[cname] then medical.lookingplayer[cname] = {dir = clicker:get_look_dir(), pos = clicker:get_pos()} end
medical.hud[cname] = clicker:hud_add({
hud_elem_type = "image",
position = {x = 0.5, y = 0.55},
offset = {x = 0, y = 0},
text = "nopulse.png",
scale = { x = 10, y = 10},
alignment = { x = 0, y = 0 },
})
medical.start_timer(cname.."pulsecheck", 60/medical.data.vitals[cname].pulse, true, cname, --todo: change this to give the patient's pulse instead of yours
function(arg)
minetest.sound_play("human-heartbeat-daniel_simon", {
pos = hitloc,
to_player = arg,
})
local circle = clicker:hud_add({
hud_elem_type = "image",
position = {x = 0.5, y = 0.55},
offset = {x = 0, y = 0},
text = "foundpulse.png",
scale = { x = 10, y = 10},
alignment = { x = 0, y = 0 },
})
minetest.after(.15, function()
local hitter = minetest.get_player_by_name(cname)
if hitter then
hitter:hud_remove(circle)
end
end)
end
)
end
controls.register_on_release(function(player, key, time)
local name = player:get_player_name()
if key == "RMB" and medical.hud[name] then
player:hud_remove(medical.hud[name]) medical.hud[name] = nil
medical.lookingplayer[name] = nil
medical.stop_timer(name.."pulsecheck", false)
end
end)
medical.register_on_lookaway(function(player, name)
if medical.hud[name] then
player:hud_remove(medical.hud[name])
medical.hud[name] = nil
medical.lookingplayer[name] = nil
medical.stop_timer(name.."pulsecheck", false)
end
end)