- Recipes in seperate file ( done to hopefully in the future make a simple auto generate recipe script)

- Contamination API allowing to contaminate nodes that later can contaminate
  players that dig that node

- Pathogen Gosirea that is uses the contamination mechanic

- Soft depend on xpanes
master
bas080 2015-02-03 16:01:07 +01:00
parent f583367e6f
commit 56e0817f84
14 changed files with 308 additions and 172 deletions

145
README.md
View File

@ -18,7 +18,7 @@ and keep your distance from players that are coughing. Death is very unlikely.
Panola
------
Contagious threw body fluids. It is ok to be near someone that has the diseases.
Contagious through body fluids. It is ok to be near someone that has the diseases.
Make sure that when cleaning up after someone that has expelled fluids, to
decontaminate the fluids first. This can be done with the Decontaminator.
@ -30,10 +30,37 @@ Items
Crafts
======
**Decontaminater**
{'xpanes:bar','',''},
{'','default:steelblock',''},
{'','',''}
```lua
pathogen.recipes['xpanes:fence_warning'] = {
{'group:stick', 'wool:red', 'group:stick'},
{'group:stick', 'wool:red', 'group:stick'},
{'group:stick', 'wool:red', 'group:stick'}
}
pathogen.recipes['pathogen:decontaminator'] = {
{'xpanes:bar','',''},
{'','default:steelblock',''},
{'','',''}
}
```
Commands
========
Infections can be initiated by using commands. It requires the "pathogen"
privilege. /grant <playername> pathogen.
```lua
/pathogens
--list all pathogens and their descriptions
/infect <player name> <pathogen name>
--infect the player
/immunize <player name> <pathogen name>
--make player immune to particular pathogen
```
API
===
@ -102,59 +129,72 @@ The infection table includes.
Functions
---------
```lua
--pathogens
pathogen.register_pathogen( pathogen_name, definition )
--getters
pathogen.get_pathogen( pathogen_name )
pathogen.get_pathogens()
pathogen.get_infection( player_name, pathogen_name )
pathogen.get_infections()
pathogen.get_players_in_radius( pos, radius )
pathogen.get_player_infections( player_name )
--PATHOGENS
pathogen.register_pathogen = function( pathogen_name, definition )
--checks if pathogen is registererd and registers if not
----
pathogen.get_pathogen = function( pathogen_name )
--get the table of a particular pathogen
----
pathogen.get_pathogens = function()
--gives all the pathogens that are registered
----
--actions
pathogen.infect( pathogen_name, player_name )
pathogen.perform_symptom( pathogen_name, player_name, faze )
--this function allows to add a pathogen that is already in a certain face.
--Fade is a number that represents the id of the state of the infection
--CONTAMINENTS
pathogen.spawn_fluid = function( name, pos, pathogen_name )
--spawn the infectious juices
----
pathogen.register_fluid = function( name )
--registering a fluid(juice). This assumes that all fluids are flat on the
--floor
------
pathogen.immunize( pathogen_name, player_name )
pathogen.remove_infection( pathogen_name, player_name )
--the difference between immunize and remove is that immunize makes the player
--never get sick of the same sickness again and remove removes the current
--infection but also it's immunization, thus allowing the player to get
--infected again.
pathogen.contaminate = function( pos, pathogen_name )
--contaminates a node which when dug infects the player that dug the node
----
pathogen.decontaminate = function( pos )
--remove the contamination from the node
----
pathogen.get_contaminant = function( pos )
--used to check if the node is infected and to get the name of the pathogen
--with which it is infected
------
--INFECTIONS
pathogen.infect = function( pathogen_name, player_name )
--infects the player with a pathogen.
----
pathogen.perform_symptom = function( pathogen_name, player_name, symptom_n )
--An infection can also be initiated without having to perform the on_infect.
--you can can cut straight to a particular symptom by using this function
--notice the symptom_n argument. This is a number that determines the state of
--the infection.
----------
pathogen.immunize = function( pathogen_name, player_name )
--immunize a player so the next symptom won"t show.
----
pathogen.remove_infection = function( pathogen_name, player_name )
--removes the immunization and the infection all together
----
pathogen.get_infection = function( player_name, pathogen_name )
--get an infection of a certain player
----
pathogen.get_infections = function()
--gives all the infections of all the players
----
pathogen.get_player_infections = function( player_name )
--helper function for getting the infections of a certain player
----
--fluids (flat node boxes that represent contaminated fluids)
pathogen.register_fluid( name )
pathogen.spawn_fluid( name, pos, pathogen_name )
pathogen.decontaminate_fluid( pos )
--fluids are contaminated nodes that will infect a player that punches that
--node. Considering making this more generic by allowing to have a function
--that allows making any node contaminable. Something like.
--pathogen.contaminate( pos ).
----------
--PERSISTENCE
pathogen.save = function( infections )
pathogen.load = function( run )
--makes the data persistent between server reloads (not yet implemented)
pathogen.save( infections )
pathogen.load( run )
```
Commands
========
Infections can be initiated by using commands. It requires the "pathogen"
privilege. /grant <playername> pathogen.
--HELPERS
pathogen.get_players_in_radius = function( pos, radius )
--helper to get players within the radius.
----
```lua
/pathogens
--list all pathogens and their descriptions
/infect <player name> <pathogen name>
--infect the player
/immunize <player name> <pathogen name>
--make player immune to particular pathogen
```
Roadmap
@ -162,8 +202,7 @@ Roadmap
- saving infections for persistence between server restarts
- more pathogens and cures
- make the API more flexible, consistent and forgiving
- consider immunization mechanic. Immunity is not indefinite...
- pathogen.contaminate( pos ) function
- register immunization with pathogen in seconds
Reference
=========

