Skip to content
Snippets Groups Projects
Commit 8c09236e authored by xo30xoqa's avatar xo30xoqa
Browse files

Added the Wyvern

Yes, this is another test species - I want to trial a simple
Lotka-Volterra model.
parent b614eee8
No related branches found
No related tags found
No related merge requests found
...@@ -43,6 +43,7 @@ include("farm/farm.jl") ...@@ -43,6 +43,7 @@ include("farm/farm.jl")
include("crop/crops.jl") include("crop/crops.jl")
include("nature/nature.jl") include("nature/nature.jl")
include("nature/wolpertinger.jl") include("nature/wolpertinger.jl")
include("nature/wyvern.jl")
include("core/simulation.jl") include("core/simulation.jl")
end end
### Persephone - a socio-economic-ecological model of European agricultural landscapes.
###
### This file holds the code for the Wyvern (https://en.wikipedia.org/wiki/Wyvern).
### NOT FOR ACTUAL USE! This is of course only a test species ;-)
### Thankfully, wyverns are not a species we have to manage for...
###
"""
initwyvern!(model)
Initialise a population of Wyverns in pairs locations around the landscape.
"""
function initwyvern!(model::AgentBasedModel)
species = getspecies("Wyvern")
x, y = size(model.landscape)
for i in 1:species.traits["initpop"]
add_agent!(Animal, model, species, hermaphrodite, 0, species.traits["birthenergy"])
end
@debug "$(species.traits["initpop"]) wyverns are now lying in wait in the landscape."
end
"""
updatewyvern!(animal, model)
Wyverns are ferocious hunters, scouring the landscape for their favourite
prey: wolpertingers...
"""
function updatewyvern!(w::Animal, model::AgentBasedModel)
# check if a wolpertinger is in pouncing distance
for a in nearby_agents(w, model, trait(w, "speed"))
(a.species.name != "Wolpertinger") && continue
move_agent!(w, a.pos, model)
w.energy -= trait(w, "pounceenergy")
if rand() < trait(w, "huntsuccess")
@debug "Wyvern $(w.id) killed wolpertinger $(a.id)."
w.energy += Int(round(a.energy/2))
kill_agent!(a, model)
@goto reproduce
end
end
# check if a wolpertinger is in seeing distance, or walk in a random direction
direction = Tuple(rand([-1,1], 2))
for a in nearby_agents(w, model, trait(w, "vision"))
if a.species.name == "Wolpertinger"
direction = get_direction(w.pos, a.pos, model)
break
end
end
for i in 1:trait(w, "speed")
walk!(w, direction, model; ifempty=false)
w.energy -= 1
end
# reproduce every once in a blue moon
@label reproduce
if rand() < 0.01
@debug "Wyvern $(w.id) has reproduced."
add_agent!(w.pos, Animal, model, getspecies("Wyvern"),
hermaphrodite, 0, trait(w, "birthenergy"))
end
end
newspecies("Wyvern",
initwyvern!,
updatewyvern!,
Dict("initpop"=>100,
"birthenergy"=>1000,
"speed"=>10,
"vision"=>50,
"pounceenergy"=>20,
"huntsuccess"=>0.3))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment