Conflicts:
	pathogen/api.lua
	pathogen_tests/init.lua
master
bas080 2015-02-20 17:47:53 +01:00
commit 0fc4dbc177
6 changed files with 321 additions and 154 deletions

196
API.md Normal file
View File

@ -0,0 +1,196 @@
# API
## Register pathogens
```lua
pathogen.register_pathogen("pathogenia", {
description = "An example disease",
symptoms = 12,
latent_period = 240,
infection_period = 740,
on_infect = function( infection )
minetest.sound_play( "pathogen_cough", { pos = pos, gain = 0.3 } )
end,
on_symptom = function( infection )
minetest.sound_play( "pathogen_cough", { pos = pos, gain = 0.3 } )
end
on_death = function( infection )
end
})
```
## Pathogen definition
|key|type|description|
|---|----|-----------|
|symptom|number|the amount of times symptoms are shown|
|latent_period|number|seconds before the symptoms start showing|
|infection_period|number|seconds from infection till last symptom|
|on_infect( infection )|function|actions to perform when infected ( this happens as soon as the infection takes place )|
|on_symptom( infection )|function|happens as many times as the defined symptom amount|
|on_death( infection )|function|called when the player dies while having the pathogen|
### infection
All function in the pathogen definition give an infection table as callback.
The infection table includes.
|key|type|description|
|---|----|-----------|
|symptom|number|an integer that represents the index of current symptom|
|player|string|the name of the player|
|immune|bool|when true the infection has stopped. For now it does not mean that the player cant be reinfected|
|pathogen|string|the name of the pathogen|
# API Functions
```lua
-----------
--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
----
--------------
--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.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, player_name )
--infects the player with a pathogen. If not able returns false
----
--return false if pathogen does not exist or player is immune
--consider making an is_immune function
----
--The table containing all the data that a infection cinsists out of. See
--the README.md for a more extensive explanation
-----
--store the infection in a table for later use. This table is also saved and
--loaded if the persistent option is set
------
--check if on_infect has been registered in pathogen
----
--perform the on_infect command that is defined in the regsiter function
--this is not the same as the on_symptoms. It is called only once at the
--beginning of the infection
--------
--latent perios is the time till the first symptom shows
----
--show the first symptom
----
pathogen.perform_symptom = function( infection, symptom )
--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.
--
--only keep showing symptoms if there is no immunity against the pathogen
----
--only show symptoms if not all symptoms have occured.
----
--set the time till the next symptom and then perfrom it again
----
--survives and is now immunized, immunization lasts till the server is
--restarted
pathogen.immunize = function( infection )
--immunize a player so the next symptom won't show. It also disables the
--abilty to reinfect the player. Use pathogen.disinfect to also remove
--the immunization It will also trigger the on_cured when the next symptom
--would have triggered.
----
--do not immunize if alread y immunized, return false
--else immunize the player and return true
pathogen.disinfect = function( infection )
--removes the immunization and the infection all together
----
--only is the is infected does it do this, return true
-- else it will only return false
pathogen.get_infection = function( player_name, pathogen_name )
--get an infection of a certain player
----
--only if the infection is registered
--otherwise return nil
pathogen.get_infections = function( )
--gives all the infections of all the players. If not infections are defined
--it returns an empty table. That's it.
pathogen.get_player_infections = function( player_name )
--helper function for getting the infections of a certain player
----
--gets and loops through the infections
----
--and adds the infection to the output of matches the player_name
-------------
--PERSISTENCE
-------------
pathogen.save = function( )
--TODO save the infections so it won"t get lost between server reloads
pathogen.load = function( )
--TODO reinfect the players when they rejoin the server. it remembers the
--infection fase thus the infection continues and does not get reset.
---------
--HELPERS
---------
pathogen.get_players_in_radius = function( pos, radius )
--helper to get players within the radius.
----
--loops threw all objects in within a radius
----
--and check if the object is a player
pathogen.on_dieplayer = function( player )
--when dying while having a pathogen it will trigger the on_death of the
--pathogen and it will remove all player infections
----
--loops through the player infections
----
--checks if it is a valid and still registered pathogen
----
--it then triggers the on_death if the on_death is defined
pathogen.on_dignode = function( pos, digger )
--infects players that dig a node that is infected with a pathogen
----
```

169
README.md
View File