1
gosirea/depends.txt Normal file
View File

@ -0,0 +1 @@
pathogen

43
gosirea/init.lua Normal file
View File

@ -0,0 +1,43 @@
pathogen.register_pathogen("gosirea", {
description = "Contagious threw contact. Symptons include gas. Carrier contaminates surfaces nearby when symptoms show. Not deadly for those that have good health",
symptoms = 10,
latent_period = 120,
infection_period = 420,
on_infect = function( infection )
local _player = minetest.get_player_by_name( infection.player )
local _pos = _player:getpos()
minetest.sound_play( "pathogen_cough", { pos = _pos, gain = 0.3 } )
end,
on_symptom = function( infection )
local player = minetest.get_player_by_name( infection.player )
local pos = player:getpos()
local burp = function()
if math.random(2) == 1 then
return 'pathogen_burp_1'
else
return 'pathogen_burp_2'
end
end
local contaminate = function( pos )
local contaminate_pos = {
x = pos.x + math.random( -5,5 ),
y = pos.y + math.random( -5,5 ),
z = pos.z + math.random( -5,5 )
}
pathogen.contaminate( contaminate_pos )
end
local hp = player:get_hp()
if hp <= 5 then
player:set_hp( hp - 1 )
end
if math.random(25) == 1 then
pathogen.spawn_fluid( "feces", pos, infection.pathogen )
minetest.sound_play( "pathogen_poop", { pos = pos, gain = 0.3} )
else
minetest.sound_play( burp(), { pos = pos, gain = 0.3 } )
end
for i=0,3 do
contaminate( pos )
end
end
})

View File

