Skip to content

Commit

Permalink
Improvements on JWE ACSE
Browse files Browse the repository at this point in the history
- DinoTorpor example performance and safety checks
- ACSE better loading
  • Loading branch information
ilodev committed Jan 27, 2021
1 parent dd62eca commit 365cc4d
Show file tree
Hide file tree
Showing 11 changed files with 201 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ local pairs = global.pairs
local DinoTorporData = module(...)

--/ Used as debug output for now
-- global.loadfile("Database.DinoTorpor.lua Loaded")
global.loadfile("Database.DinoTorpor.lua Loaded")

--/ List of custom managers to force injection on a park
DinoTorporData.tParkManagers = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ local require = global.require
--/ Module creation
local DinoTorpor = module(...)

-- global.loadfile("TorporLuaDatabase Loaded")
global.loadfile("TorporLuaDatabase Loaded")

-- @brief add our custom managers to the ACSE database
DinoTorpor.AddContentToCall = function(_tContentToCall)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,66 @@ local api = global.api
local pairs = global.pairs
local require = global.require
local module = global.module
local math = global.math
local table = require("Common.tableplus")
local Vector3 = require("Vector3")
local Quaternion = require("Quaternion")
local Object = require("Common.object")
local Mutators = require("Environment.ModuleMutators")

--/ Create module
local DinoTorporManager= module(..., (Mutators.Manager)())

-- global.loadfile("Manager.DinoTorporManager.lua loaded")
global.api.debug.Trace("acse Manager.DinoTorporManager.lua loaded")

-- @Brief Init function for the DinoTorpor mod
DinoTorporManager.Init = function(self, _tProperties, _tEnvironment)
-- global.loadfile("Manager.DinoTorporManager:Init()")
self.dinosAPI = api.world.GetWorldAPIs().dinosaurs
global.api.debug.Trace("acse Manager.DinoTorporManager Init")

self.worldAPIS = api.world.GetWorldAPIs()
self.dinosAPI = self.worldAPIS.dinosaurs
self.weaponsAPI = self.worldAPIS.weapons
self.messageAPI = global.api.messaging
self.tranqdDinos = {}

self.tMessageRecievers = {
--/ Used to register when a dinosaur is tranquillised
[self.messageAPI.MsgType_DinosaurActionMessage] = function(_tMessages)
self:_fnHandleDinosaurActionReceiver(_tMessages)
end,
--/ Used to register when a dinosaur is killed or dies
[self.messageAPI.MsgType_DinosaurDeathMessage] = function(_tMessages)
self:_fnDinosaurDeathReceiver(_tMessages)
end,
--/ Used to register when a dinosaur is shot (even when already tranquillised)
[self.messageAPI.MsgType_ProjectileImpactMessage] = function(_tMessages)
self:_fnProjectileImpactReceiver(_tMessages)
end
}
--/ Register the manager receivers
for nMessageType,fnReceiver in pairs(self.tMessageRecievers) do
self.messageAPI.RegisterReceiver(nMessageType, fnReceiver)
end
end


-- @Brief Manages tranqued dinos
-- @TODO remove tranqued dinos from the list if they are being transported
-- @TODO make wakeup time variable
DinoTorporManager.Advance = function(self, _nDeltaTime)
-- Check for recently tranqued dinos and add them to the list
local parkDinos = self.dinosAPI:GetDinosaurs(false)
for i = 1, #parkDinos do
local dinosaurEntity = parkDinos[i]
if not self.dinosAPI:IsConscious(dinosaurEntity) and self.tranqdDinos[dinosaurEntity] == nil then
self.tranqdDinos[dinosaurEntity] = 10
end
end
-- Check for recently tranqued dinos and add them to the list, looping all dinos on
-- Advance is quite expensive, it was moved to a callback
-- local parkDinos = self.dinosAPI:GetDinosaurs(false)
-- for i = 1, #parkDinos do
-- local dinosaurEntity = parkDinos[i]
-- end

-- wake up sleeping dinos after their wake-up period
for k,v in pairs(self.tranqdDinos) do
self.tranqdDinos[k] = v - _nDeltaTime
if self.tranqdDinos[k] < 0 and not self.dinosAPI:IsDead(k) then
self.dinosAPI:MakeConscious(k)
self.tranqdDinos[k] = nil
for dinosaurEntity,v in pairs(self.tranqdDinos) do
self.tranqdDinos[dinosaurEntity] = v - _nDeltaTime
if self.tranqdDinos[dinosaurEntity] < 0 and self:IsValidDinosaur(dinosaurEntity) then
self:TryWakeUpEntity(dinosaurEntity)
end
end

end

-- @Brief Called when the manager is activated
Expand All @@ -64,8 +85,126 @@ end

-- @Brief Called when the manager needs to be finished
DinoTorporManager.Shutdown = function(self)
--/ clear all callback handlers
for nMessageType,fnReceiver in pairs(self.tMessageRecievers) do
self.messageAPI.UnregisterReceiver(nMessageType, fnReceiver)
end
self.tMessageRecievers = nil
end

--[[
Table of api.dinosaurs actions, not in order
DAT_FinishedHuntingLiveBait
DAT_CountermeasuresApplied
DAT_AttackedCar
DAT_AttackedFenceUnsuccessfully
DAT_AttackedFenceSuccessfully
DAT_StartedFighting
DAT_FinishedFighting
DAT_Tranquillised
DAT_TranquillisedCount
DAT_WokeUp
DAT_GotDisease"
DAT_NoLongerDiseased
DAT_KilledGuest
DAT_KilledDinosaur
DAT_WonFight
DAT_Terrorising
DAT_InjuredGuest
DAT_FinishedHunting
]]

-- @Brief Receives dinosaur actions
DinoTorporManager._fnHandleDinosaurActionReceiver = function(self, _tMessages)
for _,tMessage in pairs(_tMessages) do
--/ nAction
--/ nEntity
--/ nOtherEntity
if tMessage.nAction == self.dinosAPI.DAT_Tranquillised then
-- Add the dinosaur to the list of Tranqed dinos
self:TryAddEntity(tMessage.nEntity)
end
end
end

-- @Brief Receives dinosaur deaths
DinoTorporManager._fnDinosaurDeathReceiver = function(self, _tMessages)
for _,tMessage in pairs(_tMessages) do
--/ nEntityID
--/ sCauseOfDeath
--/ sDiseaseType
--/ Forced removal of dinosaur from the tranqued table
self.tranqdDinos[tMessage.nEntityID] = nil
end
end

-- @Brief Receives projectile impacts
DinoTorporManager._fnProjectileImpactReceiver = function(self, _tMessages)
for _,tMessage in pairs(_tMessages) do
--/ MsgType_ProjectileImpactMessage
--/ Vector3 vPosition
--/ number nHitEntity
--/ number nGunEntity
--/ number nProjectileEntity
if self:IsValidDinosaur(tMessage.nHitEntity)
and self.weaponsAPI:GetProjectileType(tMessage.nProjectileEntity) == self.weaponsAPI.ProjectileType_Sedative then
self:TryAddTorpor( tMessage.nHitEntity, math.random() * 5 + 25 )
end
end
end


-- @Brief Confirm a dinosaur is a valid target
DinoTorporManager.IsValidDinosaur = function(self, nEntityID)
if self.dinosAPI:IsDinosaur(nEntityID) and
not self.dinosAPI:IsDead(nEntityID) and
not self.dinosAPI:IsLiveBait(nEntityID) and
not self.dinosAPI:IsPterosaur(nEntityID) and
not self.dinosAPI:IsAirborne(nEntityID) then
return true
end

return false
end