@ -1,41 +1,41 @@
PATHOGEN
========
# PATHOGEN
A minetest mod that enables users to get a pathogen.
Features
========
# Features
- Easily define a new pathogen using the pathogen API
- Demo pathogens that are infectious and sometimes deadly.
Diseases
========
# Diseases
Influencia
----------
## Gravititus
Occurs when ascending too quickly. Symptons include hiccups and random sense of
gravity. There is no known cure yet. ( any suggestions? stone soup anyone? )
## Influencia
Highly contagious as it is airborne. Being around someone that has the diseases
increases the chances of getting the virus drastically. It is advised to eat well
and keep your distance from players that are coughing. Death is very unlikely.
Panola
------
Contagious through body fluids. It is ok to be near someone that has the diseases.
## Panola
Contagious through body fluids. It is ok to be near someone that has the disease.
Make sure that when cleaning up after someone that has expelled fluids, to
decontaminate the fluids first. This can be done with the Decontaminator.
decontaminate the fluids first. This can be done with the Decontaminator
![Decontaminator](pathogen/textures/pathogen_decontaminator.png).
Gosirea
-------
## Gosirea
Symptons include gas and burps. Occasionaly a shard.
Carrier contaminates nearby surfaces when symptoms show. Not deadly for those
that have good health.
Carrier contaminates nearby surfaces when symptoms show. These can intern infect
players that dig the infected nodes. Not deadly for those that have good health.
Items
=====
# Items
- Comes with nodes like vomit, blood and feces that are infectious when dug.
- A bio hazard warning fence, in case a quarantine is required.
- A decontaminater for removing infectious fluids.
Crafts
======
# Crafts
```lua
pathogen.recipes['xpanes:fence_warning'] = {
{'group:stick', 'wool:red', 'group:stick'},
@ -50,8 +50,8 @@ pathogen.recipes['pathogen:decontaminator'] = {
}
```
Commands
========
# Commands
Infections can be initiated by using commands. It requires the "pathogen"
privilege. /grant <playername> pathogen.
@ -68,135 +68,20 @@ privilege. /grant <playername> pathogen.
```
API
===
# Roadmap
Register pathogens
------------------
```lua
pathogen.register_pathogen("pathogenia", {
description = "An example disease",
symptoms = 12,
latent_period = 240,
infection_period = 740,
on_infect = function( infection )
minetest.sound_play( "pathogen_cough", { pos = pos, gain = 0.3 } )
end,
on_symptom = function( infection )
minetest.sound_play( "pathogen_cough", { pos = pos, gain = 0.3 } )
end
on_death = function( infection )
end
})
```
Pathogen definition
-------------------
|key|type|description|
|---|----|-----------|
|symptom|number|the amount of times symptoms are shown|
|latent_period|number|seconds before the symptoms start showing|
|infection_period|number|seconds from infection till last symptom|
|on_infect( infection )|function|actions to perform when infected ( this happens as soon as the infection takes place )|
|on_symptom( infection )|function|happens as many times as the defined symptom amount|
|on_death( infection )|function|called when the player dies while having the pathogen|
###infection
All function in the pathogen definition give an infection table as callback.
The infection table includes.
|key|type|description|
|---|----|-----------|
|symptom|number|an integer that represents the index of current symptom|
|player|string|the name of the player|
|immune|bool|when true the infection has stopped. For now it does not mean that the player cant be reinfected|
|pathogen|string|the name of the pathogen|
Functions
---------
```lua
--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
----
--CONTAMINENTS
pathogen.spawn_fluid = function( name, pos, pathogen )
--spawn the infectious juices
----
pathogen.register_fluid = function( name )
--registering a fluid(juice). This assumes that all fluids are flat on the
--floor
------
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, player_name )
--infects the player with a pathogen. If not able returns false
----
pathogen.perform_symptom = function( infection, symptom )
--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( infection )
--immunize a player so the next symptom won"t show.
----
pathogen.remove_infection = function( infection )
--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
----
--PERSISTENCE (WIP)
pathogen.save = function( )
pathogen.load = function( )
--HELPERS
pathogen.get_players_in_radius = function( pos, radius )
--helper to get players within the radius.
----
```
Roadmap
=======
- saving infections for persistence between server restarts
- more pathogens and cures
- make the API more flexible, consistent and forgiving
- register immunization with pathogen in seconds
Reference
=========
# Reference
- https://en.wikipedia.org/wiki/Incubation_period#mediaviewer/File:Concept_of_incubation_period.svg
- https://www.freesound.org
License
=======
# License
- Code WTFPL
- Images WTFPL
- Sounds CC

1
gravititus/depends.txt Normal file
View File

@ -0,0 +1 @@
pathogen

51
gravititus/init.lua Normal file
View File

@ -0,0 +1,51 @@
local gravititus = {}
local set_player_gravity = function( player_name, gravity )
local player = minetest.get_player_by_name( player_name )
local pos = player:getpos()
minetest.sound_play( "gravititus_hiccup", { pos = pos, gain = 0.3 } )
player:set_physics_override({
gravity = gravity
})
end
pathogen.register_pathogen("gravititus", {
description = "Occurs when ascending too quickly. Symptons are hiccups and random sense of gravity.",
symptoms = 10,
latent_period = 120,
infection_period = 420,
on_infect = function( infection )
set_player_gravity( infection.player, 2 / math.random( 1, 5 ) )
minetest.sound_play( "gravititus_hiccup", { pos = pos, gain = 0.3 } )
end,
on_symptom = function( infection )
set_player_gravity( infection.player, 2/ math.random( 1, 5 ) )
minetest.sound_play( "gravititus_hiccup", { pos = pos, gain = 0.3 } )
end,
on_death = function( infection )
set_player_gravity( infection.player, 1 )
end,
on_cured = function( infection )
set_player_gravity( infection.player, 1 )
end
})
minetest.register_on_dignode( function( pos, node, digger )
--determines when infection occurs.
----
local pln = digger:get_player_name()
local pos = pos
local pre = gravititus[pln]
gravititus[pln] = pos
if ( pre == nil ) then
minetest.after( 15, function()
local pre = gravititus[pln]
local dis = math.abs( pre.y - pos.y )
if ( dis > 20 ) then
local pat = pathogen.get_pathogen( 'gravititus' )
pathogen.infect( pat, pln )
end
gravititus[pln] = nil
end)
end
end )

Binary file not shown.

View File

@ -178,7 +178,8 @@ pathogen.perform_symptom = function( infection, symptom )
----
local symptom = symptom + 1
if ( infection.pathogen.symptoms >= symptom ) then --check if all symptoms have occured
--only show symptoms not all symptoms have occured.
--only show symptoms if not all symptoms have occured.
----
infection.symptom = symptom
local on_symptom = infection.pathogen.on_symptom
@ -191,12 +192,13 @@ pathogen.perform_symptom = function( infection, symptom )
local interval = ( ( infection.pathogen.infection_period - infection.pathogen.latent_period ) / infection.pathogen.symptoms )
minetest.after( interval , function()
--set the time till the next symptom and then perfrom it again
----
--
pathogen.perform_symptom( infection, symptom )
end)
infection.symptom = symptom
return true
elseif ( infection.pathogen.symptoms < symptom ) then
----
--survives and is now immunized, immunization lasts till the server is
--restarted
------
@ -218,12 +220,16 @@ end
pathogen.immunize = function( infection )
--immunize a player so the next symptom won't show. It also disables the
--abilty to reinfect the player. Use pathogen.remove_infection to also remove
--the immunization
------------------
--abilty to reinfect the player. Use pathogen.disinfect to also remove
--the immunization It will also trigger the on_cured when the next symptom
--would have triggered.
----
if infection.immune == true then
--do not immunize if alread y immunized, return false
--
return false
else
--else immunize the player and return true
infection.immune = true
return true
end
@ -233,9 +239,11 @@ pathogen.disinfect = function( infection )
--removes the immunization and the infection all together
----
if pathogen.infections[ infection.player..infection.pathogen.name ] then
--only is the is infected does it do this, return true
pathogen.infections[ infection.player..infection.pathogen.name ]= nil
return true
else
-- else it will only return false
return false
end
end
@ -244,15 +252,17 @@ pathogen.get_infection = function( player_name, pathogen_name )
--get an infection of a certain player
----
if player_name and pathogen_name then
--only if the infection is registered
return pathogen.infections[ player_name..pathogen_name ]
else
--otherwise return nil
return nil
end
end
pathogen.get_infections = function( )
--gives all the infections of all the players
----
--gives all the infections of all the players. If not infections are defined
--it returns an empty table. That's it.
return pathogen.infections
end
@ -262,36 +272,55 @@ pathogen.get_player_infections = function( player_name )
local infections = pathogen.get_infections()
local output = {}
for index, infection in pairs(infections) do
--gets and loops through the infections
----
if infection.player == player_name then
--and adds the infection to the output of matches the player_name
output[#output+1] = infection
end
end
return output
end
-------------
--PERSISTENCE
-------------
-------------
--PERSISTENCE
-------------
pathogen.save = function( )
--TODO save the infections so it won"t get lost between server reloads
--TODO save the infections so it won"t get lost between server reloads
local serialized = minetest.serialize( infections )
return serialized
end
pathogen.load = function( )
--TODO if run is true the loaded pathogens will run immediatly
--TODO reinfect the players when they rejoin the server. it remembers the
--infection fase thus the infection continues and does not get reset.
local deserialized = minetest.deserialize(string)
return deserialized
end
---------
--HELPERS
---------
---------
--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
--loops threw all objects in within a radius
----
if object:is_player() then
--and check if the object is a player
players[#players+1] = object
end
end
@ -301,15 +330,20 @@ end
pathogen.on_dieplayer = function( player )
--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
--loops through the player infections
----
local _pathogen = pathogen.get_pathogen( infection.pathogen )
if _pathogen then
--checks if it is a valid and still registered pathogen
----
local on_death = _pathogen.on_death
if on_death then
pathogen.disinfect( infecton )
--it then triggers the on_death if the on_death is defined
pathogen.disinfect( infection )
on_death( infection )
return true
end