@ -1,5 +1,6 @@
--PATHOGENS
pathogen.register_pathogen = function( pathogen_name, definition )
--the command that is used to register pathogens
--checks if pathogen is registererd and registers if not
----
if not pathogen.get_pathogen( pathogen_name ) then
definition.name = pathogen_name;
@ -9,14 +10,26 @@ pathogen.register_pathogen = function( pathogen_name, definition )
end
end
pathogen.get_pathogen = function( pathogen_name )
--get the table of a particular pathogen
----
return pathogen.pathogens[pathogen_name]
end
pathogen.get_pathogens = function()
--gives all the pathogens that are registered
----
return pathogen.pathogens
end
--CONTAMINENTS
pathogen.spawn_fluid = function( name, pos, pathogen_name )
--spawn the infectious juices
----
if minetest.get_node( pos ).name == "air" then
local node_name = "pathogen:fluid_"..name
minetest.set_node( pos, { name = node_name, param2=1 } )
local meta = minetest.get_meta( pos )
meta:set_string( "pathogen", pathogen_name )
pathogen.contaminate( pos )
end
end
@ -51,31 +64,49 @@ pathogen.register_fluid = function( name )
})
end
pathogen.decontaminate_fluid = function( pos )
if not pos then return end
local _meta = minetest.get_meta( pos )
local _pathogen = _meta:get_string( 'pathogen' )
if #_pathogen ~= 0 then
_meta:set_string( 'pathogen', '' )
pathogen.contaminate = function( pos, pathogen_name )
--contaminates a node which when dug infects the player that dug the node
----
local meta = minetest.get_meta( pos )
meta:set_string( 'pathogen', pathogen_name )
end
pathogen.decontaminate = function( pos )
--remove the contamination from the node
----
if pos then
local meta = minetest.get_meta( pos )
meta:set_string( 'pathogen', '' )
end
end
pathogen.infect = function( pathogen_name, player_name )
--notice that all parameters are strings. Threwout the mod the arguments are
--all primitive strings. is that good practice or should i use complex types?
--infect a player with a pathogen
--------
pathogen.get_contaminant = function( pos )
--used to check if the node is infected and to get the name of the pathogen
--with which it is infected
------
local meta = minetest.get_meta( pos )
local pathogen = meta:get_string( 'pathogen', pathogen_name )
if #pathogen == 0 then
return nil
else
return pathogen
end
end
--INFECTIONS
pathogen.infect = function( pathogen_name, player_name )
--infects the player with a pathogen. If not able to returns false
----
local _pathogen = pathogen.get_pathogen( pathogen_name, player_name )
if not _pathogen then return end
--do not perform infection if infection has already occured
----
if not _pathogen or _pathogen.immune == true then return false end
--do not perform infection if infection has already occured or if player no
--longer immune
------
local _player = minetest.get_player_by_name( player_name )
if _pathogen == nil then return false end
--check if pathogen exists
------
local _infection = {
--The table containing all the data that a infection cinsists out of. See
--the README.md for a more extensive explanation
@ -107,24 +138,15 @@ pathogen.infect = function( pathogen_name, player_name )
--show the first symptom
----
end)
end
pathogen.get_players_in_radius = function( pos, radius )
local objects = minetest.get_objects_inside_radius(pos, 5)
local players = {}
for index, object in ipairs(objects) do
if object:is_player() then
players[#players+1] = object
end
end
return players
return true
end
pathogen.perform_symptom = function( pathogen_name, player_name, symptom_n )
--An infection can also be initiated without having to perform the on_infect.
--you can can cut straight to a particular symptom by using this function
--notice the symptom_n argument.
--------
--notice the symptom_n argument. This is a number that determines the state of
--the infection.
----------
local _infection = pathogen.infections[ player_name..pathogen_name ]
local _pathogen = pathogen.pathogens[pathogen_name]
if not _infection.immune then
@ -150,18 +172,6 @@ pathogen.perform_symptom = function( pathogen_name, player_name, symptom_n )
end
end
pathogen.get_pathogen = function( pathogen_name )
--get the datat of a particular pathogen
----
return pathogen.pathogens[pathogen_name]
end
pathogen.get_infection = function( player_name, pathogen_name )
--get an infection of a certain player
----
return pathogen.infections[ player_name..pathogen_name ]
end
pathogen.immunize = function( pathogen_name, player_name )
--immunize a player so the next symptom won"t show.
----
@ -184,27 +194,21 @@ pathogen.remove_infection = function( pathogen_name, player_name )
end
end
pathogen.save = function( infections )
--TODO save the infections so it won"t get lost between server reloads
local serialized = minetest.serialize( infections )
return serialized
end
pathogen.load = function( run )
--TODO if run is true the loaded pathogens will run immediatly
local deserialized = minetest.deserialize(string)
return deserialized
pathogen.get_infection = function( player_name, pathogen_name )
--get an infection of a certain player
----
return pathogen.infections[ player_name..pathogen_name ]
end
pathogen.get_infections = function()
--gives all the infections of all the players
----
return pathogen.infections
end
pathogen.get_pathogens = function()
return pathogen.pathogens
end
pathogen.get_player_infections = function( player_name )
--helper function for getting the infections of a certain player
----
local _infections = pathogen.get_infections()
local _output = {}
for index, infection in pairs(_infections) do
@ -215,10 +219,37 @@ pathogen.get_player_infections = function( player_name )
return _output
end
--PERSISTENCE
pathogen.save = function( infections )
--TODO save the infections so it won"t get lost between server reloads
local serialized = minetest.serialize( infections )
return serialized
end
pathogen.load = function( run )
--TODO if run is true the loaded pathogens will run immediatly
local deserialized = minetest.deserialize(string)
return deserialized
end
--HELPERS
pathogen.get_players_in_radius = function( pos, radius )
--helper to get players within the radius.
----
local objects = minetest.get_objects_inside_radius(pos, 5)
local players = {}
for index, object in ipairs(objects) do
if object:is_player() then
players[#players+1] = object
end
end
return players
end
minetest.register_on_dieplayer( function( player )
--when dying while having a pathogen it will trigger the on_death and it will
--remove the current infections
------
--when dying while having a pathogen it will trigger the on_death of the
--pathogen and it will remove all player infections
------
local player_name = player:get_player_name()
local _infections = pathogen.get_player_infections( player_name )
for index, infection in pairs(_infections) do
@ -231,3 +262,13 @@ minetest.register_on_dieplayer( function( player )
end
end)
minetest.register_on_dignode( function( pos, oldnode, digger)
--infects players that dig a node that is infected with a pathogen
----
local pathogen_name = pathogen.get_contaminant( pos )
if pathogen_name then
local player_name = digger:get_player_name( )
pathogen.infect( player_name, pathogen_name )
end
return true
end)

View File

@ -16,8 +16,11 @@ minetest.register_chatcommand("infect", {
minetest.chat_send_player(name, 'could not infect: pathogen '..pathogen_name..' does not exist')
return nil
end
pathogen.infect( pathogen_name, player_name )
minetest.chat_send_player(name, 'infected '..player_name..' with '..pathogen_name)
if pathogen.infect( pathogen_name, player_name ) then
minetest.chat_send_player(name, 'infected '..player_name..' with '..pathogen_name)
else
minetest.chat_send_player(name, 'could not infect: for some unknown reason' )
end
end
})

View File

@ -1,8 +1,4 @@
minetest.register_craft({
output = 'pathogen:decontaminator',
recipe = {
{'xpanes:bar','',''},
{'','default:steelblock',''},
{'','',''}
}
recipe = pathogen.recipes['pathogen:decontaminator']
})

View File

@ -1,3 +1,3 @@
default
wool
xpanes
xpanes?

View File

@ -4,9 +4,10 @@ pathogen = {
fluids = {},
}
dofile( minetest.get_modpath( "pathogen" ) .. "/options.lua" ) --WIP
dofile( minetest.get_modpath( "pathogen" ) .. "/api.lua" )
dofile( minetest.get_modpath( "pathogen" ) .. "/tools.lua" )
dofile( minetest.get_modpath( "pathogen" ) .. "/crafts.lua" )
dofile( minetest.get_modpath( "pathogen" ) .. "/nodes.lua" )
dofile( minetest.get_modpath( "pathogen" ) .. "/commands.lua" )
dofile( minetest.get_modpath( "pathogen" ) .. "/options.lua" ) --WIP
dofile( minetest.get_modpath( "pathogen" ) .. "/recipes.lua")
dofile( minetest.get_modpath( "pathogen" ) .. "/api.lua" )
dofile( minetest.get_modpath( "pathogen" ) .. "/tools.lua" )
dofile( minetest.get_modpath( "pathogen" ) .. "/crafts.lua" )
dofile( minetest.get_modpath( "pathogen" ) .. "/nodes.lua" )
dofile( minetest.get_modpath( "pathogen" ) .. "/commands.lua" )

View File

@ -2,48 +2,46 @@ pathogen.register_fluid( 'vomit' )
pathogen.register_fluid( 'blood' )
pathogen.register_fluid( 'feces' )
if not minetest.get_modpath( "xpanes" ) then
--[[ in case you do not want the xpanes dependency
minetest.register_node("pathogen:fence", {
description = "Infection Hazard Fence",
drawtype = 'nodebox',
tiles = {"pathogen_fence.png"},
inventory_image = 'pathogen_fence.png',
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "facedir",
is_ground_content = false,
groups = {tree=1,choppy=2,oddly_breakable_by_hand=1,flammable=2},
sounds = default.node_sound_wood_defaults(),
--visual_scale = 33/32,
node_box = {
type = 'fixed',
fixed = {
{-0.5, -0.5, 63/128,
0.5, 0.5 , 63/128},
}
},
})
]]--
minetest.register_node("pathogen:fence", {
description = "Infection Hazard Fence",
drawtype = 'nodebox',
tiles = {"pathogen_fence.png"},
inventory_image = 'pathogen_fence.png',
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "facedir",
is_ground_content = false,
groups = {tree=1,choppy=2,oddly_breakable_by_hand=1,flammable=2},
sounds = default.node_sound_wood_defaults(),
node_box = {
type = 'fixed',
fixed = {
{-0.5, -0.5, 63/128,
0.5, 0.5 , 63/128},
}
},
})
xpanes.register_pane("fence_warning", {
description = "Infection Hazard Fence",
tiles = {"pathogen_fence.png"},
drawtype = "airlike",
paramtype = "light",
sunlight_propagates = true,
walkable = false,
pointable = false,
diggable = false,
buildable_to = true,
air_equivalent = true,
textures = {"pathogen_fence.png", "pathogen_fence.png", 'xpanes_space.png'},
inventory_image = "pathogen_fence.png",
wield_image = "pathogen_fence.png",
groups = {snappy=2, cracky=3, oddly_breakable_by_hand=3, pane=1},
recipe = {
{'group:stick', 'wool:red', 'group:stick'},
{'group:stick', 'wool:red', 'group:stick'},
{'group:stick', 'wool:red', 'group:stick'}
}
})
else
xpanes.register_pane("fence_warning", {
description = "Infection Hazard Fence",
tiles = {"pathogen_fence.png"},
drawtype = "airlike",
paramtype = "light",
sunlight_propagates = true,
walkable = false,
pointable = false,
diggable = false,
buildable_to = true,
air_equivalent = true,
textures = {"pathogen_fence.png", "pathogen_fence.png", 'xpanes_space.png'},
inventory_image = "pathogen_fence.png",
wield_image = "pathogen_fence.png",
groups = {snappy=2, cracky=3, oddly_breakable_by_hand=3, pane=1},
recipe = pathogen.recipes['xpanes:fence_warning']
})
end

View File

@ -1,4 +1,5 @@
--DOES NOT WORK YET WIP
pathogen.options = {
persistent = false
persistence = false,
immunization = false,
}

13
pathogen/recipes.lua Normal file
View File

@ -0,0 +1,13 @@
pathogen.recipes = {}
pathogen.recipes['xpanes:fence_warning'] = {
{'group:stick', 'wool:red', 'group:stick'},
{'group:stick', 'wool:red', 'group:stick'},
{'group:stick', 'wool:red', 'group:stick'}
}
pathogen.recipes['pathogen:decontaminator'] = {
{'xpanes:bar','',''},
{'','default:steelblock',''},
{'','',''}
}

Binary file not shown.

Binary file not shown.

View File

@ -5,6 +5,6 @@ minetest.register_tool( 'pathogen:decontaminator', {
minetest.sound_play( 'pathogen_spray', { pos = user:getpos(), gain = 0.2, max_hear_distance = 5 })
if not pt then return itemstack end
if math.random(5) == 1 then return itemstack end
pathogen.decontaminate_fluid( pt.under )
pathogen.decontaminate( pt.under )
end
})