-- @Brief Adds torpor to the dino if shot while tranquillised
DinoTorporManager.TryAddTorpor = function(self, nEntityID, nValue)
if self:IsValidDinosaur(nEntityID) and self.tranqdDinos[nEntityID] then
self.tranqdDinos[nEntityID] = self.tranqdDinos[nEntityID] + nValue
end

-- Something to look up later
-- local nAwakeness = self.dinosAPI:GetSatisfactionLevel(dinosaurEntity, self.dinosAPI.DNT_Drowsiness)
end

-- @Brief Adds an entry to the wake up list
DinoTorporManager.TryAddEntity = function(self, nEntityID)
global.api.debug.Trace("acse _TryAddEntity" .. nEntityID)
if self:IsValidDinosaur(nEntityID) then
local Traits = self.dinosAPI:GetDinosaurTraits(nEntityID)
self.tranqdDinos[nEntityID] = math.sqrt(Traits.sedativeResistance) * 15 + math.random() * math.sqrt(Traits.size)

end
end

-- @Brief Tries to wake up an entity
DinoTorporManager.TryWakeUpEntity = function(self, nEntityID)
global.api.debug.Trace("acse _TryWakeUpEntity" .. nEntityID)
if self:IsValidDinosaur(nEntityID) then

local dinoTransform = api.transform.CalculateWorldTransform(nEntityID)
dinoTransform = dinoTransform:WithOr((Quaternion.FromUF)(Vector3.YAxis , (dinoTransform:GetOr()):GetF()))
self.dinosAPI:DinosaurTeleportTo(nEntityID, dinoTransform)
self.dinosAPI:MakeConscious(nEntityID)

global.api.debug.Trace("acse _TryWakeUpEntity" .. nEntityID .. " set conscious")
end

self.tranqdDinos[nEntityID] = nil
end

-- Validate the class methods/interfaces
(Mutators.VerifyManagerModule)(DinoTorporManager)


Binary file modified Release/Jurassic World Evolution/ACSE/Main.ovl
Binary file not shown.
Binary file modified Release/Jurassic World Evolution/DinoTorpor/Main.ovl
Binary file not shown.
5 changes: 3 additions & 2 deletions Source/Jurassic World Evolution/ACSE/Main/Database.ACSE.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ local Main = require("Database.Main")
local GameDatabase = require("Database.GameDatabase")
local ACSE = module(...)

-- global.loadfile("Database.ACSE.lua loaded")

-- Constant version
ACSE.nVersion = 0.231

Expand Down Expand Up @@ -54,6 +52,7 @@ ACSE.tDatabaseMethods = {
end
}

global.api.debug.Trace("ACSE " .. ACSE.nVersion .. " loaded")

-- @brief Database init
ACSE.Init = function()
Expand Down Expand Up @@ -119,3 +118,5 @@ ACSE.AddParkManagers = function(_fnAdd)
_fnAdd(sManagerName, tParams)
end
end


Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,18 @@ local type = global.type
local require = require
local ACSEDatabase = module(...)

-- global.loadfile("Database.ACSELuaDatabase.lua loaded")
-- @brief setup a custom debug/trace system to use
global.api.asec = {}
global.api.asec.Trace = function(msg)
global.loadfile("acse :" .. msg)
end
global.api.asec.Error = function(msg)
global.api.asec.Trace("Err- " .. msg)
end
global.api.debug.Trace = global.api.asec.Trace
global.api.debug.Error = global.api.asec.Error

global.api.debug.Trace("Database.ACSELuaDatabase.lua loaded on " .. global._VERSION)

-- @brief add our custom databases
ACSEDatabase.AddContentToCall = function(_tContentToCall)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ local GameDatabase = require("Database.GameDatabase")
local Mutators = require("Environment.ModuleMutators")
local Module = module(..., Mutators.EnvironmentPrototype)

global.api.debug.Trace("Custom Park Environment loaded")

