SERVER: refactored the server lua scripts
parent
5f54ad00ca
commit
5faac7fd32
|
@ -1,4 +1,4 @@
|
|||
function animalDefault(container)
|
||||
local function animalDefault(container)
|
||||
container:addAbsolute("SPEED", 1.5)
|
||||
container:addAbsolute("HEALTH", 100.0)
|
||||
container:addAbsolute("ATTACKRANGE", 0.0)
|
||||
|
|
|
@ -2,36 +2,36 @@ project(server)
|
|||
set(SRCS
|
||||
Server.cpp Server.h
|
||||
)
|
||||
|
||||
set(ENTITIES
|
||||
animal-rabbit
|
||||
animal-wolf
|
||||
dwarf-male-blacksmith
|
||||
human-male-blacksmith
|
||||
human-male-knight
|
||||
human-male-shepherd
|
||||
human-male-worker
|
||||
human-female-worker
|
||||
undead-male-skeleton
|
||||
undead-male-zombie
|
||||
)
|
||||
|
||||
# These lua scripts are matching up with the entity type enum
|
||||
set(LUA_BEHAVIOURTREES
|
||||
ai/animal-rabbit.lua
|
||||
ai/animal-wolf.lua
|
||||
ai/dwarf-male-blacksmith.lua
|
||||
ai/human-male-blacksmith.lua
|
||||
ai/human-male-knight.lua
|
||||
ai/human-male-shepherd.lua
|
||||
ai/human-male-worker.lua
|
||||
ai/human-female-worker.lua
|
||||
ai/undead-male-skeleton.lua
|
||||
ai/undead-male-zombie.lua
|
||||
ai/shared.lua
|
||||
behaviourtrees.lua
|
||||
behaviourtreenodes.lua
|
||||
)
|
||||
set(LUA_ATTRIBUTES
|
||||
attrib/animal-rabbit.lua
|
||||
attrib/animal-wolf.lua
|
||||
attrib/dwarf-male-blacksmith.lua
|
||||
attrib/human-male-blacksmith.lua
|
||||
attrib/human-male-knight.lua
|
||||
attrib/human-male-shepherd.lua
|
||||
attrib/human-male-worker.lua
|
||||
attrib/human-female-worker.lua
|
||||
attrib/undead-male-skeleton.lua
|
||||
attrib/undead-male-zombie.lua
|
||||
attrib/shared.lua
|
||||
attributes.lua
|
||||
)
|
||||
|
||||
foreach(ENT ${ENTITIES})
|
||||
list(APPEND LUA_BEHAVIOURTREES "ai/${ENT}.lua")
|
||||
list(APPEND LUA_ATTRIBUTES "attrib/${ENT}.lua")
|
||||
endforeach()
|
||||
|
||||
set(LUA_EVENTS
|
||||
event/generic.lua
|
||||
events.lua
|
||||
|
@ -39,7 +39,13 @@ set(LUA_EVENTS
|
|||
set(LUA_MAPS
|
||||
map/map001.lua
|
||||
)
|
||||
set(LUA_SRCS ${LUA_BEHAVIOURTREES} ${LUA_ATTRIBUTES} ${LUA_EVENTS} ${LUA_MAPS})
|
||||
set(LUA_SRCS
|
||||
${LUA_BEHAVIOURTREES}
|
||||
${LUA_ATTRIBUTES}
|
||||
${LUA_EVENTS}
|
||||
${LUA_MAPS}
|
||||
shared/entities.lua
|
||||
)
|
||||
|
||||
set(FILES
|
||||
server/server-autoexec.cfg
|
||||
|
|
|
@ -1,14 +1,18 @@
|
|||
require "ai.shared"
|
||||
local module = {}
|
||||
|
||||
function rabbitStayAlive (parentnode)
|
||||
local shared = require "ai.shared"
|
||||
|
||||
local function rabbitStayAlive (parentnode)
|
||||
parentnode:addNode("Steer(SelectionFlee)", "fleefromhunter"):setCondition("And(Filter(SelectEntitiesOfTypes{ANIMAL_WOLF}),IsCloseToSelection{10})")
|
||||
end
|
||||
|
||||
function registerRabbit ()
|
||||
function module.register()
|
||||
local name = "ANIMAL_RABBIT"
|
||||
local rootNode = AI.createTree(name):createRoot("PrioritySelector", name)
|
||||
rabbitStayAlive(rootNode)
|
||||
increasePopulation(rootNode)
|
||||
idle(rootNode)
|
||||
die(rootNode)
|
||||
shared.increasePopulation(rootNode)
|
||||
shared.idle(rootNode)
|
||||
shared.die(rootNode)
|
||||
end
|
||||
|
||||
return module
|
||||
|
|
|
@ -1,14 +1,18 @@
|
|||
require "ai.shared"
|
||||
local module = {}
|
||||
|
||||
function wolfStayAlive (parentnode)
|
||||
local shared = require "ai.shared"
|
||||
|
||||
local function wolfStayAlive (parentnode)
|
||||
end
|
||||
|
||||
function registerWolf ()
|
||||
function module.register()
|
||||
local name = "ANIMAL_WOLF"
|
||||
local rootNode = AI.createTree(name):createRoot("PrioritySelector", name)
|
||||
wolfStayAlive(rootNode)
|
||||
hunt(rootNode)
|
||||
increasePopulation(rootNode)
|
||||
idle(rootNode)
|
||||
die(rootNode)
|
||||
shared.hunt(rootNode)
|
||||
shared.increasePopulation(rootNode)
|
||||
shared.idle(rootNode)
|
||||
shared.die(rootNode)
|
||||
end
|
||||
|
||||
return module
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
require "ai.shared"
|
||||
local module = {}
|
||||
|
||||
function registerDwarfBlacksmith ()
|
||||
local shared = require "ai.shared"
|
||||
|
||||
function module.register()
|
||||
local name = "DWARF_MALE_BLACKSMITH"
|
||||
local rootNode = AI.createTree(name):createRoot("PrioritySelector", name)
|
||||
idlehome(rootNode)
|
||||
shared.idlehome(rootNode)
|
||||
end
|
||||
|
||||
return module
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
require "ai.shared"
|
||||
local module = {}
|
||||
|
||||
function registerHumanFemaleWorker ()
|
||||
local shared = require "ai.shared"
|
||||
|
||||
function module.register()
|
||||
local name = "HUMAN_FEMALE_WORKER"
|
||||
local rootNode = AI.createTree(name):createRoot("PrioritySelector", name)
|
||||
idlehome(rootNode)
|
||||
shared.idlehome(rootNode)
|
||||
end
|
||||
|
||||
return module
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
require "ai.shared"
|
||||
local module = {}
|
||||
|
||||
function registerHumanBlacksmith ()
|
||||
local shared = require "ai.shared"
|
||||
|
||||
function module.register()
|
||||
local name = "HUMAN_MALE_BLACKSMITH"
|
||||
local rootNode = AI.createTree(name):createRoot("PrioritySelector", name)
|
||||
idlehome(rootNode)
|
||||
shared.idlehome(rootNode)
|
||||
end
|
||||
|
||||
return module
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
require "ai.shared"
|
||||
local module = {}
|
||||
|
||||
function registerHumanKnight ()
|
||||
local shared = require "ai.shared"
|
||||
|
||||
function module.register()
|
||||
local name = "HUMAN_MALE_KNIGHT"
|
||||
local rootNode = AI.createTree(name):createRoot("PrioritySelector", name)
|
||||
idlehome(rootNode)
|
||||
shared.idlehome(rootNode)
|
||||
end
|
||||
|
||||
return module
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
require "ai.shared"
|
||||
local module = {}
|
||||
|
||||
function registerHumanShepherd ()
|
||||
local shared = require "ai.shared"
|
||||
|
||||
function module.register()
|
||||
local name = "HUMAN_MALE_SHEPHERD"
|
||||
local rootNode = AI.createTree(name):createRoot("PrioritySelector", name)
|
||||
idlehome(rootNode)
|
||||
shared.idlehome(rootNode)
|
||||
end
|
||||
|
||||
return module
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
require "ai.shared"
|
||||
local module = {}
|
||||
|
||||
function registerHumanMaleWorker ()
|
||||
local shared = require "ai.shared"
|
||||
|
||||
function module.register()
|
||||
local name = "HUMAN_MALE_WORKER"
|
||||
local rootNode = AI.createTree(name):createRoot("PrioritySelector", name)
|
||||
idlehome(rootNode)
|
||||
shared.idlehome(rootNode)
|
||||
end
|
||||
|
||||
return module
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
function increasePopulation (parentnode)
|
||||
local module = {}
|
||||
|
||||
function module.increasePopulation (parentnode)
|
||||
local parallel = parentnode:addNode("Parallel", "increasepopulation")
|
||||
parallel:setCondition("And(Not(IsOnCooldown{INCREASE}),Filter(SelectIncreasePartner{INCREASE}))")
|
||||
|
||||
|
@ -11,7 +13,7 @@ function increasePopulation (parentnode)
|
|||
spawn:addNode("TriggerCooldownOnSelection{INCREASE}", "increasecooldownonpartner")
|
||||
end
|
||||
|
||||
function hunt (parentnode)
|
||||
function module.hunt (parentnode)
|
||||
local parallel = parentnode:addNode("Parallel", "hunt")
|
||||
parallel:setCondition("And(Not(IsOnCooldown{HUNT}),Filter(SelectEntitiesOfTypes{ANIMAL_RABBIT}))")
|
||||
|
||||
|
@ -21,13 +23,13 @@ function hunt (parentnode)
|
|||
parallel:addNode("TriggerCooldown{HUNT}", "increasecooldown"):setCondition("Not(IsSelectionAlive)")
|
||||
end
|
||||
|
||||
function idle (parentnode)
|
||||
function module.idle (parentnode)
|
||||
local prio = parentnode:addNode("PrioritySelector", "walkuncrowded")
|
||||
|
||||
prio:addNode("Steer(Wander)", "wanderfreely")
|
||||
end
|
||||
|
||||
function idlehome (parentnode)
|
||||
function module.idlehome (parentnode)
|
||||
local prio = parentnode:addNode("PrioritySelector", "walkuncrowded")
|
||||
|
||||
-- if there are too many objects (see parameter) visible of either the same npc type or the max count, leave the area
|
||||
|
@ -37,5 +39,7 @@ function idlehome (parentnode)
|
|||
prio:addNode("Steer(Wander)", "wanderfreely")
|
||||
end
|
||||
|
||||
function die (parentnode)
|
||||
function module.die (parentnode)
|
||||
end
|
||||
|
||||
return module
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
require "ai.shared"
|
||||
local module = {}
|
||||
|
||||
function registerUndeadSkeleton ()
|
||||
local shared = require "ai.shared"
|
||||
|
||||
function module.register()
|
||||
local name = "UNDEAD_MALE_SKELETON"
|
||||
local rootNode = AI.createTree(name):createRoot("PrioritySelector", name)
|
||||
idlehome(rootNode)
|
||||
shared.idlehome(rootNode)
|
||||
end
|
||||
|
||||
return module
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
require "ai.shared"
|
||||
local module = {}
|
||||
|
||||
function registerUndeadZombie ()
|
||||
local shared = require "ai.shared"
|
||||
|
||||
function module.register()
|
||||
local name = "UNDEAD_MALE_ZOMBIE"
|
||||
local rootNode = AI.createTree(name):createRoot("PrioritySelector", name)
|
||||
idlehome(rootNode)
|
||||
shared.idlehome(rootNode)
|
||||
end
|
||||
|
||||
return module
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
require "attrib.shared"
|
||||
local module = {}
|
||||
|
||||
function registerRabbit()
|
||||
local shared = require "attrib.shared"
|
||||
|
||||
function module.register()
|
||||
local animal = attrib.createContainer("ANIMAL_RABBIT")
|
||||
animalDefault(animal)
|
||||
shared.animalDefault(animal)
|
||||
animal:addAbsolute("FIELDOFVIEW", 240.0)
|
||||
end
|
||||
|
||||
return module
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
require "attrib.shared"
|
||||
local module = {}
|
||||
|
||||
function registerWolf()
|
||||
local shared = require "attrib.shared"
|
||||
|
||||
function module.register()
|
||||
local animal = attrib.createContainer("ANIMAL_WOLF")
|
||||
animalDefault(animal)
|
||||
shared.animalDefault(animal)
|
||||
animal:addAbsolute("VIEWDISTANCE", 500.0)
|
||||
animal:addAbsolute("FIELDOFVIEW", 240.0)
|
||||
animal:addAbsolute("ATTACKRANGE", 2.0)
|
||||
animal:addAbsolute("SPEED", 16.0)
|
||||
end
|
||||
|
||||
return module
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
require "attrib.shared"
|
||||
local module = {}
|
||||
|
||||
function registerDwarfBlacksmith()
|
||||
local shared = require "attrib.shared"
|
||||
|
||||
function module.register()
|
||||
local chr = attrib.createContainer("DWARF_MALE_BLACKSMITH")
|
||||
characterDefault(chr)
|
||||
shared.characterDefault(chr)
|
||||
end
|
||||
|
||||
return module
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
require "attrib.shared"
|
||||
local module = {}
|
||||
|
||||
function registerHumanFemaleWorker()
|
||||
local chr = attrib.createContainer("HUMAN_FEMALE_WORKER")
|
||||
characterDefault(chr)
|
||||
local shared = require "attrib.shared"
|
||||
|
||||
function module.register()
|
||||
local chr = attrib.createContainer("HUMAN_FEMALE_WORKER")
|
||||
shared.characterDefault(chr)
|
||||
end
|
||||
|
||||
return module
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
require "attrib.shared"
|
||||
local module = {}
|
||||
|
||||
function registerHumanBlacksmith()
|
||||
local shared = require "attrib.shared"
|
||||
|
||||
function module.register()
|
||||
local chr = attrib.createContainer("HUMAN_MALE_BLACKSMITH")
|
||||
characterDefault(chr)
|
||||
shared.characterDefault(chr)
|
||||
end
|
||||
|
||||
return module
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
require "attrib.shared"
|
||||
local module = {}
|
||||
|
||||
function registerHumanKnight()
|
||||
local shared = require "attrib.shared"
|
||||
|
||||
function module.register()
|
||||
local chr = attrib.createContainer("HUMAN_MALE_KNIGHT")
|
||||
characterDefault(chr)
|
||||
shared.characterDefault(chr)
|
||||
end
|
||||
|
||||
return module
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
require "attrib.shared"
|
||||
local module = {}
|
||||
|
||||
function registerHumanShepherd()
|
||||
local shared = require "attrib.shared"
|
||||
|
||||
function module.register()
|
||||
local chr = attrib.createContainer("HUMAN_MALE_SHEPHERD")
|
||||
characterDefault(chr)
|
||||
shared.characterDefault(chr)
|
||||
end
|
||||
|
||||
return module
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
require "attrib.shared"
|
||||
local module = {}
|
||||
|
||||
function registerHumanMaleWorker()
|
||||
local shared = require "attrib.shared"
|
||||
|
||||
function module.register()
|
||||
local chr = attrib.createContainer("HUMAN_MALE_WORKER")
|
||||
characterDefault(chr)
|
||||
shared.characterDefault(chr)
|
||||
end
|
||||
|
||||
return module
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
function animalDefault(container)
|
||||
local module = {}
|
||||
|
||||
function module.animalDefault(container)
|
||||
container:addAbsolute("SPEED", 10.0)
|
||||
container:addAbsolute("HEALTH", 100.0)
|
||||
container:addAbsolute("ATTACKRANGE", 0.0)
|
||||
|
@ -7,7 +9,7 @@ function animalDefault(container)
|
|||
container:addAbsolute("FIELDOFVIEW", 120.0)
|
||||
end
|
||||
|
||||
function characterDefault(container)
|
||||
function module.characterDefault(container)
|
||||
container:addAbsolute("SPEED", 14.0)
|
||||
container:addAbsolute("HEALTH", 100.0)
|
||||
container:addAbsolute("ATTACKRANGE", 0.0)
|
||||
|
@ -15,3 +17,5 @@ function characterDefault(container)
|
|||
container:addAbsolute("VIEWDISTANCE", 50.0)
|
||||
container:addAbsolute("FIELDOFVIEW", 60.0)
|
||||
end
|
||||
|
||||
return module
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
require "attrib.shared"
|
||||
local module = {}
|
||||
|
||||
function registerUndeadSkeleton()
|
||||
local shared = require "attrib.shared"
|
||||
|
||||
function module.register()
|
||||
local chr = attrib.createContainer("UNDEAD_MALE_SKELETON")
|
||||
characterDefault(chr)
|
||||
shared.characterDefault(chr)
|
||||
end
|
||||
|
||||
return module
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
require "attrib.shared"
|
||||
local module = {}
|
||||
|
||||
function registerUndeadZombie()
|
||||
local shared = require "attrib.shared"
|
||||
|
||||
function module.register()
|
||||
local chr = attrib.createContainer("UNDEAD_MALE_ZOMBIE")
|
||||
characterDefault(chr)
|
||||
shared.characterDefault(chr)
|
||||
chr:addAbsolute("SPEED", 8.0)
|
||||
end
|
||||
|
||||
return module
|
||||
|
|
|
@ -1,28 +1,7 @@
|
|||
require "attrib.animal-rabbit"
|
||||
require "attrib.animal-wolf"
|
||||
require "attrib.dwarf-male-blacksmith"
|
||||
require "attrib.human-male-blacksmith"
|
||||
require "attrib.human-male-knight"
|
||||
require "attrib.human-male-shepherd"
|
||||
require "attrib.human-male-worker"
|
||||
require "attrib.human-female-worker"
|
||||
require "attrib.undead-male-skeleton"
|
||||
require "attrib.undead-male-zombie"
|
||||
local entities = require("shared.entities")
|
||||
|
||||
function init()
|
||||
registerDwarfBlacksmith()
|
||||
|
||||
registerHumanBlacksmith()
|
||||
registerHumanKnight()
|
||||
registerHumanShepherd()
|
||||
registerHumanMaleWorker()
|
||||
registerHumanFemaleWorker()
|
||||
|
||||
registerUndeadSkeleton()
|
||||
registerUndeadZombie()
|
||||
|
||||
registerRabbit()
|
||||
registerWolf()
|
||||
entities.register("attrib")
|
||||
|
||||
local player = attrib.createContainer("PLAYER")
|
||||
player:addAbsolute("SPEED", 20.0)
|
||||
|
|
|
@ -1,26 +1,5 @@
|
|||
require "ai.animal-rabbit"
|
||||
require "ai.animal-wolf"
|
||||
require "ai.dwarf-male-blacksmith"
|
||||
require "ai.human-male-blacksmith"
|
||||
require "ai.human-male-knight"
|
||||
require "ai.human-male-shepherd"
|
||||
require "ai.human-male-worker"
|
||||
require "ai.human-female-worker"
|
||||
require "ai.undead-male-skeleton"
|
||||
require "ai.undead-male-zombie"
|
||||
local entities = require("shared.entities")
|
||||
|
||||
function init ()
|
||||
registerDwarfBlacksmith()
|
||||
|
||||
registerHumanBlacksmith()
|
||||
registerHumanKnight()
|
||||
registerHumanShepherd()
|
||||
registerHumanMaleWorker()
|
||||
registerHumanFemaleWorker()
|
||||
|
||||
registerUndeadSkeleton()
|
||||
registerUndeadZombie()
|
||||
|
||||
registerRabbit()
|
||||
registerWolf()
|
||||
function init()
|
||||
entities.register("ai")
|
||||
end
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
local module = {}
|
||||
|
||||
module.entities = {
|
||||
"animal-rabbit",
|
||||
"animal-wolf",
|
||||
"dwarf-male-blacksmith",
|
||||
"human-male-blacksmith",
|
||||
"human-male-knight",
|
||||
"human-male-shepherd",
|
||||
"human-male-worker",
|
||||
"human-female-worker",
|
||||
"undead-male-skeleton",
|
||||
"undead-male-zombie"
|
||||
}
|
||||
|
||||
function module.register(prefix)
|
||||
for key, value in ipairs(module.entities) do
|
||||
local mod = require(prefix .. '.' .. value)
|
||||
mod.register()
|
||||
end
|
||||
end
|
||||
|
||||
return module
|
Loading…
Reference in New Issue