-- Default Park Environment defintion from JWE 1.8
Module.EnvironmentPrototype = {
SearchPaths = {"Managers"},
Expand Down Expand Up @@ -147,10 +149,11 @@ Module.EnvironmentPrototype = {
}

-- Merge default Managers with ACSE collected protos
if GameDatabase.GetStartEnvironmentProtos then
for _sName, _tParams in pairs( GameDatabase.GetParkEnvironmentManagers() ) do
Module.EnvironmentPrototype['Managers'][_sName] = _tParams
end
if GameDatabase.GetParkEnvironmentManagers then
for _sName, _tParams in pairs( GameDatabase.GetParkEnvironmentManagers() ) do
global.api.debug.Trace("acse Adding Manager: " .. _sName)
Module.EnvironmentPrototype['Managers'][_sName] = _tParams
end
end

-- confirm the environment comply its proto
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@
--/ Evolution
--/ @see https:/OpenNaja/ACSE
-----------------------------------------------------------------------
local global = _G
local api = global.api
local require = global.require
local module = global.module
local type = global.type
local pairs = global.pairs
local global = _G
local api = global.api
local require = global.require
local module = global.module
local type = global.type
local pairs = global.pairs
local loadfile = global.loadfile
local Main = require("Database.Main")
local Main = require("Database.Main")
local GameDatabase = require("Database.GameDatabase")
local Mutators = require("Environment.ModuleMutators")
local Module = module(..., Mutators.EnvironmentPrototype)
local Module = module(..., Mutators.EnvironmentPrototype)

global.api.debug.Trace("Custom StartScreen Environment loaded")

-- Default Start Screen Environment defintion from JWE 1.8
Module.EnvironmentPrototype = {
Expand All @@ -29,8 +31,9 @@ Module.EnvironmentPrototype = {
}

-- Merge default protos with ACSE collected protos
if GameDatabase.GetStartEnvironmentProtos then
if GameDatabase.GetStartEnvironmentManagers then
for _sName, _tParams in pairs( GameDatabase.GetStartEnvironmentManagers() ) do
global.api.debug.Trace("acse Adding Manager: " .. _sName)
Module.EnvironmentPrototype['Managers'][_sName] = _tParams
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ local module = global.module
local table = require("Common.tableplus")
local Object = require("Common.object")
local Mutators = require("Environment.ModuleMutators")
local ACSEParkManager= module(..., Mutators.Manager())
local ACSEParkManager = module(..., Mutators.Manager())

-- global.loadfile("Managers..ACSEParkManager.lua loaded")
global.api.debug.Trace("ACSEParkManager loaded")

-- @Brief Init function for this manager
ACSEParkManager.Init = function(self, _tProperties, _tEnvironment)
global.api.debug.Trace("ACSEParkManager:Init()")
end

-- @Brief Update function for this manager
Expand All @@ -38,4 +39,4 @@ ACSEParkManager.Shutdown = function(self)
end

--/ Validate class methods and interfaces
(Mutators.VerifyManagerModule)(ACSEParkManager)
(Mutators.VerifyManagerModule)(ACSEParkManager)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
--/
--/ @brief Boilerplate template for the starting screen manager script
--/ @see https:/OpenNaja/ACSE
-----------------------------------------------------------------------local global = _G
-----------------------------------------------------------------------
local global = _G
local api = global.api
local pairs = global.pairs
local require = global.require
Expand All @@ -14,10 +15,11 @@ local Object = require("Common.object")
local Mutators = require("Environment.ModuleMutators")
local ACSEStartScreenManager= module(..., Mutators.Manager())

-- global.loadfile("Managers..ACSEStartScreenManager.lua loaded")
global.api.debug.Trace("ACSE StartScreen manager loaded")

-- @Brief Init function for this manager
ACSEStartScreenManager.Init = function(self, _tProperties, _tEnvironment)
global.api.debug.Trace("ACSEStartScreenManager:Init()")
end

-- @Brief Update function for this manager
Expand Down

0 comments on commit 365cc4d

Please sign in to comment.